1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-23 14:57:46 +01:00

Aggiunto supporto FE a allegati

This commit is contained in:
Thomas Zilio 2018-11-09 13:15:19 +01:00
parent 083dcaa518
commit f686c98188
4 changed files with 60 additions and 19 deletions

View File

@ -84,7 +84,10 @@ if (!empty($missing)) {
echo '
<p>'.tr("Per effettuare la generazione dell'XML della fattura elettronica clicca sul pulsante _BTN_", [
'_BTN_' => '<b>Genera</b>',
]).'. '.tr('Successivamente sarà possibile procedere alla visualizzazione e al download della fattura generata attraverso i pulsanti dedicati').'.</p>';
]).'. '.tr('Successivamente sarà possibile procedere alla visualizzazione e al download della fattura generata attraverso i pulsanti dedicati').'.</p>
<p>'.tr("Tutti gli allegati inseriti all'interno della categoria \"Fattura Elettronica\" saranno inclusi come allegati dell'XML").'.</p>
<br>';
echo '
<div class="text-center">

View File

@ -465,7 +465,7 @@ class FatturaElettronica
// Controllo le le righe per la fatturazione di contratti
$dati_contratti = static::getDatiContratto($fattura);
if (!empty($dati_contratti)) {
foreach($dati_contratti as $dato){
foreach ($dati_contratti as $dato) {
$result[] = [
'DatiContratto' => $dato,
];
@ -620,37 +620,67 @@ class FatturaElettronica
/**
* Restituisce l'array responsabile per la generazione del tag Allegati.
* Supporta un singolo allegato in PDF.
*
* @return array
*/
protected static function getAllegati($fattura)
{
$documento = $fattura->getDocumento();
$cliente = $fattura->getCliente();
$attachments = [];
if (!setting('Aggiungere stampa nella Fattura Elettronica')) {
return [];
// Informazioni sul modulo
$id_module = Modules::get('Fatture di vendita')['id'];
$directory = Uploads::getDirectory($id_module);
// Allegati
$allegati = Uploads::get([
'id_module' => $id_module,
'id_record' => $documento['id'],
]);
// Inclusione
foreach ($allegati as $allegato) {
if ($allegato['category'] == 'Fattura Elettronica') {
$file = DOCROOT.'/'.$directory.'/'.$allegato['filename'];
$attachments[] = [
'NomeAttachment' => $allegato['name'],
'FormatoAttachment' => Uploads::fileInfo($file)['extension'],
'Attachment' => base64_encode(file_get_contents($file)),
];
}
}
// Aggiunta della stampa
$print = false;
if ($cliente['tipo'] == 'Privato') {
$print = setting('Allega stampa per fattura verso Privati');
} elseif ($cliente['tipo'] == 'Azienda') {
$print = setting('Allega stampa per fattura verso Aziende');
} else {
$print = setting('Allega stampa per fattura verso PA');
}
if (!$print) {
return $attachments;
}
$id_module = Modules::get('Fatture di vendita')['id'];
$dir = Uploads::getDirectory($id_module, Plugins::get('Fatturazione Elettronica')['id']);
$rapportino_nome = sanitizeFilename($documento['numero'].'.pdf');
$filename = slashes(DOCROOT.'/'.$dir.'/'.$rapportino_nome);
$print = Prints::getModulePredefinedPrint($id_module);
Prints::render($print['id'], $documento['id'], $filename);
$pdf = file_get_contents($filename);
$result = [
$attachments[] = [
'NomeAttachment' => 'Fattura',
'FormatoAttachment' => 'PDF',
'Attachment' => base64_encode($pdf),
'Attachment' => base64_encode(file_get_contents($filename)),
];
return $result;
return $attachments;
}
/**
@ -686,9 +716,14 @@ class FatturaElettronica
'DatiPagamento' => static::getDatiPagamento($fattura),
];
// Allegati
$allegati = static::getAllegati($fattura);
if (!empty($allegati)) {
$result['Allegati'] = $allegati;
foreach ($allegati as $allegato) {
$result[] = [
'Allegati' => $allegato,
];
}
}
return $result;

View File

@ -62,7 +62,7 @@ class Uploads
*/
public static function getName($source, $data)
{
$extension = strtolower(pathinfo($source)['extension']);
$extension = strtolower(self::fileInfo($source)['extension']);
$ok = self::isSupportedType($extension);
$directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']);

View File

@ -29,7 +29,10 @@ UPDATE `zz_modules` `t1` INNER JOIN `zz_modules` `t2` ON (`t1`.`name` = 'Categor
ALTER TABLE `an_nazioni` ADD `name` VARCHAR(255);
ALTER TABLE `co_documenti` ADD `codice_xml` VARCHAR(255);
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES (NULL, 'Aggiungere stampa nella Fattura Elettronica', '0', 'boolean', 1, 'Generali', 20);
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES
(NULL, 'Allega stampa per fattura verso Privati', '0', 'boolean', 1, 'Fatturazione Elettronica', 8),
(NULL, 'Allega stampa per fattura verso Aziende', '0', 'boolean', 1, 'Fatturazione Elettronica', 9),
(NULL, 'Allega stampa per fattura verso PA', '0', 'boolean', 1, 'Fatturazione Elettronica', 10);
CREATE TABLE IF NOT EXISTS `fe_regime_fiscale` (
`codice` varchar(4) NOT NULL,
@ -57,7 +60,7 @@ INSERT INTO `fe_regime_fiscale` (`codice`, `descrizione`) VALUES
('RF18','Altro'),
('RF19','Regime forfettario (art.1, c.54-89, L. 190/2014)');
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES (NULL, 'Regime Fiscale', '', 'query=SELECT codice AS id, descrizione FROM fe_regime_fiscale', 1, 'Generali', 19);
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES (NULL, 'Regime Fiscale', '', 'query=SELECT codice AS id, descrizione FROM fe_regime_fiscale', 1, 'Fatturazione Elettronica', 1);
CREATE TABLE IF NOT EXISTS `fe_tipo_cassa` (
`codice` varchar(4) NOT NULL,
@ -89,7 +92,7 @@ INSERT INTO `fe_tipo_cassa` (`codice`, `descrizione`) VALUES
('TC21','Ente nazionale previdenza e assistenza psicologi (ENPAP)'),
('TC22','INPS');
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES (NULL, 'Tipo Cassa', '', 'query=SELECT codice AS id, descrizione FROM fe_tipo_cassa', 1, 'Fatturazione', 0);
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES (NULL, 'Tipo Cassa', '', 'query=SELECT codice AS id, descrizione FROM fe_tipo_cassa', 1, 'Fatturazione Elettronica', 2);
CREATE TABLE IF NOT EXISTS `fe_modalita_pagamento` (
`codice` varchar(4) NOT NULL,
@ -365,9 +368,9 @@ età svizzere che possiedono i requisiti di cui all''art. 15, c. 2 dellAccord
('Y', 'Canoni corrisposti dal 1.01.2005 al 26.07.2005 da soggetti di cui al punto precedente'),
('Z', 'Titolo diverso dai precedenti');
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES (NULL, 'Causale ritenuta d''acconto', '', 'query=SELECT codice AS id, descrizione FROM fe_causali_pagamento_ritenuta', 1, 'Fatturazione', 0);
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES (NULL, 'Causale ritenuta d''acconto', '', 'query=SELECT codice AS id, descrizione FROM fe_causali_pagamento_ritenuta', 1, 'Fatturazione Elettronica', 3);
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES (NULL, 'Authorization ID Indice PA', '', 'string', 1, 'Generali', 0);
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES (NULL, 'Authorization ID Indice PA', '', 'string', 1, 'Fatturazione Elettronica', 4);
ALTER TABLE `an_anagrafiche` ADD `codice_destinatario` varchar(7);