Changeset 485 for trunk/phpbms/modules/bms/include/receipts.php
- Timestamp:
- 04/07/09 11:44:18 (3 years ago)
- Files:
-
- 1 modified
-
trunk/phpbms/modules/bms/include/receipts.php (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/modules/bms/include/receipts.php
r384 r485 40 40 41 41 class receiptitems{ 42 42 43 43 function receiptitems($db){ 44 44 45 45 $this->db = $db; 46 47 }//end method 48 46 47 }//end method 48 49 49 function get($receiptid){ 50 50 … … 67 67 aritems.type, 68 68 aritems.itemdate"; 69 69 70 70 return $this->db->query($querystatement); 71 71 72 72 }//end function 73 74 73 74 75 75 function show($queryresult, $receiptPosted, $receiptid){ 76 76 77 77 $count = 1; 78 78 79 79 while($therecord = $this->db->fetchArray($queryresult)){ 80 80 81 81 $recID = "i".$count; 82 82 83 83 if($therecord["type"] == "invoice"){ 84 84 85 85 $tempDate = stringToDate($therecord["itemdate"], "SQL"); 86 86 $dueDate = dateToString( strtotime(TERM1_DAYS." days", $tempDate) ); 87 88 } else 87 88 } else 89 89 $dueDate = " "; 90 90 91 91 if($therecord["type"] == "deposit" && $therecord["relatedid"] == $receiptid){ 92 92 $therecord["relatedid"] = ""; … … 94 94 $therecord["aritemid"] = 0; 95 95 } 96 97 if($receiptPosted) 98 $docDue = $therecord["amount"] - $therecord["paid"]; 96 97 if($receiptPosted) 98 $docDue = $therecord["amount"] - $therecord["paid"]; 99 99 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"]; 101 101 else 102 102 $docDue = 0; 103 104 103 104 105 105 ?> 106 106 … … 122 122 <td><input id="<?php echo $recID?>TaxAdj" class="currency" value="<?php echo formatVariable($therecord["taxadjustment"], "currency")?>" size="10" maxlength="12"/></td> 123 123 <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 126 126 <?php 127 127 128 128 $count++; 129 129 }//endwhile 130 131 132 }//end method 133 134 130 131 132 }//end method 133 134 135 135 function set($itemlist, $receiptid, $clientid, $userid){ 136 136 137 137 //remove any exisiting items 138 138 $deletestatement = "DELETE FROM receiptitems WHERE receiptid =".((int) $receiptid); 139 139 $this->db->query($deletestatement); 140 140 141 141 //remove any ar deposits created by ths receipt 142 142 $deletestatement = "DELETE FROM aritems WHERE relatedid = ".((int) $receiptid)." AND `type` = 'deposit'"; … … 146 146 147 147 foreach($itemsArray as $item){ 148 148 149 149 $itemRecord = explode("::", $item); 150 150 151 151 if(count($itemRecord) > 1){ 152 152 153 153 //if no ar id, or the deposit is from this record, we need to create the ar item 154 154 if(!$itemRecord[0] || ($itemRecord[1] == $receiptid && $itemRecord[2] == "deposit") ){ 155 155 156 156 $arrecord = array(); 157 157 $arrecord["type"] = "deposit"; 158 158 $arrecord["status"] = "open"; 159 159 $arrecord["posted"] = 0; 160 $arrecord["amount"] = -1 * currencyToNumber($itemRecord[8]); 160 $arrecord["amount"] = -1 * currencyToNumber($itemRecord[8]); 161 161 $arrecord["itemdate"] = $itemRecord[3]; 162 162 $arrecord["clientid"] = $clientid; 163 163 $arrecord["relatedid"] = $receiptid; 164 165 164 165 166 166 if(!isset($aritems)) 167 167 $aritems = new phpbmsTable($this->db, 303); 168 168 169 169 $aritems->insertRecord($arrecord, $userid); 170 170 171 171 $itemRecord[0] = $this->db->insertId(); 172 172 173 173 }//end if 174 174 175 175 $insertstatement =" 176 176 INSERT INTO … … 184 184 ".currencyToNumber($itemRecord[10])." 185 185 )"; 186 186 187 187 $this->db->query($insertstatement); 188 188 189 189 }//endif 190 190 191 191 }//endforeach 192 193 }//end method 194 192 193 }//end method 194 195 195 }// end class 196 196 … … 199 199 //====================================================================== 200 200 class receipts extends phpbmsTable{ 201 201 202 var $availableClientIDs = array(); 203 var $availablePaymentMethodIDs = array(); 202 204 203 205 function showPaymentOptions($selectedid){ 204 206 205 207 global $phpbms; 206 208 207 209 $querystatement = " 208 210 SELECT … … 221 223 priority, 222 224 name"; 223 225 224 226 $queryresult = $this->db->query($querystatement); 225 227 226 228 ?> 227 229 <label for="paymentmethodid">payment type</label><br /> 228 230 <select id="paymentmethodid" name="paymentmethodid"> 229 <?php 231 <?php 230 232 $phpbms->bottomJS[] = 'paymentTypes = Array()'; 231 233 $phpbms->bottomJS[] = 'paymentTypes["s-1"] = Array();'; … … 233 235 $phpbms->bottomJS[] = 'paymentTypes["s-1"]["onlineprocess"] = 0'; 234 236 $phpbms->bottomJS[] = 'paymentTypes["s-1"]["onlineprocess"] = null'; 235 237 236 238 while($therecord = $this->db->fetchArray($queryresult)){ 237 239 … … 240 242 $phpbms->bottomJS[] = 'paymentTypes["s'.$therecord["id"].'"]["onlineprocess"] = "'.$therecord["onlineprocess"].'";'; 241 243 $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 244 246 echo "\n"; 245 247 246 248 }//endwhile 247 249 248 250 ?> 249 251 <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 255 257 // CLASS OVERRIDES ====================================================================================== 256 258 257 259 function getDefaults(){ 258 260 $therecord = parent::getDefaults(); 259 261 260 262 $therecord["clientid"] = ""; 261 263 $therecord["status"] = "open"; 262 264 $therecord["receiptdate"] = dateToString(mktime(),"SQL"); 263 265 264 266 return $therecord; 265 267 } 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 268 379 function prepareVariables($variables){ 269 380 270 381 $variables["amount"] = currencyToNumber($variables["amount"]); 271 382 272 383 return $variables; 273 384 } 274 275 385 386 276 387 function updateRecord($variables, $modifiedby = NULL){ 277 278 if($modifiedby === NULL) 279 $modifiedby = $_SESSION["userinfo"]["id"]; 280 281 $variables = $this->prepareVariables($variables); 282 388 283 389 if(parent::updateRecord($variables, $modifiedby)){ 284 390 285 391 if($variables["itemschanged"]==1){ 286 392 287 393 $items = new receiptitems($this->db); 288 394 289 395 $items->set($variables["itemslist"], $variables["id"], $variables["clientid"], $modifiedby); 290 396 291 397 }//end if 292 398 293 399 }//end if 294 400 295 401 }//end method 296 297 298 402 403 404 299 405 function insertRecord($variables, $createdby = NULL){ 300 301 if($createdby === NULL) 302 $createdby = $_SESSION["userinfo"]["id"]; 303 304 $variables = $this->prepareVariables($variables); 305 406 306 407 $newid = parent::insertRecord($variables, $createdby); 307 408 308 409 if($variables["itemschanged"]==1){ 309 410 310 411 $items = new receiptitems($this->db); 311 412 312 413 $items->set($variables["itemslist"], $newid, $variables["clientid"], $createdby); 313 414 314 415 }//end if 315 416 316 417 return $newid; 317 418 } … … 322 423 if(class_exists("searchFunctions")){ 323 424 class receiptsSearchFunctions extends searchFunctions{ 324 425 325 426 function post(){ 326 427 327 428 $whereclause = $this->buildWhereClause(); 328 429 329 430 include_once("include/post_class.php"); 330 431 defineReceiptPost(); 331 432 332 433 $receiptPost = new receiptPost($this->db); 333 434 334 435 $count = $receiptPost->post($whereclause); 335 436 336 437 $message = $this->buildStatusMessage($count); 337 438 $message .= " posted."; 338 439 339 440 return $message; 340 441 }//end method 341 342 442 443 343 444 function delete_record(){ 344 445 345 446 //passed variable is array of user ids to be revoked 346 447 $whereclause = $this->buildWhereClause(); 347 448 348 449 $querystatement =" 349 SELECT 450 SELECT 350 451 id 351 452 FROM … … 357 458 358 459 $queryresult = $this->db->query($querystatement); 359 460 360 461 $count = $this->db->numRows($queryresult); 361 462 362 463 $newWhere = ""; 363 464 while($therecord = $this->db->fetchArray($queryresult)) 364 465 $newWhere .= " OR id = ".$therecord["id"]; 365 466 366 467 if(strlen($newWhere)) 367 468 $newWhere = substr($newWhere, 4); 368 469 else 369 470 $newWhere = "id = -1974"; 370 471 371 472 $deletestatement = " 372 473 DELETE FROM … … 375 476 `type` = 'deposit' 376 477 AND (".str_replace("id =", "relatedid =", $newWhere).")"; 377 478 378 479 $this->db->query($deletestatement); 379 480 380 481 $deletestatement = " 381 482 DELETE FROM … … 383 484 WHERE 384 485 ".str_replace("id =", "receiptid =", $newWhere); 385 486 386 487 $this->db->query($deletestatement); 387 488 … … 391 492 WHERE 392 493 ".$newWhere; 393 394 $this->db->query($deletestatement); 395 494 495 $this->db->query($deletestatement); 496 396 497 $message = $this->buildStatusMessage($count); 397 498 $message.=" deleted."; 398 499 399 500 return $message; 400 501 }//end method 401 402 502 503 403 504 function _getFullyDistributed(){ 404 505 405 506 $whereclause = $this->buildWhereClause(); 406 507 407 508 $querystatement = " 408 509 SELECT … … 420 521 $count = 0; 421 522 while($therecord = $this->db->fetchArray($queryresult)){ 422 523 423 524 $querystatement = " 424 525 SELECT … … 432 533 433 534 $checkrecord = $this->db->fetchArray($checkresult); 434 535 435 536 if($therecord["amount"] == $checkrecord["thesum"]){ 436 537 $newWhere .= " OR id = ".$therecord["id"]; 437 538 $count++; 438 539 439 540 }//endif 440 541 441 542 }//endif 442 543 … … 445 546 else 446 547 $newWhere = "id = -1974"; 447 548 448 549 return array("clause" => $newWhere, "count" => $count); 449 450 }//end method 451 452 550 551 }//end method 552 553 453 554 function mark_rtp(){ 454 555 455 556 $where = $this->_getFullyDistributed(); 456 557 457 558 $updatestatement=" 458 559 UPDATE … … 462 563 readytopost = 1, 463 564 modifiedby = ".$_SESSION["userinfo"]["id"].", 464 modifieddate = NOW() 565 modifieddate = NOW() 465 566 WHERE 466 567 ".$where["clause"]; 467 568 468 569 $this->db->query($updatestatement); 469 570 470 571 $message = $this->buildStatusMessage($where["count"]); 471 572 $message.=" marked ready to post."; 472 573 473 574 return $message; 474 575 }//end method 475 476 576 577 477 578 function mark_collected(){ 478 579 479 580 $where = $this->_getFullyDistributed(); 480 581 481 582 $updatestatement=" 482 583 UPDATE … … 488 589 WHERE 489 590 ".$where["clause"]; 490 591 491 592 $this->db->query($updatestatement); 492 593 493 594 $message = $this->buildStatusMessage($where["count"]); 494 595 $message.=" marked collected."; 495 596 496 597 return $message; 497 598 }//end method 498 599 499 600 }//end class 500 601 }//end if … … 504 605 505 606 class receiptPost extends tablePost{ 506 607 507 608 function receiptPost($db, $modifiedby = NULL){ 508 609 509 610 parent::tablePost($db, $modifiedby); 510 611 511 612 }//end method 512 613 513 614 514 615 function prepareWhere($whereclause=NULL){ 515 616 516 617 $this->whereclause = ""; 517 518 if($whereclause) 618 619 if($whereclause) 519 620 $this->whereclause = "(".$whereclause.") AND "; 520 621 521 622 $this->whereclause .= "receipts.posted = 0 AND receipts.readytopost = 1"; 522 523 }//end method 524 525 623 624 }//end method 625 626 526 627 function post($whereclause=NULL){ 527 628 528 629 if($whereclause) 529 630 $this->prepareWhere($whereclause); 530 631 531 632 532 633 $querystatement = " … … 537 638 WHERE 538 639 ".$this->whereclause; 539 640 540 641 $queryresult = $this->db->query($querystatement); 541 642 542 643 $count = $this->db->numRows($queryresult); 543 644 $newWhere = ""; 544 645 while($therecord = $this->db->fetchArray($queryresult)){ 545 646 546 647 $querystatement = " 547 648 SELECT … … 559 660 WHERE 560 661 receiptitems.receiptid = ".$therecord["id"]; 561 662 562 663 $itemsresult = $this->db->query($querystatement); 563 664 564 665 while($itemrecord = $this->db->fetchArray($itemsresult)){ 565 666 566 667 if($itemrecord["relatedid"] == $therecord["id"] && $itemrecord["type"] == "deposit") 567 668 $paid = $itemrecord["paid"]; … … 573 674 else 574 675 $status = "open"; 575 676 576 677 $updatestatement =" 577 678 UPDATE … … 582 683 `status` = '".$status."', 583 684 modifiedby = ".$_SESSION["userinfo"]["id"].", 584 modifieddate = NOW() 685 modifieddate = NOW() 585 686 WHERE 586 687 id = ".$itemrecord["aritemid"]; 587 688 588 689 $this->db->query($updatestatement); 589 690 590 691 if($itemrecord["type"] == "invoice"){ 591 692 592 693 $updatestatement = " 593 UPDATE 694 UPDATE 594 695 invoices 595 696 SET … … 601 702 602 703 $this->db->query($updatestatement); 603 704 604 705 }//endif 605 706 606 707 }//endwhile 607 708 … … 611 712 if(strlen($newWhere)) 612 713 $newWhere = substr($newWhere, 4); 613 714 614 715 if($newWhere){ 615 716 616 717 $updatestatement = " 617 718 UPDATE … … 628 729 ccnumber = LPAD(SUBSTRING(ccnumber,-4),LENGTH(ccnumber),'*'), 629 730 "; 630 }//endif 631 731 }//endif 732 632 733 $updatestatement .=" 633 734 modifiedby = ".$_SESSION["userinfo"]["id"].", … … 635 736 WHERE 636 737 ".$newWhere; 637 738 638 739 $this->db->query($updatestatement); 639 740 640 741 641 742 }//endif 642 743 643 744 return $count; 644 645 }//end method 646 745 746 }//end method 747 647 748 }//end class invoicePost 648 749