Recurrent Invoices: fixed buggy call to non existing function and payment terms type...
[fa-stable.git] / reporting / rep204.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 = 'SA_SUPPLIERANALYTIC';
13 // ----------------------------------------------------------------
14 // $ Revision:  2.0 $
15 // Creator:     Joe Hunt
16 // date_:       2005-05-19
17 // Title:       Outstanding GRNs Report
18 // ----------------------------------------------------------------
19 $path_to_root="..";
20
21 include_once($path_to_root . "/includes/session.inc");
22 include_once($path_to_root . "/includes/date_functions.inc");
23 include_once($path_to_root . "/includes/data_checks.inc");
24 include_once($path_to_root . "/gl/includes/gl_db.inc");
25
26 //----------------------------------------------------------------------------------------------------
27
28 print_outstanding_GRN();
29
30 function getTransactions($fromsupp)
31 {
32         $sql = "SELECT grn.id,
33                         order_no,
34                         grn.supplier_id,
35                         supplier.supp_name,
36                         item.item_code,
37                         item.description,
38                         qty_recd,
39                         quantity_inv,
40                         act_price,
41                         unit_price
42                 FROM ".TB_PREF."grn_items item,
43                         ".TB_PREF."grn_batch grn,
44                         ".TB_PREF."purch_order_details poline,
45                         ".TB_PREF."suppliers supplier
46                 WHERE grn.supplier_id=supplier.supplier_id
47                 AND grn.id = item.grn_batch_id
48                 AND item.po_detail_item = poline.po_detail_item
49                 AND qty_recd-quantity_inv!=0";
50
51         if ($fromsupp != ALL_TEXT)
52                 $sql .= " AND grn.supplier_id =".db_escape($fromsupp);
53
54         $sql .= " ORDER BY grn.supplier_id,     grn.id";
55
56     return db_query($sql, "No transactions were returned");
57 }
58
59 //----------------------------------------------------------------------------------------------------
60
61 function print_outstanding_GRN()
62 {
63     global $path_to_root;
64
65     $fromsupp = $_POST['PARAM_0'];
66     $comments = $_POST['PARAM_1'];
67         $orientation = $_POST['PARAM_2'];
68         $destination = $_POST['PARAM_3'];
69         if ($destination)
70                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
71         else
72                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
73
74         $orientation = ($orientation ? 'L' : 'P');
75         if ($fromsupp == ALL_TEXT)
76                 $from = _('All');
77         else
78                 $from = get_supplier_name($fromsupp);
79     $dec = user_price_dec();
80
81         $cols = array(0, 40, 80, 190,   250, 320, 385, 450,     515);
82
83         $headers = array(_('GRN'), _('Order'), _('Item') . '/' . _('Description'), _('Qty Recd'), _('qty Inv'), _('Balance'),
84                 _('Act Price'), _('Value'));
85
86         $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
87
88     $params =   array(  0 => $comments,
89                                     1 => array('text' => _('Supplier'), 'from' => $from, 'to' => ''));
90
91     $rep = new FrontReport(_('Outstanding GRNs Report'), "OutstandingGRN", user_pagesize(), 9, $orientation);
92     if ($orientation == 'L')
93         recalculate_cols($cols);
94
95     $rep->Font();
96     $rep->Info($params, $cols, $headers, $aligns);
97     $rep->NewPage();
98
99         $Tot_Val=0;
100         $Supplier = '';
101         $SuppTot_Val=0;
102         $res = getTransactions($fromsupp);
103
104         while ($GRNs = db_fetch($res))
105         {
106                 $dec2 = get_qty_dec($GRNs['item_code']);
107                 if ($Supplier != $GRNs['supplier_id'])
108                 {
109                         if ($Supplier != '')
110                         {
111                                 $rep->NewLine(2);
112                                 $rep->TextCol(0, 7, _('Total'));
113                                 $rep->AmountCol(7, 8, $SuppTot_Val, $dec);
114                                 $rep->Line($rep->row - 2);
115                                 $rep->NewLine(3);
116                                 $SuppTot_Val = 0;
117                         }
118                         $rep->TextCol(0, 6, $GRNs['supp_name']);
119                         $Supplier = $GRNs['supplier_id'];
120                 }
121                 $rep->NewLine();
122                 $rep->TextCol(0, 1, $GRNs['id']);
123                 $rep->TextCol(1, 2, $GRNs['order_no']);
124                 $rep->TextCol(2, 3, $GRNs['item_code'] . '-' . $GRNs['description']);
125                 $rep->AmountCol(3, 4, $GRNs['qty_recd'], $dec2);
126                 $rep->AmountCol(4, 5, $GRNs['quantity_inv'], $dec2);
127                 $QtyOstg = $GRNs['qty_recd'] - $GRNs['quantity_inv'];
128                 $Value = ($GRNs['qty_recd'] - $GRNs['quantity_inv']) * $GRNs['unit_price'];
129                 $rep->AmountCol(5, 6, $QtyOstg, $dec2);
130                 $rep->AmountCol(6, 7, $GRNs['unit_price'], $dec);
131                 $rep->AmountCol(7, 8, $Value, $dec);
132                 $Tot_Val += $Value;
133                 $SuppTot_Val += $Value;
134
135                 $rep->NewLine(0, 1);
136         }
137         if ($Supplier != '')
138         {
139                 $rep->NewLine();
140                 $rep->TextCol(0, 7, _('Total'));
141                 $rep->AmountCol(7, 8, $SuppTot_Val, $dec);
142                 $rep->Line($rep->row - 2);
143                 $rep->NewLine(3);
144                 $SuppTot_Val = 0;
145         }
146         $rep->NewLine(2);
147         $rep->TextCol(0, 7, _('Grand Total'));
148         $rep->AmountCol(7, 8, $Tot_Val, $dec);
149         $rep->Line($rep->row - 2);
150         $rep->NewLine();
151     $rep->End();
152 }
153