protected function insertSubStore($data)
 {
     $rawMaterial = Utility::getRawMaterialInfo($data['supplyType']);
     $menuSubStore = $this->menuSubStoreModel->findOneBy(array('name' => $rawMaterial->getValue()));
     if ($menuSubStore) {
         $menuSubStore->setName($rawMaterial->getValue());
         $menuSubStore->setUnit($data['unit']);
         $menuSubStore->setOutOfStock($data['OutOfStock']);
         $menuSubStore->setCost(0);
         $menuSubStore->setSupplier(0);
         $menuSubStore->setDes('');
         $menuSubStore->setSupplyItem($data['supplyType']);
         $menuSubStore->setIsdelete(0);
         $menuSubStore = $this->menuSubStoreModel->insert($menuSubStore);
         $menuSubStoreId = $menuSubStore->getId();
         return $menuSubStoreId;
     } else {
         $menuSubStore = new MenuStore();
         $menuSubStore->setName($rawMaterial->getValue());
         $menuSubStore->setUnit($data['unit']);
         $menuSubStore->setOutOfStock($data['OutOfStock']);
         $menuSubStore->setCost(0);
         $menuSubStore->setSupplier(0);
         $menuSubStore->setDes('');
         $menuSubStore->setSupplyItem($data['supplyType']);
         $menuSubStore->setIsdelete(0);
         $menuSubStore = $this->menuSubStoreModel->insert($menuSubStore);
         $menuSubStoreId = $menuSubStore->getId();
         return $menuSubStoreId;
     }
     return -1;
 }
 public function addMultiAction()
 {
     if ($this->getRequest()->isPost()) {
         $datas = $this->params()->fromPost('item');
         $menuStoreId = 0;
         foreach ($datas as $data) {
             if ($data['quantity'] > 0) {
                 $name = $data['name'];
                 $menuStore = $this->menuStoreModel->findOneBy(array('name' => $name));
                 if ($menuStore) {
                     $menuStore->setName($data['name']);
                     $menuStore->setUnit($data['unit']);
                     $menuStore->setDes('');
                     $menuStore->setOutOfStock(0);
                     $menuStore->setCost(0);
                     $menuStore->setSupplier(0);
                     $menuStore->setSupplyItem($data['supplyType']);
                     $menuStore->setIsdelete(0);
                     $this->menuStoreModel->edit($menuStore);
                     $menuStoreId = $menuStore->getId();
                 } else {
                     //else add
                     $menuStore = new MenuStore();
                     $menuStore->setName($data['name']);
                     $menuStore->setUnit($data['unit']);
                     $menuStore->setDes('');
                     $menuStore->setOutOfStock(0);
                     $menuStore->setCost(0);
                     $menuStore->setSupplier(0);
                     $menuStore->setSupplyItem($data['supplyType']);
                     $menuStore->setIsdelete(0);
                     $menuStore = $this->menuStoreModel->insert($menuStore);
                     $menuStoreId = $menuStore->getId();
                 }
                 //insert transaction
                 //insert transaction in menuID
                 $data['menuStoreId'] = $menuStoreId;
                 $data['quantity'] = $data['quantity'] * INSERT_STORE;
                 $data['action'] = INSERT_STORE_ACRION;
                 $data['unit'] = $data['unit'];
                 $data['note'] = $this->translator->translate('Import item into store');
                 TransactionUtility::insertTransaction($data, 0, 0);
                 //transaction main store
                 $data['menuStoreId'] = $data['id'];
                 $data['quantity'] = $data['quantity'] * ADD_ORDER;
                 $data['action'] = ADD_ORDER_ACTION;
                 $data['unit'] = $data['unit'];
                 $data['note'] = $this->translator->translate('Insert sub store');
                 TransactionUtility::insertTransaction($data, 0, 0, MAIN_STORE);
             }
         }
         //flash
         $this->flashMessenger()->addSuccessMessage("Insert Success");
         $this->redirect()->toRoute('admin/child', array('controller' => 'menustore'));
     }
     return new ViewModel(array('title' => $this->translator->translate('Add Inventory Multi')));
 }