[Vtigercrm-commits] [vtiger-commits] r9295 - in /vtigercrm/trunk/modules: PurchaseOrder/CreatePDF.php Quotes/CreatePDF.php SalesOrder/CreateSOPDF.php

vtigercrm-commits at vtiger.fosslabs.com vtigercrm-commits at vtiger.fosslabs.com
Tue Sep 5 13:52:38 EDT 2006


Author: saraj
Date: Tue Sep  5 11:52:32 2006
New Revision: 9295

Log:
* Modified to display the product and tax details

Modified:
    vtigercrm/trunk/modules/PurchaseOrder/CreatePDF.php
    vtigercrm/trunk/modules/Quotes/CreatePDF.php
    vtigercrm/trunk/modules/SalesOrder/CreateSOPDF.php

Modified: vtigercrm/trunk/modules/PurchaseOrder/CreatePDF.php
==============================================================================
--- vtigercrm/trunk/modules/PurchaseOrder/CreatePDF.php (original)
+++ vtigercrm/trunk/modules/PurchaseOrder/CreatePDF.php Tue Sep  5 11:52:32 2006
@@ -78,62 +78,114 @@
 		$logo_name = $adb->query_result($result,0,"logoname");
 }
 
-//getting the Total Array
-$price_subtotal = $currency_symbol.number_format(StripLastZero($focus->column_fields["hdnSubTotal"]),2,'.',',');
-$price_tax = $currency_symbol.number_format(StripLastZero($focus->column_fields["txtTax"]),2,'.',',');
-$price_adjustment = $currency_symbol.number_format(StripLastZero($focus->column_fields["txtAdjustment"]),2,'.',',');
-$price_total = $currency_symbol.number_format(StripLastZero($focus->column_fields["hdnGrandTotal"]),2,'.',',');
-
-//getting the Product Data
-$query="select vtiger_products.productname, vtiger_products.unit_price, vtiger_products.product_description, vtiger_inventoryproductrel.* from vtiger_inventoryproductrel inner join vtiger_products on vtiger_products.productid=vtiger_inventoryproductrel.productid where id=".$id;
-
-global $result;
-$result = $adb->query($query);
-$num_products=$adb->num_rows($result);
-for($i=0;$i<$num_products;$i++) {
-	$product_name[$i]=$adb->query_result($result,$i,'productname');
-	$prod_description[$i]=$adb->query_result($result,$i,'product_description');
-	$product_id[$i]=$adb->query_result($result,$i,'productid');
-	$qty[$i]=$adb->query_result($result,$i,'quantity');
-
-	$unit_price[$i]= $currency_symbol.number_format($adb->query_result($result,$i,'unit_price'),2,'.',',');
-	$list_price[$i]= $currency_symbol.number_format(StripLastZero($adb->query_result($result,$i,'listprice')),2,'.',',');
-	$list_pricet[$i]= $adb->query_result($result,$i,'listprice');
-	$prod_total[$i]= $qty[$i]*$list_pricet[$i];
-
-        $total_taxes = '0.00';
-        if($product_taxes == "true") {
-                $q = "SELECT * FROM vtiger_inventoryproductrel WHERE id='".$focus->column_fields["record_id"]."' AND productid='".$product_id[$i]."' AND tax2 IS NOT NULL";
-                $trs = $adb->query($q);
-                $tax = $adb->query_result($trs,'0','tax2');
-                $taxable_total = ($adb->query_result($trs,'0','listprice') * $adb->query_result($trs,'0','quantity'));
-                if($tax != "") {
-                        $total_taxes = ($taxable_total/$tax);
-                        $prod_total[$i] = ($prod_total[$i]+$total_taxes);
-                }
-        }
-
-        $product_line[] = array( "Product Name"    => $product_name[$i],
-                "Description"  => $prod_description[$i],
-                "Qty"     => $qty[$i],
-                "List Price"      => $list_price[$i],
-                "Unit Price" => $unit_price[$i],
-                "Tax" => $currency_symbol.$total_taxes,
-                "Total" => $currency_symbol.$prod_total[$i]
-        );
-}
-
-	$total[]=array("Unit Price" => $app_strings['LBL_SUB_TOTAL'],
-		"Total" => $price_subtotal);
-
-	$total[]=array("Unit Price" => $app_strings['LBL_ADJUSTMENT'],
-		"Total" => $price_adjustment);
-
-	$total[]=array("Unit Price" => $app_strings['LBL_TAX'],
-		"Total" => $price_tax);
-
-	$total[]=array("Unit Price" => $app_strings['LBL_GRAND_TOTAL'],
-		"Total" => $price_total);
+//Population of Product Details - Starts
+
+//we can cut and paste the following lines in a file and include that file here is enough. For that we have to put a new common file. we will do this later
+//NOTE : Removed currency symbols and added with Grand Total text. it is enough to show the currency symbol in one place
+
+//we can also get the NetTotal, Final Discount Amount/Percent, Adjustment and GrandTotal from the array $associated_products[1]['final_details']
+
+//getting the Net Total
+$price_subtotal = number_format($focus->column_fields["hdnSubTotal"],2,'.',',');
+
+//Final discount amount/percentage
+$discount_amount = $focus->column_fields["hdnDiscountAmount"];
+$discount_percent = $focus->column_fields["hdnDiscountPercent"];
+
+if($discount_amount != "")
+	$price_discount = number_format($discount_amount,2,'.',',');
+else if($discount_percent != "")
+	$price_discount = $discount_percent."%";
+else
+	$price_discount = "0.00";
+
+//Adjustment
+$price_adjustment = number_format($focus->column_fields["txtAdjustment"],2,'.',',');
+//Grand Total
+$price_total = number_format($focus->column_fields["hdnGrandTotal"],2,'.',',');
+
+
+//get the Associated Products for this Invoice
+$focus->id = $focus->column_fields["record_id"];
+$associated_products = getAssociatedProducts("PurchaseOrder",$focus);
+$num_products = count($associated_products);
+
+//This $final_details array will contain the final total, discount, Group Tax, S&H charge, S&H taxes and adjustment
+$final_details = $associated_products[1]['final_details'];
+
+//To calculate the group tax amount
+if($final_details['taxtype'] == 'group')
+{
+	$group_tax_total = $final_details['tax_totalamount'];
+	$price_salestax = number_format($group_tax_total,2,'.',',');
+
+	$group_total_tax_percent = '0.00';
+	$group_tax_details = $final_details['taxes'];
+	for($i=0;$i<count($group_tax_details);$i++)
+	{
+		$group_total_tax_percent = $group_total_tax_percent+$group_tax_details[$i]['percentage'];
+	}
+}
+
+//S&H amount
+$sh_amount = $final_details['shipping_handling_charge'];
+$price_shipping = number_format($sh_amount,2,'.',',');
+
+//S&H taxes
+$sh_tax_details = $final_details['sh_taxes'];
+$sh_tax_percent = '0.00';
+for($i=0;$i<count($sh_tax_details);$i++)
+{
+	$sh_tax_percent = $sh_tax_percent + $sh_tax_details[$i]['percentage'];
+}
+$sh_tax_amount = $final_details['shtax_totalamount'];
+$price_shipping_tax = number_format($sh_tax_amount,2,'.',',');
+
+
+//This is to get all prodcut details as row basis
+for($i=1,$j=$i-1;$i<=$num_products;$i++,$j++)
+{
+	$product_name[$i] = $associated_products[$i]['productName'.$i];
+	$prod_description[$i] = $associated_products[$i]['productDescription'.$i];
+	$product_id[$i] = $associated_products[$i]['hdnProductId'.$i];
+	$qty[$i] = $associated_products[$i]['qty'.$i];
+	$unit_price[$i] = number_format($associated_products[$i]['unitPrice'.$i],2,'.',',');
+	$list_price[$i] = number_format($associated_products[$i]['listPrice'.$i],2,'.',',');
+	$list_pricet[$i] = $associated_products[$i]['listPrice'.$i];
+	$discount_total[$i] = $associated_products[$i]['discountTotal'.$i];
+	
+	$taxable_total = $qty[$i]*$list_pricet[$i]-$discount_total[$i];
+
+	$producttotal = $taxable_total;
+	$total_taxes = '0.00';
+	if($focus->column_fields["hdnTaxType"] == "individual")
+	{
+		$total_tax_percent = '0.00';
+		//This loop is to get all tax percentage and then calculate the total of all taxes
+		for($tax_count=0;$tax_count<count($associated_products[$i]['taxes']);$tax_count++)
+		{
+			$tax_percent = $associated_products[$i]['taxes'][$tax_count]['percentage'];
+			$total_tax_percent = $total_tax_percent+$tax_percent;
+			$tax_amount = (($taxable_total*$tax_percent)/100);
+			$total_taxes = $total_taxes+$tax_amount;
+		}
+		$producttotal = $taxable_total+$total_taxes;
+		$product_line[$j]["Tax"] = number_format($total_taxes,2,'.',',')."\n ($total_tax_percent %) ";
+	}
+	$prod_total[$i] = number_format($producttotal,2,'.',',');
+
+	$product_line[$j]["Product Name"] = $product_name[$i];
+	$product_line[$j]["Description"] = $prod_description[$i];
+	$product_line[$j]["Qty"] = $qty[$i];
+	$product_line[$j]["Price"] = $list_price[$i];
+	$product_line[$j]["Discount"] = $discount_total[$i];
+	$product_line[$j]["Total"] = $prod_total[$i];
+}
+//echo '<pre>Product Details ==>';print_r($product_line);echo '</pre>';
+//echo '<pre>';print_r($associated_products);echo '</pre>';
+
+
+//Population of Product Details - Ends
 
 
 // ************************ END POPULATE DATA ***************************8

