/** * Uploads the file and returns an \Application\Model\Bean\File * @author joseluis * @param String $fileField * @param String $path * @return \Application\Model\Bean\File if success false otherwise */ private function saveFile($fileField, $path) { $type = $_FILES[$fileField]['type']; if ($type) { try { $uploadPath = 'public/files/' . $path; $fileUploader = new FileUploader($fileField); if (strstr($type, "image") != false) { $folder = 'images'; $uploadPath .= $folder; $fileUploader->saveFile($uploadPath, true); $fileType = 1; } else { $folder = 'files'; $uploadPath .= $folder; $fileUploader->saveFile($uploadPath, false); $fileType = 2; } $myFile = new File(); $uploadPath = 'files/' . $path . $folder; $myFile->setContent($uploadPath . $fileUploader->getFileName()); $myFile->setType($fileType); return $myFile; } catch (Exception $e) { //the file wasn't uploaded return false; } } }
/** * * @return array */ public function updateAction() { $params = $this->getRequest()->getParams(); if ($this->getRequest()->isPost()) { $idProformaInvoice = $this->getRequest()->getParam('id_proforma_invoice'); $proformaInvoiceParams['date'] = $this->getRequest()->getParam('date', null); $proformaInvoiceParams['folio'] = $this->getRequest()->getParam('folio', null); $proformaInvoiceParams['id_courtyard'] = $this->getRequest()->getParam('id_courtyard', null); $proformaInvoiceParams['id_currency'] = $this->getRequest()->getParam('id_currency'); $proformaInvoiceParams['comments'] = $this->getRequest()->getParam('comments', null); $proformaInvoiceEntriesParams['warehouseStore'] = $this->getRequest()->getParam('warehouse_store', ''); $proformaInvoiceEntriesParams['entries'] = $this->getRequest()->getParam('entries', array()); $proformaInvoicePaymentTermIds = ProformaInvoiceProgrammedPaymentQuery::create()->addColumn(ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE_PAYMENT_TERM)->whereAdd(ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE, $idProformaInvoice)->fetchCol(); $proformaInvoiceNotErasableEvents = ProformaInvoicePaymentTermQuery::create()->addColumn(ProformaInvoicePaymentTerm::ID_EVENT)->whereAdd(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE_PAYMENT, $proformaInvoicePaymentTermIds, ProformaInvoicePaymentTermQuery::IN)->distinct()->fetchCol(); $erasableEvents = EventQuery::create()->addColumn(Event::ID_EVENT)->whereAdd(Event::ID_EVENT, $proformaInvoiceNotErasableEvents, EventQuery::NOT_IN)->distinct()->fetchCol(); $proformaInvoicePaymentTermsParams["events"] = $this->getRequest()->getParam('events', array()); $totalAmmount = $this->getRequest()->getParam('quantityMatch'); $totalProformaInvoiceEntries = count($proformaInvoiceEntriesParams['entries']); try { $proformaInvoice = ProformaInvoiceQuery::create()->findByPKOrThrow($idProformaInvoice, $this->i18n->_("Proforma Invoice with id {$idProformaInvoice} not found")); $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PROFORMA_INVOICE, $proformaInvoice->getIdProformaInvoice())->find(); foreach ($proformaInvoiceEntriesParams['entries'] as $index => $values) { $proformaInvoiceEntry = $proformaInvoiceEntries->getByPK($index); $values["id_warehouse_store"] = $proformaInvoiceEntriesParams['warehouseStore']; ProformaInvoiceEntryFactory::populate($proformaInvoiceEntry, $values); } ProformaInvoiceFactory::populate($proformaInvoice, $proformaInvoiceParams); $sapConnectionClient = new SAPConnectorClient(); $result = $sapConnectionClient->purchaseQuotation($proformaInvoice, $proformaInvoiceEntries); if ($result->purchaseQuotationResult->code == 200) { $proformaInvoiceFiles = ProformaInvoiceFileQuery::create()->whereAdd(ProformaInvoiceFile::ID_PROFORMA_INVOICE, $proformaInvoice->getIdProformaInvoice())->find(); $uploadPath = 'public/' . ($filePath = "files/proformas/" . $result->purchaseQuotationResult->id); if ($_FILES["proforma_invoice_file"]["name"] != "") { $fileUploader = new FileUploader("proforma_invoice_file"); $fileUploader->saveFile($uploadPath, false); $newFile = FileFactory::createFromArray(array(File::CONTENT => $filePath . $fileUploader->getFileName(), File::TYPE => file::$typeFile["typeFile"])); $this->getFileCatalog()->create($newFile); $newProformaInvoiceFile = ProformaInvoiceFileFactory::createFromArray(array(ProformaInvoiceFile::ID_PROFORMA_INVOICE => $proformaInvoice->getIdProformaInvoice(), ProformaInvoiceFile::ID_FILE => $newFile->getIdFile(), ProformaInvoiceFile::TYPE => ProformaInvoiceFile::$Types["PINew"])); $this->getProformaInvoiceFileCatalog()->create($newProformaInvoiceFile); $proformaInvoiceFile = $proformaInvoiceFiles->getByType(ProformaInvoiceFile::$Types["PINew"]); if ($proformaInvoiceFile->getIdProformaInvoiceFile() > 0) { $this->getProformaInvoiceFileCatalog()->deleteById($proformaInvoiceFile->getIdProformaInvoiceFile()); $this->getFileCatalog()->deleteById($proformaInvoiceFile->getIdFile()); } } if ($_FILES["proforma_invoice_file_authorized"]["name"] != "") { $fileUploader = new FileUploader("proforma_invoice_file_authorized"); $fileUploader->saveFile($uploadPath, false); $newFile = FileFactory::createFromArray(array(File::CONTENT => $filePath . $fileUploader->getFileName(), File::TYPE => file::$typeFile["typeFile"])); $this->getFileCatalog()->create($newFile); $newProformaInvoiceFile = ProformaInvoiceFileFactory::createFromArray(array(ProformaInvoiceFile::ID_PROFORMA_INVOICE => $proformaInvoice->getIdProformaInvoice(), ProformaInvoiceFile::ID_FILE => $newFile->getIdFile(), ProformaInvoiceFile::TYPE => ProformaInvoiceFile::$Types["PIAuthorized"])); $this->getProformaInvoiceFileCatalog()->create($newProformaInvoiceFile); $proformaInvoiceFile = $proformaInvoiceFiles->getByType(ProformaInvoiceFile::$Types["PIAuthorized"]); if ($proformaInvoiceFile->getIdProformaInvoiceFile() > 0) { $this->getProformaInvoiceFileCatalog()->deleteById($proformaInvoiceFile->getIdProformaInvoiceFile()); $this->getFileCatalog()->deleteById($proformaInvoiceFile->getIdFile()); } } $allPaymentTerms = ProformaInvoicePaymentTermQuery::create()->whereAdd(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE, $proformaInvoice->getIdProformaInvoice())->find(); try { $this->getProformaInvoicePaymentTermCatalog()->beginTransaction(); $paymentTerms = $allPaymentTerms->filterByEventId($erasableEvents); while ($paymentTerms->valid()) { $paymentTerm = $paymentTerms->read(); $this->getProformaInvoicePaymentTermCatalog()->deleteById($paymentTerm->getIdProformaInvoicePayment()); } $notErasabledPaymentTerms = $allPaymentTerms->filterByEventId($proformaInvoiceNotErasableEvents, $line); $programmedPayments = ProformaInvoiceProgrammedPaymentQuery::create()->whereAdd(ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE_PAYMENT_TERM, $notErasabledPaymentTerms->getPrimaryKeys())->find(); while ($proformaInvoiceEntries->valid()) { $proformaInvoiceEntry = $proformaInvoiceEntries->read(); $totalPayment = 0; foreach ($proformaInvoicePaymentTermsParams["events"] as $key => $payment) { $amount = str_replace(",", "", $payment['payment']); $proformaInvoicePaymentTermsParams["events"][$key]['percentage'] = $amount / $totalAmmount * 100; } foreach ($proformaInvoicePaymentTermsParams["events"] as $event) { $newPaymentTerm = ProformaInvoicePaymentTermFactory::createFromArray(array(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE => $proformaInvoice->getIdProformaInvoice(), ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE_ENTRY => $proformaInvoiceEntry->getIdProformaInvoiceEntry(), ProformaInvoicePaymentTerm::LINE => $proformaInvoiceEntry->getVisOrder(), ProformaInvoicePaymentTerm::ID_EVENT => $event["id"], ProformaInvoicePaymentTerm::PIECES => $proformaInvoiceEntry->getQuantity(), ProformaInvoicePaymentTerm::PAYMENT => $proformaInvoiceEntry->getTotalImport() * $event["percentage"] / 100, ProformaInvoicePaymentTerm::CURRENCY => $proformaInvoice->getIdCurrency())); $this->getProformaInvoicePaymentTermCatalog()->create($newPaymentTerm); } $entryPaymentTerms = $notErasabledPaymentTerms->filterByProformaInvoiceEntry($proformaInvoiceEntry); while ($entryPaymentTerms->valid()) { $paymentTerm = $entryPaymentTerms->read(); $entryProgrammedPayments = $programmedPayments->filterByPaymentTerm($paymentTerm); while ($entryProgrammedPayments->valid()) { $payment = $entryProgrammedPayments->read(); $payment->setIdCurrency($proformaInvoice->getIdCurrency()); $payment->setLine($proformaInvoiceEntry->getVisOrder()); $this->getProformaInvoiceProgrammedPaymentCatalog()->update($payment); } $paymentTerm->setCurrency($proformaInvoice->getIdCurrency()); $paymentTerm->setIdProformaInvoiceEntry($proformaInvoiceEntry->getIdProformaInvoiceEntry()); $paymentTerm->setLine($proformaInvoiceEntry->getVisOrder()); $this->getProformaInvoicePaymentTermCatalog()->update($paymentTerm); } } $this->newLogForUpdate($proformaInvoice); $this->getProformaInvoicePaymentTermCatalog()->commit(); $this->setFlash('ok', $this->i18n->_("Proforma Invoice with id {$result->purchaseQuotationResult->id} was updated.")); } catch (Exception $e) { $this->getProformaInvoicePaymentTermCatalog()->rollBack(); $this->setFlash('error', $this->i18n->_($e->getMessage())); } } else { $this->setFlash('error', $result->purchaseQuotationResult->code . " - " . $result->purchaseQuotationResult->message); } } catch (Exception $e) { $this->setFlash('error', $this->i18n->_($e->getMessage())); } } $this->_redirect('proforma-invoice/list'); }
/** * * @return array */ public function createAction() { if ($this->getRequest()->isPost()) { $params = $this->getRequest()->getParams(); try { $this->getNpdSheetSupplierCatalog()->beginTransaction(); foreach ($params["supplier"] as $index => $supplier) { $idSupplier = $supplier['id_supplier']; $idNpdSupplier = $supplier['id_npd_supplier']; // $supplierParams = Application\Query\SapSupplierQuery::create()->findByPKOrThrow($idSupplier,$this->i18n->_("It does not exist the supplier with id {$idSupplier}")); if ($idNpdSupplier > 0) { $npdSupplierParams = Application\Query\NpdSheetSupplierQuery::create()->findByPKOrElse($idNpdSupplier, new NpdSheetSupplier()); $npdSheetSupplier = NpdSheetSupplierFactory::populate($npdSupplierParams, $supplier); $this->getNpdSheetSupplierCatalog()->update($npdSupplierParams); foreach ($_FILES as $name => $value) { if (strstr($name, "image_" . $index . "_") != false && $value["name"] != "") { $fileUploader = new FileUploader($name); if (strstr($name, "image") != false) { $uploadPath = 'public/files/npd/' . $supplier['id_npd_sheet'] . '/imagesSupplier'; $fileUploader->saveFile($uploadPath, true); $type = File::$typeFile["typeImage"]; } $sheetFile = new File(); $sheetFile->setType($type)->setContent('files/npd/' . $supplier['id_npd_sheet'] . '/imagesSupplier' . $fileUploader->getFileName()); $this->getCatalog("FileCatalog")->create($sheetFile); $this->getNpdSheetSupplierCatalog()->linkToFile($idNpdSupplier, $sheetFile->getIdFile()); } } //Videos //search if npd supplier have videos $npdVideos = NpdSheetSupplierQuery::create()->addColumns(array("File.*"))->innerJoinFile()->whereAdd("NpdSheetSupplier." . NpdSheetSupplier::ID_NPD_SUPPLIER, $idNpdSupplier)->whereAdd("File." . File::TYPE, File::$typeFile["typeLink"])->fetchAll(); // if npd supplier have videos then delete it all foreach ($npdVideos as $npdVideo) { $this->getFileCatalog()->unlinkFromNpdSheetSupplier($npdVideo["id_file"], $idNpdSupplier); $this->getFileCatalog()->deleteById($npdVideo["id_file"]); } //die("<pre>".print_r($supplier, true)."</pre>"); // insert new videos $supplier["video"] = (array) $supplier["video"]; foreach ($supplier["video"] as $video) { if ($video != "") { //insert a new video with Type -> video $sheetFile = new File(); $sheetFile->setType(File::$typeFile["typeLink"])->setContent($video); //make relationship file - npdSupplier $this->getFileCatalog()->create($sheetFile); $this->getNpdSheetSupplierCatalog()->linkToFile($idNpdSupplier, $sheetFile->getIdFile()); } } //Moq and Price //search if npd supplier have moq and price $npdMoqPrices = SupplierBudgetQuery::create()->whereAdd(SupplierBudget::ID_NPD_SUPPLIER, $idNpdSupplier)->fetchAll(); //if npd supplier have moq and price then delete it all foreach ($npdMoqPrices as $npdMoqPrice) { $this->getSupplierBudgetCatalog()->deleteById($npdMoqPrice["id_supplier_budget"]); } //insert new moq and price foreach ($supplier["moqPrice"] as $moqprice) { $npdMoq = new SupplierBudget(); $npdMoq->setIdNpdSupplier($idNpdSupplier)->setMoq($moqprice["moq"])->setLeadTime($moqprice["leadtime"])->setPrice($moqprice["price"])->setIdCurrency($supplier["id_currency"]); $this->getSupplierBudgetCatalog()->create($npdMoq); } $this->getNpdSheetSupplierCatalog()->unlinkAllColor($idNpdSupplier); } else { $newSuppliers = $supplier; $npdSheetSupplier = NpdSheetSupplierFactory::createFromArray($newSuppliers); $this->getNpdSheetSupplierCatalog()->create($npdSheetSupplier); $newSupplier = $npdSheetSupplier->getIdNpdSupplier(); foreach ($_FILES as $name => $value) { if (strstr($name, "image_" . $index . "_") != false && $value["name"] != "") { $fileUploader = new FileUploader($name); if (strstr($name, "image") != false) { $uploadPath = 'public/files/npd/' . $supplier['id_npd_sheet'] . '/imagesSupplier'; $fileUploader->saveFile($uploadPath, true); $type = File::$typeFile["typeImage"]; } $uploadPath = 'files/npd/' . $supplier['id_npd_sheet'] . '/imagesSupplier'; $sheetFile = new File(); $sheetFile->setType($type)->setContent($uploadPath . $fileUploader->getFileName()); $this->getCatalog("FileCatalog")->create($sheetFile); $this->getNpdSheetSupplierCatalog()->linkToFile($newSupplier, $sheetFile->getIdFile()); } } foreach ($supplier["video"] as $video) { if ($video != "") { //insert a new video with Type -> video $sheetFile = new File(); $sheetFile->setType(File::$typeFile["typeLink"])->setContent($video); //make relationship file - npdSupplier $this->getFileCatalog()->create($sheetFile); $this->getNpdSheetSupplierCatalog()->linkToFile($newSupplier, $sheetFile->getIdFile()); } } //insert new moq and price foreach ($supplier["moqPrice"] as $moqprice) { $npdMoq = new SupplierBudget(); $npdMoq->setIdNpdSupplier($newSupplier)->setMoq($moqprice["moq"])->setLeadTime($moqprice["leadtime"])->setPrice($moqprice["price"])->setIdCurrency($supplier["id_currency"]); $this->getSupplierBudgetCatalog()->create($npdMoq); } } } $this->getNpdSheetSupplierCatalog()->commit(); $this->setFlash('ok', $this->i18n->_("The Supplier has been saved")); } catch (Exception $e) { // Roll back any change in database $this->getNpdSheetSupplierCatalog()->rollBack(); $this->setFlash('error', $this->i18n->_($e->getMessage())); throw $e; } } $this->_redirect('npd-sheet/list'); }
/** * */ public function payAction() { $params = $this->getRequest()->getParams(); $returnAction = $this->getRequest()->getParam("returnAction", "list"); $payment = Zend_Json::decode(stripslashes($params["sapPayment"])); $this->getActualPaymentCatalog()->beginTransaction(); try { $fileUploader = new FileUploader('file'); if (!$fileUploader->isUpload()) { throw new Exception("El archivo es invalido"); } $uploadDir = 'public/files/payments/docnum' . $docnum; $fileUploader->saveFile($uploadDir, false); $file = new File(); $file->setContent($uploadDir . $fileUploader->getFileName()); $file->setType(File::$typeFile['typeImage']); $this->getFileCatalog()->create($file); foreach ($params["payment"] as $programmedPaymentParam) { if ($programmedPaymentParam["payment"] > 0) { $programmedPayment = ProgrammedPaymentQuery::create()->findByPK($programmedPaymentParam["id"]); $balance = $this->getPaymentBalance($programmedPayment); if ($balance + $programmedPaymentParam["payment"] > $programmedPayment->getAmmount()) { throw new Exception("Balance overloaded"); } $actualPayment = ActualPaymentFactory::createFromArray(array(ActualPayment::ID_FILE => $file->getIdFile(), ActualPayment::DOCNUM => $payment["idPayment"], ActualPayment::ID_PROGRAMMED_PAYMENT => $programmedPayment->getIdProgrammedPayment(), ActualPayment::AMMOUNT => $programmedPaymentParam["payment"], ActualPayment::PAYMENT_DATE => $payment["paymentDate"], ActualPayment::TYPE => $payment["type"])); $this->getActualPaymentCatalog()->create($actualPayment); if ($balance + $programmedPaymentParam["payment"] == $programmedPayment->getAmmount()) { $programmedPayment->setStatus(ProgrammedPayment::$TypeStatus['Paid']); $event = ProgrammedPaymentEvent::TOTAL_PAYMENT; } else { $programmedPayment->setStatus(ProgrammedPayment::$TypeStatus['Partial']); $event = ProgrammedPaymentEvent::PARTIAL_PAYMENT; } $this->getProgrammedPaymentCatalog()->update($programmedPayment); $this->getEventDispatcherService()->createProgrammedPaymentNotification($event, $programmedPayment, $actualPayment); //TODO Despachar el evento de Pago Realizado } } $this->getActualPaymentCatalog()->commit(); $this->setFlash("ok", $this->i18n->_('The payments were successfully saved')); } catch (Exception $e) { $this->getActualPaymentCatalog()->rollBack(); $this->setFlash("error", $this->i18n->_('The payments could not be saved: ' . $e->getMessage())); } $this->getHelper('redirector')->goto($returnAction); }
public function savefileAction($inputFile, $type, $idSupplier) { $fileUploader = new FileUploader($inputFile); if ($fileUploader->isUpload()) { $filePath = "files/company/supplier/" . $idSupplier; $uploadPath = 'public/' . $filePath; $files = SupplierFileQuery::create()->innerJoinFile()->addColumns(array('File.*', 'SupplierFile.*'))->whereAdd('SupplierFile.' . SupplierFile::ID_SUPPLIER, $idSupplier)->whereAdd('SupplierFile.document_type', $type)->fetchAll(); foreach ($files as $file) { $idSupplierFile = $file['id_supplier_file']; $dir = 'public/'; $filename = $file['content']; $idFile = $file['id_file']; if (file_exists($dir . $filename)) { unlink($dir . $filename); } $this->getSupplierFileCatalog()->deleteById($idSupplierFile); $this->getFileCatalog()->deleteById($file['id_file']); } $fileUploader->saveFile($uploadPath, false); $setupFormFile = new SupplierFile(); $setupFormFile->setContent($filePath . $fileUploader->getFileName()); $setupFormFile->setType(File::$typeFile['typeFile']); $setupFormFile->setIdSupplier($idSupplier); $setupFormFile->setDocumentType($type); $this->getSupplierFileCatalog()->create($setupFormFile); } }
/** * * @return array */ public function updateAction() { $params = $this->getRequest()->getParams(); $id = $params['id_customs_broker']; $customsBroker = CustomsBrokerQuery::create()->findByPKOrThrow($id, $this->i18n->_('It does not exist Customs Broker with id')); $this->getCustomsBrokerCatalog()->beginTransaction(); try { $address = AddressFactory::createFromArray($params); $this->getCatalog('AddressCatalog')->update($address); } catch (Exception $e) { //Address couldn't be created $this->getCustomsBrokerCatalog()->rollBack(); $this->setFlash('error', $this->i18n->_($e->getMessage())); } //updates the file and its register in the db and eliminates previous one $type = $_FILES['id_last_fee_file']['type']; if ($type) { try { $uploadPath = 'files/company/customs-broker/' . $params['id_company']; $fileUploader = new FileUploader("id_last_fee_file"); if ($fileUploader->isUpload()) { if ($customsBroker->getIdLastFeeFile()) { $idFile = $customsBroker->getIdLastFeeFile(); $feeFile = \Application\Query\FileQuery::create()->findByPK($idFile); //$this->getCatalog('FileCatalog')->deleteById($feeFile->getIdFile()); is_dir(unlink('public/' . $feeFile->getContent())); } if (strstr($type, "image") != false) { $uploadPath .= '/images'; $fileUploader->saveFile('public/' . $uploadPath, true); } else { $uploadPath .= '/files'; $fileUploader->saveFile('public/' . $uploadPath, false); } $myFile = new File(); $myFile->setContent($uploadPath . $fileUploader->getFileName()); $myFile->setType(file::$typeFile['typeFile']); $this->getCatalog('FileCatalog')->create($myFile); $customsBroker->setIdLastFeeFile($myFile->getIdFile()); } } catch (Exception $e) { //the images wasn't uploaded $this->setFlash('error', $this->i18n->_($e->getMessage())); } } try { $this->getCustomsBrokerCatalog()->unlinkAllPortCustom($id); $idsCustomsPort = $params['idsCustomsPort']; foreach ($idsCustomsPort as $idCustomsPort) { $this->getCustomsBrokerCatalog()->linkToPortCustom($customsBroker->getIdCustomsBroker(), $idCustomsPort); } } catch (Exception $e) { $this->setFlash('error', $this->i18n->_($e->getMessage())); } //Inserts a customs broker register try { CustomsBrokerFactory::populate($customsBroker, $params); $this->getCustomsBrokerCatalog()->update($customsBroker); } catch (Exception $e) { $this->setFlash('error', $this->i18n->_($e->getMessage())); } $this->getCustomsBrokerCatalog()->commit(); $this->setFlash('ok', $this->i18n->_("The Customs Brokers with id {$id} has been updated")); $this->_redirect("customs-broker/list"); }
public function savefileAction($idInspection, $idOrderEntry) { $fileUploader = new FileUploader("file"); if ($fileUploader->isUpload()) { $filePath = "files/order-entry/" . $idOrderEntry . '/result'; $uploadPath = 'public/' . $filePath; $files = InspectionQuery::create()->innerJoinFile()->addColumns(array('File.*'))->whereAdd('Inspection.' . Inspection::ID_INSPECTION, $idInspection)->fetchAll(); foreach ($files as $file) { $dir = 'public/'; $filename = $file['content']; $idFile = $file['id_file']; unlink($dir . $filename); $this->getInspectionFileCatalog()->deleteById($file['id_file']); $this->getFileCatalog()->deleteById($idFile); } $fileUploader->saveFile($uploadPath, false); $resultFile = new InspectionFile(); $resultFile->setContent($filePath . $fileUploader->getFileName()); $resultFile->setType(1); $resultFile->setIdInspection($idInspection); //$resultFile->setDocumentType($type); $this->getInspectionFileCatalog()->create($resultFile); } }
/** * * @return array */ public function updateAction() { if ($this->getRequest()->isPost()) { $params = $this->getRequest()->getParams(); $id = $this->getRequest()->getParam("id_npd_sheet"); $npdSheet = NpdSheetQuery::create()->findByPKOrThrow($id, $this->i18n->_("The Family with id {$id} does not exist.")); try { $this->getCatalog("NpdSheetCatalog")->beginTransaction(); NpdSheetFactory::populate($npdSheet, $params); if ($npdSheet->getPrice() == 0) { $this->setFlash('error', $this->i18n->_("The NPD price cannot be zero")); return $this->getHelper('redirector')->goto('edit', null, null, array('id' => $id)); } if ($this->getRequest()->getParam('id_subfamily') == '') { $npdSheet->setIdSubfamily(null); } $this->getCatalog("NpdSheetCatalog")->update($npdSheet); foreach ($_FILES as $name => $value) { if ($value["name"] != "") { $fileUploader = new FileUploader($name); if (strstr($name, "image") != false) { $filePath = 'files/npd/' . $npdSheet->getIdNpdSheet() . '/images'; $uploadPath = 'public/' . $filePath; $fileUploader->saveFile($uploadPath, true); $type = File::$typeFile["typeImage"]; } else { // Check if a file exist with the same type equal to file $npdFiles = NpdSheetQuery::create()->addColumns(array("File.*"))->innerJoinFile()->whereAdd("NpdSheet." . NpdSheet::ID_NPD_SHEET, $npdSheet->getIdNpdSheet())->whereAdd("File." . File::TYPE, File::$typeFile["typeFile"])->fetchAll(); // if the file exist then delete it to be able to save a new file foreach ($npdFiles as $npdFile) { $this->getCatalog("FileCatalog")->unlinkFromNpdSheet($npdFile["id_file"], $npdSheet->getIdNpdSheet()); $this->getCatalog("FileCatalog")->deleteById($npdFile["id_file"]); if (file_exists("public/" . $npdFile["content"])) { unlink("public/" . $npdFile["content"]); } } $filePath = 'files/npd/' . $npdSheet->getIdNpdSheet() . '/files'; $uploadPath = 'public/' . $filePath; $fileUploader->saveFile($uploadPath, false); $type = File::$typeFile["typeFile"]; } $sheetFile = new File(); $sheetFile->setType($type)->setContent($filePath . $fileUploader->getFileName()); $this->getCatalog("FileCatalog")->create($sheetFile); $this->getCatalog("NpdSheetCatalog")->linkToFile($npdSheet->getIdNpdSheet(), $sheetFile->getIdFile()); } } // search if npd have videos $npdVideos = NpdSheetQuery::create()->addColumns(array("File.*"))->innerJoinFile()->whereAdd("NpdSheet." . NpdSheet::ID_NPD_SHEET, $npdSheet->getIdNpdSheet())->whereAdd("File." . File::TYPE, File::$typeFile["typeLink"])->fetchAll(); // if npd have videos then delete it all foreach ($npdVideos as $npdVideo) { $this->getCatalog("FileCatalog")->unlinkFromNpdSheet($npdVideo["id_file"], $npdSheet->getIdNpdSheet()); $this->getCatalog("FileCatalog")->deleteById($npdVideo["id_file"]); } foreach ($params["video"] as $video) { if ($video != "") { $sheetFile = new File(); $sheetFile->setType(File::$typeFile["typeLink"])->setContent($video); $this->getCatalog("FileCatalog")->create($sheetFile); $this->getCatalog("NpdSheetCatalog")->linkToFile($npdSheet->getIdNpdSheet(), $sheetFile->getIdFile()); } } $this->getCatalog("NpdSheetCatalog")->unlinkAllColor($npdSheet->getIdNpdSheet()); if ($params["color"]) { foreach ($params["color"] as $color) { if ($color) { $this->getCatalog("NpdSheetCatalog")->linkToColor($npdSheet->getIdNpdSheet(), $color); } } } $this->getCatalog("NpdSheetCatalog")->commit(); $this->setFlash('ok', $this->i18n->_("Has been saved successfully")); } catch (Exception $e) { } $this->setFlash('ok', $this->i18n->_("The NpdSheet was updated")); } $this->_redirect('npd-sheet/list'); }
/** * * @param string $fileName * @throws Exception * @return unknown */ private function readData($fileName) { $tempdir = sys_get_temp_dir(); $fileUploader = new FileUploader($fileName); try { $fileUploader->saveFile($tempdir); $filePath = $tempdir . $fileUploader->getFileName(); $fileType = \PHPExcel_IOFactory::identify($filePath); $reader = \PHPExcel_IOFactory::createReader($fileType); $PHPExcel = $reader->load($filePath); return $PHPExcel; } catch (\Exception $e) { throw new \Exception('The file cannot be read'); } }