X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=admin%2Fpayment_terms.php;h=56f6652c432af93f60eb1f33f8d1784e5bf6a943;hb=7618d9d62ee39a932f56565a4ce25d965bf53462;hp=76ccd53eb3f3ebebcf0768cc92cebbf2422d428b;hpb=bb991dc5b071e966b39954bb53d3b0efe8420938;p=fa-stable.git diff --git a/admin/payment_terms.php b/admin/payment_terms.php index 76ccd53e..56f6652c 100644 --- a/admin/payment_terms.php +++ b/admin/payment_terms.php @@ -19,25 +19,6 @@ include($path_to_root . "/includes/ui.inc"); simple_page_mode(true); -//------------------------------ -// Helper to translate record content to more intuitive form -// -function term_days($myrow) -{ - return $myrow["day_in_following_month"] != 0 ? $myrow["day_in_following_month"] : - $myrow["days_before_due"]; -} - -function term_type($myrow) -{ - if ($myrow["day_in_following_month"] != 0) - return PTT_FOLLOWING; - - $days = $myrow["days_before_due"]; - - return $days < 0 ? PTT_PRE : ($days ? PTT_DAYS : PTT_CASH); -} - //------------------------------------------------------------------------------------------- if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') @@ -57,28 +38,36 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') display_error( _("The Terms description must be entered.")); set_focus('terms'); } - - if ($_POST['DayNumber'] == '') - $_POST['DayNumber'] = 0; + $early_days = input_num('early_days', 0); + if ($early_days) { + if ($early_days >= $_POST['DayNumber']) { + $input_error = 1; + display_error(_("Early payment days option should be shorter that payment term days.")); + set_focus('early_days'); + } else if (!check_num('early_discount', 0, 100) or input_num('early_discount') == 0) + { + $input_error = 1; + display_error(_("The payment discount must be numeric and is expected to be less than 100% and greater than or equal to 0.")); + set_focus('early_discount'); + } + } else { + if (input_num('early_discount', 0)) { + $input_error = 1; + display_error(_("Early payment days option should be positive and less than payment term days.")); + set_focus('early_days'); + } + } if ($input_error != 1) { - $type = get_post('type'); - $days = input_num('DayNumber'); - $from_now = ($type != PTT_FOLLOWING); - if ($type == PTT_CASH) - $days = 0; - if ($type == PTT_PRE) - $days = -1; - if ($selected_id != -1) { - update_payment_terms($selected_id, $from_now, $_POST['terms'], $days); + update_payment_terms($selected_id, get_post('terms'), get_post('type'), input_num('DayNumber', 0), input_num('early_discount')/100, $early_days); $note = _('Selected payment terms have been updated'); } else { - add_payment_terms($from_now, $_POST['terms'], $days); + add_payment_terms(get_post('terms'), get_post('type'), input_num('DayNumber', 0), input_num('early_discount')/100, $early_days); $note = _('New payment terms have been added'); } //run the sql from either of the above possibilites @@ -124,23 +113,24 @@ $result = get_payment_terms_all(check_value('show_inactive')); start_form(); start_table(TABLESTYLE); -$th = array(_("Description"), _("Type"), _("Due After/Days"), "", ""); +$th = array(_("Description"), _("Type"), _("Due After/Days"), _("Early payment discount"),"", ""); inactive_control_column($th); table_header($th); $k = 0; //row colour counter while ($myrow = db_fetch($result)) { + $days = $myrow['days']; + $percent = $myrow['early_discount']; alt_table_row_color($k); - $type = term_type($myrow); - $days = term_days($myrow); label_cell($myrow["terms"]); - label_cell($pterm_types[$type]); - label_cell($type == PTT_DAYS ? "$days "._("days") : ($type == PTT_FOLLOWING ? $days : _("N/A"))); - inactive_control_cell($myrow["terms_indicator"], $myrow["inactive"], 'payment_terms', "terms_indicator"); - edit_button_cell("Edit".$myrow["terms_indicator"], _("Edit")); - delete_button_cell("Delete".$myrow["terms_indicator"], _("Delete")); + label_cell($pterm_types[$myrow['type']]); + label_cell($myrow['type'] == PTT_DAYS ? "$days "._("days") : ($myrow['type'] == PTT_FOLLOWING ? $days : _("N/A"))); + label_cell(in_array($myrow['type'], array(PTT_FOLLOWING, PTT_DAYS)) ? ($percent==0 ? _("None") : ($percent*100).'/'.$myrow['early_days']) : _("N/A")); + inactive_control_cell($myrow["id"], $myrow["inactive"], 'payment_terms', "id"); + edit_button_cell("Edit".$myrow["id"], _("Edit")); + delete_button_cell("Delete".$myrow["id"], _("Delete")); end_row(); } @@ -157,7 +147,6 @@ div_start('edits'); start_table(TABLESTYLE2); -$day_in_following_month = $days_before_due = 0; if ($selected_id != -1) { if ($Mode == 'Edit') { @@ -165,8 +154,10 @@ if ($selected_id != -1) $myrow = get_payment_terms($selected_id); $_POST['terms'] = $myrow["terms"]; - $_POST['DayNumber'] = term_days($myrow); - $_POST['type'] = term_type($myrow); + $_POST['type'] = $myrow['type']; + $_POST['DayNumber'] = $myrow['days']; + $_POST['early_discount'] = $myrow['early_discount']*100; + $_POST['early_days'] = $myrow['early_days']; } hidden('selected_id', $selected_id); } @@ -175,9 +166,11 @@ text_row(_("Terms Description:"), 'terms', null, 40, 40); payment_type_list_row(_("Payment type:"), 'type', null, true); -if ( in_array(get_post('type'), array(PTT_FOLLOWING, PTT_DAYS))) +if ( in_array(get_post('type'), array(PTT_FOLLOWING, PTT_DAYS))) { text_row_ex(_("Days (Or Day In Following Month):"), 'DayNumber', 3); -else + small_amount_row(_("Days of early payment discount option:"), 'early_days', null, null, _('days'), 0); + small_amount_row(_("Early payment discount percent:"), 'early_discount', null, null, _('%'), 1); +} else hidden('DayNumber', 0); end_table(1); @@ -188,5 +181,3 @@ submit_add_or_update_center($selected_id == -1, '', 'both'); end_form(); end_page(); - -?>