2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = $_POST['PARAM_0'] == $_POST['PARAM_1'] ?
13 'SA_SALESTRANSVIEW' : 'SA_SALESBULKREP';
14 // ----------------------------------------------------------------
18 // Title: Print Invoices
19 // ----------------------------------------------------------------
22 include_once($path_to_root . "/includes/session.inc");
23 include_once($path_to_root . "/includes/date_functions.inc");
24 include_once($path_to_root . "/includes/data_checks.inc");
25 include_once($path_to_root . "/sales/includes/sales_db.inc");
27 //----------------------------------------------------------------------------------------------------
31 //----------------------------------------------------------------------------------------------------
33 function print_invoices()
35 global $path_to_root, $alternative_tax_include_on_docs, $suppress_tax_rates, $no_zero_lines_amount;
37 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
39 $from = $_POST['PARAM_0'];
40 $to = $_POST['PARAM_1'];
41 $currency = $_POST['PARAM_2'];
42 $email = $_POST['PARAM_3'];
43 $pay_service = $_POST['PARAM_4'];
44 $comments = $_POST['PARAM_5'];
45 $customer = $_POST['PARAM_6'];
46 $orientation = $_POST['PARAM_7'];
48 if (!$from || !$to) return;
50 $orientation = ($orientation ? 'L' : 'P');
51 $dec = user_price_dec();
53 $fno = explode("-", $from);
54 $tno = explode("-", $to);
55 $from = min($fno[0], $tno[0]);
56 $to = max($fno[0], $tno[0]);
58 $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
60 // $headers in doctext.inc
61 $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
63 $params = array('comments' => $comments);
65 $cur = get_company_Pref('curr_default');
68 $rep = new FrontReport(_('INVOICE'), "InvoiceBulk", user_pagesize(), 9, $orientation);
69 if ($orientation == 'L')
70 recalculate_cols($cols);
71 for ($i = $from; $i <= $to; $i++)
73 if (!exists_customer_trans(ST_SALESINVOICE, $i))
76 $myrow = get_customer_trans($i, ST_SALESINVOICE);
78 if($customer && $myrow['debtor_no'] != $customer) {
81 $baccount = get_default_bank_account($myrow['curr_code']);
82 $params['bankaccount'] = $baccount['id'];
84 $branch = get_branch($myrow["branch_code"]);
85 $sales_order = get_sales_order_header($myrow["order_"], ST_SALESORDER);
88 $rep = new FrontReport("", "", user_pagesize(), 9, $orientation);
89 $rep->title = _('INVOICE');
90 $rep->filename = "Invoice" . $myrow['reference'] . ".pdf";
92 $rep->SetHeaderType('Header2');
93 $rep->currency = $cur;
95 $rep->Info($params, $cols, null, $aligns);
97 $contacts = get_branch_contacts($branch['branch_code'], 'invoice', $branch['debtor_no'], true);
98 $baccount['payment_service'] = $pay_service;
99 $rep->SetCommonData($myrow, $branch, $sales_order, $baccount, ST_SALESINVOICE, $contacts);
101 $result = get_customer_trans_details(ST_SALESINVOICE, $i);
103 while ($myrow2=db_fetch($result))
105 if ($myrow2["quantity"] == 0)
108 $Net = round2($sign * ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
111 $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
112 $DisplayQty = number_format2($sign*$myrow2["quantity"],get_qty_dec($myrow2['stock_id']));
113 $DisplayNet = number_format2($Net,$dec);
114 if ($myrow2["discount_percent"]==0)
115 $DisplayDiscount ="";
117 $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
118 $rep->TextCol(0, 1, $myrow2['stock_id'], -2);
120 $rep->TextColLines(1, 2, $myrow2['StockDescription'], -2);
123 if ($Net != 0.0 || !is_service($myrow2['mb_flag']) || !isset($no_zero_lines_amount) || $no_zero_lines_amount == 0)
125 $rep->TextCol(2, 3, $DisplayQty, -2);
126 $rep->TextCol(3, 4, $myrow2['units'], -2);
127 $rep->TextCol(4, 5, $DisplayPrice, -2);
128 $rep->TextCol(5, 6, $DisplayDiscount, -2);
129 $rep->TextCol(6, 7, $DisplayNet, -2);
133 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
137 $memo = get_comments_string(ST_SALESINVOICE, $i);
141 $rep->TextColLines(1, 5, $memo, -2);
144 $DisplaySubTot = number_format2($SubTotal,$dec);
145 $DisplayFreight = number_format2($sign*$myrow["ov_freight"],$dec);
147 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
148 $doctype = ST_SALESINVOICE;
150 $rep->TextCol(3, 6, _("Sub-total"), -2);
151 $rep->TextCol(6, 7, $DisplaySubTot, -2);
153 $rep->TextCol(3, 6, _("Shipping"), -2);
154 $rep->TextCol(6, 7, $DisplayFreight, -2);
156 $tax_items = get_trans_tax_details(ST_SALESINVOICE, $i);
158 while ($tax_item = db_fetch($tax_items))
160 if ($tax_item['amount'] == 0)
162 $DisplayTax = number_format2($sign*$tax_item['amount'], $dec);
164 if (isset($suppress_tax_rates) && $suppress_tax_rates == 1)
165 $tax_type_name = $tax_item['tax_type_name'];
167 $tax_type_name = $tax_item['tax_type_name']." (".$tax_item['rate']."%) ";
169 if ($tax_item['included_in_price'])
171 if (isset($alternative_tax_include_on_docs) && $alternative_tax_include_on_docs == 1)
175 $rep->TextCol(3, 6, _("Total Tax Excluded"), -2);
176 $rep->TextCol(6, 7, number_format2($sign*$tax_item['net_amount'], $dec), -2);
179 $rep->TextCol(3, 6, $tax_type_name, -2);
180 $rep->TextCol(6, 7, $DisplayTax, -2);
184 $rep->TextCol(3, 7, _("Included") . " " . $tax_type_name . _("Amount") . ": " . $DisplayTax, -2);
188 $rep->TextCol(3, 6, $tax_type_name, -2);
189 $rep->TextCol(6, 7, $DisplayTax, -2);
195 $DisplayTotal = number_format2($sign*($myrow["ov_freight"] + $myrow["ov_gst"] +
196 $myrow["ov_amount"]+$myrow["ov_freight_tax"]),$dec);
198 $rep->TextCol(3, 6, _("TOTAL INVOICE"), - 2);
199 $rep->TextCol(6, 7, $DisplayTotal, -2);
200 $words = price_in_words($myrow['Total'], ST_SALESINVOICE);
204 $rep->TextCol(1, 7, $myrow['curr_code'] . ": " . $words, - 2);