[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

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


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