X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fmanage%2Frecurrent_invoices.php;h=f5f18f6243943bc76442cedc0edd9b187844fd7b;hb=0c760ea65c8c6f0a45ea8328abab53be649f2105;hp=ad2e4b4e675b328600c207298e4a0d816dce1e14;hpb=902f1015d874c33bd7946b17de2ad80b4f2144b6;p=fa-stable.git diff --git a/sales/manage/recurrent_invoices.php b/sales/manage/recurrent_invoices.php index ad2e4b4e..f5f18f62 100644 --- a/sales/manage/recurrent_invoices.php +++ b/sales/manage/recurrent_invoices.php @@ -13,6 +13,7 @@ $page_security = 'SA_SRECURRENT'; $path_to_root = "../.."; include($path_to_root . "/includes/session.inc"); include($path_to_root . "/includes/ui.inc"); +include_once($path_to_root . "/sales/includes/sales_db.inc"); $js = ""; if ($use_popup_windows) @@ -20,7 +21,7 @@ if ($use_popup_windows) if ($use_date_picker) $js .= get_js_date_picker(); -page(_("Recurrent Invoices"), false, false, "", $js); +page(_($help_context = "Recurrent Invoices"), false, false, "", $js); simple_page_mode(true); @@ -35,34 +36,39 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') display_error(_("The area description cannot be empty.")); set_focus('description'); } + if (!is_date($_POST['begin'])) { + $input_error = 1; + display_error(_("The entered date is invalid.")); + set_focus('begin'); + } + if (!is_date($_POST['end'])) { + $input_error = 1; + display_error(_("The entered date is invalid.")); + set_focus('end'); + } + if (isset($_POST['last_sent']) && !is_date($_POST['last_sent'])) { + $input_error = 1; + display_error(_("The entered date is invalid.")); + set_focus('last_sent'); + } if ($input_error != 1) { if ($selected_id != -1) { - $sql = "UPDATE ".TB_PREF."recurrent_invoices SET - description=".db_escape($_POST['description']).", - order_no=".db_escape($_POST['order_no']).", - debtor_no=".db_escape($_POST['debtor_no']).", - group_no=".db_escape($_POST['group_no']).", - days=".input_num('days', 0).", - monthly=".input_num('monthly', 0).", - begin='".date2sql($_POST['begin'])."', - end='".date2sql($_POST['end'])."' - WHERE id = '$selected_id'"; + update_recurrent_invoice($selected_id, $_POST['description'], $_POST['order_no'], input_num('debtor_no'), + input_num('group_no'), input_num('days', 0), input_num('monthly', 0), $_POST['begin'], $_POST['end']); + if (isset($_POST['last_sent'])) + update_last_sent_recurrent_invoice($selected_id, $_POST['last_sent']); $note = _('Selected recurrent invoice has been updated'); } else { - $sql = "INSERT INTO ".TB_PREF."recurrent_invoices (description, order_no, debtor_no, - group_no, days, monthly, begin, end, last_sent) VALUES (".db_escape($_POST['description']) . ", " - .db_escape($_POST['order_no']).", ".db_escape($_POST['debtor_no']).", " - .db_escape($_POST['group_no']).", ".input_num('days', 0).", ".input_num('monthly', 0).", '" - .date2sql($_POST['begin'])."', '".date2sql($_POST['end'])."', '".date2sql(Add_Years($_POST['begin'], -5))."')"; + add_recurrent_invoice($_POST['description'], $_POST['order_no'], input_num('debtor_no'), input_num('group_no'), + input_num('days', 0), input_num('monthly', 0), $_POST['begin'], $_POST['end']); $note = _('New recurrent invoice has been added'); } - db_query($sql,"The recurrent invoice could not be updated or added"); display_notification($note); $Mode = 'RESET'; } @@ -75,8 +81,7 @@ if ($Mode == 'Delete') if ($cancel_delete == 0) { - $sql="DELETE FROM ".TB_PREF."recurrent_invoices WHERE id='" . $selected_id . "'"; - db_query($sql,"could not delete recurrent invoice"); + delete_recurrent_invoice($selected_id); display_notification(_('Selected recurrent invoice has been deleted')); } //end if Delete area @@ -89,19 +94,11 @@ if ($Mode == 'RESET') unset($_POST); } //------------------------------------------------------------------------------------------------- -function get_sales_group_name($group_no) -{ - $sql = "SELECT description FROM ".TB_PREF."groups WHERE id = $group_no"; - $result = db_query($sql, "could not get group"); - $row = db_fetch($result); - return $row[0]; -} -$sql = "SELECT * FROM ".TB_PREF."recurrent_invoices ORDER BY description, group_no, debtor_no"; -$result = db_query($sql,"could not get recurrent invoices"); +$result = get_recurrent_invoices(); start_form(); -start_table("$table_style width=70%"); +start_table(TABLESTYLE, "width=70%"); $th = array(_("Description"), _("Template No"),_("Customer"),_("Branch")."/"._("Group"),_("Days"),_("Monthly"),_("Begin"),_("End"),_("Last Created"),"", ""); table_header($th); $k = 0; @@ -109,12 +106,12 @@ while ($myrow = db_fetch($result)) { $begin = sql2date($myrow["begin"]); $end = sql2date($myrow["end"]); - $last_sent = sql2date($myrow["last_sent"]); + $last_sent = $myrow["last_sent"] == '0000-00-00' ? '' : sql2date($myrow["last_sent"]); alt_table_row_color($k); label_cell($myrow["description"]); - label_cell(get_customer_trans_view_str(30, $myrow["order_no"])); + label_cell(get_customer_trans_view_str(ST_SALESORDER, $myrow["order_no"])); if ($myrow["debtor_no"] == 0) { label_cell(""); @@ -143,16 +140,13 @@ echo '
'; start_form(); -start_table($table_style2); +start_table(TABLESTYLE2); if ($selected_id != -1) { if ($Mode == 'Edit') { //editing an existing area - $sql = "SELECT * FROM ".TB_PREF."recurrent_invoices WHERE id='$selected_id'"; - - $result = db_query($sql,"could not get recurrent invoice"); - $myrow = db_fetch($result); + $myrow = get_recurrent_invoice($selected_id); $_POST['description'] = $myrow["description"]; $_POST['order_no'] = $myrow["order_no"]; @@ -162,6 +156,7 @@ if ($selected_id != -1) $_POST['monthly'] = $myrow["monthly"]; $_POST['begin'] = sql2date($myrow["begin"]); $_POST['end'] = sql2date($myrow["end"]); + $_POST['last_sent'] = ($myrow['last_sent']=="0000-00-00"?"":sql2date($myrow["last_sent"])); } hidden("selected_id", $selected_id); } @@ -186,6 +181,9 @@ date_row(_("Begin:"), 'begin'); date_row(_("End:"), 'end', null, null, 0, 0, 5); +if ($selected_id != -1 && $_POST['last_sent'] != "") + date_row(_("Last Created"), 'last_sent'); + end_table(1); submit_add_or_update_center($selected_id == -1, '', 'both');