Example #1
0
 public function editBatchNo()
 {
     $stock_detail = new Model_StockDetail();
     $stock_detail->form_values['pk_id'] = $this->form_values['pk_id'];
     $quantity_and_batch = $stock_detail->getQuantityById($this->form_values['pk_id']);
     // echo $quantity_and_batch['number']."<br>" ;
     // echo $this->form_values['number'];
     //exit;
     if ($quantity_and_batch['number'] != $this->form_values['number']) {
         $data = array('number' => $quantity_and_batch['number'], 'batch_id' => $quantity_and_batch['stock_batch_id'], 'item_id' => $quantity_and_batch['item_pack_size_id']);
         // check batch is new or old
         $batch_id = $this->checkNewBatch($data);
         if ($batch_id === 0) {
             // if batch is new then  new batch
             $data_pre = array('number' => $this->form_values['number'], 'item_id' => $quantity_and_batch['item_pack_size_id']);
             $batch_id_previous = $this->checkBatch($data_pre);
             if ($batch_id_previous === 0) {
                 $this->form_values['pk_id'] = $quantity_and_batch['stock_batch_id'];
                 return $this->updateName();
             } else {
                 $stock_detail->updateDetail($quantity_and_batch['stock_detail'], $batch_id_previous);
                 $this->adjustQuantityByWarehouse($batch_id_previous);
                 $this->batch_id = $quantity_and_batch['stock_batch_id'];
                 return $this->updateWarehouseId();
             }
         } else {
             $data_array = array('number' => $this->form_values['number'], 'item_id' => $quantity_and_batch['item_pack_size_id']);
             $batch_id_pre = $this->checkBatch($data_array);
             if ($batch_id_pre === 0) {
                 $data_pr = array('number' => $this->form_values['number'], 'item_id' => $quantity_and_batch['item_pack_size_id'], 'expiry_date' => $quantity_and_batch['expiryDate'], 'quantity' => $quantity_and_batch['quantity'], 'vvm_type_id' => $quantity_and_batch['vvmTypeId'], 'unit_price' => $quantity_and_batch['unitPrice'], 'manufacturer_id' => $quantity_and_batch['stakeholderItemPackSizeId']);
                 // App_Controller_Functions::pr($data_pr);
                 $batch_id_new = $this->createBatch($data_pr);
                 $stock_detail->updateDetail($quantity_and_batch['stock_detail'], $batch_id_new);
                 $this->adjustQuantityByWarehouse($quantity_and_batch['stock_batch_id']);
             } else {
                 $stock_detail->updateDetail($quantity_and_batch['stock_detail'], $batch_id_pre);
                 $this->adjustQuantityByWarehouse($quantity_and_batch['stock_batch_id']);
                 $this->adjustQuantityByWarehouse($batch_id_pre);
                 // $this->batch_id = $quantity_and_batch['stock_batch_id'];
                 // return $this->updateWarehouseId();
             }
         }
     }
 }