Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function calculateData(): array
- {
- //Listenpreis
- self::calculateAddPercentage(self::$buying_price, self::$discount, 'discount');
- //Bareinkaufspreis
- self::calculateSubPercentage($this->calculated_cash_discount, self::$procurement_cost, 'procurement_cost');
- //Zieleinkaufspreis
- self::calculateAddPercentage($this->calculated_discount, self::$cash_discount, 'cash_discount');
- //Bezugs- oder Einstandpreis
- self::calculateSubPercentage($this->calculated_procurement_cost, self::$cost, 'cost');
- //Selbstkostenpreis
- self::calculateSubPercentage($this->calculated_cost, self::$profit, 'profit');
- //Barverkaufspreis
- self::calculateSubPercentage($this->calculated_profit, self::$customer_card_discount, 'customer_card_discount');
- //Zielverkaufspreis
- self::calculateSubPercentage($this->calculated_customer_card_discount, self::$discount_two, 'discount_two');
- //Listenverkaufspreis
- self::calculateSubPercentage($this->calculated_value_added_tax, self::$calculated_loss, 'calculated_loss');
- //Mehrwersteuer
- self::calculateSubPercentage($this->calculated_discount_two, self::$value_added_tax, 'value_added_tax');
- // difference as number between selling price and result
- $difference_displayed = $this->calculated_calculated_loss - self::$selling_price;
- $difference_calculated = $this->calculated_calculated_loss - self::$selling_price;
- $difference_displayed_plus = strpos($difference_displayed, '-') ? '+' : '-';
- $difference_calculated_plus = strpos($difference_calculated, '-') ? '+' : '-';
- $plus_minus = '';
- switch(true)
- {
- case $difference_displayed_plus == '+':
- case $difference_calculated_plus == '+':
- $plus_minus = '+';
- break;
- case $difference_displayed_plus == '-':
- case $difference_calculated_plus == '-':
- $plus_minus = '-';
- $difference_displayed = str_replace('-', '', $difference_displayed);
- $difference_calculated = str_replace('-', '', $difference_calculated);
- }
- $difference_displayed = $plus_minus.self::numberFormat($difference_displayed, 'de_DE', 2);
- $difference_calculated = $plus_minus.self::numberFormat($difference_calculated, 'de_DE', 4);
- // percentage difference between selling price and buying price displayed ( 2 digits)
- $lost_percentage_displayed = ($this->displayed_calculated_loss - self::$selling_price) / $this->displayed_calculated_loss * 100;
- // percentage difference between selling price and buying price calculated (4 digits)
- $lost_percentage_calculated = ($this->calculated_calculated_loss - self::$selling_price) / $this->calculated_calculated_loss * 100;
- $lost_percentage_displayed = round($lost_percentage_displayed, self::$displayed_digits);
- $lost_percentage_calculated = round($lost_percentage_calculated, self::$calculated_digits);
- $lost_percentage_displayed = str_replace('--', '-', $plus_minus.self::dotToComma($lost_percentage_displayed)).'%';
- $lost_percentage_calculated = str_replace('--', '-', $plus_minus.self::dotToComma($lost_percentage_calculated)).'%';
- $factor_displayed = round($this->displayed_calculated_loss / self::$buying_price, 2);
- $factor_calculated = round($this->calculated_calculated_loss / self::$buying_price, 4);
- // get factor for the calculation
- $factor_currency_displayed = self::dotToComma($factor_displayed);
- $factor_currency_calculated = self::dotToComma($factor_calculated);
- $result = [
- 'buying_price' => self::numberFormat(self::$buying_price, 'de_DE', 2),
- 'selling_price' => self::numberFormat(self::$selling_price, 'de_DE', 2),
- 'currency' => self::$currency,
- 'displayed' => [
- 'discount' => $this->displayed_discount,
- 'cash_discount' => $this->displayed_cash_discount,
- 'procurement_cost' => $this->displayed_procurement_cost,
- 'cost' => $this->displayed_cost,
- 'profit' => $this->displayed_profit,
- 'customer_card_discount' => $this->displayed_customer_card_discount,
- 'discount_two' => $this->displayed_discount_two,
- 'value_added_tax' => $this->displayed_value_added_tax,
- 'calculated_loss' => $this->displayed_calculated_loss,
- 'final_value' => $this->displayed_calculated_loss,
- 'lost_percentage' => $lost_percentage_displayed,
- 'lost_value' => $difference_displayed,
- 'factor' => $factor_displayed,
- 'positive_negative' => ($plus_minus == '+' ? 'positive' : 'negative')
- ],
- 'displayed_currency' => [
- 'discount' => $this->displayed_currency_discount,
- 'cash_discount' => $this->displayed_currency_cash_discount,
- 'procurement_cost' => $this->displayed_currency_procurement_cost,
- 'cost' => $this->displayed_currency_cost,
- 'profit' => $this->displayed_currency_profit,
- 'customer_card_discount' => $this->displayed_currency_customer_card_discount,
- 'discount_two' => $this->displayed_currency_discount_two,
- 'value_added_tax' => $this->displayed_currency_value_added_tax,
- 'calculated_loss' => $this->displayed_currency_calculated_loss,
- 'final_value' => $this->displayed_currency_calculated_loss,
- 'lost_percentage' => $lost_percentage_displayed,
- 'lost_value' => $difference_displayed,
- 'factor' => $factor_currency_displayed,
- 'positive_negative' => ($plus_minus == '+' ? 'positive' : 'negative')
- ],
- 'calculated' => [
- 'discount' => $this->calculated_discount,
- 'cash_discount' => $this->calculated_cash_discount,
- 'procurement_cost' => $this->calculated_procurement_cost,
- 'cost' => $this->calculated_cost,
- 'profit' => $this->calculated_profit,
- 'customer_card_discount' => $this->calculated_customer_card_discount,
- 'discount_two' => $this->calculated_discount_two,
- 'value_added_tax' => $this->calculated_value_added_tax,
- 'calculated_loss' => $this->calculated_calculated_loss,
- 'final_value' => $this->calculated_calculated_loss,
- 'lost_percentage' => $lost_percentage_calculated,
- 'lost_value' => $difference_calculated,
- 'factor' => $factor_calculated,
- 'positive_negative' => ($plus_minus == '+' ? 'positive' : 'negative')
- ],
- 'calculated_currency' => [
- 'discount' => $this->calculated_currency_discount,
- 'cash_discount' => $this->calculated_currency_cash_discount,
- 'procurement_cost' => $this->calculated_currency_procurement_cost,
- 'cost' => $this->calculated_currency_cost,
- 'profit' => $this->calculated_currency_profit,
- 'customer_card_discount' => $this->calculated_currency_customer_card_discount,
- 'discount_two' => $this->calculated_currency_discount_two,
- 'value_added_tax' => $this->calculated_currency_value_added_tax,
- 'calculated_loss' => $this->calculated_currency_calculated_loss,
- 'final_value' => $this->calculated_currency_calculated_loss,
- 'lost_percentage' => $lost_percentage_calculated,
- 'lost_value' => $difference_calculated,
- 'factor' => $factor_currency_calculated,
- 'positive_negative' => ($plus_minus == '+' ? 'positive' : 'negative')
- ],
- 'calculated_base' => [
- 'discount' => self::$discount,
- 'cash_discount' => self::$cash_discount,
- 'procurement_cost' => self::$procurement_cost,
- 'cost' => self::$cost,
- 'profit' => self::$profit,
- 'customer_card_discount' => self::$customer_card_discount,
- 'discount_two' => self::$discount_two,
- 'value_added_tax' => self::$value_added_tax,
- 'calculated_loss' => self::$calculated_loss,
- ],
- 'calculated_base_displayed' => [
- 'discount' => self::dotToComma(self::$discount),
- 'cash_discount' => self::dotToComma(self::$cash_discount),
- 'procurement_cost' => self::dotToComma(self::$procurement_cost),
- 'cost' => self::dotToComma(self::$cost),
- 'profit' => self::dotToComma(self::$profit),
- 'customer_card_discount' => self::dotToComma(self::$customer_card_discount),
- 'discount_two' => self::dotToComma(self::$discount_two),
- 'value_added_tax' => self::dotToComma(self::$value_added_tax),
- 'calculated_loss' => self::dotToComma(self::$calculated_loss),
- ]
- ];
- $_SESSION['calculated_data'] = $result;
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement