[Vtigercrm-commits] [vtiger-commits] r7382 - in /vtigercrm/trunk: data/CRMEntity.php include/utils/CommonUtils.php include/utils/InventoryUtils.php schema/DatabaseSchema.xml

vtigercrm-commits at vtiger.fosslabs.com vtigercrm-commits at vtiger.fosslabs.com
Wed Jun 21 09:43:51 EDT 2006


Author: saraj
Date: Wed Jun 21 07:43:44 2006
New Revision: 7382

Log:
* Modified to handle the history of PO, SO, Quotes and Invoice

Modified:
    vtigercrm/trunk/data/CRMEntity.php
    vtigercrm/trunk/include/utils/CommonUtils.php
    vtigercrm/trunk/include/utils/InventoryUtils.php
    vtigercrm/trunk/schema/DatabaseSchema.xml

Modified: vtigercrm/trunk/data/CRMEntity.php
==============================================================================
--- vtigercrm/trunk/data/CRMEntity.php (original)
+++ vtigercrm/trunk/data/CRMEntity.php Wed Jun 21 07:43:44 2006
@@ -704,7 +704,29 @@
 				  $adb->query($sql);
 			  }
 		  }
-		
+		  elseif($_REQUEST['module'] == 'PurchaseOrder' || $_REQUEST['module'] == 'SalesOrder' || $_REQUEST['module'] == 'Quotes' || $_REQUEST['module'] == 'Invoice')
+		  {
+			  //added to update the history for PO, SO, Quotes and Invoice
+			  $history_field_array = Array(
+				  			"PurchaseOrder"=>"postatus",
+							"SalesOrder"=>"sostatus",
+							"Quotes"=>"quotestage",
+							"Invoice"=>"invoicestatus"
+						      );
+
+			  $inventory_module = $_REQUEST['module'];
+			  if($inventory_module == "PurchaseOrder")
+			  	$relatedname = $_REQUEST["vendor_name"];
+			  else
+			  	$relatedname = $_REQUEST["account_name"];
+
+			  $oldvalue = getSingleFieldValue($this->table_name,$history_field_array[$inventory_module],$this->module_id,$this->id);
+			  if($oldvalue != $this->column_fields["$history_field_array[$inventory_module]"])
+			  {
+				  addInventoryHistory($inventory_module, $this->id,$relatedname,$_REQUEST['grandTotal'],$this->column_fields["$history_field_array[$inventory_module]"]);
+			  }
+		  }
+
 		  //Check done by Don. If update is empty the the query fails
 		  if(trim($update) != '')
         	  {

Modified: vtigercrm/trunk/include/utils/CommonUtils.php
==============================================================================
--- vtigercrm/trunk/include/utils/CommonUtils.php (original)
+++ vtigercrm/trunk/include/utils/CommonUtils.php Wed Jun 21 07:43:44 2006
@@ -2390,5 +2390,23 @@
 	return $description;
 }
 
+/**	Function used to retrieve a single field value from database
+ *	@param string $tablename - tablename from which we will retrieve the field value
+ *	@param string $fieldname - fieldname to which we want to get the value from database
+ *	@param string $idname	 - idname which is the name of the entity id in the table like, inoviceid, quoteid, etc.,
+ *	@param int    $id	 - entity id
+ *	return string $fieldval  - field value of the needed fieldname from database will be returned
+ */
+function getSingleFieldValue($tablename, $fieldname, $idname, $id)
+{
+	global $log, $adb;
+	$log->debug("Entering into function getSingleFieldValue($tablename, $fieldname, $idname, $id)");
+
+	$fieldval = $adb->query_result($adb->query("select $fieldname from $tablename where $idname = $id"),0,$fieldname);
+
+	$log->debug("Exit from function getSingleFieldValue. return value ==> \"$fieldval\"");
+
+	return $fieldval;
+}
 
 ?>

Modified: vtigercrm/trunk/include/utils/InventoryUtils.php
==============================================================================
--- vtigercrm/trunk/include/utils/InventoryUtils.php (original)
+++ vtigercrm/trunk/include/utils/InventoryUtils.php Wed Jun 21 07:43:44 2006
@@ -315,5 +315,30 @@
 	return $taxpercentage;
 }
 
