6 include($path_to_root . "/includes/session.inc");
7 include($path_to_root . "/includes/ui.inc");
10 if ($use_popup_windows)
11 $js .= get_js_open_window(900, 600);
13 $js .= get_js_date_picker();
15 page(_("Recurrent Invoices"), false, false, "", $js);
18 simple_page_mode(true);
20 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
25 if (strlen($_POST['description']) == 0)
28 display_error(_("The area description cannot be empty."));
29 set_focus('description');
32 if ($input_error != 1)
34 if ($selected_id != -1)
36 $sql = "UPDATE ".TB_PREF."recurrent_invoices SET
37 description=".db_escape($_POST['description']).",
38 order_no=".db_escape($_POST['order_no']).",
39 debtor_no=".db_escape($_POST['debtor_no']).",
40 group_no=".db_escape($_POST['group_no']).",
41 days=".input_num('days').",
42 monthly=".input_num('monthly').",
43 begin='".date2sql($_POST['begin'])."',
44 end='".date2sql($_POST['end'])."'
45 WHERE id = '$selected_id'";
46 $note = _('Selected recurrent invoice has been updated');
50 $sql = "INSERT INTO ".TB_PREF."recurrent_invoices (description, order_no, debtor_no,
51 group_no, days, monthly, begin, end, last_sent) VALUES (".db_escape($_POST['description']) . ", "
52 .db_escape($_POST['order_no']).", ".db_escape($_POST['debtor_no']).", "
53 .db_escape($_POST['group_no']).", ".input_num('days').", ".input_num('monthly').", '"
54 .date2sql($_POST['begin'])."', '".date2sql($_POST['end'])."', '".date2sql(Add_Years($_POST['begin'], -5))."')";
55 $note = _('New recurrent invoice has been added');
58 db_query($sql,"The recurrent invoice could not be updated or added");
59 display_notification($note);
64 if ($Mode == 'Delete')
69 if ($cancel_delete == 0)
71 $sql="DELETE FROM ".TB_PREF."recurrent_invoices WHERE id='" . $selected_id . "'";
72 db_query($sql,"could not delete recurrent invoice");
74 display_notification(_('Selected recurrent invoice has been deleted'));
75 } //end if Delete area
84 //-------------------------------------------------------------------------------------------------
85 function get_sales_group_name($group_no)
87 $sql = "SELECT description FROM ".TB_PREF."groups WHERE id = $group_no";
88 $result = db_query($sql, "could not get group");
89 $row = db_fetch($result);
93 $sql = "SELECT * FROM ".TB_PREF."recurrent_invoices ORDER BY description, group_no, debtor_no";
94 $result = db_query($sql,"could not get recurrent invoices");
97 start_table("$table_style width=70%");
98 $th = array(_("Description"), _("Template No"),_("Customer"),_("Branch")."/"._("Group"),_("Days"),_("Monthly"),_("Begin"),_("End"),_("Last Created"),"", "");
101 while ($myrow = db_fetch($result))
103 $begin = sql2date($myrow["begin"]);
104 $end = sql2date($myrow["end"]);
105 $last_sent = sql2date($myrow["last_sent"]);
107 alt_table_row_color($k);
109 label_cell($myrow["description"]);
110 label_cell(get_customer_trans_view_str(30, $myrow["order_no"]));
111 if ($myrow["debtor_no"] == 0)
114 label_cell(get_sales_group_name($myrow["group_no"]));
118 label_cell(get_customer_name($myrow["debtor_no"]));
119 label_cell(get_branch_name($myrow['group_no']));
121 label_cell($myrow["days"]);
122 label_cell($myrow['monthly']);
125 label_cell($last_sent);
126 edit_button_cell("Edit".$myrow["id"], _("Edit"));
127 edit_button_cell("Delete".$myrow["id"], _("Delete"));
135 //-------------------------------------------------------------------------------------------------
139 start_table("$table_style2 width=40%");
141 if ($selected_id != -1)
143 if ($Mode == 'Edit') {
144 //editing an existing area
145 $sql = "SELECT * FROM ".TB_PREF."recurrent_invoices WHERE id='$selected_id'";
147 $result = db_query($sql,"could not get recurrent invoice");
148 $myrow = db_fetch($result);
150 $_POST['description'] = $myrow["description"];
151 $_POST['order_no'] = $myrow["order_no"];
152 $_POST['debtor_no'] = $myrow["debtor_no"];
153 $_POST['group_no'] = $myrow["group_no"];
154 $_POST['days'] = $myrow["days"];
155 $_POST['monthly'] = $myrow["monthly"];
156 $_POST['begin'] = sql2date($myrow["begin"]);
157 $_POST['end'] = sql2date($myrow["end"]);
159 hidden("selected_id", $selected_id);
163 text_row_ex(_("Description:"), 'description', 50);
165 templates_list_row(_("Template:"), 'order_no');
167 customer_list_row(_("Customer:"), 'debtor_no', null, " ", true);
169 if ($_POST['debtor_no'] > 0)
170 customer_branches_list_row(_("Branch:"), $_POST['debtor_no'], 'group_no', null, false);
172 sales_groups_list_row(_("Sales Group:"), 'group_no', null, " ");
174 small_amount_row(_("Days:"), 'days', null, null, null, 0);
176 small_amount_row(_("Monthly:"), 'monthly', null, null, null, 0);
178 date_row(_("Begin:"), 'begin');
180 date_row(_("End:"), 'end', null, null, 0, 0, 5);
184 submit_add_or_update_center($selected_id == -1, '', true);