PHP code example of netcore / module-invoice

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

    

netcore / module-invoice example snippets


    return [
        'relations' => [
            [
                'name'       => 'user', // relation name
                'type'       => 'belongsTo', // relation type
                'foreignKey' => 'user_id', // foreign key (user_id in invoices table in this case)
                'ownerKey'   => 'id', // owner key (id in related table in this case)
                'enabled'    => false, // is relation enabled? (it should be enable when migrating)
                'class'      => \App\User::class, // related model class
    
                // Datatable colum config
                'table' => [
                    'show' => true, // Show this column?
                    'name' => 'User', // Column name?
    
                    'searchable' => true, // Is column searchable?
                    'sortable'   => true, // Is column sortable?
                    'd_data'     => 'user', // Datatables data param
                    'd_name'     => 'user.first_name', // Datatables SQL field param
                    'modifier'   => 'fullName', // Accessor in model to format display format
                ],
            ],
        ...
    ];
 
    /**
     * Get user data for invoices.
     *
     * @return array
     */
    public function getInvoiceReceiverData(): array
    {
        return [
            'first_name' => $this->first_name,
            'last_name'  => $this->last_name,
            'email'      => $this->email,
            'phone'      => $this->phone,
        ];
    }
 
    $user = auth()->user();
    $items = [
        [
            'price' => 10.99,
            'name'  => 'Test item #1' // Name is equal for all languages 
        ],
        [
            'price' => 25.65,
            // Name is different for each language
            'translations' => [
                'en' => ['name' => 'First product.'],                    
                'ru' => ['name' => 'Первый товар..'],         
                'lv' => ['name' => 'Pirmā prece.'],
            ],
        ]
    ];

    $invoice = invoice()
        ->setItems($items)
        ->setPaymentDetails('VISA ending XXXX')
        
        ->forUser($user) // optional - set associated user (user relation should be enabled and configured)
        ->setInvoiceNr('MY123') // optional - set custom invoice nr.
        ->setVat(21) // optional - overrides vat specified in config
        ->setSender([ 'name' => 'My awesome company', ... ]) // optional - overrides sender data specified in config
        ->setReceiver([ 'first_name' => ..., 'last_name' => ... ]) // optional - overrides receiver data
        ->mergeReceiver([ 'some_additional_field' => ... ]) // optional - use if you need to add some extra receiver data

        ->make(); // build eveything up and returns Invoice instance
bash
    php artisan module:publish Invoice
    php artisan module:publish-config Invoice
    php artisan module:publish-migration Invoice
text
    edit config/netcore/module-invoice.php file to enable/disable used relations
bash 
    php artisan migrate
    php artisan module:seed Invoice