Example #1
0
 public function add_inventory($organizationId, $productId)
 {
     $userType = $this->CI->session->userdata('userType');
     $returnArr = array();
     $returnArr['stock'] = '';
     $returnArr['sellPrice'] = '';
     $returnArr['spacePointComisson'] = '';
     $returnArr['retailerPrice'] = '';
     $returnArr['displayPrice'] = '';
     $returnArr['organizationId'] = $organizationId;
     $returnArr['productId'] = $productId;
     $returnArr['productName'] = '';
     $returnArr['productDescription'] = '';
     $returnArr['imageName'] = '';
     $returnArr['availableSize'] = '';
     $returnArr['product_size'] = '';
     $returnArr['productcolorlist'] = $this->CI->product_m->get_product_color_list($productId);
     $productDetails = $this->CI->product_m->product_brand_image_category_tax_details_row($productId);
     if (!empty($productDetails)) {
         $returnArr['productName'] = $productDetails->code;
         $returnArr['productDescription'] = $productDetails->description;
         $returnArr['imageName'] = $productDetails->imageName;
         $returnArr['product_size'] = $productDetails->sizes;
     }
     $inventoryDet = $this->CI->product_m->organization_with_product($organizationId, $productId);
     if (!empty($inventoryDet)) {
         $this->CI->session->set_flashdata('error', $this->CI->lang->line('error_add_inventory_already'));
         if ($this->CI->session->userdata('userType') == 'retailer') {
             redirect(base_url() . $this->CI->session->userdata('userType') . '/product_management');
         }
         if ($this->CI->session->userdata('userType') == 'cse') {
             redirect(base_url() . $this->CI->session->userdata('userType') . '/check_stock_management/check_stock_list/' . id_encrypt($organizationId));
         }
     }
     if ($_POST) {
         $rules = add_inventory_rules();
         $returnArr['productcolorlist'] = array_filter($returnArr['productcolorlist']);
         if (!empty($returnArr['productcolorlist'])) {
             $rules[] = array('field' => 'availablecolor[]', 'label' => 'color', 'rules' => 'trim|required');
         }
         if (isset($returnArr['product_size']) && !empty($returnArr['product_size'])) {
             $sizesarray = str_replace(',', '', $returnArr['product_size']);
         } else {
             $sizesarray = '';
         }
         if (isset($sizesarray) && !empty($sizesarray)) {
             $rules[] = array('field' => 'availablesize[]', 'label' => 'size', 'rules' => 'trim|required');
         }
         $returnArr['stock'] = $this->CI->input->post('stock');
         $returnArr['sellPrice'] = $this->CI->input->post('sellPrice');
         $returnArr['spacePointComisson'] = $this->CI->input->post('spacePointComisson');
         $returnArr['retailerPrice'] = $this->CI->input->post('retailerPrice');
         $returnArr['displayPrice'] = $this->CI->input->post('displayPrice');
         $returnArr['stockvalue'] = $returnArr['stock'];
         $available_color = '';
         if (isset($_POST['availablesize'])) {
             $sizeArray = $this->CI->input->post('availablesize');
             $available_size = array_values($sizeArray);
             $stockmultiplier = count($available_size);
             $returnArr['stock'] = $returnArr['stock'] * $stockmultiplier;
             $returnArr['availablesize'] = implode(',', $available_size);
         }
         if (isset($_POST['availablecolor'])) {
             $colorArray = $this->CI->input->post('availablecolor');
             $available_color = array_values($colorArray);
             $colormultiplier = count($available_color);
             //	$returnArr['stockvalue']=	$returnArr['stock'];
             $returnArr['stock'] = $returnArr['stock'] * $colormultiplier;
             //$returnArr['availablecolor']=implode(',',$available_size);
         }
         //echo "<pre>"; print_r($colorArray); exit;
         $this->CI->form_validation->set_rules($rules);
         $this->CI->form_validation->set_error_delimiters('<div class="error">', '</div>');
         if ($this->CI->form_validation->run()) {
             $organizationProductId = $this->CI->product_m->add_organization_product($organizationId, $productId, $returnArr);
             /*********Inventory History Start******************/
             $this->CI->product_m->unactive_old_inventory_history($organizationProductId);
             $returnArr['organizationProductId'] = $organizationProductId;
             $returnArr['organizationId'] = $organizationId;
             $returnArr['productId'] = $productId;
             $returnArr['quantity'] = $returnArr['stock'];
             $returnArr['unitPrice'] = $returnArr['sellPrice'];
             $returnArr['act'] = 1;
             $inventoryHistoryId = $this->CI->product_m->add_inventory_history($returnArr);
             $this->CI->custom_log->write_log('custom_log', 'Inventory history id is ' . $inventoryHistoryId);
             /*********Inventory History End  ******************/
             $this->CI->custom_log->write_log('custom_log', 'new organizationProductId is ' . $organizationProductId);
             if ($organizationProductId) {
                 if (!empty($sizeArray)) {
                     foreach ($sizeArray as $size) {
                         $organizationStockId = $this->CI->product_m->add_size_stock($organizationProductId, $returnArr['stockvalue'], $size, $available_color);
                     }
                 } elseif (!empty($colorArray)) {
                     $organizationStockId = $this->CI->product_m->add_color_stock($organizationProductId, $returnArr['stockvalue'], $colorArray);
                 }
                 $this->CI->session->set_flashdata('success', $this->CI->lang->line('success_add_inventory'));
                 $this->CI->custom_log->write_log('custom_log', $this->CI->lang->line('success_add_inventory'));
             } else {
                 $this->CI->session->set_flashdata('error', $this->CI->lang->line('error_add_inventory'));
                 $this->CI->custom_log->write_log('custom_log', $this->CI->lang->line('error_add_inventory'));
             }
             redirect(base_url() . $this->CI->session->userdata('userType') . '/check_stock_management/check_stock_list/' . id_encrypt($organizationId));
         } else {
             //print_r($this->CI->form_validation->error_array());
         }
     }
     return $returnArr;
 }
