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);
37 $sql = "SELECT DISTINCT ".TB_PREF."grn_batch.supplier_id,
38 ".TB_PREF."purch_order_details.*,
39 ".TB_PREF."stock_master.description, ".TB_PREF."stock_master.inactive
40 FROM ".TB_PREF."stock_master,
41 ".TB_PREF."purch_order_details,
43 WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."purch_order_details.item_code
44 AND ".TB_PREF."grn_batch.purch_order_no=".TB_PREF."purch_order_details.order_no
45 AND ".TB_PREF."purch_order_details.quantity_received>0
46 AND ".TB_PREF."grn_batch.delivery_date>='$from'
47 AND ".TB_PREF."grn_batch.delivery_date<='$to'
48 ORDER BY ".TB_PREF."stock_master.stock_id, ".TB_PREF."grn_batch.delivery_date";
50 return db_query($sql,"No transactions were returned");
54 //----------------------------------------------------------------------------------------------------
56 function print_grn_valuation()
60 $from = $_POST['PARAM_0'];
61 $to = $_POST['PARAM_1'];
62 $comments = $_POST['PARAM_2'];
63 $destination = $_POST['PARAM_3'];
65 include_once($path_to_root . "/reporting/includes/excel_report.inc");
67 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
69 $dec = user_price_dec();
71 $cols = array(0, 75, 225, 275, 345, 390, 445, 515);
72 $headers = array(_('Stock ID'), _('Description'), _('PO No'), _('Qty Received'), _('Unit Price'), _('Actual Price'), _('Total'));
74 $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right');
76 $params = array( 0 => $comments,
77 1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
79 $rep = new FrontReport(_('GRN Valuation Report'), "GRNValuationReport", user_pagesize());
82 $rep->Info($params, $cols, $headers, $aligns);
85 $res = getTransactions($from, $to);
86 $total = $qtotal = $grandtotal = 0.0;
88 while ($trans=db_fetch($res))
90 if ($stock_id != $trans['item_code'])
94 $rep->Line($rep->row - 4);
96 $rep->TextCol(0, 3, _('Total'));
97 $rep->AmountCol(3, 4, $qtotal, $qdec);
98 $rep->AmountCol(6, 7, $total, $dec);
100 $total = $qtotal = 0;
102 $stock_id = $trans['item_code'];
104 $curr = get_supplier_currency($trans['supplier_id']);
105 $rate = get_exchange_rate_from_home_currency($curr, sql2date($trans['delivery_date']));
106 $trans['unit_price'] *= $rate;
107 $trans['act_price'] *= $rate;
110 $rep->TextCol(0, 1, $trans['item_code']);
111 $rep->TextCol(1, 2, $trans['description'].($trans['inactive']==1 ? " ("._("Inactive").")" : ""), -1);
112 $rep->TextCol(2, 3, $trans['order_no']);
113 $qdec = get_qty_dec($trans['item_code']);
114 $rep->AmountCol(3, 4, $trans['quantity_received'], $qdec);
115 $rep->AmountCol(4, 5, $trans['unit_price'], $dec);
116 $rep->AmountCol(5, 6, $trans['act_price'], $dec);
117 $amt = round2($trans['quantity_received'] * $trans['act_price'], $dec);
118 $rep->AmountCol(6, 7, $amt, $dec);
120 $qtotal += $trans['quantity_received'];
125 $rep->Line($rep->row - 4);
127 $rep->TextCol(0, 3, _('Total'));
128 $rep->AmountCol(3, 4, $qtotal, $qdec);
129 $rep->AmountCol(6, 7, $total, $dec);
130 $rep->Line($rep->row - 4);
132 $rep->TextCol(0, 6, _('Grand Total'));
133 $rep->AmountCol(6, 7, $grandtotal, $dec);
136 $rep->Line($rep->row - 4);