Invoices

ZATCA Invoice System Documentation

Table of Contents

  1. Invoice Setup

  2. Creating Invoices

  3. Submitting Invoices

  4. Returns and Credit Notes

  5. Status Checking

  6. Available Methods

  7. Important Notes

Invoice Setup

Adding ZATCA Invoice Capability

First, add the HasZatcaInvoice trait to your model:

use Hazem\Zatca\Traits\HasZatcaInvoice;

class Order extends Model
{
    use HasZatcaInvoice;
    
    protected function prepareZatcaInvoiceData()
    {
        $items = $this->prepareZatcaItems();
        return [
            'invoice_number' => $this->invoice_no,
            'total_amount' => round($this->final_total, 2),
            'vat_amount' => collect($items)->sum(function ($item) {
                return round($item['vat'] * $item['quantity'], 2);
            }),
            'is_pos' => true,
            'is_invoice' => $this->type === 'sell',
            'items' => $items,
            'date' => $this->transaction_date,
            // Buyer information
            'buyer_name' => $this->contact->name ?? null,
            'buyer_tax_number' => null,
            'buyer_address' => null,
            'buyer_city' => null,
            'buyer_state' => null,
            'buyer_postal' => null,
            'buyer_building_no' => null
        ];
    }

    protected function prepareZatcaItems()
    {
        return $this->sell_lines->map(function($item) {
            return [
                'name' => $item->product?->name,
                'quantity' => $item->quantity,
                'price' => round($item->unit_price, 2),
                'vat' => round(round($item->unit_price, 2) * 0.15, 2)
            ];
        })->toArray();
    }
}

Important Note: Always round monetary values to 2 decimal places to ensure accuracy in calculations.

Creating Invoices

Using the Fluent Interface

The fluent interface provides a clean and chainable way to create invoices:

Pro Tip: You can chain multiple addItem() calls to add multiple products to the invoice.

Submitting Invoices

There are two methods to submit invoices to ZATCA:

1. Basic Submission

2. Custom Data Submission

Best Practice: Always validate your data before submission to avoid rejection.

Returns and Credit Notes

To create a return/credit note invoice:

Critical Notes for Returns:

  • All monetary values must be negative

  • Reference the original invoice number when possible

  • Use a unique return/credit note number

  • Keep the same VAT rate as the original invoice

Status Checking

Monitor your invoice status:

Available Methods

Invoice Operations

Important Notes

General Guidelines

  1. Data Accuracy

    • Always validate data before submission

    • Use proper rounding for monetary values

    • Ensure all required fields are filled

  2. Error Handling

    • Always check for errors after submission

    • Log all errors for debugging

    • Implement proper error handling in your code

  3. Performance

    • Consider implementing queueing for bulk submissions

    • Cache device information when possible

    • Monitor API rate limits

Common Pitfalls to Avoid

  1. Not handling decimal places properly

  2. Forgetting to mark returns as non-invoices

  3. Missing required buyer information

  4. Incorrect VAT calculations

  5. Not validating data before submission

Best Practices

  1. Data Validation

  2. Error Handling

  3. Status Monitoring

Security Considerations

  1. Store sensitive data securely

  2. Implement proper authentication

  3. Use HTTPS for all API communications

  4. Regular audit of access logs

  5. Proper handling of cryptographic materials

Last updated