Created
January 7, 2013 08:38
-
-
Save brankoajzele/4473378 to your computer and use it in GitHub Desktop.
Fiskalizacija - RacunZahtjev
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| public function generateRacunZahtjevXML($fiscalInvoice, $invoice, $store, $storniraj = false) | |
| { | |
| $helper = $this; | |
| $grandTotal = floatval($invoice->getGrandTotal()); | |
| $PDV = $grandTotal * ($helper->getRacunPdvPorezStopa($store) / 100); /* Replace 25 with config option */ | |
| $ns = 'tns'; | |
| $writer = new XMLWriter(); | |
| $writer->openMemory(); | |
| $writer->startDocument('1.0', 'UTF-8'); | |
| $writer->setIndent(4); | |
| $writer->startElementNs('soapenv', 'Envelope', 'http://schemas.xmlsoap.org/soap/envelope/'); | |
| $writer->startElementNs('soapenv', 'Body', null); | |
| $writer->startElementNs($ns, 'RacunZahtjev', 'http://www.apis-it.hr/fin/2012/types/f73'); | |
| $writer->writeAttribute('Id', uniqid()); | |
| $writer->startElementNs($ns, 'Zaglavlje', null); | |
| $writer->writeElementNs($ns, 'IdPoruke', null, UUID::v4()); | |
| $writer->writeElementNs($ns, 'DatumVrijeme', null, date('d.m.Y\Th:i:s')); | |
| $writer->endElement(); /* #Zaglavlje */ | |
| $writer->startElementNs($ns, 'Racun', null); | |
| $writer->writeElementNs($ns, 'Oib', null, $helper->getOib($store)); | |
| $writer->writeElementNs($ns, 'USustPdv', null, (($helper->getRacunUSustPdv($store)) ? '1' : '0')); | |
| $writer->writeElementNs($ns, 'DatVrijeme', null, date('d.m.Y\Th:i:s', strtotime($invoice->getCreatedAt()))); | |
| $writer->writeElementNs($ns, 'OznSlijed', null, 'P'); /* P ili N => P na nivou Poslovnog prostora, N na nivou naplatnog uredaja */ | |
| $writer->startElementNs($ns, 'BrRac', null); | |
| $writer->writeElementNs($ns, 'BrOznRac', null, $fiscalInvoice->getId()); | |
| $writer->writeElementNs($ns, 'OznPosPr', null, $helper->getPoslovniProstorOznPoslProstora($store)); | |
| $writer->writeElementNs($ns, 'OznNapUr', null, $helper->getOznNapUr($store)); | |
| $writer->endElement(); /* #BrRac */ | |
| if ($helper->getRacunUSustPdv($store)) { | |
| $writer->startElementNs($ns, 'Pdv', null); | |
| $writer->startElementNs($ns, 'Porez', null); | |
| $writer->writeElementNs($ns, 'Stopa', null, number_format($helper->getRacunPdvPorezStopa($store), 2, '.', '')); | |
| $writer->writeElementNs($ns, 'Osnovica', null, number_format(($grandTotal - $PDV), '2', '.', '')); | |
| $writer->writeElementNs($ns, 'Iznos', null, number_format($grandTotal, '2', '.', '')); | |
| $writer->endElement(); /* #Porez */ | |
| $writer->endElement(); /* #Pdv */ | |
| } | |
| if ($storniraj) { | |
| $writer->writeElementNs($ns, 'IznosUkupno', null, '-'.number_format($grandTotal, '2', '.', '')); | |
| } else { | |
| $writer->writeElementNs($ns, 'IznosUkupno', null, number_format($grandTotal, '2', '.', '')); | |
| } | |
| $writer->writeElementNs($ns, 'NacinPlac', null, $helper->getRacunNacinPlac($invoice->getOrder()->getPayment()->getMethod(), $store)); | |
| $writer->writeElementNs($ns, 'OibOper', null, $helper->getOib($store)); | |
| $writer->writeElementNs($ns, 'ZastKod', null, $helper->getZastKod($fiscalInvoice, $store, $invoice)); | |
| $writer->writeElementNs($ns, 'NakDost', null, '0'); | |
| $writer->endElement(); /* #Racun */ | |
| $writer->endElement(); /* #RacunZahtjev */ | |
| $writer->endElement(); /* #Body */ | |
| $writer->endElement(); /* #Envelope */ | |
| $writer->endDocument(); | |
| return $writer->outputMemory(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment