Changeset 485 for trunk/phpbms/modules/bms/include/discounts.php
- Timestamp:
- 04/07/09 11:44:18 (3 years ago)
- Files:
-
- 1 modified
-
trunk/phpbms/modules/bms/include/discounts.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/modules/bms/include/discounts.php
r285 r485 39 39 if(class_exists("phpbmsTable")){ 40 40 class discounts extends phpbmsTable{ 41 41 42 42 function getDefaults(){ 43 43 44 44 $therecord = parent::getDefaults(); 45 45 46 46 $therecord["type"]="percent"; 47 47 48 48 return $therecord; 49 49 } 50 51 52 function formatValue($variables){ 53 50 51 52 function verifyVariables($variables){ 53 54 //table's default is fine 55 if(isset($variables["type"])){ 56 57 switch($variables["type"]){ 58 59 case "percent": 60 case "amount": 61 break; 62 63 default: 64 $this->verifyErrors[] = "The value of the `type` field is invalid. 65 It must be either 'percent' or 'amount'."; 66 break; 67 68 }//end switch 69 70 }//end if 71 72 return parent::verifyVariables($variables); 73 74 }//end method --verifyVariables-- 75 76 77 function prepareVariables($variables){ 78 54 79 if($variables["type"] == "percent") 55 80 $variables["value"] = ((real) str_replace("%","",$variables["percentvalue"])); 56 else 81 else 57 82 $variables["value"] = currencyToNumber($variables["amountvalue"]); 58 83 59 84 return $variables; 60 85 } 61 62 63 function updateRecord($variables, $modifiedby = NULL){ 64 65 $variables = $this->formatValue($variables); 66 67 parent::updateRecord($variables,$modifiedby); 68 } 69 70 71 function insertRecord($variables,$createdby = NULL){ 72 73 $variables = $this->formatValue($variables); 74 return parent::insertRecord($variables,$createdby); 75 } 76 77 86 87 78 88 function getTotals($id=0){ 79 89 80 90 $returnArray["Invoice"]["total"]=0; 81 91 $returnArray["Invoice"]["sum"]=0; 82 92 $returnArray["Order"]["total"]=0; 83 93 $returnArray["Order"]["sum"]=0; 84 94 85 95 if($id>0){ 86 96 $querystatement="SELECT invoices.type,count(invoices.id) as total,sum(discountamount) as sum 87 FROM discounts inner join invoices on discounts.id=invoices.discountid 97 FROM discounts inner join invoices on discounts.id=invoices.discountid 88 98 WHERE discounts.id=".((int) $id)." and (invoices.type=\"Order\" or invoices.type=\"Invoice\") GROUP BY invoices.type"; 89 99 $queryresult = $this->db->query($querystatement); 90 100 91 101 while($therecord=$this->db->fetchArray($queryresult)){ 92 102 $returnArray[$therecord["type"]]["total"]=$therecord["total"]; 93 103 $returnArray[$therecord["type"]]["sum"]=$therecord["sum"]; 94 104 } 95 105 96 106 } 97 107 98 108 return $returnArray; 99 109 100 110 }//end function 101 111 102 112 }//end class 103 113 }//end if