public static function insertTransaction($data, $supplier = 0, $cost = 0, $store = 'sub')
 {
     $doctrine = self::$servicelocator->get('doctrine');
     $transactionModel = new transactionModel($doctrine);
     //$transactionModel->begin();
     $transaction = new Transaction();
     $transaction->setMenuStoreId($data['menuStoreId']);
     //create function get menuItem quantity
     $transaction->setQuantity($data['quantity']);
     $transaction->setAction($data['action']);
     $transaction->setDate(time());
     //create function get menuItem quantity
     $transaction->setUnit($data['unit']);
     $transaction->setNote($data['note']);
     $transaction->setCost($cost);
     $transaction->setSupplier($supplier);
     $transaction->setStore($store);
     if (isset($data['orderId'])) {
         $transaction->setOrderId($data['orderId']);
     } else {
         $transaction->setOrderId(0);
     }
     //insert transaction
     $transactionModel->insert($transaction);
     //$transactionModel->commit();
 }
 public function insertTransactionMainAction()
 {
     $menuStoreId = $this->params()->fromRoute('id');
     $menuStoreMain = $this->modelMenuStoreMain->findOneBy(array('id' => $menuStoreId));
     $request = $this->getRequest();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $data = $this->params()->fromPost();
         if ($data['quantity'] != '' && $data['mainMenuStoreId'] != '' && $data['toDate'] != '') {
             $transaction = new Transaction();
             $transaction->setMenuStoreId($data['mainMenuStoreId']);
             $transaction->setAction($data['action']);
             $transaction->setQuantity($data['quantity']);
             $transaction->setUnit($data['unit']);
             $transaction->setDate(strtotime($data['toDate']));
             $transaction->setNote($data['des']);
             $transaction->setCost($data['cost']);
             $transaction->setSupplier(0);
             $transaction->setOrderId(0);
             $transaction->setStore(MAIN_STORE);
             $inserted = $this->modelTransaction->insert($transaction);
             if ($inserted) {
                 $this->flashMessenger()->addSuccessMessage("Insert success");
                 $this->redirect()->toRoute('admin/child', array('controller' => 'menustoremain', 'action' => 'detail', 'id' => $inserted->getMenuStoreId(), 'filter_action' => $inserted->getAction()));
             }
         }
     }
     return new ViewModel(array('menuStoreId' => $menuStoreId, 'menuStore' => $menuStoreMain));
 }