phpBMS

Ticket #220: invoices.php.patch

File invoices.php.patch, 9.1 KB (added by m.waldeck@…, 3 years ago)

first step for individual invoice number

  • modules/bms/include/invoices.php

     
    164164                                <?php 
    165165 
    166166                                foreach($statuses as $therecord){ 
    167                                         ?><option value="<?php echo $therecord["id"]?>" <?php if($statusid==$therecord["id"]) echo "selected=\"selected\""?>><?php echo $therecord["name"]?></option><?php 
     167                                        ?><option value="<?php echo $therecord["id"]?>" <?php if($statusid==$therecord["id"]) echo "selected=\"selected\""?>><?php ___ ($therecord["name"]);?></option><?php 
    168168                                }//endforeach 
    169169                                 
    170170                                ?> 
     
    368368                 
    369369                }//end function 
    370370                 
     371                 
    371372                // CLASS OVERRIDES ====================================================================================== 
    372373                 
    373374                function getDefaults(){ 
     
    401402                        $therecord["hascredit"]=0; 
    402403                        $therecord["creditlimit"]=0; 
    403404                        $therecord["creditleft"]=0; 
     405                        // mw 
     406                        $therecord['invoice_id']=0; // for individual invoice number 
    404407                        return $therecord; 
    405408                } 
    406409                 
     
    432435                                $therecord["creditleft"] = $therecord["creditlimit"] - $arrecord["amtopen"]; 
    433436                        } else 
    434437                                $therecord["creditleft"] =0; 
    435                                  
     438 
    436439                        return $therecord; 
    437440                } 
    438441                 
     
    542545                 
    543546                 
    544547                function updateRecord($variables, $modifiedby = NULL){ 
    545          
     548                print "<!--hier ggf. ID aendern zur Zeit: ". __FILE__ ." " . __LINE__  . "//-->"; 
     549 
    546550                        if($modifiedby === NULL) 
    547551                                $modifiedby = $_SESSION["userinfo"]["id"]; 
    548552                 
     
    608612                        $variables = $this->prepareVariables($variables); 
    609613         
    610614                        $newid = parent::insertRecord($variables, $createdby); 
     615                        //print "hier neue ID einschreiben zur Zeit: ". $newid. " " . __FILE__ ." " . __LINE__ ; 
    611616                         
    612617                        if($variables["billingsaveoptions"] != "orderOnly" || $variables["shiptosaveoptions"] != "orderOnly"){ 
    613618                                 
     
    660665                                SELECT 
    661666                                        products.partname, 
    662667                                        products.partnumber, 
    663  
     668                                        lineitems.displayorder, 
    664669                                        lineitems.id, 
    665670                                        lineitems.productid, 
    666671                                        lineitems.taxable, 
     
    690695                        while($therecord = $this->db->fetchArray($this->queryresult)){ 
    691696                         
    692697                                ?><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"'?>>                                
    695700                                                <input type="hidden" id="li<?php echo $count?>ProductID" value="<?php echo $therecord["productid"]?>"/> 
    696701                                                <input type="hidden" id="li<?php echo $count?>Taxable" value="<?php echo $therecord["taxable"]?>"/> 
    697702                                                <input type="hidden" id="li<?php echo $count?>UnitWeight" class="lineitemWeights" value="<?php echo $therecord["unitweight"]?>"/> 
     
    705710                                                        ?> 
    706711                                                </div> 
    707712                                        </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> 
    710718                                         
    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> 
    714722                                         
    715723                                        <td class="lineitemsButtonTDs"> 
    716724                                                <div id="li<?php echo $count?>ButtonsDiv" class="lineitemsButtonDivs"> 
     
    751759                                $itemRecord = explode("::", $item); 
    752760                                if(count($itemRecord) > 1){ 
    753761                                 
    754                                         $insertstatement =" 
     762                                $insertstatement =" 
    755763                                                INSERT INTO 
    756764                                                        lineitems( 
    757765                                                                invoiceid,  
     
    784792                                                        NOW()                                                    
    785793                                                )"; 
    786794                                         
     795                                         
    787796                                        $this->db->query($insertstatement); 
    788                                                  
     797                                         
    789798                                        $count++; 
    790799                                         
    791800                                }//end if 
     
    985994                function mark_rtp(){ 
    986995                         
    987996                        $whereclause=$this->buildWhereClause(); 
    988                         $whereclause="(".$whereclause.") AND invoices.type='Order'"; 
     997                        $whereclause="(".$whereclause.") AND invoices.type='Order'"; // @TODO Credit Memo 
    989998 
    990999                        // since marking RTP is dependent on the payment method type, 
    9911000                        // items must be updated individually 
     
    11671313                         
    11681314                        if($whereclause)                         
    11691315                                $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"; 
    11721319                 
    11731320                }//end method 
    11741321                 
     
    11741321                 
    11751322                 
    11761323                function post($whereclause=NULL){ 
     1324                        print "<!-- ReadyToPost -> Rechnungsnummer generieren..." . __FILE__ . " ".__LINE__  . "//-->"; 
    11771325                         
    11781326                        if($whereclause) 
    11791327                                $this->prepareWhere($whereclause); 
    1180                          
    1181                          
     1328 
     1329                                // added invoices.type mw 
    11821330                        $querystatement = " 
    11831331                                SELECT 
    11841332                                        invoices.id, 
     
    11831331                                SELECT 
    11841332                                        invoices.id, 
    11851333                                        invoices.clientid, 
     1334                                        invoices.type as invoice_type, 
    11861335                                        invoices.totalti, 
    11871336                                        invoices.invoicedate, 
    11881337                                        paymentmethods.type, 
     
    11971346                                        ".$this->whereclause; 
    11981347                        $queryresult = $this->db->query($querystatement); 
    11991348                         
    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                                                ; 
    12021358 
     1359                                */ 
    12031360                                $updatestatement = " 
    12041361                                        UPDATE 
    12051362                                                `invoices` 
     
    12341391                                                `invoicedate` = NOW(), "; 
    12351392                                                 
    12361393                                }//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                                }                
    12371406                                 
    12381407                                $updatestatement .= " 
    12391408                                                `modifiedby` = ".$this->modifiedby.", 
     
    12421411                                                `id` = ".$therecord["id"]; 
    12431412                                                 
    12441413                                $updateresult = $this->db->query($updatestatement); 
    1245                                                  
     1414         
    12461415                                if($therecord["type"] == "receivable") { 
    12471416                                        // if type = AR, create AR item 
    12481417                                         
     
    12531422                                        $arrecord["itemdate"] = dateToString(stringToDate($therecord["invoicedate"],"SQL") ); 
    12541423                                        $arrecord["clientid"] = $therecord["clientid"]; 
    12551424                                        $arrecord["relatedid"] = $therecord["id"]; 
    1256                                          
     1425                                                                         
    12571426                                        if(!class_exists("phpbmsTable")) 
    12581427                                                include("include/tables.php"); 
    12591428                                                 
     
    12711440                         
    12721441                }//end method 
    12731442                 
     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                 
    12741498        }//end class invoicePost 
    12751499 
    12761500}//end function 
Scanned by Orvant Copyright © 2010 Kreotek, LLC. All Rights reserved.