New Fixed Assets Report file
[fa-stable.git] / reporting / rep451.php
1 <?php
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 // ----------------------------------------------------------------
14 // $ Revision:  2.0 $
15 // Creator:     Joe Hunt
16 // date_:       2015-12-01
17 // Title:       Fixed Assets Valuation
18 // ----------------------------------------------------------------
19 $path_to_root="..";
20
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
28 //----------------------------------------------------------------------------------------------------
29
30 print_fixed_assets_valuation_report();
31
32 //----------------------------------------------------------------------------------------------------
33
34 function print_fixed_assets_valuation_report()
35 {
36     global $path_to_root, $SysPrefs;
37
38         $date = $_POST['PARAM_0'];
39     $category = $_POST['PARAM_1'];
40     $location = $_POST['PARAM_2'];
41     $detail = $_POST['PARAM_3'];
42     $comments = $_POST['PARAM_4'];
43         $orientation = $_POST['PARAM_5'];
44         $destination = $_POST['PARAM_6'];
45         if ($destination)
46                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
47         else
48                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
49         $detail = !$detail;
50     $dec = user_price_dec();
51
52         $orientation = ($orientation ? 'L' : 'P');
53         if ($category == ALL_NUMERIC)
54                 $category = 0;
55         if ($category == 0)
56                 $cat = _('All');
57         else
58                 $cat = get_category_name($category);
59
60         if ($location == ALL_TEXT)
61                 $location = 'all';
62         if ($location == 'all')
63                 $loc = _('All');
64         else
65                 $loc = get_location_name($location);
66
67         $cols = array(0, 75, 225, 250, 350, 450,        515);
68
69         $headers = array(_('Class'), '', _('UOM'),  _('Amount'), _('Depreciations'), _('Balance'));
70
71         $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right');
72
73     $params =   array(  0 => $comments,
74                                         1 => array('text' => _('End Date'), 'from' => $date,            'to' => ''),
75                                     2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
76                                     3 => array('text' => _('Location'), 'from' => $loc, 'to' => ''));
77
78     $rep = new FrontReport(_('Fixed Assets Valuation Report'), "FixedAssetsValReport", user_pagesize(), 9, $orientation);
79     if ($orientation == 'L')
80         recalculate_cols($cols);
81     $rep->Font();
82     $rep->Info($params, $cols, $headers, $aligns);
83     $rep->NewPage();
84
85         //$res = getTransactions($category, $location, $date);
86         $sql = get_sql_for_fixed_assets(true);
87         $res = db_query($sql,"No transactions were returned");
88         
89         $total = $grandtotal = 0.0;
90         $catt = '';
91         while ($trans=db_fetch($res))
92         {
93                 if ($catt != $trans['description'])
94                 {
95                         if ($catt != '')
96                         {
97                                 if ($detail)
98                                 {
99                                         $rep->NewLine(2, 3);
100                                         $rep->TextCol(0, 4, _('Total'));
101                                 }
102                                 $rep->AmountCol(5, 6, $total, $dec);
103                                 if ($detail)
104                                 {
105                                         $rep->Line($rep->row - 2);
106                                         $rep->NewLine();
107                                 }
108                                 $rep->NewLine();
109                                 $total = 0.0;
110                         }
111                         $rep->TextCol(0, 2, $trans['description']);
112                         $catt = $trans['description'];
113                         if ($detail)
114                                 $rep->NewLine();
115                 }
116                 $UnitCost = $trans['last_cost'];
117                 $Depreciation = $trans['last_cost'] - $trans['material_cost'];;
118                 $Balance = $trans['material_cost'];
119                 if ($detail)
120                 {
121                         $rep->NewLine();
122                         $rep->TextCol(0, 1, $trans['stock_id']);
123                         $rep->TextCol(1, 2, $trans['name'].($trans['inactive']==1 ? " ("._("Inactive").")" : ""), -1);
124                         $rep->TextCol(2, 3, $trans['units']);
125                         $rep->AmountCol(3, 4, $UnitCost, $dec);
126                         $rep->AmountCol(4, 5, $Depreciation, $dec);
127                         $rep->AmountCol(5, 6, $Balance, $dec);
128                 }
129                 $total += $Balance;
130                 $grandtotal += $Balance;
131         }
132         if ($detail)
133         {
134                 $rep->NewLine(2, 3);
135                 $rep->TextCol(0, 4, _('Total'));
136         }
137         $rep->Amountcol(5, 6, $total, $dec);
138         if ($detail)
139         {
140                 $rep->Line($rep->row - 2);
141                 $rep->NewLine();
142         }
143         $rep->NewLine(2, 1);
144         $rep->TextCol(0, 4, _('Grand Total'));
145         $rep->AmountCol(5, 6, $grandtotal, $dec);
146         $rep->Line($rep->row  - 4);
147         $rep->NewLine();
148     $rep->End();
149 }
150