Skip to content

Commit

Permalink
fix #10
Browse files Browse the repository at this point in the history
the handlebars template was converted with muban-convert-hbs and this script:
```
var fs = require('fs');
var convert = require('muban-convert-hbs').default;
var filename = process.argv[2];
var twig = convert(fs.readFileSync('fatturaPA_1.2.hbs', 'utf-8'), 'twig');
console.log(twig);
```
but required quite a lot of manual editing
  • Loading branch information
Paolo Greppi committed Jul 18, 2018
1 parent 89d0862 commit 6fe9fd3
Show file tree
Hide file tree
Showing 4 changed files with 691 additions and 2 deletions.
159 changes: 159 additions & 0 deletions bin/json2xml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/usr/bin/php
<?php
// creates a nested array with incvoice data and converts it to XML
// based on samples/IT01234567890_FPR01-js.json
//
// Copyright (c) 2018, Paolo Greppi <[email protected]>
// License: BSD 3-Clause

declare(strict_types=1);

require_once './vendor/autoload.php';

# initialize the twig templating engine
$loader = new Twig_Loader_Filesystem('.');
$twig = new Twig_Environment($loader, array(
'cache' => './tmp',
));
$template = $twig->load('fatturaPA_1.2.twig');

$fattura = array("FatturaElettronica" =>
array(
"versione" => "FPR12",
"FatturaElettronicaHeader" => array(
"DatiTrasmissione" => array(
"IdTrasmittente" => array(
"IdPaese" => "IT",
"IdCodice" => "01234567890"
),
"ProgressivoInvio" => "00001",
"FormatoTrasmissione" => "FPR12",
"CodiceDestinatario" => "ABC1234",
"ContattiTrasmittente" => array()
),
"CedentePrestatore" => array(
"DatiAnagrafici" => array(
"IdFiscaleIVA" => array(
"IdPaese" => "IT",
"IdCodice" => "01234567890"
),
"Anagrafica" => array(
"Denominazione" => "SOCIETA' ALPHA SRL"
),
"RegimeFiscale" => "RF19"
),
"Sede" => array(
"Indirizzo" => "VIALE ROMA 543",
"CAP" => "07100",
"Comune" => "SASSARI",
"Provincia" => "SS",
"Nazione" => "IT"
)
),
"CessionarioCommittente" => array(
"DatiAnagrafici" => array(
"CodiceFiscale" => "09876543210",
"Anagrafica" => array(
"Denominazione" => "DITTA BETA"
)
),
"Sede" => array(
"Indirizzo" => "VIA TORINO 38-B",
"CAP" => "00145",
"Comune" => "ROMA",
"Provincia" => "RM",
"Nazione" => "IT"
)
),
),
"FatturaElettronicaBody" => array(
array(
"DatiGenerali" => array(
"DatiGeneraliDocumento" => array(
"TipoDocumento" => "TD01",
"Divisa" => "EUR",
"Data" => "2014-12-18",
"Numero" => "123",
"Causale" => array(
"LA FATTURA FA RIFERIMENTO AD UNA OPERAZIONE AAAA BBBBBBBBBBBBBBBBBB CCC DDDDDDDDDDDDDDD E FFFFFFFFFFFFFFFFFFFF GGGGGGGGGG HHHHHHH II LLLLLLLLLLLLLLLLL MMM NNNNN OO PPPPPPPPPPP QQQQ RRRR SSSSSSSSSSSSSS",
"SEGUE DESCRIZIONE CAUSALE NEL CASO IN CUI NON SIANO STATI SUFFICIENTI 200 CARATTERI AAAAAAAAAAA BBBBBBBBBBBBBBBBB"
)
),
"DatiOrdineAcquisto" => array(
array(
"RiferimentoNumeroLinea" => array(
"1"
),
"IdDocumento" => "66685",
"NumItem" => "1"
)
),
"DatiContratto" => array(
array(
"RiferimentoNumeroLinea" => array(
"1"
),
"IdDocumento" => "123",
"Data" => "2012-09-01",
"NumItem" => "5",
"CodiceCUP" => "123abc",
"CodiceCIG" => "456def"
)
),
"DatiTrasporto" => array(
"DatiAnagraficiVettore" => array(
"IdFiscaleIVA" => array(
"IdPaese" => "IT",
"IdCodice" => "24681012141"
),
"Anagrafica" => array(
"Denominazione" => "Trasporto spa"
)
),
"DataOraConsegna" => "2012-10-22T16:46:12.000+02:00"
)
),
"DatiBeniServizi" => array(
"DettaglioLinee" => array(
array(
"NumeroLinea" => "1",
"Descrizione" => "DESCRIZIONE DELLA FORNITURA",
"Quantita" => "5.00",
"PrezzoUnitario" => "1.00",
"PrezzoTotale" => "5.00",
"AliquotaIVA" => "22.00"
)
),
"DatiRiepilogo" => array(
array(
"AliquotaIVA" => "22.00",
"ImponibileImporto" => "5.00",
"Imposta" => "1.10",
"EsigibilitaIVA" => "I"
)
)
),
"DatiPagamento" => array(
array(
"CondizioniPagamento" => "TP01",
"DettaglioPagamento" => array(
"ModalitaPagamento" => "MP01",
"DataScadenzaPagamento" => "2015-01-30",
"ImportoPagamento" => "6.10"
)
)
)
)
)
)
);
$json = json_encode($fattura, JSON_PRETTY_PRINT);

// echo $json;
// validate with:
// ./bin/validate_json.js IT01234567890_FPR01.json
// ./bin/validate_json.php IT01234567890_FPR01.json

echo $template->render($fattura);
// validate with:
// ./bin/validate_xml.sh IT01234567890_FPR01.xml
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"require": {
"squizlabs/php_codesniffer": "*",
"justinrainbow/json-schema": "^5.2"
"justinrainbow/json-schema": "^5.2",
"twig/twig": "^2.5"
}
}
183 changes: 182 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6fe9fd3

Please sign in to comment.