Modified: vtigercrm/trunk/modules/Quotes/CreatePDF.php
==============================================================================
--- vtigercrm/trunk/modules/Quotes/CreatePDF.php (original)
+++ vtigercrm/trunk/modules/Quotes/CreatePDF.php Tue Sep  5 11:52:32 2006
@@ -78,67 +78,115 @@
 		$logo_name = $adb->query_result($result,0,"logoname");
 }
 
-//getting the Total Array
-$price_subtotal = $currency_symbol.number_format(StripLastZero($focus->column_fields["hdnSubTotal"]),2,'.',',');
-$price_tax = $currency_symbol.number_format(StripLastZero($focus->column_fields["txtTax"]),2,'.',',');
-$price_adjustment = $currency_symbol.number_format(StripLastZero($focus->column_fields["txtAdjustment"]),2,'.',',');
-$price_total = $currency_symbol.number_format(StripLastZero($focus->column_fields["hdnGrandTotal"]),2,'.',',');
-
-//getting the Product Data
-// DG 15 Aug 2006
-// Add "ORDER BY sequence_no to preserve add order in printed version
-// Seems not to be strictly necessary as the upstream ORDER BY in EditView appears to produce this behaviour by default
-// Having this here makes sure though. 
-$query="select vtiger_products.productname, vtiger_products.unit_price, vtiger_products.product_description, vtiger_inventoryproductrel.* from vtiger_inventoryproductrel inner join vtiger_products on vtiger_products.productid=vtiger_inventoryproductrel.productid where id=".$quote_id." ORDER BY sequence_no";
-//$query="select vtiger_products.productname, vtiger_products.unit_price, vtiger_products.product_description, vtiger_inventoryproductrel.* from vtiger_inventoryproductrel inner join vtiger_products on vtiger_products.productid=vtiger_inventoryproductrel.productid where id=".$quote_id;
-
-global $result;
-$result = $adb->query($query);
-$num_products=$adb->num_rows($result);
-for($i=0;$i<$num_products;$i++) {
-	$product_name[$i]=$adb->query_result($result,$i,'productname');
-	$prod_description[$i]=$adb->query_result($result,$i,'product_description');
-	$product_id[$i]=$adb->query_result($result,$i,'productid');
-	$qty[$i]=$adb->query_result($result,$i,'quantity');
-
-	$unit_price[$i]= $currency_symbol.number_format($adb->query_result($result,$i,'unit_price'),2,'.',',');
-	$list_price[$i]= $currency_symbol.number_format(StripLastZero($adb->query_result($result,$i,'listprice')),2,'.',',');
-	$list_pricet[$i]= $adb->query_result($result,$i,'listprice');
-	$prod_total[$i]= $qty[$i]*$list_pricet[$i];
-
-        $total_taxes = '0.00';
-        if($product_taxes == "true") {
-                $q = "SELECT * FROM vtiger_inventoryproductrel WHERE id='".$focus->column_fields["record_id"]."' AND productid='".$product_id[$i]."' AND tax2 IS NOT NULL";
-                $trs = $adb->query($q);
-                $tax = $adb->query_result($trs,'0','tax2');
-                $taxable_total = ($adb->query_result($trs,'0','listprice') * $adb->query_result($trs,'0','quantity'));
-                if($tax != "") {
-                        $total_taxes = ($taxable_total/$tax);
-                        $prod_total[$i] = ($prod_total[$i]+$total_taxes);
-                }
-        }
-
-        $product_line[] = array( "Product Name"    => $product_name[$i],
-                "Description"  => $prod_description[$i],
-                "Qty"     => $qty[$i],
-                "List Price"      => $list_price[$i],
-                "Unit Price" => $unit_price[$i],
-                "Tax" => $currency_symbol.$total_taxes,
-                "Total" => $currency_symbol.$prod_total[$i]
-        );
-}
-
-	$total[]=array("Unit Price" => $app_strings['LBL_SUB_TOTAL'],
-		"Total" => $price_subtotal);
-
-	$total[]=array("Unit Price" => $app_strings['LBL_ADJUSTMENT'],
-		"Total" => $price_adjustment);
-
-	$total[]=array("Unit Price" => $app_strings['LBL_TAX'],
-		"Total" => $price_tax);
-
-	$total[]=array("Unit Price" => $app_strings['LBL_GRAND_TOTAL'],
-		"Total" => $price_total);
+
+//Population of Product Details - Starts
+
+//we can cut and paste the following lines in a file and include that file here is enough. For that we have to put a new common file. we will do this later
+//NOTE : Removed currency symbols and added with Grand Total text. it is enough to show the currency symbol in one place
+
+//we can also get the NetTotal, Final Discount Amount/Percent, Adjustment and GrandTotal from the array $associated_products[1]['final_details']
+
+//getting the Net Total
+$price_subtotal = number_format($focus->column_fields["hdnSubTotal"],2,'.',',');
+
+//Final discount amount/percentage
+$discount_amount = $focus->column_fields["hdnDiscountAmount"];
+$discount_percent = $focus->column_fields["hdnDiscountPercent"];
+
+if($discount_amount != "")
+	$price_discount = number_format($discount_amount,2,'.',',');
+else if($discount_percent != "")
+	$price_discount = $discount_percent."%";
+else
+	$price_discount = "0.00";
+
+//Adjustment
+$price_adjustment = number_format($focus->column_fields["txtAdjustment"],2,'.',',');
+//Grand Total
+$price_total = number_format($focus->column_fields["hdnGrandTotal"],2,'.',',');
+
+
+//get the Associated Products for this Invoice
+$focus->id = $focus->column_fields["record_id"];
+$associated_products = getAssociatedProducts("Quotes",$focus);
+$num_products = count($associated_products);
+
+//This $final_details array will contain the final total, discount, Group Tax, S&H charge, S&H taxes and adjustment
+$final_details = $associated_products[1]['final_details'];
+
+//To calculate the group tax amount
+if($final_details['taxtype'] == 'group')
+{
+	$group_tax_total = $final_details['tax_totalamount'];
+	$price_salestax = number_format($group_tax_total,2,'.',',');
+
+	$group_total_tax_percent = '0.00';
+	$group_tax_details = $final_details['taxes'];
+	for($i=0;$i<count($group_tax_details);$i++)
+	{
+		$group_total_tax_percent = $group_total_tax_percent+$group_tax_details[$i]['percentage'];
+	}
+}
+
+//S&H amount
+$sh_amount = $final_details['shipping_handling_charge'];
+$price_shipping = number_format($sh_amount,2,'.',',');
+
+//S&H taxes
+$sh_tax_details = $final_details['sh_taxes'];
+$sh_tax_percent = '0.00';
+for($i=0;$i<count($sh_tax_details);$i++)
+{
+	$sh_tax_percent = $sh_tax_percent + $sh_tax_details[$i]['percentage'];
+}
+$sh_tax_amount = $final_details['shtax_totalamount'];
+$price_shipping_tax = number_format($sh_tax_amount,2,'.',',');
+
+
+//This is to get all prodcut details as row basis
+for($i=1,$j=$i-1;$i<=$num_products;$i++,$j++)
+{
+	$product_name[$i] = $associated_products[$i]['productName'.$i];
+	$prod_description[$i] = $associated_products[$i]['productDescription'.$i];
+	$product_id[$i] = $associated_products[$i]['hdnProductId'.$i];
+	$qty[$i] = $associated_products[$i]['qty'.$i];
+	$unit_price[$i] = number_format($associated_products[$i]['unitPrice'.$i],2,'.',',');
+	$list_price[$i] = number_format($associated_products[$i]['listPrice'.$i],2,'.',',');
+	$list_pricet[$i] = $associated_products[$i]['listPrice'.$i];
+	$discount_total[$i] = $associated_products[$i]['discountTotal'.$i];
+	
+	$taxable_total = $qty[$i]*$list_pricet[$i]-$discount_total[$i];
+
+	$producttotal = $taxable_total;
+	$total_taxes = '0.00';
+	if($focus->column_fields["hdnTaxType"] == "individual")
+	{
+		$total_tax_percent = '0.00';
+		//This loop is to get all tax percentage and then calculate the total of all taxes
+		for($tax_count=0;$tax_count<count($associated_products[$i]['taxes']);$tax_count++)
+		{
+			$tax_percent = $associated_products[$i]['taxes'][$tax_count]['percentage'];
+			$total_tax_percent = $total_tax_percent+$tax_percent;
+			$tax_amount = (($taxable_total*$tax_percent)/100);
+			$total_taxes = $total_taxes+$tax_amount;
+		}
+		$producttotal = $taxable_total+$total_taxes;
+		$product_line[$j]["Tax"] = number_format($total_taxes,2,'.',',')."\n ($total_tax_percent %) ";
+	}
+	$prod_total[$i] = number_format($producttotal,2,'.',',');
+
+	$product_line[$j]["Product Name"] = $product_name[$i];
+	$product_line[$j]["Description"] = $prod_description[$i];
+	$product_line[$j]["Qty"] = $qty[$i];
+	$product_line[$j]["Price"] = $list_price[$i];
+	$product_line[$j]["Discount"] = $discount_total[$i];
+	$product_line[$j]["Total"] = $prod_total[$i];
+}
+//echo '<pre>Product Details ==>';print_r($product_line);echo '</pre>';
+//echo '<pre>';print_r($associated_products);echo '</pre>';
+
+
+//Population of Product Details - Ends
 
 
 // ************************ END POPULATE DATA ***************************8

