PHP code example of ag84ark / smartbill

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

    

ag84ark / smartbill example snippets


use Ag84ark\SmartBill\SmartBill;
use Ag84ark\SmartBill\Resources\Invoice;
use Ag84ark\SmartBill\Resources\Client;
use Ag84ark\SmartBill\Resources\InvoiceProduct;

$invoice = Invoice::make();
$invoice->setIsDraft(true);

$invoice->setClient(
  Client::make()
    ->setName("ACME CO")
    ->setVatCode("RO12345678")
    ->setRegCom("")
    ->setAddress("Main street, no 10")
    ->setIsTaxPayer(false)
    ->setCity("Bucharest")
    ->setCounty("Bucharest")
    ->setCountry("Romania")
    ->setEmail("[email protected]")
);

$invoice->addProduct(
  InvoiceProduct::make()
    ->setName("Produs 1")
    ->setCode("ccd1")
    ->setMeasuringUnitName("buc")
    ->setCurrency("RON")
    ->setQuantity(2)
    ->setPrice(10)
    ->setIsTaxIncluded(true)
    ->setTaxName("Redusa")
    ->setTaxPercentage(9)
);

$invoice->addProduct(InvoiceProduct::makeValoricDiscountItem("Discount", 5));

$invoice->setPayment(
  InvoicePayment::make()
    ->setIsCash(true)
    ->setType(Ag84ark\SmartBill\Enums\PaymentType::OrdinPlata)
    ->setValue(15)
);

echo 'Emitere factura simpla: ';
try {
    $smartbill = new SmartBill();
    $output = $smartbill->invoiceEndpoint->createInvoice($invoice);
    $invoiceNumber = $output->getNumber();
    $invoiceSeries = $output->getSeries();
    echo $invoiceSeries . $invoiceNumber;
} catch (\Exception $ex) {
    echo $ex->getMessage();
}



$invoice = [
    'companyVatCode' => config('smartbill.vatCode'),
    'client' 		=> [
        'name' 			=> "ACME CO",
        'vatCode' 		=> "RO12345678",
        'regCom' 		=> "",
        'address' 		=> "Main street, no 10",
        'isTaxPayer' 	=> false,
        'city' 			=> "Bucharest",
        'country' 		=> "Romania",
        'email' 		=> "[email protected]",
    ],
    'issueDate'      => date('Y-m-d'),
    'seriesName'     => config('smartbill.invoiceSeries'),
    'isDraft'        => false,
    'dueDate'		=> date('Y-m-d', time() + 3600 * 24 * 30),
    'mentions'		=> '',
    'observations'   => '',
    'deliveryDate'   => date('Y-m-d', time() + 3600 * 24 * 10),
    'precision'      => 2,
    'products'		=> [
        [
            'name' 				=> "Produs 1",
            'code' 				=> "ccd1",
            'isDiscount' 		=> false,
            'measuringUnitName' => "buc",
            'currency' 			=> "RON",
            'quantity' 			=> 2,
            'price' 			=> 10,
            'isTaxIncluded' 	=> true,
            'taxName' 			=> "Redusa",
            'taxPercentage' 	=> 9,
            'isService'         => false,
            'saveToDb'          => false,
        ],
    ],
];

echo 'Emitere factura simpla: ';
try {
    $smartbill = new SmartBill();
    $output = $smartbill->invoiceEndpoint->createInvoiceFromArray($invoice);
    $invoiceNumber = $output->getNumber();
    $invoiceSeries = $output->getSeries();
    echo $invoiceSeries . $invoiceNumber;
} catch (\Exception $ex) {
    echo $ex->getMessage();
}
bash
php artisan vendor:publish --provider="Ag84ark\SmartBill\SmartBillServiceProvider" --tag="laravel-smartbill-config"