/** * * @param string $idProduct * @return array */ private function getLandedCost($idProduct, Application\Model\Bean\ProductPriceList $productPriceList, $productPrice = null) { $product = ProductQuery::create()->findByPK($idProduct); if (FreightFareQuery::create()->whereAdd(FreightFare::ID_FREIGHT_FARE, $product->getDefaultFreightFare())->count()) { $freightFare = FreightFareQuery::create()->findByPK($product->getDefaultFreightFare()); $freightType = FreightTypeQuery::create()->findByPK($freightFare->getIdFreightType()); } else { $result['message'] = $this->i18n->_('You must edit the Freight Fare.'); $result['result'] = false; return $result; } if (CustomsTariffCodeQuery::create()->whereAdd(CustomsTariffCode::CODE, $product->getIdCustomsTariffCode())->count()) { $customsTariffCode = CustomsTariffCodeQuery::create()->findByPK($product->getIdCustomsTariffCode()); } else { $result['message'] = $this->i18n->_('You must edit the Customs Code.'); $result['result'] = false; return $result; } $unit = $freightFare->getUnit(); $unitCost = $freightFare->getUnitCost(); $maxLoad = $freightType->getMaxLoad(); $cbmByCarton = $product->getCbmByCarton(); if (!$cbmByCarton) { $result['message'] = $this->i18n->_('You must edit the Cartons.'); $result['result'] = false; return $result; } $containerCartons = ceil($maxLoad / $cbmByCarton); $containerWeight = $containerCartons * $product->getMcWeight(); $containerTotalProducts = $containerCartons * $product->getMcParts(); if (!$containerTotalProducts) { $result['message'] = $this->i18n->_('You must edit Master Carton Parts.'); $result['result'] = false; return $result; } if (!$productPrice) { if (!$product->getCost()) { $result['message'] = $this->i18n->_('You must edit the Price.'); $result['result'] = false; return $result; } $productCost = $productPriceList->getProductPriceInUsd() * $containerTotalProducts; } else { $productCost = $productPrice * $containerTotalProducts; } switch ($unit) { case FreightFare::$Units['CBM']: $freightCost = $unitCost * $maxLoad; break; case FreightFare::$Units['Container']: $freightCost = $unitCost; break; case FreightFare::$Units['KG']: $freightCost = $unitCost * $containerWeight; break; } $productCostAndFreightCost = $productCost + $freightCost; $igi = $productCostAndFreightCost * $customsTariffCode->getPercent() / 100; $dta = $productCostAndFreightCost * 0.8 / 100; $iva = ($productCostAndFreightCost + $dta + $igi) * 0.16; $totalCostProduct = $productCostAndFreightCost + $igi + $dta + $iva; $landedCost = $totalCostProduct / $containerTotalProducts; $result['message'] = $this->i18n->_('yep! everything goes well'); $result['result'] = strval(round($landedCost, 2)); return $result; }