Modified: vtigercrm/trunk/modules/SalesOrder/CreateSOPDF.php
==============================================================================
--- vtigercrm/trunk/modules/SalesOrder/CreateSOPDF.php (original)
+++ vtigercrm/trunk/modules/SalesOrder/CreateSOPDF.php Tue Sep  5 11:52:32 2006
@@ -77,90 +77,115 @@
 		$logo_name = $adb->query_result($result,0,"logoname");
 }
 
-//getting the Total Array
-$price_subtotal = $currency_symbol.number_format($focus->column_fields["hdnSubTotal"],2,'.',',');
-$price_salestax = $focus->column_fields["txtTax"]."%";
-if($price_salestax != "")
-        $price_salestax = $currency_symbol."0.00";
-
+//Population of Product Details - Starts
+
+//we can cut and paste the following lines in a file and include that file here is enough. For that we have to put a new common file. we will do this later
+//NOTE : Removed currency symbols and added with Grand Total text. it is enough to show the currency symbol in one place
+
+//we can also get the NetTotal, Final Discount Amount/Percent, Adjustment and GrandTotal from the array $associated_products[1]['final_details']
+
+//getting the Net Total
+$price_subtotal = number_format($focus->column_fields["hdnSubTotal"],2,'.',',');
+
+//Final discount amount/percentage
 $discount_amount = $focus->column_fields["hdnDiscountAmount"];
 $discount_percent = $focus->column_fields["hdnDiscountPercent"];
 
