PHP code example of vaened / php-price-engine

1. Go to this page and download the library: Download vaened/php-price-engine library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vaened / php-price-engine example snippets


$cashier = new SimpleCashier(
    Amount::taxable(
        Money::of(100, 'USD'),
        TaxCodes::any()
    ),
    quantity : 1,
    taxes    : Taxes::from([
        Tax\Inclusive::proporcional(21, TaxCode::IVA),
    ])
);

$cashier->update(10);

$cashier->apply(
    Discount::proporcional(2)->named('NEW_USERS'),
    Discount::fixed(5)->named('PROMOTIONAL'),
);

$cashier->add(
    Charge::proporcional(5)->named('POS'),
    Charge::fixed(10)->named('DELIVERY')
);

$cashier->taxes()->locate('IVA');
$cashier->charges()->locate('DELIVERY');
$cashier->discounts()->locate('NEW_USERS');

$cashier->quantity();
$cashier->unitPrice();
$cashier->subtotal();
$cashier->taxes()->total();
$cashier->charges()->total();
$cashier->discounts()->total();
$cashier->total();

  Amount::taxable(
      Money::of(100, 'PEN'),
      TaxCodes::only(['IGV'])
  );
  

  Amount::taxexempt(
      Money::of(10, 'PEN')
  );
  

  use Vaened\PriceEngine\Adjustments\Tax;
  
  $amount->impose([
    Tax\Inclusive::proporcional(18, 'IGV'); // 18%
    Tax\Inclusive::fixed(2, 'ISC'); // 2 PEN
  ]);
  // or
  $cashier = new RegularCashier(
    ...
    taxes : Taxes::from([
      Tax\Inclusive::proporcional(18, 'IGV'); // 18%
      Tax\Inclusive::fixed(2, 'ISC'); // 2 PEN
    ])
  );
  

  use Vaened\PriceEngine\Adjustments\Tax;

  $amount->impose([
    Tax\Exclusive::proporcional(18, 'IGV'); // 18%
    Tax\Exclusive::fixed(2, 'ISC'); // 2 PEN
  ]);
  // or
  $cashier = new RegularCashier(
    ...
    taxes : Taxes::from([
      Tax\Exclusive::proporcional(18, 'IGV'); // 18%
      Tax\Exclusive::fixed(2, 'ISC'); // 2 PEN
    ])
  );
  
shell
composer