Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.77 KB | None | 0 0
  1. public function calculateData(): array
  2.     {
  3.         //Listenpreis
  4.         self::calculateAddPercentage(self::$buying_price, self::$discount, 'discount');
  5.         //Bareinkaufspreis
  6.         self::calculateSubPercentage($this->calculated_cash_discount, self::$procurement_cost, 'procurement_cost');
  7.         //Zieleinkaufspreis
  8.         self::calculateAddPercentage($this->calculated_discount, self::$cash_discount, 'cash_discount');
  9.         //Bezugs- oder Einstandpreis
  10.         self::calculateSubPercentage($this->calculated_procurement_cost, self::$cost, 'cost');
  11.         //Selbstkostenpreis
  12.         self::calculateSubPercentage($this->calculated_cost, self::$profit, 'profit');
  13.         //Barverkaufspreis
  14.         self::calculateSubPercentage($this->calculated_profit, self::$customer_card_discount, 'customer_card_discount');
  15.         //Zielverkaufspreis
  16.         self::calculateSubPercentage($this->calculated_customer_card_discount, self::$discount_two, 'discount_two');
  17.         //Listenverkaufspreis
  18.         self::calculateSubPercentage($this->calculated_value_added_tax, self::$calculated_loss, 'calculated_loss');
  19.         //Mehrwersteuer
  20.         self::calculateSubPercentage($this->calculated_discount_two, self::$value_added_tax, 'value_added_tax');
  21.  
  22.         // difference as number between selling price and result
  23.         $difference_displayed  = $this->calculated_calculated_loss - self::$selling_price;
  24.         $difference_calculated = $this->calculated_calculated_loss - self::$selling_price;
  25.  
  26.         $difference_displayed_plus  = strpos($difference_displayed, '-') ? '+' : '-';
  27.         $difference_calculated_plus = strpos($difference_calculated, '-') ? '+' : '-';
  28.  
  29.         $plus_minus = '';
  30.         switch(true)
  31.         {
  32.             case $difference_displayed_plus == '+':
  33.             case $difference_calculated_plus == '+':
  34.                 $plus_minus = '+';
  35.             break;
  36.             case $difference_displayed_plus == '-':
  37.             case $difference_calculated_plus == '-':
  38.                 $plus_minus            = '-';
  39.                 $difference_displayed  = str_replace('-', '', $difference_displayed);
  40.                 $difference_calculated = str_replace('-', '', $difference_calculated);
  41.         }
  42.  
  43.         $difference_displayed  = $plus_minus.self::numberFormat($difference_displayed, 'de_DE', 2);
  44.         $difference_calculated = $plus_minus.self::numberFormat($difference_calculated, 'de_DE', 4);
  45.  
  46.         // percentage difference between selling price and buying price displayed ( 2 digits)
  47.         $lost_percentage_displayed = ($this->displayed_calculated_loss - self::$selling_price) / $this->displayed_calculated_loss * 100;
  48.  
  49.         // percentage difference between selling price and buying price calculated (4 digits)
  50.         $lost_percentage_calculated = ($this->calculated_calculated_loss - self::$selling_price) / $this->calculated_calculated_loss * 100;
  51.  
  52.         $lost_percentage_displayed  = round($lost_percentage_displayed, self::$displayed_digits);
  53.         $lost_percentage_calculated = round($lost_percentage_calculated, self::$calculated_digits);
  54.  
  55.         $lost_percentage_displayed  = str_replace('--', '-', $plus_minus.self::dotToComma($lost_percentage_displayed)).'%';
  56.         $lost_percentage_calculated = str_replace('--', '-', $plus_minus.self::dotToComma($lost_percentage_calculated)).'%';
  57.  
  58.         $factor_displayed  = round($this->displayed_calculated_loss / self::$buying_price, 2);
  59.         $factor_calculated = round($this->calculated_calculated_loss / self::$buying_price, 4);
  60.         // get factor for the calculation
  61.         $factor_currency_displayed  = self::dotToComma($factor_displayed);
  62.         $factor_currency_calculated = self::dotToComma($factor_calculated);
  63.  
  64.         $result = [
  65.             'buying_price'              => self::numberFormat(self::$buying_price, 'de_DE', 2),
  66.             'selling_price'             => self::numberFormat(self::$selling_price, 'de_DE', 2),
  67.             'currency'                  => self::$currency,
  68.             'displayed'                 => [
  69.                 'discount'               => $this->displayed_discount,
  70.                 'cash_discount'          => $this->displayed_cash_discount,
  71.                 'procurement_cost'       => $this->displayed_procurement_cost,
  72.                 'cost'                   => $this->displayed_cost,
  73.                 'profit'                 => $this->displayed_profit,
  74.                 'customer_card_discount' => $this->displayed_customer_card_discount,
  75.                 'discount_two'           => $this->displayed_discount_two,
  76.                 'value_added_tax'        => $this->displayed_value_added_tax,
  77.                 'calculated_loss'        => $this->displayed_calculated_loss,
  78.                 'final_value'            => $this->displayed_calculated_loss,
  79.                 'lost_percentage'        => $lost_percentage_displayed,
  80.                 'lost_value'             => $difference_displayed,
  81.                 'factor'                 => $factor_displayed,
  82.                 'positive_negative'      => ($plus_minus == '+' ? 'positive' : 'negative')
  83.             ],
  84.             'displayed_currency'        => [
  85.                 'discount'               => $this->displayed_currency_discount,
  86.                 'cash_discount'          => $this->displayed_currency_cash_discount,
  87.                 'procurement_cost'       => $this->displayed_currency_procurement_cost,
  88.                 'cost'                   => $this->displayed_currency_cost,
  89.                 'profit'                 => $this->displayed_currency_profit,
  90.                 'customer_card_discount' => $this->displayed_currency_customer_card_discount,
  91.                 'discount_two'           => $this->displayed_currency_discount_two,
  92.                 'value_added_tax'        => $this->displayed_currency_value_added_tax,
  93.                 'calculated_loss'        => $this->displayed_currency_calculated_loss,
  94.                 'final_value'            => $this->displayed_currency_calculated_loss,
  95.                 'lost_percentage'        => $lost_percentage_displayed,
  96.                 'lost_value'             => $difference_displayed,
  97.                 'factor'                 => $factor_currency_displayed,
  98.                 'positive_negative'      => ($plus_minus == '+' ? 'positive' : 'negative')
  99.  
  100.             ],
  101.             'calculated'                => [
  102.                 'discount'               => $this->calculated_discount,
  103.                 'cash_discount'          => $this->calculated_cash_discount,
  104.                 'procurement_cost'       => $this->calculated_procurement_cost,
  105.                 'cost'                   => $this->calculated_cost,
  106.                 'profit'                 => $this->calculated_profit,
  107.                 'customer_card_discount' => $this->calculated_customer_card_discount,
  108.                 'discount_two'           => $this->calculated_discount_two,
  109.                 'value_added_tax'        => $this->calculated_value_added_tax,
  110.                 'calculated_loss'        => $this->calculated_calculated_loss,
  111.                 'final_value'            => $this->calculated_calculated_loss,
  112.                 'lost_percentage'        => $lost_percentage_calculated,
  113.                 'lost_value'             => $difference_calculated,
  114.                 'factor'                 => $factor_calculated,
  115.                 'positive_negative'      => ($plus_minus == '+' ? 'positive' : 'negative')
  116.  
  117.             ],
  118.             'calculated_currency'       => [
  119.                 'discount'               => $this->calculated_currency_discount,
  120.                 'cash_discount'          => $this->calculated_currency_cash_discount,
  121.                 'procurement_cost'       => $this->calculated_currency_procurement_cost,
  122.                 'cost'                   => $this->calculated_currency_cost,
  123.                 'profit'                 => $this->calculated_currency_profit,
  124.                 'customer_card_discount' => $this->calculated_currency_customer_card_discount,
  125.                 'discount_two'           => $this->calculated_currency_discount_two,
  126.                 'value_added_tax'        => $this->calculated_currency_value_added_tax,
  127.                 'calculated_loss'        => $this->calculated_currency_calculated_loss,
  128.                 'final_value'            => $this->calculated_currency_calculated_loss,
  129.                 'lost_percentage'        => $lost_percentage_calculated,
  130.                 'lost_value'             => $difference_calculated,
  131.                 'factor'                 => $factor_currency_calculated,
  132.                 'positive_negative'      => ($plus_minus == '+' ? 'positive' : 'negative')
  133.  
  134.             ],
  135.             'calculated_base'           => [
  136.                 'discount'               => self::$discount,
  137.                 'cash_discount'          => self::$cash_discount,
  138.                 'procurement_cost'       => self::$procurement_cost,
  139.                 'cost'                   => self::$cost,
  140.                 'profit'                 => self::$profit,
  141.                 'customer_card_discount' => self::$customer_card_discount,
  142.                 'discount_two'           => self::$discount_two,
  143.                 'value_added_tax'        => self::$value_added_tax,
  144.                 'calculated_loss'        => self::$calculated_loss,
  145.             ],
  146.             'calculated_base_displayed' => [
  147.                 'discount'               => self::dotToComma(self::$discount),
  148.                 'cash_discount'          => self::dotToComma(self::$cash_discount),
  149.                 'procurement_cost'       => self::dotToComma(self::$procurement_cost),
  150.                 'cost'                   => self::dotToComma(self::$cost),
  151.                 'profit'                 => self::dotToComma(self::$profit),
  152.                 'customer_card_discount' => self::dotToComma(self::$customer_card_discount),
  153.                 'discount_two'           => self::dotToComma(self::$discount_two),
  154.                 'value_added_tax'        => self::dotToComma(self::$value_added_tax),
  155.                 'calculated_loss'        => self::dotToComma(self::$calculated_loss),
  156.             ]
  157.         ];
  158.  
  159.         $_SESSION['calculated_data'] = $result;
  160.  
  161.         return $result;
  162.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement