src/bekanntmacher/boxmaker-bundle/src/Module/TypeUtil.php line 175

Open in your IDE?
  1. <?php
  2. /**
  3.  * Boxmaker extension for Contao Open Source CMS
  4.  *
  5.  * Copyright (C) 2013-2014 bekanntmacher
  6.  *
  7.  * @author     Yanick Witschi <yanick.witschi@terminal42.ch>
  8.  * @license    commercial
  9.  */
  10. namespace Bekanntmacher\BoxmakerBundle\Module;
  11. use Bekanntmacher\BoxmakerBundle\Model\TypeModel;
  12. use Bekanntmacher\BoxmakerBundle\Model\FarbeModel;
  13. use Bekanntmacher\BoxmakerBundle\Model\WelleModel;
  14. use Bekanntmacher\BoxmakerBundle\Model\TypeOptionModel;
  15. use Bekanntmacher\BoxmakerBundle\Calculation\PriceCalculator;
  16. use Bekanntmacher\BoxmakerBundle\Calculation\OptionCalculator;
  17. use Bekanntmacher\BoxmakerBundle\Calculation\Margin;
  18. use Haste\Util\Url;
  19. abstract class TypeUtil extends \Module
  20. {
  21.     // ok Dem Modell Preise adden
  22.     public function addTypePrices()
  23.     {
  24.         // Marge
  25.         $objMargin = new Margin($this->objType$this->objUserInput);
  26.         $grundmarge_pro_stk $objMargin->getBaseMarginStk();
  27.         // Preise berechnen
  28.         $arrPricesTotal = array();
  29.         $objCalc        = new PriceCalculator($this->objType$this->objConfig$this->objUserInput);
  30.         $arrPrices      $objCalc->getAll();
  31.         $arrMaterial    $arrPrices['material'];
  32.         // tiefster einkaufspreis material + stanzen + kleben berechen
  33.         foreach ($arrPrices['material']['p'] as $idWelle => $arrFarbe)
  34.         {
  35.             foreach ($arrFarbe as $idFarbe => $priceMaterial) {
  36.                 $lowestEp null;
  37.                 foreach ($GLOBALS['BOXMAKER']['productionMethods'] as $method)
  38.                 {
  39.                     $material $arrPrices['material'][$method][$idWelle][$idFarbe];
  40.                     $stanzen $arrPrices['stanzen'][$method]['stanzen_per_stk'];
  41.                     $kleben $arrPrices['kleben'][$method]['kleben_per_stk'];
  42.                     $ep $material $stanzen $kleben;
  43.                     $arrPrices['ep'][$method][$idWelle][$idFarbe] = $ep;
  44.                     if ($lowestEp === null || $ep $lowestEp)
  45.                     {
  46.                         $lowestEp $ep;
  47.                         $arrPrices['lowestEp'][$idWelle][$idFarbe] = $ep;
  48.                         $arrPrices['lowestMethod'][$idWelle][$idFarbe] = $method;
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.         // array mit den kleinsten ep generieren
  54.         foreach($arrPrices['lowestEp'] as $welle => $arrFarben)
  55.         {
  56.             foreach ($arrFarben as $farbe_id => $ep)
  57.             {
  58.                 $f_id str_replace('farbe_',''$farbe_id);
  59.                 foreach ($GLOBALS['BOXMAKER']['printingMethods'] as $method)
  60.                 {
  61.                     // aufpreis schnellere Lieferung
  62.                     $lowestMethode $arrPrices['lowestMethod'][$welle][$farbe_id];
  63.                     $diff $arrPrices['ep']['p'][$welle][$farbe_id] - $ep;
  64.                     $arrDeliverySurcharge[$welle][$f_id][$method]['p'] = $this->getAmount($objMargin->getDynamicMarginStk($diff) + $diff);
  65.                     if($lowestMethode == 'ht' || $lowestMethode == 'ap')
  66.                     {
  67.                         $diff $arrPrices['ep']['ht'][$welle][$farbe_id] - $ep;
  68.                         $arrDeliverySurcharge[$welle][$f_id][$method]['ht'] = $this->getAmount($objMargin->getDynamicMarginStk($diff) + $diff);
  69.                     }
  70.                     if($lowestMethode == 'ap')
  71.                     {
  72.                         $diff $arrPrices['ep']['ap'][$welle][$farbe_id] - $ep;
  73.                         $arrDeliverySurcharge[$welle][$f_id][$method]['ap'] = $this->getAmount($objMargin->getDynamicMarginStk($diff) + $diff);
  74.                     }
  75.                     // preis einseitig
  76.                     $arrPricesTotal[$welle][$f_id][$method]['1s'] = $this->getAmount
  77.                     (
  78.                         $ep
  79.                         $objCalc->getDruckPrice('1f'$method)
  80.                         + $grundmarge_pro_stk
  81.                         $objMargin->getDynamicMarginStk($ep $objCalc->getDruckPrice('1f'$method))
  82.                     );
  83.                     // preis zweiseitig
  84.                     $intDruckpreis = ($objCalc->getDruckPrice('1f'$method) > 0) ? $objCalc->getDruckPrice('1f'$method) : $objCalc->getDruckPrice('4f'$method);
  85.                     $arrPricesTotal[$welle][$f_id][$method]['2s'] = $this->getAmount
  86.                     (
  87.                         $ep
  88.                         + ($intDruckpreis)
  89.                         + $grundmarge_pro_stk
  90.                         $objMargin->getDynamicMarginStk($ep + ($objCalc->getDruckPrice('1f'$method)))
  91.                     );
  92.                 }
  93.             }
  94.         }
  95.         // digitaldruckeco 2s überschreiben
  96.         foreach ($arrPricesTotal as $key => $array)
  97.         {
  98.             foreach ($array as $k => $arr)
  99.             {
  100.                 $lowest 0;
  101.                 foreach ($arr as $method => $set)
  102.                 {
  103.                     if(strpos($method,'_4f') !== false) {
  104.                         if($method != 'digitaldruckeco_4f' && ($lowest == || $set['2s'] < $lowest)) {
  105.                             $lowest $set['2s'];
  106.                         }
  107.                     }
  108.                 }
  109.                 $arrPricesTotal[$key][$k]['digitaldruckeco_4f']['2s'] = $lowest;
  110.             }
  111.         }
  112.         // return results
  113.         return array
  114.         (
  115.             'arrPriceTotal' => $arrPricesTotal,
  116.             'arrDeliverySurcharge' => $arrDeliverySurcharge,
  117.             'arrAll' => $objCalc->getAll(),
  118.             'cheapestProductionMethod' => $objCalc->getCheapestProductionMethod(),
  119.             'cheapestPrintingMethod' => $objCalc->getCheapestPrintingMethod()
  120.         );
  121.     }
  122.     // ok Bilder und PDF compilieren und als array zurückgeben
  123.     protected function compileTypeData(TypeModel $typeModel)
  124.     {
  125.         $arrReturn $typeModel->row();
  126.         // Image
  127.         $image_b = \FilesModel::findByUuid($typeModel->image_b);
  128.         $image_w = \FilesModel::findByUuid($typeModel->image_w);
  129.         $image_s = \FilesModel::findByUuid($typeModel->image_s);
  130.         $image_f = \FilesModel::findByUuid($typeModel->image_f);
  131.         // PDF
  132.         $pdf = \FilesModel::findByUuid($typeModel->pdf3d);
  133.         if ($pdf !== null)
  134.         {
  135.             if (\Input::get('pdf') && \Input::get('pdf') === $pdf->path)
  136.             {
  137.                 $file = new \File($pdf->path);
  138.                 $file->sendToBrowser();
  139.             }
  140.             $pdf Url::addQueryString('pdf=' urlencode($pdf->path));
  141.         }
  142.         $arrReturn array_merge
  143.         (
  144.             $arrReturn,
  145.             array
  146.             (
  147.                 'title'             => specialchars($typeModel->title),
  148.                 'norm'              => $typeModel->norm,
  149.                 'image'             => array
  150.                 (
  151.                     'braun'         => ($image_b === null) ?:  $image_b->path,
  152.                     'weiss'         => ($image_w === null) ?:  $image_w->path,
  153.                     'schwarz'       => ($image_s === null) ?:  $image_s->path,
  154.                     'wunschfarbe'   => ($image_f === null) ?:  $image_f->path
  155.                 ),
  156.                 'pdf3d'             => ($pdf === null) ?: $pdf,
  157.                 'href'              => ($this->jumpTo == 0) ?:  Url::addQueryString('type=' $typeModel->id$this->jumpTo),
  158.                 'type_options'       => \StringUtil::deserialize($typeModel->type_options,true),
  159.                 'ht_delivery_time'  => $typeModel->ht_delivery_time,
  160.                 'ap_delivery_time'  => $typeModel->ap_delivery_time,
  161.             )
  162.         );
  163.         return $arrReturn;
  164.     }
  165.     // ok Währung und Welleninfo
  166.     protected function addGeneralTemplateData()
  167.     {
  168.         // Währungskürzel
  169.         $this->Template->boxmaker_currency $this->objConfig->boxmaker_currency;
  170.     }
  171.     protected function getDruckLabel()
  172.     {
  173.         $druckverfahren str_replace($this->objUserInput->druckfarben,'',$this->objUserInput->druckverfahren);
  174.         $strDruck  = ($druckverfahren == '') ? 'unbedruckt' $GLOBALS['BOXMAKER']['printingMethodsLabels_short'][$druckverfahren];
  175.         $strDruck .= ($druckverfahren != '') ? ', ' str_replace(array('_1f','_4f'),array('einfarbig','mehrfarbig'), $this->objUserInput->druckfarben) : '';
  176.         $strDruck .= ($druckverfahren != '') ? ', ' str_replace(array('1s','2s'),array('einseitig','beidseitig'), $this->objUserInput->seite) : '';
  177.         return $strDruck;
  178.     }
  179.     public function getDeliveryDate($productionMethod)
  180.     {
  181.         $var $productionMethod .'_delivery_time';
  182.         return $this->objType->$var;
  183.     }
  184.     // ok Preis runden und formatieren
  185.     public function getAmount($price$convert_currency=true$number_format=true$thousands_sep=true)
  186.     {
  187.         if($convert_currency === true)
  188.         {
  189.             $price $price $this->objConfig->boxmaker_priceCalculateFactor;
  190.         }
  191.         $price round($price,2);
  192.         if($number_format === true)
  193.         {
  194.             if($thousands_sep === true)
  195.             {
  196.                 $price number_format($price,2,'.','`');
  197.             } else {
  198.                 $price number_format($price,2,'.','');
  199.             }
  200.         }
  201.         return $price;
  202.     }
  203. }