[Vtigercrm-commits] [vtiger-commits] r10045 - in /vtigercrm/branches/5.0.3: modules/Accounts/ modules/Contacts/ modules/Leads/ modules/Potentials/ modules/Products/ modules/Reports/ modules/Vendors/ schema/

vtigercrm-commits at vtiger.fosslabs.com vtigercrm-commits at vtiger.fosslabs.com
Fri Jan 12 06:31:48 EST 2007


Author: richie
Date: Fri Jan 12 04:31:34 2007
New Revision: 10045

Log:
* Added setype in vtiger_seproductsrel table to handle the Product - Lead/Account/Contact/Potential relationship

Modified:
    vtigercrm/branches/5.0.3/modules/Accounts/updateRelations.php
    vtigercrm/branches/5.0.3/modules/Contacts/updateRelations.php
    vtigercrm/branches/5.0.3/modules/Leads/LeadConvertToEntities.php
    vtigercrm/branches/5.0.3/modules/Leads/updateRelations.php
    vtigercrm/branches/5.0.3/modules/Potentials/updateRelations.php
    vtigercrm/branches/5.0.3/modules/Products/Products.php
    vtigercrm/branches/5.0.3/modules/Products/updateRelations.php
    vtigercrm/branches/5.0.3/modules/Reports/ReportRun.php
    vtigercrm/branches/5.0.3/modules/Vendors/updateRelations.php
    vtigercrm/branches/5.0.3/schema/DatabaseSchema.xml

Modified: vtigercrm/branches/5.0.3/modules/Accounts/updateRelations.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Accounts/updateRelations.php (original)
+++ vtigercrm/branches/5.0.3/modules/Accounts/updateRelations.php Fri Jan 12 04:31:34 2007
@@ -26,7 +26,7 @@
 	$accountid = $_REQUEST['parid'];
 	$productid = $_REQUEST['entityid'];
 	if($accountid != '' && $productid != '')
-		$adb->query("insert into vtiger_seproductsrel values($accountid,$productid)");
+		$adb->query("insert into vtiger_seproductsrel values($accountid,$productid,'".$dest_mod."')");
 		
 	$record = $accountid;
 }

Modified: vtigercrm/branches/5.0.3/modules/Contacts/updateRelations.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Contacts/updateRelations.php (original)
+++ vtigercrm/branches/5.0.3/modules/Contacts/updateRelations.php Fri Jan 12 04:31:34 2007
@@ -27,7 +27,7 @@
 	$contactid = $_REQUEST['parid'];
 	$productid = $_REQUEST['entityid'];
 	if($contactid != '' && $productid != '')
-		$adb->query("insert into vtiger_seproductsrel values($contactid,$productid)");
+		$adb->query("insert into vtiger_seproductsrel values ($contactid,$productid,'".$dest_mod."')");
 
 	$record = $contactid;
 }

Modified: vtigercrm/branches/5.0.3/modules/Leads/LeadConvertToEntities.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Leads/LeadConvertToEntities.php (original)
+++ vtigercrm/branches/5.0.3/modules/Leads/LeadConvertToEntities.php Fri Jan 12 04:31:34 2007
@@ -228,26 +228,20 @@
 /**	Function used to save the lead related products with other entities Account, Contact and Potential
  *	$leadid - leadid
  *	$relatedid - related entity id (accountid/contactid/potentialid)
- *	$relatedmodule - related entity module name - optional, but for contacts we have to pass Contact because we have to update contactid in vtiger_products table.
  */
