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_SRECURRENT';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
15 include($path_to_root . "/includes/ui.inc");
16 include_once($path_to_root . "/sales/includes/sales_db.inc");
19 if ($use_popup_windows)
20 $js .= get_js_open_window(900, 600);
22 $js .= get_js_date_picker();
24 page(_($help_context = "Recurrent Invoices"), false, false, "", $js);
26 simple_page_mode(true);
28 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
33 if (strlen($_POST['description']) == 0)
36 display_error(_("The area description cannot be empty."));
37 set_focus('description');
40 if ($input_error != 1)
42 if ($selected_id != -1)
44 update_recurrent_invoice($selected_id, $_POST['description'], $_POST['order_no'], $_POST['debtor_no'],
45 $_POST['group_no'], input_num('days', 0), input_num('monthly', 0), $_POST['begin'], $_POST['end']);
46 $note = _('Selected recurrent invoice has been updated');
50 add_recurrent_invoice($_POST['description'], $_POST['order_no'], $_POST['debtor_no'], $_POST['group_no'],
51 input_num('days', 0), input_num('monthly', 0), $_POST['begin'], $_POST['end']);
52 $note = _('New recurrent invoice has been added');
55 display_notification($note);
60 if ($Mode == 'Delete')
65 if ($cancel_delete == 0)
67 delete_recurrent_invoice($selected_id);
69 display_notification(_('Selected recurrent invoice has been deleted'));
70 } //end if Delete area
79 //-------------------------------------------------------------------------------------------------
81 $result = get_recurrent_invoices();
84 start_table(TABLESTYLE, "width=70%");
85 $th = array(_("Description"), _("Template No"),_("Customer"),_("Branch")."/"._("Group"),_("Days"),_("Monthly"),_("Begin"),_("End"),_("Last Created"),"", "");
88 while ($myrow = db_fetch($result))
90 $begin = sql2date($myrow["begin"]);
91 $end = sql2date($myrow["end"]);
92 $last_sent = sql2date($myrow["last_sent"]);
94 alt_table_row_color($k);
96 label_cell($myrow["description"]);
97 label_cell(get_customer_trans_view_str(ST_SALESORDER, $myrow["order_no"]));
98 if ($myrow["debtor_no"] == 0)
101 label_cell(get_sales_group_name($myrow["group_no"]));
105 label_cell(get_customer_name($myrow["debtor_no"]));
106 label_cell(get_branch_name($myrow['group_no']));
108 label_cell($myrow["days"]);
109 label_cell($myrow['monthly']);
112 label_cell($last_sent);
113 edit_button_cell("Edit".$myrow["id"], _("Edit"));
114 delete_button_cell("Delete".$myrow["id"], _("Delete"));
122 //-------------------------------------------------------------------------------------------------
126 start_table(TABLESTYLE2);
128 if ($selected_id != -1)
130 if ($Mode == 'Edit') {
131 //editing an existing area
132 $myrow = get_recurrent_invoice($selected_id);
134 $_POST['description'] = $myrow["description"];
135 $_POST['order_no'] = $myrow["order_no"];
136 $_POST['debtor_no'] = $myrow["debtor_no"];
137 $_POST['group_no'] = $myrow["group_no"];
138 $_POST['days'] = $myrow["days"];
139 $_POST['monthly'] = $myrow["monthly"];
140 $_POST['begin'] = sql2date($myrow["begin"]);
141 $_POST['end'] = sql2date($myrow["end"]);
143 hidden("selected_id", $selected_id);
147 text_row_ex(_("Description:"), 'description', 50);
149 templates_list_row(_("Template:"), 'order_no');
151 customer_list_row(_("Customer:"), 'debtor_no', null, " ", true);
153 if ($_POST['debtor_no'] > 0)
154 customer_branches_list_row(_("Branch:"), $_POST['debtor_no'], 'group_no', null, false);
156 sales_groups_list_row(_("Sales Group:"), 'group_no', null, " ");
158 small_amount_row(_("Days:"), 'days', 0, null, null, 0);
160 small_amount_row(_("Monthly:"), 'monthly', 0, null, null, 0);
162 date_row(_("Begin:"), 'begin');
164 date_row(_("End:"), 'end', null, null, 0, 0, 5);
168 submit_add_or_update_center($selected_id == -1, '', 'both');