Created
January 7, 2013 08:45
-
-
Save brankoajzele/4473397 to your computer and use it in GitHub Desktop.
Fiskalizacija - Zaštitni kod
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 getZastKod($fiscalInvoice, $store, $invoice = null) | |
| { | |
| if ($invoice === null) { | |
| $invoice = Mage::getModel('sales/order_invoice'); | |
| $invoice->load($fiscalInvoice->getInvoiceEntityId()); | |
| } | |
| $cert = Mage::getModel('inchoo_fiskalizacija/cert'); | |
| $cert->load(Mage::getModel('core/store')->load($store)->getWebsiteId(), 'website_id'); | |
| $oib = $this->getOib(); | |
| $datumVrijemeIzdavanjaRacuna = date('d.m.Y H:i:s', strtotime($fiscalInvoice->getCreatedAt())); | |
| $brojcanaOznakaRacuna = $fiscalInvoice->getId(); | |
| $oznakaPoslovnogProstora = $this->getPoslovniProstorOznPoslProstora(); | |
| $oznakaNaplatnogUredaja = $this->getOznNapUr(); | |
| $ukupniIznosRacuna = number_format($invoice->getGrandTotal(), '2', '.', ''); | |
| $medjurezultat = $oib; | |
| $medjurezultat .= $datumVrijemeIzdavanjaRacuna; | |
| $medjurezultat .= $brojcanaOznakaRacuna; | |
| $medjurezultat .= $oznakaPoslovnogProstora; | |
| $medjurezultat .= $oznakaNaplatnogUredaja; | |
| $medjurezultat .= $ukupniIznosRacuna; | |
| /* $medjurezultat => something like "7934368740720.12.2012 11:14:101MAGE11567.5" */ | |
| $signature = ""; | |
| $pkeyid = openssl_get_privatekey($cert->getPemPrivateKey(), $cert->getPemPrivateKeyPassphrase()); | |
| openssl_sign($medjurezultat, $signature, $pkeyid, OPENSSL_ALGO_SHA1); | |
| openssl_free_key($pkeyid); | |
| $zastitniKod = md5($signature); | |
| return $zastitniKod; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment