Preparing for graphic links
[fa-stable.git] / sales / manage / customers.php
index e7ebac5713c0035813bf73f022d6583fd2111f76..6eff21173c8a7934ae51924fa627a28516319982 100644 (file)
@@ -10,6 +10,10 @@ include_once($path_to_root . "/includes/date_functions.inc");
 include_once($path_to_root . "/includes/banking.inc");
 include_once($path_to_root . "/includes/ui.inc");
 
+if (isset($_GET['debtor_no'])) 
+{
+       $_POST['customer_id'] = $_GET['debtor_no'];
+}
 $new_customer = (!isset($_POST['customer_id']) || $_POST['customer_id'] == ""); 
 //--------------------------------------------------------------------------------------------
 
@@ -18,24 +22,28 @@ function can_process()
        if (strlen($_POST['CustName']) == 0) 
        {
                display_error(_("The customer name cannot be empty."));
+               set_focus('CustName');
                return false;
        } 
        
        if (!check_num('credit_limit', 0))
        {
                display_error(_("The credit limit must be numeric and not less than zero."));
+               set_focus('credit_limit');
                return false;           
        } 
        
        if (!check_num('pymt_discount', 0, 100)) 
        {
                display_error(_("The payment discount must be numeric and is expected to be less than 100% and greater than or equal to 0."));
+               set_focus('pymt_discount');
                return false;           
        } 
        
        if (!check_num('discount', 0, 100)) 
        {
                display_error(_("The discount percentage must be numeric and is expected to be less than 100% and greater than or equal to 0."));
+               set_focus('discount');
                return false;           
        } 
 
@@ -71,7 +79,6 @@ function handle_submit()
 
                db_query($sql,"The customer could not be updated");
                display_notification(_("Customer has been updated."));
-
        } 
        else 
        {       //it is a new customer
@@ -79,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']) . ", " 
@@ -98,15 +105,19 @@ function handle_submit()
                $Ajax->activate('_page_body');
        }
 }
-
 //--------------------------------------------------------------------------------------------
 
 if (isset($_POST['submit'])) 
 {
-       
        handle_submit();
 }
+//-------------------------------------------------------------------------------------------- 
 
+if (isset($_POST['select']))
+{
+       context_return(array('customer_id' => $_POST['customer_id'], 
+               'branch_id' => '')); // this fires customer history checks
+}
 //-------------------------------------------------------------------------------------------- 
 
 if (isset($_POST['delete'])) 
@@ -159,11 +170,9 @@ if (isset($_POST['delete']))
                unset($_POST['customer_id']);
                $new_customer = true;
                $Ajax->activate('_page_body');
-//             meta_forward($_SERVER['PHP_SELF']); 
        } //end if Delete Customer
 }
 
-
 check_db_has_sales_types(_("There are no sales types defined. Please define at least one sales type before adding a customer."));
  
 start_form();
@@ -177,7 +186,7 @@ if (db_has_customers())
 } 
 else 
 {
-       hidden('customer_id', $_POST['customer_id']);
+       hidden('customer_id');
 }
 
 start_table($table_style2, 7, 6);
@@ -263,14 +272,17 @@ amount_row(_("Credit Limit:"), 'credit_limit', $_POST['credit_limit']);
 payment_terms_list_row(_("Payment Terms:"), 'payment_terms', $_POST['payment_terms']);
 credit_status_list_row(_("Credit Status:"), 'credit_status', $_POST['credit_status']); 
 if (!$new_customer)  {
-start_row();
-  hyperlink_params_td($path_to_root . "/sales/manage/customer_branches.php", _("Edit customer branches"), "debtor_no=".$_POST['customer_id']);
-end_row();
+       start_row();
+       echo '<td>'._('Customer branches').':</td>';
+       hyperlink_params_td($path_to_root . "/sales/manage/customer_branches.php",
+               '<b>'. (count($_SESSION['Context']) ?  _("Select or &Add") : _("&Add or Edit ")).'</b>', 
+               "debtor_no=".$_POST['customer_id']);
+       end_row();
 }
 end_table();
 
 end_table(1); // outer table   
-
+div_start('controls');
 if ($new_customer)
 {
        submit_center('submit', _("Add New Customer"), true, '', true);
@@ -279,10 +291,11 @@ else
 {
        submit_center_first('submit', _("Update Customer"), 
          _('Update customer data'), true);
+       submit_return('select', _("Return"), _("Select this customer and return to document entry."), true);
        submit_center_last('delete', _("Delete Customer"), 
-         _('Delete user data if have been never used'), true);
+         _('Delete customer data if have been never used'), true);
 }
-
+div_end();
 end_form();
 end_page();