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: GRN Valuation 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 . "/includes/banking.inc");
25 include_once($path_to_root . "/gl/includes/gl_db.inc");
26 include_once($path_to_root . "/inventory/includes/db/items_category_db.inc");
28 //----------------------------------------------------------------------------------------------------
30 print_grn_valuation();
32 function getTransactions($from, $to)
34 $from = date2sql($from);
36 $sql = "SELECT ".TB_PREF."grn_batch.delivery_date, ".TB_PREF."grn_batch.supplier_id,
37 ".TB_PREF."purch_order_details.*,
38 ".TB_PREF."stock_master.description
39 FROM ".TB_PREF."stock_master,
40 ".TB_PREF."purch_order_details,
42 WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."purch_order_details.item_code
43 AND ".TB_PREF."grn_batch.purch_order_no=".TB_PREF."purch_order_details.order_no
44 AND ".TB_PREF."purch_order_details.quantity_received>0
45 AND ".TB_PREF."grn_batch.delivery_date>='$from'
46 AND ".TB_PREF."grn_batch.delivery_date<='$to'
47 ORDER BY ".TB_PREF."stock_master.stock_id, ".TB_PREF."grn_batch.delivery_date";
48 return db_query($sql,"No transactions were returned");
52 //----------------------------------------------------------------------------------------------------
54 function print_grn_valuation()
58 $from = $_POST['PARAM_0'];
59 $to = $_POST['PARAM_1'];
60 $comments = $_POST['PARAM_2'];
61 $destination = $_POST['PARAM_3'];
63 include_once($path_to_root . "/reporting/includes/excel_report.inc");
65 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
67 $dec = user_price_dec();
69 $cols = array(0, 75, 225, 275, 345, 390, 445, 515);
70 $headers = array(_('Stock ID'), _('Description'), _('PO No'), _('Qty Received'), _('Unit Price'), _('Actual Price'), _('Total'));
72 $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right');
74 $params = array( 0 => $comments,
75 1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
77 $rep = new FrontReport(_('GRN Valuation Report'), "GRNValuationReport", user_pagesize());
80 $rep->Info($params, $cols, $headers, $aligns);
83 $res = getTransactions($from, $to);
84 $total = $qtotal = $grandtotal = 0.0;
86 while ($trans=db_fetch($res))
88 if ($stock_id != $trans['item_code'])
92 $rep->Line($rep->row - 4);
94 $rep->TextCol(0, 3, _('Total'));
95 $rep->AmountCol(3, 4, $qtotal, $qdec);
96 $rep->AmountCol(6, 7, $total, $dec);
100 $stock_id = $trans['item_code'];
102 $curr = get_supplier_currency($trans['supplier_id']);
103 $rate = get_exchange_rate_from_home_currency($curr, sql2date($trans['delivery_date']));
104 $trans['unit_price'] *= $rate;
105 $trans['act_price'] *= $rate;
108 $rep->TextCol(0, 1, $trans['item_code']);
109 $rep->TextCol(1, 2, $trans['description']);
110 $rep->TextCol(2, 3, $trans['order_no']);
111 $qdec = get_qty_dec($trans['item_code']);
112 $rep->AmountCol(3, 4, $trans['quantity_received'], $qdec);
113 $rep->AmountCol(4, 5, $trans['unit_price'], $dec);
114 $rep->AmountCol(5, 6, $trans['act_price'], $dec);
115 $amt = round2($trans['quantity_received'] * $trans['act_price'], $dec);
116 $rep->AmountCol(6, 7, $amt, $dec);
118 $qtotal += $trans['quantity_received'];
123 $rep->Line($rep->row - 4);
125 $rep->TextCol(0, 3, _('Total'));
126 $rep->AmountCol(3, 4, $qtotal, $qdec);
127 $rep->AmountCol(6, 7, $total, $dec);
128 $rep->Line($rep->row - 4);
130 $rep->TextCol(0, 6, _('Grand Total'));
131 $rep->AmountCol(6, 7, $grandtotal, $dec);
134 $rep->Line($rep->row - 4);