Je voudrais ajouter une note au cas où d'autres personnes tenteraient d'implémenter SII à partir de PHP.
Il n'est en fait pas nécessaire de créer des classes/objets pour la structure de données.
Autrement dit, créez simplement un tableau associatif multiniveau PHP avec toute la structure et transmettez-le comme paramètre à la fonction que nous appelons, et cela suffit, puis le même client SOAP se charge d'encoder les données avec la structure XML nécessaire.
Exemple de tableau PHP avec var_export() :
$datos=array (
'Cabecera' =>
array (
'IDVersionSii' => '1.0',
'Titular' =>
array (
'NombreRazon' => 'ALEXANDRU CATALIN TRANDAFIR',
'NIF' => 'X4378072E',
),
'TipoComunicacion' => 'A0',
),
'RegistroLRFacturasEmitidas' =>
array (
0 =>
array (
'PeriodoImpositivo' =>
array (
'Ejercicio' => '2017',
'Periodo' => '12',
),
'IDFactura' =>
array (
'IDEmisorFactura' =>
array (
'NIF' => 'X4378072E',
),
'NumSerieFacturaEmisor' => 'SIIDEMO/1',
'FechaExpedicionFacturaEmisor' => '31-12-2017',
),
'FacturaExpedida' =>
array (
'TipoFactura' => 'F1',
'ClaveRegimenEspecialOTrascendencia' => '01',
'ImporteTotal' => 1210,
'DescripcionOperacion' => 'Compra ordenador portátil',
'FechaOperacion' => '31-12-2017',
'Contraparte' =>
array (
'NombreRazon' => 'HeavyDots SL',
'NIF' => 'B66544586',
),
'TipoDesglose' =>
array (
'DesgloseFactura' =>
array (
'Sujeta' =>
array (
'NoExenta' =>
array (
'TipoNoExenta' => 'S1',
'DesgloseIVA' =>
array (
'DetalleIVA' =>
array (
0 =>
array (
'TipoImpositivo' => 21,
'BaseImponible' => 500,
'CuotaRepercutida' => 105,
),
1 =>
array (
'TipoImpositivo' => 21,
'BaseImponible' => 500,
'CuotaRepercutida' => 105,
),
),
),
),
),
),
),
),
),
1 =>
array (
'PeriodoImpositivo' =>
array (
'Ejercicio' => '2017',
'Periodo' => '12',
),
'IDFactura' =>
array (
'IDEmisorFactura' =>
array (
'NIF' => 'X4378072E',
),
'NumSerieFacturaEmisor' => 'SIIDEMO/2',
'FechaExpedicionFacturaEmisor' => '31-12-2017',
),
'FacturaExpedida' =>
array (
'TipoFactura' => 'F1',
'ClaveRegimenEspecialOTrascendencia' => '01',
'ImporteTotal' => 1210,
'DescripcionOperacion' => 'Compra ordenador portátil',
'FechaOperacion' => '31-12-2017',
'Contraparte' =>
array (
'NombreRazon' => 'HeavyDots SL',
'NIF' => 'B66544586',
),
'TipoDesglose' =>
array (
'DesgloseFactura' =>
array (
'Sujeta' =>
array (
'NoExenta' =>
array (
'TipoNoExenta' => 'S1',
'DesgloseIVA' =>
array (
'DetalleIVA' =>
array (
0 =>
array (
'TipoImpositivo' => 21,
'BaseImponible' => 500,
'CuotaRepercutida' => 105,
),
1 =>
array (
'TipoImpositivo' => 21,
'BaseImponible' => 500,
'CuotaRepercutida' => 105,
),
),
),
),
),
),
),
),
),
),
)
Puis l'appel :
$comando = 'SuministroLRFacturasEmitidas';
$response = $client->$comando($datos);
Et puis si nous le voulons, nous pouvons obtenir le XML généré comme ceci :
$peticion_xml = $client->__getLastRequest();
XML généré :
1.0
ALEXANDRU CATALIN TRANDAFIR
X4378072E
A0
2017
12
X4378072E
SIIDEMO/1
31-12-2017
F1
31-12-2017
01
1210
Compra ordenador portátil
HeavyDots SL
B66544586
S1
21
500
105
21
500
105
2017
12
X4378072E
SIIDEMO/2
31-12-2017
F1
31-12-2017
01
1210
Compra ordenador portátil
HeavyDots SL
B66544586
S1
21
500
105
21
500
105
Pour ceux qui sont toujours intéressés par l'intégration de SII dans les applications PHP (et pas seulement), je vous dis que je vais bientôt finir d'écrire et de publier l'ebook/tutorial sur http://www.aeatsiidesarrolladores.es/