Example #2
0
 public function add_inventory($product_id = '')
 {
     $this->session->set_userdata(array('log_MODULE' => 'add_inventory', 'log_MID' => ''));
     $this->data['title'] = 'Add Inventory';
     if (empty($product_id)) {
         $this->session->set_flashdata('error', $this->lang->line('error_product_id_not'));
         redirect(base_url());
     }
     $product_id = id_decrypt($product_id);
     $used = '';
     $this->data['product_attribute'] = $this->product_m->product_attribute($product_id);
     if ($_POST) {
         $this->custom_log->write_log('custom_log', 'Form submit ' . print_r($_POST, true));
         $used = $this->input->post('used');
         $rules = add_inventory_rules();
         $this->form_validation->set_rules($rules);
         $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
         if ($this->form_validation->run()) {
             $sale_price = $this->input->post('sale_price');
             $displayed_price = $this->input->post('displayed_price');
             $inventory = $this->input->post('inventory');
             $commission = $this->input->post('commission');
             $invtryDetails = $this->product_m->inventry_details($product_id);
             $this->custom_log->write_log('custom_log', 'Inventry details ' . print_r($invtryDetails, true));
             if (!empty($invtryDetails)) {
                 $inventryID = $invtryDetails->product_detail_id;
                 $totalInventry = $invtryDetails->inventory + $inventory;
                 $this->product_m->update_retailer_product_detail($inventryID, $sale_price, $displayed_price, $totalInventry, $commission, $used);
             } else {
                 $inventryID = $this->product_m->add_retailer_product_detail($product_id, $sale_price, $displayed_price, $inventory, $commission, $used);
             }
             $this->custom_log->write_log('custom_log', 'inventry id is ' . $inventryID);
             $historyID = $this->product_m->add_retailer_product_detail_history($product_id, $sale_price, $displayed_price, $inventory, $commission, $inventryID, $used);
             $this->custom_log->write_log('custom_log', 'history id is ' . $historyID);
             if ($inventryID) {
                 $this->session->set_flashdata('success', $this->lang->line('success_add_product_detail'));
                 $this->custom_log->write_log('custom_log', $this->lang->line('success_add_product_detail'));
             } else {
                 $this->session->set_flashdata('error', $this->lang->line('error_add_product_detail'));
                 $this->custom_log->write_log('custom_log', $this->lang->line('error_add_product_detail'));
             }
             redirect(base_url() . 'retailer/inventory');
         }
     }
     $this->data['used'] = $used;
     $this->retailerCustomView('inventory/add_inventory', $this->data);
 }