/**
  *
  */
 public function saveQuarantineDebugAction()
 {
     $url = 'warehouse-entrance/quarantine-list';
     $SapConnection = new SAPConnectorClient();
     $entrances = $this->getRequest()->getParam('entrances');
     $entrance = $entrances[0];
     $idWarehouseEntry = $entrance['idWarehouseEntrance'];
     $idWarehouseEntryLine = $entrance['idWarehouseEntranceProduct'];
     $warehouseEntry = WarehouseEntranceQuery::create()->findByPK($idWarehouseEntry);
     $warehouseEntryLine = WarehouseEntranceProductQuery::create()->whereAdd(WarehouseEntranceProduct::ID_WAREHOUSE_ENTRANCE, $idWarehouseEntry)->whereAdd(WarehouseEntranceProduct::ID_WAREHOUSE_ENTRANCE_PRODUCT, $idWarehouseEntryLine)->findOne();
     $folioImport = FolioImportQuery::create()->findByPK($warehouseEntry->getIdFolioImport());
     $this->getCatalog('QuarantineCatalog')->beginTransaction();
     $quarantine = $this->getQuarantine($idWarehouseEntry, $idWarehouseEntryLine);
     $quantity = $quarantine->getQuantity() - $entrance['ppv'] - $entrance['second'] - $entrance['destruction'] - $entrance['missing'] - $entrance['other_code'];
     $quarantine->setQuantity($quantity);
     $quarantine->setPpv($entrance['ppv'] + $quarantine->getPpv());
     $quarantine->setSecond($entrance['second'] + $quarantine->getSecond());
     $quarantine->setDestruction($entrance['destruction'] + $quarantine->getDestruction());
     $quarantine->setMissing($entrance['missing'] + $quarantine->getMissing());
     $quarantine->setLeftover($entrance['leftover'] + $quarantine->getLeftover());
     $quarantine->setOtherCode($entrance['other_code'] + $quarantine->getOtherCode());
     $this->getCatalog('QuarantineCatalog')->update($quarantine);
     $transfer = TransferQuery::create()->whereAdd(Transfer::ID_FOLIO_IMPORT, $warehouseEntry->getIdFolioImport())->whereAdd(TransferLine::ITEM_CODE, $warehouseEntryLine->getIdProduct())->innerJoinTransferLine()->findOne();
     $baseTransferLine = TransferLineQuery::create()->whereAdd(TransferLine::ID_TRANSFER, $transfer->getIdTransfer())->whereAdd(TransferLine::ITEM_CODE, $warehouseEntryLine->getIdProduct())->findOne();
     $warehouseStore = WarehouseStoreQuery::create()->whereAdd(WarehouseStore::CODE, $warehouseEntryLine->getIdWarehouse())->findOne();
     $idWarehouse = $warehouseEntryLine->getIdWarehouse();
     $ppvToQuarantine = array_flip(TransferLine::$fromQuarantineToPpv);
     $idWarehouseQuarantine = $ppvToQuarantine[$idWarehouse];
     $idWarehousePpv = TransferLine::$fromQuarantineToPpv[$idWarehouseQuarantine];
     $entries['ppv'] = $entrance['ppv'];
     $entries['second'] = $entrance['second'];
     $entries['destruction'] = $entrance['destruction'];
     $entries['missing'] = $entrance['missing'];
     $entries['otherCode'] = $entrance['other_code'];
     if ($entrance['leftover']) {
         $idPurchaseOrder = $warehouseEntryLine->getIdPurchaseOrder();
         $purchaseOrderEntryLine = $warehouseEntryLine->getBaseLine();
         $purchaseOrder = PurchaseOrderQuery::create()->findByPK($idPurchaseOrder);
         $specialWarehouseEntry = new WarehouseEntrance();
         $specialWarehouseEntry->setArrivalDate(\Zend_Date::now()->get('YYYY-MM-dd'));
         $specialWarehouseEntry->setComments($entrance['commentaries'] . ' ');
         $specialWarehouseEntry->setCurrency($purchaseOrder->getIdCurrency());
         $specialWarehouseEntry->setImportLicense($batchNumber);
         $specialWarehouseEntry->setGroupnum($purchaseOrder->getGroupnum());
         $specialWarehouseEntry->setIdFolioImport($folioImport->getIdFolioImport());
         $specialWarehouseEntry->setIdSupplier($purchaseOrder->getIdSupplier());
         $specialWarehouseEntry->setSamplingType(WarehouseEntrance::$SampingType['Normal']);
         $specialWarehouseEntry->setNumAtCard(0);
         $specialWarehouseEntry->setQuarantine(0);
         $specialWarehouseEntry->setStatus(0);
         $specialWarehouseEntry->setImportLicense(str_replace(' ', '', $folioImport->getImportLicence()));
         $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($idWarehousePpv);
         $specialWarehouseEntryLine->setIdWarehouseEntrance(0);
         $specialWarehouseEntryLine->setIdWarehouseEntranceProduct($line);
         $specialWarehouseEntryLine->setPrice($purchaseOrderEntry->getPrice());
         $specialWarehouseEntryLine->setQuantity($entrance['leftover']);
         $specialWarehouseEntryLine->setQuantityByWarehouse($purchaseOrderEntry->getQuantityByWarehouse());
         $specialWarehouseEntryLine->setStatus(0);
         $specialWarehouseEntryLine->setTaxCode($purchaseOrderEntry->getTaxCode());
         $specialWarehouseEntryLine->setCurrency($purchaseOrder->getIdCurrency());
         $specialWarehouseEntry->getLines()->append($specialWarehouseEntryLine);
         $result = $SapConnection->createFreeWarehouseEntry($specialWarehouseEntry);
     }
     $transfer = new Transfer();
     $transfer->setComments($entrance['commentaries']);
     $transfer->setFolioWarehouse($entrance['folioWarehouse']);
     $transfer->setIdFolioImport($warehouseEntry->getIdFolioImport());
     $transfer->setIdWarehouseOrigin($idWarehouseQuarantine);
     $transfer->setInspectionResult(0);
     $transfer->setSamplingType(0);
     $transfer->setStatus(0);
     $i = 0;
     $ppvBase = StoreHouseByLocationQuery::create()->whereAdd(StoreHouseByLocation::WHS_CODE_STORE_HOUSES_DESTINATION, $baseTransferLine->getIdWarehouse())->findOne();
     foreach ($entries as $type => $entry) {
         if ($entry) {
             if (StoreHouseByLocationQuery::create()->whereAdd(StoreHouseByLocation::WHS_CODE_STORE_HOUSES_PPV, $warehouseEntryLine->getIdWarehouse())->whereAdd(StoreHouseByLocation::TYPE, WarehouseStore::$Type[$type])->count()) {
                 $idWarehouseStore = StoreHouseByLocationQuery::create()->whereAdd(StoreHouseByLocation::WHS_CODE_STORE_HOUSES_PPV, $warehouseEntryLine->getIdWarehouse())->whereAdd(StoreHouseByLocation::TYPE, WarehouseStore::$Type[$type])->findOne()->getWhsCodeStoreHousesDestination();
             } else {
                 $idWarehouseStore = $warehouseEntryLine->getIdWarehouse();
             }
             $transferLine = new TransferLine();
             // 				$baseIdWarehouse =StoreHouseByLocationQuery::create()->whereAdd(StoreHouseByLocation::WHS_CODE_STORE_HOUSES_PPV, $baseTransferLine->getIdWarehouse())->whereAdd(StoreHouseByLocation::TYPE, WarehouseStore::$Type['quarantine'])->findOne()->getWhsCodeStoreHousesDestination();
             if ($idWarehouseStore != $baseTransferLine->getIdWarehouse()) {
                 $transferLine->setBaseEntry($baseTransferLine->getIdTransfer());
                 $transferLine->setBaseLine($baseTransferLine->getLineNum());
                 $transferLine->setFolioWarehouse($folioImport->getImportLicence());
                 $transferLine->setItemCode($warehouseEntryLine->getIdProduct());
                 $transferLine->setLineNum($i);
                 $transferLine->setIdWarehouse($idWarehouseStore);
                 $transferLine->setQuantity($entry);
                 $transferLine->setStatus(0);
                 $transfer->getLines()->append($transferLine);
                 $i++;
             }
         }
     }
     $result = $SapConnection->createTransfer($transfer, $folioImport->getImportLicence(), true);
     if ($result->createTransferResult->success) {
         $this->setFlash('ok', $this->i18n->_('The quarantine debugging has been saved.'));
         $this->getCatalog('QuarantineCatalog')->commit();
     } else {
         $this->setFlash('error', $result->createTransferResult->message);
         $this->getCatalog('QuarantineCatalog')->rollBack();
     }
     $this->_redirect($url);
 }
Example #2
0
 /**
  *
  * @param Transfer $transfer
  * @param string $batchNumber
  * @param bool $quarantine
  * @return stdClass
  */
 public function createTransfer(Transfer $transfer, $batchNumber, $quarantine = false)
 {
     $lines = array();
     $transferLines = $transfer->getLines();
     $numberOfLines = $transfer->getLines()->count();
     while ($transferLine = $transferLines->read()) {
         $lines[] = $this->createTransferLine($transferLine, $batchNumber);
     }
     $quarantine = $quarantine == false ? 0 : 1;
     $parameters['transfer'] = array('fromWarehouse' => utf8_encode($transfer->getIdWarehouseOrigin()), 'IdFolioImport' => $transfer->getIdFolioImport(), 'InspectionResult' => utf8_encode($transfer->getInspectionResult()), 'SamplingType' => $transfer->getSamplingType(), 'Status' => $transfer->getStatus(), 'Comments' => utf8_encode($transfer->getComments()), 'Quarantine' => $quarantine, 'transferLines' => $lines);
     if ($numberOfLines) {
         $result = $this->soapClient->createTransfer($parameters);
     } else {
         $result->createTransferResult->success = true;
         $result->createTransferResult->message = true;
     }
     return $result;
 }