PHP code example of morningtrain / economic

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

    

morningtrain / economic example snippets


use Morningtrain\Economic\EconomicApi;

EconomicApiService::setDriver(new YourDriver($appSecretToken, $agreementGrantToken));

use Morningtrain\Economic\Resources\Customer;

$customer = Customer::where('email', '[email protected]')
                ->orWhere('name', 'Morningtrain')
                ->first();

use Morningtrain\Economic\Resources\Customer;

$customers = Customer::all();

use Morningtrain\Economic\Resources\Customer;

$customers = Customer::where('email', '[email protected]');

use Morningtrain\Economic\Resources\Customer;
use Morningtrain\Economic\Resources\Product;

$customer = Customer::find(1); // Where 1 is the customer number

$product = Product::find('proudct-1'); // Where 'product-1' is the product number

use Morningtrain\Economic\Resources\Product;

$product = Product::create(
    'Product 1', // product name
    1, // product group number
    'p-1', // product number
    barCode: '1234567890', 
    costPrice: 100.0, 
    recommendedPrice: 150.0, 
    salesPrice: 199.95, 
    description: 'test', 
    unit: 1 // unit number
);

use Morningtrain\Economic\Resources\Invoice\DraftInvoice;

$draftInvoice = DraftInvoice::new(
    'DKK',
    1,
    new DateTime('2024-02-13T12:20:18+00:00'),
    14,
    1,
    Recipient::new(
        'John Doe',
        new VatZone(1),
    ),
    [
        ProductLine::new(
            description: 'T-shirt - Size L',
            product: new Product([
                'productNumber' => 1,
            ]),
            quantity: 1,
            unitNetPrice: 500
        )
    ]
    notes: Note::new(
        heading: 'Heading',
        textLine1: 'Text line 1',
        textLine2: 'Text line 2'
    )
);

$draftInvoice->save();

use Morningtrain\Economic\Resources\Customer;

$customer = new Customer::find(1); // Where 1 is the customer number

$customer->name = 'New name';

$customer->save();

use Morningtrain\Economic\Resources\Customer;

$customer = new Customer([
    'customerNumber' => 1,
    'name' => 'New Name',
]);

$customer->save();

use Morningtrain\Economic\Resources\Customer;

$customer = new Customer::find(1); // Where 1 is the customer number

$customer->delete();

use Morningtrain\Economic\Resources\Customer;

Customer::deleteByPrimaryKey(1); // Where 1 is the customer number

use Morningtrain\Economic\Resources\Customer;

$customers = Customer::all();

foreach ($customers as $customer) {
    echo $customer->name;
}

use Morningtrain\Economic\Resources\Customer;

$customer = Customer::find(1); // Where 1 is the customer number

if(!empty($customer)) {
    echo $customer->name;
}

use Morningtrain\Economic\Resources\Customer;

$customer = Customer::where('email', '[email protected]');

if(!empty($customer)) {
    echo $customer->name;
}