Svea/Helper/Helper.php
/**
     * Takes a total discount value ex. vat, a mean tax rate & an array of allowed tax rates.
     * returns an array of FixedDiscount objects representing the discount split
     * over the allowed Tax Rates, defined using AmountExVat & VatPercent.
     *
     * Note: only supports two allowed tax rates for now.
     * 
     * @deprecated -- use Helper::splitMeanAcrossTaxRates() instead
     */
Takes a total discount value ex. vat, a mean tax rate & an array of allowed tax rates.
returns an array of FixedDiscount objects representing the discount split
over the allowed Tax Rates, defined using AmountExVat & VatPercent.

only supports two allowed tax rates for now.

@deprecated -- use Helper::splitMeanAcrossTaxRates() instead
Takes a total discount value ex . vat a mean tax rate & an array of allowed tax rates . returns an array of FixedDiscount objects representing the discount split over the allowed Tax Rates defined using AmountExVat & VatPercent . only supports two allowed tax rates for now . @deprecated -- use Helper :: splitMeanAcrossTaxRates () instead
static function splitMeanToTwoTaxRates( $discountAmountExVat, $discountMeanVat, $discountName, $discountDescription, $allowedTaxRates ) {
        $fixedDiscounts = array();
        if( sizeof( $allowedTaxRates ) > 1 ) {
            $a = ($discountMeanVat - $allowedTaxRates[1]) / ( $allowedTaxRates[0] - $allowedTaxRates[1] );
            $b = 1 - $a;
            $discountA = \WebPayItem::fixedDiscount()
                            ->setAmountExVat( Helper::bround(($discountAmountExVat * $a),2) )
                            ->setVatPercent( $allowedTaxRates[0] )
                            ->setName( isset( $discountName) ? $discountName : "" )
                            ->setDescription( (isset( $discountDescription) ? $discountDescription : "") . ' (' .$allowedTaxRates[0]. '%)' )
            ;
            $discountB = \WebPayItem::fixedDiscount()
                            ->setAmountExVat( Helper::bround(($discountAmountExVat * $b),2) )
                            ->setVatPercent(  $allowedTaxRates[1] )
                            ->setName( isset( $discountName) ? $discountName : "" )
                            ->setDescription( (isset( $discountDescription) ? $discountDescription : "") . ' (' .$allowedTaxRates[1]. '%)' )
            ;
            $fixedDiscounts[] = $discountA;
            $fixedDiscounts[] = $discountB;
        }
        else {
            $discountA = \WebPayItem::fixedDiscount()
                ->setAmountExVat( Helper::bround(($discountAmountExVat),2) )
                ->setVatPercent( $allowedTaxRates[0] )
                ->setName( isset( $discountName) ? $discountName : "" )
                ->setDescription( (isset( $discountDescription) ? $discountDescription : "") )
            ;
            $fixedDiscounts[] = $discountA;
        }
        return $fixedDiscounts;
    }
static function splitMeanToTwoTaxRates ( $ discountAmountExVat , $ discountMeanVat , $ discountName , $ discountDescription , $ allowedTaxRates ) { $ fixedDiscounts = array ( ) ; if ( sizeof ( $ allowedTaxRates ) > 1 ) { $ a = ( $ discountMeanVat - $ allowedTaxRates [ 1 ] ) / ( $ allowedTaxRates [ 0 ] - $ allowedTaxRates [ 1 ] ) ; $ b = 1 - $ a ; $ discountA = \ WebPayItem :: fixedDiscount ( ) -> setAmountExVat ( Helper :: bround ( ( $ discountAmountExVat * $ a ) , 2 ) ) -> setVatPercent ( $ allowedTaxRates [ 0 ] ) -> setName ( isset ( $ discountName ) ? $ discountName : " " ) -> setDescription ( ( isset ( $ discountDescription ) ? $ discountDescription : " " ) . ' (' . $ allowedTaxRates [ 0 ] . '%)' ) ; $ discountB = \ WebPayItem :: fixedDiscount ( ) -> setAmountExVat ( Helper :: bround ( ( $ discountAmountExVat * $ b ) , 2 ) ) -> setVatPercent ( $ allowedTaxRates [ 1 ] ) -> setName ( isset ( $ discountName ) ? $ discountName : " " ) -> setDescription ( ( isset ( $ discountDescription ) ? $ discountDescription : " " ) . ' (' . $ allowedTaxRates [ 1 ] . '%)' ) ; $ fixedDiscounts [ ] = $ discountA ; $ fixedDiscounts [ ] = $ discountB ; } else { $ discountA = \ WebPayItem :: fixedDiscount ( ) -> setAmountExVat ( Helper :: bround ( ( $ discountAmountExVat ) , 2 ) ) -> setVatPercent ( $ allowedTaxRates [ 0 ] ) -> setName ( isset ( $ discountName ) ? $ discountName : " " ) -> setDescription ( ( isset ( $ discountDescription ) ? $ discountDescription : " " ) ) ; $ fixedDiscounts [ ] = $ discountA ; } return $ fixedDiscounts ; }
Takes a total discount value ex.
Takes a total discount value ex .
// m = $discountMeanVat // r0 = allowedTaxRates[0]; r1 = allowedTaxRates[1] // m = a r0 + b r1 => m = a r0 + (1-a) r1 => m = (r0-r1) a + r1 => a = (m-r1)/(r0-r1) // d = $discountAmountExVat; // d = d (a+b) => 1 = a+b => b = 1-a // single tax rate, so use shop supplied mean as vat rate