-function saveLeadRelatedProducts($leadid, $relatedid, $relatedmodule = '')
+function saveLeadRelatedProducts($leadid, $relatedid)
 {
 	global $adb, $log;
-	$log->debug("Entering into function saveLeadRelatedProducts($leadid, $relatedid, \"$relatedmodule\")");
+	$log->debug("Entering into function saveLeadRelatedProducts($leadid, $relatedid)");
 
 	$product_result = $adb->query("select * from vtiger_seproductsrel where crmid=$leadid");
 	$noofproducts = $adb->num_rows($product_result);
 	for($i = 0; $i < $noofproducts; $i++)
 	{
 		$productid = $adb->query_result($product_result,$i,'productid');
-
-		$adb->query("insert into vtiger_seproductsrel (productid, crmid) values($productid, $relatedid)");
-
-		if($relatedmodule == 'Contacts')
-		{
-			//update contactid in products table then only the products will be shown in contact relatedlist
-			$adb->query("update vtiger_products set contactid=$relatedid where productid=$productid");
-		}
+		$setype = $adb->query_result($product_result,$i,'setype');
+
+		$adb->query("insert into vtiger_seproductsrel values($relatedid, $productid,'".$setype."')");
 	}
 
 	$log->debug("Exit from function saveLeadRelatedProducts.");
@@ -376,7 +370,7 @@
 getRelatedActivities($account_id,$contact_id); //To convert relates Activites  and Email -Jaguar
 
 //Retrieve the lead related products and relate them with this new contact
-saveLeadRelatedProducts($id, $contact_id, "Contacts");
+saveLeadRelatedProducts($id, $contact_id);
 
 //Retrieve the lead related Campaigns and relate them with this new contact --Minnie
 saveLeadRelatedCampaigns($id, $contact_id);

Modified: vtigercrm/branches/5.0.3/modules/Leads/updateRelations.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Leads/updateRelations.php (original)
+++ vtigercrm/branches/5.0.3/modules/Leads/updateRelations.php Fri Jan 12 04:31:34 2007
@@ -27,7 +27,7 @@
 	$leadid = $_REQUEST['parid'];
 	$productid = $_REQUEST['entityid'];
 	if($leadid != '' && $productid != '')
-		$adb->query("insert into vtiger_seproductsrel values($leadid,$productid)");
+		$adb->query("insert into vtiger_seproductsrel values($leadid,$productid,'".$dest_mod."')");
 	
 	$record = $leadid;
 }

Modified: vtigercrm/branches/5.0.3/modules/Potentials/updateRelations.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Potentials/updateRelations.php (original)
+++ vtigercrm/branches/5.0.3/modules/Potentials/updateRelations.php Fri Jan 12 04:31:34 2007
@@ -13,12 +13,13 @@
 require_once('user_privileges/default_module_view.php');
 global $adb, $singlepane_view;
 $idlist = $_REQUEST['idlist'];
-$returnmodule = $_REQUEST['return_module'];
+$dest_mod = $_REQUEST['destination_module'];
 
 if($singlepane_view == 'true')
 	$action = "DetailView";
 else
 	$action = "CallRelatedList";
+
 if(isset($_REQUEST['idlist']) && $_REQUEST['idlist'] != '')
 {
 	//split the string and store in an array
@@ -29,7 +30,7 @@
 		{
 			$sql = "insert into vtiger_contpotentialrel values (".$id.",".$_REQUEST["parentid"] .")";
 			$adb->query($sql);
-			$sql = "insert into vtiger_seproductsrel values (". $_REQUEST["parentid"] .",".$id.")";
+			$sql = "insert into vtiger_seproductsrel values (". $_REQUEST["parentid"] .",".$id.",'".$dest_mod."')";
 			$adb->query($sql);
 		}
 	}
