Replaced the Excel Writer engine with XLS driver (the XML driver can later be downloaded)
[fa-stable.git] / reporting / rep110.php
1 <?php
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 = 2;
13 // ----------------------------------------------------------------
14 // $ Revision:  2.0 $
15 // Creator:     Janusz Dobrwolski
16 // date_:       2008-01-14
17 // Title:       Print Delivery Notes
18 // draft version!
19 // ----------------------------------------------------------------
20 $path_to_root="..";
21
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
27 //----------------------------------------------------------------------------------------------------
28
29 print_deliveries();
30
31 //----------------------------------------------------------------------------------------------------
32
33 function print_deliveries()
34 {
35         global $path_to_root;
36
37         include_once($path_to_root . "/reporting/includes/pdf_report.inc");
38
39         $from = $_POST['PARAM_0'];
40         $to = $_POST['PARAM_1'];
41         $email = $_POST['PARAM_2'];
42         $comments = $_POST['PARAM_3'];
43
44         if ($from == null)
45                 $from = 0;
46         if ($to == null)
47                 $to = 0;
48         $dec = user_price_dec();
49
50         $fno = explode("-", $from);
51         $tno = explode("-", $to);
52
53         $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
54
55         // $headers in doctext.inc
56         $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
57
58         $params = array('comments' => $comments);
59
60         $cur = get_company_Pref('curr_default');
61
62         if ($email == 0)
63         {
64                 $rep = new FrontReport(_('DELIVERY'), "DeliveryNoteBulk", user_pagesize());
65                 $rep->currency = $cur;
66                 $rep->Font();
67                 $rep->Info($params, $cols, null, $aligns);
68         }
69
70         for ($i = $fno[0]; $i <= $tno[0]; $i++)
71         {
72                         if (!exists_customer_trans(13, $i))
73                                 continue;
74                         $myrow = get_customer_trans($i, 13);
75                         $branch = get_branch($myrow["branch_code"]);
76                         $sales_order = get_sales_order_header($myrow["order_"]); // ?
77                         if ($email == 1)
78                         {
79                                 $rep = new FrontReport("", "", user_pagesize());
80                                 $rep->currency = $cur;
81                                 $rep->Font();
82                                         $rep->title = _('DELIVERY NOTE');
83                                         $rep->filename = "Delivery" . $myrow['reference'] . ".pdf";
84                                 $rep->Info($params, $cols, null, $aligns);
85                         }
86                         else
87                                 $rep->title = _('DELIVERY NOTE');
88                         $rep->Header2($myrow, $branch, $sales_order, '', 13);
89
90                 $result = get_customer_trans_details(13, $i);
91                         $SubTotal = 0;
92                         while ($myrow2=db_fetch($result))
93                         {
94                                 $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
95                                    user_price_dec());
96                                 $SubTotal += $Net;
97                         $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
98                         $DisplayQty = number_format2($myrow2["quantity"],get_qty_dec($myrow2['stock_id']));
99                         $DisplayNet = number_format2($Net,$dec);
100                         if ($myrow2["discount_percent"]==0)
101                                         $DisplayDiscount ="";
102                         else
103                                         $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
104                                 $rep->TextCol(0, 1,     $myrow2['stock_id'], -2);
105                                 $oldrow = $rep->row;
106                                 $rep->TextColLines(1, 2, $myrow2['StockDescription'], -2);
107                                 $newrow = $rep->row;
108                                 $rep->row = $oldrow;
109                                 $rep->TextCol(2, 3,     $DisplayQty, -2);
110                                 $rep->TextCol(3, 4,     $myrow2['units'], -2);
111                                 $rep->TextCol(4, 5,     $DisplayPrice, -2);
112                                 $rep->TextCol(5, 6,     $DisplayDiscount, -2);
113                                 $rep->TextCol(6, 7,     $DisplayNet, -2);
114                                 $rep->row = $newrow;
115                                 //$rep->NewLine(1);
116                                 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
117                                         $rep->Header2($myrow, $branch, $sales_order,'',13);
118                         }
119
120                         $comments = get_comments(13, $i);
121                         if ($comments && db_num_rows($comments))
122                         {
123                                 $rep->NewLine();
124                         while ($comment=db_fetch($comments))
125                                 $rep->TextColLines(0, 6, $comment['memo_'], -2);
126                         }
127
128                         $DisplaySubTot = number_format2($SubTotal,$dec);
129                         $DisplayFreight = number_format2($myrow["ov_freight"],$dec);
130
131                 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
132                         $linetype = true;
133                         $doctype=13;
134                         if ($rep->currency != $myrow['curr_code'])
135                         {
136                                 include($path_to_root . "/reporting/includes/doctext2.inc");
137                         }
138                         else
139                         {
140                                 include($path_to_root . "/reporting/includes/doctext.inc");
141                         }
142
143                         $rep->TextCol(3, 6, $doc_Sub_total, -2);
144                         $rep->TextCol(6, 7,     $DisplaySubTot, -2);
145                         $rep->NewLine();
146                         $rep->TextCol(3, 6, $doc_Shipping, -2);
147                         $rep->TextCol(6, 7,     $DisplayFreight, -2);
148                         $rep->NewLine();
149                         $tax_items = get_trans_tax_details(13, $i);
150                 while ($tax_item = db_fetch($tax_items))
151                 {
152                         $DisplayTax = number_format2($tax_item['amount'], $dec);
153                         if ($tax_item['included_in_price'])
154                         {
155                                         $rep->TextCol(3, 7, $doc_Included . " " . $tax_item['tax_type_name'] .
156                                                 " (" . $tax_item['rate'] . "%) " . $doc_Amount . ":" . $DisplayTax, -2);
157                                 }
158                         else
159                         {
160                                         $rep->TextCol(3, 6, $tax_item['tax_type_name'] . " (" .
161                                                 $tax_item['rate'] . "%)", -2);
162                                         $rep->TextCol(6, 7,     $DisplayTax, -2);
163                                 }
164                                 $rep->NewLine();
165                 }
166                 $rep->NewLine();
167                         $DisplayTotal = number_format2($myrow["ov_freight"] +$myrow["ov_freight_tax"] + $myrow["ov_gst"] +
168                                 $myrow["ov_amount"],$dec);
169                         $rep->Font('bold');
170                         $rep->TextCol(3, 6, $doc_TOTAL_DELIVERY, - 2);
171                         $rep->TextCol(6, 7,     $DisplayTotal, -2);
172                         $rep->Font();
173                         if ($email == 1)
174                         {
175                                 $myrow['dimension_id'] = $paylink; // helper for pmt link
176                                 if ($myrow['email'] == '')
177                                 {
178                                         $myrow['email'] = $branch['email'];
179                                         $myrow['DebtorName'] = $branch['br_name'];
180                                 }
181                                 $rep->End($email, $doc_Delivery_no . " " . $myrow['reference'], $myrow, 13);
182                         }
183         }
184         if ($email == 0)
185                 $rep->End();
186 }
187
188 ?>