public function getNetPriceAfterTaxUpdate($productId, $oldNetPrice, $oldTaxRate)
    {

        // if old tax was 0, $oldTaxRate === null (tax 0 has no record in table tax) and would reset the price to 0
        if (is_null($oldTaxRate)) {
            $oldTaxRate = 0;
        }

        $sql = 'SELECT ROUND(:oldNetPrice / ((100 + t.rate) / 100) * (1 + :oldTaxRate / 100), 6) as new_net_price ';
        $sql .= $this->getTaxJoins();
        $params = [
            'oldNetPrice' => $oldNetPrice,
            'oldTaxRate' => $oldTaxRate,
            'productId' => $productId
        ];
        $statement = $this->getConnection()->prepare($sql);
        $statement->execute($params);
        $rate = $statement->fetchAll('assoc');

        // if tax == 0 %, tax is empty
        if (empty($rate)) {
            $newNetPrice = $oldNetPrice * (1 + $oldTaxRate / 100);
        } else {
            $newNetPrice = $rate[0]['new_net_price'];
        }

        return $newNetPrice;
    }
public function getNetPriceAfterTaxUpdate($productId, $oldNetPrice, $oldTaxRate)
    {

        // if old tax was 0, $oldTaxRate === null (tax 0 has no record in table tax) and would reset the price to 0
        if (is_null($oldTaxRate)) {
            $oldTaxRate = 0;
        }

        $sql = 'SELECT ROUND(:oldNetPrice / ((100 + t.rate) / 100) * (1 + :oldTaxRate / 100), 6) as new_net_price ';
        $sql .= $this->getTaxJoins();
        $params = [
            'oldNetPrice' => $oldNetPrice,
            'oldTaxRate' => $oldTaxRate,
            'productId' => $productId
        ];
        $statement = $this->getConnection()->prepare($sql);
        $statement->execute($params);
        $rate = $statement->fetchAll('assoc');

        // if tax == 0 %, tax is empty
        if (empty($rate)) {
            $newNetPrice = $oldNetPrice * (1 + $oldTaxRate / 100);
        } else {
            $newNetPrice = $rate[0]['new_net_price'];
        }

        return $newNetPrice;
    }
public function getNetPriceAfterTaxUpdate ( $ productId , $ oldNetPrice , $ oldTaxRate ) { // if old tax was 0, $oldTaxRate === null (tax 0 has no record in table tax) and would reset the price to 0
 if ( is_null ( $ oldTaxRate ) ) { $ oldTaxRate = 0 ; } $ sql = 'SELECT ROUND(:oldNetPrice / ((100 + t.rate) / 100) * (1 + :oldTaxRate / 100), 6) as new_net_price ' ; $ sql .= $ this -> getTaxJoins ( ) ; $ params = [ 'oldNetPrice' => $ oldNetPrice , 'oldTaxRate' => $ oldTaxRate , 'productId' => $ productId ] ; $ statement = $ this -> getConnection ( ) -> prepare ( $ sql ) ; $ statement -> execute ( $ params ) ; $ rate = $ statement -> fetchAll ( 'assoc' ) ; // if tax == 0 %, tax is empty
 if ( empty ( $ rate ) ) { $ newNetPrice = $ oldNetPrice * ( 1 + $ oldTaxRate / 100 ) ; } else { $ newNetPrice = $ rate [ 0 ] [ 'new_net_price' ] ; } return $ newNetPrice ; }
needs to be called AFTER taxId of product was updated
needs to be called AFTER taxId of product was updated