@@ -40,7 +41,7 @@
 {
 	$sql = "insert into vtiger_contpotentialrel values (". $_REQUEST["entityid"] .",".$_REQUEST["parid"] .")";
 	$adb->query($sql);
-	$sql = "insert into vtiger_seproductsrel values (". $_REQUEST["parid"] .",".$_REQUEST["entityid"] .")";
+	$sql = "insert into vtiger_seproductsrel values (". $_REQUEST["parid"] .",".$_REQUEST["entityid"] .",'".$dest_mod."')";
 	$adb->query($sql);
 
 	header("Location: index.php?action=$action&module=Potentials&record=".$_REQUEST["parid"]);

Modified: vtigercrm/branches/5.0.3/modules/Products/Products.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Products/Products.php (original)
+++ vtigercrm/branches/5.0.3/modules/Products/Products.php Fri Jan 12 04:31:34 2007
@@ -82,15 +82,6 @@
 
 	function save_module($module)
 	{
-		//Inserting into vtiger_seproductsrel table
-		if(isset($this->column_fields['parent_id']) && $this->column_fields['parent_id'] != '')
-		{
-			$this->insertIntoEntityTable('vtiger_seproductsrel', 'Products');
-		}
-		elseif($this->column_fields['parent_id']=='' && $insertion_mode=="edit")
-		{
-			$this->deleteRelation('vtiger_seproductsrel');
-		}
 		//Inserting into product_taxrel table
 		if($_REQUEST['ajxaction'] != 'DETAILVIEW')
 		{

Modified: vtigercrm/branches/5.0.3/modules/Products/updateRelations.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Products/updateRelations.php (original)
+++ vtigercrm/branches/5.0.3/modules/Products/updateRelations.php Fri Jan 12 04:31:34 2007
@@ -32,18 +32,22 @@
 	{
 		if($crmid != '' && $productid != '')
 		{
-			$sql = "insert into vtiger_seproductsrel values ($crmid,$productid)";
+			$sql = "insert into vtiger_seproductsrel values ($crmid,$productid,'".$dest_mod."')";
 			$adb->query($sql);
 		}
 	}
+	
+	$return_module = 'Products';
 }
 
-$return_action = 'DetailView';
-$return_module = 'Vendors';
-if($_REQUEST['return_action'] != '') $return_action = $_REQUEST['return_action'];
+if($singlepane_view == 'true')
+	$return_action = "DetailView";
+else
+	$return_action = "CallRelatedList";
+
 if($_REQUEST['return_module'] != '') $return_module = $_REQUEST['return_module'];
 
-header("Location:index.php?action=$return_action&module=$return_module&record=".$_REQUEST["parid"]);
+header("Location:index.php?action=$return_action&module=$return_module&record=".$productid);
 
 
 

Modified: vtigercrm/branches/5.0.3/modules/Reports/ReportRun.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Reports/ReportRun.php (original)
+++ vtigercrm/branches/5.0.3/modules/Reports/ReportRun.php Fri Jan 12 04:31:34 2007
@@ -922,12 +922,12 @@
 			}
 			if($secmodule == "Products")
 			{
-				$query = "left join vtiger_seproductsrel on vtiger_seproductsrel.crmid = vtiger_account.accountid
+				$query = "left join vtiger_seproductsrel on vtiger_seproductsrel.crmid = vtiger_account.accountid and vtiger_seproductsrel.setype = 'Accounts'
 					left join vtiger_products on vtiger_products.productid = vtiger_seproductsrel.productid
 					left join vtiger_crmentity as vtiger_crmentityProducts on vtiger_crmentityProducts.crmid=vtiger_products.productid
 					left join vtiger_productcf on vtiger_products.productid = vtiger_productcf.productid
 					left join vtiger_users as vtiger_usersProducts on vtiger_usersProducts.id = vtiger_crmentityProducts.smownerid
-					left join vtiger_contactdetails as vtiger_contactdetailsProducts on vtiger_contactdetailsProducts.contactid = vtiger_products.contactid
+					left join vtiger_contactdetails as vtiger_contactdetailsProducts on vtiger_contactdetailsProducts.contactid = vtiger_seproductsrel.crmid
 					left join vtiger_vendor as vtiger_vendorRel on vtiger_vendorRel.vendorid = vtiger_products.vendor_id
 					left join vtiger_crmentity as vtiger_crmentityRel on vtiger_crmentityRel.crmid = vtiger_seproductsrel.crmid
 					left join vtiger_account as vtiger_accountRel on vtiger_accountRel.accountid=vtiger_crmentityRel.crmid
@@ -1010,11 +1010,14 @@
 					left join vtiger_users as vtiger_usersAccounts on vtiger_usersAccounts.id = vtiger_crmentityAccounts.smownerid ";
 			}
 		}
