diff --git a/modules/ddt/edit.php b/modules/ddt/edit.php
index f0f30d379..ec19fffae 100644
--- a/modules/ddt/edit.php
+++ b/modules/ddt/edit.php
@@ -12,6 +12,7 @@ if ($module['name'] == 'Ddt di vendita') {
unset($_SESSION['superselect']['idanagrafica']);
unset($_SESSION['superselect']['idsede_partenza']);
unset($_SESSION['superselect']['idsede_destinazione']);
+unset($_SESSION['superselect']['codice_modalita_pagamento_fe']);
$_SESSION['superselect']['idanagrafica'] = $record['idanagrafica'];
$_SESSION['superselect']['idsede_partenza'] = $record['idsede_partenza'];
$_SESSION['superselect']['idsede_destinazione'] = $record['idsede_destinazione'];
@@ -152,7 +153,7 @@ $_SESSION['superselect']['idsede_destinazione'] = $record['idsede_destinazione']
- {[ "type": "select", "label": "", "name": "idpagamento", "values": "query=SELECT id, descrizione FROM co_pagamenti GROUP BY descrizione ORDER BY descrizione ASC", "value": "$idpagamento$", "readonly": "" ]}
+ {[ "type": "select", "label": "", "name": "idpagamento", "ajax-source": "pagamenti", "value": "$idpagamento$", "readonly": "" ]}
diff --git a/modules/fatture/buttons.php b/modules/fatture/buttons.php
index ff5e74888..18696befa 100644
--- a/modules/fatture/buttons.php
+++ b/modules/fatture/buttons.php
@@ -13,9 +13,11 @@ echo '
'.tr('Duplica fattura').'
';
-if ($record['stato'] != 'Emessa' && $record['stato'] != 'Parzialmente pagato' && $record['stato'] != 'Pagato') {
+if ($module->name == 'Fatture di vendita') {
+ $attributi_visibili = $record['stato'] != 'Emessa' && $record['stato'] != 'Parzialmente pagato' && $record['stato'] != 'Pagato';
+
echo '
-
+
'.tr('Attributi avanzati').'
';
}
diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php
index c7edafd72..99f422482 100644
--- a/modules/fatture/edit.php
+++ b/modules/fatture/edit.php
@@ -11,6 +11,7 @@ $tipodoc = $rs[0]['descrizione'];
unset($_SESSION['superselect']['idanagrafica']);
unset($_SESSION['superselect']['idsede_partenza']);
unset($_SESSION['superselect']['idsede_destinazione']);
+unset($_SESSION['superselect']['codice_modalita_pagamento_fe']);
$_SESSION['superselect']['idsede_partenza'] = $record['idsede_partenza'];
$_SESSION['superselect']['idsede_destinazione'] = $record['idsede_destinazione'];
$_SESSION['superselect']['idanagrafica'] = $record['idanagrafica'];
@@ -201,7 +202,7 @@ if (empty($record['is_fiscale'])) {
- {[ "type": "select", "label": "", "name": "idpagamento", "required": 1, "values": "query=SELECT id, CONCAT_WS(' - ', codice_modalita_pagamento_fe, descrizione) AS descrizione, (SELECT id FROM co_banche WHERE id_pianodeiconti3 = co_pagamenti.idconto_ LIMIT 0,1) AS idbanca FROM co_pagamenti GROUP BY descrizione ORDER BY descrizione ASC", "value": "$idpagamento$", "extra": "onchange=\"$('#idbanca').val( $(this).find('option:selected').data('idbanca') ).change(); \" " ]}
+ {[ "type": "select", "label": "", "name": "idpagamento", "required": 1, "ajax-source": "pagamenti", "value": "$idpagamento$", "extra": "onchange=\"$('#idbanca').val($(this).selectData().id_banca_).change(); \" " ]}
diff --git a/modules/ordini/edit.php b/modules/ordini/edit.php
index 5130e8707..9d3aaf2a9 100644
--- a/modules/ordini/edit.php
+++ b/modules/ordini/edit.php
@@ -9,6 +9,7 @@ if ($module['name'] == 'Ordini cliente') {
$dir = 'uscita';
}
+unset($_SESSION['superselect']['codice_modalita_pagamento_fe']);
$_SESSION['superselect']['idanagrafica'] = $record['idanagrafica'];
?>
- {[ "type": "select", "label": "", "name": "idpagamento", "required": 1, "values": "query=SELECT id, descrizione FROM co_pagamenti GROUP BY descrizione ORDER BY descrizione ASC", "value": "$idpagamento$", "readonly": "" ]}
+ {[ "type": "select", "label": "", "name": "idpagamento", "required": 1, "ajax-source": "pagamenti", "value": "$idpagamento$", "readonly": "" ]}
diff --git a/modules/pagamenti/ajax/select.php b/modules/pagamenti/ajax/select.php
new file mode 100644
index 000000000..6be2570f6
--- /dev/null
+++ b/modules/pagamenti/ajax/select.php
@@ -0,0 +1,26 @@
+';
// Riferimenti ad altre fatture
-if (in_array($dati_generali['TipoDocumento'], ['TD04', 'TD05'])){
+if (in_array($dati_generali['TipoDocumento'], ['TD04', 'TD05'])) {
$anagrafica = $fattura_pa->saveAnagrafica();
$query = "SELECT
co_documenti.id,
CONCAT('Fattura num. ', co_documenti.numero_esterno, ' del ', DATE_FORMAT(co_documenti.data, '%d/%m/%Y')) AS descrizione
- FROM
- co_documenti INNER JOIN co_tipidocumento ON co_tipidocumento.id = co_documenti.idtipodocumento
+ FROM co_documenti
+ INNER JOIN co_tipidocumento ON co_tipidocumento.id = co_documenti.idtipodocumento
WHERE
co_tipidocumento.dir = 'uscita' AND
+ (co_documenti.data BETWEEN NOW() - INTERVAL 1 YEAR AND NOW()) AND
+ co_documenti.idstatodocumento IN (SELECT id FROM co_statidocumento WHERE co_tipidocumento.descrizione != 'Bozza') AND
co_documenti.idanagrafica = ".prepare($anagrafica->id);
echo '
{[ "type": "select", "label": "'.tr('Fattura collegata').'", "name": "ref_fattura", "required": 1, "values": "query='.$query.'" ]}
';
-}elseif ($dati_generali['TipoDocumento'] == 'TD06'){
+} elseif ($dati_generali['TipoDocumento'] == 'TD06') {
$anagrafica = $fattura_pa->saveAnagrafica();
+ $query = "SELECT
+ co_documenti.id,
+ CONCAT('Fattura num. ', co_documenti.numero_esterno, ' del ', DATE_FORMAT(co_documenti.data, '%d/%m/%Y')) AS descrizione
+ FROM co_documenti
+ INNER JOIN co_tipidocumento ON co_tipidocumento.id = co_documenti.idtipodocumento
+ WHERE
+ co_tipidocumento.dir = 'uscita' AND
+ (co_documenti.data BETWEEN NOW() - INTERVAL 1 YEAR AND NOW()) AND
+ co_documenti.idstatodocumento IN (SELECT id FROM co_statidocumento WHERE co_tipidocumento.descrizione != 'Bozza') AND
+ co_documenti.id_segment = (SELECT id FROM zz_segments WHERE name = 'Fatture pro-forma' AND id_module = ".prepare($id_module).') AND
+ co_documenti.idanagrafica = '.prepare($anagrafica->id);
echo '
- {[ "type": "select", "label": "'.tr('Fattura collegata').'", "name": "ref_fattura", "values": "query='.$query.'" ]}
+ {[ "type": "select", "label": "'.tr('Fattura pro-forma').'", "name": "ref_fattura", "values": "query='.$query.'" ]}
';
}
@@ -155,18 +168,19 @@ if (!empty($pagamenti)) {
';
}
-// prc '.($pagamenti['CondizioniPagamento'] == 'TP01' ? '!' : '').'= 100 AND
-$query = 'SELECT id, CONCAT (descrizione, IF((codice_modalita_pagamento_fe IS NULL), \"\", CONCAT( \" (\", codice_modalita_pagamento_fe, \")\" ) )) as descrizione FROM co_pagamenti';
if (!empty($codice_modalita_pagamento)) {
- $query .= ' WHERE codice_modalita_pagamento_fe = '.prepare($codice_modalita_pagamento);
+ $_SESSION['superselect']['codice_modalita_pagamento_fe'] = $codice_modalita_pagamento;
}
-$query .= ' GROUP BY descrizione ORDER BY descrizione ASC';
// Pagamento
echo '
- {[ "type": "select", "label": "'.tr('Pagamento').'", "name": "pagamento", "required": 1, "values": "query='.$query.'" ]}
+
+ '.tr('Reset modalità').'
+
+
+ {[ "type": "select", "label": "'.tr('Pagamento').'", "name": "pagamento", "required": 1, "ajax-source": "pagamenti" ]}
';
// Movimentazioni
diff --git a/plugins/importFE/src/FatturaElettronica.php b/plugins/importFE/src/FatturaElettronica.php
index c1328f165..1a8e250ba 100644
--- a/plugins/importFE/src/FatturaElettronica.php
+++ b/plugins/importFE/src/FatturaElettronica.php
@@ -110,14 +110,17 @@ class FatturaElettronica
public static function manage($name)
{
try {
- $fattura = new FatturaOrdinaria($name);
+ $manager = new FatturaOrdinaria($name);
- return $fattura;
+ $tipo = $manager->getBody()['DatiGenerali']['DatiGeneraliDocumento']['TipoDocumento'];
+ if ($tipo == 'TD06') {
+ $manager = new Parcella($name);
+ }
} catch (UnexpectedValueException $e) {
- $fattura = new FatturaSemplificata($name);
-
- return $fattura;
+ $manager = new FatturaSemplificata($name);
}
+
+ return $manager;
}
public function getHeader()
@@ -188,6 +191,7 @@ class FatturaElettronica
* Restituisce l'anagrafica collegata alla fattura, eventualmente generandola con i dati forniti.
*
* @param string $type
+ *
* @return Anagrafica
*/
public function saveAnagrafica($type = 'Fornitore')
@@ -273,29 +277,25 @@ class FatturaElettronica
/**
* Registra la fattura elettronica come fattura del gestionale.
*
- * @param int $id_pagamento
- * @param int $id_sezionale
- * @param int $id_tipo
+ * @param int $id_pagamento
+ * @param int $id_sezionale
+ * @param int $id_tipo
* @param string $data_registrazione
- * @param int $ref_fattura
+ * @param int $ref_fattura
*
* @return Fattura
*/
- public function saveFattura($id_pagamento, $id_sezionale, $id_tipo, $data_registrazione, $ref_fattura = null)
+ public function saveFattura($id_pagamento, $id_sezionale, $id_tipo, $data_registrazione, $ref_fattura)
{
- $anagrafica = $this->saveAnagrafica();
-
$dati_generali = $this->getBody()['DatiGenerali']['DatiGeneraliDocumento'];
$data = $dati_generali['Data'];
+ $fattura = $this->prepareFattura($id_tipo, $data, $id_sezionale, $ref_fattura);
+ $this->fattura = $fattura;
+
$numero_esterno = $dati_generali['Numero'];
$progressivo_invio = $this->getHeader()['DatiTrasmissione']['ProgressivoInvio'];
- $tipo = TipoFattura::where('id', $id_tipo)->first();
-
- $fattura = Fattura::build($anagrafica, $tipo, $data, $id_sezionale);
- $this->fattura = $fattura;
-
$fattura->progressivo_invio = $progressivo_invio;
$fattura->numero_esterno = $numero_esterno;
$fattura->idpagamento = $id_pagamento;
@@ -360,6 +360,21 @@ class FatturaElettronica
return $this->getFattura()->id;
}
+ protected function prepareFattura($id_tipo, $data, $id_sezionale, $ref_fattura)
+ {
+ $anagrafica = $this->saveAnagrafica();
+
+ $tipo = TipoFattura::where('id', $id_tipo)->first();
+
+ $fattura = Fattura::build($anagrafica, $tipo, $data, $id_sezionale);
+ $this->fattura = $fattura;
+
+ // Riferimento per nota di credito e debito
+ $fattura->ref_documento = $ref_fattura ?: null;
+
+ return $fattura;
+ }
+
protected function forceArray($result)
{
$result = isset($result[0]) ? $result : [$result];
diff --git a/plugins/importFE/src/Parcella.php b/plugins/importFE/src/Parcella.php
new file mode 100644
index 000000000..d70ae284d
--- /dev/null
+++ b/plugins/importFE/src/Parcella.php
@@ -0,0 +1,48 @@
+saveAnagrafica();
+
+ $tipo = TipoFattura::where('id', $id_tipo)->first();
+
+ $fattura = Fattura::find($ref_fattura);
+
+ // Rimozione righe precedenti (query per evitare procedure automatiche di compensazione)
+ database()->query('DELETE FROM co_righe_documenti WHERE iddocumento = '.prepare($fattura->id));
+
+ $fattura->anagrafica()->associate($anagrafica);
+ $fattura->tipo()->associate($tipo);
+ $fattura->data = $data;
+ $fattura->id_segment = $id_sezionale;
+
+ return $fattura;
+ }
+}
diff --git a/update/2_4_11.sql b/update/2_4_11.sql
index b35bcafbe..7c61ad21a 100644
--- a/update/2_4_11.sql
+++ b/update/2_4_11.sql
@@ -116,3 +116,6 @@ INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `e
INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES
(NULL, 'OSMCloud Services API Version', 'v2', 'string', 0, 'Fatturazione Elettronica', 11);
DELETE FROM `zz_settings` WHERE `nome` = 'apilayer API key for Email';
+
+-- Fatture pro-forma di acquisto
+INSERT INTO `zz_segments` (`id`, `id_module`, `name`, `clause`, `position`, `pattern`, `is_fiscale`) VALUES (NULL, '15', 'Fatture pro-forma', '1=1', 'WHR', 'PRO-###', '1');