[Vtigercrm-commits] [vtiger-commits] r9605 - in /vtigercrm/branches/5.0.1: include/utils/InventoryUtils.php include/utils/utils.php modules/SalesOrder/Save.php

vtigercrm-commits at vtiger.fosslabs.com vtigercrm-commits at vtiger.fosslabs.com
Mon Oct 9 09:47:19 EDT 2006


Author: richie
Date: Mon Oct  9 07:47:12 2006
New Revision: 9605

Log:
* Added code to deduct the quantity from Qty In Demand when SO status is Approved and deduct quantity from Qty In Stock and Qty in Demand when SO status is Delivered

Modified:
    vtigercrm/branches/5.0.1/include/utils/InventoryUtils.php
    vtigercrm/branches/5.0.1/include/utils/utils.php
    vtigercrm/branches/5.0.1/modules/SalesOrder/Save.php

Modified: vtigercrm/branches/5.0.1/include/utils/InventoryUtils.php
==============================================================================
--- vtigercrm/branches/5.0.1/include/utils/InventoryUtils.php (original)
+++ vtigercrm/branches/5.0.1/include/utils/InventoryUtils.php Mon Oct  9 07:47:12 2006
@@ -469,7 +469,7 @@
  *	@param $update_prod_stock - true or false (default), if true we have to update the stock for PO only
  *	@return void
  */
-function saveInventoryProductDetails($focus, $module, $update_prod_stock='false')
+function saveInventoryProductDetails($focus, $module, $update_prod_stock='false', $updateStockAndDemand='false', $updateDemand='false')
 {
 	global $log, $adb;
 	$log->debug("Entering into function saveInventoryProductDetails($focus, $module).");
@@ -507,6 +507,18 @@
 		if($module == 'PurchaseOrder' && $update_prod_stock == 'true')
 		{
 			addToProductStock($prod_id,$qty);
+		}
+		if($module == 'SalesOrder')
+		{
+			if($updateStockAndDemand == 'true')
+			{
+				deductFromProductStock($prod_id,$qty);
+				deductFromProductDemand($prod_id,$qty);
+			}
+			if($updateDemand == 'true')
+			{
+				addToProductDemand($prod_id,$qty);
+			}
 		}
 
 		$query ="insert into vtiger_inventoryproductrel(id, productid, sequence_no, quantity, listprice, comment) values($focus->id, $prod_id , $prod_seq, $qty, $listprice, '$comment')";

Modified: vtigercrm/branches/5.0.1/include/utils/utils.php
==============================================================================
--- vtigercrm/branches/5.0.1/include/utils/utils.php (original)
+++ vtigercrm/branches/5.0.1/include/utils/utils.php Mon Oct  9 07:47:12 2006
@@ -2105,6 +2105,59 @@
 	$log->debug("Exiting addToProductStock method ...");
 	
 }
+
+/**	This Function adds the specified product quantity to the Product Quantity in Demand in the Warehouse 
+  *	@param int $productId - ProductId
+  *	@param int $qty - Quantity to be added
+  */
+function addToProductDemand($productId,$qty)
+{
+	global $log;
+	$log->debug("Entering addToProductDemand(".$productId.",".$qty.") method ...");
+	global $adb;
+	$qtyInStck=getProductQtyInDemand($productId);
+	$updQty=$qtyInStck + $qty;
+	$sql = "UPDATE vtiger_products set qtyindemand=$updQty where productid=".$productId;
+	$adb->query($sql);
+	$log->debug("Exiting addToProductDemand method ...");
+	
+}
+
+/**	This Function subtract the specified product quantity to the Product Quantity in Stock in the Warehouse 
+  *	@param int $productId - ProductId
+  *	@param int $qty - Quantity to be subtracted
+  */
+function deductFromProductStock($productId,$qty)
+{
+	global $log;
+	$log->debug("Entering deductFromProductStock(".$productId.",".$qty.") method ...");
+	global $adb;
+	$qtyInStck=getProductQtyInStock($productId);
+	$updQty=$qtyInStck - $qty;
+	$sql = "UPDATE vtiger_products set qtyinstock=$updQty where productid=".$productId;
+	$adb->query($sql);
+	$log->debug("Exiting deductFromProductStock method ...");
+	
+}
+
+/**	This Function subtract the specified product quantity to the Product Quantity in Demand in the Warehouse 
+  *	@param int $productId - ProductId
+  *	@param int $qty - Quantity to be subtract
+  */
+function deductFromProductDemand($productId,$qty)
+{
+	global $log;
+	$log->debug("Entering deductFromProductDemand(".$productId.",".$qty.") method ...");
+	global $adb;
+	$qtyInStck=getProductQtyInDemand($productId);
+	$updQty=$qtyInStck - $qty;
+	$sql = "UPDATE vtiger_products set qtyindemand=$updQty where productid=".$productId;
+	$adb->query($sql);
+	$log->debug("Exiting deductFromProductDemand method ...");
+	
+}
+
+
 /** This Function returns the current product quantity in stock.
   * The following is the input parameter for the function:
   *  $product_id --> ProductId, Type:Integer
@@ -2122,6 +2175,23 @@
 
 
 }
+
+/**	This Function returns the current product quantity in demand.
+  *	@param int $product_id - ProductId
+  *	@return int $qtyInDemand - Quantity in Demand of a product
+  */
+function getProductQtyInDemand($product_id)
+{
+	global $log;
+	$log->debug("Entering getProductQtyInDemand(".$product_id.") method ...");
+        global $adb;
+        $query1 = "select qtyindemand from vtiger_products where productid=".$product_id;
+        $result = $adb->query($query1);
+        $qtyInDemand = $adb->query_result($result,0,"qtyindemand");
+	$log->debug("Exiting getProductQtyInDemand method ...");
+        return $qtyInDemand;
+}
+
 /** Function to seperate the Date and Time
   * This function accepts a sting with date and time and
   * returns an array of two elements.The first element

Modified: vtigercrm/branches/5.0.1/modules/SalesOrder/Save.php
==============================================================================
--- vtigercrm/branches/5.0.1/modules/SalesOrder/Save.php (original)
+++ vtigercrm/branches/5.0.1/modules/SalesOrder/Save.php Mon Oct  9 07:47:12 2006
@@ -31,6 +31,26 @@
 $focus = new SalesOrder();
 setObjectValuesFromRequest(&$focus);
 
+if($focus->mode == 'edit' && ($focus->column_fields['sostatus'] == 'Delivered' || $focus->column_fields['sostatus'] == 'Approved'))
+{
+	$prev_sostatus=$adb->query_result($adb->query("select sostatus from vtiger_salesorder where salesorderid=$focus->id"),0,'sostatus');
+
+	if($focus->column_fields['sostatus'] != $prev_sostatus)
+	{
+       		if($focus->column_fields['sostatus'] == 'Delivered')
+        	{
+			//Deduct the quantity from Quantity In Stock and Quantity In Demand
+                	$updateStockAndDemand = 'true';
+		}
+		elseif($focus->column_fields['sostatus'] == 'Approved')
+		{
+			//Add the quantity with Quantity In Demand
+			$updateDemand = 'true';
+		}
+        }
+
+}
+
 $focus->save("SalesOrder");
 
 //Checking if quote_id is present and updating the quote status
@@ -42,7 +62,7 @@
 }
 
 //Based on the total Number of rows we will save the product relationship with this entity
-saveInventoryProductDetails(&$focus, 'SalesOrder');
+saveInventoryProductDetails(&$focus, 'SalesOrder','',$updateStockAndDemand, $updateDemand);
 
 
 $return_id = $focus->id;





More information about the vtigercrm-commits mailing list