Changed license type to GPLv3 in top of files
[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 = 2;
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 // trial_inquiry_controls();
29 print_outstanding_GRN();
30
31 function getTransactions($fromsupp)
32 {
33         $sql = "SELECT ".TB_PREF."grn_batch.id,
34                         order_no,
35                         ".TB_PREF."grn_batch.supplier_id,
36                         ".TB_PREF."suppliers.supp_name,
37                         ".TB_PREF."grn_items.item_code,
38                         ".TB_PREF."grn_items.description,
39                         qty_recd,
40                         quantity_inv,
41                         std_cost_unit,
42                         act_price,
43                         unit_price
44                 FROM ".TB_PREF."grn_items,
45                         ".TB_PREF."grn_batch,
46                         ".TB_PREF."purch_order_details,
47                         ".TB_PREF."suppliers
48                 WHERE ".TB_PREF."grn_batch.supplier_id=".TB_PREF."suppliers.supplier_id
49                 AND ".TB_PREF."grn_batch.id = ".TB_PREF."grn_items.grn_batch_id
50                 AND ".TB_PREF."grn_items.po_detail_item = ".TB_PREF."purch_order_details.po_detail_item
51                 AND qty_recd-quantity_inv <>0 ";
52         if ($fromsupp != reserved_words::get_all_numeric())
53                 $sql .= "AND ".TB_PREF."grn_batch.supplier_id ='" . $fromsupp . "' ";
54         $sql .= "ORDER BY ".TB_PREF."grn_batch.supplier_id,
55                         ".TB_PREF."grn_batch.id";
56
57     return db_query($sql, "No transactions were returned");
58 }
59
60 //----------------------------------------------------------------------------------------------------
61
62 function print_outstanding_GRN()
63 {
64     global $path_to_root;
65
66     include_once($path_to_root . "/reporting/includes/pdf_report.inc");
67
68     $fromsupp = $_POST['PARAM_0'];
69     $comments = $_POST['PARAM_1'];
70
71         if ($fromsupp == reserved_words::get_all_numeric())
72                 $from = _('All');
73         else
74                 $from = get_supplier_name($fromsupp);
75     $dec = user_price_dec();
76
77         $cols = array(0, 40, 80, 190,   250, 320, 385, 450,     515);
78
79         $headers = array(_('GRN'), _('Order'), _('Item') . '/' . _('Description'), _('Qty Recd'), _('qty Inv'), _('Balance'),
80                 _('Std Cost'), _('Value'));
81
82         $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
83
84     $params =   array(  0 => $comments,
85                                     1 => array('text' => _('Supplier'), 'from' => $from, 'to' => ''));
86
87     $rep = new FrontReport(_('Outstanding GRNs Report'), "OutstandingGRN.pdf", user_pagesize());
88
89     $rep->Font();
90     $rep->Info($params, $cols, $headers, $aligns);
91     $rep->Header();
92
93         $Tot_Val=0;
94         $Supplier = '';
95         $SuppTot_Val=0;
96         $res = getTransactions($fromsupp);
97
98         While ($GRNs = db_fetch($res))
99         {
100                 $dec2 = get_qty_dec($GRNs['item_code']);
101                 if ($Supplier != $GRNs['supplier_id'])
102                 {
103                         if ($Supplier != '')
104                         {
105                                 $rep->NewLine(2);
106                                 $rep->TextCol(0, 7, _('Total'));
107                                 $rep->TextCol(7, 8, number_format2($SuppTot_Val, $dec));
108                                 $rep->Line($rep->row - 2);
109                                 $rep->NewLine(3);
110                                 $SuppTot_Val = 0;
111                         }
112                         $rep->TextCol(0, 6, $GRNs['supp_name']);
113                         $Supplier = $GRNs['supplier_id'];
114                 }
115                 $rep->NewLine();
116                 $rep->TextCol(0, 1, $GRNs['id']);
117                 $rep->TextCol(1, 2, $GRNs['order_no']);
118                 $rep->TextCol(2, 3, $GRNs['item_code'] . '-' . $GRNs['description']);
119                 $rep->TextCol(3, 4, number_format2($GRNs['qty_recd'], $dec2));
120                 $rep->TextCol(4, 5, number_format2($GRNs['quantity_inv'], $dec2));
121                 $QtyOstg = $GRNs['qty_recd'] - $GRNs['quantity_inv'];
122                 $Value = ($GRNs['qty_recd'] - $GRNs['quantity_inv']) * $GRNs['std_cost_unit'];
123                 $rep->TextCol(5, 6, number_format2($QtyOstg, $dec2));
124                 $rep->TextCol(6, 7, number_format2($GRNs['std_cost_unit'], $dec));
125                 $rep->TextCol(7, 8, number_format2($Value, $dec));
126                 $Tot_Val += $Value;
127                 $SuppTot_Val += $Value;
128
129                 $rep->NewLine(0, 1);
130         }
131         if ($Supplier != '')
132         {
133                 $rep->NewLine();
134                 $rep->TextCol(0, 7, _('Total'));
135                 $rep->TextCol(7, 8, number_format2($SuppTot_Val, $dec));
136                 $rep->Line($rep->row - 2);
137                 $rep->NewLine(3);
138                 $SuppTot_Val = 0;
139         }
140         $rep->NewLine(2);
141         $rep->TextCol(0, 7, _('Grand Total'));
142         $rep->TextCol(7, 8, number_format2($Tot_Val, $dec));
143         $rep->Line($rep->row - 2);
144     $rep->End();
145 }
146
147 ?>