-$price_shipping = $currency_symbol.number_format($focus->column_fields["hdnS_H_Amount"],2,'.',',');
-if($price_shipping > 0 || price_shipping == "")
-        $price_shipping = $currency_symbol."0.00";
-
-$q = "SELECT * FROM vtiger_inventoryshippingrel WHERE id='".$focus->column_fields["record_id"]."'";
-$shrs = $adb->query($q);
-$shtax1 = $adb->query_result($shrs,'0','shtax1');
-$shtax2 = $adb->query_result($shrs,'0','shtax2');
-$shtax3 = $adb->query_result($shrs,'0','shtax3');
-if($shtax1 != "" && $shtax1 != "0.00")
-        $price_shipping_tax = number_format($shtax1,2,'.',',')."%";
-if($shtax2 != "" && $shtax2 != "0.00")
-        $price_shipping_tax = number_format($shtax2,2,'.',',')."%";
-if($shtax3 != "" && $shtax3 != "0.00")
-        $price_shipping_tax = number_format($shtax3,2,'.',',')."%";
-
-
 if($discount_amount != "")
-        $price_discount = $currency_symbol.number_format($discount_amount,2,'.',',');
+	$price_discount = number_format($discount_amount,2,'.',',');
 else if($discount_percent != "")
-        $price_discount = $discount_percent."%";
+	$price_discount = $discount_percent."%";
 else
