phpBMS

Show
Ignore:
Timestamp:
04/07/09 11:44:18 (3 years ago)
Author:
nate
Message:
  • Merged Nathan branch back into trunk.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/modules/bms/include/receipts.php

    r384 r485  
    4040 
    4141        class receiptitems{ 
    42          
     42 
    4343                function receiptitems($db){ 
    44                          
     44 
    4545                        $this->db = $db; 
    46                          
    47                 }//end method 
    48                  
     46 
     47                }//end method 
     48 
    4949                function get($receiptid){ 
    5050 
     
    6767                                        aritems.type, 
    6868                                        aritems.itemdate"; 
    69                                          
     69 
    7070                                return $this->db->query($querystatement); 
    71                  
     71 
    7272                }//end function 
    73                  
    74                  
     73 
     74 
    7575                function show($queryresult, $receiptPosted, $receiptid){ 
    76                          
     76 
    7777                        $count = 1; 
    78                  
     78 
    7979                        while($therecord = $this->db->fetchArray($queryresult)){ 
    80                                  
     80 
    8181                                $recID = "i".$count; 
    82                                                                  
     82 
    8383                                if($therecord["type"] == "invoice"){ 
    84                                  
     84 
    8585                                        $tempDate = stringToDate($therecord["itemdate"], "SQL"); 
    8686                                        $dueDate = dateToString( strtotime(TERM1_DAYS." days", $tempDate) ); 
    87                                  
    88                                 } else  
     87 
     88                                } else 
    8989                                        $dueDate = " "; 
    90                                  
     90 
    9191                                if($therecord["type"] == "deposit" && $therecord["relatedid"] == $receiptid){ 
    9292                                        $therecord["relatedid"] = ""; 
     
    9494                                        $therecord["aritemid"] = 0; 
    9595                                } 
    96                                  
    97                                 if($receiptPosted)                                       
    98                                         $docDue = $therecord["amount"] - $therecord["paid"];                                     
     96 
     97                                if($receiptPosted) 
     98                                        $docDue = $therecord["amount"] - $therecord["paid"]; 
    9999                                elseif($therecord["relatedid"]) 
    100                                         $docDue = $therecord["amount"] - $therecord["paid"] - $therecord["applied"] - $therecord["discount"] - $therecord["taxadjustment"];      
     100                                        $docDue = $therecord["amount"] - $therecord["paid"] - $therecord["applied"] - $therecord["discount"] - $therecord["taxadjustment"]; 
    101101                                else 
    102102                                        $docDue = 0; 
    103                                  
    104                                  
     103 
     104 
    105105                                ?> 
    106106 
     
    122122                                        <td><input id="<?php echo $recID?>TaxAdj" class="currency" value="<?php echo formatVariable($therecord["taxadjustment"], "currency")?>" size="10" maxlength="12"/></td> 
    123123                                        <td><button type="button" id="<?php echo $recID?>RemoveARItemButton" class="graphicButtons buttonMinus" title="remove item"><span>-</span></button></td> 
    124                                 </tr>                            
    125                                  
     124                                </tr> 
     125 
    126126                                <?php 
    127                                  
     127 
    128128                                $count++; 
    129129                        }//endwhile 
    130                  
    131                  
    132                 }//end method 
    133  
    134                  
     130 
     131 
     132                }//end method 
     133 
     134 
    135135                function set($itemlist, $receiptid, $clientid, $userid){ 
    136                          
     136 
    137137                        //remove any exisiting items 
    138138                        $deletestatement = "DELETE FROM receiptitems WHERE receiptid =".((int) $receiptid); 
    139139                        $this->db->query($deletestatement); 
    140                          
     140 
    141141                        //remove any ar deposits created by ths receipt 
    142142                        $deletestatement = "DELETE FROM aritems WHERE relatedid = ".((int) $receiptid)." AND `type` = 'deposit'"; 
     
    146146 
    147147                        foreach($itemsArray as $item){ 
    148                          
     148 
    149149                                $itemRecord = explode("::", $item); 
    150                                  
     150 
    151151                                if(count($itemRecord) > 1){ 
    152152 
    153153                                        //if no ar id, or the deposit is from this record, we need to create the ar item 
    154154                                        if(!$itemRecord[0] || ($itemRecord[1] == $receiptid && $itemRecord[2] == "deposit") ){ 
    155                                          
     155 
    156156                                                $arrecord = array(); 
    157157                                                $arrecord["type"] = "deposit"; 
    158158                                                $arrecord["status"] = "open"; 
    159159                                                $arrecord["posted"] = 0; 
    160                                                 $arrecord["amount"] = -1 * currencyToNumber($itemRecord[8]);                                             
     160                                                $arrecord["amount"] = -1 * currencyToNumber($itemRecord[8]); 
    161161                                                $arrecord["itemdate"] = $itemRecord[3]; 
    162162                                                $arrecord["clientid"] = $clientid; 
    163163                                                $arrecord["relatedid"] = $receiptid; 
    164          
    165          
     164 
     165 
    166166                                                if(!isset($aritems)) 
    167167                                                        $aritems = new phpbmsTable($this->db, 303); 
    168                                                  
     168 
    169169                                                $aritems->insertRecord($arrecord, $userid); 
    170                                                  
     170 
    171171                                                $itemRecord[0] = $this->db->insertId(); 
    172                                                  
     172 
    173173                                        }//end if 
    174                                          
     174 
    175175                                        $insertstatement =" 
    176176                                        INSERT INTO 
     
    184184                                                ".currencyToNumber($itemRecord[10])." 
    185185                                        )"; 
    186                                  
     186 
    187187                                        $this->db->query($insertstatement); 
    188188 
    189189                                }//endif 
    190                                  
     190 
    191191                        }//endforeach 
    192                  
    193                 }//end method 
    194          
     192 
     193                }//end method 
     194 
    195195        }// end class 
    196196 
     
    199199        //====================================================================== 
    200200        class receipts extends phpbmsTable{ 
    201                  
     201 
     202                var $availableClientIDs = array(); 
     203                var $availablePaymentMethodIDs = array(); 
    202204 
    203205                function showPaymentOptions($selectedid){ 
    204                  
     206 
    205207                        global $phpbms; 
    206                          
     208 
    207209                        $querystatement = " 
    208210                                SELECT 
     
    221223                                        priority, 
    222224                                        name"; 
    223                          
     225 
    224226                        $queryresult = $this->db->query($querystatement); 
    225                  
     227 
    226228                        ?> 
    227229                        <label for="paymentmethodid">payment type</label><br /> 
    228230                        <select id="paymentmethodid" name="paymentmethodid"> 
    229                                 <?php  
     231                                <?php 
    230232                                        $phpbms->bottomJS[] = 'paymentTypes = Array()'; 
    231233                                        $phpbms->bottomJS[] = 'paymentTypes["s-1"] = Array();'; 
     
    233235                                        $phpbms->bottomJS[] = 'paymentTypes["s-1"]["onlineprocess"] = 0'; 
    234236                                        $phpbms->bottomJS[] = 'paymentTypes["s-1"]["onlineprocess"] = null'; 
    235                                  
     237 
    236238                                        while($therecord = $this->db->fetchArray($queryresult)){ 
    237239 
     
    240242                                                $phpbms->bottomJS[] = 'paymentTypes["s'.$therecord["id"].'"]["onlineprocess"] = "'.$therecord["onlineprocess"].'";'; 
    241243                                                $phpbms->bottomJS[] = 'paymentTypes["s'.$therecord["id"].'"]["processscript"] = "'.$therecord["processscript"].'";'; 
    242                                          
    243                                                 ?><option value="<?php echo $therecord["id"]?>" <?php if($therecord["id"] == $selectedid) echo 'selected="selected"'?>><?php echo $therecord["name"]?></option><?php  
     244 
     245                                                ?><option value="<?php echo $therecord["id"]?>" <?php if($therecord["id"] == $selectedid) echo 'selected="selected"'?>><?php echo $therecord["name"]?></option><?php 
    244246                                                echo "\n"; 
    245                                          
     247 
    246248                                        }//endwhile 
    247                                          
     249 
    248250                                ?> 
    249251                                <option value="-1" <?php if($selectedid == -1) echo 'selected="selected"'?>>Other...</option> 
    250                         </select><?php  
    251  
    252                          
    253                 }//end method 
    254                  
     252                        </select><?php 
     253 
     254 
     255                }//end method 
     256 
    255257                // CLASS OVERRIDES ====================================================================================== 
    256                  
     258 
    257259                function getDefaults(){ 
    258260                        $therecord = parent::getDefaults(); 
    259                          
     261 
    260262                        $therecord["clientid"] = ""; 
    261263                        $therecord["status"] = "open"; 
    262264                        $therecord["receiptdate"] = dateToString(mktime(),"SQL"); 
    263                          
     265 
    264266                        return $therecord; 
    265267                } 
    266                                                  
    267                  
     268 
     269 
     270                function populateClientArray(){ 
     271 
     272                        $this->availableClientIDs = array(); 
     273 
     274                        $querystatement = " 
     275                                SELECT 
     276                                        `id` 
     277                                FROM 
     278                                        `clients`; 
     279                                "; 
     280 
     281                        $queryresult = $this->db->query($querystatement); 
     282 
     283                        if($this->db->numRows($queryresult)){ 
     284                                while($therecord = $this->db->fetchArray($queryresult)) 
     285                                        $this->availableClientIDs[] = $therecord["id"]; 
     286                        }else 
     287                                $this->availableClientIDs[] = "none"; 
     288 
     289                }//end method --populateClientArray-- 
     290 
     291 
     292                function populatePaymentArray(){ 
     293 
     294                        $this->availablePaymentMethodIDs = array(); 
     295 
     296                        $querystatement = " 
     297                                SELECT 
     298                                        `id` 
     299                                FROM 
     300                                        `paymentmethods`; 
     301                                "; 
     302 
     303                        $queryresult = $this->db->query($querystatement); 
     304 
     305                        //for the "other" choice on receipts 
     306                        $this->availablePaymentMethodIDs[] = -1; 
     307 
     308                        while($therecord = $this->db->fetchArray($queryresult)) 
     309                                $this->availablePaymentMethodIDs[] = $therecord["id"]; 
     310 
     311                }//end method --populatePaymentArray-- 
     312 
     313 
     314                function verifyVariables($variables){ 
     315 
     316                        //default not sufficient 
     317                        if(isset($variables["clientid"])){ 
     318 
     319                                if(((int) $variables["clientid"]) > 0){ 
     320 
     321                                        if(!count($this->availableClientIDs)) 
     322                                                $this->populateClientArray(); 
     323 
     324                                        if(!in_array(((int)$variables["clientid"]),$this->availableClientIDs)) 
     325                                                $this->verifyErrors[] = "The `clientid` field does not give an existing/acceptable client id number."; 
     326                                }else 
     327                                        $this->verifyErrors[] = "The `clientid` field must be a positive number."; 
     328 
     329                        }else 
     330                                $this->verifyErrors[] = "The `clientid` field must be set."; 
     331 
     332                        //because enum, default not sufficient 
     333                        if(isset($variables["status"])){ 
     334                                switch($variables["status"]){ 
     335 
     336                                        case "open": 
     337                                        case "collected": 
     338                                                break; 
     339 
     340                                        default: 
     341                                                $this->verifyErrors[] = "The value of the `status` field is invalid.  It must 
     342                                                        be either 'open' or 'closed'."; 
     343                                        break; 
     344 
     345                                }//end switch 
     346                        }else 
     347                                $this->verifyErrors[] = "The `status` field must be set."; 
     348 
     349                        // Default is not sufficient 
     350                        if(isset($variables["paymentmethodid"])){ 
     351 
     352                                if(is_numeric($variables["paymentmethodid"])){ 
     353 
     354                                        if(!count($this->availablePaymentMethodIDs)) 
     355                                                $this->populatePaymentArray(); 
     356 
     357                                        if(!in_array(((int)$variables["paymentmethodid"]),$this->availablePaymentMethodIDs)) 
     358                                                $this->verifyErrors[] = "The `paymentmethod` field does not give an existing/accpetable payment method id number."; 
     359                                }else 
     360                                        $this->verifyErrors[] = "The `paymentmethodid` field must be numeric."; 
     361 
     362                        }else 
     363                                $this->verifyErrors[] = "The `paymentmethodid` field must be set."; 
     364 
     365                        //check booleans 
     366                        if(isset($variables["readytopost"])) 
     367                                if($variables["readytopost"] && $variables["readytopost"] != 1) 
     368                                        $this->verifyErrors[] = "The `readytopost` field must be a boolean (equivalent to 0 or exactly 1)."; 
     369 
     370                        if(isset($variables["posted"])) 
     371                                if($variables["posted"] && $variables["posted"] != 1) 
     372                                        $this->verifyErrors[] = "The `posted` field must be a boolean (equivalent to 0 or exactly 1)."; 
     373 
     374                        return parent::verifyVariables($variables); 
     375 
     376                }//end method --verifyVariables-- 
     377 
     378 
    268379                function prepareVariables($variables){ 
    269                                          
     380 
    270381                        $variables["amount"] = currencyToNumber($variables["amount"]); 
    271                                  
     382 
    272383                        return $variables; 
    273384                } 
    274                  
    275                  
     385 
     386 
    276387                function updateRecord($variables, $modifiedby = NULL){ 
    277          
    278                         if($modifiedby === NULL) 
    279                                 $modifiedby = $_SESSION["userinfo"]["id"]; 
    280                          
    281                         $variables = $this->prepareVariables($variables); 
    282                  
     388 
    283389                        if(parent::updateRecord($variables, $modifiedby)){ 
    284                                  
     390 
    285391                                if($variables["itemschanged"]==1){ 
    286                                  
     392 
    287393                                        $items = new receiptitems($this->db); 
    288          
     394 
    289395                                        $items->set($variables["itemslist"], $variables["id"], $variables["clientid"], $modifiedby); 
    290                                  
     396 
    291397                                }//end if 
    292                                                                  
     398 
    293399                        }//end if 
    294400 
    295401                }//end method 
    296          
    297          
    298          
     402 
     403 
     404 
    299405                function insertRecord($variables, $createdby = NULL){ 
    300          
    301                         if($createdby === NULL) 
    302                                 $createdby = $_SESSION["userinfo"]["id"]; 
    303          
    304                         $variables = $this->prepareVariables($variables); 
    305          
     406 
    306407                        $newid = parent::insertRecord($variables, $createdby); 
    307          
     408 
    308409                        if($variables["itemschanged"]==1){ 
    309                                  
     410 
    310411                                $items = new receiptitems($this->db); 
    311412 
    312413                                $items->set($variables["itemslist"], $newid, $variables["clientid"], $createdby); 
    313                          
     414 
    314415                        }//end if 
    315                          
     416 
    316417                        return $newid; 
    317418                } 
     
    322423if(class_exists("searchFunctions")){ 
    323424        class receiptsSearchFunctions extends searchFunctions{ 
    324          
     425 
    325426                function post(){ 
    326                  
     427 
    327428                        $whereclause = $this->buildWhereClause(); 
    328                  
     429 
    329430                        include_once("include/post_class.php"); 
    330431                        defineReceiptPost(); 
    331                          
     432 
    332433                        $receiptPost = new receiptPost($this->db); 
    333                          
     434 
    334435                        $count = $receiptPost->post($whereclause); 
    335                  
     436 
    336437                        $message = $this->buildStatusMessage($count); 
    337438                        $message .= " posted."; 
    338                          
     439 
    339440                        return $message; 
    340441                }//end method 
    341                  
    342          
     442 
     443 
    343444                function delete_record(){ 
    344                                          
     445 
    345446                        //passed variable is array of user ids to be revoked 
    346447                        $whereclause = $this->buildWhereClause(); 
    347                          
     448 
    348449                        $querystatement =" 
    349                                 SELECT  
     450                                SELECT 
    350451                                        id 
    351452                                FROM 
     
    357458 
    358459                        $queryresult = $this->db->query($querystatement); 
    359                          
     460 
    360461                        $count = $this->db->numRows($queryresult); 
    361                          
     462 
    362463                        $newWhere = ""; 
    363464                        while($therecord = $this->db->fetchArray($queryresult)) 
    364465                                $newWhere .= " OR id = ".$therecord["id"]; 
    365                                  
     466 
    366467                        if(strlen($newWhere)) 
    367468                                $newWhere = substr($newWhere, 4); 
    368469                        else 
    369470                                $newWhere = "id = -1974"; 
    370                          
     471 
    371472                        $deletestatement = " 
    372473                                DELETE FROM 
     
    375476                                        `type` = 'deposit' 
    376477                                        AND (".str_replace("id =", "relatedid =", $newWhere).")"; 
    377                                          
     478 
    378479                        $this->db->query($deletestatement); 
    379                          
     480 
    380481                        $deletestatement = " 
    381482                                DELETE FROM 
     
    383484                                WHERE 
    384485                                        ".str_replace("id =", "receiptid =", $newWhere); 
    385                                          
     486 
    386487                        $this->db->query($deletestatement); 
    387488 
     
    391492                                WHERE 
    392493                                        ".$newWhere; 
    393                                          
    394                         $this->db->query($deletestatement);                                      
    395                                                  
     494 
     495                        $this->db->query($deletestatement); 
     496 
    396497                        $message = $this->buildStatusMessage($count); 
    397498                        $message.=" deleted."; 
    398                  
     499 
    399500                        return $message; 
    400501                }//end method 
    401                  
    402                  
     502 
     503 
    403504                function _getFullyDistributed(){ 
    404505 
    405506                        $whereclause = $this->buildWhereClause(); 
    406                          
     507 
    407508                        $querystatement = " 
    408509                                SELECT 
     
    420521                        $count = 0; 
    421522                        while($therecord = $this->db->fetchArray($queryresult)){ 
    422                          
     523 
    423524                                $querystatement = " 
    424525                                        SELECT 
     
    432533 
    433534                                $checkrecord = $this->db->fetchArray($checkresult); 
    434                                  
     535 
    435536                                if($therecord["amount"] == $checkrecord["thesum"]){ 
    436537                                        $newWhere .= " OR id = ".$therecord["id"]; 
    437538                                        $count++; 
    438                                          
     539 
    439540                                }//endif 
    440                                  
     541 
    441542                        }//endif 
    442543 
     
    445546                        else 
    446547                                $newWhere = "id = -1974"; 
    447                          
     548 
    448549                        return array("clause" => $newWhere, "count" => $count); 
    449                                          
    450                 }//end method 
    451                  
    452                  
     550 
     551                }//end method 
     552 
     553 
    453554                function mark_rtp(){ 
    454                  
     555 
    455556                        $where = $this->_getFullyDistributed(); 
    456                          
     557 
    457558                        $updatestatement=" 
    458559                                UPDATE 
     
    462563                                        readytopost = 1, 
    463564                                        modifiedby = ".$_SESSION["userinfo"]["id"].", 
    464                                         modifieddate = NOW()                                     
     565                                        modifieddate = NOW() 
    465566                                WHERE 
    466567                                        ".$where["clause"]; 
    467                                          
     568 
    468569                        $this->db->query($updatestatement); 
    469570 
    470571                        $message = $this->buildStatusMessage($where["count"]); 
    471572                        $message.=" marked ready to post."; 
    472                  
     573 
    473574                        return $message; 
    474575                }//end method 
    475                  
    476                  
     576 
     577 
    477578                function mark_collected(){ 
    478                  
     579 
    479580                        $where = $this->_getFullyDistributed(); 
    480                          
     581 
    481582                        $updatestatement=" 
    482583                                UPDATE 
     
    488589                                WHERE 
    489590                                        ".$where["clause"]; 
    490                                          
     591 
    491592                        $this->db->query($updatestatement); 
    492593 
    493594                        $message = $this->buildStatusMessage($where["count"]); 
    494595                        $message.=" marked collected."; 
    495                  
     596 
    496597                        return $message; 
    497598                }//end method 
    498          
     599 
    499600        }//end class 
    500601}//end if 
     
    504605 
    505606        class receiptPost extends tablePost{ 
    506                  
     607 
    507608                function receiptPost($db, $modifiedby = NULL){ 
    508                          
     609 
    509610                        parent::tablePost($db, $modifiedby); 
    510                          
     611 
    511612                }//end method 
    512613 
    513614 
    514615                function prepareWhere($whereclause=NULL){ 
    515                          
     616 
    516617                        $this->whereclause = ""; 
    517                          
    518                         if($whereclause)                         
     618 
     619                        if($whereclause) 
    519620                                $this->whereclause = "(".$whereclause.") AND "; 
    520                          
     621 
    521622                        $this->whereclause .= "receipts.posted = 0 AND receipts.readytopost = 1"; 
    522                  
    523                 }//end method 
    524                  
    525                  
     623 
     624                }//end method 
     625 
     626 
    526627                function post($whereclause=NULL){ 
    527                          
     628 
    528629                        if($whereclause) 
    529630                                $this->prepareWhere($whereclause); 
    530                          
     631 
    531632 
    532633                        $querystatement = " 
     
    537638                                WHERE 
    538639                                        ".$this->whereclause; 
    539                                          
     640 
    540641                        $queryresult = $this->db->query($querystatement); 
    541                          
     642 
    542643                        $count = $this->db->numRows($queryresult); 
    543644                        $newWhere = ""; 
    544645                        while($therecord = $this->db->fetchArray($queryresult)){ 
    545                          
     646 
    546647                                $querystatement = " 
    547648                                        SELECT 
     
    559660                                        WHERE 
    560661                                                receiptitems.receiptid = ".$therecord["id"]; 
    561                                  
     662 
    562663                                $itemsresult = $this->db->query($querystatement); 
    563                                  
     664 
    564665                                while($itemrecord = $this->db->fetchArray($itemsresult)){ 
    565                                  
     666 
    566667                                        if($itemrecord["relatedid"] == $therecord["id"] && $itemrecord["type"] == "deposit") 
    567668                                                $paid = $itemrecord["paid"]; 
     
    573674                                        else 
    574675                                                $status = "open"; 
    575                                  
     676 
    576677                                        $updatestatement =" 
    577678                                                UPDATE 
     
    582683                                                        `status` = '".$status."', 
    583684                                                        modifiedby = ".$_SESSION["userinfo"]["id"].", 
    584                                                         modifieddate = NOW()                                                     
     685                                                        modifieddate = NOW() 
    585686                                                WHERE 
    586687                                                        id = ".$itemrecord["aritemid"]; 
    587                                          
     688 
    588689                                        $this->db->query($updatestatement); 
    589                                          
     690 
    590691                                        if($itemrecord["type"] == "invoice"){ 
    591                                                  
     692 
    592693                                                $updatestatement = " 
    593                                                         UPDATE  
     694                                                        UPDATE 
    594695                                                                invoices 
    595696                                                        SET 
     
    601702 
    602703                                                        $this->db->query($updatestatement); 
    603                                                          
     704 
    604705                                        }//endif 
    605                                  
     706 
    606707                                }//endwhile 
    607708 
     
    611712                        if(strlen($newWhere)) 
    612713                                $newWhere = substr($newWhere, 4); 
    613                          
     714 
    614715                        if($newWhere){ 
    615                          
     716 
    616717                                $updatestatement = " 
    617718                                        UPDATE 
     
    628729                                                ccnumber = LPAD(SUBSTRING(ccnumber,-4),LENGTH(ccnumber),'*'), 
    629730                                        "; 
    630                                 }//endif                                                 
    631                                                  
     731                                }//endif 
     732 
    632733                                $updatestatement .=" 
    633734                                                modifiedby = ".$_SESSION["userinfo"]["id"].", 
     
    635736                                        WHERE 
    636737                                                ".$newWhere; 
    637          
     738 
    638739                                $this->db->query($updatestatement); 
    639          
     740 
    640741 
    641742                        }//endif 
    642                          
     743 
    643744                        return $count; 
    644                          
    645                 }//end method 
    646                  
     745 
     746                }//end method 
     747 
    647748        }//end class invoicePost 
    648749 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.