No display of shipping if there are no shipping costs on sales documents or views.
[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 = $_POST['PARAM_0'] == $_POST['PARAM_1'] ?
13         'SA_SALESTRANSVIEW' : 'SA_SALESBULKREP';
14 // ----------------------------------------------------------------
15 // $ Revision:  2.0 $
16 // Creator:     Janusz Dobrwolski
17 // date_:       2008-01-14
18 // Title:       Print Delivery Notes
19 // draft version!
20 // ----------------------------------------------------------------
21 $path_to_root="..";
22
23 include_once($path_to_root . "/includes/session.inc");
24 include_once($path_to_root . "/includes/date_functions.inc");
25 include_once($path_to_root . "/includes/data_checks.inc");
26 include_once($path_to_root . "/sales/includes/sales_db.inc");
27
28 $packing_slip = 0;
29 //----------------------------------------------------------------------------------------------------
30
31 print_deliveries();
32
33 //----------------------------------------------------------------------------------------------------
34
35 function print_deliveries()
36 {
37         global $path_to_root, $packing_slip, $alternative_tax_include_on_docs, $suppress_tax_rates, $no_zero_lines_amount;
38
39         include_once($path_to_root . "/reporting/includes/pdf_report.inc");
40
41         $from = $_POST['PARAM_0'];
42         $to = $_POST['PARAM_1'];
43         $email = $_POST['PARAM_2'];
44         $packing_slip = $_POST['PARAM_3'];
45         $comments = $_POST['PARAM_4'];
46         $orientation = $_POST['PARAM_5'];
47
48         if (!$from || !$to) return;
49
50         $orientation = ($orientation ? 'L' : 'P');
51         $dec = user_price_dec();
52
53         $fno = explode("-", $from);
54         $tno = explode("-", $to);
55         $from = min($fno[0], $tno[0]);
56         $to = max($fno[0], $tno[0]);
57
58         $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
59
60         // $headers in doctext.inc
61         $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
62
63         $params = array('comments' => $comments);
64
65         $cur = get_company_Pref('curr_default');
66
67         if ($email == 0)
68         {
69                 if ($packing_slip == 0)
70                         $rep = new FrontReport(_('DELIVERY'), "DeliveryNoteBulk", user_pagesize(), 9, $orientation);
71                 else
72                         $rep = new FrontReport(_('PACKING SLIP'), "PackingSlipBulk", user_pagesize(), 9, $orientation);
73         }
74     if ($orientation == 'L')
75         recalculate_cols($cols);
76         for ($i = $from; $i <= $to; $i++)
77         {
78                         if (!exists_customer_trans(ST_CUSTDELIVERY, $i))
79                                 continue;
80                         $myrow = get_customer_trans($i, ST_CUSTDELIVERY);
81                         $branch = get_branch($myrow["branch_code"]);
82                         $sales_order = get_sales_order_header($myrow["order_"], ST_SALESORDER); // ?
83                         if ($email == 1)
84                         {
85                                 $rep = new FrontReport("", "", user_pagesize(), 9, $orientation);
86                                 if ($packing_slip == 0)
87                                 {
88                                         $rep->title = _('DELIVERY NOTE');
89                                         $rep->filename = "Delivery" . $myrow['reference'] . ".pdf";
90                                 }
91                                 else
92                                 {
93                                         $rep->title = _('PACKING SLIP');
94                                         $rep->filename = "Packing_slip" . $myrow['reference'] . ".pdf";
95                                 }
96                         }
97                         $rep->SetHeaderType('Header2');
98                         $rep->currency = $cur;
99                         $rep->Font();
100                         $rep->Info($params, $cols, null, $aligns);
101
102                         $contacts = get_branch_contacts($branch['branch_code'], 'delivery', $branch['debtor_no'], true);
103                         $rep->SetCommonData($myrow, $branch, $sales_order, '', ST_CUSTDELIVERY, $contacts);
104                         $rep->NewPage();
105
106                         $result = get_customer_trans_details(ST_CUSTDELIVERY, $i);
107                         $SubTotal = 0;
108                         while ($myrow2=db_fetch($result))
109                         {
110                                 if ($myrow2["quantity"] == 0)
111                                         continue;
112                                         
113                                 $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
114                                    user_price_dec());
115                                 $SubTotal += $Net;
116                         $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
117                         $DisplayQty = number_format2($myrow2["quantity"],get_qty_dec($myrow2['stock_id']));
118                         $DisplayNet = number_format2($Net,$dec);
119                         if ($myrow2["discount_percent"]==0)
120                                         $DisplayDiscount ="";
121                         else
122                                         $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
123                                 $rep->TextCol(0, 1,     $myrow2['stock_id'], -2);
124                                 $oldrow = $rep->row;
125                                 $rep->TextColLines(1, 2, $myrow2['StockDescription'], -2);
126                                 $newrow = $rep->row;
127                                 $rep->row = $oldrow;
128                                 if ($Net != 0.0  || !is_service($myrow2['mb_flag']) || !isset($no_zero_lines_amount) || $no_zero_lines_amount == 0)
129                                 {                       
130                                         $rep->TextCol(2, 3,     $DisplayQty, -2);
131                                         $rep->TextCol(3, 4,     $myrow2['units'], -2);
132                                         if ($packing_slip == 0)
133                                         {
134                                                 $rep->TextCol(4, 5,     $DisplayPrice, -2);
135                                                 $rep->TextCol(5, 6,     $DisplayDiscount, -2);
136                                                 $rep->TextCol(6, 7,     $DisplayNet, -2);
137                                         }
138                                 }       
139                                 $rep->row = $newrow;
140                                 //$rep->NewLine(1);
141                                 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
142                                         $rep->NewPage();
143                         }
144
145                         $memo = get_comments_string(ST_CUSTDELIVERY, $i);
146                         if ($memo != "")
147                         {
148                                 $rep->NewLine();
149                                 $rep->TextColLines(1, 5, $memo, -2);
150                         }
151
152                         $DisplaySubTot = number_format2($SubTotal,$dec);
153
154                 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
155                         $doctype=ST_CUSTDELIVERY;
156                         if ($packing_slip == 0)
157                         {
158                                 $rep->TextCol(3, 6, _("Sub-total"), -2);
159                                 $rep->TextCol(6, 7,     $DisplaySubTot, -2);
160                                 $rep->NewLine();
161                                 if ($myrow['ov_freight'] != 0.0)
162                                 {
163                                         $DisplayFreight = number_format2($myrow["ov_freight"],$dec);
164                                         $rep->TextCol(3, 6, _("Shipping"), -2);
165                                         $rep->TextCol(6, 7,     $DisplayFreight, -2);
166                                         $rep->NewLine();
167                                 }       
168                                 $tax_items = get_trans_tax_details(ST_CUSTDELIVERY, $i);
169                                 $first = true;
170                         while ($tax_item = db_fetch($tax_items))
171                         {
172                                 if ($tax_item['amount'] == 0)
173                                         continue;
174                                 $DisplayTax = number_format2($tax_item['amount'], $dec);
175  
176                                         if (isset($suppress_tax_rates) && $suppress_tax_rates == 1)
177                                                 $tax_type_name = $tax_item['tax_type_name'];
178                                         else
179                                                 $tax_type_name = $tax_item['tax_type_name']." (".$tax_item['rate']."%) ";
180  
181                                         if ($tax_item['included_in_price'])
182                                 {
183                                                 if (isset($alternative_tax_include_on_docs) && $alternative_tax_include_on_docs == 1)
184                                         {
185                                                 if ($first)
186                                                 {
187                                                                 $rep->TextCol(3, 6, _("Total Tax Excluded"), -2);
188                                                                 $rep->TextCol(6, 7,     number_format2($tax_item['net_amount'], $dec), -2);
189                                                                 $rep->NewLine();
190                                                 }
191                                                         $rep->TextCol(3, 6, $tax_type_name, -2);
192                                                         $rep->TextCol(6, 7,     $DisplayTax, -2);
193                                                         $first = false;
194                                         }
195                                         else
196                                                         $rep->TextCol(3, 7, _("Included") . " " . $tax_type_name . _("Amount") . ": " . $DisplayTax, -2);
197                                         }
198                                 else
199                                 {
200                                                 $rep->TextCol(3, 6, $tax_type_name, -2);
201                                                 $rep->TextCol(6, 7,     $DisplayTax, -2);
202                                         }
203                                         $rep->NewLine();
204                         }
205                         $rep->NewLine();
206                                 $DisplayTotal = number_format2($myrow["ov_freight"] +$myrow["ov_freight_tax"] + $myrow["ov_gst"] +
207                                         $myrow["ov_amount"],$dec);
208                                 $rep->Font('bold');
209                                 $rep->TextCol(3, 6, _("TOTAL DELIVERY INCL. VAT"), - 2);
210                                 $rep->TextCol(6, 7,     $DisplayTotal, -2);
211                                 $words = price_in_words($myrow['Total'], ST_CUSTDELIVERY);
212                                 if ($words != "")
213                                 {
214                                         $rep->NewLine(1);
215                                         $rep->TextCol(1, 7, $myrow['curr_code'] . ": " . $words, - 2);
216                                 }       
217                                 $rep->Font();
218                         }       
219                         if ($email == 1)
220                         {
221                                 $rep->End($email);
222                         }
223         }
224         if ($email == 0)
225                 $rep->End();
226 }
227
228 ?>