/**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\PurchaseOrderFile
  */
 protected function makeBean($resultset)
 {
     return PurchaseOrderFileFactory::createFromArray($resultset);
 }
 public function readyToShipmentAction()
 {
     $idPurchaseOrder = $this->getRequest()->getParam("id_purchase_order");
     $blHouseData[PurchaseOrderCommercialInvoice::PIECES] = $this->getRequest()->getParam("pieces");
     $blHouseData[PurchaseOrderCommercialInvoice::CARTONS] = $this->getRequest()->getParam("cartons");
     $blHouseData[PurchaseOrderCommercialInvoice::LOAD] = $this->getRequest()->getParam("load");
     $blHouseData[PurchaseOrderCommercialInvoice::PAYLOAD] = $this->getRequest()->getParam("payload");
     $blHouseData[PurchaseOrderCommercialInvoice::NUM_BL_HOUSE] = $this->getRequest()->getParam("num_bl_house");
     $courtyardArrivalDate = $this->getRequest()->getParam("courtyard_arrival_date");
     $purchaseOrder = PurchaseOrderQuery::create()->findByPKOrThrow($idPurchaseOrder, $this->i18n->_("The Purchase Order with id {$idPurchaseOrder} does not exist"));
     if (PurchaseOrderCommercialInvoiceQuery::create()->whereAdd(PurchaseOrderCommercialInvoice::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->count()) {
         $purchaseOrderCommercialInvoice = PurchaseOrderCommercialInvoiceQuery::create()->whereAdd(PurchaseOrderCommercialInvoice::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->find()->getOne();
     } else {
         $purchaseOrderCommercialInvoice = new PurchaseOrderCommercialInvoice();
     }
     $purchaseOrderEntries = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->find();
     $purchaseOrder->setStatus(PurchaseOrder::$Status["Ready"])->setCourtyardArrivalDate($courtyardArrivalDate);
     $sap = new SAPConnectorClient();
     $result = $sap->purchaseOrder($purchaseOrder, $purchaseOrderEntries);
     if ($result->purchaseOrderResult->code == 200) {
         try {
             $this->getPurchaseOrderCatalog()->beginTransaction();
             if ($_FILES["bl_house_file"]["name"] != "") {
                 $filePath = "files/purchase-order/" . $purchaseOrder->getIdPurchaseOrder();
                 $uploadPath = 'public/' . $filePath;
                 $fileUploader = new FileUploader("bl_house_file");
                 $fileUploader->saveFile($uploadPath, false);
                 $blHouseFile = PurchaseOrderFileFactory::createFromArray(array(PurchaseOrderFile::CONTENT => $filePath . $fileUploader->getFileName(), PurchaseOrderFile::TYPE => File::$typeFile["typeFile"], PurchaseOrderFile::DOCUMENT_TYPE => PurchaseOrderFile::$DocumentType["BLHouse"], PurchaseOrderFile::ID_PURCHASE_ORDER => $purchaseOrder->getIdPurchaseOrder()));
                 $this->getPurchaseOrderFileCatalog()->create($blHouseFile);
                 $this->newLogForUploadBL($purchaseOrder);
             }
             PurchaseOrderCommercialInvoiceFactory::populate($purchaseOrderCommercialInvoice, $blHouseData);
             if ($purchaseOrderCommercialInvoice->getIdPurchaseOrderCommercialInvoice()) {
                 $this->getPurchaseOrderCommercialInvoiceCatalog()->update($purchaseOrderCommercialInvoice);
             } else {
                 $purchaseOrderCommercialInvoice->setIdPurchaseOrder($idPurchaseOrder);
                 $this->getPurchaseOrderCommercialInvoiceCatalog()->create($purchaseOrderCommercialInvoice);
             }
             $this->newLogForReadyToShipment($purchaseOrder);
             $this->getPurchaseOrderCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("The Purchase Order has ready to shipment."));
         } catch (Exception $e) {
             $this->getPurchaseOrderCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     } else {
         $this->setFlash('error', $result->purchaseOrderResult->code . " - " . $result->purchaseOrderResult->message);
     }
     $this->_redirect('purchase-order/list');
 }