4 // ----------------------------------------------------------------
8 // Title: Supplier Balances
9 // ----------------------------------------------------------------
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "gl/includes/gl_db.inc");
16 include_once($path_to_root . "inventory/includes/db/items_category_db.inc");
18 //----------------------------------------------------------------------------------------------------
20 // trial_inquiry_controls();
21 print_inventory_valuation_report();
23 function getTransactions($category, $location)
25 $sql = "SELECT ".TB_PREF."stock_master.category_id,
26 ".TB_PREF."stock_category.description AS cat_description,
27 ".TB_PREF."stock_master.stock_id,
28 ".TB_PREF."stock_master.description,
29 ".TB_PREF."stock_moves.loc_code,
30 SUM(".TB_PREF."stock_moves.qty) AS QtyOnHand,
31 ".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost AS UnitCost,
32 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
33 FROM ".TB_PREF."stock_master,
34 ".TB_PREF."stock_category,
35 ".TB_PREF."stock_moves
36 WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id
37 AND ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
38 GROUP BY ".TB_PREF."stock_master.category_id,
39 ".TB_PREF."stock_category.description, ";
40 if ($location != 'all')
41 $sql .= TB_PREF."stock_moves.loc_code, ";
43 ".TB_PREF."stock_master.stock_id,
44 ".TB_PREF."stock_master.description
45 HAVING SUM(".TB_PREF."stock_moves.qty) != 0";
47 $sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
48 if ($location != 'all')
49 $sql .= " AND ".TB_PREF."stock_moves.loc_code = '$location'";
50 $sql .= " ORDER BY ".TB_PREF."stock_master.category_id,
51 ".TB_PREF."stock_master.stock_id";
53 return db_query($sql,"No transactions were returned");
56 //----------------------------------------------------------------------------------------------------
58 function print_inventory_valuation_report()
62 include_once($path_to_root . "reporting/includes/pdf_report.inc");
64 $category = $_POST['PARAM_0'];
65 $location = $_POST['PARAM_1'];
66 $detail = $_POST['PARAM_2'];
67 $comments = $_POST['PARAM_3'];
69 $dec = user_price_dec();
71 if ($category == reserved_words::get_all_numeric())
76 $cat = get_category_name($category);
78 if ($location == reserved_words::get_all())
80 if ($location == 'all')
85 $cols = array(0, 100, 250, 350, 450, 515);
87 $headers = array(_('Category'), '', _('Quantity'), _('Unit Cost'), _('Value'));
89 $aligns = array('left', 'left', 'right', 'right', 'right');
91 $params = array( 0 => $comments,
92 1 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
93 2 => array('text' => _('Location'), 'from' => $loc, 'to' => ''));
95 $rep = new FrontReport(_('Inventory Valuation Report'), "InventoryValReport.pdf", user_pagesize());
98 $rep->Info($params, $cols, $headers, $aligns);
101 $res = getTransactions($category, $location);
102 $total = $grandtotal = 0.0;
104 while ($trans=db_fetch($res))
106 if ($catt != $trans['cat_description'])
113 $rep->TextCol(0, 4, _('Total'));
115 $rep->Textcol(4, 5, number_format2($total, $dec));
118 $rep->Line($rep->row - 2);
124 $rep->TextCol(0, 1, $trans['category_id']);
125 $rep->TextCol(1, 2, $trans['cat_description']);
126 $catt = $trans['cat_description'];
134 $rep->TextCol(0, 1, $trans['stock_id']);
135 $rep->TextCol(1, 2, $trans['description']);
136 $rep->TextCol(2, 3, number_format2($trans['QtyOnHand'], get_qty_dec($trans['stock_id'])));
137 $rep->TextCol(3, 4, number_format2($trans['UnitCost'], $dec));
138 $rep->TextCol(4, 5, number_format2($trans['ItemTotal'], $dec));
141 $total += $trans['ItemTotal'];
142 $grandtotal += $trans['ItemTotal'];
147 $rep->TextCol(0, 4, _('Total'));
149 $rep->Textcol(4, 5, number_format2($total, $dec));
152 $rep->Line($rep->row - 2);
156 $rep->TextCol(0, 4, _('Grand Total'));
157 $rep->TextCol(4, 5, number_format2($grandtotal, $dec));
158 $rep->Line($rep->row - 4);