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