Пример #1
0
 /**
  * Saves files and removes old ones
  * @author joseluis
  */
 public function saveFileAction()
 {
     $params = $this->getRequest()->getParams();
     //Purchase Order Id
     $id = $params['id'];
     //die(print_r($id));
     $documentType = $params['documentType'];
     //the route inside public/files/
     $path = 'purchase-order/' . $id . '/';
     $savedFile = $this->saveFile('file', $path);
     $purchaseOrderFile = new PurchaseOrderFile();
     $fileCount = PurchaseOrderFileQuery::create()->whereAdd('PurchaseOrderFile.' . PurchaseOrderFile::ID_PURCHASE_ORDER, $id)->whereAdd('PurchaseOrderFile.' . PurchaseOrderFile::DOCUMENT_TYPE, $documentType)->count();
     if ($fileCount) {
         $purchaseOrderFile = PurchaseOrderFileQuery::create()->whereAdd('PurchaseOrderFile.' . PurchaseOrderFile::ID_PURCHASE_ORDER, $id)->whereAdd('PurchaseOrderFile.' . PurchaseOrderFile::DOCUMENT_TYPE, $documentType)->findOne();
         if ($purchaseOrderFile->getType() == 1) {
             $point = strripos($purchaseOrderFile->getContent(), '.');
             $fileExtension = substr($purchaseOrderFile->getContent(), $point);
             $fileName = substr($purchaseOrderFile->getContent(), 0, $point);
             $file = 'public/' . $fileName . $fileExtension;
             if (file_exists($file)) {
                 unlink($file);
             }
             $file = 'public/' . $fileName . '_o' . $fileExtension;
             if (file_exists($file)) {
                 unlink($file);
             }
             $file = 'public/' . $fileName . '_mini' . $fileExtension;
             if (file_exists($file)) {
                 unlink($file);
             }
         } else {
             if (file_exists('public/' . $purchaseOrderFile->getContent())) {
                 unlink('public/' . $purchaseOrderFile->getContent());
             }
         }
         $purchaseOrderFile->setContent($savedFile->getContent());
         $purchaseOrderFile->setType($savedFile->getType());
         $this->getCatalog('PurchaseOrderFileCatalog')->beginTransaction();
         try {
             $this->getCatalog('PurchaseOrderFileCatalog')->update($purchaseOrderFile);
             //$this->getCatalog('PurchaseOrderFileCatalog')->commit();
             $this->setFlash('ok', $this->i18n->_($this->CREATE_FILE_OK));
         } catch (Exception $e) {
             $this->getCatalog('PurchaseOrderFileCatalog')->rollBack();
             $this->setFlash('error', $this->i18n->_($this->ERROR));
         }
     } else {
         $purchaseOrderFile->setContent($savedFile->getContent());
         $purchaseOrderFile->setType($savedFile->getType());
         $purchaseOrderFile->setIdPurchaseOrder($id);
         $purchaseOrderFile->setDocumentType($documentType);
         $this->getCatalog('PurchaseOrderFileCatalog')->beginTransaction();
         try {
             $this->getCatalog('PurchaseOrderFileCatalog')->create($purchaseOrderFile);
             $this->setFlash('ok', $this->i18n->_($this->CREATE_FILE_OK));
         } catch (Exception $e) {
             $this->getCatalog('FolioImportFileCatalog')->rollBack();
             $this->setFlash('error', $this->i18n->_($this->ERROR));
         }
         $type = array_flip(PurchaseOrderFile::$DocumentType);
         $documentType = $type[$documentType];
     }
     $this->getCatalog('PurchaseOrderFileCatalog')->commit();
     $this->_redirect('purchase-order/list');
 }
