! -> Note
$ -> Affected files
+14-Nov-2008 Joe Hunt
++ Added Sales Groups and Recurrent Invoices.
+$ /applications/customers.php
+ /includes/ui/ui_lists.inc
+ /reporting/includes/reporting.inc
+ /reporting/rep108.php
+ /sales/includes/db/branches_db.inc
+ /sales/includes/db/sales_credit_db.inc
+ /sales/includes/db/sales_delivery_db.inc
+ /sales/includes/db/sales_invoice_db.inc
+ /sales/inquiry/sales_orders_view.php
+ /sales/manage/customer_branches.php
+ /sales/manage/customers.php
+ /sql/alter2.1.sql
+ /sales/create_recurrent_invoices.php (new file)
+ /sales/manage/recurrent_invoices.php (new file)
+ /sales/manage/sales_groups.php (new file)
+
13-Nov-2008 Janusz Dobrowolski
! Rewritten for paged query results.
$ /dimensions/inquiry/search_dimensions.php
$this->add_rapp_function(0, _("&Template Delivery"),"sales/inquiry/sales_orders_view.php?DeliveryTemplates=Yes");
$this->add_rapp_function(0, _("&Template Invoice"),"sales/inquiry/sales_orders_view.php?InvoiceTemplates=Yes");
+ $this->add_rapp_function(0, _("&Create and Print Recurrent Invoices"),"sales/create_recurrent_invoices.php?");
$this->add_rapp_function(0, "","");
$this->add_rapp_function(0, _("Customer &Payments"),"sales/customer_payments.php?");
$this->add_rapp_function(0, _("Customer &Credit Notes"),"sales/credit_note_entry.php?NewCredit=Yes");
$this->add_module(_("Maintenance"));
$this->add_lapp_function(2, _("Add and Manage &Customers"),"sales/manage/customers.php?");
$this->add_lapp_function(2, _("Customer &Branches"),"sales/manage/customer_branches.php?");
+ $this->add_lapp_function(2, _("Sales &Groups"),"sales/manage/sales_groups.php?");
+ $this->add_lapp_function(2, _("Recurrent &Invoices"),"sales/manage/recurrent_invoices.php?");
$this->add_rapp_function(2, _("Sales T&ypes"),"sales/manage/sales_types.php?");
$this->add_rapp_function(2, _("Sales &Persons"),"sales/manage/sales_people.php?");
$this->add_rapp_function(2, _("Sales &Areas"),"sales/manage/sales_areas.php?");
//------------------------------------------------------------------------------------
+function sales_groups_list($name, $selected_id=null, $special_option=false)
+{
+ $sql = "SELECT id, description FROM ".TB_PREF."groups";
+ combo_input($name, $selected_id, $sql, 'id', 'description', array(
+ 'spec_option' => $special_option===true ? ' ' : $special_option,
+ 'order' => 'description', 'spec_id' => 0,
+ ));
+}
+
+function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
+{
+ if ($label != null)
+ echo "<td>$label</td>\n";
+ echo "<td>";
+ sales_groups_list($name, $selected_id, $special_option);
+ echo "</td>\n";
+}
+
+function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
+{
+ echo "<tr>\n";
+ sales_groups_list_cells($label, $name, $selected_id, $special_option);
+ echo "</tr>\n";
+}
+
+//------------------------------------------------------------------------------------
+
+function _format_template_items($row)
+{
+ return ($row[0] . " - " . _("Amount") . " ".$row[1]);
+}
+
+function templates_list($name, $selected_id=null, $special_option=false)
+{
+ $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
+ FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
+ WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
+ combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
+ 'format' => '_format_template_items',
+ 'spec_option' => $special_option===true ? ' ' : $special_option,
+ 'order' => 'order_no', 'spec_id' => 0,
+ ));
+}
+
+function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
+{
+ if ($label != null)
+ echo "<td>$label</td>\n";
+ echo "<td>";
+ templates_list($name, $selected_id, $special_option);
+ echo "</td>\n";
+}
+
+function templates_list_row($label, $name, $selected_id=null, $special_option=false)
+{
+ echo "<tr>\n";
+ templates_list_cells($label, $name, $selected_id, $special_option);
+ echo "</tr>\n";
+}
+
+//------------------------------------------------------------------------------------
+
function workorders_list($name, $selected_id=null)
{
$sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
function get_first_bank_account()
{
- $sql = "SELECT ".TB_PREF."bank_accounts.account_code FROM ".TB_PREF."bank_accounts, ".TB_PREF."company
+ $sql = "SELECT ".TB_PREF."bank_accounts.id FROM ".TB_PREF."bank_accounts, ".TB_PREF."company
WHERE bank_curr_code=curr_default LIMIT 0, 1";
$result = db_query($sql);
$row = db_fetch_row($result);
$rep->TextCol(7, 8, $DisplayNet, -2);
$rep->NewLine();
if ($rep->row < $rep->bottomMargin + (10 * $rep->lineHeight))
- $rep->Header2($myrow, null, null, $baccount);
+ $rep->Header2($myrow, null, null, $baccount, 12);
}
$nowdue = "1-" . $PastDueDays1 . " " . $doc_Days;
$pastdue1 = $PastDueDays1 + 1 . "-" . $PastDueDays2 . " " . $doc_Days;
--- /dev/null
+<?php
+
+
+$page_security = 3;
+$path_to_root="..";
+include_once($path_to_root . "/sales/includes/cart_class.inc");
+include_once($path_to_root . "/includes/session.inc");
+include_once($path_to_root . "/sales/includes/ui/sales_order_ui.inc");
+include_once($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/reporting/includes/reporting.inc");
+
+$js = "";
+if ($use_popup_windows)
+ $js .= get_js_open_window(900, 600);
+
+page(_("Create and Print Recurrent Invoices"), false, false, "", $js);
+
+function set_last_sent($id, $date)
+{
+ $date = date2sql($date);
+ $sql = "UPDATE ".TB_PREF."recurrent_invoices SET last_sent='$date' WHERE id=$id";
+ db_query($sql,"The recurrent invoice could not be updated or added");
+}
+
+function create_recurrent_invoices($customer_id, $branch_id, $order_no, $tmpl_no)
+{
+ $doc = new Cart(30, array($order_no));
+
+ get_customer_details_to_order($doc, $customer_id, $branch_id);
+
+ $doc->trans_type = 30;
+ $doc->trans_no = 0;
+ $doc->document_date = Today(); // 2006-06-15. Added so Invoices and Deliveries get current day
+
+ $doc->due_date = get_invoice_duedate($doc->customer_id, $doc->document_date);
+ $doc->reference = references::get_next($doc->trans_type);
+ $doc->Comments='';
+
+ foreach ($doc->line_items as $line_no=>$item) {
+ $line = &$doc->line_items[$line_no];
+ $line->price = get_price($line->stock_id, $doc->customer_currency,
+ $doc->sales_type, $doc->price_factor, $doc->document_date);
+ }
+ $cart = $doc;
+ $cart->trans_type = 10;
+ $cart->reference = references::get_next($cart->trans_type);
+ $invno = $cart->write(1);
+ set_last_sent($tmpl_no, $cart->document_date);
+ return $invno;
+}
+
+if (isset($_GET['recurrent']))
+{
+ $invs = array();
+ $sql = "SELECT * FROM ".TB_PREF."recurrent_invoices WHERE id=".$_GET['recurrent'];
+
+ $result = db_query($sql,"could not get recurrent invoice");
+ $myrow = db_fetch($result);
+ if ($myrow['debtor_no'] == 0)
+ {
+ $cust = get_cust_branches_from_group($myrow['group_no']);
+ while ($row = db_fetch($cust))
+ {
+ $invs[] = create_recurrent_invoices($row['debtor_no'], $row['branch_code'], $myrow['order_no'], $myrow['id']);
+ }
+ }
+ else
+ {
+ $invs[] = create_recurrent_invoices($myrow['debtor_no'], $myrow['group_no'], $myrow['order_no'], $myrow['id']);
+ }
+ if (count($invs) > 0)
+ {
+ $min = min($invs);
+ $max = max($invs);
+ }
+ else
+ $min = $max = 0;
+ display_notification(sprintf(_("%s recurrent invoice(s) created, # $min - # $max."), count($invs)));
+ if (count($invs) > 0)
+ {
+ $ar = array('PARAM_0' => $min, 'PARAM_1' => $max, 'PARAM_2' => "", 'PARAM_3' => get_first_bank_account(),
+ 'PARAM_4' => 0, 'PARAM_5' => 0, 'PARAM_6' => "", 'PARAM_7' => 10);
+ display_note(print_link(_("&Print Recurrent Invoices # $min - # $max"), 107, $ar), 0, 1);
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+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");
+
+start_table("$table_style width=70%");
+$th = array(_("Description"), _("Template No"),_("Customer"),_("Branch")."/"._("Group"),_("Days"),_("Monthly"),_("Begin"),_("End"),_("Last Created"),"");
+table_header($th);
+$k = 0;
+$today = add_days(Today(), 1);
+$due = false;
+while ($myrow = db_fetch($result))
+{
+ $begin = sql2date($myrow["begin"]);
+ $end = sql2date($myrow["end"]);
+ $last_sent = sql2date($myrow["last_sent"]);
+ if ($myrow['monthly'] > 0)
+ $due_date = begin_month($last_sent);
+ else
+ $due_date = $last_sent;
+ $due_date = add_months($due_date, $myrow['monthly']);
+ $due_date = add_days($due_date, $myrow['days']);
+ $overdue = date1_greater_date2($today, $due_date) && date1_greater_date2($today, $begin)
+ && date1_greater_date2($end, $today);
+ if ($overdue)
+ {
+ start_row("class='overduebg'");
+ $due = true;
+ }
+ else
+ alt_table_row_color($k);
+
+ label_cell($myrow["description"]);
+ label_cell(get_customer_trans_view_str(30, $myrow["order_no"]));
+ if ($myrow["debtor_no"] == 0)
+ {
+ label_cell("");
+ label_cell(get_sales_group_name($myrow["group_no"]));
+ }
+ else
+ {
+ label_cell(get_customer_name($myrow["debtor_no"]));
+ label_cell(get_branch_name($myrow['group_no']));
+ }
+ label_cell($myrow["days"]);
+ label_cell($myrow['monthly']);
+ label_cell($begin);
+ label_cell($end);
+ label_cell($last_sent);
+ if ($overdue)
+ label_cell("<a href='$path_to_root/sales/create_recurrent_invoices.php?recurrent=" . $myrow["id"] . "'>" . _("Create Invoices") . "</a>");
+ else
+ label_cell("");
+ end_row();
+}
+end_table();
+if ($due)
+ display_note(_("Marked items are due."), 1, 0, "class='overduefg'");
+else
+ display_note(("No recurrent invoices are due."), 1, 0);
+
+echo '<br>';
+
+end_page();
+?>
return $myrow[0];
}
+function get_cust_branches_from_group($group_no)
+{
+ $sql = "SELECT branch_code, debtor_no FROM ".TB_PREF."cust_branch
+ WHERE group_no = '$group_no'";
+
+ return db_query($sql,"could not retreive branches for group " . $group_no);
+}
?>
\ No newline at end of file
$customer = get_customer($order->customer_id);
// 2008-08-01. If there is a Customer Dimension, then override with this,
// else take the Item Dimension (if any)
- $dim = ($order->dimension_id > 0 ? $order->dimension_id : ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_codes["dimension_id"]));
- $dim2 = ($order->dimension2_id > 0 ? $order->dimension2_id : ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_codes["dimension2_id"]));
+ $dim = ($order->dimension_id != $customer['dimension_id'] ? $order->dimension_id :
+ ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_codes["dimension_id"]));
+ $dim2 = ($order->dimension2_id != $customer['dimension2_id'] ? $order->dimension2_id :
+ ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_codes["dimension2_id"]));
/* insert gl_trans to credit stock and debit cost of sales at standard cost*/
$standard_cost = get_standard_cost($order_line->stock_id);
/*first the cost of sales entry*/
// 2008-08-01. If there is a Customer Dimension, then override with this,
// else take the Item Dimension (if any)
- $dim = ($delivery->dimension_id > 0 ? $delivery->dimension_id : ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_code["dimension_id"]));
- $dim2 = ($delivery->dimension2_id > 0 ? $delivery->dimension2_id : ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"]));
+ $dim = ($delivery->dimension_id != $customer['dimension_id'] ? $delivery->dimension_id :
+ ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_code["dimension_id"]));
+ $dim2 = ($delivery->dimension2_id != $customer['dimension2_id'] ? $delivery->dimension2_id :
+ ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"]));
add_gl_trans_std_cost(13, $delivery_no,
$delivery->document_date, $stock_gl_code["cogs_account"], $dim, $dim2, "",
$sales_account = ($branch_data['sales_account'] != "" ? $branch_data['sales_account'] : $stock_gl_code['sales_account']);
// 2008-08-01. If there is a Customer Dimension, then override with this,
// else take the Item Dimension (if any)
- $dim = ($invoice->dimension_id > 0 ? $invoice->dimension_id : ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_code["dimension_id"]));
- $dim2 = ($invoice->dimension2_id > 0 ? $invoice->dimension2_id : ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"]));
+ $dim = ($invoice->dimension_id != $customer['dimension_id'] ? $invoice->dimension_id :
+ ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_code["dimension_id"]));
+ $dim2 = ($invoice->dimension2_id != $customer['dimension2_id'] ? $invoice->dimension2_id :
+ ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"]));
add_gl_trans_customer(10, $invoice_no, $date_, $sales_account, $dim, $dim2,
(-$line_taxfree_price * $invoice_line->qty_dispatched),
$invoice->customer_id, "The sales price GL posting could not be inserted");
$page_security = 2;
$path_to_root="../..";
-include($path_to_root . "/sales/includes/sales_ui.inc");
include($path_to_root . "/includes/db_pager.inc");
-include_once($path_to_root . "/reporting/includes/reporting.inc");
include($path_to_root . "/includes/session.inc");
+include($path_to_root . "/sales/includes/sales_ui.inc");
+include_once($path_to_root . "/reporting/includes/reporting.inc");
$js = "";
if ($use_popup_windows)
default_location=".db_escape($_POST['default_location']) . ",
br_post_address =".db_escape($_POST['br_post_address']) . ",
disable_trans=".db_escape($_POST['disable_trans']) . ",
+ group_no=".db_escape($_POST['group_no']) . ",
default_ship_via=".db_escape($_POST['default_ship_via']) . "
WHERE branch_code =".db_escape($_POST['branch_code']) . "
AND debtor_no=".db_escape($_POST['customer_id']);
$sql = "INSERT INTO ".TB_PREF."cust_branch (debtor_no, br_name, br_address,
salesman, phone, fax,
contact_name, area, email, tax_group_id, sales_account, receivables_account, payment_discount_account, sales_discount_account, default_location,
- br_post_address, disable_trans, default_ship_via)
+ br_post_address, disable_trans, group_no, default_ship_via)
VALUES (".db_escape($_POST['customer_id']). ",".db_escape($_POST['br_name']) . ", "
.db_escape($_POST['br_address']) . ", ".db_escape($_POST['salesman']) . ", "
.db_escape($_POST['phone']) . ", ".db_escape($_POST['fax']) . ","
.db_escape($_POST['default_location']) . ", "
.db_escape($_POST['br_post_address']) . ","
.db_escape($_POST['disable_trans']) . ", "
+ .db_escape($_POST['group_no']) . ", "
.db_escape($_POST['default_ship_via']) . ")";
$note = _('New customer branch has been added');
$_POST['sales_discount_account'] = $myrow['sales_discount_account'];
$_POST['receivables_account'] = $myrow['receivables_account'];
$_POST['payment_discount_account'] = $myrow['payment_discount_account'];
+ $_POST['group_no'] = $myrow["group_no"];
}
}
elseif ($Mode != 'ADD_ITEM')
yesno_list_row(_("Disable this Branch:"), 'disable_trans', null);
+sales_groups_list_row(_("Sales Group:"), 'group_no', null, true);
+
echo "</table>";
echo "</td><td class='tableseparator'>"; // outer table
begin_transaction();
$sql = "INSERT INTO ".TB_PREF."debtors_master (name, address, tax_id, email, dimension_id, dimension2_id,
- curr_code, credit_status, payment_terms, discount, pymt_discount,credit_limit,
+ curr_code, credit_status, payment_terms, discount, pymt_discount,credit_limit,
sales_type) VALUES (".db_escape($_POST['CustName']) .", "
.db_escape($_POST['address']) . ", " . db_escape($_POST['tax_id']) . ","
.db_escape($_POST['email']) . ", ".db_escape($_POST['dimension_id']) . ", "
--- /dev/null
+<?php
+
+
+$page_security = 3;
+$path_to_root="../..";
+include($path_to_root . "/includes/session.inc");
+include($path_to_root . "/includes/ui.inc");
+
+$js = "";
+if ($use_popup_windows)
+ $js .= get_js_open_window(900, 600);
+if ($use_date_picker)
+ $js .= get_js_date_picker();
+
+page(_("Recurrent Invoices"), false, false, "", $js);
+
+
+simple_page_mode(true);
+
+if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
+{
+
+ $input_error = 0;
+
+ if (strlen($_POST['description']) == 0)
+ {
+ $input_error = 1;
+ display_error(_("The area description cannot be empty."));
+ set_focus('description');
+ }
+
+ 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').",
+ monthly=".input_num('monthly').",
+ begin='".date2sql($_POST['begin'])."',
+ end='".date2sql($_POST['end'])."'
+ WHERE id = '$selected_id'";
+ $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').", ".input_num('monthly').", '"
+ .date2sql($_POST['begin'])."', '".date2sql($_POST['end'])."', '".date2sql(Add_Years($_POST['begin'], -5))."')";
+ $note = _('New recurrent invoice has been added');
+ }
+
+ db_query($sql,"The recurrent invoice could not be updated or added");
+ display_notification($note);
+ $Mode = 'RESET';
+ }
+}
+
+if ($Mode == 'Delete')
+{
+
+ $cancel_delete = 0;
+
+ if ($cancel_delete == 0)
+ {
+ $sql="DELETE FROM ".TB_PREF."recurrent_invoices WHERE id='" . $selected_id . "'";
+ db_query($sql,"could not delete recurrent invoice");
+
+ display_notification(_('Selected recurrent invoice has been deleted'));
+ } //end if Delete area
+ $Mode = 'RESET';
+}
+
+if ($Mode == 'RESET')
+{
+ $selected_id = -1;
+ 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");
+
+start_form();
+start_table("$table_style width=70%");
+$th = array(_("Description"), _("Template No"),_("Customer"),_("Branch")."/"._("Group"),_("Days"),_("Monthly"),_("Begin"),_("End"),_("Last Created"),"", "");
+table_header($th);
+$k = 0;
+while ($myrow = db_fetch($result))
+{
+ $begin = sql2date($myrow["begin"]);
+ $end = sql2date($myrow["end"]);
+ $last_sent = sql2date($myrow["last_sent"]);
+
+ alt_table_row_color($k);
+
+ label_cell($myrow["description"]);
+ label_cell(get_customer_trans_view_str(30, $myrow["order_no"]));
+ if ($myrow["debtor_no"] == 0)
+ {
+ label_cell("");
+ label_cell(get_sales_group_name($myrow["group_no"]));
+ }
+ else
+ {
+ label_cell(get_customer_name($myrow["debtor_no"]));
+ label_cell(get_branch_name($myrow['group_no']));
+ }
+ label_cell($myrow["days"]);
+ label_cell($myrow['monthly']);
+ label_cell($begin);
+ label_cell($end);
+ label_cell($last_sent);
+ edit_button_cell("Edit".$myrow["id"], _("Edit"));
+ edit_button_cell("Delete".$myrow["id"], _("Delete"));
+ end_row();
+}
+end_table();
+
+end_form();
+echo '<br>';
+
+//-------------------------------------------------------------------------------------------------
+
+start_form();
+
+start_table("$table_style2 width=40%");
+
+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);
+
+ $_POST['description'] = $myrow["description"];
+ $_POST['order_no'] = $myrow["order_no"];
+ $_POST['debtor_no'] = $myrow["debtor_no"];
+ $_POST['group_no'] = $myrow["group_no"];
+ $_POST['days'] = $myrow["days"];
+ $_POST['monthly'] = $myrow["monthly"];
+ $_POST['begin'] = sql2date($myrow["begin"]);
+ $_POST['end'] = sql2date($myrow["end"]);
+ }
+ hidden("selected_id", $selected_id);
+}
+
+
+text_row_ex(_("Description:"), 'description', 50);
+
+templates_list_row(_("Template:"), 'order_no');
+
+customer_list_row(_("Customer:"), 'debtor_no', null, " ", true);
+
+if ($_POST['debtor_no'] > 0)
+ customer_branches_list_row(_("Branch:"), $_POST['debtor_no'], 'group_no', null, false);
+else
+ sales_groups_list_row(_("Sales Group:"), 'group_no', null, " ");
+
+small_amount_row(_("Days:"), 'days', null, null, null, 0);
+
+small_amount_row(_("Monthly:"), 'monthly', null, null, null, 0);
+
+date_row(_("Begin:"), 'begin');
+
+date_row(_("End:"), 'end', null, null, 0, 0, 5);
+
+end_table(1);
+
+submit_add_or_update_center($selected_id == -1, '', true);
+
+end_form();
+
+end_page();
+?>
--- /dev/null
+<?php
+
+
+$page_security = 3;
+$path_to_root="../..";
+include($path_to_root . "/includes/session.inc");
+
+page(_("Sales Groups"));
+
+include($path_to_root . "/includes/ui.inc");
+
+simple_page_mode(true);
+
+if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
+{
+
+ $input_error = 0;
+
+ if (strlen($_POST['description']) == 0)
+ {
+ $input_error = 1;
+ display_error(_("The area description cannot be empty."));
+ set_focus('description');
+ }
+
+ if ($input_error != 1)
+ {
+ if ($selected_id != -1)
+ {
+ $sql = "UPDATE ".TB_PREF."groups SET description=".db_escape($_POST['description'])." WHERE id = '$selected_id'";
+ $note = _('Selected sales group has been updated');
+ }
+ else
+ {
+ $sql = "INSERT INTO ".TB_PREF."groups (description) VALUES (".db_escape($_POST['description']) . ")";
+ $note = _('New sales group has been added');
+ }
+
+ db_query($sql,"The sales group could not be updated or added");
+ display_notification($note);
+ $Mode = 'RESET';
+ }
+}
+
+if ($Mode == 'Delete')
+{
+
+ $cancel_delete = 0;
+
+ // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtors_master'
+
+ $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtors_master WHERE group_no='$selected_id'";
+ $result = db_query($sql,"check failed");
+ $myrow = db_fetch_row($result);
+ if ($myrow[0] > 0)
+ {
+ $cancel_delete = 1;
+ display_error(_("Cannot delete this group because customers have been created using this group."));
+ }
+ if ($cancel_delete == 0)
+ {
+ $sql="DELETE FROM ".TB_PREF."groups WHERE id='" . $selected_id . "'";
+ db_query($sql,"could not delete sales group");
+
+ display_notification(_('Selected sales group has been deleted'));
+ } //end if Delete area
+ $Mode = 'RESET';
+}
+
+if ($Mode == 'RESET')
+{
+ $selected_id = -1;
+ unset($_POST);
+}
+//-------------------------------------------------------------------------------------------------
+
+$sql = "SELECT * FROM ".TB_PREF."groups ORDER BY description";
+$result = db_query($sql,"could not get groups");
+
+start_form();
+start_table("$table_style width=40%");
+$th = array(_("Group Name"), "", "");
+table_header($th);
+$k = 0;
+
+while ($myrow = db_fetch($result))
+{
+
+ alt_table_row_color($k);
+
+ label_cell($myrow["description"]);
+ edit_button_cell("Edit".$myrow["id"], _("Edit"));
+ edit_button_cell("Delete".$myrow["id"], _("Delete"));
+ end_row();
+}
+
+
+end_table();
+end_form();
+echo '<br>';
+
+//-------------------------------------------------------------------------------------------------
+
+start_form();
+
+start_table("$table_style2 width=40%");
+
+if ($selected_id != -1)
+{
+ if ($Mode == 'Edit') {
+ //editing an existing area
+ $sql = "SELECT * FROM ".TB_PREF."groups WHERE id='$selected_id'";
+
+ $result = db_query($sql,"could not get group");
+ $myrow = db_fetch($result);
+
+ $_POST['description'] = $myrow["description"];
+ }
+ hidden("selected_id", $selected_id);
+}
+
+text_row_ex(_("Group Name:"), 'description', 30);
+
+end_table(1);
+
+submit_add_or_update_center($selected_id == -1, '', true);
+
+end_form();
+
+end_page();
+?>
+DROP TABLE IF EXISTS `0_groups`;
+
+CREATE TABLE `0_groups` (
+ `id` int(11) NOT NULL auto_increment,
+ `description` varchar(60) NOT NULL default '',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `description` (`description`)
+) TYPE=MyISAM AUTO_INCREMENT=1 ;
+
+INSERT INTO `0_groups` VALUES ('1', 'Small');
+INSERT INTO `0_groups` VALUES ('2', 'Medium');
+INSERT INTO `0_groups` VALUES ('3', 'Large');
+
+DROP TABLE IF EXISTS `0_recurrent_invoices`;
+
+CREATE TABLE `0_recurrent_invoices` (
+ `id` int(11) NOT NULL auto_increment,
+ `description` varchar(60) NOT NULL default '',
+ `order_no` int(11) NOT NULL default '0',
+ `debtor_no` int(11) NOT NULL default '0',
+ `group_no` int(11) NOT NULL default '0',
+ `days` int(11) NOT NULL default '0',
+ `monthly` int(11) NOT NULL default '0',
+ `begin` date NOT NULL default '0000-00-00',
+ `end` date NOT NULL default '0000-00-00',
+ `last_sent` date NOT NULL default '0000-00-00',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `description` (`description`)
+) TYPE=InnoDB AUTO_INCREMENT=1 ;
+
+ALTER TABLE `0_cust_branch` ADD `group_no` int(11) NOT NULL default '0';
+
ALTER TABLE `0_debtor_trans` ADD `dimension_id` int(11) NOT NULL default '0';
ALTER TABLE `0_debtor_trans` ADD `dimension2_id` int(11) NOT NULL default '0';