[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/modules/SalesOrder/ -> CreateSOPDF.php (source)

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


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7