5 include($path_to_root . "/includes/session.inc");
7 page(_("Payment Terms"));
9 include($path_to_root . "/includes/ui.inc");
12 //-------------------------------------------------------------------------------------------
14 if (isset($_GET['selected_id']))
16 $selected_id = $_GET['selected_id'];
18 elseif (isset($_POST['selected_id']))
20 $selected_id = $_POST['selected_id'];
23 //-------------------------------------------------------------------------------------------
25 if (isset($_POST['ADD_ITEM']) OR isset($_POST['UPDATE_ITEM']))
30 if (!is_numeric($_POST['DayNumber']))
33 display_error( _("The number of days or the day in the following month must be numeric."));
35 elseif (strlen($_POST['terms']) == 0)
38 display_error( _("The Terms description must be entered."));
40 elseif ($_POST['DayNumber'] > 30 && !check_value('DaysOrFoll'))
43 display_error( _("When the check box to indicate a day in the following month is the due date, the due date cannot be a day after the 30th. A number between 1 and 30 is expected."));
45 elseif ($_POST['DayNumber'] > 500 && check_value('DaysOrFoll'))
48 display_error( _("When the check box is not checked to indicate that the term expects a number of days after which accounts are due, the number entered should be less than 500 days."));
51 if ($_POST['DayNumber'] == '')
52 $_POST['DayNumber'] = 0;
54 if ($inpug_error != 1)
56 if (isset($selected_id))
58 if (check_value('DaysOrFoll'))
60 $sql = "UPDATE ".TB_PREF."payment_terms SET terms='" . $_POST['terms'] . "',
61 day_in_following_month=0,
62 days_before_due=" . $_POST['DayNumber'] . "
63 WHERE terms_indicator = '" . $selected_id . "'";
67 $sql = "UPDATE ".TB_PREF."payment_terms SET terms='" . $_POST['terms'] . "',
68 day_in_following_month=" . $_POST['DayNumber'] . ",
70 WHERE terms_indicator = '" . $selected_id . "'";
77 if (check_value('DaysOrFoll'))
79 $sql = "INSERT INTO ".TB_PREF."payment_terms (terms,
80 days_before_due, day_in_following_month)
82 $_POST['terms'] . "', " . $_POST['DayNumber'] . ", 0)";
86 $sql = "INSERT INTO ".TB_PREF."payment_terms (terms,
87 days_before_due, day_in_following_month)
88 VALUES ('" . $_POST['terms'] . "',
89 0, " . $_POST['DayNumber'] . ")";
93 //run the sql from either of the above possibilites
94 db_query($sql,"The payment term could not be added or updated");
96 meta_forward($_SERVER['PHP_SELF']);
100 if (isset($_GET['delete']))
102 // PREVENT DELETES IF DEPENDENT RECORDS IN debtors_master
104 $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtors_master WHERE payment_terms = '$selected_id'";
105 $result = db_query($sql,"check failed");
106 $myrow = db_fetch_row($result);
109 display_error(_("Cannot delete this payment term, because customer accounts have been created referring to this term."));
113 $sql= "SELECT COUNT(*) FROM ".TB_PREF."suppliers WHERE payment_terms = '$selected_id'";
114 $result = db_query($sql,"check failed");
115 $myrow = db_fetch_row($result);
118 display_error(_("Cannot delete this payment term, because supplier accounts have been created referring to this term"));
122 //only delete if used in neither customer or supplier accounts
124 $sql="DELETE FROM ".TB_PREF."payment_terms WHERE terms_indicator='$selected_id'";
125 db_query($sql,"could not delete a payment terms");
127 meta_forward($_SERVER['PHP_SELF']);
130 //end if payment terms used in customer or supplier accounts
133 //-------------------------------------------------------------------------------------------------
135 $sql = "SELECT * FROM ".TB_PREF."payment_terms";
136 $result = db_query($sql,"could not get payment terms");
138 start_table($table_style);
139 $th = array(_("Description"), _("Following Month On"), _("Due After (Days)"), "", "");
142 $k = 0; //row colour counter
143 while ($myrow = db_fetch($result))
145 if ($myrow["day_in_following_month"] == 0)
147 $full_text = _("N/A");
151 $full_text = $myrow["day_in_following_month"];
154 if ($myrow["days_before_due"] == 0)
156 $after_text = _("N/A");
160 $after_text = $myrow["days_before_due"] . " " . _("days");
163 alt_table_row_color($k);
165 label_cell($myrow["terms"]);
166 label_cell($full_text);
167 label_cell($after_text);
168 edit_link_cell("selected_id=".$myrow["terms_indicator"]);
169 delete_link_cell("selected_id=".$myrow["terms_indicator"]."&delete=1");
173 } //END WHILE LIST LOOP
177 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Payment Term"));
179 //-------------------------------------------------------------------------------------------------
183 start_table($table_style2);
185 $day_in_following_month = $days_before_due = 0;
186 if (isset($selected_id))
188 //editing an existing payment terms
189 $sql = "SELECT * FROM ".TB_PREF."payment_terms
190 WHERE terms_indicator='$selected_id'";
192 $result = db_query($sql,"could not get payment term");
193 $myrow = db_fetch($result);
195 $_POST['terms'] = $myrow["terms"];
196 $days_before_due = $myrow["days_before_due"];
197 $day_in_following_month = $myrow["day_in_following_month"];
199 hidden('selected_id', $selected_id);
201 text_row(_("Terms Description:"), 'terms', null, 40, 40);
203 check_row(_("Due After A Given No. Of Days:"), 'DaysOrFoll', $day_in_following_month == 0);
205 if (!isset($_POST['DayNumber']))
207 if ($days_before_due != 0)
208 $_POST['DayNumber'] = $days_before_due;
210 $_POST['DayNumber'] = $day_in_following_month;
213 text_row_ex(_("Days (Or Day In Following Month):"), 'DayNumber', 3);
217 submit_add_or_update_center(!isset($selected_id));