Changeset 451
- Timestamp:
- 03/12/09 11:42:41 (3 years ago)
- Files:
-
- 1 modified
-
trunk/phpbms/modules/bms/include/invoices.php (modified) (56 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/modules/bms/include/invoices.php
r405 r451 39 39 if(class_exists("phpbmsTable")){ 40 40 class invoices extends phpbmsTable{ 41 41 42 42 function showClientType($id){ 43 43 44 44 if(((int) $id) != 0){ 45 45 46 46 $querystatement=" 47 SELECT 47 SELECT 48 48 type 49 49 FROM … … 51 51 WHERE 52 52 id=".((int) $id); 53 53 54 54 $therecord = $this->db->fetchArray($this->db->query($querystatement)); 55 55 56 } else { 57 56 } else { 57 58 58 $therecord["type"] = "client"; 59 59 60 60 }//endif id 61 61 62 ?><input type="hidden" id="clienttype" name="clienttype" <?php if($id) echo 'value="'.$therecord["type"].'"'?> /><?php 63 64 }//end method 65 66 62 ?><input type="hidden" id="clienttype" name="clienttype" <?php if($id) echo 'value="'.$therecord["type"].'"'?> /><?php 63 64 }//end method 65 66 67 67 function updateStatus($invoiceid,$statusid,$statusdate,$assignedtoid){ 68 68 69 69 $querystatement="DELETE FROM invoicestatushistory WHERE invoiceid=".$invoiceid." AND invoicestatusid=".$statusid; 70 70 $queryresult=$this->db->query($querystatement); 71 71 72 72 $querystatement="INSERT INTO invoicestatushistory (invoiceid,invoicestatusid,statusdate,assignedtoid) values("; 73 73 $querystatement.=((int) $invoiceid).", "; 74 74 $querystatement.=((int) $statusid).", "; 75 75 76 76 if($statusdate=="" || $statusdate=="0/0/0000") $tempdate="NULL"; 77 77 else{ … … 83 83 else 84 84 $querystatement.=((int) $assignedtoid); 85 85 86 86 $querystatement.=")"; 87 87 88 88 $queryresult=$this->db->query($querystatement); 89 89 } 90 91 90 91 92 92 function showPaymentSelect($id,$paymentMethods){ 93 93 ?><select name="paymentmethodid" id="paymentmethodid" onchange="showPaymentOptions()"> 94 94 <option value="0" <?php if($id==0) echo "selected=\"selected\""?>><none></option> 95 95 <?php foreach($paymentMethods as $method){?> 96 <option value="<?php echo $method["id"]?>" <?php if($id==$method["id"]) echo "selected=\"selected\""?>><?php echo $method["name"]?></option> 96 <option value="<?php echo $method["id"]?>" <?php if($id==$method["id"]) echo "selected=\"selected\""?>><?php echo $method["name"]?></option> 97 97 <?php } ?> 98 98 </select> 99 <?php 99 <?php 100 100 } 101 102 101 102 103 103 function getDefaultStatus(){ 104 104 105 105 $querystatement="SELECT id FROM invoicestatuses WHERE invoicedefault=1"; 106 106 $queryresult=$this->db->query($querystatement); 107 107 108 108 $therecord=$this->db->fetchArray($queryresult); 109 109 110 110 return $therecord["id"]; 111 111 } 112 113 112 113 114 114 function getStatuses($statusid){ 115 115 116 116 global $phpbms; 117 117 118 118 $querystatement=" 119 SELECT 119 SELECT 120 120 invoicestatuses.id, 121 121 invoicestatuses.name, … … 125 125 users.firstname, 126 126 users.lastname 127 FROM 127 FROM 128 128 (invoicestatuses LEFT JOIN users ON invoicestatuses.defaultassignedtoid=users.id) 129 WHERE 129 WHERE 130 130 invoicestatuses.inactive=0 131 131 OR invoicestatuses.id =".((int) $statusid)." 132 ORDER BY 132 ORDER BY 133 133 invoicestatuses.priority, 134 134 invoicestatuses.name"; 135 135 136 136 $queryresult=$this->db->query($querystatement); 137 137 138 138 $thereturn = array(); 139 139 140 140 $phpbms->topJS[] = 'statuses=Array();'; 141 141 142 142 143 143 while($therecord = $this->db->fetchArray($queryresult)){ 144 144 145 145 $thereturn[] = $therecord; 146 146 147 147 $phpbms->topJS[] = 'statuses['.$therecord["id"].']=Array();'; 148 148 $phpbms->topJS[] = 'statuses['.$therecord["id"].']["name"]="'.htmlQuotes($therecord["name"]).'";'; … … 150 150 $phpbms->topJS[] = 'statuses['.$therecord["id"].']["userid"]="'.htmlQuotes($therecord["defaultassignedtoid"]).'";'; 151 151 $phpbms->topJS[] = 'statuses['.$therecord["id"].']["firstname"]="'.htmlQuotes($therecord["firstname"]).'";'; 152 $phpbms->topJS[] = 'statuses['.$therecord["id"].']["lastname"]="'.htmlQuotes($therecord["lastname"]).'";'; 153 152 $phpbms->topJS[] = 'statuses['.$therecord["id"].']["lastname"]="'.htmlQuotes($therecord["lastname"]).'";'; 153 154 154 }//endwhile 155 155 156 156 return $thereturn; 157 157 158 158 }//end function 159 159 160 160 161 161 function displayStatusDropDown($statusid,$statuses){ 162 162 163 163 ?><select id="statusid" name="statusid" class="important"> 164 164 <?php … … 167 167 ?><option value="<?php echo $therecord["id"]?>" <?php if($statusid==$therecord["id"]) echo "selected=\"selected\""?>><?php echo $therecord["name"]?></option><?php 168 168 }//endforeach 169 169 170 170 ?> 171 171 </select><?php … … 173 173 }//end method 174 174 175 175 176 176 function getPayments($paymentmethodid){ 177 177 178 178 $querystatement=" 179 SELECT 179 SELECT 180 180 id, 181 181 name, … … 183 183 onlineprocess, 184 184 processscript 185 FROM 186 paymentmethods 187 WHERE 188 inactive=0 185 FROM 186 paymentmethods 187 WHERE 188 inactive=0 189 189 OR id=".((int) $paymentmethodid)." 190 ORDER BY 190 ORDER BY 191 191 priority, 192 192 name"; 193 193 194 194 $queryresult=$this->db->query($querystatement); 195 195 196 196 $thereturn = array(); 197 197 198 198 global $phpbms; 199 199 200 200 $phpbms->topJS[] = 'paymentMethods=Array();'; 201 201 202 202 while($therecord = $this->db->fetchArray($queryresult)) { 203 $thereturn[$therecord["id"]]=$therecord; 204 203 $thereturn[$therecord["id"]]=$therecord; 204 205 205 $phpbms->topJS[] = 'paymentMethods['.$therecord["id"].']=Array();'; 206 206 $phpbms->topJS[] = 'paymentMethods['.$therecord["id"].']["name"]="'.htmlQuotes($therecord["name"]).'";'; 207 207 $phpbms->topJS[] = 'paymentMethods['.$therecord["id"].']["type"]="'.htmlQuotes($therecord["type"]).'";'; 208 208 $phpbms->topJS[] = 'paymentMethods['.$therecord["id"].']["onlineprocess"]="'.htmlQuotes($therecord["onlineprocess"]).'";'; 209 $phpbms->topJS[] = 'paymentMethods['.$therecord["id"].']["processscript"]="'.htmlQuotes($therecord["processscript"]).'";'; 209 $phpbms->topJS[] = 'paymentMethods['.$therecord["id"].']["processscript"]="'.htmlQuotes($therecord["processscript"]).'";'; 210 210 } 211 211 212 212 return $thereturn; 213 213 214 214 }//end function 215 216 215 216 217 217 function showShippingSelect($id,$shippingMethods){ 218 218 … … 220 220 <option value="0" <?php if($id==0) echo "selected=\"selected\""?>><none></option> 221 221 <?php foreach($shippingMethods as $method){?> 222 <option value="<?php echo $method["id"]?>" <?php if($id==$method["id"]) echo "selected=\"selected\""?>><?php echo $method["name"]?></option> 222 <option value="<?php echo $method["id"]?>" <?php if($id==$method["id"]) echo "selected=\"selected\""?>><?php echo $method["name"]?></option> 223 223 <?php } ?> 224 224 </select> 225 <?php 225 <?php 226 226 227 227 }//end function 228 229 228 229 230 230 function getShipping($shippingmethodid){ 231 231 232 232 $querystatement=" 233 SELECT 233 SELECT 234 234 id, 235 235 name, 236 236 canestimate, 237 237 estimationscript 238 FROM 239 shippingmethods 240 WHERE 238 FROM 239 shippingmethods 240 WHERE 241 241 inactive=0 242 OR id=".((int) $shippingmethodid)." 243 ORDER BY 242 OR id=".((int) $shippingmethodid)." 243 ORDER BY 244 244 priority, 245 245 name"; 246 246 247 247 $queryresult=$this->db->query($querystatement); 248 248 249 249 $thereturn=array(); 250 250 251 251 global $phpbms; 252 252 253 253 $phpbms->topJS[] = 'shippingMethods=Array();'; 254 254 255 255 while($therecord = $this->db->fetchArray($queryresult)) { 256 $thereturn[$therecord["id"]]=$therecord; 257 256 $thereturn[$therecord["id"]]=$therecord; 257 258 258 $phpbms->topJS[] = 'shippingMethods['.$therecord["id"].']=Array();'; 259 259 $phpbms->topJS[] = 'shippingMethods['.$therecord["id"].']["name"]="'.htmlQuotes($therecord["name"]).'";'; … … 265 265 266 266 }//end function 267 268 267 268 269 269 function showTaxSelect($id){ 270 270 … … 272 272 $querystatement="SELECT id,name,percentage FROM tax WHERE inactive=0 OR id=".$id." ORDER BY name"; 273 273 $queryresult=$this->db->query($querystatement); 274 274 275 275 ?><select name="taxareaid" id="taxareaid" onchange="getPercentage()" size="5"> 276 276 <option value="0" <?php if($id==0) echo "selected=\"selected\""?>><none></option> 277 <?php 277 <?php 278 278 while($therecord = $this->db->fetchArray($queryresult)){ 279 279 ?><option value="<?php echo $therecord["id"]?>" <?php if($id==$therecord["id"]) echo "selected=\"selected\""?>><?php echo $therecord["name"].": ".$therecord["percentage"]."%"?></option><?php … … 281 281 ?> 282 282 </select><?php 283 283 284 284 }//end function 285 286 285 286 287 287 function showDiscountSelect($id){ 288 288 … … 290 290 $querystatement="SELECT id,name,type,value FROM discounts WHERE inactive!=1 ORDER BY name"; 291 291 $queryresult=$this->db->query($querystatement); 292 292 293 293 ?><select name="discountid" id="discountid" size="8"> 294 294 <option value="0" <?php if($id==0) echo 'selected="selected"'?>><none></option> 295 <?php 295 <?php 296 296 while($therecord=$this->db->fetchArray($queryresult)){ 297 297 if($therecord["type"]=="amount") … … 305 305 306 306 }//end function 307 308 307 308 309 309 function getDiscount($id){ 310 310 311 311 $therecord["name"]=""; 312 312 $therecord["value"]=0; 313 314 if(((int) $id)!=0){ 313 314 if(((int) $id)!=0){ 315 315 $querystatement="SELECT name,type,value FROM discounts WHERE id=".$id; 316 316 $queryresult=$this->db->query($querystatement); 317 317 318 318 $therecord=$this->db->fetchArray($queryresult); 319 319 if($therecord["type"]!="amount"){ … … 323 323 $therecord["name"].=": ".numberToCurrency($therecord["value"]); 324 324 } 325 325 326 326 $therecord["name"]=htmlQuotes($therecord["name"]); 327 327 328 328 return $therecord; 329 329 330 330 }//end function 331 332 331 332 333 333 function getTax($id){ 334 334 335 335 $therecord["name"]=""; 336 336 337 337 if(((int) $id)!=0){ 338 338 339 339 $querystatement="SELECT name,percentage FROM tax WHERE id=".$id; 340 340 $queryresult=$this->db->query($querystatement); 341 341 342 342 if($this->db->numRows($queryresult)) 343 343 $therecord=$this->db->fetchArray($queryresult); … … 346 346 $therecord["percentage"] = NULL; 347 347 } 348 348 349 349 $therecord["name"]= htmlQuotes($therecord["name"]); 350 350 351 351 return $therecord; 352 352 … … 355 355 356 356 function prospectToClient($clientid){ 357 357 358 358 $updatestatement = " 359 359 UPDATE … … 364 364 WHERE 365 365 id=".$clientid; 366 366 367 367 $this->db->query($updatestatement); 368 368 369 369 }//end function 370 370 371 371 // CLASS OVERRIDES ====================================================================================== 372 372 373 373 function getDefaults(){ 374 374 $therecord = parent::getDefaults(); 375 375 376 376 if(isset($_GET["cid"])) 377 377 $therecord["clientid"] = $_GET["cid"]; 378 else 378 else 379 379 $therecord["clientid"]=""; 380 380 381 381 $therecord["type"] = "Order"; 382 382 $therecord["statusid"] = $this->getDefaultStatus(); … … 393 393 $therecord["discountname"]=$discountinfo["name"]; 394 394 $therecord["discount"]=$discountinfo["value"]; 395 395 396 396 $taxinfo = $this->getTax($therecord["taxareaid"]); 397 397 $therecord["taxname"]=$taxinfo["name"]; … … 404 404 return $therecord; 405 405 } 406 407 406 407 408 408 function getRecord($id){ 409 409 410 410 $therecord = parent::getRecord($id); 411 411 412 412 $discountinfo=$this->getDiscount($therecord["discountid"]); 413 413 $therecord["discountname"]=$discountinfo["name"]; 414 414 $therecord["discount"]=$discountinfo["value"]; 415 415 416 416 $taxinfo = $this->getTax($therecord["taxareaid"]); 417 417 $therecord["taxname"]=$taxinfo["name"]; 418 418 419 419 $therecord["amountdue"] = $therecord["totalti"] - $therecord["amountpaid"]; 420 420 421 421 $querystatement = "SELECT hascredit, creditlimit FROM clients WHERE id=".$therecord["clientid"]; 422 422 $queryresult = $this->db->query($querystatement); 423 423 424 424 $therecord = array_merge($this->db->fetchArray($queryresult), $therecord); 425 425 … … 427 427 $querystatement = "SELECT SUM(`amount` - `paid`) AS amtopen FROM aritems WHERE `status` = 'open' AND clientid=".$therecord["clientid"]." AND posted=1"; 428 428 $queryresult = $this->db->query($querystatement); 429 429 430 430 $arrecord = $this->db->fetchArray($queryresult); 431 431 432 432 $therecord["creditleft"] = $therecord["creditlimit"] - $arrecord["amtopen"]; 433 433 } else 434 434 $therecord["creditleft"] =0; 435 435 436 436 return $therecord; 437 437 } 438 439 438 439 440 440 function prepareVariables($variables){ 441 441 442 442 $variables["totaltni"] = currencyToNumber($variables["totaltni"]); 443 443 $variables["discountamount"] = currencyToNumber($variables["discountamount"]); … … 446 446 $variables["shipping"] = currencyToNumber($variables["shipping"]); 447 447 $variables["tax"] = currencyToNumber($variables["tax"]); 448 $variables["amountpaid"] = currencyToNumber($variables["amountpaid"]); 449 448 $variables["amountpaid"] = currencyToNumber($variables["amountpaid"]); 449 450 450 if($variables["type"]=="Invoice" && $variables["invoicedate"] == "") 451 451 $variables["invoicedate"] = dateToString(mktime()); 452 452 453 453 if($variables["taxpercentage"]=="" or $variables["taxpercentage"]=="0" or $variables["taxpercentage"]=="0.0") 454 454 $variables["taxpercentage"]="NULL"; 455 455 456 456 $variables["taxpercentage"]=str_replace("%","",$variables["taxpercentage"]); 457 457 458 458 if($variables["type"]=="VOID"){ 459 459 $variables["totaltni"]=0; … … 461 461 $variables["amountpaid"]=0; 462 462 } 463 463 464 464 return $variables; 465 465 } 466 466 467 467 function addressUpdate($variables, $invoiceid, $modifiedby, $method){ 468 468 // Updates/Inserts address records (billing or shipping )for the sales order's corresponding client … … 472 472 $idprefix = "shipto"; 473 473 break; 474 474 475 475 case "billing": 476 476 $varprefix = ""; … … 478 478 break; 479 479 }//endswitch 480 480 481 481 switch($variables[$idprefix."saveoptions"]){ 482 482 483 483 case "updateAddress": 484 484 if($variables[$idprefix."addressid"]){ 485 485 486 486 $address = new addresses($this->db, 306); 487 487 488 488 $addressRecord = $address->getRecord($variables[$idprefix."addressid"]); 489 489 490 490 if($varprefix == "shipto") 491 491 $addressRecord["shiptoname"] = $variables["shiptoname"]; … … 496 496 $addressRecord["postalcode"] = $variables[$varprefix."postalcode"]; 497 497 $addressRecord["country"] = $variables[$varprefix."country"]; 498 498 499 499 $address->updateRecord($addressRecord, $modifiedby); 500 500 501 501 }//endif 502 502 503 503 break; 504 504 505 505 case "createAddress": 506 506 $addresstorecord = new addresstorecord($this->db,306); 507 507 508 508 if($varprefix == "shipto") 509 509 $addressRecord["shiptoname"] = $variables["shiptoname"]; … … 519 519 $atrRecord["shiptodefault"] = 0; 520 520 $atrRecord["notes"] = "Created from sales order #".$invoiceid; 521 521 522 522 $newAtrID = $addresstorecord->insertRecord($atrRecord, $modifiedby); 523 523 524 524 $atrRecord = $addresstorecord->getRecord($newAtrID); 525 525 526 526 //Need to connect the sales order to the new address record 527 527 $updatestatement = " … … 532 532 WHERE 533 533 id = ".$invoiceid; 534 534 535 535 $this->db->query($updatestatement); 536 536 537 537 break; 538 538 539 539 }//endswitch - saveoptions 540 540 541 541 }//end method - addressUpdate 542 543 542 543 544 544 function updateRecord($variables, $modifiedby = NULL){ 545 545 546 546 if($modifiedby === NULL) 547 547 $modifiedby = $_SESSION["userinfo"]["id"]; 548 549 548 549 550 550 if($variables["oldType"]=="Invoice") 551 551 return false; 552 552 553 553 $variables = $this->prepareVariables($variables); 554 554 555 555 if(!hasRights(20)){ 556 556 557 557 unset($this->fields["paymentmethodid"]); 558 558 unset($this->fields["checkno"]); … … 564 564 unset($this->fields["transactionid"]); 565 565 566 }//endif 566 }//endif 567 567 568 568 if(parent::updateRecord($variables, $modifiedby)){ 569 569 570 570 if($variables["lineitemschanged"]==1){ 571 571 572 572 $lineitems = new lineitems($this->db, $variables["id"]); 573 $lineitems->set($variables["thelineitems"], $modifiedby); 574 573 $lineitems->set($variables["thelineitems"], $modifiedby); 574 575 575 }//endif 576 576 577 577 if($variables["statuschanged"]==1) 578 $this->updateStatus($variables["id"],$variables["statusid"],$variables["statusdate"],$variables["assignedtoid"]); 579 580 // Check to see if we need to update/create the client addresses from the 578 $this->updateStatus($variables["id"],$variables["statusid"],$variables["statusdate"],$variables["assignedtoid"]); 579 580 // Check to see if we need to update/create the client addresses from the 581 581 // billing address 582 582 if($variables["billingsaveoptions"] != "orderOnly" || $variables["shiptosaveoptions"] != "orderOnly"){ 583 583 584 584 require_once("addresses.php"); 585 585 require_once("addresstorecord.php"); 586 586 587 587 $this->addressUpdate($variables, $variables["id"], $modifiedby, "billing"); 588 588 $this->addressUpdate($variables, $variables["id"], $modifiedby, "shipping"); 589 589 590 590 }//end if 591 591 592 592 }//end if 593 593 594 594 if($variables["clienttype"] == "prospect" && $variables["type"] == "Order") 595 595 $this->prospectToClient($variables["clientid"]); 596 596 597 597 //reset field after updating (if unset by rights management) 598 598 $this->getTableInfo(); 599 599 } 600 601 602 600 601 602 603 603 function insertRecord($variables, $createdby = NULL){ 604 604 605 605 if($createdby === NULL) 606 606 $createdby = $_SESSION["userinfo"]["id"]; 607 607 608 608 $variables = $this->prepareVariables($variables); 609 609 610 610 $newid = parent::insertRecord($variables, $createdby); 611 611 612 612 if($variables["billingsaveoptions"] != "orderOnly" || $variables["shiptosaveoptions"] != "orderOnly"){ 613 613 614 614 require_once("addresses.php"); 615 615 require_once("addresstorecord.php"); 616 616 617 617 $this->addressUpdate($variables, $newid, $createdby, "billing"); 618 618 $this->addressUpdate($variables, $newid, $createdby, "shipping"); 619 619 620 620 }//end if 621 621 622 622 if($variables["lineitemschanged"]==1){ 623 623 624 624 $lineitems = new lineitems($this->db, $newid); 625 625 $lineitems->set($variables["thelineitems"],$createdby); 626 626 627 627 }//end if 628 628 629 629 if($variables["statuschanged"]==1) 630 630 $this->updateStatus($newid,$variables["statusid"],$variables["statusdate"],$variables["assignedtoid"]); … … 632 632 if($variables["clienttype"] == "prospect" && $variables["type"] == "Order") 633 633 $this->prospectToClient($variables["clientid"]); 634 634 635 635 return $newid; 636 636 637 637 }//end method - insertRecord 638 638 639 639 }//end class 640 640 641 641 642 // LINE ITEMS CLASS 642 // LINE ITEMS CLASS 643 643 // ============================================================================================== 644 644 class lineitems{ 645 645 646 646 var $queryresult = NULL; 647 647 648 648 function lineitems($db, $invoiceid, $invoicetype = "Order"){ 649 649 650 650 $this->db = $db; 651 651 $this->invoiceid = ((int) $invoiceid); 652 652 $this->invoicetype = $invoicetype; 653 654 }//end method 655 656 653 654 }//end method 655 656 657 657 function get(){ 658 658 659 659 $querystatement = " 660 660 SELECT … … 666 666 lineitems.taxable, 667 667 lineitems.quantity, 668 lineitems.unitprice, 669 lineitems.unitcost, 668 lineitems.unitprice, 669 lineitems.unitcost, 670 670 lineitems.unitweight, 671 671 lineitems.memo … … 676 676 ORDER BY 677 677 lineitems.displayorder"; 678 678 679 679 $this->queryresult = $this->db->query($querystatement); 680 681 }//end method 682 683 680 681 }//end method 682 683 684 684 function show(){ 685 685 686 686 if($this->queryresult === NULL) 687 687 $this->get(); 688 688 689 689 $count = 1; 690 690 while($therecord = $this->db->fetchArray($this->queryresult)){ 691 691 692 692 ?><tr id="li<?php echo $count?>" class="lineitems"> 693 693 694 694 <td colspan="2" class="lineitemsLeft" <?php if($this->invoicetype == "Void" || $this->invoicetype == "Invoice") echo 'nowrap="nowrap"'?>> 695 695 <input type="hidden" id="li<?php echo $count?>ProductID" value="<?php echo $therecord["productid"]?>"/> … … 706 706 </div> 707 707 </td> 708 708 709 709 <td><input id="li<?php echo $count?>Memo" class="lineitemMemos" value="<?php echo formatVariable($therecord["memo"])?>"/></td> 710 710 711 711 <td><input id="li<?php echo $count?>UnitPrice" class="fieldCurrency lineitemPrices" value="<?php echo formatVariable($therecord["unitprice"], "currency")?>"/></td> 712 712 <td><input id="li<?php echo $count?>Quantity" class="lineitemQuantities" value="<?php echo formatVariable($therecord["quantity"], "real")?>"/></td> 713 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> 714 714 715 715 <td class="lineitemsButtonTDs"> 716 716 <div id="li<?php echo $count?>ButtonsDiv" class="lineitemsButtonDivs"> … … 718 718 <button type="button" id="li<?php echo $count?>ButtonMoveUp" class="graphicButtons buttonUp LIUpButtons" title="Move Item Up"><span>Up</span></button><br /> 719 719 <button type="button" id="li<?php echo $count?>ButtonMoveDown" class="graphicButtons buttonDown LIDnButtons" title="Move Item Down"><span>Dn</span></button><br /> 720 </div> 720 </div> 721 721 </td> 722 722 723 723 </tr><?php 724 724 725 725 $count++; 726 726 727 727 }//endwhile 728 729 }//end method 730 731 728 729 }//end method 730 731 732 732 function set($itemlist, $userid = NULL){ 733 733 734 734 if(!$userid) 735 735 $userid = $_SESSION["userinfo"]["id"]; 736 736 737 737 $deletestatement = " 738 738 DELETE FROM … … 740 740 WHERE 741 741 invoiceid = ".$this->invoiceid; 742 742 743 743 $this->db->query($deletestatement); 744 744 745 745 $itemsArray = explode(";;", $itemlist); 746 746 747 747 $count = 0; 748 748 749 749 foreach($itemsArray as $item){ 750 750 751 751 $itemRecord = explode("::", $item); 752 752 if(count($itemRecord) > 1){ 753 753 754 754 $insertstatement =" 755 755 INSERT INTO 756 756 lineitems( 757 invoiceid, 758 productid, 757 invoiceid, 758 productid, 759 759 memo, 760 taxable, 760 taxable, 761 761 unitweight, 762 762 unitcost, … … 772 772 ".$this->invoiceid.", 773 773 ".((int) $itemRecord[0]).", 774 '". $itemRecord[1]."',774 '".mysql_real_escape_string($itemRecord[1])."', 775 775 ".((int) $itemRecord[2]).", 776 776 ".((real) $itemRecord[3]).", … … 782 782 NOW(), 783 783 ".$userid.", 784 NOW() 784 NOW() 785 785 )"; 786 786 787 787 $this->db->query($insertstatement); 788 788 789 789 $count++; 790 790 791 791 }//end if 792 793 }//endforeach 794 795 }//end method 796 792 793 }//endforeach 794 795 }//end method 796 797 797 }//end class 798 798 799 799 }// end if 800 800 … … 804 804 805 805 function email_invoice(){ 806 806 807 807 if(DEMO_ENABLED == "true") 808 808 return "Functionality disabled in demo."; 809 809 810 810 $this->db->setEncoding("latin1"); 811 811 812 812 include("modules/bms/report/invoices_pdf_class.php"); 813 813 814 814 $processed = 0; 815 815 816 816 foreach($this->idsArray as $id){ 817 818 $report = new invoicePDF($this->db, 'P', 'in', 'Letter'); 819 817 818 $report = new invoicePDF($this->db, 'P', 'in', 'Letter'); 819 820 820 $report->generate("invoices.id = ".$id); 821 821 822 822 if($report->output("email")) 823 823 $processed++; 824 825 }//end foreach 824 825 }//end foreach 826 826 827 827 $this->db->setEncoding(); 828 829 828 829 830 830 $count = count($this->idsArray); 831 831 $message = $processed." of ".$count." invoice PDF"; … … 833 833 if($count !== 1) 834 834 $message .= "s"; 835 835 836 836 $message .= " e-mailed to client."; 837 837 838 838 return $message; 839 839 840 840 }//end method 841 841 842 842 843 843 function email_quote(){ 844 844 845 845 if(DEMO_ENABLED == "true") 846 846 return "Functionality disabled in demo."; 847 847 848 848 $this->db->setEncoding("latin1"); 849 849 850 850 $noOutput = true; 851 851 include("modules/bms/report/invoices_pdf_class.php"); 852 852 include("modules/bms/report/invoices_pdfquote.php"); 853 853 854 854 $processed = 0; 855 855 856 856 foreach($this->idsArray as $id){ 857 858 $report = new quotePDF($this->db, 'P', 'in', 'Letter'); 859 857 858 $report = new quotePDF($this->db, 'P', 'in', 'Letter'); 859 860 860 $report->generate("invoices.id = ".$id); 861 861 862 862 if($report->output("email")) 863 863 $processed++; 864 865 }//end foreach 864 865 }//end foreach 866 866 867 867 $this->db->setEncoding(); 868 869 868 869 870 870 $count = count($this->idsArray); 871 871 $message = $processed." of ".$count." quote PDF"; … … 873 873 if($count !== 1) 874 874 $message .= "s"; 875 875 876 876 $message .= " e-mailed to client."; 877 877 878 878 return $message; 879 880 }//end method 881 882 879 880 }//end method 881 882 883 883 function _mark_as_status($statusid){ 884 884 885 885 //Look up shippings defaults 886 886 $querystatement="SELECT defaultassignedtoid,setreadytopost FROM invoicestatuses WHERE id = ".$statusid; … … 889 889 if($this->db->numRows($queryresult)){ 890 890 $therecord = $this->db->fetchArray($queryresult); 891 891 892 892 if($therecord["defaultassignedtoid"]!="") 893 893 $assignedtoid = $therecord["defaultassignedtoid"]; 894 894 else 895 895 $assignedtoid="NULL"; 896 896 897 897 $readytopost = $therecord["setreadytopost"]; 898 898 } else { … … 906 906 // items must be updated individually 907 907 $querystatement = " 908 SELECT 908 SELECT 909 909 invoices.id, 910 910 paymentmethods.type, … … 914 914 WHERE 915 915 ".$whereclause; 916 916 917 917 $queryresult = $this->db->query($querystatement); 918 918 919 919 $count=0; 920 920 while($therecord = $this->db->fetchArray($queryresult)){ 921 921 922 922 $updatestatement = " 923 UPDATE 924 invoices 925 SET 926 invoices.statusdate=NOW(), 923 UPDATE 924 invoices 925 SET 926 invoices.statusdate=NOW(), 927 927 assignedtoid=".$assignedtoid.", 928 928 modifiedby=".$_SESSION["userinfo"]["id"].", "; … … 939 939 else 940 940 $updatestatement.="amountpaid = totalti,"; 941 941 942 942 }//endif 943 943 944 944 $updatestatement.=" 945 945 invoices.statusid=".$statusid.", 946 modifieddate=NOW() 947 WHERE 946 modifieddate=NOW() 947 WHERE 948 948 id =".$therecord["id"]; 949 949 950 950 $updateresult = $this->db->query($updatestatement); 951 951 952 952 //delete conlflicting history 953 953 $querystatement="DELETE FROM invoicestatushistory WHERE invoiceid=".$therecord["id"]." AND invoicestatusid=".$statusid; 954 954 $deleteresult = $this->db->query($querystatement); 955 955 956 956 //insert new history 957 957 $querystatement="INSERT INTO invoicestatushistory (invoiceid,invoicestatusid,statusdate,assignedtoid) values ("; … … 959 959 $querystatement.=$assignedtoid; 960 960 $querystatement.=")"; 961 $insertresult = $this->db->query($querystatement); 962 961 $insertresult = $this->db->query($querystatement); 962 963 963 $count++; 964 965 }//endwhile 966 964 965 }//endwhile 966 967 967 $message = $this->buildStatusMessage($count); 968 968 969 969 return $message; 970 970 971 971 }//end private method 972 972 973 973 974 974 function mark_ashipped(){ 975 975 976 976 $statusid = 4; //The default id for "shipped"; 977 977 978 978 $message = $this->_mark_as_status($statusid); 979 979 980 980 return $message." marked as shipped."; 981 982 }//end method 983 984 981 982 }//end method 983 984 985 985 function mark_rtp(){ 986 986 987 987 $whereclause=$this->buildWhereClause(); 988 988 $whereclause="(".$whereclause.") AND invoices.type='Order'"; … … 991 991 // items must be updated individually 992 992 $querystatement = " 993 SELECT 993 SELECT 994 994 invoices.id, 995 995 paymentmethods.type, … … 999 999 WHERE 1000 1000 ".$whereclause; 1001 1001 1002 1002 $queryresult = $this->db->query($querystatement); 1003 1003 1004 1004 $count=0; 1005 1005 while($therecord = $this->db->fetchArray($queryresult)){ 1006 1006 $updatestatement =" 1007 UPDATE 1008 invoices 1009 SET 1007 UPDATE 1008 invoices 1009 SET 1010 1010 modifiedby=".$_SESSION["userinfo"]["id"].", "; 1011 1011 1012 1012 if(!$therecord["invoicedate"] || $therecord["invoicedate"] == "0000-00-00") 1013 1013 $updatestatement.="invoicedate = NOW(), "; 1014 1014 1015 1015 if($therecord["type"] == "receivable") 1016 1016 $updatestatement.="amountpaid = 0, "; … … 1021 1021 readytopost=1, 1022 1022 modifieddate=NOW() 1023 WHERE 1023 WHERE 1024 1024 id =".$therecord["id"]; 1025 1025 1026 1026 $updateresult = $this->db->query($updatestatement); 1027 1027 1028 1028 $count++; 1029 1029 1030 1030 }//endwhile 1031 1031 1032 1032 $message = $this->buildStatusMessage($count); 1033 1033 return $message." marked ready to post."; 1034 1035 }//end method 1036 1034 1035 }//end method 1036 1037 1037 1038 1038 function mark_aspaid(){ 1039 1039 1040 1040 $whereclause = $this->buildWhereClause(); 1041 1041 $whereclause = trim(" 1042 1042 invoices.type='Order' 1043 AND paymentmethods.type != 'receivable' 1043 AND paymentmethods.type != 'receivable' 1044 1044 AND (".$whereclause.")"); 1045 1045 1046 1046 $querystatement =" 1047 1047 SELECT 1048 1048 invoices.id 1049 1049 FROM 1050 invoices LEFT JOIN paymentmethods ON invoices.paymentmethodid = paymentmethods.id 1050 invoices LEFT JOIN paymentmethods ON invoices.paymentmethodid = paymentmethods.id 1051 1051 WHERE 1052 1052 ".$whereclause; 1053 1053 1054 1054 $queryresult = $this->db->query($querystatement); 1055 1055 1056 1056 $count = 0; 1057 1057 while($therecord = $this->db->fetchArray($queryresult)){ 1058 1058 1059 1059 $updatestatement = " 1060 UPDATE invoices 1061 SET 1060 UPDATE invoices 1061 SET 1062 1062 invoices.amountpaid=invoices.totalti, 1063 modifiedby=\"".$_SESSION["userinfo"]["id"]."\", 1064 modifieddate=NOW() 1063 modifiedby=\"".$_SESSION["userinfo"]["id"]."\", 1064 modifieddate=NOW() 1065 1065 WHERE 1066 1066 id=".$therecord["id"]; 1067 1067 1068 1068 $this->db->query($updatestatement); 1069 1069 1070 1070 $count++; 1071 1071 1072 1072 }//endwhile 1073 1074 1073 1074 1075 1075 $message=$this->buildStatusMessage($count); 1076 1076 $message.=" paid in full."; 1077 1077 1078 1078 return $message; 1079 1080 }//end method 1081 1082 1079 1080 }//end method 1081 1082 1083 1083 function mark_asinvoice(){ 1084 1084 1085 1085 $whereclause = $this->buildWhereClause(); 1086 1086 1087 1087 include_once("include/post_class.php"); 1088 1088 defineInvoicePost(); 1089 1089 1090 1090 $invoicePost = new invoicePost($this->db); 1091 1091 1092 1092 $count = $invoicePost->post($whereclause); 1093 1093 1094 1094 $message = $this->buildStatusMessage($count); 1095 1095 $message .= " posted as invoice"; 1096 1096 1097 1097 return $message; 1098 1098 }//end method 1099 1100 1099 1100 1101 1101 function delete_record(){ 1102 1102 1103 1103 //passed variable is array of user ids to be revoked 1104 1104 $whereclause = $this->buildWhereClause(); 1105 1105 1106 1106 $querystatement = " 1107 UPDATE 1108 invoices 1109 SET 1107 UPDATE 1108 invoices 1109 SET 1110 1110 invoices.type='VOID',"; 1111 1111 1112 1112 if(CLEAR_PAYMENT_ON_INVOICE){ 1113 1113 $querystatement .=" … … 1119 1119 "; 1120 1120 }//endif 1121 1121 1122 1122 $querystatement .=" 1123 modifiedby = ".$_SESSION["userinfo"]["id"].", 1124 modifieddate = NOW() 1125 WHERE (".$whereclause.") 1123 modifiedby = ".$_SESSION["userinfo"]["id"].", 1124 modifieddate = NOW() 1125 WHERE (".$whereclause.") 1126 1126 AND invoices.type!='Invoice';"; 1127 1127 1128 1128 $queryresult = $this->db->query($querystatement); 1129 1129 1130 1130 $message = $this->buildStatusMessage(); 1131 1131 $message.=" voided."; 1132 1132 1133 1133 return $message; 1134 1134 } 1135 1135 1136 1136 }//end class 1137 1137 }//end if … … 1154 1154 1155 1155 class invoicePost extends tablePost{ 1156 1156 1157 1157 function invoicePost($db, $modifiedby = NULL){ 1158 1158 1159 1159 parent::tablePost($db, $modifiedby); 1160 1160 1161 1161 }//end method 1162 1162 1163 1163 1164 1164 function prepareWhere($whereclause=NULL){ 1165 1165 1166 1166 $this->whereclause = ""; 1167 1168 if($whereclause) 1167 1168 if($whereclause) 1169 1169 $this->whereclause = "(".$whereclause.") AND "; 1170 1170 1171 1171 $this->whereclause .= "invoices.type='Order' AND readytopost = 1"; 1172 1173 }//end method 1174 1175 1172 1173 }//end method 1174 1175 1176 1176 function post($whereclause=NULL){ 1177 1177 1178 1178 if($whereclause) 1179 1179 $this->prepareWhere($whereclause); 1180 1181 1180 1181 1182 1182 $querystatement = " 1183 1183 SELECT … … 1197 1197 ".$this->whereclause; 1198 1198 $queryresult = $this->db->query($querystatement); 1199 1199 1200 1200 $count =0; 1201 1201 while($therecord = $this->db->fetchArray($queryresult)){ … … 1208 1208 1209 1209 if(CLEAR_PAYMENT_ON_INVOICE){ 1210 1210 1211 1211 $therecord = obfuscatePayment($therecord); 1212 1212 1213 1213 if($therecord["ccnumber"]) 1214 1214 $updatestatement .= "ccnumber = '".$therecord["ccnumber"]."', "; … … 1216 1216 if($therecord["ccexpiration"]) 1217 1217 $updatestatement .= "ccexpiration = '".$therecord["ccexpiration"]."', "; 1218 1218 1219 1219 if($therecord["ccverification"]) 1220 1220 $updatestatement .= "ccverification = '".$therecord["ccverification"]."', "; … … 1225 1225 if($therecord["accountnumber"]) 1226 1226 $updatestatement .= "accountnumber = NULL, "; 1227 1227 1228 1228 }//endif - CLEAR_PAYMENT_ON_INVOICE 1229 1229 1230 1230 if(!$therecord["invoicedate"] || $therecord["invoicedate"] == "0000-00-00"){ 1231 1231 $therecord["invoicedate"] = dateToString(mktime(0,0,0),"SQL"); … … 1233 1233 $updatestatement .= " 1234 1234 `invoicedate` = NOW(), "; 1235 1235 1236 1236 }//end if 1237 1237 1238 1238 $updatestatement .= " 1239 1239 `modifiedby` = ".$this->modifiedby.", … … 1241 1241 WHERE 1242 1242 `id` = ".$therecord["id"]; 1243 1243 1244 1244 $updateresult = $this->db->query($updatestatement); 1245 1245 1246 1246 if($therecord["type"] == "receivable") { 1247 1247 // if type = AR, create AR item 1248 1248 1249 1249 $arrecord["type"] = "invoice"; 1250 1250 $arrecord["status"] = "open"; 1251 1251 $arrecord["posted"] = 1; 1252 $arrecord["amount"] = $therecord["totalti"]; 1252 $arrecord["amount"] = $therecord["totalti"]; 1253 1253 $arrecord["itemdate"] = dateToString(stringToDate($therecord["invoicedate"],"SQL") ); 1254 1254 $arrecord["clientid"] = $therecord["clientid"]; 1255 1255 $arrecord["relatedid"] = $therecord["id"]; 1256 1256 1257 1257 if(!class_exists("phpbmsTable")) 1258 1258 include("include/tables.php"); 1259 1259 1260 1260 $aritems = new phpbmsTable($this->db, 303); 1261 1261 1262 1262 $aritems->insertRecord($arrecord,$this->modifiedby); 1263 1263 1264 1264 }//endif 1265 1265 1266 1266 $count++; 1267 1267 1268 1268 }//endwhile 1269 1269 1270 1270 return $count; 1271 1272 }//end method 1273 1271 1272 }//end method 1273 1274 1274 }//end class invoicePost 1275 1275