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 grn.id,
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";
51 if ($fromsupp != ALL_TEXT)
52 $sql .= " AND grn.supplier_id =".db_escape($fromsupp);
54 $sql .= " ORDER BY grn.supplier_id, grn.id";
56 return db_query($sql, "No transactions were returned");
59 //----------------------------------------------------------------------------------------------------
61 function print_outstanding_GRN()
65 $fromsupp = $_POST['PARAM_0'];
66 $comments = $_POST['PARAM_1'];
67 $orientation = $_POST['PARAM_2'];
68 $destination = $_POST['PARAM_3'];
70 include_once($path_to_root . "/reporting/includes/excel_report.inc");
72 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
74 $orientation = ($orientation ? 'L' : 'P');
75 if ($fromsupp == ALL_TEXT)
78 $from = get_supplier_name($fromsupp);
79 $dec = user_price_dec();
81 $cols = array(0, 40, 80, 190, 250, 320, 385, 450, 515);
83 $headers = array(_('GRN'), _('Order'), _('Item') . '/' . _('Description'), _('Qty Recd'), _('qty Inv'), _('Balance'),
84 _('Act Price'), _('Value'));
86 $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
88 $params = array( 0 => $comments,
89 1 => array('text' => _('Supplier'), 'from' => $from, 'to' => ''));
91 $rep = new FrontReport(_('Outstanding GRNs Report'), "OutstandingGRN", user_pagesize(), 9, $orientation);
92 if ($orientation == 'L')
93 recalculate_cols($cols);
96 $rep->Info($params, $cols, $headers, $aligns);
102 $res = getTransactions($fromsupp);
104 while ($GRNs = db_fetch($res))
106 $dec2 = get_qty_dec($GRNs['item_code']);
107 if ($Supplier != $GRNs['supplier_id'])
112 $rep->TextCol(0, 7, _('Total'));
113 $rep->AmountCol(7, 8, $SuppTot_Val, $dec);
114 $rep->Line($rep->row - 2);
118 $rep->TextCol(0, 6, $GRNs['supp_name']);
119 $Supplier = $GRNs['supplier_id'];
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);
133 $SuppTot_Val += $Value;
140 $rep->TextCol(0, 7, _('Total'));
141 $rep->AmountCol(7, 8, $SuppTot_Val, $dec);
142 $rep->Line($rep->row - 2);
147 $rep->TextCol(0, 7, _('Grand Total'));
148 $rep->AmountCol(7, 8, $Tot_Val, $dec);
149 $rep->Line($rep->row - 2);