Changed the Quantity routines to use the Item Units decimals if any. A lot of files.
[fa-stable.git] / reporting / rep109.php
1 <?php
2
3 $page_security = 2;
4 // ----------------------------------------------------------------
5 // $ Revision:  2.0 $
6 // Creator:     Joe Hunt
7 // date_:       2005-05-19
8 // Title:       Print Sales Orders
9 // ----------------------------------------------------------------
10 $path_to_root="../";
11
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "sales/includes/sales_db.inc");
16
17 //----------------------------------------------------------------------------------------------------
18
19 // trial_inquiry_controls();
20 print_sales_orders();
21
22 $print_as_quote = 0;
23
24 function print_sales_orders()
25 {
26         global $path_to_root, $print_as_quote;
27
28         include_once($path_to_root . "reporting/includes/pdf_report.inc");
29
30         $from = $_POST['PARAM_0'];
31         $to = $_POST['PARAM_1'];
32         $currency = $_POST['PARAM_2'];
33         $bankaccount = $_POST['PARAM_3'];
34         $email = $_POST['PARAM_4'];
35         $print_as_quote = $_POST['PARAM_5'];
36         $comments = $_POST['PARAM_6'];
37
38         if ($from == null)
39                 $from = 0;
40         if ($to == null)
41                 $to = 0;
42         $dec = user_price_dec();
43
44         $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
45
46         // $headers in doctext.inc
47         $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
48
49         $params = array('comments' => $comments,
50                                         'bankaccount' => $bankaccount);
51
52         $baccount = get_bank_account($params['bankaccount']);
53         $cur = get_company_Pref('curr_default');
54
55         if ($email == 0)
56         {
57                 if ($print_as_quote == 1)
58                         $rep = new FrontReport(_("QUOTE"), "QuoteBulk.pdf", user_pagesize());
59                 else
60                         $rep = new FrontReport(_("SALES ORDER"), "SalesOrderBulk.pdf", user_pagesize());
61                 $rep->currency = $cur;
62                 $rep->Font();
63                 $rep->Info($params, $cols, null, $aligns);
64         }
65
66         for ($i = $from; $i <= $to; $i++)
67         {
68                 $myrow = get_sales_order_header($i);
69                 $branch = get_branch($myrow["branch_code"]);
70                 if ($email == 1)
71                 {
72                         $rep = new FrontReport("", "", user_pagesize());
73                         $rep->currency = $cur;
74                         $rep->Font();
75                         if ($print_as_quote == 1)
76                         {
77                                 $rep->title = _('QUOTE');
78                                 $rep->filename = "Quote" . $i . ".pdf";
79                         }
80                         else
81                         {
82                                 $rep->title = _("SALES ORDER");
83                                 $rep->filename = "SalesOrder" . $i . ".pdf";
84                         }
85                         $rep->Info($params, $cols, null, $aligns);
86                 }
87                 else
88                         $rep->title = ($print_as_quote==1 ? _("QUOTE") : _("SALES ORDER"));
89                 $rep->Header2($myrow, $branch, $myrow, $baccount, 9);
90
91                 $result = get_sales_order_details($i);
92                 $SubTotal = 0;
93                 while ($myrow2=db_fetch($result))
94                 {
95                         $Net = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
96                            user_price_dec());
97                         $SubTotal += $Net;
98                         $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
99                         $DisplayQty = number_format2($myrow2["quantity"],get_qty_dec($myrow2['stk_code']));
100                         $DisplayNet = number_format2($Net,$dec);
101                         if ($myrow2["discount_percent"]==0)
102                                 $DisplayDiscount ="";
103                         else
104                                 $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
105                         $rep->TextCol(0, 1,     $myrow2['stk_code'], -2);
106                         $rep->TextCol(1, 2,     $myrow2['description'], -2);
107                         $rep->TextCol(2, 3,     $DisplayQty, -2);
108                         $rep->TextCol(3, 4,     $myrow2['units'], -2);
109                         $rep->TextCol(4, 5,     $DisplayPrice, -2);
110                         $rep->TextCol(5, 6,     $DisplayDiscount, -2);
111                         $rep->TextCol(6, 7,     $DisplayNet, -2);
112                         $rep->NewLine(1);
113                         if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
114                                 $rep->Header2($myrow, $branch, $sales_order, $baccount);
115                 }
116                 if ($myrow['comments'] != "")
117                 {
118                         $rep->NewLine();
119                         $rep->TextColLines(1, 5, $myrow['comments'], -2);
120                 }
121                 $DisplaySubTot = number_format2($SubTotal,$dec);
122                 $DisplayFreight = number_format2($myrow["freight_cost"],$dec);
123
124                 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
125                 $linetype = true;
126                 $doctype = 9;
127                 if ($rep->currency != $myrow['curr_code'])
128                 {
129                         include($path_to_root . "reporting/includes/doctext2.inc");
130                 }
131                 else
132                 {
133                         include($path_to_root . "reporting/includes/doctext.inc");
134                 }
135
136                 $rep->TextCol(3, 6, $doc_Sub_total, -2);
137                 $rep->TextCol(6, 7,     $DisplaySubTot, -2);
138                 $rep->NewLine();
139                 $rep->TextCol(3, 6, $doc_Shipping, -2);
140                 $rep->TextCol(6, 7,     $DisplayFreight, -2);
141                 $rep->NewLine();
142                 $DisplayTotal = number_format2($myrow["freight_cost"] + $SubTotal, $dec);
143                 $rep->Font('bold');
144                 $rep->TextCol(3, 6, $doc_TOTAL_ORDER, - 2);
145                 $rep->TextCol(6, 7,     $DisplayTotal, -2);
146                 $rep->Font();
147                 if ($email == 1)
148                 {
149                         if ($myrow['contact_email'] == '')
150                         {
151                                 $myrow['contact_email'] = $branch['email'];
152                                 $myrow['DebtorName'] = $branch['br_name'];
153                         }
154                         $rep->End($email, $doc_Invoice_no . " " . $myrow['reference'], $myrow);
155                 }
156         }
157         if ($email == 0)
158                 $rep->End();
159 }
160
161 ?>