2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 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/agpl-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 //----------------------------------------------------------------------------------------------------
28 // trial_inquiry_controls();
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 $bankaccount = $_POST['PARAM_3'];
43 $email = $_POST['PARAM_4'];
44 $print_as_quote = $_POST['PARAM_5'];
45 $comments = $_POST['PARAM_6'];
51 $dec = user_price_dec();
53 $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
55 // $headers in doctext.inc
56 $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
58 $params = array('comments' => $comments,
59 'bankaccount' => $bankaccount);
61 $baccount = get_bank_account($params['bankaccount']);
62 $cur = get_company_Pref('curr_default');
66 if ($print_as_quote == 0)
67 $rep = new FrontReport(_("SALES ORDER"), "SalesOrderBulk.pdf", user_pagesize());
69 $rep = new FrontReport(_("QUOTE"), "QuoteBulk.pdf", user_pagesize());
70 $rep->currency = $cur;
72 $rep->Info($params, $cols, null, $aligns);
75 for ($i = $from; $i <= $to; $i++)
77 $myrow = get_sales_order_header($i);
78 $branch = get_branch($myrow["branch_code"]);
81 $rep = new FrontReport("", "", user_pagesize());
82 $rep->currency = $cur;
84 if ($print_as_quote == 1)
86 $rep->title = _('QUOTE');
87 $rep->filename = "Quote" . $i . ".pdf";
91 $rep->title = _("SALES ORDER");
92 $rep->filename = "SalesOrder" . $i . ".pdf";
94 $rep->Info($params, $cols, null, $aligns);
97 $rep->title = ($print_as_quote==1 ? _("QUOTE") : _("SALES ORDER"));
98 $rep->Header2($myrow, $branch, $myrow, $baccount, 9);
100 $result = get_sales_order_details($i);
102 while ($myrow2=db_fetch($result))
104 $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
107 $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
108 $DisplayQty = number_format2($myrow2["quantity"],get_qty_dec($myrow2['stk_code']));
109 $DisplayNet = number_format2($Net,$dec);
110 if ($myrow2["discount_percent"]==0)
111 $DisplayDiscount ="";
113 $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
114 $rep->TextCol(0, 1, $myrow2['stk_code'], -2);
116 $rep->TextColLines(1, 2, $myrow2['description'], -2);
119 $rep->TextCol(2, 3, $DisplayQty, -2);
120 $rep->TextCol(3, 4, $myrow2['units'], -2);
121 $rep->TextCol(4, 5, $DisplayPrice, -2);
122 $rep->TextCol(5, 6, $DisplayDiscount, -2);
123 $rep->TextCol(6, 7, $DisplayNet, -2);
126 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
127 $rep->Header2($myrow, $branch, $myrow, $baccount, 9);
129 if ($myrow['comments'] != "")
132 $rep->TextColLines(1, 5, $myrow['comments'], -2);
134 $DisplaySubTot = number_format2($SubTotal,$dec);
135 $DisplayFreight = number_format2($myrow["freight_cost"],$dec);
137 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
140 if ($rep->currency != $myrow['curr_code'])
142 include($path_to_root . "/reporting/includes/doctext2.inc");
146 include($path_to_root . "/reporting/includes/doctext.inc");
149 $rep->TextCol(3, 6, $doc_Sub_total, -2);
150 $rep->TextCol(6, 7, $DisplaySubTot, -2);
152 $rep->TextCol(3, 6, $doc_Shipping, -2);
153 $rep->TextCol(6, 7, $DisplayFreight, -2);
155 $DisplayTotal = number_format2($myrow["freight_cost"] + $SubTotal, $dec);
157 $rep->TextCol(3, 6, $doc_TOTAL_ORDER, - 2);
158 $rep->TextCol(6, 7, $DisplayTotal, -2);
162 if ($myrow['contact_email'] == '')
164 $myrow['contact_email'] = $branch['email'];
165 $myrow['DebtorName'] = $branch['br_name'];
167 $rep->End($email, $doc_Invoice_no . " " . $myrow['reference'], $myrow);