Final rewriting of sales module
[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 = ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]);
87                                 $SubTotal += $Net;
88                         $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
89                         $DisplayQty = number_format2($myrow2["quantity"],user_qty_dec());
90                         $DisplayNet = number_format2($Net,$dec);
91                         if ($myrow2["discount_percent"]==0)
92                                         $DisplayDiscount ="";
93                         else 
94                                         $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
95                                 $rep->TextCol(0, 1,     $myrow2['stock_id'], -2);
96                                 $rep->TextCol(1, 2,     $myrow2['StockDescription'], -2);
97                                 $rep->TextCol(2, 3,     $DisplayQty, -2);
98                                 $rep->TextCol(3, 4,     $myrow2['units'], -2);
99                                 $rep->TextCol(4, 5,     $DisplayPrice, -2);
100                                 $rep->TextCol(5, 6,     $DisplayDiscount, -2);
101                                 $rep->TextCol(6, 7,     $DisplayNet, -2);
102                                 $rep->NewLine(1);
103                                 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight)) 
104                                         $rep->Header2($myrow, $branch, $sales_order,'',13);
105                         }
106                         
107                         $comments = get_comments(13, $i);
108                         if ($comments && db_num_rows($comments))
109                         {       
110                                 $rep->NewLine();
111                         while ($comment=db_fetch($comments)) 
112                                 $rep->TextColLines(0, 6, $comment['memo_'], -2);
113                         }       
114                                 
115                         $DisplaySubTot = number_format2($SubTotal,$dec);
116                         $DisplayFreight = number_format2($myrow["ov_freight"],$dec);
117
118                 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
119                         $linetype = true;
120                         $doctype=13;
121                         if ($rep->currency != $myrow['curr_code'])
122                         {
123                                 include($path_to_root . "reporting/includes/doctext2.inc");                     
124                         }       
125                         else
126                         {
127                                 include($path_to_root . "reporting/includes/doctext.inc");                      
128                         }       
129                 
130                         $rep->TextCol(3, 6, $doc_Sub_total, -2);
131                         $rep->TextCol(6, 7,     $DisplaySubTot, -2);
132                         $rep->NewLine();
133                         $rep->TextCol(3, 6, $doc_Shipping, -2);
134                         $rep->TextCol(6, 7,     $DisplayFreight, -2);
135                         $rep->NewLine();
136                         $tax_items = get_customer_trans_tax_details(13, $i);
137                 while ($tax_item = db_fetch($tax_items)) 
138                 {
139                         $DisplayTax = number_format2($tax_item['amount'], $dec);
140                         if ($tax_item['included_in_price'])
141                         {
142                                         $rep->TextCol(3, 7, $doc_Included . " " . $tax_item['tax_type_name'] . 
143                                                 " (" . $tax_item['rate'] . "%) " . $doc_Amount . ":" . $DisplayTax, -2);
144                                 }               
145                         else
146                         {
147                                         $rep->TextCol(3, 6, $tax_item['tax_type_name'] . " (" . 
148                                                 $tax_item['rate'] . "%)", -2);
149                                         $rep->TextCol(6, 7,     $DisplayTax, -2);
150                                 }                       
151                                 $rep->NewLine();
152                 }
153                 $rep->NewLine();
154                         $DisplayTotal = number_format2($myrow["ov_freight"] +$myrow["ov_freight_tax"] + $myrow["ov_gst"] +
155                                 $myrow["ov_amount"],$dec);
156                         $rep->Font('bold');     
157                         $rep->TextCol(3, 6, $doc_TOTAL_DELIVERY, - 2); 
158                         $rep->TextCol(6, 7,     $DisplayTotal, -2);
159                         $rep->Font();   
160                         if ($email == 1)
161                         {
162                                 $myrow['dimension_id'] = $paylink; // helper for pmt link
163                                 if ($myrow['email'] == '')
164                                 {
165                                         $myrow['email'] = $branch['email'];
166                                         $myrow['DebtorName'] = $branch['br_name'];
167                                 }
168                                 $rep->End($email, $doc_Delivery_no . " " . $myrow['reference'], $myrow, 13);
169                         }       
170         }
171         if ($email == 0)
172                 $rep->End();
173 }
174
175 ?>