+
+		//Here we will get the Products - Accounts, Contacts relationship (Also Leads, Potentials)
 		if($module == "Products")
 		{
 			if($secmodule == "Accounts")
 			{
-				$query = "left join vtiger_account on vtiger_account.accountid = vtiger_crmentityRelProducts.crmid
+				$query = "
+					left join vtiger_account on vtiger_account.accountid = vtiger_seproductsrel.crmid
 					left join vtiger_crmentity as vtiger_crmentityAccounts on vtiger_crmentityAccounts.crmid=vtiger_account.accountid
 					left join vtiger_accountbillads on vtiger_account.accountid=vtiger_accountbillads.accountaddressid
 					left join vtiger_accountshipads on vtiger_account.accountid=vtiger_accountshipads.accountaddressid
@@ -1024,7 +1027,8 @@
 			}
 			if($secmodule == "Contacts")
 			{
-				$query = "left join vtiger_contactdetails on vtiger_contactdetails.contactid = vtiger_products.contactid
+				$query = "
+					left join vtiger_contactdetails on vtiger_contactdetails.contactid = vtiger_seproductsrel.crmid
 					left join vtiger_crmentity as vtiger_crmentityContacts on vtiger_crmentityContacts.crmid = vtiger_contactdetails.contactid
 					left join vtiger_contactaddress on vtiger_contactdetails.contactid = vtiger_contactaddress.contactaddressid
 					left join vtiger_contactsubdetails on vtiger_contactdetails.contactid = vtiger_contactsubdetails.contactsubscriptionid
@@ -1083,7 +1087,6 @@
 					left join vtiger_crmentity as vtiger_crmentityProducts on vtiger_crmentityProducts.crmid=vtiger_products.productid
 					left join vtiger_productcf on vtiger_products.productid = vtiger_productcf.productid
 					left join vtiger_users as vtiger_usersProducts on vtiger_usersProducts.id = vtiger_crmentityProducts.smownerid
-					left join vtiger_contactdetails as vtiger_contactdetailsProducts on vtiger_contactdetailsProducts.contactid = vtiger_products.contactid 
 					left join vtiger_vendor as vtiger_vendorRel on vtiger_vendorRel.vendorid = vtiger_products.vendor_id
 					left join vtiger_seproductsrel on vtiger_seproductsrel.productid = vtiger_products.productid
 					left join vtiger_crmentity as vtiger_crmentityRelProducts on vtiger_crmentityRelProducts.crmid = vtiger_seproductsrel.crmid
@@ -1146,7 +1149,6 @@
 					left join vtiger_crmentity as vtiger_crmentityProducts on vtiger_crmentityProducts.crmid=vtiger_products.productid
 					left join vtiger_productcf on vtiger_products.productid = vtiger_productcf.productid
 					left join vtiger_users as vtiger_usersProducts on vtiger_usersProducts.id = vtiger_crmentityProducts.smownerid
-					left join vtiger_contactdetails as vtiger_contactdetailsProducts on vtiger_contactdetailsProducts.contactid = vtiger_products.contactid 
 					left join vtiger_vendor as vtiger_vendorRel on vtiger_vendorRel.vendorid = vtiger_products.vendor_id
 					left join vtiger_seproductsrel on vtiger_seproductsrel.productid = vtiger_products.productid
 					left join vtiger_crmentity as vtiger_crmentityRelProducts on vtiger_crmentityRelProducts.crmid = vtiger_seproductsrel.crmid
@@ -1215,21 +1217,17 @@
 				where vtiger_crmentityPotentials.deleted=0 ";
 		}
 
+		//For this Product - we can related Accounts, Contacts (Also Leads, Potentials)
 		if($module == "Products")
 		{
 			$query = "from vtiger_products 
 				inner join vtiger_crmentity as vtiger_crmentityProducts on vtiger_crmentityProducts.crmid=vtiger_products.productid 
 				left join vtiger_productcf on vtiger_products.productid = vtiger_productcf.productid 
 				left join vtiger_users as vtiger_usersProducts on vtiger_usersProducts.id = vtiger_crmentityProducts.smownerid 
-				left join vtiger_contactdetails as vtiger_contactdetailsProducts on vtiger_contactdetailsProducts.contactid = vtiger_products.contactid
-				left join vtiger_vendor as vtiger_vendorRel on vtiger_vendorRel.vendorid = vtiger_products.vendor_id  
-				left join vtiger_seproductsrel on vtiger_seproductsrel.productid = vtiger_products.productid 
-				left join vtiger_crmentity as vtiger_crmentityRelProducts on vtiger_crmentityRelProducts.crmid = vtiger_seproductsrel.crmid 
-				left join vtiger_account as vtiger_accountRelProducts on vtiger_accountRelProducts.accountid=vtiger_crmentityRelProducts.crmid 
-				left join vtiger_leaddetails as vtiger_leaddetailsRelProducts on vtiger_leaddetailsRelProducts.leadid = vtiger_crmentityRelProducts.crmid 
-				left join vtiger_potential as vtiger_potentialRelProducts on vtiger_potentialRelProducts.potentialid = vtiger_crmentityRelProducts.crmid 
+				left join vtiger_vendor as vtiger_vendorRel on vtiger_vendorRel.vendorid = vtiger_products.vendor_id 
+				left join vtiger_seproductsrel on vtiger_seproductsrel.productid= vtiger_products.productid and vtiger_seproductsrel.setype='".$this->secondarymodule."'	
 				".$this->getRelatedModulesQuery($module,$this->secondarymodule)."
-				where vtiger_crmentityProducts.deleted=0 ";
+				where vtiger_crmentityProducts.deleted=0";
 		}
 
 		if($module == "HelpDesk")

Modified: vtigercrm/branches/5.0.3/modules/Vendors/updateRelations.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Vendors/updateRelations.php (original)
+++ vtigercrm/branches/5.0.3/modules/Vendors/updateRelations.php Fri Jan 12 04:31:34 2007
@@ -19,7 +19,9 @@
 	$action = "DetailView";
 else
 	$action = "CallRelatedList";
-	
+
+$dest_mod = $_REQUEST['destination_module'];
+
 //This will be true, when we select product from vendor related list
 if($_REQUEST['destination_module']=='Products')
 {
@@ -41,7 +43,7 @@
 		{
 			$sql = "insert into vtiger_vendorcontactrel values (".$_REQUEST["parentid"].",".$id.")";
 			$adb->query($sql);
-			$sql = "insert into vtiger_seproductsrel values (". $_REQUEST["parentid"] .",".$id.")";
+			$sql = "insert into vtiger_seproductsrel values (". $_REQUEST["parentid"] .",".$id.",'".$dest_mod."')";
 			$adb->query($sql);
 		}
 	}
@@ -54,7 +56,7 @@
 
 		$sql = "insert into vtiger_vendorcontactrel values (".$_REQUEST['parid'].",".$_REQUEST['entityid'].")";
 		$adb->query($sql);
-		$sql = "insert into vtiger_seproductsrel values (". $_REQUEST["parid"] .",".$_REQUEST["entityid"] .")";
+		$sql = "insert into vtiger_seproductsrel values (". $_REQUEST["parid"] .",".$_REQUEST["entityid"] .",'".$dest_mod."')";
 		$adb->query($sql);
 		
 		$record = $_REQUEST["parid"];

Modified: vtigercrm/branches/5.0.3/schema/DatabaseSchema.xml
==============================================================================
--- vtigercrm/branches/5.0.3/schema/DatabaseSchema.xml (original)
+++ vtigercrm/branches/5.0.3/schema/DatabaseSchema.xml Fri Jan 12 04:31:34 2007
@@ -1870,6 +1870,9 @@
 			<key />
 			<default value="0" />
 		</field>
+		<field name="setype" type="C" size="30">
+			<notnull />
+		</field>
 
 		<index name="seproductsrel_productid_idx">
 			<col>productid</col>





More information about the vtigercrm-commits mailing list