Example #1
0
 public function generateRequisitionAction()
 {
     $restocks = RestockQuery::create()->find();
     if (!$restocks->isEmpty()) {
         $restockEntries = RestockEntryQuery::create()->whereAdd(RestockEntry::ID_RESTOCK, $restocks->current()->getIdRestock(), RestockQuery::EQUAL)->find();
         if (!$restockEntries->isEmpty()) {
             $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $restockEntries->getDistinctProducts(), ProductQuery::IN)->find();
             $currencies = CurrencyQuery::create()->find();
             $exchangeRates = CurrencyExchangeQuery::create()->find();
             $restockFinalResultManager = new RestockFinalResultsManager($restockEntries, $products);
             try {
                 $this->getRequisitionCatalog()->beginTransaction();
                 $requisition = RequisitionFactory::createFromArray(array(Requisition::ID_DESTINATION_COUNTRY => Country::$defaultIdCountry, Requisition::TYPE => Requisition::$Type["Weekly"], Requisition::STATUS => Requisition::$Status["New"], Requisition::NUM_REQUISITION => "Weekly Restock."));
                 $this->getRequisitionCatalog()->create($requisition);
                 while ($restockEntries->valid()) {
                     $restockEntry = $restockEntries->read();
                     if ($restockEntry->isChecked()) {
                         $quantity = $restockFinalResultManager->getTotalCartonsByIdRestockEntry($restockEntry->getIdRestockEntry());
                         if ($quantity > 0) {
                             $product = $products->getByPK($restockEntry->getIdProduct());
                             $requisitionEntry = RequisitionEntryFactory::createFromArray(array(RequisitionEntry::ID_REQUISITION => $requisition->getIdRequisition(), RequisitionEntry::ID_PRODUCT => $product->getItemCode(), RequisitionEntry::PRICE => $restockEntry->getMinTargetPrice() * $exchangeRates->getByFromAndTo(Currency::$defaultCurrency, $product->getCurrency())->getRate(), RequisitionEntry::ID_CURRENCY => $product->getCurrency(), RequisitionEntry::ID_SUPPLIER_DEFAULT => $product->getIdSupplier(), RequisitionEntry::QUANTITY => $quantity, RequisitionEntry::STATUS => RequisitionEntry::$Status["New"]));
                             $this->getRequisitionEntryCatalog()->create($requisitionEntry);
                         }
                     }
                 }
                 $this->getRestockEntryCatalog()->truncate();
                 $this->getRestockCatalog()->truncate();
                 $this->getRequisitionCatalog()->commit();
                 $this->setFlash('ok', $this->i18n->_("Requisition was saved with folio {$requisition->getIdRequisition()}"));
             } catch (Exception $e) {
                 $this->getRequisitionCatalog()->rollBack();
                 $this->setFlash('error', $this->i18n->_($e->getMessage()));
             }
         }
     }
     $this->_redirect('requisition/list');
 }
Example #2
0
 /**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\Requisition
  */
 protected function makeBean($resultset)
 {
     return RequisitionFactory::createFromArray($resultset);
 }
Example #3
0
 /**
  *
  * @return array
  */
 public function createAction()
 {
     if ($this->getRequest()->isPost()) {
         // Get params and complete the default info to save the requistion
         $requistionParams[Requisition::NUM_REQUISITION] = $this->getRequest()->getParam(Requisition::NUM_REQUISITION, "");
         $requistionParams[Requisition::COMMENT] = $this->getRequest()->getParam(Requisition::COMMENT, null);
         $requistionParams[Requisition::ID_DESTINATION_COUNTRY] = $this->getRequest()->getParam(Requisition::ID_DESTINATION_COUNTRY);
         $requistionParams[Requisition::FOLIO_PROYECTO_ESPECIAL] = $this->getRequest()->getParam(Requisition::FOLIO_PROYECTO_ESPECIAL, "");
         $requistionParams[Requisition::FECHA_PROMESA_ENTREGA] = $this->getRequest()->getParam(Requisition::FECHA_PROMESA_ENTREGA, "");
         $requistionParams[Requisition::PROYECTO_ESPECIAL] = $this->getRequest()->getParam(Requisition::PROYECTO_ESPECIAL, "");
         $requistionParams[Requisition::STATUS] = $this->getRequest()->getParam("quick", 0) ? Requisition::$Status["Approved"] : Requisition::$Status["New"];
         $requistionParams[Requisition::TYPE] = $this->getRequest()->getParam("quick", 0) ? Requisition::$Type["Quick"] : Requisition::$Type["Special"];
         // Get Params and complete the default info to save the requisition Entry
         $requistionEntries = $this->getRequest()->getParam("entries");
         try {
             // Save the requisition in database
             $this->getRequisitionCatalog()->beginTransaction();
             $requisition = RequisitionFactory::createFromArray($requistionParams);
             $this->getRequisitionCatalog()->create($requisition);
             $this->newLogForCreate($requisition);
             // Save a entry for each product in database
             foreach ($requistionEntries as $requisitionEntry) {
                 $requisitionEntry = RequisitionEntryFactory::createFromArray(array(RequisitionEntry::ID_REQUISITION => $requisition->getIdRequisition(), RequisitionEntry::ID_PRODUCT => $requisitionEntry[RequisitionEntry::ID_PRODUCT], RequisitionEntry::ID_SUPPLIER_DEFAULT => $requisitionEntry[RequisitionEntry::ID_SUPPLIER_DEFAULT] == "" ? Null : $requisitionEntry[RequisitionEntry::ID_SUPPLIER_DEFAULT], RequisitionEntry::ID_CURRENCY => $requisitionEntry[RequisitionEntry::ID_CURRENCY], RequisitionEntry::QUANTITY => $requisitionEntry[RequisitionEntry::QUANTITY], RequisitionEntry::PRICE => $requisitionEntry[RequisitionEntry::PRICE], RequisitionEntry::COMMENTS => $requisitionEntry[RequisitionEntry::COMMENTS], RequisitionEntry::STATUS => $this->getRequest()->getParam("quick", 0) ? RequisitionEntry::$Status["Pending Price"] : RequisitionEntry::$Status["New"]));
                 $this->getRequisitionEntryCatalog()->create($requisitionEntry);
             }
             // Commit all changes and set a confrimation message
             $this->getRequisitionCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("The requisition was saved with folio {$requisition->getIdRequisition()}"));
         } catch (Exception $e) {
             // If something goes wrong then revert all changes in database and set a error status
             $this->getRequisitionCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect('requisition/list');
 }