/**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\KeyMotherSupplierBudget
  */
 protected function makeBean($resultset)
 {
     return KeyMotherSupplierBudgetFactory::createFromArray($resultset);
 }
Exemplo n.º 2
0
 /**
  * This action save budgets to benchmarking
  * @todo crear log 
  * @author Erick Guevara Martínez
  */
 public function saveBudgetAction()
 {
     //die("<pre>".print_r($this->getRequest()->getParams(), true)."</pre>");
     if ($this->getRequest()->isPost()) {
         try {
             $this->getKeyMotherSupplierBudgetCatalog()->beginTransaction();
             // Check if the key mother have another budgets actives
             $budgetActive = KeyMotherSupplierBudgetQuery::create()->whereAdd(KeyMotherSupplierBudget::KEY_MOTHER, $this->getRequest()->getParam("key_mother"), BaseQuery::EQUAL)->actives()->findOne();
             // If the key mother have at least one budget then search your requisitionEntries if not then search by params
             if ($budgetActive) {
                 $requisitionEntries = RequisitionEntryQuery::create()->innerJoinKeyMotherSupplierBudget()->whereAdd("KeyMotherSupplierBudget." . KeyMotherSupplierBudget::ID_KEY_MOTHER_SUPPLIER_BUDGET, $budgetActive->getIdKeyMotherSupplierBudget())->find();
             } else {
                 $requisitionEntries = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_REQUISITION_ENTRY, $this->getRequest()->getParam("id_requisition_entries"), BaseQuery::IN)->find();
             }
             // Insert all params into KeyMotherSupplierBudget Bean
             $budget = KeyMotherSupplierBudgetFactory::createFromArray(array(KeyMotherSupplierBudget::ID_SUPPLIER => $this->getRequest()->getParam("id_supplier"), KeyMotherSupplierBudget::KEY_MOTHER => $this->getRequest()->getParam("key_mother"), KeyMotherSupplierBudget::LEAD_TIME => $this->getRequest()->getParam("lead_time"), KeyMotherSupplierBudget::PRICE => $this->getRequest()->getParam("price"), KeyMotherSupplierBudget::QUANTITY => $this->getRequest()->getParam("quantity"), KeyMotherSupplierBudget::STATUS => KeyMotherSupplierBudget::$Status["Active"], KeyMotherSupplierBudget::ID_CURRENCY => $this->getRequest()->getParam("id_currency"), KeyMotherSupplierBudget::COMMENTS => $this->getRequest()->getParam("comments")));
             // Save Bean
             $this->getKeyMotherSupplierBudgetCatalog()->create($budget);
             // Change status of all searched requisition entries and links to created budget
             while ($requisitionEntry = $requisitionEntries->read()) {
                 $requisitionEntry->setStatus(RequisitionEntry::$Status["Pending Price Auth"]);
                 $this->getRequisitionEntryCatalog()->update($requisitionEntry);
                 $this->getKeyMotherSupplierBudgetCatalog()->linkToRequisitionEntry($budget->getIdKeyMotherSupplierBudget(), $requisitionEntry->getIdRequisitionEntry());
             }
             $this->getKeyMotherSupplierBudgetCatalog()->commit();
             $this->setFlash("ok", $this->i18n->_("The Supplier Budget to Parent Key {$this->getRequest()->getParam("key_mother")} was saved correctly."));
         } catch (Exception $e) {
             $this->getKeyMotherSupplierBudgetCatalog()->rollBack();
             $this->setFlash("error", $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect("requisition/entries");
 }