+/**	Function used to add the history entry in the relevant tables for PO, SO, Quotes and Invoice modules
+ *	@param string 	$module		- current module name
+ *	@param int 	$id		- entity id
+ *	@param string 	$relatedname	- parent name of the entity ie, required field venor name for PO and account name for SO, Quotes and Invoice
+ *	@param float 	$total		- grand total value of the product details included tax
+ *	@param string 	$history_fldval	- history field value ie., quotestage for Quotes and status for PO, SO and Invoice
+ */
+function addInventoryHistory($module, $id, $relatedname, $total, $history_fldval)
+{
+	global $log, $adb;
+	$log->debug("Entering into function addInventoryHistory($module, $id, $relatedname, $total, $history_fieldvalue)");
+
+	$history_table_array = Array(
+					"PurchaseOrder"=>"vtiger_postatushistory",
+					"SalesOrder"=>"vtiger_sostatushistory",
+					"Quotes"=>"vtiger_quotestagehistory",
+					"Invoice"=>"vtiger_invoicestatushistory"
+				    );
+
+	$modifiedtime = date('YmdHis');
+	$query = "insert into $history_table_array[$module] values('',$id,\"$relatedname\",\"$total\",\"$history_fldval\",\"$modifiedtime\")";
+	$adb->query($query);
+
+	$log->debug("Exit from function addInventoryHistory");
+}
 
 ?>

Modified: vtigercrm/trunk/schema/DatabaseSchema.xml
==============================================================================
--- vtigercrm/trunk/schema/DatabaseSchema.xml (original)
+++ vtigercrm/trunk/schema/DatabaseSchema.xml Wed Jun 21 07:43:44 2006
@@ -5207,5 +5207,82 @@
 		</index>
 		<opt platform="mysql">Type=InnoDB</opt>
 	</table>
-	
+
+	<table name="vtiger_postatushistory">
+		<field name="historyid" type="I" size="19">
+			<key />
+			<autoincrement />
+		</field>
+		<field name="purchaseorderid" type="I" size="19">
+			<notnull />
+			<constraint>REFERENCES vtiger_purchaseorder(purchaseorderid) ON DELETE CASCADE</constraint>
+		</field>
+		<field name="vendorname" type="C" size="100" />
+		<field name="total" type="N" />
+		<field name="postatus" type="C" size="200" />
+		<field name="lastmodified" type="T" />
+
+		<index name="postatushistory_purchaseorderid_idx">
+			<col>purchaseorderid</col>
+		</index>
+		<opt platform="mysql">Type=InnoDB</opt>
+	</table>
+	<table name="vtiger_sostatushistory">
+		<field name="historyid" type="I" size="19">
+			<key />
+			<autoincrement />
+		</field>
+		<field name="salesorderid" type="I" size="19">
+			<notnull />
+			<constraint>REFERENCES vtiger_salesorder(salesorderid) ON DELETE CASCADE</constraint>
+		</field>
+		<field name="accountname" type="C" size="100" />
+		<field name="total" type="N" />
+		<field name="sostatus" type="C" size="200" />
+		<field name="lastmodified" type="T" />
+
+		<index name="sostatushistory_salesorderid_idx">
+			<col>salesorderid</col>
+		</index>
+		<opt platform="mysql">Type=InnoDB</opt>
+	</table>
+	<table name="vtiger_quotestagehistory">
+		<field name="historyid" type="I" size="19">
+			<key />
+			<autoincrement />
+		</field>
+		<field name="quoteid" type="I" size="19">
+			<notnull />
+			<constraint>REFERENCES vtiger_quotes(quoteid) ON DELETE CASCADE</constraint>
+		</field>
+		<field name="accountname" type="C" size="100" />
+		<field name="total" type="N" />
+		<field name="quotestage" type="C" size="200" />
+		<field name="lastmodified" type="T" />
+
+		<index name="quotestagehistory_quoteid_idx">
+			<col>quoteid</col>
+		</index>
+		<opt platform="mysql">Type=InnoDB</opt>
+	</table>
+	<table name="vtiger_invoicestatushistory">
+		<field name="historyid" type="I" size="19">
+			<key />
+			<autoincrement />
+		</field>
+		<field name="invoiceid" type="I" size="19">
+			<notnull />
+			<constraint>REFERENCES vtiger_invoice(invoiceid) ON DELETE CASCADE</constraint>
+		</field>
+		<field name="accountname" type="C" size="100" />
+		<field name="total" type="N" />
+		<field name="invoicestatus" type="C" size="200" />
+		<field name="lastmodified" type="T" />
+
+		<index name="invoicestatushistory_invoiceid_idx">
+			<col>invoiceid</col>
+		</index>
+		<opt platform="mysql">Type=InnoDB</opt>
+	</table>
+
 </schema>





More information about the vtigercrm-commits mailing list