2 /**********************************************
4 Name: Revenue / Cost Accruals v2.2
5 Free software under GNU GPL
6 ***********************************************/
7 $page_security = 'SA_ACCRUALS';
10 include_once($path_to_root . "/includes/session.inc");
11 include_once($path_to_root . "/gl/includes/db/gl_db_trans.inc");
13 $js = get_js_open_window(800, 500);
15 $js .= get_js_date_picker();
18 include_once($path_to_root . "/includes/ui.inc");
20 $_SESSION['page_title'] = _($help_context = "Revenue / Cost Accruals");
21 page($_SESSION['page_title'], false, false,'', $js);
23 //--------------------------------------------------------------------------------------------------
24 if (!isset($_POST['freq']))
26 // If the import button was selected, we'll process the form here. (If not, skip to actual content below.)
27 if (isset($_POST['go']) || isset($_POST['show']))
30 if (!is_date($_POST['date_']))
32 display_error(_("The entered date is invalid."));
36 elseif (!is_date_in_fiscalyear($_POST['date_']))
38 display_error(_("The entered date is not in fiscal year."));
42 elseif (input_num('amount', 0) == 0.0)
44 display_error(_("The amount can not be 0."));
48 elseif (input_num('periods', 0) < 1)
50 display_error(_("The periods must be greater than 0."));
54 if ($input_error == 0)
56 $periods = input_num('periods');
58 $date = $date_ = get_post('date_');
59 $freq = get_post('freq');
60 $lastdate = ($freq == 1 ? add_days($date_, 7*$per)
61 : ($freq == 2 ? add_days($date_, 14*$per)
62 : ($freq == 3 ? add_months($date_, $per)
63 : add_months($date_, 3*$per))));
65 if (!is_date_in_fiscalyears($lastdate, false))
67 display_error(_("Some of the period dates are outside the fiscal year. Create a new fiscal year first!"));
71 if ($input_error == 0)
73 $amount = input_num('amount');
74 $am = round2($amount / $periods, user_price_dec());
75 if ($am * $periods != $amount)
76 $am0 = $am + $amount - $am * $periods;
79 if (get_post('memo_') != "")
80 $memo = $_POST['memo_'];
82 $memo = sprintf(_("Accruals for %s"), $amount);
83 if (isset($_POST['go']))
87 start_table(TABLESTYLE);
88 $dim = get_company_pref('use_dimension');
90 $first_cols = array(_("Date"), _("Account"));
92 $dim_cols = array(_("Dimension"). " 1", _("Dimension"). " 2");
94 $dim_cols = array(_("Dimension"));
98 $remaining_cols = array(_("Debit"), _("Credit"), _("Memo"));
100 $th = array_merge($first_cols, $dim_cols, $remaining_cols);
104 for ($i = 0; $i < $periods; $i++)
111 $date = add_days($date_, $i*7);
114 $date = add_days($date_, $i*14);
117 $date = add_months($date_, $i*1);
120 $date = add_months($date_, $i*3);
125 if (isset($_POST['go']))
127 $id = get_next_trans_no(ST_JOURNAL);
128 $ref = $Refs->get_next(ST_JOURNAL);
129 add_gl_trans(ST_JOURNAL, $id, $date, get_post('acc_act'), 0,
131 add_gl_trans(ST_JOURNAL, $id, $date, get_post('res_act'), get_post('dimension_id'),
132 get_post('dimension2_id'), $ref, $am0);
133 add_audit_trail(ST_JOURNAL, $id, $date);
134 add_comments(ST_JOURNAL, $id, $date, $memo);
135 $Refs->save(ST_JOURNAL, $id, $ref);
139 alt_table_row_color($k);
141 label_cell($_POST['acc_act'] . " " . get_gl_account_name($_POST['acc_act']));
146 display_debit_or_credit_cells($am0 * -1);
148 alt_table_row_color($k);
150 label_cell($_POST['res_act'] . " " . get_gl_account_name($_POST['res_act']));
152 label_cell(get_dimension_string($_POST['dimension_id'], true));
154 label_cell(get_dimension_string($_POST['dimension2_id'], true));
155 display_debit_or_credit_cells($am0);
159 if (isset($_POST['go']))
161 commit_transaction();
162 display_notification_centered(_("Revenue / Cost Accruals have been processed."));
163 $_POST['date_'] = $_POST['amount'] = $_POST['periods'] = "";
168 display_notification_centered(_("Showing GL Transactions."));
174 function frequency_list_row($label, $name, $selected=null)
177 label_cell($label, "class='label'");
181 '2'=> _("Bi-weekly"),
183 '4' => _("Quarterly"),
185 echo array_selector($name, $selected, $freq);
190 $dim = get_company_pref('use_dimension');
192 start_form(false, false, "", "accrual");
193 start_table(TABLESTYLE2);
195 date_row(_("Date"), 'date_', _('First date of Accruals'), true, 0, 0, 0, null, true);
197 label_cell(_("Accrued Balance Account"), "class='label'");
198 gl_all_accounts_list_cells(null, 'acc_act', null, true, false, false, true);
200 gl_all_accounts_list_row(_("Revenue / Cost Account"), 'res_act', null, true);
203 dimensions_list_row(_("Dimension"), 'dimension_id', null, true, " ", false, 1);
205 dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
207 $url = "gl/view/accrual_trans.php?act=".get_post('acc_act')."&date=".get_post('date_');
208 amount_row(_("Amount"), 'amount', null, null, viewer_link(_("Search Amount"), $url, "", "", ICON_VIEW));
210 frequency_list_row(_("Frequency"), 'freq', null);
212 text_row(_("Periods"), 'periods', null, 3, 3);
213 textarea_row(_("Memo"), 'memo_', null, 35, 3);
216 submit_center_first('show', _("Show GL Rows"));//,true,false,'process',ICON_SUBMIT);
217 submit_center_last('go', _("Process Accruals"));//,true,false,'process',ICON_SUBMIT);
218 submit_js_confirm('go', _("Are you sure you want to post accruals?"));