/**
  *
  */
 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);
 }
Exemplo n.º 2
0
 /**
  *
  * @param WarehouseEntrance $warehouseEntrance
  * @return \stdClass
  */
 public function createWarehouseEntry(WarehouseEntrance $warehouseEntrance)
 {
     $lines = array();
     $warehouseEntryLines = $warehouseEntrance->getLines();
     $folioImport = FolioImportQuery::create()->findByPK($warehouseEntrance->getIdFolioImport());
     while ($warehouseEntryLine = $warehouseEntryLines->read()) {
         $lines[] = self::createWarehouseEntryLine($warehouseEntryLine, $warehouseEntrance->getImportLicense(), $folioImport->getCustoms(), $folioImport->getInDate());
     }
     $parameters['warehouseEntry'] = array('DocEntry' => 0, 'DocNum' => 0, 'Cardcode' => utf8_encode($warehouseEntrance->getIdSupplier()), 'DocCur' => utf8_encode($warehouseEntrance->getCurrency()), 'NumAtCard' => utf8_encode($warehouseEntrance->getNumAtCard()), 'Comments' => utf8_encode($warehouseEntrance->getComments()), 'status' => $warehouseEntrance->getStatus(), 'samplingType' => $warehouseEntrance->getSamplingType(), 'inspectionResult' => utf8_encode($warehouseEntrance->getQuarantine()), 'idFolioImport' => $warehouseEntrance->getIdFolioImport(), 'idCourtYard' => 0, 'folioWarehouse' => utf8_encode($warehouseEntrance->getImportLicense()), 'courtyardArrivalDate' => $warehouseEntrance->getArrivalDate(), 'Lines' => $lines);
     $this->createLogrequest($parameters);
     $result = $this->soapClient->createWarehouseEntry($parameters);
     return $result;
 }