Ejemplo n.º 1
0
function handle_submit(&$selected_id)
{
    global $path_to_root, $Ajax, $auto_create_branch;
    if (!can_process()) {
        return;
    }
    if ($selected_id) {
        update_customer($_POST['customer_id'], $_POST['CustName'], $_POST['cust_ref'], $_POST['address'], $_POST['tax_id'], $_POST['curr_code'], $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['credit_status'], $_POST['payment_terms'], input_num('discount') / 100, input_num('pymt_discount') / 100, input_num('credit_limit'), $_POST['sales_type'], $_POST['notes']);
        update_record_status($_POST['customer_id'], $_POST['inactive'], 'debtors_master', 'debtor_no');
        $Ajax->activate('customer_id');
        // in case of status change
        display_notification(_("Customer has been updated."));
    } else {
        //it is a new customer
        begin_transaction();
        add_customer($_POST['CustName'], $_POST['cust_ref'], $_POST['address'], $_POST['tax_id'], $_POST['curr_code'], $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['credit_status'], $_POST['payment_terms'], input_num('discount') / 100, input_num('pymt_discount') / 100, input_num('credit_limit'), $_POST['sales_type'], $_POST['notes']);
        $selected_id = $_POST['customer_id'] = db_insert_id();
        if (isset($auto_create_branch) && $auto_create_branch == 1) {
            add_branch($selected_id, $_POST['CustName'], $_POST['cust_ref'], $_POST['address'], $_POST['salesman'], $_POST['area'], $_POST['tax_group_id'], '', get_company_pref('default_sales_discount_act'), get_company_pref('debtors_act'), get_company_pref('default_prompt_payment_act'), $_POST['location'], $_POST['address'], 0, 0, $_POST['ship_via'], $_POST['notes']);
            $selected_branch = db_insert_id();
            add_crm_person($_POST['CustName'], $_POST['cust_ref'], '', $_POST['address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], '', '');
            add_crm_contact('cust_branch', 'general', $selected_branch, db_insert_id());
        }
        commit_transaction();
        display_notification(_("A new customer has been added."));
        if (isset($auto_create_branch) && $auto_create_branch == 1) {
            display_notification(_("A default Branch has been automatically created, please check default Branch values by using link below."));
        }
        $Ajax->activate('_page_body');
    }
}
Ejemplo n.º 2
0
function write_customer($email, $name, $company, $address, $phone, $fax, $currency)
{
    global $paypal_sales_type_id, $paypal_tax_group_id, $paypal_salesman, $paypal_area, $paypal_location, $paypal_credit_status, $paypal_shipper;
    global $SysPrefs;
    log_message("Memory, write_customer start:" . memory_get_usage());
    $customer_id = find_customer_by_email($email);
    if (empty($customer_id)) {
        $customer_id = find_customer_by_name($company);
    }
    if (empty($customer_id)) {
        //it is a new customer
        begin_transaction();
        add_customer($company, substr($company, 0, 30), $address, '', $currency, 0, 0, $paypal_credit_status, -1, 0, 0, $SysPrefs->default_credit_limit(), $paypal_sales_type_id, 'PayPal');
        $customer_id = db_insert_id();
        add_branch($customer_id, $company, substr($company, 0, 30), $address, $paypal_salesman, $paypal_area, $paypal_tax_group_id, '', get_company_pref('default_sales_discount_act'), get_company_pref('debtors_act'), get_company_pref('default_prompt_payment_act'), $paypal_location, $address, 0, 0, $paypal_shipper, 'PayPal');
        $selected_branch = db_insert_id();
        $nameparts = explode(" ", $name);
        $firstname = "";
        for ($i = 0; $i < count($nameparts) - 1; $i++) {
            if (!empty($firstname)) {
                $firstname .= " ";
            }
            $firstname .= $nameparts[$i];
        }
        $lastname = $nameparts[count($nameparts) - 1];
        add_crm_person('paypal', $firstname, $lastname, $address, $phone, '', $fax, $email, '', '');
        add_crm_contact('customer', 'general', $selected_branch, db_insert_id());
        commit_transaction();
    } else {
        $selected_branch = 0;
    }
    log_message("Memory, write_customer end:" . memory_get_usage());
    return array($customer_id, $selected_branch);
}
Ejemplo n.º 3
0
        display_error(_("The supplier short name must be entered."));
        set_focus('supp_ref');
    }
    if ($input_error != 1) {
        begin_transaction();
        if ($supplier_id) {
            update_supplier($_POST['supplier_id'], $_POST['supp_name'], $_POST['supp_ref'], $_POST['address'], $_POST['supp_address'], $_POST['gst_no'], $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'], input_num('credit_limit', 0), $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['curr_code'], $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'], $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id'], get_post('tax_included', 0));
            update_record_status($_POST['supplier_id'], $_POST['inactive'], 'suppliers', 'supplier_id');
            $Ajax->activate('supplier_id');
            // in case of status change
            display_notification(_("Supplier has been updated."));
        } else {
            add_supplier($_POST['supp_name'], $_POST['supp_ref'], $_POST['address'], $_POST['supp_address'], $_POST['gst_no'], $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'], input_num('credit_limit', 0), $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['curr_code'], $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'], $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id'], check_value('tax_included'));
            $supplier_id = $_POST['supplier_id'] = db_insert_id();
            add_crm_person($_POST['supp_ref'], $_POST['contact'], '', $_POST['address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['rep_lang'], '');
            add_crm_contact('supplier', 'general', $supplier_id, db_insert_id());
            display_notification(_("A new supplier has been added."));
            $Ajax->activate('_page_body');
        }
        commit_transaction();
    }
} elseif (isset($_POST['delete']) && $_POST['delete'] != "") {
    //the link to delete a selected record was clicked instead of the submit button
    $cancel_delete = 0;
    // PREVENT DELETES IF DEPENDENT RECORDS IN 'supp_trans' , purch_orders
    if (key_in_foreign_table($_POST['supplier_id'], 'supp_trans', 'supplier_id')) {
        $cancel_delete = 1;
        display_error(_("Cannot delete this supplier because there are transactions that refer to this supplier."));
    } else {
        if (key_in_foreign_table($_POST['supplier_id'], 'purch_orders', 'supplier_id')) {
            $cancel_delete = 1;
Ejemplo n.º 4
0
        $input_error = 1;
        display_error(_("The Branch short name cannot be empty."));
        set_focus('br_ref');
    }
    if ($input_error != 1) {
        begin_transaction();
        if ($selected_id != -1) {
            update_branch($_POST['customer_id'], $_POST['branch_code'], $_POST['br_name'], $_POST['br_ref'], $_POST['br_address'], $_POST['salesman'], $_POST['area'], $_POST['tax_group_id'], $_POST['sales_account'], $_POST['sales_discount_account'], $_POST['receivables_account'], $_POST['payment_discount_account'], $_POST['default_location'], $_POST['br_post_address'], $_POST['disable_trans'], $_POST['group_no'], $_POST['default_ship_via'], $_POST['notes']);
            //			update_record_status($_POST['supplier_id'], $_POST['inactive'],
            //				'cust_branch', 'branch_code');
            $note = _('Selected customer branch has been updated');
        } else {
            add_branch($_POST['customer_id'], $_POST['br_name'], $_POST['br_ref'], $_POST['br_address'], $_POST['salesman'], $_POST['area'], $_POST['tax_group_id'], $_POST['sales_account'], $_POST['sales_discount_account'], $_POST['receivables_account'], $_POST['payment_discount_account'], $_POST['default_location'], $_POST['br_post_address'], 0, $_POST['group_no'], $_POST['default_ship_via'], $_POST['notes']);
            $selected_id = db_insert_id();
            add_crm_person($_POST['contact_name'], $_POST['contact_name'], '', $_POST['br_post_address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['rep_lang'], '');
            add_crm_contact('cust_branch', 'general', $selected_id, db_insert_id());
            $note = _('New customer branch has been added');
        }
        commit_transaction();
        display_notification($note);
        //		$Mode = 'RESET';
        if (@$_REQUEST['popup']) {
            set_focus("Select" . ($_POST['branch_code'] == -1 ? $selected_id : $_POST['branch_code']));
        }
    }
} elseif ($Mode == 'Delete') {
    //the link to delete a selected record was clicked instead of the submit button
    // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtor_trans'
    if (branch_in_foreign_table($_POST['customer_id'], $_POST['branch_code'], 'debtor_trans')) {
        display_error(_("Cannot delete this branch because customer transactions have been created to this branch."));
    } else {
 public function post($rest)
 {
     $req = $rest->request();
     $info = $req->post();
     // Validate Required Fields
     if (!isset($info['custname'])) {
         api_error(412, 'Customer Name is required [custname]');
     }
     if (!isset($info['cust_ref'])) {
         api_error(412, 'Customer Reference is required [cust_ref]');
     }
     if (!isset($info['address'])) {
         api_error(412, 'Address is required [address]');
     }
     if (!isset($info['tax_id'])) {
         api_error(412, 'Tax Id is required [tax_id]');
     }
     if (!isset($info['curr_code'])) {
         api_error(412, 'Currency Code is required [curr_code]');
     }
     if (!isset($info['credit_status'])) {
         // TODO Set a default initial credit status
         api_error(412, 'Credit Status is required [credit_status]');
     }
     if (!isset($info['payment_terms'])) {
         api_error(412, 'Payment Terms is required [payment_terms]');
     }
     if (!isset($info['discount'])) {
         // TODO Set default discount as 0
         api_error(412, 'Discount is required [discount]');
     }
     if (!isset($info['pymt_discount'])) {
         // TODO Set default payment discount as 0
         api_error(412, 'Payment Discount is required [pymt_discount]');
     }
     if (!isset($info['credit_limit'])) {
         // TODO Set default credit limit from company configuration
         api_error(412, 'Credit Limit is required [credit_limit]');
     }
     if (!isset($info['sales_type'])) {
         api_error(412, 'Sales Type is required [sales_type]');
     }
     if (!isset($info['notes'])) {
         $info['notes'] = '';
     }
     // For default branch
     if (!isset($info['salesman'])) {
         $info['salesman'] = '';
     }
     if (!isset($info['area'])) {
         $info['area'] = '';
     }
     if (!isset($info['tax_group_id'])) {
         $info['tax_group_id'] = '1';
     }
     if (!isset($info['location'])) {
         $info['location'] = '1';
     }
     if (!isset($info['ship_via'])) {
         $info['ship_via'] = '1';
     }
     if (!isset($info['phone'])) {
         $info['phone'] = '';
     }
     if (!isset($info['phone2'])) {
         $info['phone2'] = '';
     }
     if (!isset($info['fax'])) {
         $info['fax'] = '';
     }
     if (!isset($info['email'])) {
         $info['email'] = '';
     }
     /*
      * $CustName, $cust_ref, $address, $tax_id, $curr_code, $dimension_id, $dimension2_id, $credit_status,
      * $payment_terms, $discount, $pymt_discount, $credit_limit, $sales_type, $notes
      */
     add_customer($info['custname'], $info['cust_ref'], $info['address'], $info['tax_id'], $info['curr_code'], 0, 0, $info['credit_status'], $info['payment_terms'], $info['discount'], $info['pymt_discount'], $info['credit_limit'], $info['sales_type'], $info['notes']);
     $selected_id = db_insert_id();
     $auto_create_branch = 1;
     if (isset($auto_create_branch) && $auto_create_branch == 1) {
         add_branch($selected_id, $info['custname'], $info['cust_ref'], $info['address'], $info['salesman'], $info['area'], $info['tax_group_id'], '1', get_company_pref('default_sales_discount_act'), get_company_pref('debtors_act'), get_company_pref('default_prompt_payment_act'), $info['location'], $info['address'], 0, 0, $info['ship_via'], $info['notes']);
         $selected_branch = db_insert_id();
         add_crm_person($info['cust_ref'], $info['custname'], '', $info['address'], $info['phone'], $info['phone2'], $info['fax'], $info['email'], '', '');
         $pers_id = db_insert_id();
         add_crm_contact('cust_branch', 'general', $selected_branch, $pers_id);
         add_crm_contact('customer', 'general', $selected_id, $pers_id);
     }
     $cust = get_customer($selected_id);
     if ($cust != null) {
         api_create_response(json_encode($cust));
     } else {
         api_error(500, 'Could Not Save to Database');
     }
 }