示例#1
0
 public function create()
 {
     if (isset($_POST['product_create_submit']) && trim($_POST['product_create_submit']) !== '') {
         try {
             $this->form_validation->set_rules('name', 'Product Name', 'trim|required');
             $this->form_validation->set_rules('code', 'Product Code', 'trim|required');
             $this->form_validation->set_rules('description', 'Product Description', 'trim|required');
             $this->form_validation->set_rules('price_ex', 'Product Ex', 'trim');
             $this->form_validation->set_rules('price_inc', 'Product Inc', 'trim');
             if ($this->form_validation->run() === false) {
                 throw new Exception(validation_errors());
             }
             if ($_POST['price_ex'] == '' && $_POST['price_inc'] == '' || $_POST['price_ex'] <= 0 && $_POST['price_inc'] <= 0 || !is_numeric($_POST['price_ex']) && !is_numeric($_POST['price_inc'])) {
                 throw new Exception('Price must be specified');
             } else {
                 if ($_POST['price_ex'] == '' || $_POST['price_ex'] <= 0 || is_numeric($_POST['price_ex'])) {
                     $_POST['price_ex'] = getGSTExclusivePrice($_POST['price_inc']);
                 }
                 if ($_POST['price_inc'] == '' || $_POST['price_inc'] <= 0 || is_numeric($_POST['price_inc'])) {
                     $_POST['price_inc'] = getGSTInclusivePrice($_POST['price_ex']);
                 }
             }
             $existingProductArray = $this->product->getProducts(array('code' => $_POST['code']), array(), array('limit' => 1));
             if (count($existingProductArray) > 0) {
                 $ep = $existingProductArray[0];
                 throw new Exception("A Product with name [" . $ep->name . "] already exists with the same code [" . $_POST['code'] . "]");
             }
             unset($_POST['product_create_submit']);
             $newProductId = $this->product->createProduct($_POST);
             setSessionData('view_success_message', "New Product Created Successfully");
             redirect('product/create');
         } catch (Exception $ex) {
             setSessionData('view_error_message', $ex->getMessage());
         }
     }
     $param = array();
     $param['header'] = true;
     $param['footer'] = true;
     $param['source'] = 'product/create';
     $param['data'] = array();
     $this->load->view('smart_view', $param);
 }
示例#2
0
 private function _precheckSellOrderInput(array $option)
 {
     if (!isset($option['customer_id']) || ($option['customer_id'] = trim($option['customer_id'])) === '') {
         $errorArray[] = "A Customer is required to create/update sell order";
     }
     if (!isset($option['sell_source_id']) || ($option['sell_source_id'] = trim($option['sell_source_id'])) === '') {
         $errorArray[] = "A Sell Source is required to create/update sell order";
     }
     if (!isset($option['product_instances']) || !is_array($option['product_instances']) || count($option['product_instances']) <= 0) {
         throw new Exception("Product(s) must be specified to create/update sell order");
     }
     if (!isset($option['sell_order_status_id']) || trim($option['sell_order_status_id']) === '') {
         throw new Exception('A status must be specified to create/update order');
     }
     if (!isset($option['delivery_method_id']) || trim($option['delivery_method_id']) === '') {
         throw new Exception('A Delivery Method must be specified to create/update order');
     }
     if (!isset($option['order_total_ex']) || trim($option['order_total_ex']) === '' || !is_numeric($option['order_total_ex'])) {
         $option['order_total_ex'] = false;
     }
     if (!isset($option['order_total_inc']) || trim($option['order_total_inc']) === '' || !is_numeric($option['order_total_inc'])) {
         $option['order_total_inc'] = false;
     }
     if ($option['order_total_ex'] === false && $option['order_total_inc'] === false) {
         $errorArray[] = 'A sell price must be specified to create/update order';
     } else {
         if ($option['order_total_ex'] === false) {
             getGSTExclusivePrice($option['order_total_inc']);
         } else {
             if ($option['order_total_inc'] === false) {
                 getGSTInclusivePrice($option['order_total_ex']);
             }
         }
     }
     if (!isset($option['payment_method_id']) || ($option['payment_method_id'] = trim($option['payment_method_id'])) === '') {
         $errorArray[] = 'A Payment method must be specified';
     }
     if (isset($option['payment_received_date']) && ($prd = trim($option['payment_received_date'])) !== '' && validateDateTime($prd, 'Y-m-d H:i:s')) {
         $option['payment_received_date'] = $prd;
     } else {
         $option['payment_received_date'] = date('Y-m-d H:i:s');
     }
     $option['address_line_1'] = isset($option['address_line_1']) ? trim($option['address_line_1']) : '';
     $option['address_line_2'] = isset($option['address_line_2']) ? trim($option['address_line_2']) : '';
     $option['suburb'] = isset($option['suburb']) ? trim($option['suburb']) : '';
     $option['postcode'] = isset($option['postcode']) ? trim($option['postcode']) : '';
     $option['state_id'] = isset($option['state_id']) ? trim($option['state_id']) : '';
     $option['email'] = isset($option['email']) ? trim($option['email']) : '';
     $option['contact_no'] = isset($option['contact_no']) ? trim($option['contact_no']) : '';
     $option['consignment_no'] = isset($option['consignment_no']) ? trim($option['consignment_no']) : '';
     $option['payment_reference_no'] = isset($option['payment_reference_no']) ? trim($option['payment_reference_no']) : '';
     $option['additional_comments'] = isset($option['additional_comments']) ? trim($option['additional_comments']) : '';
     $option['external_identifier'] = isset($option['external_identifier']) ? trim($option['external_identifier']) : '';
     $option['postage_cost_inc'] = isset($option['postage_cost_inc']) ? trim($option['postage_cost_inc']) : '';
     return $option;
 }
示例#3
0
 public function createProduct(array $option)
 {
     if (count($option) <= 0) {
         throw new Exception('No data provided to create new product');
     }
     if (!isset($option['name']) || trim($option['name']) === '') {
         throw new Exception('A name must be provided to create/update product');
     } else {
         $option['name'] = trim($option['name']);
     }
     if (!isset($option['description']) || trim($option['description']) === '') {
         throw new Exception('A description must be provided to create/update product');
     } else {
         $option['description'] = trim($option['description']);
     }
     if (!isset($option['code']) || trim($option['code']) === '') {
         throw new Exception('A Product code must be provided to create/update product');
     } else {
         $option['code'] = trim($option['code']);
     }
     if (isset($option['price_ex'])) {
         $option['price_ex'] = trim($option['price_ex']);
     } else {
         $option['price_ex'] = 0;
     }
     if (isset($option['price_inc'])) {
         $option['price_inc'] = trim($option['price_inc']);
     } else {
         $option['price_inc'] = 0;
     }
     $invalidPriceEx = false;
     if ($option['price_ex'] <= 0 || $option['price_ex'] == '' || !is_numeric($option['price_ex'])) {
         $invalidPriceEx = true;
     }
     $invalidPriceInc = false;
     if ($option['price_inc'] <= 0 || $option['price_inc'] == '' || !is_numeric($option['price_inc'])) {
         $invalidPriceInc = true;
     }
     if ($invalidPriceEx && $invalidPriceInc) {
         throw new Exception("Price (GST Ex AND/OR GST Inc.) must be specified to create/update product");
     }
     if ($invalidPriceEx) {
         $option['price_ex'] = getGSTExclusivePrice($option['price_inc']);
     }
     if ($invalidPriceInc) {
         $option['price_inc'] = getGSTInclusivePrice($option['price_ex']);
     }
     $option['active'] = 1;
     $option['created'] = $option['updated'] = date('Y-m-d H:i:s');
     $option['created_by_id'] = $option['updated_by_id'] = 1;
     $result = $this->db->insert('product', $option);
     if (!$result) {
         throw new Exception('Product Create Failed. Query Failed!!!!');
     }
     return $this->db->insert_id();
 }