Ticket #220: invoices.php.patch
| File invoices.php.patch, 9.1 KB (added by m.waldeck@…, 3 years ago) |
|---|
-
modules/bms/include/invoices.php
164 164 <?php 165 165 166 166 foreach($statuses as $therecord){ 167 ?><option value="<?php echo $therecord["id"]?>" <?php if($statusid==$therecord["id"]) echo "selected=\"selected\""?>><?php echo $therecord["name"]?></option><?php167 ?><option value="<?php echo $therecord["id"]?>" <?php if($statusid==$therecord["id"]) echo "selected=\"selected\""?>><?php ___ ($therecord["name"]);?></option><?php 168 168 }//endforeach 169 169 170 170 ?> … … 368 368 369 369 }//end function 370 370 371 371 372 // CLASS OVERRIDES ====================================================================================== 372 373 373 374 function getDefaults(){ … … 401 402 $therecord["hascredit"]=0; 402 403 $therecord["creditlimit"]=0; 403 404 $therecord["creditleft"]=0; 405 // mw 406 $therecord['invoice_id']=0; // for individual invoice number 404 407 return $therecord; 405 408 } 406 409 … … 432 435 $therecord["creditleft"] = $therecord["creditlimit"] - $arrecord["amtopen"]; 433 436 } else 434 437 $therecord["creditleft"] =0; 435 438 436 439 return $therecord; 437 440 } 438 441 … … 542 545 543 546 544 547 function updateRecord($variables, $modifiedby = NULL){ 545 548 print "<!--hier ggf. ID aendern zur Zeit: ". __FILE__ ." " . __LINE__ . "//-->"; 549 546 550 if($modifiedby === NULL) 547 551 $modifiedby = $_SESSION["userinfo"]["id"]; 548 552 … … 608 612 $variables = $this->prepareVariables($variables); 609 613 610 614 $newid = parent::insertRecord($variables, $createdby); 615 //print "hier neue ID einschreiben zur Zeit: ". $newid. " " . __FILE__ ." " . __LINE__ ; 611 616 612 617 if($variables["billingsaveoptions"] != "orderOnly" || $variables["shiptosaveoptions"] != "orderOnly"){ 613 618 … … 660 665 SELECT 661 666 products.partname, 662 667 products.partnumber, 663 668 lineitems.displayorder, 664 669 lineitems.id, 665 670 lineitems.productid, 666 671 lineitems.taxable, … … 690 695 while($therecord = $this->db->fetchArray($this->queryresult)){ 691 696 692 697 ?><tr id="li<?php echo $count?>" class="lineitems"> 693 694 <td colspan="2" class="lineitemsLeft" <?php if($this->invoicetype == "Void" || $this->invoicetype == "Invoice") echo 'nowrap="nowrap"'?>> 698 <td align="center" valign="top"><?php echo intval($therecord["displayorder"])+1;?></td> 699 <td colspan="2" class="lineitemsLeft" <?php if($this->invoicetype == "Void" || $this->invoicetype == "Invoice") echo 'nowrap="nowrap"'?>> 695 700 <input type="hidden" id="li<?php echo $count?>ProductID" value="<?php echo $therecord["productid"]?>"/> 696 701 <input type="hidden" id="li<?php echo $count?>Taxable" value="<?php echo $therecord["taxable"]?>"/> 697 702 <input type="hidden" id="li<?php echo $count?>UnitWeight" class="lineitemWeights" value="<?php echo $therecord["unitweight"]?>"/> … … 705 710 ?> 706 711 </div> 707 712 </td> 708 709 <td><input id="li<?php echo $count?>Memo" class="lineitemMemos" value="<?php echo formatVariable($therecord["memo"])?>"/></td> 713 <td> 714 <textarea id="li<?php echo $count?>Memo" class="lineitemMemos" style="width:95%;height:65px;"><?php 715 echo formatVariable($therecord["memo"]); 716 ?></textarea> 717 </td> 710 718 711 <td ><input id="li<?php echo $count?>UnitPrice" class="fieldCurrency lineitemPrices" value="<?php echo formatVariable($therecord["unitprice"], "currency")?>"/></td>712 <td ><input id="li<?php echo $count?>Quantity" class="lineitemQuantities" value="<?php echo formatVariable($therecord["quantity"], "real")?>"/></td>713 <td ><input id="li<?php echo $count?>Extended" class="uneditable fieldCurrency lineitemExtendeds" readonly="readonly" value="<?php echo formatVariable($therecord["quantity"] * $therecord["unitprice"], "currency")?>"/></td>719 <td valign="top"><input id="li<?php echo $count?>UnitPrice" class="fieldCurrency lineitemPrices" value="<?php echo formatVariable($therecord["unitprice"], "currency")?>"/></td> 720 <td valign="top"><input id="li<?php echo $count?>Quantity" class="lineitemQuantities" value="<?php echo formatVariable($therecord["quantity"], "real")?>"/></td> 721 <td valign="top"><input id="li<?php echo $count?>Extended" class="uneditable fieldCurrency lineitemExtendeds" readonly="readonly" value="<?php echo formatVariable($therecord["quantity"] * $therecord["unitprice"], "currency")?>"/></td> 714 722 715 723 <td class="lineitemsButtonTDs"> 716 724 <div id="li<?php echo $count?>ButtonsDiv" class="lineitemsButtonDivs"> … … 751 759 $itemRecord = explode("::", $item); 752 760 if(count($itemRecord) > 1){ 753 761 754 $insertstatement ="762 $insertstatement =" 755 763 INSERT INTO 756 764 lineitems( 757 765 invoiceid, … … 784 792 NOW() 785 793 )"; 786 794 795 787 796 $this->db->query($insertstatement); 788 797 789 798 $count++; 790 799 791 800 }//end if … … 985 994 function mark_rtp(){ 986 995 987 996 $whereclause=$this->buildWhereClause(); 988 $whereclause="(".$whereclause.") AND invoices.type='Order'"; 997 $whereclause="(".$whereclause.") AND invoices.type='Order'"; // @TODO Credit Memo 989 998 990 999 // since marking RTP is dependent on the payment method type, 991 1000 // items must be updated individually … … 1167 1313 1168 1314 if($whereclause) 1169 1315 $this->whereclause = "(".$whereclause.") AND "; 1170 1171 $this->whereclause .= "invoices.type='Order' AND readytopost = 1"; 1316 1317 // MW added Support for Credit Memo 1318 $this->whereclause .= "( invoices.type='Order' OR invoices.type='Credit Memo' ) AND readytopost = 1"; 1172 1319 1173 1320 }//end method 1174 1321 … … 1174 1321 1175 1322 1176 1323 function post($whereclause=NULL){ 1324 print "<!-- ReadyToPost -> Rechnungsnummer generieren..." . __FILE__ . " ".__LINE__ . "//-->"; 1177 1325 1178 1326 if($whereclause) 1179 1327 $this->prepareWhere($whereclause); 1180 1181 1328 1329 // added invoices.type mw 1182 1330 $querystatement = " 1183 1331 SELECT 1184 1332 invoices.id, … … 1183 1331 SELECT 1184 1332 invoices.id, 1185 1333 invoices.clientid, 1334 invoices.type as invoice_type, 1186 1335 invoices.totalti, 1187 1336 invoices.invoicedate, 1188 1337 paymentmethods.type, … … 1197 1346 ".$this->whereclause; 1198 1347 $queryresult = $this->db->query($querystatement); 1199 1348 1200 $count =0; 1201 while($therecord = $this->db->fetchArray($queryresult)){ 1349 $count = 0; 1350 $old_invoice_type = ''; 1351 while($therecord = $this->db->fetchArray($queryresult)) 1352 { 1353 // $old_invoice_type = $therecord['invoice_type']; 1354 1355 /* 1356 if ( strtolower ($old_invoice_type) == 'credit memo') 1357 ; 1202 1358 1359 */ 1203 1360 $updatestatement = " 1204 1361 UPDATE 1205 1362 `invoices` … … 1234 1391 `invoicedate` = NOW(), "; 1235 1392 1236 1393 }//end if 1394 1395 1396 // MW 1397 $iid = $this->generateItemNumber ($old_invoice_type); 1398 1399 if ( $iid ) 1400 $updatestatement .= "invoice_id = '".$iid."', "; 1401 else 1402 { 1403 print "Fehlermeldung - keine Rechnungsnummer gefunden/generiert. " . __FILE__ . " " . __LINE__; 1404 continue; 1405 } 1237 1406 1238 1407 $updatestatement .= " 1239 1408 `modifiedby` = ".$this->modifiedby.", … … 1242 1411 `id` = ".$therecord["id"]; 1243 1412 1244 1413 $updateresult = $this->db->query($updatestatement); 1245 1414 1246 1415 if($therecord["type"] == "receivable") { 1247 1416 // if type = AR, create AR item 1248 1417 … … 1253 1422 $arrecord["itemdate"] = dateToString(stringToDate($therecord["invoicedate"],"SQL") ); 1254 1423 $arrecord["clientid"] = $therecord["clientid"]; 1255 1424 $arrecord["relatedid"] = $therecord["id"]; 1256 1425 1257 1426 if(!class_exists("phpbmsTable")) 1258 1427 include("include/tables.php"); 1259 1428 … … 1271 1440 1272 1441 }//end method 1273 1442 1443 1444 /** 1445 * Create a individual invoice number 1446 * @author m.waldeck@ibased.de 1447 * @copyright Copyright (c) 2009, Mathias Waldeck, i.based: Systemhaus GmbH & Co. KG 1448 * @todo Implementing various Number-Typs and Integration in central Configuration 1449 * 1450 * ALTER TABLE `invoices` ADD `invoice_id` VARCHAR( 11 ) NOT NULL AFTER `clientid` ; 1451 */ 1452 1453 function generateItemNumber ( $type = "" ) 1454 { 1455 $querystatement = ' 1456 SELECT invoice_id 1457 FROM `invoices` 1458 ORDER BY `invoices`.`invoice_id` DESC 1459 LIMIT 0 , 1'; 1460 1461 $queryresult = $this->db->query($querystatement); 1462 1463 $last_invoice_id=""; 1464 $therecord=0; 1465 if ( ($therecord = $this->db->fetchArray($queryresult)) && is_array ($therecord) ) 1466 { 1467 $last_invoice_id = $therecord['invoice_id']; 1468 } 1469 else 1470 { 1471 return FALSE; 1472 } 1473 1474 if (substr ($last_invoice_id,-5) < 13950 ) $last_invoice_id = 13950; // our first Invoice Number from old erp 1475 1476 do 1477 { 1478 // our number type YearMonth + to number consecutively 1479 $nr = substr ($last_invoice_id,-5); 1480 $prefix = date ('ym'); 1481 $new_invoice_id = $prefix . ($nr + 1); 1482 1483 $querystatement = sprintf (' 1484 SELECT invoice_id 1485 FROM `invoices` WHERE invoice_id = "%s" 1486 ORDER BY `invoices`.`invoice_id` DESC 1487 LIMIT 0 , 1', $new_invoice_id); 1488 1489 $queryresult = $this->db->query($querystatement); 1490 } 1491 while (mysql_num_rows ($queryresult)>0 ); 1492 1493 return $new_invoice_id; 1494 1495 } 1496 1497 1274 1498 }//end class invoicePost 1275 1499 1276 1500 }//end function