Exemplo n.º 1
0
 function set_vendor_details($id, $code_vendor, $name_vendor, $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("vendors_manager", "Executing set_vendor_details({$id}, values...)");
     if (user_permissions_get("vendors_write")) {
         $obj_vendor = new vendor();
         /*
         	Load SOAP Data
         */
         $obj_vendor->id = @security_script_input_predefined("int", $id);
         $obj_vendor->data["code_vendor"] = @security_script_input_predefined("any", $code_vendor);
         $obj_vendor->data["name_vendor"] = @security_script_input_predefined("any", $name_vendor);
         $obj_vendor->data["name_contact"] = @security_script_input_predefined("any", $name_contact);
         $obj_vendor->data["contact_phone"] = @security_script_input_predefined("any", $contact_phone);
         $obj_vendor->data["contact_fax"] = @security_script_input_predefined("any", $contact_fax);
         $obj_vendor->data["contact_email"] = @security_script_input_predefined("email", $contact_email);
         $obj_vendor->data["date_start"] = @security_script_input_predefined("date", $date_start);
         $obj_vendor->data["date_end"] = @security_script_input_predefined("date", $date_end);
         $obj_vendor->data["address1_street"] = @security_script_input_predefined("any", $address1_street);
         $obj_vendor->data["address1_city"] = @security_script_input_predefined("any", $address1_city);
         $obj_vendor->data["address1_state"] = @security_script_input_predefined("any", $address1_state);
         $obj_vendor->data["address1_country"] = @security_script_input_predefined("any", $address1_country);
         $obj_vendor->data["address1_zipcode"] = @security_script_input_predefined("any", $address1_zipcode);
         $obj_vendor->data["address2_street"] = @security_script_input_predefined("any", $address2_street);
         $obj_vendor->data["address2_city"] = @security_script_input_predefined("any", $address2_city);
         $obj_vendor->data["address2_state"] = @security_script_input_predefined("any", $address2_state);
         $obj_vendor->data["address2_country"] = @security_script_input_predefined("any", $address2_country);
         $obj_vendor->data["address2_zipcode"] = @security_script_input_predefined("any", $address2_zipcode);
         $obj_vendor->data["tax_number"] = @security_script_input_predefined("any", $tax_number);
         $obj_vendor->data["tax_default"] = @security_script_input_predefined("int", $tax_default);
         $obj_vendor->data["discount"] = @security_script_input_predefined("float", $discount);
         foreach (array_keys($obj_vendor->data) as $key) {
             if ($obj_vendor->data[$key] == "error") {
                 throw new SoapFault("Sender", "INVALID_INPUT");
             }
         }
         /*
         	Error Handling
         */
         // verify vendor ID (if editing an existing vendor)
         if ($obj_vendor->id) {
             if (!$obj_vendor->verify_id()) {
                 throw new SoapFault("Sender", "INVALID_ID");
             }
         }
         // make sure we don't choose a vendor name that has already been taken
         if (!$obj_vendor->verify_name_vendor()) {
             throw new SoapFault("Sender", "DUPLICATE_NAME_VENDOR");
         }
         // make sure we don't choose a vendor code that has already been taken
         if (!$obj_vendor->verify_code_vendor()) {
             throw new SoapFault("Sender", "DUPLICATE_CODE_VENDOR");
         }
         /*
         				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_vendor->data["name_contact"])) {
             $obj_vendor->data["name_contact"] = "Accounts";
         }
         if ($obj_vendor->id) {
             // existing vendor - we need to load the contacts and then adjust the values in the
             // primary records with the values provided by the API.
             if (!$obj_vendor->load_data_contacts()) {
                 throw new SoapFault("Sender", "UNEXPECTED_ACTION_ERROR");
             }
             // overwrite the accounts primary values
             if (!empty($obj_vendor->data["contacts"][0]["records"])) {
                 $obj_vendor->data["contacts"][0]["contact"] = $obj_vendor->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_vendor->data["contacts"][0]["num_records"]; $i++) {
                     if (!$set_email) {
                         if ($obj_vendor->data["contacts"][0]["records"][$i]["type"] == "email") {
                             $obj_vendor->data["contacts"][0]["records"][$i]["detail"] = $obj_vendor->data["contact_email"];
                             $set_email = 1;
                         }
                     }
                     if (!$set_phone) {
                         if ($obj_vendor->data["contacts"][0]["records"][$i]["type"] == "phone") {
                             $obj_vendor->data["contacts"][0]["records"][$i]["detail"] = $obj_vendor->data["contact_phone"];
                             $set_phone = 1;
                         }
                     }
                     if (!$set_fax) {
                         if ($obj_vendor->data["contacts"][0]["records"][$i]["type"] == "fax") {
                             $obj_vendor->data["contacts"][0]["records"][$i]["detail"] = $obj_vendor->data["contact_fax"];
                             $set_fax = 1;
                         }
                     }
                 }
                 // no existing record existed, add a new one
                 if (!$set_email) {
                     $i = $obj_vendor->data["contact"]["num_records"];
                     $obj_vendor->data["contact"]["num_records"]++;
                     $obj_vendor->data["contacts"][0]["records"][$i]["delete"] = "false";
                     $obj_vendor->data["contacts"][0]["records"][$i]["type"] = "email";
                     $obj_vendor->data["contacts"][0]["records"][$i]["label"] = "Email";
                     $obj_vendor->data["contacts"][0]["records"][$i]["detail"] = $obj_vendor->data["contact_email"];
                 }
                 if (!$set_phone) {
                     $i = $obj_vendor->data["contact"]["num_records"];
                     $obj_vendor->data["contact"]["num_records"]++;
                     $obj_vendor->data["contacts"][0]["records"][$i]["delete"] = "false";
                     $obj_vendor->data["contacts"][0]["records"][$i]["type"] = "phone";
                     $obj_vendor->data["contacts"][0]["records"][$i]["label"] = "Phone";
                     $obj_vendor->data["contacts"][0]["records"][$i]["detail"] = $obj_vendor->data["contact_phone"];
                 }
                 if (!$set_fax) {
                     $i = $obj_vendor->data["contact"]["num_records"];
                     $obj_vendor->data["contact"]["num_records"]++;
                     $obj_vendor->data["contacts"][0]["records"][$i]["delete"] = "false";
                     $obj_vendor->data["contacts"][0]["records"][$i]["type"] = "fax";
                     $obj_vendor->data["contacts"][0]["records"][$i]["label"] = "Fax";
                     $obj_vendor->data["contacts"][0]["records"][$i]["detail"] = $obj_vendor->data["contact_fax"];
                 }
             } else {
                 // no valid contact records exist, re-define the entry
                 $obj_vendor->data["contacts"][0]["contact"] = $obj_vendor->data["name_contact"];
                 $obj_vendor->data["contacts"][0]["role"] = "accounts";
                 $obj_vendor->data["contacts"][0]["records"][0]["delete"] = "false";
                 $obj_vendor->data["contacts"][0]["records"][0]["type"] = "email";
                 $obj_vendor->data["contacts"][0]["records"][0]["label"] = "Email";
                 $obj_vendor->data["contacts"][0]["records"][0]["detail"] = $obj_vendor->data["contact_email"];
                 $obj_vendor->data["contacts"][0]["records"][1]["delete"] = "false";
                 $obj_vendor->data["contacts"][0]["records"][1]["type"] = "phone";
                 $obj_vendor->data["contacts"][0]["records"][1]["label"] = "Phone";
                 $obj_vendor->data["contacts"][0]["records"][1]["detail"] = $obj_vendor->data["contact_phone"];
                 $obj_vendor->data["contacts"][0]["records"][2]["delete"] = "false";
                 $obj_vendor->data["contacts"][0]["records"][2]["type"] = "fax";
                 $obj_vendor->data["contacts"][0]["records"][2]["label"] = "Fax";
                 $obj_vendor->data["contacts"][0]["records"][2]["detail"] = $obj_vendor->data["contact_fax"];
             }
         } else {
             // new vendor, easy for us to define a new structure.
             $obj_vendor->data["num_contacts"] = 1;
             $obj_vendor->data["contacts"][0]["contact_id"] = "";
             $obj_vendor->data["contacts"][0]["contact"] = $obj_vendor->data["name_contact"];
             $obj_vendor->data["contacts"][0]["role"] = "accounts";
             $obj_vendor->data["contacts"][0]["delete_contact"] = "false";
             $obj_vendor->data["contacts"][0]["num_records"] = 3;
             $obj_vendor->data["contacts"][0]["records"][0]["delete"] = "false";
             $obj_vendor->data["contacts"][0]["records"][0]["type"] = "email";
             $obj_vendor->data["contacts"][0]["records"][0]["label"] = "Email";
             $obj_vendor->data["contacts"][0]["records"][0]["detail"] = $obj_vendor->data["contact_email"];
             $obj_vendor->data["contacts"][0]["records"][1]["delete"] = "false";
             $obj_vendor->data["contacts"][0]["records"][1]["type"] = "phone";
             $obj_vendor->data["contacts"][0]["records"][1]["label"] = "Phone";
             $obj_vendor->data["contacts"][0]["records"][1]["detail"] = $obj_vendor->data["contact_phone"];
             $obj_vendor->data["contacts"][0]["records"][2]["delete"] = "false";
             $obj_vendor->data["contacts"][0]["records"][2]["type"] = "fax";
             $obj_vendor->data["contacts"][0]["records"][2]["label"] = "Fax";
             $obj_vendor->data["contacts"][0]["records"][2]["detail"] = $obj_vendor->data["contact_fax"];
         }
         /*
         	Perform Changes
         */
         if ($obj_vendor->action_update()) {
             return $obj_vendor->id;
         } else {
             throw new SoapFault("Sender", "UNEXPECTED_ACTION_ERROR");
         }
     } else {
         throw new SoapFault("Sender", "ACCESS DENIED");
     }
 }
