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 Sales Quotations
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");
26 include_once($path_to_root . "/taxes/tax_calc.inc");
28 //----------------------------------------------------------------------------------------------------
30 print_sales_quotations();
32 function print_sales_quotations()
34 global $path_to_root, $print_as_quote, $print_invoice_no;
36 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
38 $from = $_POST['PARAM_0'];
39 $to = $_POST['PARAM_1'];
40 $currency = $_POST['PARAM_2'];
41 $email = $_POST['PARAM_3'];
42 $comments = $_POST['PARAM_4'];
48 $dec = user_price_dec();
50 $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
52 // $headers in doctext.inc
53 $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
55 $params = array('comments' => $comments);
57 $cur = get_company_Pref('curr_default');
61 $rep = new FrontReport(_("SALES QUOTATION"), "SalesQuotationBulk", user_pagesize());
62 $rep->SetHeaderType('Header2');
63 $rep->currency = $cur;
65 $rep->Info($params, $cols, null, $aligns);
68 for ($i = $from; $i <= $to; $i++)
70 $myrow = get_sales_order_header($i, ST_SALESQUOTE);
71 $baccount = get_default_bank_account($myrow['curr_code']);
72 $params['bankaccount'] = $baccount['id'];
73 $branch = get_branch($myrow["branch_code"]);
76 $rep = new FrontReport("", "", user_pagesize());
77 $rep->SetHeaderType('Header2');
78 $rep->currency = $cur;
80 if ($print_invoice_no == 1)
81 $rep->filename = "SalesQuotation" . $i . ".pdf";
83 $rep->filename = "SalesQuotation" . $myrow['reference'] . ".pdf";
84 $rep->Info($params, $cols, null, $aligns);
86 $rep->title = _("SALES QUOTATION");
87 $contacts = get_branch_contacts($branch['branch_code'], 'order', $branch['debtor_no']);
88 $rep->SetCommonData($myrow, $branch, $myrow, $baccount, ST_SALESQUOTE, $contacts);
89 //$rep->headerFunc = 'Header2';
92 $result = get_sales_order_details($i, ST_SALESQUOTE);
94 $items = $prices = array();
95 while ($myrow2=db_fetch($result))
97 $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
100 $items[] = $myrow2['stk_code'];
102 $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
103 $DisplayQty = number_format2($myrow2["quantity"],get_qty_dec($myrow2['stk_code']));
104 $DisplayNet = number_format2($Net,$dec);
105 if ($myrow2["discount_percent"]==0)
106 $DisplayDiscount ="";
108 $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
109 $rep->TextCol(0, 1, $myrow2['stk_code'], -2);
111 $rep->TextColLines(1, 2, $myrow2['description'], -2);
114 $rep->TextCol(2, 3, $DisplayQty, -2);
115 $rep->TextCol(3, 4, $myrow2['units'], -2);
116 $rep->TextCol(4, 5, $DisplayPrice, -2);
117 $rep->TextCol(5, 6, $DisplayDiscount, -2);
118 $rep->TextCol(6, 7, $DisplayNet, -2);
121 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
124 if ($myrow['comments'] != "")
127 $rep->TextColLines(1, 5, $myrow['comments'], -2);
129 $DisplaySubTot = number_format2($SubTotal,$dec);
130 $DisplayFreight = number_format2($myrow["freight_cost"],$dec);
132 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
134 $doctype = ST_SALESQUOTE;
135 include($path_to_root . "/reporting/includes/doctext.inc");
137 $rep->TextCol(3, 6, $doc_Sub_total, -2);
138 $rep->TextCol(6, 7, $DisplaySubTot, -2);
140 $rep->TextCol(3, 6, $doc_Shipping, -2);
141 $rep->TextCol(6, 7, $DisplayFreight, -2);
144 $DisplayTotal = number_format2($myrow["freight_cost"] + $SubTotal, $dec);
145 if ($myrow['tax_included'] == 0) {
146 $rep->TextCol(3, 6, $doc_TOTAL_ORDER, - 2);
147 $rep->TextCol(6, 7, $DisplayTotal, -2);
151 $tax_items = get_tax_for_items($items, $prices, $myrow["freight_cost"],
152 $myrow['tax_group_id'], $myrow['tax_included'], null);
154 foreach($tax_items as $tax_item)
156 if ($tax_item['Value'] == 0)
158 $DisplayTax = number_format2($tax_item['Value'], $dec);
160 $tax_type_name = $tax_item['tax_type_name'];
162 if ($myrow['tax_included'])
164 if (isset($alternative_tax_include_on_docs) && $alternative_tax_include_on_docs == 1)
168 $rep->TextCol(3, 6, _("Total Tax Excluded"), -2);
169 $rep->TextCol(6, 7, number_format2($sign*$tax_item['net_amount'], $dec), -2);
172 $rep->TextCol(3, 6, $tax_type_name, -2);
173 $rep->TextCol(6, 7, $DisplayTax, -2);
177 $rep->TextCol(3, 7, $doc_Included . " " . $tax_type_name . " " . $doc_Amount . ": " . $DisplayTax, -2);
181 $SubTotal += $tax_item['Value'];
182 $rep->TextCol(3, 6, $tax_type_name, -2);
183 $rep->TextCol(6, 7, $DisplayTax, -2);
190 $DisplayTotal = number_format2($myrow["freight_cost"] + $SubTotal, $dec);
192 $rep->TextCol(3, 6, $doc_TOTAL_ORDER2, - 2);
193 $rep->TextCol(6, 7, $DisplayTotal, -2);
194 $words = price_in_words($myrow["freight_cost"] + $SubTotal, ST_SALESQUOTE);
198 $rep->TextCol(1, 7, $myrow['curr_code'] . ": " . $words, - 2);
203 if ($print_invoice_no == 1)
204 $myrow['reference'] = $i;
205 $rep->End($email, $doc_Invoice_no . " " . $myrow['reference'], $myrow);