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);
}
Beispiel #2
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');
    }
}
Beispiel #3
0
function add_assembly($p_assembly_number, $p_revision, $m_customer_name, $new_customer, $new_assembly)
{
    $p_customer_id = add_customer($m_customer_name, $new_customer);
    global $g_mantis_serials_assembly;
    if ($new_assembly == 'true') {
        $query = "INSERT\n\t\t\t\t\tINTO {$g_mantis_serials_assembly}\n\t\t\t\t\t( assembly_id, customer_id, assembly_number, revision )\n\t\t\t\t\tVALUES\n\t\t\t\t\t( null, '{$p_customer_id}', '{$p_assembly_number}', '{$p_revision}' )";
        db_query_bound($query);
        $t_assembly_id = db_insert_id($g_mantis_serials_assembly);
        return $t_assembly_id;
    } else {
        return $new_assembly;
    }
}
Beispiel #4
0
     }
     if (empty($bill_state)) {
         display_error('Billing state is required.');
     }
     if (strlen($bill_state) > 2) {
         display_error('Use two-letter code for billing state.');
     }
     if (empty($bill_zip)) {
         display_error('Billing ZIP code is required.');
     }
     if (empty($bill_phone)) {
         display_error('Billing phone number is required.');
     }
 }
 // Add the customer data to the database
 $customer_id = add_customer($email, $first_name, $last_name, $password_1, $password_2);
 // Add the shipping address
 $shipping_id = add_address($customer_id, $ship_line1, $ship_line2, $ship_city, $ship_state, $ship_zip, $ship_phone);
 customer_change_shipping_id($customer_id, $shipping_id);
 // Add the billing address
 if ($use_shipping) {
     $billing_id = add_address($customer_id, $ship_line1, $ship_line2, $ship_city, $ship_state, $ship_zip, $ship_phone);
 } else {
     $billing_id = add_address($customer_id, $bill_line1, $bill_line2, $bill_city, $bill_state, $bill_zip, $bill_phone);
 }
 customer_change_billing_id($customer_id, $billing_id);
 // Set up session data
 unset($_SESSION['form_data']);
 $_SESSION['user'] = get_customer($customer_id);
 // Redirect to the Checkout application if necessary
 if (isset($_SESSION['checkout'])) {
 $email = $cust['customers_email_address'];
 $name = $cust['customers_firstname'] . ' ' . $cust['customers_lastname'];
 $contact = $cust['entry_firstname'] . ' ' . $cust['entry_lastname'];
 $addr = osc_address_format($osc, $cust, 'entry_');
 $tax_id = '';
 $phone = $cust['customers_telephone'];
 $fax = $cust['customers_fax'];
 $area_code = $_POST['area'];
 $currency = $_POST['currency'];
 // id; name; address1; address2; address3; address4; area; phone; fax; email; contact; tax_id; currency; tax_group
 $taxgid = get_tax_group_from_zone_id($osc, $cust['entry_zone_id'], $_POST['tax_group_id']);
 $sql = "SELECT debtor_no,name FROM " . TB_PREF . "debtors_master WHERE name=" . db_escape($name);
 $result = db_query($sql, "customer could not be retreived");
 $row = db_fetch_assoc($result);
 if (!$row) {
     add_customer($name, $name, $addr, $tax_id, $currency, $_POST['dimension_id'], $_POST['dimension2_id'], 1, $_POST['payment_terms'], 0, 0, input_num('credit_limit'), $_POST['sales_type'], NULL);
     if ($debug_sql) {
         display_notification("INSERT DM " . $sql);
     }
     db_query($sql, "The customer could not be added");
     $id = db_insert_id();
     add_branch($id, $name, $name, $addr, $_POST['salesman'], $area_code, $taxgid, $_POST['sales_account'], $_POST['sales_discount_account'], $_POST['receivables_account'], $_POST['payment_discount_account'], $_POST['default_location'], $addr, 0, 0, 1, NULL);
     if ($debug_sql) {
         display_notification("INSERT BR " . $sql);
     }
     display_notification("Added New Customer {$name}");
     $i++;
 } else {
     update_customer($row['debtor_no'], $name, $name, $addr, $tax_id, $currency, $_POST['dimension_id'], $_POST['dimension2_id'], 1, $_POST['payment_terms'], 0, 0, input_num('credit_limit'), $_POST['sales_type'], NULL);
     if ($debug_sql) {
         display_notification("UPDATE DM " . $sql);
Beispiel #6
0
function add_order()
{
    // получаем общие данные
    $prim = teg($_POST['prim']);
    if (isset($_SESSION['auth']['user'])) {
        $customer_id = $_SESSION['auth']['customer_id'];
    }
    if (!$_SESSION['auth']['user']) {
        $error = '';
        // флаг как в предыдущих функциях
        $name = teg($_POST['name']);
        $email = teg($_POST['email']);
        $phone = teg($_POST['phone']);
        $address = teg($_POST['address']);
        if (empty($name)) {
            $error .= '<li>Не указано ФИО</li>';
        }
        if (empty($email)) {
            $error .= '<li>Не указан Email</li>';
        }
        if (empty($phone)) {
            $error .= '<li>Не указан телефон</li>';
        }
        if (empty($address)) {
            $error .= '<li>Не указан адрес</li>';
        }
        if (!empty($email)) {
            if (preg_match("|^[-0-9a-z_\\.]+@[-0-9a-z_^\\.]+\\.[a-z]{2,6}\$|i", $email)) {
            } else {
                $error .= '<li>Указаный E-mail не соотвествует маске</li>';
            }
        }
        if (empty($error)) {
            // добавляем гостя в заказчики (но без данных авторизации)
            $customer_id = add_customer($name, $email, $phone, $address);
            if (!$customer_id) {
                return false;
            }
            // если ошибка где-то
        } else {
            // если не заполнены обязательные поля
            $_SESSION['order']['res'] = "<div class='error'>Не заполнены обязательные поля: <ul> {$error} </ul></div>";
            $_SESSION['order']['name'] = $name;
            $_SESSION['order']['email'] = $email;
            $_SESSION['order']['phone'] = $phone;
            $_SESSION['order']['addres'] = $address;
            $_SESSION['order']['prim'] = $prim;
            return false;
        }
    }
    $_SESSION['order']['email'] = $email;
    //$_SESSION['order']['res'] = $customer_id;
    save_order($customer_id, $prim);
}
     $responseArray['response'] = add_user($values);
     $responseArray['message'] = 'User successfully added';
     break;
 case 'get_users':
     include_once __DIR__ . '/customers/get_users.php';
     $responseArray['response'] = get_users($values);
     $responseArray['message'] = 'Users successfully read';
     break;
 case 'update_user':
     include_once __DIR__ . '/customers/update_user.php';
     $responseArray['response'] = update_user($values);
     $responseArray['message'] = 'User updated.';
     break;
 case 'add_customer':
     include_once __DIR__ . '/customers/add_customer.php';
     $responseArray['response'] = add_customer($values);
     $responseArray['message'] = 'Customer successfully added';
     break;
 case 'update_customer':
     include_once __DIR__ . '/customers/update_customer.php';
     $responseArray['response'] = update_customer($values);
     $responseArray['message'] = 'Customer updated.';
     break;
 case 'get_customers':
     include_once __DIR__ . '/customers/get_customers.php';
     $responseArray['response'] = get_customers($values);
     $responseArray['message'] = 'Customers successfully read';
     break;
 case 'verify_user':
     include_once __DIR__ . '/customers/verify_user.php';
     $responseArray['response'] = verify_user($values);
<?php 
function add_customer($fname, $lname, $contact, $email_id)
{
    $dbc = mysql_connect('localhost', 'root', 'rishi');
    if (!$dbc) {
        die('NOT CONNECTED:' . mysql_error());
    }
    $db_selected = mysql_select_db("restaurant", $dbc);
    if (!$db_selected) {
        die('NOT CONNECTED TO DATABASE:' . mysql_error());
    }
    $items = "\"" . $fname . "\",\"" . $lname . "\",\"" . $contact . "\",\"" . $email_id . "\"";
    $query = "insert into `CUSTOMER`(`Fname`,`Lname`,`Contact`,`Email_id`)values (" . $items . ");";
    mysql_query($query);
    $query = "SELECT Customer_Id from CUSTOMER WHERE Contact={$contact}";
    $res = mysql_query($query);
    $cust_id = intval(mysql_result($res, 0, 0));
    echo "<form id = \"form1\" name=\"form1\" action = \"menu_dine.php\" method =\"post\">";
    echo "<input type = \"text\" name = \"cust_id\" value=\"{$cust_id}\"></td></tr>";
    echo "<input type=\"submit\" name=\"submitbutton\" value=\"Check\"></td></tr></table>";
    echo "</form>";
    echo "<script type=\"text/javascript\">" . "\n";
    echo "document.getElementById(\"form1\").submit();";
    echo "</script>" . "\n";
}
add_customer($_POST["firstname"], $_POST["lastname"], $_POST["contact"], $_POST["email_id"]);
?>
<body background="1.png">
</body>
</html>
Beispiel #9
0
 if (isset($_POST["delete"]) && $_POST["delete"] == "刪除") {
     $cid = $data["select_cid"];
     if (delete_customer($cid)) {
         $output = "資料刪除完成~";
         unset($cid);
         $data = array();
         $_POST["display_form"] = "no";
     } else {
         $output = "客戶資料刪除發生問題";
     }
 } else {
     if (isset($_POST["send_order"]) && $_POST["send_order"] == "報價傳送") {
         /* ##### Check if customer exists. If not, insert a new record ##### */
         $found = check_customer($data["tax_id"]);
         if (!$found) {
             $cid = add_customer($data);
         } else {
             $cid = $found;
         }
         /* ################################################################## */
         /* ##### Insert Order Record ##### */
         $status = add_order($oid, $cid, $data);
         if (!$status) {
             $output = "建立報價單發生問題<br />";
         } else {
             $output = "報價單資料已儲存<br />";
         }
         /* ############################### */
         /* ##### Sending Sales Order ##### */
         $sender = "*****@*****.**";
         $receipient = $data["email"];
Beispiel #10
0
    // if (preg_match('/^[a-zA-Z]+$/i', $_POST['lastname']) === 0)
    // { $errors[] = 'Your last name should contain letters only.';
    //}
    //Checks if the email is valid
    if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
        $errors[] = 'Your email address does not appear to be valid.';
    }
    if (preg_match('/^[a-zA-Z0-9]+$/i', $_POST['phone']) === 0) {
        $errors[] = 'The phone you selected does not appear to be valid.';
    }
    if (preg_match('/^[a-zA-Z0-9 ]+$/i', $_POST['address']) === 0) {
        $errors[] = 'Your username should contain letters only.';
    }
    //if there are no errors then it will add users to the database
    if (empty($errors)) {
        if (add_customer($_POST['name'], $_POST['address'], $_POST['phone'], $_POST['email']) === false) {
            $errors[] = 'Something went wrong, you may have already submitted your information.';
        }
        /*mail_order($_POST['email']);*/
    }
}
?>


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
       <link rel="shortcut icon" href="../images/icon.ico">
Beispiel #11
0
                        alter_table_customers();
                        $userID = add_customerUser($customer);
                        $customer['customerID'] = $userID;
                        $customer['billingStreet'] = null;
                        $customer['billingCity'] = null;
                        $customer['billingState'] = null;
                        $customer['billingZipCode'] = null;
                        $customer['shippingStreet'] = null;
                        $customer['shippingCity'] = null;
                        $customer['shippingState'] = null;
                        $customer['shippingZipCode'] = null;
                        $customer['cardTypeID'] = null;
                        $customer['cardNumber'] = null;
                        $customer['cardExpMonth'] = null;
                        $customer['cardExpYear'] = null;
                        add_customer($customer);
                        $_SESSION['customer'] = $customer;
                        header("Location: step4.php");
                    }
                } catch (PDOException $e) {
                    display_db_error($e->getMessage());
                }
            }
        }
    }
}
?>
<div class="container">
<!-- /.row -->
<div class="back">
    <!-- Section Header -->
Beispiel #12
0
function add_order()
{
    //принимать данные из формы, брабатывать их, проверять заполнины ли все обязательные данные
    //соответствующим образом реагировать
    //получаем общие данные для всех (и авториз-ых и новых пользователей)
    $delivery_id = (int) $_POST['delivery'];
    if (!$delivery_id) {
        $delivery_id = 1;
    }
    $payment_id = (int) $_POST['payment'];
    if (!$payment_id) {
        $payment_id = 1;
    }
    $comment = trim($_POST['comment']);
    if ($_SESSION['auth']['user']) {
        $customer_id = $_SESSION['auth']['customer_id'];
    }
    //получаем id авторизованного пользователя
    if (!$_SESSION['auth']['user']) {
        //если пользователь новый, гость
        $error = '';
        //флаг проверки заполненности обязательных полей (пустое)
        //получаем значения из полей
        $surname = trim($_POST['surname']);
        $name = trim($_POST['name']);
        $email = trim($_POST['email']);
        $phone = trim($_POST['phone']);
        $address = trim($_POST['address']);
        //проверка на пустоту поля
        if (empty($surname)) {
            $error .= '<li>Не указана фамилия!</li>';
        }
        if (empty($name)) {
            $error .= '<li>Не указано имя!</li>';
        }
        if (empty($email)) {
            $error .= '<li>Не указан e-mail!</li>';
        }
        if (empty($phone)) {
            $error .= '<li>Не указан контактный телефон!</li>';
        }
        if (empty($address)) {
            $error .= '<li>Не указан адрес!</li>';
        }
        if (empty($error)) {
            //значит все поля заполнены
            //добавляем гостя в заказчики (но без данных авторизации - логин/пароль)
            $customer_id = add_customer($surname, $name, $email, $phone, $address);
            if (!$customer_id) {
                return false;
            }
            //если id не вернулся, возникла ошибка при добавлении гостя в заказчики, то прекращаем выполнение
        } else {
            //не заполнены обяз поля
            $_SESSION['order']['res'] = "<div class='error'>Не заполнены обязательные поля: <ul> {$error} </ul></div>";
            //сохранение уже заполненных полей в сессию, чтобы пользователь повторно не вводил их
            $_SESSION['order']['surname'] = $surname;
            $_SESSION['order']['name'] = $name;
            //элемент в массиве по названию переменных
            $_SESSION['order']['email'] = $email;
            $_SESSION['order']['phone'] = $phone;
            $_SESSION['order']['address'] = $address;
            $_SESSION['order']['comment'] = $comment;
            return false;
            //чтобы далее не срабатывала функция save order, поскольку есть ошибки
        }
    }
    $_SESSION['order']['email'] = $email;
    //получаем еьфл пользователя
    save_order($customer_id, $delivery_id, $payment_id, $comment);
}
Beispiel #13
0
function add_order()
{
    // получаем общие данные для всех (авторизованные и не очень)
    $dostavka_id = (int) $_POST['dostavka'];
    if (!$dostavka_id) {
        $dostavka_id = 1;
    }
    $prim = clear($_POST['prim']);
    if ($_SESSION['auth']['user']) {
        $customer_id = $_SESSION['auth']['customer_id'];
    }
    if (!$_SESSION['auth']['user']) {
        $error = '';
        // флаг проверки пустых полей
        $name = clear($_POST['name']);
        $email = clear($_POST['email']);
        $phone = clear($_POST['phone']);
        $address = clear($_POST['address']);
        if (empty($name)) {
            $error .= '<li>Не указано ФИО</li>';
        }
        if (empty($email)) {
            $error .= '<li>Не указан Email</li>';
        }
        if (empty($phone)) {
            $error .= '<li>Не указан телефон</li>';
        }
        if (empty($address)) {
            $error .= '<li>Не указан адрес</li>';
        }
        if (empty($error)) {
            // добавляем гостя в заказчики (но без данных авторизации)
            $customer_id = add_customer($name, $email, $phone, $address);
            if (!$customer_id) {
                return false;
            }
            // прекращаем выполнение в случае возникновения ошибки добавления гостя-заказчика
        } else {
            // если не заполнены обязательные поля
            $_SESSION['order']['res'] = "<div class='error'>Не заполнены обязательные поля: <ul> {$error} </ul></div>";
            $_SESSION['order']['name'] = $name;
            $_SESSION['order']['email'] = $email;
            $_SESSION['order']['phone'] = $phone;
            $_SESSION['order']['addres'] = $address;
            $_SESSION['order']['prim'] = $address;
            return false;
        }
    }
    $_SESSION['order']['email'] = $email;
    save_order($customer_id, $dostavka_id, $prim);
}
 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');
     }
 }