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_DEPRECIATION';
15 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/admin/db/fiscalyears_db.inc");
19 include_once($path_to_root . "/includes/ui.inc");
20 include_once($path_to_root . "/includes/data_checks.inc");
21 include_once($path_to_root . "/includes/ui/items_cart.inc");
23 include_once($path_to_root . "/fixed_assets/includes/depreciation.inc");
24 include_once($path_to_root . "/fixed_assets/includes/fixed_assets_db.inc");
27 if (user_use_date_picker())
28 $js .= get_js_date_picker();
30 page(_($help_context = "Process Depreciation"), false, false, "", $js);
32 //---------------------------------------------------------------------------------------------
35 $myrow = get_item($_POST['stock_id']);
37 if ($_POST['months'] > depreciation_months($myrow['depreciation_date'])) {
38 display_error(_("The number of months is greater than the timespan between the depreciation start and the end of the fiscal year."));
46 //---------------------------------------------------------------------------------------------
48 function handle_submit()
53 $item = get_item($_POST['stock_id']);
55 $period = get_company_pref('depreciation_period');
56 $gl_rows = compute_gl_rows_for_depreciation($item, $_POST['months'], $period);
58 $trans_no = process_fixed_asset_depreciation($_POST['stock_id'], $gl_rows, $_POST['refline'], $_POST['memo_']);
60 meta_forward($_SERVER['PHP_SELF'], "AddedID=".$trans_no);
63 //---------------------------------------------------------------------------------------------
65 if (get_post('process'))
68 //---------------------------------------------------------------------------------------------
70 if (isset($_GET['AddedID']))
72 $trans_no = $_GET['AddedID'];
73 $trans_type = ST_JOURNAL;
75 display_notification(_("The fixed asset has been depreciated for this year"));
77 display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL &Postings for this Depreciation")), 1, 0);
79 hyperlink_no_params($_SERVER['PHP_SELF'], _("Depreciate &Another Fixed Asset"));
81 display_footer_exit();
84 //--------------------------------------------------------------------------------------
86 check_db_has_depreciable_fixed_assets(_("There are no fixed assets that could be depreciated."));
88 //---------------------------------------------------------------------------------------------
90 function show_gl_rows() {
92 $item = get_item($_POST['stock_id']);
99 start_table(TABLESTYLE, "width=40%");
100 $th = array(_("Item"), _('Date'), _('Account'), _('Debit'), _("Credit"));
103 $k = 0; //row colour counter
105 $period = get_company_pref('depreciation_period');
106 $gl_rows = compute_gl_rows_for_depreciation($item, $_POST['months'], $period);
108 foreach($gl_rows as $myrow)
110 alt_table_row_color($k);
111 label_cell($item['stock_id']);
112 label_cell($myrow["date"]);
113 label_cell($item['cogs_account'].' '.get_gl_account_name($item["cogs_account"]));
114 amount_cell($myrow["value"]);
118 alt_table_row_color($k);
119 label_cell($item['stock_id']);
120 label_cell($myrow["date"]);
121 label_cell($item["adjustment_account"].' '.get_gl_account_name($item["adjustment_account"]));
123 amount_cell($myrow["value"]);
129 submit_center('process', _("Process Depreciation"), true, false);
132 function show_gl_controls() {
135 check_db_has_depreciable_fixed_assets('There are no active fixed asset defined in the system.');
137 start_table(TABLESTYLE_NOBORDER);
139 stock_depreciable_fa_list_cells(_("Select an item:"), 'stock_id', null,
144 $myrow = get_item($_POST['stock_id']);
146 if (list_updated('stock_id') || !isset($_POST['months'])) {
147 //$_POST['depreciation_start'] = sql2date($myrow['depreciation_start']);
148 $_POST['months'] = depreciation_months($myrow['depreciation_date']);
149 unset($_POST['memo_']);
152 $Ajax->activate('depreciation_date');
153 $Ajax->activate('months');
154 $Ajax->activate('memo_');
156 start_table(TABLESTYLE2);
158 if (!isset($_POST['date']))
159 $_POST['date'] = Today();
161 $start = next_depreciation_date($myrow['depreciation_date']);
162 $start_text = _(date('F', $start)).' '.date('Y', $start);
164 //date_row(_("Starting from month").":", 'depreciation_start', '', null, 0, 0, 0, null, true);
165 label_row(_("Starting from month").":", $start_text, null, null, 0, 'depreciation_date');
166 $period = get_company_pref('depreciation_period');
167 if ($period != FA_YEARLY) {
168 text_row(_("Period").":", 'months', null, 4, 3, null, null, _("months"));
171 label_row(_("Period").":", '1 year');
174 refline_list_row(_("Reference line:"), 'refline', ST_JOURNAL, null, false, true);
175 textarea_row(_("Memo:"), 'memo_', null, 40,4);
179 submit_center_first('show', _("Show GL Rows"), true, false);
180 submit_center_last('process', _("Process Depreciation"), true, false);
183 //---------------------------------------------------------------------------------------------
187 if (isset($_POST['show']) && check_data())