-        $price_discount = $currency_symbol."0.00";
-
-
-$price_adjustment = $currency_symbol.number_format($focus->column_fields["txtAdjustment"],2,'.',',');
-$price_total = $currency_symbol.number_format($focus->column_fields["hdnGrandTotal"],2,'.',',');
-
-//getting the Product Data
-$query="select vtiger_products.productname, vtiger_products.unit_price, vtiger_products.product_description, vtiger_inventoryproductrel.* from vtiger_inventoryproductrel inner join vtiger_products on vtiger_products.productid=vtiger_inventoryproductrel.productid where id=".$id;
-
-global $result;
-$result = $adb->query($query);
-$num_products=$adb->num_rows($result);
-for($i=0;$i<$num_products;$i++) {
-	$product_name[$i]=$adb->query_result($result,$i,'productname');
-	$prod_description[$i]=$adb->query_result($result,$i,'product_description');
-	$product_id[$i]=$adb->query_result($result,$i,'productid');
-	$qty[$i]=$adb->query_result($result,$i,'quantity');
-
-	$unit_price[$i]= $currency_symbol.number_format($adb->query_result($result,$i,'unit_price'),2,'.',',');
-	$list_price[$i]= $currency_symbol.number_format(StripLastZero($adb->query_result($result,$i,'listprice')),2,'.',',');
-	$list_pricet[$i]= $adb->query_result($result,$i,'listprice');
-	$prod_total[$i]= $qty[$i]*$list_pricet[$i];
-
-        $total_taxes = '0.00';
-        if($focus->column_fields["hdnTaxType"] == "individual") {
-                $q = "SELECT * FROM vtiger_inventoryproductrel WHERE id='".$focus->column_fields["record_id"]."' AND productid='".$product_id[$i]."'";
-                $trs = $adb->query($q);
-                $tax1 = $adb->query_result($trs,'0','tax1');
-                $tax2 = $adb->query_result($trs,'0','tax2');
-                $tax3 = $adb->query_result($trs,'0','tax3');
-                $taxable_total = ($adb->query_result($trs,'0','listprice') * $adb->query_result($trs,'0','quantity'));
-
-                if($tax1 != "" && $tax1 > 0) {
-                        $total_taxes = (($taxable_total*$tax1)/100);
-                        $prod_total[$i] = ($prod_total[$i]+$total_taxes);
-                }
-                if($tax2 != "" && $tax2 > 0) {
-                        $total_taxes = (($taxable_total*$tax2)/100);
-                        $prod_total[$i] = ($prod_total[$i]+$total_taxes);
-                }
-                if($tax3 != "" && $tax3 > 0) {
-                        $total_taxes = (($taxable_total*$tax3)/100);
-                        $prod_total[$i] = ($prod_total[$i]+$total_taxes);
-                }
-                $product_line[$i]["Tax"] = $total_taxes."%";
-        }
-        $product_line[$i]["Product Name"] = $product_name[$i];
-        $product_line[$i]["Description"] = $prod_description[$i];
-        $product_line[$i]["Qty"] = $qty[$i];
-        $product_line[$i]["Price"] = $list_price[$i];
-        $product_line[$i]["Total"] = $currency_symbol.number_format($prod_total[$i],"2",".",",");
-
-}
+	$price_discount = "0.00";
+
+//Adjustment
+$price_adjustment = number_format($focus->column_fields["txtAdjustment"],2,'.',',');
+//Grand Total
+$price_total = number_format($focus->column_fields["hdnGrandTotal"],2,'.',',');
+
+
+//get the Associated Products for this Invoice
+$focus->id = $focus->column_fields["record_id"];
+$associated_products = getAssociatedProducts("SalesOrder",$focus);
+$num_products = count($associated_products);
+
+//This $final_details array will contain the final total, discount, Group Tax, S&H charge, S&H taxes and adjustment
+$final_details = $associated_products[1]['final_details'];
+
+//To calculate the group tax amount
+if($final_details['taxtype'] == 'group')
+{
+	$group_tax_total = $final_details['tax_totalamount'];
+	$price_salestax = number_format($group_tax_total,2,'.',',');
+
+	$group_total_tax_percent = '0.00';
+	$group_tax_details = $final_details['taxes'];
+	for($i=0;$i<count($group_tax_details);$i++)
+	{
+		$group_total_tax_percent = $group_total_tax_percent+$group_tax_details[$i]['percentage'];
+	}
+}
+
+//S&H amount
+$sh_amount = $final_details['shipping_handling_charge'];
+$price_shipping = number_format($sh_amount,2,'.',',');
+
+//S&H taxes
+$sh_tax_details = $final_details['sh_taxes'];
+$sh_tax_percent = '0.00';
+for($i=0;$i<count($sh_tax_details);$i++)
+{
+	$sh_tax_percent = $sh_tax_percent + $sh_tax_details[$i]['percentage'];
+}
+$sh_tax_amount = $final_details['shtax_totalamount'];
+$price_shipping_tax = number_format($sh_tax_amount,2,'.',',');
+
+
+//This is to get all prodcut details as row basis
+for($i=1,$j=$i-1;$i<=$num_products;$i++,$j++)
+{
+	$product_name[$i] = $associated_products[$i]['productName'.$i];
+	$prod_description[$i] = $associated_products[$i]['productDescription'.$i];
+	$product_id[$i] = $associated_products[$i]['hdnProductId'.$i];
+	$qty[$i] = $associated_products[$i]['qty'.$i];
+	$unit_price[$i] = number_format($associated_products[$i]['unitPrice'.$i],2,'.',',');
+	$list_price[$i] = number_format($associated_products[$i]['listPrice'.$i],2,'.',',');
+	$list_pricet[$i] = $associated_products[$i]['listPrice'.$i];
+	$discount_total[$i] = $associated_products[$i]['discountTotal'.$i];
+	
+	$taxable_total = $qty[$i]*$list_pricet[$i]-$discount_total[$i];
+
+	$producttotal = $taxable_total;
+	$total_taxes = '0.00';
+	if($focus->column_fields["hdnTaxType"] == "individual")
+	{
+		$total_tax_percent = '0.00';
+		//This loop is to get all tax percentage and then calculate the total of all taxes
+		for($tax_count=0;$tax_count<count($associated_products[$i]['taxes']);$tax_count++)
+		{
+			$tax_percent = $associated_products[$i]['taxes'][$tax_count]['percentage'];
+			$total_tax_percent = $total_tax_percent+$tax_percent;
+			$tax_amount = (($taxable_total*$tax_percent)/100);
+			$total_taxes = $total_taxes+$tax_amount;
+		}
+		$producttotal = $taxable_total+$total_taxes;
+		$product_line[$j]["Tax"] = number_format($total_taxes,2,'.',',')."\n ($total_tax_percent %) ";
+	}
+	$prod_total[$i] = number_format($producttotal,2,'.',',');
+
+	$product_line[$j]["Product Name"] = $product_name[$i];
+	$product_line[$j]["Description"] = $prod_description[$i];
+	$product_line[$j]["Qty"] = $qty[$i];
+	$product_line[$j]["Price"] = $list_price[$i];
+	$product_line[$j]["Discount"] = $discount_total[$i];
+	$product_line[$j]["Total"] = $prod_total[$i];
+}
+//echo '<pre>Product Details ==>';print_r($product_line);echo '</pre>';
+//echo '<pre>';print_r($associated_products);echo '</pre>';
+
+
+//Population of Product Details - Ends
+
 
 // ************************ END POPULATE DATA ***************************8
 





More information about the vtigercrm-commits mailing list