PHP code example of gerardojbaez / sale-statements

1. Go to this page and download the library: Download gerardojbaez/sale-statements 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/ */

    

gerardojbaez / sale-statements example snippets


use \Gerardojbaez\SaleStatements\Models\SaleStatement;
use \Gerardojbaez\SaleStatements\Models\SaleStatementType;

// Create Invoice sale statement
$invoice = SaleStatement::create(SaleStatementType::TYPE_ORDER);

// Add Billing and Shipping Address
$invoice->addresses()->create([
    'is_shipping' => true,
    'is_billing' => true,
    'line_1' => '711-2880 Nulla St',
    'locality' => 'Mankato', // City, Town, Municipality, etc...
    'administrative_area' => 'Mississipi', // State, Province, Region, etc...
    'country_code' => 'US',
    'postalcode' => 96522,
    'given_name' => 'Cecilia', // i.e., first name
    'additional_name' => 'J.', // Can be used to hold a middle name, or a patronymic.
    'family_name' => 'Chapman', // i.e., last name
    'organization' => 'Acme Co.',
]);

// Store a discount at the statement-level
$discount = $invoice->discounts()->create([
    'name' => 'Get 20% off of license!',
    'discount' => 20,
    'is_percentage' => true,
]);

// Store tax rate at the statement-level
$tax = $statement->taxes()->create([
    'name' => 'PR 10.5 %',
    'rate' => 0.105,
    'amount' => 2486
]);

// Add line item to statement
$item = $invoice->items()->create([
    'name' => 'Software license',
    'price' => 14900, // $149.00
    'quantity' => 1,
]);

// Optionally associate discount with item
$item->discounts()->attach($discount);

// Associate tax rate with item
$item->taxes()->attach($tax);