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 ***********************************************************************/
13 // ----------------------------------------------------------------
17 // Title: Supplier Balances
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");
25 include_once($path_to_root . "/inventory/includes/db/items_category_db.inc");
27 //----------------------------------------------------------------------------------------------------
29 // trial_inquiry_controls();
30 print_inventory_valuation_report();
32 function getTransactions($category, $location)
34 $sql = "SELECT ".TB_PREF."stock_master.category_id,
35 ".TB_PREF."stock_category.description AS cat_description,
36 ".TB_PREF."stock_master.stock_id,
37 ".TB_PREF."stock_master.description,
38 ".TB_PREF."stock_moves.loc_code,
39 SUM(".TB_PREF."stock_moves.qty) AS QtyOnHand,
40 ".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost AS UnitCost,
41 SUM(".TB_PREF."stock_moves.qty) *(".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost) AS ItemTotal
42 FROM ".TB_PREF."stock_master,
43 ".TB_PREF."stock_category,
44 ".TB_PREF."stock_moves
45 WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id
46 AND ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
47 GROUP BY ".TB_PREF."stock_master.category_id,
48 ".TB_PREF."stock_category.description, ";
49 if ($location != 'all')
50 $sql .= TB_PREF."stock_moves.loc_code, ";
52 ".TB_PREF."stock_master.stock_id,
53 ".TB_PREF."stock_master.description
54 HAVING SUM(".TB_PREF."stock_moves.qty) != 0";
56 $sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
57 if ($location != 'all')
58 $sql .= " AND ".TB_PREF."stock_moves.loc_code = '$location'";
59 $sql .= " ORDER BY ".TB_PREF."stock_master.category_id,
60 ".TB_PREF."stock_master.stock_id";
62 return db_query($sql,"No transactions were returned");
65 //----------------------------------------------------------------------------------------------------
67 function print_inventory_valuation_report()
71 $category = $_POST['PARAM_0'];
72 $location = $_POST['PARAM_1'];
73 $detail = $_POST['PARAM_2'];
74 $comments = $_POST['PARAM_3'];
75 $destination = $_POST['PARAM_4'];
78 include_once($path_to_root . "/reporting/includes/excel_report.inc");
79 $filename = "InventoryValReport.xml";
83 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
84 $filename = "InventoryValReport.pdf";
87 $dec = user_price_dec();
89 if ($category == reserved_words::get_all_numeric())
94 $cat = get_category_name($category);
96 if ($location == reserved_words::get_all())
98 if ($location == 'all')
103 $cols = array(0, 100, 250, 350, 450, 515);
105 $headers = array(_('Category'), '', _('Quantity'), _('Unit Cost'), _('Value'));
107 $aligns = array('left', 'left', 'right', 'right', 'right');
109 $params = array( 0 => $comments,
110 1 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
111 2 => array('text' => _('Location'), 'from' => $loc, 'to' => ''));
113 $rep = new FrontReport(_('Inventory Valuation Report'), $filename, user_pagesize());
116 $rep->Info($params, $cols, $headers, $aligns);
119 $res = getTransactions($category, $location);
120 $total = $grandtotal = 0.0;
122 while ($trans=db_fetch($res))
124 if ($catt != $trans['cat_description'])
131 $rep->TextCol(0, 4, _('Total'));
133 $rep->AmountCol(4, 5, $total, $dec);
136 $rep->Line($rep->row - 2);
142 $rep->TextCol(0, 1, $trans['category_id']);
143 $rep->TextCol(1, 2, $trans['cat_description']);
144 $catt = $trans['cat_description'];
152 $rep->TextCol(0, 1, $trans['stock_id']);
153 $rep->TextCol(1, 2, $trans['description']);
154 $rep->AmountCol(2, 3, $trans['QtyOnHand'], get_qty_dec($trans['stock_id']));
155 $rep->AmountCol(3, 4, $trans['UnitCost'], $dec);
156 $rep->AmountCol(4, 5, $trans['ItemTotal'], $dec);
159 $total += $trans['ItemTotal'];
160 $grandtotal += $trans['ItemTotal'];
165 $rep->TextCol(0, 4, _('Total'));
167 $rep->Amountcol(4, 5, $total, $dec);
170 $rep->Line($rep->row - 2);
174 $rep->TextCol(0, 4, _('Grand Total'));
175 $rep->AmountCol(4, 5, $grandtotal, $dec);
176 $rep->Line($rep->row - 4);