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_ASSETSANALYTIC';
13 // ----------------------------------------------------------------
17 // Title: Fixed Assets Valuation
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");
26 include_once($path_to_root . "/fixed_assets/includes/fixed_assets_db.inc");
27 include_once($path_to_root . "/fixed_assets/includes/fa_classes_db.inc");
29 function find_last_location($stock_id, $end_date)
31 $end_date = date2sql($end_date);
32 $sql = "SELECT loc_code FROM ".TB_PREF."stock_moves WHERE stock_id = ".db_escape($stock_id)." AND
33 tran_date <= '$end_date' ORDER BY tran_date DESC LIMIT 1";
34 $res = db_query($sql,"No stock moves were returned");
35 $row = db_fetch_row($res);
39 //----------------------------------------------------------------------------------------------------
41 print_fixed_assets_valuation_report();
43 //----------------------------------------------------------------------------------------------------
45 function print_fixed_assets_valuation_report()
47 global $path_to_root, $SysPrefs;
49 $date = $_POST['PARAM_0'];
50 $class = $_POST['PARAM_1'];
51 $location = $_POST['PARAM_2'];
52 $detail = $_POST['PARAM_3'];
53 $comments = $_POST['PARAM_4'];
54 $orientation = $_POST['PARAM_5'];
55 $destination = $_POST['PARAM_6'];
57 include_once($path_to_root . "/reporting/includes/excel_report.inc");
59 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
61 $dec = user_price_dec();
63 $orientation = ($orientation ? 'L' : 'P');
64 if ($class == ALL_NUMERIC)
69 $cln = get_fixed_asset_classname($class);
71 if ($location == ALL_TEXT)
73 if ($location == 'all')
76 $loc = get_location_name($location);
78 $cols = array(0, 75, 225, 250, 350, 450, 515);
80 $headers = array(_('Class'), '', _('UOM'), _('Initial'), _('Depreciations'), _('Current'));
82 $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right');
84 $params = array( 0 => $comments,
85 1 => array('text' => _('End Date'), 'from' => $date, 'to' => ''),
86 2 => array('text' => _('Class'), 'from' => $cln, 'to' => ''),
87 3 => array('text' => _('Location'), 'from' => $loc, 'to' => ''));
89 $rep = new FrontReport(_('Fixed Assets Valuation Report'), "FixedAssetsValReport", user_pagesize(), 9, $orientation);
90 if ($orientation == 'L')
91 recalculate_cols($cols);
93 $rep->Info($params, $cols, $headers, $aligns);
96 //$res = getTransactions($category, $location, $date);
97 $sql = get_sql_for_fixed_assets(true);
98 $res = db_query($sql,"No transactions were returned");
100 $total = $grandtotal = 0.0;
102 while ($trans=db_fetch($res))
104 $loc = find_last_location($trans['stock_id'], $date);
105 if ($location != 'all' && $location != $loc)
107 $purchase = get_fixed_asset_purchase($trans['stock_id']);
108 $d = sql2date($purchase['tran_date']);
109 if (date1_greater_date2($d, $date))
111 if ($class != 0 && $cln != $trans['description'])
113 if ($catt != $trans['description'])
120 $rep->TextCol(0, 4, _('Total'));
122 $rep->AmountCol(5, 6, $total, $dec);
125 $rep->Line($rep->row - 2);
131 $rep->TextCol(0, 2, $trans['description']);
132 $catt = $trans['description'];
136 $UnitCost = $trans['purchase_cost'];
137 $Depreciation = $trans['purchase_cost'] - $trans['material_cost'];
138 $Balance = $trans['material_cost'];
142 $rep->TextCol(0, 1, $trans['stock_id']);
143 $rep->TextCol(1, 2, $trans['name'].($trans['inactive']==1 ? " ("._("Inactive").")" : ""), -1);
144 $rep->TextCol(2, 3, $trans['units']);
145 $rep->AmountCol(3, 4, $UnitCost, $dec);
146 $rep->AmountCol(4, 5, $Depreciation, $dec);
147 $rep->AmountCol(5, 6, $Balance, $dec);
150 $grandtotal += $Balance;
155 $rep->TextCol(0, 4, _('Total'));
157 $rep->Amountcol(5, 6, $total, $dec);
160 $rep->Line($rep->row - 2);
164 $rep->TextCol(0, 4, _('Grand Total'));
165 $rep->AmountCol(5, 6, $grandtotal, $dec);
166 $rep->Line($rep->row - 4);