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_PAYTERMS';
14 include($path_to_root . "/includes/session.inc");
16 page(_($help_context = "Payment Terms"));
18 include($path_to_root . "/includes/ui.inc");
20 simple_page_mode(true);
22 //-------------------------------------------------------------------------------------------
24 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
29 if (!is_numeric($_POST['DayNumber']))
32 display_error( _("The number of days or the day in the following month must be numeric."));
33 set_focus('DayNumber');
35 elseif (strlen($_POST['terms']) == 0)
38 display_error( _("The Terms description must be entered."));
42 if ($_POST['DayNumber'] == '')
43 $_POST['DayNumber'] = 0;
45 if ($input_error != 1)
48 if ($selected_id != -1)
50 update_payment_terms($selected_id, get_post('terms'), get_post('type'), input_num('DayNumber', 0));
51 $note = _('Selected payment terms have been updated');
55 add_payment_terms(get_post('terms'), get_post('type'), input_num('DayNumber', 0));
56 $note = _('New payment terms have been added');
58 //run the sql from either of the above possibilites
59 display_notification($note);
64 if ($Mode == 'Delete')
66 // PREVENT DELETES IF DEPENDENT RECORDS IN debtors_master
67 if (key_in_foreign_table($selected_id, 'debtors_master', 'payment_terms'))
69 display_error(_("Cannot delete this payment term, because customer accounts have been created referring to this term."));
73 if (key_in_foreign_table($selected_id, 'suppliers', 'payment_terms'))
75 display_error(_("Cannot delete this payment term, because supplier accounts have been created referring to this term"));
79 //only delete if used in neither customer or supplier accounts
80 delete_payment_terms($selected_id);
81 display_notification(_('Selected payment terms have been deleted'));
84 //end if payment terms used in customer or supplier accounts
91 $sav = get_post('show_inactive');
93 $_POST['show_inactive'] = $sav;
95 //-------------------------------------------------------------------------------------------------
97 $result = get_payment_terms_all(check_value('show_inactive'));
100 start_table(TABLESTYLE);
101 $th = array(_("Description"), _("Type"), _("Due After/Days"), "", "");
102 inactive_control_column($th);
105 $k = 0; //row colour counter
106 while ($myrow = db_fetch($result))
108 $days = $myrow['days'];
109 alt_table_row_color($k);
110 label_cell($myrow["terms"]);
111 label_cell($pterm_types[$myrow['type']]);
112 label_cell($myrow['type'] == PTT_DAYS ? "$days "._("days") : ($myrow['type'] == PTT_FOLLOWING ? $days : _("N/A")));
113 inactive_control_cell($myrow["id"], $myrow["inactive"], 'payment_terms', "id");
114 edit_button_cell("Edit".$myrow["id"], _("Edit"));
115 delete_button_cell("Delete".$myrow["id"], _("Delete"));
120 inactive_control_row($th);
123 //-------------------------------------------------------------------------------------------------
124 if (list_updated('type')) {
125 $Ajax->activate('edits');
130 start_table(TABLESTYLE2);
132 if ($selected_id != -1)
134 if ($Mode == 'Edit') {
135 //editing an existing payment terms
136 $myrow = get_payment_terms($selected_id);
138 $_POST['terms'] = $myrow["terms"];
139 $_POST['type'] = $myrow['type'];
140 $_POST['DayNumber'] = $myrow['days'];
142 hidden('selected_id', $selected_id);
145 text_row(_("Terms Description:"), 'terms', null, 40, 40);
147 payment_type_list_row(_("Payment type:"), 'type', null, true);
149 if ( in_array(get_post('type'), array(PTT_FOLLOWING, PTT_DAYS)))
150 text_row_ex(_("Days (Or Day In Following Month):"), 'DayNumber', 3);
152 hidden('DayNumber', 0);
157 submit_add_or_update_center($selected_id == -1, '', 'both');