/**
  * This action create a proforma invoice and link with respective budgets and requisition entries
  *
  * @author Erick Guevara Martinez
  */
 public function createAction()
 {
     $proformaParams["proforma_invoice_number"] = $this->getRequest()->getParam("proforma_invoice_number", "");
     $proformaParams["date"] = $this->getRequest()->getParam("required_date", "");
     $proformaParams["delivery_estimate_date"] = $this->getRequest()->getParam("required_date", "");
     $proformaParams["id_forwarder"] = $this->getRequest()->getParam("id_forwarder", "");
     $proformaParams["id_supplier"] = $this->getRequest()->getParam("id_supplier", "");
     $proformaParams["id_port_custom"] = $this->getRequest()->getParam("id_port_custom", "");
     $proformaParams["id_courtyard"] = $this->getRequest()->getParam("id_courtyard", "");
     $proformaParams["idCurrencyPI"] = $this->getRequest()->getParam("idCurrencyPI", "");
     $supplier = SapSupplierQuery::create()->findByPKOrThrow($proformaParams["id_supplier"], $this->i18n->_("The Supplier with id {$proformaParams["id_supplier"]} does not exist"));
     $date = \Zend_Date::now();
     $accessRole = $this->getUser()->getAccessRole();
     $proformaInvoice = ProformaInvoiceFactory::createFromArray(array("id_proforma_invoice" => 0, "folio" => $proformaParams["proforma_invoice_number"], "groupnum" => $supplier->getGroupnum(), "id_courtyard" => $proformaParams["id_courtyard"], "id_currency" => $proformaParams["idCurrencyPI"], "id_supplier" => $proformaParams["id_supplier"], "date" => $proformaParams["date"], "delivery_estimate_date" => $proformaParams["delivery_estimate_date"], "creation_date" => $date->get("yyyy-MM-dd"), "status" => ProformaInvoice::$Status["New"]));
     $proformaInvoiceEntries = new ProformaInvoiceEntryCollection();
     $proformaEntriesParams["parentKeys"] = $this->getRequest()->getParam("parentKeys", "");
     $proformaEntriesParams["warehouse_store"] = $this->getRequest()->getParam("warehouse_store", WarehouseStore::$defaultWarehouseStore);
     $arrayRequisitionEntries = array();
     $lineCount = 0;
     foreach ($proformaEntriesParams["parentKeys"] as $parentKey) {
         foreach ($parentKey["products"] as $key => $product) {
             $proformaInvoiceEntry = ProformaInvoiceEntryFactory::createFromArray(array("id_proforma_invoice_entry" => 0, "line" => $lineCount, "vis_order" => $lineCount, "id_product" => $product["product"], "id_warehouse_store" => $proformaEntriesParams["warehouse_store"], "lead_time" => $parentKey["lead_time"], "quantity" => $product["Quantity"], "status" => ProformaInvoiceEntry::$Status["New"], "price" => $parentKey["price"], "currency" => $proformaParams["idCurrencyPI"], "tax_code" => "W0", "requisition_ids" => implode('-', $product['entries'])));
             $proformaInvoiceEntries->append($proformaInvoiceEntry);
             $lineCount++;
             $arrayRequisitionEntries = array_merge($arrayRequisitionEntries, $product["entries"]);
         }
     }
     $sapConnectionClient = new SAPConnectorClient();
     $result = $sapConnectionClient->purchaseQuotation($proformaInvoice, $proformaInvoiceEntries);
     if ($result->purchaseQuotationResult->code == 200) {
         try {
             $this->getFileCatalog()->beginTransaction();
             $proformaInvoice->setIdProformaInvoice($result->purchaseQuotationResult->id);
             while ($proformaInvoiceEntry = $proformaInvoiceEntries->read()) {
                 $proformaInvoiceEntry->setIdProformaInvoice($result->purchaseQuotationResult->id);
                 $this->newEntryLogForCreate($proformaInvoiceEntry);
             }
             $fileUploader = new FileUploader("proforma_invoice_file");
             $filePath = "files/proformas/" . $result->purchaseQuotationResult->id;
             $uploadPath = 'public/' . $filePath;
             $fileUploader->saveFile($uploadPath, false);
             // Create the file record in database
             $file = new File();
             $file->setType(File::$typeFile["typeFile"])->setContent($filePath . $fileUploader->getFileName());
             $this->getFileCatalog()->create($file);
             $proformaInvoiceFile = ProformaInvoiceFileFactory::createFromArray(array(ProformaInvoiceFile::ID_FILE => $file->getIdFile(), ProformaInvoiceFile::ID_PROFORMA_INVOICE => $result->purchaseQuotationResult->id, ProformaInvoiceFile::TYPE => ProformaInvoiceFile::$Types["PINew"]));
             $this->getProformaInvoiceFileCatalog()->create($proformaInvoiceFile);
             // Create Payment terms by Proforma invoice Line
             // Se consultan las entries debido a que hasta el momento no tenian id
             $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PROFORMA_INVOICE, $result->purchaseQuotationResult->id)->find();
             //die("<pre>".print_r($proformaInvoiceEntries, true));
             $events = EventQuery::create()->addColumns(array("Event2PaymentTerm.*", "Event.*"))->innerJoinPaymentTerm()->whereAdd("Event2PaymentTerm." . PaymentTerm::ID_PAYMENT_TERM, $supplier->getIdPaymentTerm(), BaseQuery::EQUAL)->fetchAll();
             foreach ($events as $event) {
                 $proformaInvoiceEntries->rewind();
                 while ($proformaInvoiceEntries->valid()) {
                     $proformaInvoiceEntry = $proformaInvoiceEntries->read();
                     $proformaInvoicePaymentTerm = ProformaInvoicePaymentTermFactory::createFromArray(array(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE => $proformaInvoiceEntry->getIdProformaInvoice(), ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE_ENTRY => $proformaInvoiceEntry->getIdProformaInvoiceEntry(), ProformaInvoicePaymentTerm::ID_EVENT => $event["id_event"], ProformaInvoicePaymentTerm::LINE => $proformaInvoiceEntry->getVisOrder(), ProformaInvoicePaymentTerm::PIECES => $proformaInvoiceEntry->getQuantity(), ProformaInvoicePaymentTerm::PAYMENT => $proformaInvoiceEntry->getTotalImport() * $event["percent"] / 100, ProformaInvoicePaymentTerm::CURRENCY => $proformaInvoiceEntry->getCurrency(), ProformaInvoicePaymentTerm::STATUS => ProformaInvoicePaymentTerm::$Status["Active"]));
                     $this->getProformaInvoicePaymentTermCatalog()->create($proformaInvoicePaymentTerm);
                 }
             }
             // Close requisition entries and requisition
             $requisitionEntries = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_REQUISITION_ENTRY, $arrayRequisitionEntries, RequisitionEntryQuery::IN)->find();
             $requisitions = RequisitionQuery::create()->whereAdd(Requisition::ID_REQUISITION, $requisitionEntries->getDistinctRequisitions(), RequisitionQuery::IN)->find();
             while ($requisitionEntries->valid()) {
                 $requisitionEntry = $requisitionEntries->read();
                 $requisitionEntry->setStatus(RequisitionEntry::$Status["Closed"]);
                 $this->getRequisitionEntryCatalog()->update($requisitionEntry);
                 $requisition = $requisitions->getByPK($requisitionEntry->getIdRequisition());
                 $requisitionEntriesByRequisition = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_REQUISITION, $requisition->getIdRequisition(), RequisitionEntryQuery::EQUAL)->whereAdd(RequisitionEntry::ID_REQUISITION_ENTRY, $requisitionEntry->getIdRequisitionEntry(), RequisitionEntryQuery::NOT_EQUAL)->find();
                 if ($requisitionEntriesByRequisition->checkClosed()) {
                     $requisition->setStatus(Requisition::$Status["Closed"]);
                     $this->getRequisitionCatalog()->update($requisition);
                 }
             }
             $keyMotherSupplierBudgets = KeyMotherSupplierBudgetQuery::create()->innerJoinRequisitionEntry()->whereAdd("RequisitionEntry." . RequisitionEntry::ID_REQUISITION_ENTRY, $requisitionEntries->getPrimaryKeys(), KeyMotherSupplierBudgetQuery::IN)->find();
             while ($keyMotherSupplierBudgets->valid()) {
                 $budget = $keyMotherSupplierBudgets->read();
                 $budget->setStatus(KeyMotherSupplierBudget::$Status["Inactive"]);
                 $this->getKeyMotherSupplierBudgetCatalog()->update($budget);
             }
             $this->newLogForCreate($proformaInvoice, $proformaInvoiceEntries);
             $this->getFileCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("The Proforma Invoice was created with id {$result->purchaseQuotationResult->id}."));
         } catch (Exception $e) {
             $this->getFileCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     } else {
         $this->setFlash('error', $result->purchaseQuotationResult->code . " - " . $result->purchaseQuotationResult->message);
     }
     $this->_redirect('proforma-invoice/list');
 }
Beispiel #2
0
 /**
  * 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;
         }
     }
 }
 /**
  *
  */
 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);
 }
 /**
  *
  * @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');
 }
 /**
  *
  * @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");
 }
Beispiel #6
0
 /**
  *
  * @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');
 }