[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 * 10 ********************************************************************************/ 11 12 /** 13 * This function returns the Product detail block values in array format. 14 * Input Parameter are $module - module name, $focus - module object, $num_of_products - no.of vtiger_products associated with it * $associated_prod = associated product details 15 * column vtiger_fields/ 16 */ 17 18 function getProductDetailsBlockInfo($mode,$module,$focus='',$num_of_products='',$associated_prod='') 19 { 20 global $log; 21 $log->debug("Entering getProductDetailsBlockInfo(".$mode.",".$module.",".$focus.",".$num_of_products.",".$associated_prod.") method ..."); 22 23 $productDetails = Array(); 24 $productBlock = Array(); 25 if($num_of_products=='') 26 { 27 $num_of_products = getNoOfAssocProducts($module,$focus); 28 } 29 $productDetails['no_products'] = $num_of_products; 30 if($associated_prod=='') 31 { 32 $productDetails['product_details'] = getAssociatedProducts($module,$focus); 33 } 34 else 35 { 36 $productDetails['product_details'] = $associated_prod; 37 } 38 if($focus != '') 39 { 40 $productBlock[] = Array('mode'=>$focus->mode); 41 $productBlock[] = $productDetails['product_details']; 42 $productBlock[] = Array('taxvalue' => $focus->column_fields['txtTax']); 43 $productBlock[] = Array('taxAdjustment' => $focus->column_fields['txtAdjustment']); 44 $productBlock[] = Array('hdnSubTotal' => $focus->column_fields['hdnSubTotal']); 45 $productBlock[] = Array('hdnGrandTotal' => $focus->column_fields['hdnGrandTotal']); 46 } 47 else 48 { 49 $productBlock[] = Array(Array()); 50 51 } 52 $log->debug("Exiting getProductDetailsBlockInfo method ..."); 53 return $productBlock; 54 } 55 56 /** 57 * This function updates the stock information once the product is ordered. 58 * Param $productid - product id 59 * Param $qty - product quantity in no's 60 * Param $mode - mode type 61 * Param $ext_prod_arr - existing vtiger_products 62 * Param $module - module name 63 * return type void 64 */ 65 66 function updateStk($product_id,$qty,$mode,$ext_prod_arr,$module) 67 { 68 global $log; 69 $log->debug("Entering updateStk(".$product_id.",".$qty.",".$mode.",".$ext_prod_arr.",".$module.") method ..."); 70 global $adb; 71 global $current_user; 72 73 $log->debug("Inside updateStk function, module=".$module); 74 $log->debug("Product Id = $product_id & Qty = $qty"); 75 76 $prod_name = getProductName($product_id); 77 $qtyinstk= getPrdQtyInStck($product_id); 78 $log->debug("Prd Qty in Stock ".$qtyinstk); 79 80 if($mode == 'edit') 81 { 82 if(array_key_exists($product_id,$ext_prod_arr)) 83 { 84 $old_qty = $ext_prod_arr[$product_id]; 85 if($old_qty > $qty) 86 { 87 $diff_qty = $old_qty - $qty; 88 $upd_qty = $qtyinstk+$diff_qty; 89 if($module == 'Invoice') 90 { 91 updateProductQty($product_id, $upd_qty); 92 sendPrdStckMail($product_id,$upd_qty,$prod_name,'','',$module); 93 } 94 else 95 sendPrdStckMail($product_id,$upd_qty,$prod_name,$qtyinstk,$qty,$module); 96 } 97 elseif($old_qty < $qty) 98 { 99 $diff_qty = $qty - $old_qty; 100 $upd_qty = $qtyinstk-$diff_qty; 101 if($module == 'Invoice') 102 { 103 updateProductQty($product_id, $upd_qty); 104 sendPrdStckMail($product_id,$upd_qty,$prod_name,'','',$module); 105 } 106 else 107 sendPrdStckMail($product_id,$upd_qty,$prod_name,$qtyinstk,$qty,$module); 108 } 109 } 110 else 111 { 112 $upd_qty = $qtyinstk-$qty; 113 if($module == 'Invoice') 114 { 115 updateProductQty($product_id, $upd_qty); 116 sendPrdStckMail($product_id,$upd_qty,$prod_name,'','',$module); 117 } 118 else 119 sendPrdStckMail($product_id,$upd_qty,$prod_name,$qtyinstk,$qty,$module); 120 } 121 } 122 else 123 { 124 $upd_qty = $qtyinstk-$qty; 125 if($module == 'Invoice') 126 { 127 updateProductQty($product_id, $upd_qty); 128 sendPrdStckMail($product_id,$upd_qty,$prod_name,'','',$module); 129 } 130 else 131 sendPrdStckMail($product_id,$upd_qty,$prod_name,$qtyinstk,$qty,$module); 132 } 133 $log->debug("Exiting updateStk method ..."); 134 } 135 136 /** 137 * This function sends a mail to the handler whenever the product reaches the reorder level. 138 * Param $product_id - product id 139 * Param $upd_qty - updated product quantity in no's 140 * Param $prod_name - product name 141 * Param $qtyinstk - quantity in stock 142 * Param $qty - quantity 143 * Param $module - module name 144 * return type void 145 */ 146 147 function sendPrdStckMail($product_id,$upd_qty,$prod_name,$qtyinstk,$qty,$module) 148 { 149 global $log; 150 $log->debug("Entering sendPrdStckMail(".$product_id.",".$upd_qty.",".$prod_name.",".$qtyinstk.",".$qty.",".$module.") method ..."); 151 global $current_user; 152 global $adb; 153 $reorderlevel = getPrdReOrderLevel($product_id); 154 $log->debug("Inside sendPrdStckMail function, module=".$module); 155 $log->debug("Prd reorder level ".$reorderlevel); 156 if($upd_qty < $reorderlevel) 157 { 158 //send mail to the handler 159 $handler=getPrdHandler($product_id); 160 $handler_name = getUserName($handler); 161 $to_address= getUserEmail($handler); 162 163 //Get the email details from database; 164 if($module == 'SalesOrder') 165 { 166 $notification_table = 'SalesOrderNotification'; 167 $quan_name = '{SOQUANTITY}'; 168 } 169 if($module == 'Quotes') 170 { 171 $notification_table = 'QuoteNotification'; 172 $quan_name = '{QUOTEQUANTITY}'; 173 } 174 if($module == 'Invoice') 175 { 176 $notification_table = 'InvoiceNotification'; 177 } 178 $query = "select * from vtiger_inventorynotification where notificationname='".$notification_table."'"; 179 $result = $adb->query($query); 180 181 $subject = $adb->query_result($result,0,'notificationsubject'); 182 $body = $adb->query_result($result,0,'notificationbody'); 183 184 $subject = str_replace('{PRODUCTNAME}',$prod_name,$subject); 185 $body = str_replace('{HANDLER}',$handler_name,$body); 186 $body = str_replace('{PRODUCTNAME}',$prod_name,$body); 187 if($module == 'Invoice') 188 { 189 $body = str_replace('{CURRENTSTOCK}',$upd_qty,$body); 190 $body = str_replace('{REORDERLEVELVALUE}',$reorderlevel,$body); 191 } 192 else 193 { 194 $body = str_replace('{CURRENTSTOCK}',$qtyinstk,$body); 195 $body = str_replace($quan_name,$qty,$body); 196 } 197 $body = str_replace('{CURRENTUSER}',$current_user->user_name,$body); 198 199 $mail_status = send_mail($module,$to_address,$current_user->user_name,$current_user->email1,$subject,$body); 200 } 201 $log->debug("Exiting sendPrdStckMail method ..."); 202 } 203 204 /**This function is used to get the quantity in stock of a given product 205 *Param $product_id - product id 206 *Returns type numeric 207 */ 208 function getPrdQtyInStck($product_id) 209 { 210 global $log; 211 $log->debug("Entering getPrdQtyInStck(".$product_id.") method ..."); 212 global $adb; 213 $query1 = "SELECT qtyinstock FROM vtiger_products WHERE productid = ".$product_id; 214 $result=$adb->query($query1); 215 $qtyinstck= $adb->query_result($result,0,"qtyinstock"); 216 $log->debug("Exiting getPrdQtyInStck method ..."); 217 return $qtyinstck; 218 } 219 220 /**This function is used to get the reorder level of a product 221 *Param $product_id - product id 222 *Returns type numeric 223 */ 224 225 function getPrdReOrderLevel($product_id) 226 { 227 global $log; 228 $log->debug("Entering getPrdReOrderLevel(".$product_id.") method ..."); 229 global $adb; 230 $query1 = "SELECT reorderlevel FROM vtiger_products WHERE productid = ".$product_id; 231 $result=$adb->query($query1); 232 $reorderlevel= $adb->query_result($result,0,"reorderlevel"); 233 $log->debug("Exiting getPrdReOrderLevel method ..."); 234 return $reorderlevel; 235 } 236 237 /**This function is used to get the handler for a given product 238 *Param $product_id - product id 239 *Returns type numeric 240 */ 241 242 function getPrdHandler($product_id) 243 { 244 global $log; 245 $log->debug("Entering getPrdHandler(".$product_id.") method ..."); 246 global $adb; 247 $query1 = "SELECT handler FROM vtiger_products WHERE productid = ".$product_id; 248 $result=$adb->query($query1); 249 $handler= $adb->query_result($result,0,"handler"); 250 $log->debug("Exiting getPrdHandler method ..."); 251 return $handler; 252 } 253 254 /** function to get the taxid 255 * @param string $type - tax type (VAT or Sales or Service) 256 * return int $taxid - taxid corresponding to the Tax type from vtiger_inventorytaxinfo vtiger_table 257 */ 258 function getTaxId($type) 259 { 260 global $adb, $log; 261 $log->debug("Entering into getTaxId($type) function."); 262 263 $res = $adb->query("SELECT taxid FROM vtiger_inventorytaxinfo WHERE taxname='$type'"); 264 $taxid = $adb->query_result($res,0,'taxid'); 265 266 $log->debug("Exiting from getTaxId($type) function. return value=$taxid"); 267 return $taxid; 268 } 269 270 /** function to get the taxpercentage 271 * @param string $type - tax type (VAT or Sales or Service) 272 * return int $taxpercentage - taxpercentage corresponding to the Tax type from vtiger_inventorytaxinfo vtiger_table 273 */ 274 function getTaxPercentage($type) 275 { 276 global $adb, $log; 277 $log->debug("Entering into getTaxPercentage($type) function."); 278 279 $taxpercentage = ''; 280 281 $res = $adb->query("SELECT percentage FROM vtiger_inventorytaxinfo WHERE taxname = '$type'"); 282 $taxpercentage = $adb->query_result($res,0,'percentage'); 283 284 $log->debug("Exiting from getTaxPercentage($type) function. return value=$taxpercentage"); 285 return $taxpercentage; 286 } 287 288 /** function to get the product's taxpercentage 289 * @param string $type - tax type (VAT or Sales or Service) 290 * @param id $productid - productid to which we want the tax percentage 291 * @param id $default - if 'default' then first look for product's tax percentage and product's tax is empty then it will return the default configured tax percentage, else it will return the product's tax (not look for default value) 292 * return int $taxpercentage - taxpercentage corresponding to the Tax type from vtiger_inventorytaxinfo vtiger_table 293 */ 294 function getProductTaxPercentage($type,$productid,$default='') 295 { 296 global $adb, $log; 297 $log->debug("Entering into getProductTaxPercentage($type,$productid) function."); 298 299 $taxpercentage = ''; 300 301 $res = $adb->query("SELECT taxpercentage 302 FROM vtiger_inventorytaxinfo 303 INNER JOIN vtiger_producttaxrel 304 ON vtiger_inventorytaxinfo.taxid = vtiger_producttaxrel.taxid 305 WHERE vtiger_producttaxrel.productid = $productid 306 AND vtiger_inventorytaxinfo.taxname = '$type'"); 307 $taxpercentage = $adb->query_result($res,0,'taxpercentage'); 308 309 //This is to retrive the default configured value if the taxpercentage related to product is empty 310 if($taxpercentage == '' && $default == 'default') 311 $taxpercentage = getTaxPercentage($type); 312 313 314 $log->debug("Exiting from getProductTaxPercentage($productid,$type) function. return value=$taxpercentage"); 315 return $taxpercentage; 316 } 317 318 /** Function used to add the history entry in the relevant tables for PO, SO, Quotes and Invoice modules 319 * @param string $module - current module name 320 * @param int $id - entity id 321 * @param string $relatedname - parent name of the entity ie, required field venor name for PO and account name for SO, Quotes and Invoice 322 * @param float $total - grand total value of the product details included tax 323 * @param string $history_fldval - history field value ie., quotestage for Quotes and status for PO, SO and Invoice 324 */ 325 function addInventoryHistory($module, $id, $relatedname, $total, $history_fldval) 326 { 327 global $log, $adb; 328 $log->debug("Entering into function addInventoryHistory($module, $id, $relatedname, $total, $history_fieldvalue)"); 329 330 $history_table_array = Array( 331 "PurchaseOrder"=>"vtiger_postatushistory", 332 "SalesOrder"=>"vtiger_sostatushistory", 333 "Quotes"=>"vtiger_quotestagehistory", 334 "Invoice"=>"vtiger_invoicestatushistory" 335 ); 336 337 $histid = $adb->getUniqueID($history_table_array[$module]); 338 $modifiedtime = $adb->formatDate(date('YmdHis')); 339 $query = "insert into $history_table_array[$module] values($histid,$id,'$relatedname','$total','$history_fldval',$modifiedtime)"; 340 $adb->query($query); 341 342 $log->debug("Exit from function addInventoryHistory"); 343 } 344 345 /** Function used to get the list of Tax types as a array 346 * @param string $available - available or empty where as default is all, if available then the taxes which are available now will be returned otherwise all taxes will be returned 347 * @param string $sh - sh or empty, if sh passed then the shipping and handling related taxes will be returned 348 * return array $taxtypes - return all the tax types as a array 349 */ 350 function getAllTaxes($available='all', $sh='') 351 { 352 global $adb, $log; 353 $log->debug("Entering into the function getAllTaxes($sh)"); 354 $taxtypes = Array(); 355 if($sh != '' && $sh == 'sh') 356 $tablename = 'vtiger_shippingtaxinfo'; 357 else 358 $tablename = 'vtiger_inventorytaxinfo'; 359 360 //This where condition is added to get all products or only availble products 361 if($available != 'all' && $available == 'available') 362 { 363 $where = " where $tablename.deleted=0"; 364 } 365 366 $res = $adb->query("select * from $tablename $where order by deleted"); 367 $noofrows = $adb->num_rows($res); 368 for($i=0;$i<$noofrows;$i++) 369 { 370 $taxtypes[$i]['taxid'] = $adb->query_result($res,$i,'taxid'); 371 $taxtypes[$i]['taxname'] = $adb->query_result($res,$i,'taxname'); 372 $taxtypes[$i]['taxlabel'] = $adb->query_result($res,$i,'taxlabel'); 373 $taxtypes[$i]['percentage'] = $adb->query_result($res,$i,'percentage'); 374 $taxtypes[$i]['deleted'] = $adb->query_result($res,$i,'deleted'); 375 } 376 $log->debug("Exit from the function getAllTaxes($sh)"); 377 378 return $taxtypes; 379 } 380 381 /** Function used to get all the tax details which are associated to the given product 382 * @param int $productid - product id to which we want to get all the associated taxes 383 * @param string $available - available or empty or available_associated where as default is all, if available then the taxes which are available now will be returned, if all then all taxes will be returned otherwise if the value is available_associated then all the associated taxes even they are not available and all the available taxes will be retruned 384 * @return array $tax_details - tax details as a array with productid, taxid, taxname, percentage and deleted 385 */ 386 function getTaxDetailsForProduct($productid, $available='all') 387 { 388 global $log, $adb; 389 $log->debug("Entering into function getTaxDetailsForProduct($productid)"); 390 if($productid != '') 391 { 392 //where condition added to avoid to retrieve the non available taxes 393 $where = ''; 394 if($available != 'all' && $available == 'available') 395 { 396 $where = ' and vtiger_inventorytaxinfo.deleted=0'; 397 } 398 if($available != 'all' && $available == 'available_associated') 399 { 400 $query = "SELECT vtiger_producttaxrel.*, vtiger_inventorytaxinfo.* FROM vtiger_inventorytaxinfo left JOIN vtiger_producttaxrel ON vtiger_inventorytaxinfo.taxid = vtiger_producttaxrel.taxid WHERE vtiger_producttaxrel.productid = $productid or vtiger_inventorytaxinfo.deleted=0 GROUP BY vtiger_inventorytaxinfo.taxid"; 401 } 402 else 403 { 404 $query = "SELECT vtiger_producttaxrel.*, vtiger_inventorytaxinfo.* FROM vtiger_inventorytaxinfo INNER JOIN vtiger_producttaxrel ON vtiger_inventorytaxinfo.taxid = vtiger_producttaxrel.taxid WHERE vtiger_producttaxrel.productid = $productid $where"; 405 } 406 407 //Postgres 8 fixes 408 if( $adb->dbType == "pgsql") 409 $query = fixPostgresQuery( $query, $log, 0); 410 411 $res = $adb->query($query); 412 for($i=0;$i<$adb->num_rows($res);$i++) 413 { 414 $tax_details[$i]['productid'] = $adb->query_result($res,$i,'productid'); 415 $tax_details[$i]['taxid'] = $adb->query_result($res,$i,'taxid'); 416 $tax_details[$i]['taxname'] = $adb->query_result($res,$i,'taxname'); 417 $tax_details[$i]['taxlabel'] = $adb->query_result($res,$i,'taxlabel'); 418 $tax_details[$i]['percentage'] = $adb->query_result($res,$i,'taxpercentage'); 419 $tax_details[$i]['deleted'] = $adb->query_result($res,$i,'deleted'); 420 } 421 } 422 else 423 { 424 $log->debug("Product id is empty. we cannot retrieve the associated products."); 425 } 426 427 $log->debug("Exit from function getTaxDetailsForProduct($productid)"); 428 return $tax_details; 429 } 430 431 /** Function used to delete the Inventory product details for the passed entity 432 * @param int $objectid - entity id to which we want to delete the product details from REQUEST values where as the entity will be Purchase Order, Sales Order, Quotes or Invoice 433 * @param string $return_old_values - string which contains the string return_old_values or may be empty, if the string is return_old_values then before delete old values will be retrieved 434 * @return array $ext_prod_arr - if the second input parameter is 'return_old_values' then the array which contains the productid and quantity which will be retrieved before delete the product details will be returned otherwise return empty 435 */ 436 function deleteInventoryProductDetails($objectid, $return_old_values='') 437 { 438 global $log, $adb; 439 $log->debug("Entering into function deleteInventoryProductDetails($objectid, $return_old_values='')."); 440 441 $ext_prod_arr = Array(); 442 443 if($return_old_values == 'return_old_values') 444 { 445 $query1 = "select * from vtiger_inventoryproductrel where id=".$objectid; 446 $result1 = $adb->query($query1); 447 $num_rows = $adb->num_rows($result1); 448 for($i=0; $i<$num_rows;$i++) 449 { 450 $pro_id = $adb->query_result($result1,$i,"productid"); 451 $pro_qty = $adb->query_result($result1,$i,"quantity"); 452 $ext_prod_arr[$pro_id] = $pro_qty; 453 } 454 } 455 456 $query2 = "delete from vtiger_inventoryproductrel where id=".$objectid; 457 $adb->query($query2); 458 459 $query3 = "delete from vtiger_inventoryshippingrel where id=".$objectid; 460 $adb->query($query3); 461 462 $log->debug("Exit from function deleteInventoryProductDetails($objectid, $return_old_values='')."); 463 return $ext_prod_arr; 464 } 465 466 /** Function used to save the Inventory product details for the passed entity 467 * @param object reference $focus - object reference to which we want to save the product details from REQUEST values where as the entity will be Purchase Order, Sales Order, Quotes or Invoice 468 * @param string $module - module name 469 * @param $update_prod_stock - true or false (default), if true we have to update the stock for PO only 470 * @return void 471 */ 472 function saveInventoryProductDetails($focus, $module, $update_prod_stock='false', $updateDemand='') 473 { 474 global $log, $adb; 475 $log->debug("Entering into function saveInventoryProductDetails($focus, $module)."); 476 477 $ext_prod_arr = Array(); 478 if($focus->mode == 'edit') 479 { 480 $return_old_values = ''; 481 if($module != 'PurchaseOrder') 482 { 483 $return_old_values = 'return_old_values'; 484 } 485 486 //we will retrieve the existing product details and store it in a array and then delete all the existing product details and save new values, retrieve the old value and update stock only for SO, Quotes and Invoice not for PO 487 $ext_prod_arr = deleteInventoryProductDetails($focus->id,$return_old_values); 488 } 489 490 $tot_no_prod = $_REQUEST['totalProductCount']; 491 492 //If the taxtype is group then retrieve all available taxes, else retrive associated taxes for each product inside loop 493 if($_REQUEST['taxtype'] == 'group') 494 $all_available_taxes = getAllTaxes('available'); 495 496 $prod_seq=1; 497 for($i=1; $i<=$tot_no_prod; $i++) 498 { 499 $prod_id = $_REQUEST['hdnProductId'.$i]; 500 $qty = $_REQUEST['qty'.$i]; 501 $listprice = $_REQUEST['listPrice'.$i]; 502 $listprice = getConvertedPrice($listprice);//convert the listPrice into $ 503 504 $comment = addslashes($_REQUEST['comment'.$i]); 505 506 //if the product is deleted then we should avoid saving the deleted products 507 if($_REQUEST["deleted".$i] == 1) 508 continue; 509 510 //we have to update the Product stock for PurchaseOrder if $update_prod_stock is true 511 if($module == 'PurchaseOrder' && $update_prod_stock == 'true') 512 { 513 addToProductStock($prod_id,$qty); 514 } 515 if($module == 'SalesOrder') 516 { 517 if($updateDemand == '-') 518 { 519 deductFromProductDemand($prod_id,$qty); 520 } 521 elseif($updateDemand == '+') 522 { 523 addToProductDemand($prod_id,$qty); 524 } 525 } 526 527 $query ="insert into vtiger_inventoryproductrel(id, productid, sequence_no, quantity, listprice, comment) values($focus->id, $prod_id , $prod_seq, $qty, $listprice, '$comment')"; 528 $prod_seq++; 529 $adb->query($query); 530 531 if($module != 'PurchaseOrder') 532 { 533 //update the stock with existing details 534 updateStk($prod_id,$qty,$focus->mode,$ext_prod_arr,$module); 535 } 536 537 //we should update discount and tax details 538 $updatequery = "update vtiger_inventoryproductrel set "; 539 540 //set the discount percentage or discount amount in update query, then set the tax values 541 if($_REQUEST['discount_type'.$i] == 'percentage') 542 { 543 $updatequery .= " discount_percent='".$_REQUEST['discount_percentage'.$i]."',"; 544 } 545 elseif($_REQUEST['discount_type'.$i] == 'amount') 546 { 547 $discount_amount = getConvertedPrice($_REQUEST['discount_amount'.$i]);//convert the amount to $ 548 $updatequery .= " discount_amount='".$discount_amount."',"; 549 } 550 551 if($_REQUEST['taxtype'] == 'group') 552 { 553 for($tax_count=0;$tax_count<count($all_available_taxes);$tax_count++) 554 { 555 $tax_name = $all_available_taxes[$tax_count]['taxname']; 556 $request_tax_name = $tax_name."_group_percentage"; 557 558 $updatequery .= "$tax_name = '".$_REQUEST[$request_tax_name]."',"; 559 } 560 $updatequery = trim($updatequery,',')." where id=$focus->id and productid=$prod_id"; 561 } 562 else 563 { 564 $taxes_for_product = getTaxDetailsForProduct($prod_id,'all'); 565 for($tax_count=0;$tax_count<count($taxes_for_product);$tax_count++) 566 { 567 $tax_name = $taxes_for_product[$tax_count]['taxname']; 568 $request_tax_name = $tax_name."_percentage".$i; 569 570 $updatequery .= "$tax_name = '".$_REQUEST[$request_tax_name]."',"; 571 } 572 $updatequery = trim($updatequery,',')." where id=$focus->id and productid=$prod_id"; 573 } 574 // jens 2006/08/19 - protect against empy update queries 575 if( !preg_match( '/set\s+where/i', $updatequery)) { 576 $adb->query($updatequery); 577 } 578 } 579 580 //we should update the netprice (subtotal), taxtype, group discount, S&H charge, S&H taxes, adjustment and total 581 //netprice, group discount, taxtype, S&H amount, adjustment and total to entity table 582 583 $updatequery = " update $focus->table_name set "; 584 585 $subtotal = getConvertedPrice($_REQUEST['subtotal']);//get the subtotal to $ 586 $updatequery .= " subtotal='".$subtotal."',"; 587 588 $updatequery .= " taxtype='".$_REQUEST['taxtype']."',"; 589 590 //for discount percentage or discount amount 591 if($_REQUEST['discount_type_final'] == 'percentage') 592 { 593 $updatequery .= " discount_percent='".$_REQUEST['discount_percentage_final']."',"; 594 } 595 elseif($_REQUEST['discount_type_final'] == 'amount') 596 { 597 $discount_amount_final = getConvertedPrice($_REQUEST['discount_amount_final']);//convert final discount amount to $ 598 $updatequery .= " discount_amount='".$discount_amount_final."',"; 599 } 600 601 $shipping_handling_charge = getConvertedPrice($_REQUEST['shipping_handling_charge']);//convert the S&H amount to $ 602 $updatequery .= " s_h_amount='".$shipping_handling_charge."',"; 603 604 //if the user gave - sign in adjustment then add with the value 605 $adjustmentType = ''; 606 if($_REQUEST['adjustmentType'] == '-') 607 $adjustmentType = $_REQUEST['adjustmentType']; 608 609 $adjustment = $_REQUEST['adjustment']; 610 $adjustment = getConvertedPrice($adjustment);//convert the adjustment to $ 611 $updatequery .= " adjustment='".$adjustmentType.$adjustment."',"; 612 613 $total = getConvertedPrice($_REQUEST['total']);//convert total to $ 614 $updatequery .= " total='".$total."'"; 615 616 $id_array = Array('PurchaseOrder'=>'purchaseorderid','SalesOrder'=>'salesorderid','Quotes'=>'quoteid','Invoice'=>'invoiceid'); 617 //Added where condition to which entity we want to update these values 618 //$updatequery .= " where ".$focus->$module_id."=$focus->id"; 619 $updatequery .= " where ".$id_array[$module]."=$focus->id"; 620 621 $adb->query($updatequery); 622 623 //to save the S&H tax details in vtiger_inventoryshippingrel table 624 $sh_tax_details = getAllTaxes('all','sh'); 625 $sh_query_fields = "id,"; 626 $sh_query_values = "$focus->id,"; 627 for($i=0;$i<count($sh_tax_details);$i++) 628 { 629 $tax_name = $sh_tax_details[$i]['taxname']."_sh_percent"; 630 if($_REQUEST[$tax_name] != '') 631 { 632 $sh_query_fields .= $sh_tax_details[$i]['taxname'].","; 633 $sh_query_values .= $_REQUEST[$tax_name].","; 634 } 635 } 636 $sh_query_fields = trim($sh_query_fields,','); 637 $sh_query_values = trim($sh_query_values,','); 638 639 $sh_query = "insert into vtiger_inventoryshippingrel(".$sh_query_fields.") values(".$sh_query_values.")"; 640 $adb->query($sh_query); 641 642 $log->debug("Exit from function saveInventoryProductDetails($focus, $module)."); 643 } 644 645 /** function used to get the tax type for the entity (PO, SO, Quotes or Invoice) 646 * @param string $module - module name 647 * @param int $id - id of the PO or SO or Quotes or Invoice 648 * @return string $taxtype - taxtype for the given entity which will be individual or group 649 */ 650 function getInventoryTaxType($module, $id) 651 { 652 global $log, $adb; 653 654 $log->debug("Entering into function getInventoryTaxType($module, $id)."); 655 656 $inv_table_array = Array('PurchaseOrder'=>'vtiger_purchaseorder','SalesOrder'=>'vtiger_salesorder','Quotes'=>'vtiger_quotes','Invoice'=>'vtiger_invoice'); 657 $inv_id_array = Array('PurchaseOrder'=>'purchaseorderid','SalesOrder'=>'salesorderid','Quotes'=>'quoteid','Invoice'=>'invoiceid'); 658 659 $res = $adb->query("select taxtype from ".$inv_table_array[$module]." where ".$inv_id_array[$module]."=".$id); 660 661 $taxtype = $adb->query_result($res,0,'taxtype'); 662 663 $log->debug("Exit from function getInventoryTaxType($module, $id)."); 664 665 return $taxtype; 666 } 667 668 /** function used to get the taxvalue which is associated with a product for PO/SO/Quotes or Invoice 669 * @param int $id - id of PO/SO/Quotes or Invoice 670 * @param int $productid - product id 671 * @param string $taxname - taxname to which we want the value 672 * @return float $taxvalue - tax value 673 */ 674 function getInventoryProductTaxValue($id, $productid, $taxname) 675 { 676 global $log, $adb; 677 $log->debug("Entering into function getInventoryProductTaxValue($id, $productid, $taxname)."); 678 679 $res = $adb->query("select $taxname from vtiger_inventoryproductrel where id = $id and productid = $productid"); 680 $taxvalue = $adb->query_result($res,0,$taxname); 681 682 if($taxvalue == '') 683 $taxvalue = '0.00'; 684 685 $log->debug("Exit from function getInventoryProductTaxValue($id, $productid, $taxname)."); 686 687 return $taxvalue; 688 } 689 690 /** function used to get the shipping & handling tax percentage for the given inventory id and taxname 691 * @param int $id - entity id which will be PO/SO/Quotes or Invoice id 692 * @param string $taxname - shipping and handling taxname 693 * @return float $taxpercentage - shipping and handling taxpercentage which is associated with the given entity 694 */ 695 function getInventorySHTaxPercent($id, $taxname) 696 { 697 global $log, $adb; 698 $log->debug("Entering into function getInventorySHTaxPercent($id, $taxname)"); 699 700 $res = $adb->query("select $taxname from vtiger_inventoryshippingrel where id= $id"); 701 $taxpercentage = $adb->query_result($res,0,$taxname); 702 703 if($taxpercentage == '') 704 $taxpercentage = '0.00'; 705 706 $log->debug("Exit from function getInventorySHTaxPercent($id, $taxname)"); 707 708 return $taxpercentage; 709 } 710 711 712 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |