PHP code example of kayedspace / laravel-erpnext

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

    

kayedspace / laravel-erpnext example snippets


use Kayedspace\Erpnext\Facades\Erpnext;

Erpnext::doctype('Lead')->create(['lead_name' => 'Ada Lovelace']);

Erpnext::doctype('Sales Invoice')
    ->query()
    ->where('status', 'Overdue')
    ->fields(['name', 'customer', 'outstanding_amount'])
    ->orderBy('due_date', 'asc')
    ->limit(25)
    ->get();

use Kayedspace\Erpnext\Documents\SalesInvoice;

$invoice = SalesInvoice::findOrFail('ACC-SINV-2025-00001');

if ($invoice->isDraft()) {
    $invoice->update(['due_date' => now()->addMonth()->toDateString()]);
    $invoice->submit();
}

Erpnext::doctype('Sales Invoice')->query()->where('status', 'Overdue')->each(
    fn (array $invoice) => Chase::dispatch($invoice['name']),
);

$page = Erpnext::query('Customer')->paginate(perPage: 25, page: 3);

$page->items();        // At most 25 customers.
$page->total();        // Scalar count returned by Frappe.
$page->previousPage(); // 2
$page->nextPage();     // 4, or null on the last page.

$next = $page->next();       // One request for page 4; no repeated count.
$fifth = $page->forPage(5);  // One request for page 5.

$tasks = Erpnext::query('ToDo')
    ->fields(['name', 'priority'])
    ->expand(['priority'])
    ->paginate(25);

$task = Erpnext::doctype('ToDo')->expandLinks()->findOrFail('TASK-1');
$same = Erpnext::doctype('ToDo')->findOrFail('TASK-1', expandLinks: true);

$file = Erpnext::upload()
    ->fromPath(storage_path('app/scan.pdf'))
    ->attachTo('Sales Invoice', 'ACC-SINV-2025-00001', 'custom_scan')
    ->store();

$file->url();       // absolute URL
$file->download();  // bytes, authenticated — so private files work too

$this->app->singleton(ErpClient::class, fn ($app) => new ErpClient(
    fn () => Connection::fromArray($app->make(YourTenantSettings::class)->all()),
));

Http::preventStrayRequests();
Http::fake(['*' => Http::response(['data' => ['name' => 'CUST-0001']])]);

Erpnext::doctype('Customer')->find('CUST-0001');