[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 * 10 ********************************************************************************/ 11 12 require ('include/fpdf/pdf.php'); 13 require_once ('modules/PurchaseOrder/PurchaseOrder.php'); 14 require_once ('include/database/PearDatabase.php'); 15 16 global $adb,$app_strings; 17 18 $sql="select currency_symbol from vtiger_currency_info"; 19 $result = $adb->query($sql); 20 $currency_symbol = $adb->query_result($result,0,'currency_symbol'); 21 22 // would you like and end page? 1 for yes 0 for no 23 $endpage="1"; 24 global $products_per_page; 25 $products_per_page="6"; 26 27 $id = $_REQUEST['record']; 28 //retreiving the vtiger_invoice info 29 $focus = new PurchaseOrder(); 30 $focus->retrieve_entity_info($_REQUEST['record'],"PurchaseOrder"); 31 $vendor_name = getVendorName($focus->column_fields[vendor_id]); 32 33 if($focus->column_fields["hdnTaxType"] == "individual") { 34 $product_taxes = 'true'; 35 } else { 36 $product_taxes = 'false'; 37 } 38 39 // **************** BEGIN POPULATE DATA ******************** 40 $reqno = $focus->column_fields["requisition_no"]; 41 $trno = $focus->column_fields["tracking_no"]; 42 43 $valid_till = $focus->column_fields["duedate"]; 44 $valid_till = getDisplayDate($valid_till); 45 $bill_street = $focus->column_fields["bill_street"]; 46 $bill_city = $focus->column_fields["bill_city"]; 47 $bill_state = $focus->column_fields["bill_state"]; 48 $bill_code = $focus->column_fields["bill_code"]; 49 $bill_country = $focus->column_fields["bill_country"]; 50 51 $ship_street = $focus->column_fields["ship_street"]; 52 $ship_city = $focus->column_fields["ship_city"]; 53 $ship_state = $focus->column_fields["ship_state"]; 54 $ship_code = $focus->column_fields["ship_code"]; 55 $ship_country = $focus->column_fields["ship_country"]; 56 57 $conditions = $focus->column_fields["terms_conditions"]; 58 $description = $focus->column_fields["description"]; 59 $status = $focus->column_fields["postatus"]; 60 61 // Company information 62 $add_query = "select * from vtiger_organizationdetails"; 63 $result = $adb->query($add_query); 64 $num_rows = $adb->num_rows($result); 65 66 if($num_rows == 1) 67 { 68 $org_name = $adb->query_result($result,0,"organizationname"); 69 $org_address = $adb->query_result($result,0,"address"); 70 $org_city = $adb->query_result($result,0,"city"); 71 $org_state = $adb->query_result($result,0,"state"); 72 $org_country = $adb->query_result($result,0,"country"); 73 $org_code = $adb->query_result($result,0,"code"); 74 $org_phone = $adb->query_result($result,0,"phone"); 75 $org_fax = $adb->query_result($result,0,"fax"); 76 $org_website = $adb->query_result($result,0,"website"); 77 78 $logo_name = $adb->query_result($result,0,"logoname"); 79 } 80 81 //Population of Product Details - Starts 82 83 //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 84 //NOTE : Removed currency symbols and added with Grand Total text. it is enough to show the currency symbol in one place 85 86 //we can also get the NetTotal, Final Discount Amount/Percent, Adjustment and GrandTotal from the array $associated_products[1]['final_details'] 87 88 //getting the Net Total 89 $price_subtotal = number_format($focus->column_fields["hdnSubTotal"],2,'.',','); 90 91 //Final discount amount/percentage 92 $discount_amount = $focus->column_fields["hdnDiscountAmount"]; 93 $discount_percent = $focus->column_fields["hdnDiscountPercent"]; 94 95 if($discount_amount != "") 96 $price_discount = number_format($discount_amount,2,'.',','); 97 else if($discount_percent != "") 98 $price_discount = $discount_percent."%"; 99 else 100 $price_discount = "0.00"; 101 102 //Adjustment 103 $price_adjustment = number_format($focus->column_fields["txtAdjustment"],2,'.',','); 104 //Grand Total 105 $price_total = number_format($focus->column_fields["hdnGrandTotal"],2,'.',','); 106 107 108 //get the Associated Products for this Invoice 109 $focus->id = $focus->column_fields["record_id"]; 110 $associated_products = getAssociatedProducts("PurchaseOrder",$focus); 111 $num_products = count($associated_products); 112 113 //This $final_details array will contain the final total, discount, Group Tax, S&H charge, S&H taxes and adjustment 114 $final_details = $associated_products[1]['final_details']; 115 116 //To calculate the group tax amount 117 if($final_details['taxtype'] == 'group') 118 { 119 $group_tax_total = $final_details['tax_totalamount']; 120 $price_salestax = number_format($group_tax_total,2,'.',','); 121 122 $group_total_tax_percent = '0.00'; 123 $group_tax_details = $final_details['taxes']; 124 for($i=0;$i<count($group_tax_details);$i++) 125 { 126 $group_total_tax_percent = $group_total_tax_percent+$group_tax_details[$i]['percentage']; 127 } 128 } 129 130 //S&H amount 131 $sh_amount = $final_details['shipping_handling_charge']; 132 $price_shipping = number_format($sh_amount,2,'.',','); 133 134 //S&H taxes 135 $sh_tax_details = $final_details['sh_taxes']; 136 $sh_tax_percent = '0.00'; 137 for($i=0;$i<count($sh_tax_details);$i++) 138 { 139 $sh_tax_percent = $sh_tax_percent + $sh_tax_details[$i]['percentage']; 140 } 141 $sh_tax_amount = $final_details['shtax_totalamount']; 142 $price_shipping_tax = number_format($sh_tax_amount,2,'.',','); 143 144 145 //This is to get all prodcut details as row basis 146 for($i=1,$j=$i-1;$i<=$num_products;$i++,$j++) 147 { 148 $product_name[$i] = $associated_products[$i]['productName'.$i]; 149 $prod_description[$i] = $associated_products[$i]['productDescription'.$i]; 150 $product_id[$i] = $associated_products[$i]['hdnProductId'.$i]; 151 $qty[$i] = $associated_products[$i]['qty'.$i]; 152 $unit_price[$i] = number_format($associated_products[$i]['unitPrice'.$i],2,'.',','); 153 $list_price[$i] = number_format($associated_products[$i]['listPrice'.$i],2,'.',','); 154 $list_pricet[$i] = $associated_products[$i]['listPrice'.$i]; 155 $discount_total[$i] = $associated_products[$i]['discountTotal'.$i]; 156 157 $taxable_total = $qty[$i]*$list_pricet[$i]-$discount_total[$i]; 158 159 $producttotal = $taxable_total; 160 $total_taxes = '0.00'; 161 if($focus->column_fields["hdnTaxType"] == "individual") 162 { 163 $total_tax_percent = '0.00'; 164 //This loop is to get all tax percentage and then calculate the total of all taxes 165 for($tax_count=0;$tax_count<count($associated_products[$i]['taxes']);$tax_count++) 166 { 167 $tax_percent = $associated_products[$i]['taxes'][$tax_count]['percentage']; 168 $total_tax_percent = $total_tax_percent+$tax_percent; 169 $tax_amount = (($taxable_total*$tax_percent)/100); 170 $total_taxes = $total_taxes+$tax_amount; 171 } 172 $producttotal = $taxable_total+$total_taxes; 173 $product_line[$j]["Tax"] = number_format($total_taxes,2,'.',',')."\n ($total_tax_percent %) "; 174 } 175 $prod_total[$i] = number_format($producttotal,2,'.',','); 176 177 $product_line[$j]["Product Name"] = $product_name[$i]; 178 $product_line[$j]["Description"] = $prod_description[$i]; 179 $product_line[$j]["Qty"] = $qty[$i]; 180 $product_line[$j]["Price"] = $list_price[$i]; 181 $product_line[$j]["Discount"] = $discount_total[$i]; 182 $product_line[$j]["Total"] = $prod_total[$i]; 183 } 184 //echo '<pre>Product Details ==>';print_r($product_line);echo '</pre>'; 185 //echo '<pre>';print_r($associated_products);echo '</pre>'; 186 187 188 //Population of Product Details - Ends 189 190 191 // ************************ END POPULATE DATA ***************************8 192 193 $page_num='1'; 194 $pdf = new PDF( 'P', 'mm', 'A4' ); 195 $pdf->Open(); 196 197 $num_pages=ceil(($num_products/$products_per_page)); 198 199 200 $current_product=0; 201 for($l=0;$l<$num_pages;$l++) 202 { 203 $line=array(); 204 if($num_pages == $page_num) 205 $lastpage=1; 206 207 while($current_product != $page_num*$products_per_page) 208 { 209 $line[]=$product_line[$current_product]; 210 $current_product++; 211 } 212 213 $pdf->AddPage(); 214 include ("pdf_templates/header.php"); 215 include ("include/fpdf/templates/body.php"); 216 include ("pdf_templates/footer.php"); 217 218 $page_num++; 219 220 if (($endpage) && ($lastpage)) 221 { 222 $pdf->AddPage(); 223 include ("pdf_templates/header.php"); 224 include ("pdf_templates/lastpage/body.php"); 225 include ("pdf_templates/lastpage/footer.php"); 226 } 227 } 228 229 230 $pdf->Output('PurchaseOrder.pdf','D'); //added file name to make it work in IE, also forces the download giving the user the option to save 231 exit(); 232 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |