PHP code example of sharpapi / laravel-invoice-manager

1. Go to this page and download the library: Download sharpapi/laravel-invoice-manager 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/ */

    

sharpapi / laravel-invoice-manager example snippets


use SharpAPI\InvoiceManager\Jobs\ParseAndStoreInvoiceJob;

ParseAndStoreInvoiceJob::dispatch('/path/to/invoice.pdf');

use SharpAPI\InvoiceManager\Services\InvoiceImporter;
use SharpAPI\InvoiceParser\InvoiceParserService;

$parser = app(InvoiceParserService::class);
$importer = app(InvoiceImporter::class);

$statusUrl = $parser->parseInvoice('/path/to/invoice.pdf');
$job = $parser->fetchResults($statusUrl);

$invoices = $importer->storeMany($job->getResultArray(), [
    'sharp_api_job_id' => $job->id,
    'source_file_path' => '/path/to/invoice.pdf',
    'source_file_name' => 'invoice.pdf',
]);

$invoice = $invoices->first();
$invoice->invoice_number;            // "INV-1688"
$invoice->total;                     // total_payable, falling back to total_incl_tax
$invoice->lineItems;                 // collection of line items
$invoice->seller->name;              // "L Dairy Foods Sdn Bhd"
$invoice->buyer->billing_city;       // "Kuala Lumpur"
$invoice->taxDetails;                // collection of tax breakdowns

use SharpAPI\InvoiceManager\Events\InvoiceImported;

// In a listener
public function handle(InvoiceImported $event): void
{
    $invoice = $event->invoice;
    // notify, post to ERP, reconcile, etc.
}

return [
    'table_prefix' => env('INVOICE_MANAGER_TABLE_PREFIX', 'invoice_'),

    'import' => [
        // update | skip | new
        'on_duplicate' => env('INVOICE_MANAGER_ON_DUPLICATE', 'update'),
    ],

    'queue' => [
        'connection' => env('INVOICE_MANAGER_QUEUE_CONNECTION'),
        'name' => env('INVOICE_MANAGER_QUEUE'),
    ],

    'nova' => [
        'enabled' => env('INVOICE_MANAGER_NOVA', true),
        'resource' => \SharpAPI\InvoiceManager\Nova\Invoice::class,
    ],

    'models' => [
        'invoice' => \SharpAPI\InvoiceManager\Models\Invoice::class,
        'party' => \SharpAPI\InvoiceManager\Models\InvoiceParty::class,
        'line_item' => \SharpAPI\InvoiceManager\Models\InvoiceLineItem::class,
        'tax_detail' => \SharpAPI\InvoiceManager\Models\InvoiceTaxDetail::class,
        'bank_detail' => \SharpAPI\InvoiceManager\Models\InvoiceBankDetail::class,
    ],
];
bash
php artisan migrate
bash
php artisan vendor:publish --tag=sharpapi-invoice-manager-config
bash
php artisan vendor:publish --tag=sharpapi-invoice-manager-migrations