src/bekanntmacher/boxmaker-bundle/src/Module/TypeDebug.php line 110

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright Bekanntmacher
  4.  *
  5.  * @author Simon Wohler <s.wohler@bekanntmacher.ch>
  6.  * @license    commercial
  7.  */
  8. namespace Bekanntmacher\BoxmakerBundle\Module;
  9. use Bekanntmacher\BoxmakerBundle\Classes\Config;
  10. use Bekanntmacher\BoxmakerBundle\Classes\UserInput;
  11. use Bekanntmacher\BoxmakerBundle\Model\FarbeModel;
  12. use Bekanntmacher\BoxmakerBundle\Model\TypeModel;
  13. use Bekanntmacher\BoxmakerBundle\Model\ConfigModel;
  14. use Bekanntmacher\BoxmakerBundle\Model\WelleModel;
  15. use Bekanntmacher\BoxmakerBundle\Calculation\PriceCalculator;
  16. use Bekanntmacher\BoxmakerBundle\Calculation\Margin;
  17. /**
  18.  * Boxmaker Typelist
  19.  */
  20. class TypeDebug extends TypeUtil
  21. {
  22.     /**
  23.      * @var string Template
  24.      */
  25.     protected $strTemplate 'mod_boxmaker_typedebug';
  26.     protected $objType null;
  27.     protected $objConfig null;
  28.     protected $objUserInput null;
  29.     /**
  30.      * Display a wildcard in the back end
  31.      * @return string
  32.      */
  33.     public function generate()
  34.     {
  35.         // Display a wildcard in the back end
  36.         if (TL_MODE === 'BE')
  37.         {
  38.             $template = new \BackendTemplate('be_wildcard');
  39.             $template->wildcard '### BOXMAKER TYPE DETAIL ###';
  40.             $template->title $this->name;
  41.             $template->id $this->id;
  42.             $template->link $this->name;
  43.             $template->href 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' $this->id;
  44.         }
  45.         return parent::generate();
  46.     }
  47.     /**
  48.      * Generate the module
  49.      */
  50.     protected function compile()
  51.     {
  52.         // Type
  53.         $objTypeModel TypeModel::findByPk((int) \Input::get('type'), array('eager' => true));
  54.         if ($objTypeModel === null)
  55.         {
  56.             global $objPage;
  57.             $objHandler = new $GLOBALS['TL_PTY']['error_404']();
  58.             $objHandler->generate($objPage->id);
  59.         }
  60.         // Type and type_config
  61.         $arrType $this->compileTypeData($objTypeModel);
  62.         $this->objType = new Type($arrType);
  63.         $this->objType->addTypeConfig($objTypeModel->getRelated('type_config_set')->row());
  64.         $this->Template->type $this->objType->getAll();
  65.         // Boxmaker Konfiguration
  66.         $this->objConfig = new Config(ConfigModel::findByPk($this->boxmaker_config)->row());
  67.         // User Input
  68.         $this->objUserInput = new UserInput($this->getUserInput());
  69.         $this->objUserInput->set('farbe_title'FarbeModel::findByPk($this->objUserInput->farbe)->selecttitle);
  70.         $this->Template->userInput $this->objUserInput->getAll();
  71.         // Welle
  72.         $objWelle WelleModel::findByPk(\Input::get('welle'));
  73.         $this->Template->welle = ($objWelle !== null) ? $objWelle->title WelleModel::findByPk($this->objType->type_standardwelle)->title;
  74.         // Farbe
  75.         $objFarbe FarbeModel::findByPk(\Input::get('wellenfarbe'));
  76.         $this->Template->farbe = ($objFarbe !== null) ? $objFarbe->title FarbeModel::findByPk($this->objType->type_standardfarbe)->title;
  77.         // Druck
  78.         $this->Template->druck $this->getDruckLabel();
  79.         // Optionen
  80.         $this->Template->optionen = array();
  81.         // Preise
  82.         $this->Template->prices $this->addDebugPrices();
  83.         // Debug
  84.        //  $this->Template->debug = print_r($this->addDebugPrices(),true);
  85.     }
  86.     private function getDruckLabel()
  87.     {
  88.         $druckverfahren str_replace(\Input::get('druckfarben'),'',\Input::get('druckverfahren'));
  89.         $strDruck  = ($druckverfahren == '') ? 'unbedruckt' ucfirst($druckverfahren);
  90.         $strDruck .= ($druckverfahren != '') ? ',&nbsp;' str_replace('_','', \Input::get('druckfarben')) : '';
  91.         $strDruck .= ($druckverfahren != '') ? ',&nbsp;' .\Input::get('seite') : '';
  92.         return $strDruck;
  93.     }
  94.     private function addDebugPrices()
  95.     {
  96.         // Marge
  97.         $objMargin = new Margin($this->objType$this->objUserInput);
  98.         $grundmarge_pro_stk $objMargin->getBaseMarginStk();
  99.         // Preise berechnen
  100.         $arrPricesTotal = array();
  101.         $objCalc        = new PriceCalculator($this->objType$this->objConfig$this->objUserInput);
  102.         $arrPrices      $objCalc->getAll();
  103.         $material       $objCalc->getMaterialPrice($objCalc->getCheapestProductionMethod(), \Input::get('welle'), \Input::get('wellenfarbe'));
  104.         $produktion     $objCalc->getProduktionPrice(); // stanzen + kleben
  105.         $drucken $objCalc->getDruckPrice(str_replace('_','', \Input::get('druckfarben')),\Input::get('druckverfahren'));
  106.         if(\Input::get('seite') == '2s')
  107.         {
  108.             $drucken $drucken 2;
  109.         }
  110.         // optionen
  111.         $options 0;
  112.         $arrO $this->generateOptionsTable();
  113.         $arrOptions = array();
  114.         foreach ($this->objType->type_options as $id)
  115.         {
  116.             if((int)(\Input::get('o_'.$id) > 0))
  117.             {
  118.                 $options $options $arrO['array'][$id]['price'];
  119.                 $arrOptions[] = $arrO[$id] = array(
  120.                     'title' => $arrO['array'][$id]['title'],
  121.                     'price' => $arrO['array'][$id]['price']
  122.                 );
  123.             }
  124.         }
  125.         $this->Template->options $arrOptions;
  126.         $arrPricesTotal['lieferant']['total'] = $this->getAmount($material $produktion);
  127.         $arrPricesTotal['lieferant']['material'] = $this->getAmount($material);
  128.         $arrPricesTotal['lieferant']['produktion'] = $this->getAmount($produktion);
  129.         $arrPricesTotal['lieferant']['stanzen'] = $this->getAmount($objCalc->getStanzenPrice());
  130.         $arrPricesTotal['lieferant']['kleben'] = $this->getAmount($objCalc->getKlebenPrice());
  131.         $arrPricesTotal['lieferant']['drucken'] = $this->getAmount($drucken);
  132.         // Totalpreise
  133.         $ep         $material $produktion;
  134.         $drucken    0;
  135.         $p          0;
  136.         if(\Input::get('druckverfahren') != 'blank')
  137.         {
  138.             $drucken $objCalc->getDruckPrice(str_replace('_''', \Input::get('druckfarben')), \Input::get('druckverfahren'));
  139.         }
  140.         if(\Input::get('druckverfahren') != '')
  141.         {
  142.             $ep_stk $ep;
  143.             $p $ep $grundmarge_pro_stk $objMargin->getDynamicMarginStk($ep);
  144.             $m $grundmarge_pro_stk $objMargin->getDynamicMarginStk($ep);
  145.             if(\Input::get('seite') == '1s')
  146.             {
  147.                 $ep_stk $ep $drucken;
  148.                 $p $ep $drucken $grundmarge_pro_stk $objMargin->getDynamicMarginStk($ep $drucken);
  149.                 $m $grundmarge_pro_stk $objMargin->getDynamicMarginStk($ep $drucken);
  150.             }
  151.             elseif(\Input::get('seite') == '2s')
  152.             {
  153.                 $ep_stk $ep + ($drucken);
  154.                 $p $ep + ($drucken) + $grundmarge_pro_stk $objMargin->getDynamicMarginStk($ep + ($drucken));
  155.                 $m $grundmarge_pro_stk $objMargin->getDynamicMarginStk($ep + ($drucken));
  156.             }
  157.         }
  158.         //$arrPricesTotal['debug3'] = print_r($this->objType->getAll(),true);
  159.         //$arrPricesTotal['debug2'] = $material;
  160.         //$arrPricesTotal['debug'] = print_r($objCalc->getAll(),true);
  161.         $arrPricesTotal['ep_stk'] = $this->getAmount($ep_stk);
  162.         $arrPricesTotal['ep_total'] = $this->getAmount($this->getAmount($ep_stk) * \Input::get('stk'));
  163.         $arrPricesTotal['total']['stk'] = $this->getAmount($p);
  164.         $arrPricesTotal['total']['total'] = $this->getAmount($this->getAmount($p) * \Input::get('stk'));
  165.         $arrPricesTotal['total']['total_options'] = $this->getAmount$options $arrPricesTotal['total']['total']);
  166.         // Spezifikationen
  167.         $this->Template->method $objCalc->getCheapestProductionMethod();
  168.         $this->Template->grundmarge $this->getAmount($grundmarge_pro_stk * \Input::get('stk'));
  169.         $this->Template->margeInProzent $objMargin->getMarginPercent();
  170.         $this->Template->margeTotal number_format(round($m * \Input::get('stk'),2),2);
  171.         // Produktion
  172.         foreach($GLOBALS['BOXMAKER']['productionMethods'] as $method)
  173.         {
  174.             $material $arrPrices['material'][$method][\Input::get('welle')]['farbe_' . \Input::get('wellenfarbe')];
  175.             $arrPricesTotal['prduktion'][$method] = array
  176.             (
  177.                 'total'      => $this->getAmount($material $objCalc->getStanzenPrice($method) + $objCalc->getKlebenPrice($method)),
  178.                 'material'   => $this->getAmount($material),
  179.                 'produktion' => $this->getAmount($objCalc->getProduktionPrice($method)),
  180.                 'stanzen'    => $this->getAmount($objCalc->getStanzenPrice($method)),
  181.                 'kleben'     => $this->getAmount($objCalc->getKlebenPrice($method))
  182.             );
  183.         }
  184.         // Druck
  185.         foreach($GLOBALS['BOXMAKER']['printingMethods'] as $method)
  186.         {
  187.             if ($method == 'blank')
  188.             {
  189.                 continue;
  190.             }
  191.             $arr explode('_'$method);
  192.             $arrPricesTotal['druck'][ucfirst($method)] = $this->getAmount($objCalc->getDruckPrice($arr[1], $method));
  193.         }
  194.         return $arrPricesTotal;
  195.     }
  196. }