public function formAction()
 {
     $id = $this->getRequest()->getParam('id');
     try {
         if (empty($id)) {
             throw new ProductAntidumpingDutyException($this->i18n->_('The product id was not defined'));
         }
         $product = ProductQuery::create()->findByPK($id);
         if (!$product instanceof Product) {
             throw new ProductAntidumpingDutyException($this->i18n->_('The Product was not found'));
         }
         $productAntidumpingDuty = ProductAntidumpingDutyQuery::create()->findByParentKey($product->getKeyMother());
         if (!$productAntidumpingDuty instanceof ProductAntidumpingDuty) {
             $productAntidumpingDuty = new ProductAntidumpingDuty();
         }
         $productAntidumpingDuty->setParentKey($product->getKeyMother());
         $comboHeader = $this->i18n->_('Select One');
         $header = array('' => $comboHeader);
         $this->view->currencies = CurrencyQuery::create()->find()->toCombo($comboHeader);
         $this->view->types = $header + array_flip(ProductAntidumpingDuty::$Type);
         $this->view->rules = $header + array_flip(ProductAntidumpingDuty::$Rule);
         $this->view->contentTitle = $this->i18n->_('Compensatory Fee');
         $this->view->productAntidumpingDuty = $productAntidumpingDuty;
     } catch (ProductAntidumpingDutyException $e) {
         $this->setFlash('error', $e->getMessage());
         $this->_redirect('product/list');
     }
 }
