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_ = get_post('date_');
59 $freq = get_post('freq');
60 $lastdate = ($freq== 1?add_days($date_,7*$per):($freq==2?add_days($date_,14*$per):
61 ($freq==3?add_months($date_,$per):add_months($date_,3*$per))));
62 if (!is_date_in_fiscalyears($lastdate, false))
64 display_error(_("Some of the period dates are outside the fiscal year. Create a new fiscal year first!"));
68 if ($input_error == 0)
70 $amount = input_num('amount');
71 $am = round2($amount / $periods, user_price_dec());
72 if ($am * $periods != $amount)
73 $am0 = $am + $amount - $am * $periods;
76 if (get_post('memo_') != "")
77 $memo = $_POST['memo_'];
79 $memo = "Accruals for $amount";
80 if (isset($_POST['go']))
84 start_table(TABLESTYLE);
85 $dim = get_company_pref('use_dimension');
87 $first_cols = array(_("Date"), _("Account"));
89 $dim_cols = array(_("Dimension"). " 1", _("Dimension"). " 2");
91 $dim_cols = array(_("Dimension"));
95 $remaining_cols = array(_("Debit"), _("Credit"), _("Memo"));
97 $th = array_merge($first_cols, $dim_cols, $remaining_cols);
101 for ($i = 0; $i < $periods; $i++)
108 $date_ = add_days($date_, 7);
111 $date_ = add_days($date_, 14);
114 $date_ = add_months($date_, 1);
117 $date_ = add_months($date_, 3);
122 if (isset($_POST['go']))
124 $id = get_next_trans_no(ST_JOURNAL);
125 $ref = $Refs->get_next(ST_JOURNAL);
126 add_gl_trans(ST_JOURNAL, $id, $date_, get_post('acc_act'), 0,
128 add_gl_trans(ST_JOURNAL, $id, $date_, get_post('res_act'), get_post('dimension_id'),
129 get_post('dimension2_id'), $ref, $am0);
130 add_comments(ST_JOURNAL, $id, $date_, $memo);
131 $Refs->save(ST_JOURNAL, $id, $ref);
135 alt_table_row_color($k);
137 label_cell($_POST['acc_act'] . " " . get_gl_account_name($_POST['acc_act']));
142 display_debit_or_credit_cells($am0 * -1);
144 alt_table_row_color($k);
146 label_cell($_POST['res_act'] . " " . get_gl_account_name($_POST['res_act']));
148 label_cell(get_dimension_string($_POST['dimension_id'], true));
150 label_cell(get_dimension_string($_POST['dimension2_id'], true));
151 display_debit_or_credit_cells($am0);
155 if (isset($_POST['go']))
157 commit_transaction();
158 display_notification_centered(_("Revenue / Cost Accruals have been processed."));
159 $_POST['date_'] = $_POST['amount'] = $_POST['periods'] = "";
164 display_notification_centered(_("Showing GL Transactions."));
170 function frequency_list_row($label, $name, $selected=null)
173 label_cell($label, "class='label'");
177 '2'=> _("Bi-weekly"),
179 '4' => _("Quarterly"),
181 echo array_selector($name, $selected, $freq);
186 $dim = get_company_pref('use_dimension');
188 start_form(false, false, "", "accrual");
189 start_table(TABLESTYLE2);
191 date_row(_("Date"), 'date_', _('First date of Accruals'), true, 0, 0, 0, null, true);
193 label_cell(_("Accrued Balance Account"), "class='label'");
194 gl_all_accounts_list_cells(null, 'acc_act', null, true, false, false, true);
196 gl_all_accounts_list_row(_("Revenue / Cost Account"), 'res_act', null, true);
199 dimensions_list_row(_("Dimension"), 'dimension_id', null, true, " ", false, 1);
201 dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
203 $url = "gl/view/accrual_trans.php?act=".get_post('acc_act')."&date=".get_post('date_');
204 amount_row(_("Amount"), 'amount', null, null, viewer_link(_("Search Amount"), $url, "", "", ICON_VIEW));
206 frequency_list_row(_("Frequency"), 'freq', null);
208 text_row(_("Periods"), 'periods', null, 3, 3);
209 textarea_row(_("Memo"), 'memo_', null, 35, 3);
212 submit_center_first('show', _("Show GL Rows"));//,true,false,'process',ICON_SUBMIT);
213 submit_center_last('go', _("Process Accruals"));//,true,false,'process',ICON_SUBMIT);
214 submit_js_confirm('go', _("Are you sure you want to post accruals?"));