Exemplo n.º 2
0
     // fetch all the taxes and see which ones are enabled for the vendor
     foreach ($sql_taxes_obj->data as $data_tax) {
         $obj_vendor->data["tax_" . $data_tax["id"]] = @security_form_input_predefined("any", "tax_" . $data_tax["id"], 0, "");
     }
 }
 /*
 	Error Handling
 */
 // verify that vendor exists (if editing an exisiting vendor)
 if ($obj_vendor->id) {
     if (!$obj_vendor->verify_id()) {
         log_write("error", "process", "The vendor you have attempted to edit - " . $obj_vendor->id . " - does not exist in this system.");
     }
 }
 // make sure we don't choose a vendor name that has already been taken
 if (!$obj_vendor->verify_name_vendor()) {
     log_write("error", "process", "This vendor name is already used for another vendor - please choose a unique name.");
     $_SESSION["error"]["name_vendor-error"] = 1;
 }
 // make sure we don't choose a vendor code that has already been taken
 if (!$obj_vendor->verify_code_vendor()) {
     log_write("error", "process", "This vendor code is already used for another vendor - please choose a unique code, or leave it blank to recieve an auto-generated value.");
     $_SESSION["error"]["code_vendor-error"] = 1;
 }
 //make sure each contact has a name
 for ($i = 0; $i < $num_contacts; $i++) {
     if (!$obj_vendor->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);
     }