Пример #2
0
 /**
  *
  * @param int $id
  * @param int $status
  * @param bool $notLike
  * @return array $purchaseOrders
  */
 private function getPurchaseOrders($idFolioImport, $status = null, $in = true)
 {
     $id = $idFolioImport;
     if ($status == null) {
         $query = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $id)->count();
         $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $id)->find();
     } else {
         if ($in) {
             $query = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $id)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::IN)->count();
             $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $id)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::IN)->find();
         } else {
             $query = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $id)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::NOT_EQUAL)->count();
             $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $id)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::NOT_EQUAL)->find();
         }
     }
     if ($query) {
         $i = 0;
         while ($purchaseOrder = $purchaseOrderQuery->read()) {
             try {
                 $purchaseOrderEntryQuery = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->find();
                 $price = 0;
                 $cbm = 0;
                 $individual_packs = 0;
                 $cartons = 0;
                 $quantity = 0;
                 $weight = 0;
                 $valuable = array();
                 $j = 0;
                 $packingList = PurchaseOrderFileQuery::create()->whereAdd(PurchaseOrderFile::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->whereAdd(PurchaseOrderFile::DOCUMENT_TYPE, PurchaseOrderFile::$DocumentType['PackingList'])->count();
                 $commercialInvoice = PurchaseOrderFileQuery::create()->whereAdd(PurchaseOrderFile::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->whereAdd(PurchaseOrderFile::DOCUMENT_TYPE, PurchaseOrderFile::$DocumentType['CommercialInvoice'])->count();
                 if ($packingList) {
                     $purchaseOrders[$i]['packing_list'] = true;
                 } else {
                     $purchaseOrders[$i]['packing_list'] = false;
                 }
                 if ($commercialInvoice) {
                     $purchaseOrders[$i]['commercial_invoice'] = true;
                 } else {
                     $purchaseOrders[$i]['commercial_invoice'] = false;
                 }
                 while ($purchaseOrderEntry = $purchaseOrderEntryQuery->read()) {
                     $product = ProductQuery::create()->findByPK($purchaseOrderEntry->getIdProduct());
                     if ($product->getMcParts()) {
                         $cartonsEntry = ceil($purchaseOrderEntry->getQuantity() / $product->getMcParts());
                     } else {
                         $cartonsEntry = $this->i18n->_('Edit Master Carton Parts');
                     }
                     $volume = $product->getMcFront() * $product->getMcHeight() * $product->getMcDepth() / 1000000;
                     $cbm += $cartonsEntry * $volume;
                     $weight += $cartonsEntry * $product->getMcWeight();
                     $price += $purchaseOrderEntry->getQuantity() * $purchaseOrderEntry->getPrice();
                     $cartons += $cartonsEntry;
                     $quantity += $purchaseOrderEntry->getQuantity();
                     $entries[$j]['id_product'] = $product->getItemCode();
                     $entries[$j]['status'] = $this->getPurchaseOrderEntryStatus($purchaseOrderEntry->getStatus());
                     $entries[$j]['important'] = $product->getImportant();
                     $entries[$j]['item_code'] = $product->getItemCode();
                     $entries[$j]['product'] = $product->getItemName();
                     $entries[$j]['price'] = $purchaseOrderEntry->getPrice();
                     $entries[$j]['amount'] = $purchaseOrderEntry->getAmount();
                     $entries[$j]['cartons'] = $cartonsEntry;
                     $entries[$j]['quantity'] = $purchaseOrderEntry->getQuantity();
                     $entries[$j]['weight'] = $product->getMcWeight() * $cartonsEntry;
                     $entries[$j]['volume'] = number_format($volume * $cartonsEntry, 2);
                     if (FreightFareQuery::create()->whereAdd(FreightFare::ID_FREIGHT_FARE, $product->getDefaultFreightFare())->count()) {
                         $idFreightType = FreightFareQuery::create()->findByPK($product->getDefaultFreightFare())->getIdFreightType();
                         $entries[$j]['default_shipping'] = FreightTypeQuery::create()->findByPK($idFreightType)->getName();
                     }
                     if (FileQuery::create()->whereAdd(File::ID_FILE, $product->getImportPermit())->count()) {
                         $importPermit = FileQuery::create()->findByPK($product->getImportPermit());
                         if ($importPermit) {
                             $entries[$j]['import_permit'] = true;
                         } else {
                             $entries[$j]['import_permit'] = false;
                         }
                     } else {
                         $entries[$j]['import_permit'] = false;
                     }
                     $entries[$j]['row_status'] = 'success';
                     $purchaseOrders[$i]['row_status'] = 'success';
                     $important = $product->getImportant();
                     if (!$entries[$j]['import_permit']) {
                         $entries[$j]['row_status'] = 'error';
                         $purchaseOrders[$i]['row_status'] = 'error';
                         $entries[$j]['label'] = $this->i18n->_('This product, does not have an Import Clearance Document.');
                         $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order has entries without Import Clearance.');
                     } else {
                         if (!$purchaseOrders[$i]['commercial_invoice']) {
                             $purchaseOrders[$i]['row_status'] = 'error';
                             $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order, does not have a Commercial Invoice Document.');
                         } else {
                             if (!$purchaseOrders[$i]['packing_list']) {
                                 $purchaseOrders[$i]['row_status'] = 'error';
                                 $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order, does not have a Packing List Document.');
                             } else {
                                 if ($important) {
                                     $entries[$j]['row_status'] = 'warning';
                                     $purchaseOrders[$i]['row_status'] = 'warning';
                                     $entries[$j]['label'] = $this->i18n->_('This product is small and valuable.');
                                     $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order has small and valuable stuff.');
                                 } else {
                                     $entries[$j]['row_status'] = 'success';
                                     $purchaseOrders[$i]['row_status'] = 'success';
                                 }
                             }
                         }
                     }
                     $j++;
                 }
                 //Checks if the entry has important stuff
                 if (count($valuable) == 1) {
                     $purchaseOrders[$i]['importance'] = $valuable[1];
                 } else {
                     $flag = 0;
                     $value = $valuable[1];
                     for ($j = 2; $j <= count($valuable); $j++) {
                         if ($valuable[$j] != $value) {
                             $value = 2;
                             break;
                         }
                     }
                     $purchaseOrders[$i]['importance'] = $value;
                 }
                 switch ($purchaseOrders[$i]['importance']) {
                     case '1':
                         $purchaseOrders[$i]['importance'] = $this->i18n->_('Yes');
                         break;
                     case '2':
                         $purchaseOrders[$i]['importance'] = $this->i18n->_('Mixed');
                         break;
                     default:
                         $purchaseOrders[$i]['importance'] = $this->i18n->_('No');
                 }
             } catch (Exception $e) {
                 var_dump($e->getMessage());
             }
             // 			$purchaseOrders[$i]['id_purchase_order_folio'] = PurchaseOrderFolioQuery::create()
             // 			->whereAdd(PurchaseOrderFolio::ID_PURCHASE_ORDER, $purchaseOrder['id_purchase_order'])
             // 			->whereAdd(PurchaseOrderFolio::ID_FOLIO_IMPORT, $idFolioImport)
             // 			->findOne()->getIdPurchaseOrderFolio();
             $cartons = 0;
             $quantity = 0;
             $weight = 0;
             $cbm = 0;
             $price = 0;
             foreach ($entries as $entry) {
                 $cartons += intval($entry['cartons']);
                 $quantity += intval($entry['quantity']);
                 $weight += $entry['weight'];
                 $cbm += $entry['volume'];
                 $price += $entry['price'] * $entry['quantity'];
             }
             $purchaseOrders[$i]['entries'] = $entries;
             $purchaseOrders[$i]['cartons'] = $cartons;
             $purchaseOrders[$i]['quantity'] = $quantity;
             $purchaseOrders[$i]['weight'] = $weight;
             $purchaseOrders[$i]['cbm'] = number_format($cbm, 2);
             $purchaseOrders[$i]['price'] = $price;
             $purchaseOrders[$i]['id_purchase_order'] = $purchaseOrder->getIdPurchaseOrder();
             $purchaseOrders[$i]['courtyard_arrival_date'] = $purchaseOrder->getIdCourtyard();
             $i++;
         }
         return $purchaseOrders;
     } else {
         return null;
     }
 }
Пример #3
0
 private function getPurchaseOrders($idFolioImport, $status = null, $in = true)
 {
     $id = $idFolioImport;
     $purchaseOrderFolioQuery = PurchaseOrderFolioQuery::create()->addColumn(PurchaseOrderFolio::ID_PURCHASE_ORDER)->whereAdd(PurchaseOrderFolio::ID_FOLIO_IMPORT, $id);
     if ($status == null) {
         $query = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->count();
         $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->fetchAll();
     } else {
         if ($in) {
             $query = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::IN)->count();
             $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::IN)->fetchAll();
         } else {
             $query = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::NOT_EQUAL)->count();
             $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::NOT_EQUAL)->fetchAll();
         }
     }
     if ($query) {
         $i = 0;
         foreach ($purchaseOrderQuery as $purchaseOrder) {
             try {
                 $purchaseOrderEntryQuery = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrder['id_purchase_order'])->fetchAll();
                 $price = 0;
                 $cbm = 0;
                 $individual_packs = 0;
                 $cartons = 0;
                 $quantity = 0;
                 $weight = 0;
                 $valuable = array();
                 $j = 0;
                 $packingList = PurchaseOrderFileQuery::create()->whereAdd(PurchaseOrderFile::ID_PURCHASE_ORDER, $purchaseOrder['id_purchase_order'])->whereAdd(PurchaseOrderFile::DOCUMENT_TYPE, PurchaseOrderFile::$DocumentType['PackingList'])->count();
                 $commercialInvoice = PurchaseOrderFileQuery::create()->whereAdd(PurchaseOrderFile::ID_PURCHASE_ORDER, $purchaseOrder['id_purchase_order'])->whereAdd(PurchaseOrderFile::DOCUMENT_TYPE, PurchaseOrderFile::$DocumentType['CommercialInvoice'])->count();
                 if ($packingList) {
                     $purchaseOrders[$i]['packing_list'] = true;
                 } else {
                     $purchaseOrders[$i]['packing_list'] = false;
                 }
                 if ($commercialInvoice) {
                     $purchaseOrders[$i]['commercial_invoice'] = true;
                 } else {
                     $purchaseOrders[$i]['commercial_invoice'] = false;
                 }
                 foreach ($purchaseOrderEntryQuery as $purchaseOrderEntry) {
                     $product = ProductQuery::create()->findByPK($purchaseOrderEntry['id_product'])->toArray();
                     if (!empty($product['mc_parts'])) {
                         $cartonsEntry = ceil($purchaseOrderEntry['quantity'] / $product['mc_parts']);
                     } else {
                         $this->setFlash('warning', $this->i18n->_("You must edit MC Parts, it cannot be cero."));
                         $this->_redirect('product/edit/id/' . $product['id_product']);
                     }
                     $volume = $product['mc_front'] * $product['mc_height'] * $product['mc_depth'] / 1000000;
                     $cbm += $cartonsEntry * $volume;
                     $weight += $cartonsEntry * $product['mc_weight'];
                     $price += $purchaseOrderEntry['quantity'] * $purchaseOrderEntry['price'];
                     $cartons += $cartonsEntry;
                     $quantity += $purchaseOrderEntry['quantity'];
                     $entries[$j]['id_product'] = $product['id_product'];
                     $entries[$j]['status'] = $this->getPurchaseOrderEntryStatus($purchaseOrderEntry['status']);
                     $entries[$j]['important'] = $product['important'];
                     $entries[$j]['item_code'] = $product['item_code'];
                     $entries[$j]['product'] = $product['item_name'];
                     $entries[$j]['price'] = $purchaseOrderEntry['price'];
                     $entries[$j]['amount'] = $purchaseOrderEntry['quantity'] * $purchaseOrderEntry['price'];
                     $entries[$j]['cartons'] = $cartonsEntry;
                     $entries[$j]['quantity'] = $purchaseOrderEntry['quantity'];
                     $entries[$j]['weight'] = $product['mc_weight'] * $cartonsEntry;
                     $entries[$j]['volume'] = number_format($volume * $cartonsEntry, 2);
                     $entries[$j]['default_shipping'] = FreightTypeQuery::create()->findByPK($product['default_freight_fare'])->getName();
                     if (!empty($product['import_permit'])) {
                         $importPermit = FileQuery::create()->findByPK($product['import_permit']);
                         if ($importPermit) {
                             $entries[$j]['import_permit'] = true;
                         } else {
                             $entries[$j]['import_permit'] = false;
                         }
                     } else {
                         $entries[$j]['import_permit'] = false;
                     }
                     $entries[$j]['row_status'] = 'success';
                     $purchaseOrders[$i]['row_status'] = 'success';
                     if (!$entries[$j]['import_permit']) {
                         $entries[$j]['row_status'] = 'error';
                         $purchaseOrders[$i]['row_status'] = 'error';
                         $entries[$j]['label'] = $this->i18n->_('This product, does not have an Import Clearance Document.');
                         $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order has entries without Import Clearance.');
                     } else {
                         if (!$purchaseOrders[$i]['commercial_invoice']) {
                             $purchaseOrders[$i]['row_status'] = 'error';
                             $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order, does not have a Commercial Invoice Document.');
                         } else {
                             if (!$purchaseOrders[$i]['packing_list']) {
                                 $purchaseOrders[$i]['row_status'] = 'error';
                                 $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order, does not have a Packing List Document.');
                             } else {
                                 if ($product['important']) {
                                     $entries[$j]['row_status'] = 'warning';
                                     $purchaseOrders[$i]['row_status'] = 'warning';
                                     $entries[$j]['label'] = $this->i18n->_('This product is small and valuable.');
                                     $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order has small and valuable stuff.');
                                 } else {
                                     $entries[$j]['row_status'] = 'success';
                                     $purchaseOrders[$i]['row_status'] = 'success';
                                 }
                             }
                         }
                     }
                     $j++;
                 }
                 //Checks if the entry has important stuff
                 if (count($valuable) == 1) {
                     $purchaseOrders[$i]['importance'] = $valuable[1];
                 } else {
                     $flag = 0;
                     $value = $valuable[1];
                     for ($j = 2; $j <= count($valuable); $j++) {
                         if ($valuable[$j] != $value) {
                             $value = 2;
                             break;
                         }
                     }
                     $purchaseOrders[$i]['importance'] = $value;
                 }
                 switch ($purchaseOrders[$i]['importance']) {
                     case '1':
                         $purchaseOrders[$i]['importance'] = $this->i18n->_('Yes');
                         break;
                     case '2':
                         $purchaseOrders[$i]['importance'] = $this->i18n->_('Mixed');
                         break;
                     default:
                         $purchaseOrders[$i]['importance'] = $this->i18n->_('No');
                 }
             } catch (Exception $e) {
                 var_dump($e->getMessage());
             }
             $purchaseOrders[$i]['id_purchase_order_folio'] = PurchaseOrderFolioQuery::create()->whereAdd(PurchaseOrderFolio::ID_PURCHASE_ORDER, $purchaseOrder['id_purchase_order'])->whereAdd(PurchaseOrderFolio::ID_FOLIO_IMPORT, $idFolioImport)->findOne()->getIdPurchaseOrderFolio();
             $cartons = 0;
             $quantity = 0;
             $weight = 0;
             $cbm = 0;
             $price = 0;
             foreach ($entries as $entry) {
                 $cartons += intval($entry['cartons']);
                 $quantity += intval($entry['quantity']);
                 $weight += $entry['weight'];
                 $cbm += $entry['volume'];
                 $price += $entry['price'] * $entry['quantity'];
             }
             $purchaseOrders[$i]['entries'] = $entries;
             $purchaseOrders[$i]['cartons'] = $cartons;
             $purchaseOrders[$i]['quantity'] = $quantity;
             $purchaseOrders[$i]['weight'] = $weight;
             $purchaseOrders[$i]['cbm'] = number_format($cbm, 2);
             $purchaseOrders[$i]['price'] = $price;
             $purchaseOrders[$i]['id_purchase_order'] = $purchaseOrder['id_purchase_order'];
             $purchaseOrders[$i]['courtyard_arrival_date'] = $purchaseOrder['courtyard_arrival_date'];
             $i++;
         }
         return $purchaseOrders;
     } else {
         return null;
     }
 }