-
Notifications
You must be signed in to change notification settings - Fork 3
Használat
dsge edited this page Jun 26, 2016
·
1 revision
$invoice = new Clapp\SzamlazzhuClient\Invoice();
$invoice->customerName = "Foo Bar";
$invoice->customerBillingPostcode = "1234";
$invoice->customerBillingCity = "Budapest";
$invoice->customerBillingAddress = "Foo utca 1.";
$invoice->merchantBankName = "FooBank";
$invoice->merchantBankAccountNumber = "12345678-12345678-12345678";
$invoice->items = [
[
'name' => 'Minta Termék',
'quantity' => 2,
'quantityUnit' => 'db',
'netUnitPrice' => 100,
'vatRate' => '25',
'netValue' => 200,
'vatValue' => 50,
'grossValue' => 250,
],
[
'name' => 'Minta Termék 2',
'quantity' => 1,
'quantityUnit' => 'db',
'netUnitPrice' => 100,
'vatRate' => '25',
'netValue' => 100,
'vatValue' => 25,
'grossValue' => 125,
],
];
$invoice->paymentMethod = 'utánvétel';
$invoice->currency = 'HUF';
$invoice->language = 'hu';
$invoice->signatureDate = '2016-01-02';
$invoice->settlementDate = '05/10/2015';
$invoice->dueDate = '2016-01-02';
try {
/**
* számla mezőinek ellenőrzése
*/
$invoice->validate();
}catch(Illuminate\Validation\ValidationException $e){
/**
* hibás vagy hiányzó mezők
*/
// var_dump( $e->validator->getMessages() );
}$xmlContents = file_get_contents("path/to/szamla.xml");
$invoice = new Clapp\SzamlazzhuClient\Invoice($xmlContents);Számla mezőinek kitöltése a saját rendszered Cart, Product, Customer és Merchant implementáció alapján
// My/Webshop/Cart.php
/**
* saját Kosár implementációd
*/
class Cart implements \Clapp\SzamlazzhuClient\Contract\InvoiceableItemCollectionContract{
/**
* valahogyan eltárolod a kosár termékeit
*/
protected $products = [];
/**
* implementálod az InvoiceableItemCollectionContract függvényét
*
* @return array
* A számlára kerülő összes termék adatai.
* A tömb elemei mind tömbök, vagy `Clapp\SzamlazzhuClient\Contract\InvoiceItemContract` instance-ok.
*/
public function getInvoiceItemCollectionData(){
$invoiceItems = [];
foreach($this->products as $product){
$invoiceItems[] = [
'name' => $product->name,
'quantity' => $product->quantity,
'quantityUnit' => $product->quantityUnit,
'netUnitPrice' => $product->netUnitPrice,
'vatRate' => $product->vatRate,
'netValue' => $product->netValue,
'vatValue' => $product->vatValue,
'grossValue' => $product->grossValue,
];
}
return $invoiceItems;
}
}// My/Webshop/Product.php
/**
* Saját Product implementációd
*/
class Product implements \Clapp\SzamlazzhuClient\Contract\InvoiceableItemContract{
public function getInvoiceItemData(){
return [
'name' => $this->name,
'quantity' => $this->quantity,
'quantityUnit' => $this->quantityUnit,
'netUnitPrice' => $this->netUnitPrice,
'vatRate' => $this->vatRate,
'netValue' => $this->netValue,
'vatValue' => $this->vatValue,
'grossValue' => $this->grossValue,
];
}
}// My/Webshop/User.php
/**
* Saját User implementációd
*/
class User implements \Clapp\SzamlazzhuClient\Contract\InvoiceableCustomerContract{
public function getInvoiceCustomerData(){
return [
customerName: $this->first_name.' '.$this->last_name,
customerBillingPostcode: $this->address->postcode,
customerBillingCity: $this->address->city,
customerBillingAddress: $this->address->address,
];
}
}$invoice = new Clapp\SzamlazzhuClient\Invoice();
$invoice->items = $cart; //$cart egy My\Webshop\Cart instance
$invoice->customer = $user; //$user egy My\Webshop\User instance
$invoice->addItem($product); //$item egy My\Webshop\Product instance
try {
$invoice->validateItems();
$invoice->validateCustomer();
}catch(Illuminate\Validation\ValidationException $e){
// var_dump( $e->validator->getMessages() );
}$client = new Clapp\SzamlazzhuClient\SzamlazzhuClient();
$client->username = /* Számlázz.hu felhasználónév */;
$client->password = /* Számlázz.hu jelszó */;
try {
$pdfContents = $client->generateInvoicePdf($invoice);
}catch(Clapp\SzamlazzhuClient\SzamlazzhuApiException $e){
// var_dump( $e->getCode(), $e->getMessage() ); //API-ból származó hibakód és hibaüzenet
}
file_put_contents("szamlam.pdf", $pdfContents);