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