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 Orders
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 //----------------------------------------------------------------------------------------------------
33 function print_sales_orders()
35 global $path_to_root, $print_as_quote;
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 $print_as_quote = $_POST['PARAM_4'];
44 $comments = $_POST['PARAM_5'];
50 $dec = user_price_dec();
52 $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
54 // $headers in doctext.inc
55 $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
57 $params = array('comments' => $comments);
59 $cur = get_company_Pref('curr_default');
63 if ($print_as_quote == 0)
64 $rep = new FrontReport(_("SALES ORDER"), "SalesOrderBulk", user_pagesize());
66 $rep = new FrontReport(_("QUOTE"), "QuoteBulk", user_pagesize());
67 $rep->SetHeaderType('Header2');
68 $rep->currency = $cur;
70 $rep->Info($params, $cols, null, $aligns);
73 for ($i = $from; $i <= $to; $i++)
75 $myrow = get_sales_order_header($i, ST_SALESORDER);
76 $baccount = get_default_bank_account($myrow['curr_code']);
77 $params['bankaccount'] = $baccount['id'];
78 $branch = get_branch($myrow["branch_code"]);
81 $rep = new FrontReport("", "", user_pagesize());
82 $rep->SetHeaderType('Header2');
83 $rep->currency = $cur;
85 if ($print_as_quote == 1)
87 $rep->title = _('QUOTE');
88 $rep->filename = "Quote" . $i . ".pdf";
92 $rep->title = _("SALES ORDER");
93 $rep->filename = "SalesOrder" . $i . ".pdf";
95 $rep->Info($params, $cols, null, $aligns);
98 $rep->title = ($print_as_quote==1 ? _("QUOTE") : _("SALES ORDER"));
100 $contacts = get_branch_contacts($branch['branch_code'], 'order', $branch['debtor_no']);
101 $rep->SetCommonData($myrow, $branch, $myrow, $baccount, ST_SALESORDER, $contacts);
104 $result = get_sales_order_details($i, ST_SALESORDER);
106 while ($myrow2=db_fetch($result))
108 $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
111 $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
112 $DisplayQty = number_format2($myrow2["quantity"],get_qty_dec($myrow2['stk_code']));
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['stk_code'], -2);
120 $rep->TextColLines(1, 2, $myrow2['description'], -2);
123 $rep->TextCol(2, 3, $DisplayQty, -2);
124 $rep->TextCol(3, 4, $myrow2['units'], -2);
125 $rep->TextCol(4, 5, $DisplayPrice, -2);
126 $rep->TextCol(5, 6, $DisplayDiscount, -2);
127 $rep->TextCol(6, 7, $DisplayNet, -2);
130 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
133 if ($myrow['comments'] != "")
136 $rep->TextColLines(1, 5, $myrow['comments'], -2);
138 $DisplaySubTot = number_format2($SubTotal,$dec);
139 $DisplayFreight = number_format2($myrow["freight_cost"],$dec);
141 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
143 $doctype = ST_SALESORDER;
144 include($path_to_root . "/reporting/includes/doctext.inc");
146 $rep->TextCol(3, 6, $doc_Sub_total, -2);
147 $rep->TextCol(6, 7, $DisplaySubTot, -2);
149 $rep->TextCol(3, 6, $doc_Shipping, -2);
150 $rep->TextCol(6, 7, $DisplayFreight, -2);
152 $DisplayTotal = number_format2($myrow["freight_cost"] + $SubTotal, $dec);
154 if ($myrow['tax_included'] == 0)
155 $rep->TextCol(3, 6, $doc_TOTAL_ORDER, - 2);
157 $rep->TextCol(3, 6, $doc_TOTAL_ORDER2, - 2);
158 $rep->TextCol(6, 7, $DisplayTotal, -2);
159 $words = price_in_words($myrow["freight_cost"] + $SubTotal, ST_SALESORDER);
163 $rep->TextCol(1, 7, $myrow['curr_code'] . ": " . $words, - 2);
168 $res = get_branch_contacts(branch_code, 'order', customer_id);
169 if ($myrow['contact_email'] == '')
171 $myrow['contact_email'] = $branch['email'];
172 if ($myrow['contact_email'] == '')
173 $myrow['contact_email'] = $myrow['master_email'];
174 $myrow['DebtorName'] = $branch['br_name'];
176 //$myrow['reference'] = $i;
177 $rep->End($email, $doc_Invoice_no . " " . $i, $myrow);