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 ***********************************************************************/
13 $path_to_root="../..";
14 include($path_to_root . "/includes/session.inc");
15 include($path_to_root . "/includes/ui.inc");
18 if ($use_popup_windows)
19 $js .= get_js_open_window(900, 600);
21 $js .= get_js_date_picker();
23 page(_("Recurrent Invoices"), false, false, "", $js);
25 simple_page_mode(true);
27 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
32 if (strlen($_POST['description']) == 0)
35 display_error(_("The area description cannot be empty."));
36 set_focus('description');
39 if ($input_error != 1)
41 if ($selected_id != -1)
43 $sql = "UPDATE ".TB_PREF."recurrent_invoices SET
44 description=".db_escape($_POST['description']).",
45 order_no=".db_escape($_POST['order_no']).",
46 debtor_no=".db_escape($_POST['debtor_no']).",
47 group_no=".db_escape($_POST['group_no']).",
48 days=".input_num('days', 0).",
49 monthly=".input_num('monthly', 0).",
50 begin='".date2sql($_POST['begin'])."',
51 end='".date2sql($_POST['end'])."'
52 WHERE id = '$selected_id'";
53 $note = _('Selected recurrent invoice has been updated');
57 $sql = "INSERT INTO ".TB_PREF."recurrent_invoices (description, order_no, debtor_no,
58 group_no, days, monthly, begin, end, last_sent) VALUES (".db_escape($_POST['description']) . ", "
59 .db_escape($_POST['order_no']).", ".db_escape($_POST['debtor_no']).", "
60 .db_escape($_POST['group_no']).", ".input_num('days', 0).", ".input_num('monthly', 0).", '"
61 .date2sql($_POST['begin'])."', '".date2sql($_POST['end'])."', '".date2sql(Add_Years($_POST['begin'], -5))."')";
62 $note = _('New recurrent invoice has been added');
65 db_query($sql,"The recurrent invoice could not be updated or added");
66 display_notification($note);
71 if ($Mode == 'Delete')
76 if ($cancel_delete == 0)
78 $sql="DELETE FROM ".TB_PREF."recurrent_invoices WHERE id='" . $selected_id . "'";
79 db_query($sql,"could not delete recurrent invoice");
81 display_notification(_('Selected recurrent invoice has been deleted'));
82 } //end if Delete area
91 //-------------------------------------------------------------------------------------------------
92 function get_sales_group_name($group_no)
94 $sql = "SELECT description FROM ".TB_PREF."groups WHERE id = $group_no";
95 $result = db_query($sql, "could not get group");
96 $row = db_fetch($result);
100 $sql = "SELECT * FROM ".TB_PREF."recurrent_invoices ORDER BY description, group_no, debtor_no";
101 $result = db_query($sql,"could not get recurrent invoices");
104 start_table("$table_style width=70%");
105 $th = array(_("Description"), _("Template No"),_("Customer"),_("Branch")."/"._("Group"),_("Days"),_("Monthly"),_("Begin"),_("End"),_("Last Created"),"", "");
108 while ($myrow = db_fetch($result))
110 $begin = sql2date($myrow["begin"]);
111 $end = sql2date($myrow["end"]);
112 $last_sent = sql2date($myrow["last_sent"]);
114 alt_table_row_color($k);
116 label_cell($myrow["description"]);
117 label_cell(get_customer_trans_view_str(30, $myrow["order_no"]));
118 if ($myrow["debtor_no"] == 0)
121 label_cell(get_sales_group_name($myrow["group_no"]));
125 label_cell(get_customer_name($myrow["debtor_no"]));
126 label_cell(get_branch_name($myrow['group_no']));
128 label_cell($myrow["days"]);
129 label_cell($myrow['monthly']);
132 label_cell($last_sent);
133 edit_button_cell("Edit".$myrow["id"], _("Edit"));
134 delete_button_cell("Delete".$myrow["id"], _("Delete"));
142 //-------------------------------------------------------------------------------------------------
146 start_table($table_style2);
148 if ($selected_id != -1)
150 if ($Mode == 'Edit') {
151 //editing an existing area
152 $sql = "SELECT * FROM ".TB_PREF."recurrent_invoices WHERE id='$selected_id'";
154 $result = db_query($sql,"could not get recurrent invoice");
155 $myrow = db_fetch($result);
157 $_POST['description'] = $myrow["description"];
158 $_POST['order_no'] = $myrow["order_no"];
159 $_POST['debtor_no'] = $myrow["debtor_no"];
160 $_POST['group_no'] = $myrow["group_no"];
161 $_POST['days'] = $myrow["days"];
162 $_POST['monthly'] = $myrow["monthly"];
163 $_POST['begin'] = sql2date($myrow["begin"]);
164 $_POST['end'] = sql2date($myrow["end"]);
166 hidden("selected_id", $selected_id);
170 text_row_ex(_("Description:"), 'description', 50);
172 templates_list_row(_("Template:"), 'order_no');
174 customer_list_row(_("Customer:"), 'debtor_no', null, " ", true);
176 if ($_POST['debtor_no'] > 0)
177 customer_branches_list_row(_("Branch:"), $_POST['debtor_no'], 'group_no', null, false);
179 sales_groups_list_row(_("Sales Group:"), 'group_no', null, " ");
181 small_amount_row(_("Days:"), 'days', 0, null, null, 0);
183 small_amount_row(_("Monthly:"), 'monthly', 0, null, null, 0);
185 date_row(_("Begin:"), 'begin');
187 date_row(_("End:"), 'end', null, null, 0, 0, 5);
191 submit_add_or_update_center($selected_id == -1, '', true);