<?php

class ModelEntegrasyonCalculate extends Model
{

    public function calculatePrice($price, $default, $tax, $code)
    {



        if($tax){
            $price = round($price + (($price*$tax)/100));

        }


        $tempPrice = $price;


            if ($default['commission']) {

                $price = $price + ($price * $default['commission'] / 100);

            }

            if ($default['price_multiplier']) {

                $price = $this->price_multiplier($tempPrice, $default['price_multiplier']);
            }


        $price = number_format($price, 2);
        $price = str_replace(',', '', $price);

        return $price;

    }


    public function price_multiplier($price, $multipliers)
    {


        $returned_price = 0;

        $wholesaleTable = explode("\n", $multipliers);

        natsort($wholesaleTable);


        foreach ($wholesaleTable as $row) {
            $wholesale = explode(':', $row);

            if (count($wholesale) == 2) {
                if (isset($wholesale[1])) {

                    if ($price < $wholesale[0]) {

                        return $price + ($price * (int)$wholesale[1] / 100);

                    }
                }
            } else {

                return $price;
            }
        }


        return $returned_price;
    }


}

