Пример #1
0
 /*
 	Error Handling
 */
 // verify valid ID (if performing update)
 if ($obj_customer->id) {
     if (!$obj_customer->verify_id()) {
         log_write("error", "process", "The customer you have attempted to edit - " . $obj_customer->id . " - does not exist in this system.");
     }
 }
 // make sure we don't choose a customer name that has already been taken
 if (!$obj_customer->verify_name_customer()) {
     log_write("error", "process", "This customer name is already used for another customer - please choose a unique name.");
     $_SESSION["error"]["name_customer-error"] = 1;
 }
 // make sure we don't choose a customer code that has already been taken
 if (!$obj_customer->verify_code_customer()) {
     log_write("error", "process", "This customer code is already used for another customer - please choose a unique code or leave blank for an automatically generated value.");
     $_SESSION["error"]["name_customer-error"] = 1;
 }
 // don't allow a date closed to be set if there are active services belonging to this customer
 if (!$obj_customer->verify_date_end()) {
     log_write("error", "process", "You can not close this customer, as there are still active services on this account");
     $_SESSION["error"]["date_end-error"] = 1;
 }
 //make sure each contact has a name
 for ($i = 0; $i < $num_contacts; $i++) {
     if (!$obj_customer->verify_name_contact($i)) {
         log_write("error", "process", "Each contact must be given a name - please ensure each contact has been assigned a unique name");
         error_flag_field("contact_" . $i);
         log_debug("edit-process", "NO NAME ERROR FLAG: contact_" . $i);
     }
Пример #2
0
 function set_customer_details($id, $code_customer, $name_customer, $name_contact, $contact_email, $contact_phone, $contact_fax, $date_start, $date_end, $tax_number, $tax_default, $address1_street, $address1_city, $address1_state, $address1_country, $address1_zipcode, $address2_street, $address2_city, $address2_state, $address2_country, $address2_zipcode, $discount)
 {
     log_debug("customers_manager", "Executing set_customer_details({$id}, values...)");
     if (user_permissions_get("customers_write")) {
         $obj_customer = new customer();
         /*
         	Load SOAP Data
         */
         $obj_customer->id = @security_script_input_predefined("int", $id);
         $obj_customer->data["code_customer"] = @security_script_input_predefined("any", $code_customer);
         $obj_customer->data["name_customer"] = @security_script_input_predefined("any", $name_customer);
         $obj_customer->data["name_contact"] = @security_script_input_predefined("any", $name_contact);
         $obj_customer->data["contact_phone"] = @security_script_input_predefined("any", $contact_phone);
         $obj_customer->data["contact_fax"] = @security_script_input_predefined("any", $contact_fax);
         $obj_customer->data["contact_email"] = @security_script_input_predefined("email", $contact_email);
         $obj_customer->data["date_start"] = @security_script_input_predefined("date", $date_start);
         $obj_customer->data["date_end"] = @security_script_input_predefined("date", $date_end);
         $obj_customer->data["address1_street"] = @security_script_input_predefined("any", $address1_street);
         $obj_customer->data["address1_city"] = @security_script_input_predefined("any", $address1_city);
         $obj_customer->data["address1_state"] = @security_script_input_predefined("any", $address1_state);
         $obj_customer->data["address1_country"] = @security_script_input_predefined("any", $address1_country);
         $obj_customer->data["address1_zipcode"] = @security_script_input_predefined("any", $address1_zipcode);
         $obj_customer->data["address2_street"] = @security_script_input_predefined("any", $address2_street);
         $obj_customer->data["address2_city"] = @security_script_input_predefined("any", $address2_city);
         $obj_customer->data["address2_state"] = @security_script_input_predefined("any", $address2_state);
         $obj_customer->data["address2_country"] = @security_script_input_predefined("any", $address2_country);
         $obj_customer->data["address2_zipcode"] = @security_script_input_predefined("any", $address2_zipcode);
         $obj_customer->data["tax_number"] = @security_script_input_predefined("any", $tax_number);
         $obj_customer->data["tax_default"] = @security_script_input_predefined("int", $tax_default);
         $obj_customer->data["discount"] = @security_script_input_predefined("float", $discount);
         foreach (array_keys($obj_customer->data) as $key) {
             if ($obj_customer->data[$key] == "error") {
                 throw new SoapFault("Sender", "INVALID_INPUT");
             }
         }
         /*
         	Error Handling
         */
         // verify customer ID (if editing an existing customer)
         if ($obj_customer->id) {
             if (!$obj_customer->verify_id()) {
                 throw new SoapFault("Sender", "INVALID_ID");
             }
         }
         // make sure we don't choose a customer name that has already been taken
         if (!$obj_customer->verify_name_customer()) {
             throw new SoapFault("Sender", "DUPLICATE_NAME_CUSTOMER");
         }
         // make sure we don't choose a customer code that has already been taken
         if (!$obj_customer->verify_code_customer()) {
             throw new SoapFault("Sender", "DUPLICATE_CODE_CUSTOMER");
         }
         // prevent a customer with active services from having an date_end value set
         if (!$obj_customer->verify_date_end()) {
             throw new SoapFault("Sender", "HAS_ACTIVE_SERVICES");
         }
         /*
         				Customer Contacts Handling
         	TODO: API Upgrade Required
         	Since the API spec is limited in order to retain backwards compatibility, we currently only get provided with the
         				primary contact details for the "account" contact entry.
         	This requires some cleverness to adjust the data structure to the new internal associative array, before calling update.
         			
         				At a future stage, we need to extend the API specification to handle the new flexible contact capabilities.
         */
         // ensure a default contact name is set
         if (empty($obj_customer->data["name_contact"])) {
             $obj_customer->data["name_contact"] = "Accounts";
         }
         if ($obj_customer->id) {
             // existing customer - we need to load the contacts and then adjust the values in the
             // primary records with the values provided by the API.
             if (!$obj_customer->load_data_contacts()) {
                 throw new SoapFault("Sender", "UNEXPECTED_ACTION_ERROR");
             }
             // overwrite the accounts primary values
             if (!empty($obj_customer->data["contacts"][0]["records"])) {
                 $obj_customer->data["contacts"][0]["contact"] = $obj_customer->data["name_contact"];
                 $set_email = 0;
                 $set_phone = 0;
                 $set_fax = 0;
                 // search and replace values for existing accounts records
                 for ($i = 0; $i < $obj_customer->data["contacts"][0]["num_records"]; $i++) {
                     if (!$set_email) {
                         if ($obj_customer->data["contacts"][0]["records"][$i]["type"] == "email") {
                             $obj_customer->data["contacts"][0]["records"][$i]["detail"] = $obj_customer->data["contact_email"];
                             $set_email = 1;
                         }
                     }
                     if (!$set_phone) {
                         if ($obj_customer->data["contacts"][0]["records"][$i]["type"] == "phone") {
                             $obj_customer->data["contacts"][0]["records"][$i]["detail"] = $obj_customer->data["contact_phone"];
                             $set_phone = 1;
                         }
                     }
                     if (!$set_fax) {
                         if ($obj_customer->data["contacts"][0]["records"][$i]["type"] == "fax") {
                             $obj_customer->data["contacts"][0]["records"][$i]["detail"] = $obj_customer->data["contact_fax"];
                             $set_fax = 1;
                         }
                     }
                 }
                 // no existing record existed, add a new one
                 if (!$set_email) {
                     $i = $obj_customer->data["contact"]["num_records"];
                     $obj_customer->data["contact"]["num_records"]++;
                     $obj_customer->data["contacts"][0]["records"][$i]["delete"] = "false";
                     $obj_customer->data["contacts"][0]["records"][$i]["type"] = "email";
                     $obj_customer->data["contacts"][0]["records"][$i]["label"] = "Email";
                     $obj_customer->data["contacts"][0]["records"][$i]["detail"] = $obj_customer->data["contact_email"];
                 }
                 if (!$set_phone) {
                     $i = $obj_customer->data["contact"]["num_records"];
                     $obj_customer->data["contact"]["num_records"]++;
                     $obj_customer->data["contacts"][0]["records"][$i]["delete"] = "false";
                     $obj_customer->data["contacts"][0]["records"][$i]["type"] = "phone";
                     $obj_customer->data["contacts"][0]["records"][$i]["label"] = "Phone";
                     $obj_customer->data["contacts"][0]["records"][$i]["detail"] = $obj_customer->data["contact_phone"];
                 }
                 if (!$set_fax) {
                     $i = $obj_customer->data["contact"]["num_records"];
                     $obj_customer->data["contact"]["num_records"]++;
                     $obj_customer->data["contacts"][0]["records"][$i]["delete"] = "false";
                     $obj_customer->data["contacts"][0]["records"][$i]["type"] = "fax";
                     $obj_customer->data["contacts"][0]["records"][$i]["label"] = "Fax";
                     $obj_customer->data["contacts"][0]["records"][$i]["detail"] = $obj_customer->data["contact_fax"];
                 }
             } else {
                 // no valid contact records exist, re-define the entry
                 $obj_customer->data["contacts"][0]["contact"] = $obj_customer->data["name_contact"];
                 $obj_customer->data["contacts"][0]["role"] = "accounts";
                 $obj_customer->data["contacts"][0]["records"][0]["delete"] = "false";
                 $obj_customer->data["contacts"][0]["records"][0]["type"] = "email";
                 $obj_customer->data["contacts"][0]["records"][0]["label"] = "Email";
                 $obj_customer->data["contacts"][0]["records"][0]["detail"] = $obj_customer->data["contact_email"];
                 $obj_customer->data["contacts"][0]["records"][1]["delete"] = "false";
                 $obj_customer->data["contacts"][0]["records"][1]["type"] = "phone";
                 $obj_customer->data["contacts"][0]["records"][1]["label"] = "Phone";
                 $obj_customer->data["contacts"][0]["records"][1]["detail"] = $obj_customer->data["contact_phone"];
                 $obj_customer->data["contacts"][0]["records"][2]["delete"] = "false";
                 $obj_customer->data["contacts"][0]["records"][2]["type"] = "fax";
                 $obj_customer->data["contacts"][0]["records"][2]["label"] = "Fax";
                 $obj_customer->data["contacts"][0]["records"][2]["detail"] = $obj_customer->data["contact_fax"];
             }
         } else {
             // new customer, easy for us to define a new structure.
             $obj_customer->data["num_contacts"] = 1;
             $obj_customer->data["contacts"][0]["contact_id"] = "";
             $obj_customer->data["contacts"][0]["contact"] = $obj_customer->data["name_contact"];
             $obj_customer->data["contacts"][0]["role"] = "accounts";
             $obj_customer->data["contacts"][0]["delete_contact"] = "false";
             $obj_customer->data["contacts"][0]["num_records"] = 3;
             $obj_customer->data["contacts"][0]["records"][0]["delete"] = "false";
             $obj_customer->data["contacts"][0]["records"][0]["type"] = "email";
             $obj_customer->data["contacts"][0]["records"][0]["label"] = "Email";
             $obj_customer->data["contacts"][0]["records"][0]["detail"] = $obj_customer->data["contact_email"];
             $obj_customer->data["contacts"][0]["records"][1]["delete"] = "false";
             $obj_customer->data["contacts"][0]["records"][1]["type"] = "phone";
             $obj_customer->data["contacts"][0]["records"][1]["label"] = "Phone";
             $obj_customer->data["contacts"][0]["records"][1]["detail"] = $obj_customer->data["contact_phone"];
             $obj_customer->data["contacts"][0]["records"][2]["delete"] = "false";
             $obj_customer->data["contacts"][0]["records"][2]["type"] = "fax";
             $obj_customer->data["contacts"][0]["records"][2]["label"] = "Fax";
             $obj_customer->data["contacts"][0]["records"][2]["detail"] = $obj_customer->data["contact_fax"];
         }
         /*
         	Perform Changes
         */
         if ($obj_customer->action_update()) {
             return $obj_customer->id;
         } else {
             throw new SoapFault("Sender", "UNEXPECTED_ACTION_ERROR");
         }
     } else {
         throw new SoapFault("Sender", "ACCESS DENIED");
     }
 }