*** empty log message ***
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 14 Nov 2008 15:57:07 +0000 (15:57 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 14 Nov 2008 15:57:07 +0000 (15:57 +0000)
16 files changed:
CHANGELOG.txt
applications/customers.php
includes/ui/ui_lists.inc
reporting/includes/reporting.inc
reporting/rep108.php
sales/create_recurrent_invoices.php [new file with mode: 0644]
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
sales/manage/recurrent_invoices.php [new file with mode: 0644]
sales/manage/sales_groups.php [new file with mode: 0644]
sql/alter2.1.sql

index 77d9da68b7b227c0e4629d7493f7d93cb83cea1c..a60246b81747e78ba20a0e43be6fec9218889fc4 100644 (file)
@@ -19,6 +19,24 @@ Legend:
 ! -> 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
index 92b10dcdc9513667af72ba4decea322dd6bdada7..245ee62e611f9c44937ccd47be39c6d246cf8f21 100644 (file)
@@ -18,6 +18,7 @@
 
                        $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");
@@ -34,6 +35,8 @@
                        $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?");
index b960c27d9809af4fab279d189230a921634933eb..4748136ee9579b17c4851bb855da35ec9639a50f 100644 (file)
@@ -1009,6 +1009,68 @@ function sales_areas_list_row($label, $name, $selected_id=null)
 
 //------------------------------------------------------------------------------------
 
+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] . "&nbsp;- &nbsp;" . _("Amount") . "&nbsp;".$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";
index a304f22ee0e764bb57995a2eab27c68658ad254d..f5c1bd384ee9584bf8fe23d8270b2a0133a2c4e4 100644 (file)
@@ -85,7 +85,7 @@ function print_link($link_text, $rep, $pars = array(), $dir = '')
 
 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);
index f6eae3ee883c4cdbea799bbe32173c20a08b6c52..4a5bb107001a5452987b90e178edbbf4ed20beee 100644 (file)
@@ -136,7 +136,7 @@ function print_statements()
                        $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;
diff --git a/sales/create_recurrent_invoices.php b/sales/create_recurrent_invoices.php
new file mode 100644 (file)
index 0000000..d398648
--- /dev/null
@@ -0,0 +1,158 @@
+<?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();
+?>
index 2c4eb5228a32840fa70597394c6ea10296ec3d09..fb709542a0b0660071badeaf20da1ef74256d51f 100644 (file)
@@ -34,4 +34,11 @@ function get_branch_name($branch_id)
        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
index 3a81094490fa06aa7a69d63c89782929739cab72..ed22cba2bec1d56cea3332349c3b1202e421209d 100644 (file)
@@ -208,8 +208,10 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_,
        $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);
index f2237dbd9fe0f6e21aef534990784543ae1a672c..5d72855f350d349f08afd1da7ed884652019d820 100644 (file)
@@ -81,8 +81,10 @@ function write_sales_delivery(&$delivery,$bo_policy)
                                /*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, "",
index 689cd95606873b8833b4fdc9b7d8d39ddeb5ff6e..0c1457158a86e10e62f5887038e7a709d85c3476 100644 (file)
@@ -105,8 +105,10 @@ function write_sales_invoice(&$invoice)
                                $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");
index 2d4e5b31972b7e5f0414d24e3be9ad4b17e3bcab..c68d63d757fbef34d9c1a51d23d4de049cd9af6a 100644 (file)
@@ -3,10 +3,10 @@
 $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)
index 69ecd9e4059e9845755d1ab6cc0165f9ccb79337..a9345a0f6af1e2d384e1cce9b86cf77cad380441 100644 (file)
@@ -82,6 +82,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
                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']);
@@ -94,7 +95,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
                        $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']) . ","
@@ -107,6 +108,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
                                        .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');
@@ -248,6 +250,7 @@ if ($selected_id != -1)
            $_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')
@@ -304,6 +307,8 @@ tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
 
 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
index 944d63e0f1b9968f9a7ffa24ce87b3574f419822..6eff21173c8a7934ae51924fa627a28516319982 100644 (file)
@@ -86,7 +86,7 @@ function handle_submit()
                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']) . ", " 
diff --git a/sales/manage/recurrent_invoices.php b/sales/manage/recurrent_invoices.php
new file mode 100644 (file)
index 0000000..c432e20
--- /dev/null
@@ -0,0 +1,189 @@
+<?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();
+?>
diff --git a/sales/manage/sales_groups.php b/sales/manage/sales_groups.php
new file mode 100644 (file)
index 0000000..1e16577
--- /dev/null
@@ -0,0 +1,131 @@
+<?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();
+?>
index 153ccda8dad380884a873f6268d851e1d95fd20a..48f286ef50c2769155129cc42a12c4037173cfa4 100644 (file)
@@ -1,3 +1,35 @@
+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';