Пример #2
0
 /**
  *
  * @param int $id folio import id
  * @return array
  */
 private function calculateFrontpage($id, CalculateAntidumpingDutyManager $antidumpingDutyManager)
 {
     $folioImport = FolioImportQuery::create()->findByPK($id);
     $antidumpingDutyValues = $antidumpingDutyManager->getAntidumpingDutyValues();
     $productAntidumpingDuties = $antidumpingDutyManager->getProductAntidumpingDuties();
     $products = $antidumpingDutyManager->getProducts();
     $booking = BookingQuery::create()->whereAdd(Booking::ID_FOLIO_IMPORT, $id)->findOne();
     $forwarder = ForwarderQuery::create()->findByPK($folioImport->getIdForwarder())->getName();
     $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $id)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status['NewService'], PurchaseOrderQuery::NOT_EQUAL)->find();
     $array = array();
     $purchaseOrderEntryQuery = new PurchaseOrderEntryCollection($array);
     while ($purchaseOrder = $purchaseOrderQuery->read()) {
         $purchaseOrderEntries = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->find();
         while ($purchaseOrderEntry = $purchaseOrderEntries->read()) {
             $purchaseOrderEntryQuery->append($purchaseOrderEntry);
         }
     }
     $entries = array();
     $totalPieces = $this->getPurchaseOrdersTotalPieces($id);
     $totalCartons = $this->getPurchaseOrdersTotalCartons($id);
     $totalLoadCost = $this->getPurchaseOrdersTotalLoadCost($id);
     $totalWeight = $this->getPurchaseOrdersTotalWeight($id);
     $totalVolume = $this->getPurchaseOrdersTotalVolume($id);
     $totalTariffMXP = 0;
     $totalCIFValue = 0;
     $i = 0;
     while ($purchaseOrderEntry = $purchaseOrderEntryQuery->read()) {
         $product = $products->getByPK($purchaseOrderEntry->getIdProduct());
         $productAntidumpingDuty = $productAntidumpingDuties->getByParentKey($product->getKeyMother());
         if (!$productAntidumpingDuty instanceof ProductAntidumpingDuty) {
             $productAntidumpingDuty = new ProductAntidumpingDuty();
         }
         $antidumpingDutyValue = $antidumpingDutyValues->getByEntryLine($purchaseOrderEntry->getIdPurchaseOrder(), $purchaseOrderEntry->getLine());
         $entry = $purchaseOrderEntry->toArray();
         $purchaseOrder = $purchaseOrderQuery->getByPK($purchaseOrderEntry->getIdPurchaseOrder());
         $idCurrency = $purchaseOrder->getIdCurrency();
         $supplier = SapSupplierQuery::create()->findByPK($purchaseOrder->getIdSupplier());
         $product = ProductQuery::create()->findByPK($purchaseOrderEntry->getIdProduct());
         $entry['doc_num'] = PurchaseOrderQuery::create()->findByPK($purchaseOrderEntry->getIdPurchaseOrder())->getSapDocumentNumber();
         $entry['supplier'] = $supplier->getName();
         $entry['item_code'] = $product->getItemCode();
         $entry['description'] = $product->getItemName();
         $entry['invoice_number'] = PurchaseOrderQuery::create()->findByPK($purchaseOrderEntry->getIdPurchaseOrder())->getInvoiceNumber();
         $entry['amount_usd'] = $this->calculateAmountInUSD($purchaseOrderEntry->getAmount(), $folioImport->getExchangeDollarToPeso(), $folioImport->getExchangeEuroToDollar(), $purchaseOrder->getIdCurrency());
         $entry['amount_mxp'] = $this->calculateAmountInMXP($entry['amount_usd'], $folioImport->getExchangeDollarToPeso());
         switch ($idCurrency) {
             case 'USD':
                 $entry['fob_usd'] = $this->calculateFOBUSD($entry['price'], $folioImport->getExchangeDollarToPeso());
                 break;
             case 'EUR':
                 $entry['fob_usd'] = $this->calculateFOBUSD($entry['price'], $folioImport->getExchangeEuroToDollar());
                 break;
         }
         $entry['fob_mxp'] = $entry['price'];
         $quantity = floatval($purchaseOrderEntry->getQuantity());
         $weight = $this->getPurchaseOrderEntryWeight($purchaseOrderEntry);
         $entry['entry_weight'] = $this->getPurchaseOrderEntryWeight($purchaseOrderEntry);
         $entry['weight_by_piece'] = $this->calculateWeightByPiece($weight, $quantity);
         $entry['weighted_factor_mxp'] = $this->calculateWeightedFactorMXP($entry['amount_usd'], $totalLoadCost);
         $entry['weighted_factor_kg'] = $this->calculateWeightedFactorKg($entry['entry_weight'], $totalWeight);
         $entry['increasable_freight_mxp'] = $this->calculateIncreasableFreightMXP($entry['weighted_factor_mxp'], $booking->getIncreasableFreight(), $folioImport->getExchangeDollarToPeso());
         $entry['increasable_insurance_mxp'] = $this->calculateIncreasableInsuranceMXP($entry['weighted_factor_mxp'], $booking->getIncreasableInsurance(), $folioImport->getExchangeDollarToPeso());
         $entry['not_increasable_freight_mxp'] = $this->calculateIncreasableInsuranceMXP($entry['weighted_factor_mxp'], $booking->getTotalNotIncreasable(), $folioImport->getExchangeDollarToPeso());
         $entry['md'] = CurrencyQuery::create()->findByPK($purchaseOrder->getIdCurrency())->getCurrCode();
         $customsValue = $entry['increasable_insurance_mxp'] + $entry['increasable_freight_mxp'] + $entry['amount_mxp'];
         $customsTariffCode = $this->getPurchaseOrderEntryTariffCode($purchaseOrderEntry);
         $tariffMXP = $customsValue * $customsTariffCode->getPercent() / 100;
         $CIFValue = $customsValue + $tariffMXP + $entry['not_increasable_freight_mxp'];
         $entry['tariff_percent'] = $customsTariffCode->getPercent();
         $entry['tariff'] = $customsTariffCode->getName();
         $entry['weighted_factor_mxp'] = $entry['weighted_factor_mxp'] * 100;
         if ($productAntidumpingDuty->getRule() == ProductAntidumpingDuty::$Rule['Piece'] && $antidumpingDutyValue->getValue() != 0) {
             $entry['cc'] = $productAntidumpingDuty->getValue() . 'xPza';
         } else {
             $entry['cc'] = '-';
         }
         if ($antidumpingDutyValue->getValue() != 0) {
             $entry['cc_value'] = $antidumpingDutyValue->getValue() . $productAntidumpingDuty->getCurrency();
         } else {
             $entry['cc_value'] = 0;
         }
         $entry['volume'] = $this->getPurchaseOrderEntryVolume($purchaseOrderEntry);
         $volumeFactor = $entry['volume'] / $totalVolume * 100;
         $entry['volume_factor'] = $volumeFactor;
         $entry['difference'] = round($volumeFactor, 4) - round($entry['weighted_factor_mxp'], 4);
         $entry['customs_value_mxp'] = $customsValue;
         $entry['tariff_mxp'] = $tariffMXP;
         $entry['cif_value'] = $CIFValue;
         $entries[] = $entry;
         $totalCIFValue += $CIFValue;
         $totalTariffMXP += $tariffMXP;
     }
     return $entries;
 }
 /**
  * 
  * Calcula la cuota compensatoria por pieza
  * @param ProductAntidumpingDuty $antidumpingDuty
  * @param PurchaseOrderEntry $purchaseOrderEntry
  * @return number
  */
 private function calculateAntidumpingDutyValueByPiece(ProductAntidumpingDuty $antidumpingDuty, PurchaseOrderEntry $purchaseOrderEntry)
 {
     $mxValue = 0;
     switch ($antidumpingDuty->getCurrency()) {
         case Currency::$IdCurrencies['Euro']:
             $mxValue = $antidumpingDuty->getValue() / $this->getEURtoUSD() * $this->getUSDToMXN();
             break;
         case Currency::$IdCurrencies['Dollar']:
             $mxValue = $antidumpingDuty->getValue() * $this->getUSDToMXN();
             break;
         default:
             $mxValue = $antidumpingDuty->getValue();
     }
     return $mxValue * $purchaseOrderEntry->getQuantity();
 }