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 ***********************************************************************/
13 // ----------------------------------------------------------------
17 // Title: Print Sales Orders
18 // ----------------------------------------------------------------
21 include_once($path_to_root . "/includes/session.inc");
22 include_once($path_to_root . "/includes/date_functions.inc");
23 include_once($path_to_root . "/includes/data_checks.inc");
24 include_once($path_to_root . "/sales/includes/sales_db.inc");
26 //----------------------------------------------------------------------------------------------------
32 function print_sales_orders()
34 global $path_to_root, $print_as_quote;
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 $bankaccount = $_POST['PARAM_3'];
42 $email = $_POST['PARAM_4'];
43 $print_as_quote = $_POST['PARAM_5'];
44 $comments = $_POST['PARAM_6'];
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,
58 'bankaccount' => $bankaccount);
60 $baccount = get_bank_account($params['bankaccount']);
61 $cur = get_company_Pref('curr_default');
65 if ($print_as_quote == 0)
66 $rep = new FrontReport(_("SALES ORDER"), "SalesOrderBulk", user_pagesize());
68 $rep = new FrontReport(_("QUOTE"), "QuoteBulk", user_pagesize());
69 $rep->currency = $cur;
71 $rep->Info($params, $cols, null, $aligns);
74 for ($i = $from; $i <= $to; $i++)
76 $myrow = get_sales_order_header($i);
77 $branch = get_branch($myrow["branch_code"]);
80 $rep = new FrontReport("", "", user_pagesize());
81 $rep->currency = $cur;
83 if ($print_as_quote == 1)
85 $rep->title = _('QUOTE');
86 $rep->filename = "Quote" . $i . ".pdf";
90 $rep->title = _("SALES ORDER");
91 $rep->filename = "SalesOrder" . $i . ".pdf";
93 $rep->Info($params, $cols, null, $aligns);
96 $rep->title = ($print_as_quote==1 ? _("QUOTE") : _("SALES ORDER"));
97 $rep->Header2($myrow, $branch, $myrow, $baccount, 9);
99 $result = get_sales_order_details($i);
101 while ($myrow2=db_fetch($result))
103 $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
106 $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
107 $DisplayQty = number_format2($myrow2["quantity"],get_qty_dec($myrow2['stk_code']));
108 $DisplayNet = number_format2($Net,$dec);
109 if ($myrow2["discount_percent"]==0)
110 $DisplayDiscount ="";
112 $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
113 $rep->TextCol(0, 1, $myrow2['stk_code'], -2);
115 $rep->TextColLines(1, 2, $myrow2['description'], -2);
118 $rep->TextCol(2, 3, $DisplayQty, -2);
119 $rep->TextCol(3, 4, $myrow2['units'], -2);
120 $rep->TextCol(4, 5, $DisplayPrice, -2);
121 $rep->TextCol(5, 6, $DisplayDiscount, -2);
122 $rep->TextCol(6, 7, $DisplayNet, -2);
125 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
126 $rep->Header2($myrow, $branch, $myrow, $baccount, 9);
128 if ($myrow['comments'] != "")
131 $rep->TextColLines(1, 5, $myrow['comments'], -2);
133 $DisplaySubTot = number_format2($SubTotal,$dec);
134 $DisplayFreight = number_format2($myrow["freight_cost"],$dec);
136 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
139 if ($rep->currency != $myrow['curr_code'])
141 include($path_to_root . "/reporting/includes/doctext2.inc");
145 include($path_to_root . "/reporting/includes/doctext.inc");
148 $rep->TextCol(3, 6, $doc_Sub_total, -2);
149 $rep->TextCol(6, 7, $DisplaySubTot, -2);
151 $rep->TextCol(3, 6, $doc_Shipping, -2);
152 $rep->TextCol(6, 7, $DisplayFreight, -2);
154 $DisplayTotal = number_format2($myrow["freight_cost"] + $SubTotal, $dec);
156 $rep->TextCol(3, 6, $doc_TOTAL_ORDER, - 2);
157 $rep->TextCol(6, 7, $DisplayTotal, -2);
161 if ($myrow['contact_email'] == '')
163 $myrow['contact_email'] = $branch['email'];
164 $myrow['DebtorName'] = $branch['br_name'];
166 $rep->End($email, $doc_Invoice_no . " " . $myrow['reference'], $myrow);