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 // ----------------------------------------------------------------
17 // Title: Outstanding GRNs Report
18 // ----------------------------------------------------------------
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");
26 //----------------------------------------------------------------------------------------------------
28 print_outstanding_GRN();
30 function getTransactions($fromsupp)
32 $sql = "SELECT ".TB_PREF."grn_batch.id,
34 ".TB_PREF."grn_batch.supplier_id,
35 ".TB_PREF."suppliers.supp_name,
36 ".TB_PREF."grn_items.item_code,
37 ".TB_PREF."grn_items.description,
43 FROM ".TB_PREF."grn_items,
45 ".TB_PREF."purch_order_details,
47 WHERE ".TB_PREF."grn_batch.supplier_id=".TB_PREF."suppliers.supplier_id
48 AND ".TB_PREF."grn_batch.id = ".TB_PREF."grn_items.grn_batch_id
49 AND ".TB_PREF."grn_items.po_detail_item = ".TB_PREF."purch_order_details.po_detail_item
50 AND qty_recd-quantity_inv <>0 ";
52 if ($fromsupp != ALL_NUMERIC)
53 $sql .= "AND ".TB_PREF."grn_batch.supplier_id =".db_escape($fromsupp)." ";
54 $sql .= "ORDER BY ".TB_PREF."grn_batch.supplier_id,
55 ".TB_PREF."grn_batch.id";
57 return db_query($sql, "No transactions were returned");
60 //----------------------------------------------------------------------------------------------------
62 function print_outstanding_GRN()
66 $fromsupp = $_POST['PARAM_0'];
67 $comments = $_POST['PARAM_1'];
68 $destination = $_POST['PARAM_2'];
70 include_once($path_to_root . "/reporting/includes/excel_report.inc");
72 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
74 if ($fromsupp == ALL_NUMERIC)
77 $from = get_supplier_name($fromsupp);
78 $dec = user_price_dec();
80 $cols = array(0, 40, 80, 190, 250, 320, 385, 450, 515);
82 $headers = array(_('GRN'), _('Order'), _('Item') . '/' . _('Description'), _('Qty Recd'), _('qty Inv'), _('Balance'),
83 _('Act Price'), _('Value'));
85 $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
87 $params = array( 0 => $comments,
88 1 => array('text' => _('Supplier'), 'from' => $from, 'to' => ''));
90 $rep = new FrontReport(_('Outstanding GRNs Report'), "OutstandingGRN", user_pagesize());
93 $rep->Info($params, $cols, $headers, $aligns);
99 $res = getTransactions($fromsupp);
101 While ($GRNs = db_fetch($res))
103 $dec2 = get_qty_dec($GRNs['item_code']);
104 if ($Supplier != $GRNs['supplier_id'])
109 $rep->TextCol(0, 7, _('Total'));
110 $rep->AmountCol(7, 8, $SuppTot_Val, $dec);
111 $rep->Line($rep->row - 2);
115 $rep->TextCol(0, 6, $GRNs['supp_name']);
116 $Supplier = $GRNs['supplier_id'];
119 $rep->TextCol(0, 1, $GRNs['id']);
120 $rep->TextCol(1, 2, $GRNs['order_no']);
121 $rep->TextCol(2, 3, $GRNs['item_code'] . '-' . $GRNs['description']);
122 $rep->AmountCol(3, 4, $GRNs['qty_recd'], $dec2);
123 $rep->AmountCol(4, 5, $GRNs['quantity_inv'], $dec2);
124 $QtyOstg = $GRNs['qty_recd'] - $GRNs['quantity_inv'];
125 $Value = ($GRNs['qty_recd'] - $GRNs['quantity_inv']) * $GRNs['act_price'];
126 $rep->AmountCol(5, 6, $QtyOstg, $dec2);
127 $rep->AmountCol(6, 7, $GRNs['act_price'], $dec);
128 $rep->AmountCol(7, 8, $Value, $dec);
130 $SuppTot_Val += $Value;
137 $rep->TextCol(0, 7, _('Total'));
138 $rep->AmountCol(7, 8, $SuppTot_Val, $dec);
139 $rep->Line($rep->row - 2);
144 $rep->TextCol(0, 7, _('Grand Total'));
145 $rep->AmountCol(7, 8, $Tot_Val, $dec);
146 $rep->Line($rep->row - 2);