예제 #1
0
 /**
  *
  * @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;
 }
예제 #2
0
 /**
  * @return \Application\Model\Bean\ProductPriceListLog
  */
 private function newLog(ProductPriceList $productPriceList, $eventType)
 {
     $now = \Zend_Date::now();
     $log = PriceListLogFactory::createFromArray(array('id_price_list' => $productPriceList->getIdProductPriceList(), 'id_user' => $this->getUser()->getBean()->getIdUser(), 'date_log' => $now->get('yyyy-MM-dd HH:mm:ss'), 'event_type' => $eventType, 'note' => ''));
     $this->getCatalog('PriceListLogCatalog')->create($log);
     return $log;
 }