[Vtigercrm-commits] [vtiger-commits] r4778 - /vtigercrm/trunk/include/utils/InventoryUtils.php
vtigercrm-commits at vtiger.fosslabs.com
vtigercrm-commits at vtiger.fosslabs.com
Thu Mar 30 08:08:18 EST 2006
Author: saraj
Date: Thu Mar 30 06:08:14 2006
New Revision: 4778
Log:
* Added functions to calculate Product Stock and send mail about the stock which was placed in Save.php file accross the modules SalesOrder, Quotes and Invoice
Modified:
vtigercrm/trunk/include/utils/InventoryUtils.php
Modified: vtigercrm/trunk/include/utils/InventoryUtils.php
==============================================================================
--- vtigercrm/trunk/include/utils/InventoryUtils.php (original)
+++ vtigercrm/trunk/include/utils/InventoryUtils.php Thu Mar 30 06:08:14 2006
@@ -49,4 +49,156 @@
}
return $productBlock;
}
+
+function updateStk($product_id,$qty,$mode,$ext_prod_arr,$module)
+{
+ global $adb;
+ global $current_user;
+ global $log;
+
+ $log->debug("Inside updateStk function, module=".$module);
+ $log->debug("Product Id = $product_id & Qty = $qty");
+
+ $prod_name = getProductName($product_id);
+ $qtyinstk= getPrdQtyInStck($product_id);
+ $log->debug("Prd Qty in Stock ".$qtyinstk);
+
+ if($mode == 'edit')
+ {
+ if(array_key_exists($product_id,$ext_prod_arr))
+ {
+ $old_qty = $ext_prod_arr[$product_id];
+ if($old_qty > $qty)
+ {
+ $diff_qty = $old_qty - $qty;
+ $upd_qty = $qtyinstk+$diff_qty;
+ if($module == 'Invoice')
+ {
+ updateProductQty($product_id, $upd_qty);
+ sendPrdStckMail($product_id,$upd_qty,$prod_name,'','',$module);
+ }
+ else
+ sendPrdStckMail($product_id,$upd_qty,$prod_name,$qtyinstk,$qty,$module);
+ }
+ elseif($old_qty < $qty)
+ {
+ $diff_qty = $qty - $old_qty;
+ $upd_qty = $qtyinstk-$diff_qty;
+ if($module == 'Invoice')
+ {
+ updateProductQty($product_id, $upd_qty);
+ sendPrdStckMail($product_id,$upd_qty,$prod_name,'','',$module);
+ }
+ else
+ sendPrdStckMail($product_id,$upd_qty,$prod_name,$qtyinstk,$qty,$module);
+ }
+ }
+ else
+ {
+ $upd_qty = $qtyinstk-$qty;
+ if($module == 'Invoice')
+ {
+ updateProductQty($product_id, $upd_qty);
+ sendPrdStckMail($product_id,$upd_qty,$prod_name,'','',$module);
+ }
+ else
+ sendPrdStckMail($product_id,$upd_qty,$prod_name,$qtyinstk,$qty,$module);
+ }
+ }
+ else
+ {
+ $upd_qty = $qtyinstk-$qty;
+ if($module == 'Invoice')
+ {
+ updateProductQty($product_id, $upd_qty);
+ sendPrdStckMail($product_id,$upd_qty,$prod_name,'','',$module);
+ }
+ else
+ sendPrdStckMail($product_id,$upd_qty,$prod_name,$qtyinstk,$qty,$module);
+ }
+}
+
+function sendPrdStckMail($product_id,$upd_qty,$prod_name,$qtyinstk,$qty,$module)
+{
+ global $current_user;
+ global $adb;
+ global $log;
+ $reorderlevel = getPrdReOrderLevel($product_id);
+ $log->debug("Inside sendPrdStckMail function, module=".$module);
+ $log->debug("Prd reorder level ".$reorderlevel);
+ if($upd_qty < $reorderlevel)
+ {
+ //send mail to the handler
+ $handler=getPrdHandler($product_id);
+ $handler_name = getUserName($handler);
+ $to_address= getUserEmail($handler);
+
+ //Get the email details from database;
+ if($module == 'SalesOrder')
+ {
+ $notification_table = 'SalesOrderNotification';
+ $quan_name = '{SOQUANTITY}';
+ }
+ if($module == 'Quotes')
+ {
+ $notification_table = 'QuoteNotification';
+ $quan_name = '{QUOTEQUANTITY}';
+ }
+ if($module == 'Invoice')
+ {
+ $notificationname = 'InvoiceNotification';
+ }
+ $query = "select * from inventorynotification where notificationname='".$notification_table."'";
+ $result = $adb->query($query);
+
+ $subject = $adb->query_result($result,0,'notificationsubject');
+ $body = $adb->query_result($result,0,'notificationbody');
+
+ $subject = str_replace('{PRODUCTNAME}',$prod_name,$subject);
+ $body = str_replace('{HANDLER}',$handler_name,$body);
+ $body = str_replace('{PRODUCTNAME}',$prod_name,$body);
+ if($module == 'Invoice')
+ {
+ $body = str_replace('{CURRENTSTOCK}',$upd_qty,$body);
+ $body = str_replace('{REORDERLEVELVALUE}',$reorderlevel,$body);
+ }
+ else
+ {
+ $body = str_replace('{CURRENTSTOCK}',$qtyinstk,$body);
+ $body = str_replace($quan_name,$qty,$body);
+ }
+ $body = str_replace('{CURRENTUSER}',$current_user->user_name,$body);
+
+ $mail_status = send_mail($module,$to_address,$current_user->user_name,$current_user->email1,$subject,$body);
+ }
+}
+
+function getPrdQtyInStck($product_id)
+{
+ global $adb;
+ $query1 = "select qtyinstock from products where productid=".$product_id;
+ $result=$adb->query($query1);
+ $qtyinstck= $adb->query_result($result,0,"qtyinstock");
+ return $qtyinstck;
+}
+
+function getPrdReOrderLevel($product_id)
+{
+ global $adb;
+ $query1 = "select reorderlevel from products where productid=".$product_id;
+ $result=$adb->query($query1);
+ $reorderlevel= $adb->query_result($result,0,"reorderlevel");
+ return $reorderlevel;
+}
+
+function getPrdHandler($product_id)
+{
+ global $adb;
+ $query1 = "select handler from products where productid=".$product_id;
+ $result=$adb->query($query1);
+ $handler= $adb->query_result($result,0,"handler");
+ return $handler;
+}
+
+
?>
More information about the vtigercrm-commits
mailing list