/** * (non-PHPdoc) * @see Application\Controller.CrudController::createAction() */ public function createAction() { $creationFlag = true; $id = $this->getRequest()->getParam('idFolioImport'); $batchNumber = FolioImportQuery::create()->findByPK($this->getRequest()->getParam('idFolioImport'))->getImportLicence(); $SapConnection = new SAPConnectorClient(); $idWarehouse = $this->getRequest()->getParam('warehouse'); $arrivalDate = $this->getRequest()->getParam('arrivalDate'); $comments = $this->getRequest()->getParam('commentariesInspection'); $first = true; $array = array(); $warehouseEntryCollection = new WarehouseEntranceCollection($array); $entrances = $this->getRequest()->getParam('entrances'); $validForm = true; if (empty($arrivalDate)) { $message = $this->i18n->_("Arrival Date is required"); $validForm = false; } foreach ($entrances as $key => $entrance) { if ($entrance['quarantine'] == WarehouseEntrance::$AllStatus['Quarantine']) { if (empty($entrance['folioWarehouse'])) { $message = $this->i18n->_("The Folio Warehouse is required in Line: " . ($key + 1)); $validForm = false; break; } } if ($entrance['quarantine'] == WarehouseEntrance::$AllStatus['Active']) { if (!isset($entrance['ppv']) || !isset($entrance['otherCode']) || !isset($entrance['missing']) || !isset($entrance['leftover']) || !isset($entrance['folioWarehouse'])) { $message = $this->i18n->_("The PPV, Other Code, Missing Pcs, Extra Pieces and Folio Warehouse are required in Line: " . ($key + 1)); $validForm = false; break; } if (!empty($entrance['missing']) && !empty($entrance['leftover'])) { $message = $this->i18n->_("Missing and Extra Pieces cannot be set together in Line: " . ($key + 1)); $validForm = false; break; } if ($entrance['ppv'] + $entrance['otherCode'] + $entrance['missing'] != $entrance['quantity']) { $message = $this->i18n->_("The sum of PPV, Other Code, Missing must match Total Invoice in Line: " . ($key + 1)); $validForm = false; break; } } } if (!$validForm) { $this->view->warning = $message; $folioImport = FolioImportQuery::create()->findByPK($id); $url = '/warehouse-entrance/list'; if ($folioImport->getStatus() == FolioImport::$Status['Inspected']) { $this->_redirect($url); } $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $id)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status['NewService'], PurchaseOrderQuery::NOT_EQUAL)->find(); $i = 0; $purchaseOrderEntries = array(); while ($purchaseOrder = $purchaseOrderQuery->read()) { $purchaseOrders = $this->getPurchaseOrderEntries($purchaseOrder->getIdPurchaseOrder()); foreach ($purchaseOrders as $entry) { $purchaseOrderEntries[] = $entry; } $i++; } $this->view->comments = $comments; $this->view->arrivalDate = $arrivalDate; $this->view->folio = FolioImportQuery::create()->findByPK($id)->getFolio(); $this->view->idWarehouse = FolioImportQuery::create()->findByPK($id)->getIdWareHouse(); $this->view->idFolioImport = $id; $this->view->purchaseOrders = $i; $this->view->purchaseOrderEntries = $purchaseOrderEntries; $this->view->warehouses = TransferLine::getIdWarehousesCombo($this->i18n->_('Select a Warehouse')); $this->view->contentTitle = $this->i18n->_('Reception Formulary'); $this->view->onsubmit = 'warehouse-entrance/create'; $this->view->setTpl('Form'); $this->view->minScripts = true; $this->view->entries = $entrances; } else { try { foreach ($entrances as $key => $entrance) { $transfersByEntry = array(); $idPurchaseOrder = $entrance['idPurchaseOrder']; $purchaseOrderEntryLine = $entrance['idPurchaseOrderEntry']; $purchaseOrder = PurchaseOrderQuery::create()->findByPK($idPurchaseOrder); if ($entrance['quarantine'] == 3) { $transfersByEntry['quarantine'] = $entrance['warehouseTotal']; } else { if ($entrance['ppv']) { $transfersByEntry['ppv'] = $entrance['ppv']; } if ($entrance['rejected']) { $transfersByEntry['rejected'] = $entrance['rejected']; } if ($entrance['otherCode']) { $transfersByEntry['otherCode'] = $entrance['otherCode']; } if ($entrance['missing']) { $transfersByEntry['missing'] = $entrance['missing']; } if ($entrance['leftover']) { $transfersByEntry['leftover'] = $entrance['leftover']; $specialWarehouseEntry = new WarehouseEntrance(); $specialWarehouseEntry->setArrivalDate($arrivalDate); $specialWarehouseEntry->setComments($comments); $specialWarehouseEntry->setCurrency($purchaseOrder->getIdCurrency()); $specialWarehouseEntry->setImportLicense($batchNumber); $specialWarehouseEntry->setGroupnum($purchaseOrder->getGroupnum()); $specialWarehouseEntry->setIdFolioImport($id); $specialWarehouseEntry->setIdSupplier($purchaseOrder->getIdSupplier()); $specialWarehouseEntry->setSamplingType(WarehouseEntrance::$SampingType['Normal']); $specialWarehouseEntry->setNumAtCard(0); $specialWarehouseEntry->setQuarantine($entrance['quarantine']); $specialWarehouseEntry->setStatus($entrance['quarantine']); $purchaseOrderEntry = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $idPurchaseOrder)->whereAdd(PurchaseOrderEntry::LINE, $purchaseOrderEntryLine)->findOne(); $specialWarehouseEntryLine = new WarehouseEntranceProduct(); $specialWarehouseEntryLine->setBaseLine(0); $specialWarehouseEntryLine->setIdWarehouseEntranceProduct(0); $specialWarehouseEntryLine->setBaseRef(0); $specialWarehouseEntryLine->setFolioWarehouse($entrance['folioWarehouse']); $specialWarehouseEntryLine->setIdProduct($purchaseOrderEntry->getIdProduct()); $specialWarehouseEntryLine->setIdPurchaseOrder($idPurchaseOrder); $specialWarehouseEntryLine->setIdWarehouse($idWarehouse); $specialWarehouseEntryLine->setIdWarehouseEntrance(0); $specialWarehouseEntryLine->setIdWarehouseEntranceProduct($line); $specialWarehouseEntryLine->setPrice($purchaseOrderEntry->getPrice()); $specialWarehouseEntryLine->setQuantity($entrance['leftover']); $specialWarehouseEntryLine->setQuantityByWarehouse($purchaseOrderEntry->getQuantityByWarehouse()); $specialWarehouseEntryLine->setStatus($entrance['quarantine']); $specialWarehouseEntryLine->setTaxCode($purchaseOrderEntry->getTaxCode()); $specialWarehouseEntryLine->setCurrency($purchaseOrder->getIdCurrency()); $specialWarehouseEntry->getLines()->append($specialWarehouseEntryLine); $result = $SapConnection->createFreeWarehouseEntry($specialWarehouseEntry); } } $createEntry = false; if ($first) { $createEntry = true; } else { if ($idPurchaseOrder != $prevIdPurchaseOrder) { $createEntry = true; } } if ($createEntry) { $warehouseEntry = new WarehouseEntrance(); $warehouseEntry->setArrivalDate($arrivalDate); $warehouseEntry->setComments($comments); $warehouseEntry->setCurrency($purchaseOrder->getIdCurrency()); $warehouseEntry->setImportLicense($batchNumber); $warehouseEntry->setGroupnum($purchaseOrder->getGroupnum()); $warehouseEntry->setIdFolioImport($purchaseOrder->getIdFolioImport()); $warehouseEntry->setIdSupplier($purchaseOrder->getIdSupplier()); $warehouseEntry->setSamplingType(WarehouseEntrance::$SampingType['Normal']); $warehouseEntry->setNumAtCard($this->createNumAtCard($idPurchaseOrder)); $warehouseEntry->setQuarantine($entrance['quarantine']); $warehouseEntry->setStatus($entrance['quarantine']); $warehouseEntryCollection->append($warehouseEntry); $line = 0; } $purchaseOrderEntry = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $idPurchaseOrder)->whereAdd(PurchaseOrderEntry::LINE, $purchaseOrderEntryLine)->findOne(); $warehouseEntryLine = new WarehouseEntranceProduct(); $warehouseEntryLine->setBaseLine($purchaseOrderEntryLine); $warehouseEntryLine->setIdWarehouseEntranceProduct($line); $warehouseEntryLine->setBaseRef($idPurchaseOrder); $warehouseEntryLine->setFolioWarehouse($entrance['folioWarehouse']); $warehouseEntryLine->setIdProduct($purchaseOrderEntry->getIdProduct()); $warehouseEntryLine->setIdPurchaseOrder($idPurchaseOrder); $warehouseEntryLine->setIdWarehouse($idWarehouse); $warehouseEntryLine->setIdWarehouseEntrance($idWarehouseEntrance); $warehouseEntryLine->setIdWarehouseEntranceProduct($line); $warehouseEntryLine->setPrice($purchaseOrderEntry->getPrice()); $warehouseEntryLine->setQuantity($entrance['warehouseTotal']); $warehouseEntryLine->setQuantityByWarehouse($purchaseOrderEntry->getQuantityByWarehouse()); $warehouseEntryLine->setStatus($entrance['quarantine']); $warehouseEntryLine->setTaxCode($purchaseOrderEntry->getTaxCode()); $warehouseEntryLine->setCurrency($purchaseOrder->getIdCurrency()); $warehouseEntryLine->transfers = $transfersByEntry; $warehouseEntry->getLines()->append($warehouseEntryLine); $first = false; $prevIdPurchaseOrder = $idPurchaseOrder; $line++; } $results = array(); while ($warehouseEntry = $warehouseEntryCollection->read()) { $result = $SapConnection->createWarehouseEntry($warehouseEntry); $results[] = array('success' => $result->createWarehouseEntryResult->success, 'message' => $result->createWarehouseEntryResult->message, 'type' => 'WarehouseEntry', 'id' => $result->createWarehouseEntryResult->id); if ($result->createWarehouseEntryResult->success) { $warehouseEntryLines = $warehouseEntry->getLines(); foreach ($warehouseEntryLines as $warehouseLine) { $transfer = new Transfer(); $transfer->setFolioWarehouse($warehouseLine->getFolioWarehouse()); $transfer->setIdFolioImport($warehouseEntry->getIdFolioImport()); $transfer->setIdWarehouseOrigin($warehouseLine->getIdWarehouse()); $transfer->setInspectionResult($warehouseEntry->getQuarantine()); $transfer->setSamplingType($warehouseEntry->getSamplingType()); $transfer->setStatus($warehouseLine->getStatus()); $i = 0; foreach ($warehouseLine->transfers as $type => $line) { $transferLine = new TransferLine(); if (StoreHouseByLocationQuery::create()->whereAdd(StoreHouseByLocation::TYPE, WarehouseStore::$Type[$type])->whereAdd(StoreHouseByLocation::WHS_CODE_STORE_HOUSES_PPV, $idWarehouse)->count()) { $idWarehouseStore = StoreHouseByLocationQuery::create()->whereAdd(StoreHouseByLocation::TYPE, WarehouseStore::$Type[$type])->whereAdd(StoreHouseByLocation::WHS_CODE_STORE_HOUSES_PPV, $idWarehouse)->findOne()->getWhsCodeStoreHousesDestination(); } else { $idWarehouseStore = $idWarehouse; } $idWarehouseStore = TransferLine::$StoreHouses[$idWarehouse][$type]; $transferLine->setBaseEntry($result->createWarehouseEntryResult->id); $transferLine->setBaseLine($warehouseLine->getIdWarehouseEntranceProduct()); $transferLine->setFolioWarehouse($warehouseLine->getFolioWarehouse()); $transferLine->setIdWarehouse($idWarehouseStore); $transferLine->setItemCode($warehouseLine->getIdProduct()); $transferLine->setLineNum($i); $transferLine->setQuantity($line); $transferLine->setStatus(TransferLine::$Status[$type]); $transferLine->setCurrency($warehouseLine->getCurrency()); $this->newLogForCreate($transferLine); if ($idWarehouseStore != $warehouseLine->getIdWarehouse()) { $transfer->getLines()->append($transferLine); $i++; } } $transferCount = $transfer->getLines()->count(); if ($transferCount > 0) { $resultTransfer = $SapConnection->createTransfer($transfer, $batchNumber); $results[] = array('success' => $resultTransfer->createTransferResult->success, 'message' => $resultTransfer->createTransferResult->message, 'type' => 'Transfer', 'id' => $resultTransfer->createTransferResult->id, 'reference' => $result->createWarehouseEntryResult->id); if (!$resultTransfer->createTransferResult->success) { $creationFlag = false; } } } } else { $creationFlag = false; } } } catch (Exception $e) { echo $e->getMessage(); $this->setFlash('error', $e->getMessage()); $this->_redirect('warehouse-entrance/list'); } $this->setResponseMessage($results); $this->getCatalog('FolioImportCatalog')->beginTransaction(); $folioImport = FolioImportQuery::create()->whereAdd(FolioImport::ID_FOLIO_IMPORT, $id)->findOne(); $warehouseEntries = WarehouseEntranceQuery::create()->whereAdd(WarehouseEntrance::ID_FOLIO_IMPORT, $id)->find(); $folioImport->setStatus(FolioImport::$Status['Inspected']); $this->getCatalog('FolioImportCatalog')->update($folioImport); $this->getEventDispatcherService()->createFolioImportNotification($folioImport, FolioImportEvent::FOLIO_IMPORT_INSPECTED); $this->getCatalog('FolioImportCatalog')->commit(); $this->_redirect('warehouse-entrance/list'); } }
/** * * @param WarehouseEntranceCollection $warehouseEntryCollection * @param LandedCost $landedCost * @return strClass */ public function createLandedCost(WarehouseEntranceCollection $warehouseEntryCollection, LandedCost $landedCost) { $docEntries = array(); while ($warehouseEntry = $warehouseEntryCollection->read()) { $docEntries[] = $warehouseEntry->getIdWarehouseEntrance(); } $parameters['DocEntries'] = array_values($docEntries); $parameters['landedCostSochi'] = $landedCost->toSAPArray(); // echo '<pre>'; // print_r($parameters); // die; return $this->soapClient->createLandedCost($parameters); }