mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
Aggiunta tabella fe_stati_documento_lang
This commit is contained in:
@@ -22,6 +22,7 @@ include_once __DIR__.'/../../core.php';
|
||||
use Carbon\Carbon;
|
||||
use Modules\Fatture\Fattura;
|
||||
use Plugins\ExportFE\Interaction;
|
||||
use Modules\Fatture\StatoFE;
|
||||
use Util\XML;
|
||||
|
||||
$services_enable = Interaction::isEnabled();
|
||||
@@ -46,7 +47,7 @@ if ($module->name == 'Fatture di vendita' && $services_enable) {
|
||||
$documenti = Fattura::where('data', '>', $data_limite)->where('data', '>', $data_setting)->whereIn('codice_stato_fe', ['EC02', 'ERR', 'ERVAL', 'NS', 'GEN', 'QUEUE'])->get();
|
||||
|
||||
foreach ($documenti as $documento) {
|
||||
$stato_fe = $database->fetchOne('SELECT descrizione, icon FROM fe_stati_documento WHERE codice = '.prepare($documento->codice_stato_fe));
|
||||
$stato_fe = StatoFE::find($documento->codice_stato_fe)->id_record;
|
||||
|
||||
if (in_array($documento->codice_stato_fe, $codici_scarto)) {
|
||||
// In caso di NS verifico che non sia semplicemente un codice 00404 (Fattura duplicata)
|
||||
|
@@ -294,7 +294,7 @@ $query .= ' ORDER BY `name`';
|
||||
?>
|
||||
|
||||
<div class="col-md-2" <?php echo ($is_fiscale) ? '' : 'hidden'; ?> >
|
||||
{[ "type": "select", "label": "<?php echo tr('Stato FE'); ?>", "name": "codice_stato_fe", "values": "query=SELECT codice as id, CONCAT_WS(' - ',codice,descrizione) as text FROM fe_stati_documento", "value": "$codice_stato_fe$", "disabled": <?php echo intval(Interaction::isEnabled() || ($record['stato'] == 'Bozza' && $abilita_genera)); ?>, "class": "unblockable", "help": "<?php echo (!empty($record['data_stato_fe'])) ? Translator::timestampToLocale($record['data_stato_fe']) : ''; ?>" ]}
|
||||
{[ "type": "select", "label": "<?php echo tr('Stato FE'); ?>", "name": "codice_stato_fe", "values": "query=SELECT `codice` as id, CONCAT_WS(' - ',`codice`, `name`) as text FROM `fe_stati_documento` LEFT JOIN `fe_stati_documento_lang` ON (`fe_stati_documento_lang`.`id_record` = `fe_stati_documento`.`codice` AND `fe_stati_documento_lang`.`id_lang` = <?php echo prepare(setting('Lingua')); ?>)", "value": "$codice_stato_fe$", "disabled": <?php echo intval(Interaction::isEnabled() || ($record['stato'] == 'Bozza' && $abilita_genera)); ?>, "class": "unblockable", "help": "<?php echo (!empty($record['data_stato_fe'])) ? Translator::timestampToLocale($record['data_stato_fe']) : ''; ?>" ]}
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
use Modules\Fatture\Fattura;
|
||||
use Modules\Fatture\StatoFE;
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
@@ -67,7 +68,7 @@ if (isset($id_record)) {
|
||||
$note_accredito = $dbo->fetchArray("SELECT `co_documenti`.`id`, IF(`numero_esterno` != '', `numero_esterno`, `numero`) AS numero, data FROM `co_documenti` JOIN `co_tipidocumento` ON `co_documenti`.`idtipodocumento`=`co_tipidocumento`.`id` WHERE `reversed` = 1 AND `ref_documento`=".prepare($id_record));
|
||||
|
||||
// Blocco gestito dallo stato della Fattura Elettronica
|
||||
$stato_fe = $database->fetchOne('SELECT * FROM `fe_stati_documento` WHERE `codice` = '.prepare($fattura->codice_stato_fe));
|
||||
$stato_fe = StatoFE::find($fattura->codice_stato_fe)->id_record;
|
||||
$abilita_genera = empty($fattura->codice_stato_fe) || intval($stato_fe['is_generabile']);
|
||||
|
||||
// Controllo autofattura e gestione avvisi
|
||||
|
@@ -26,6 +26,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Models\Upload;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Banche\Banca;
|
||||
use Modules\Fatture\StatoFE;
|
||||
use Modules\Fatture\Gestori\Bollo as GestoreBollo;
|
||||
use Modules\Fatture\Gestori\Movimenti as GestoreMovimenti;
|
||||
use Modules\Fatture\Gestori\Scadenze as GestoreScadenze;
|
||||
@@ -645,7 +646,7 @@ class Fattura extends Document
|
||||
|
||||
// Operazioni automatiche per le Fatture Elettroniche
|
||||
if ($this->direzione == 'entrata' && $stato_precedente->name == 'Bozza' && $stato->name == 'Emessa') {
|
||||
$stato_fe = database()->fetchOne('SELECT * FROM fe_stati_documento WHERE codice = '.prepare($this->codice_stato_fe));
|
||||
$stato_fe = StatoFE::find($this->codice_stato_fe);
|
||||
$abilita_genera = empty($this->codice_stato_fe) || intval($stato_fe['is_generabile']);
|
||||
|
||||
// Generazione automatica della Fattura Elettronica
|
||||
|
@@ -34,4 +34,34 @@ class StatoFE extends Model
|
||||
{
|
||||
return $this->hasMany(Fattura::class, 'codice_stato_fe');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ritorna l'attributo name dello stato fe.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return database()->table($this->table.'_lang')
|
||||
->select('name')
|
||||
->where('id_record', '=', $this->codice)
|
||||
->where('id_lang', '=', setting('Lingua'))
|
||||
->first()->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ritorna l'id dello stato fe a partire dal nome.
|
||||
*
|
||||
* @param string $name il nome da ricercare
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getByName($name)
|
||||
{
|
||||
return database()->table($this->table.'_lang')
|
||||
->select('id_record')
|
||||
->where('name', '=', $name)
|
||||
->where('id_lang', '=', setting('Lingua'))
|
||||
->first();
|
||||
}
|
||||
}
|
||||
|
@@ -21,11 +21,12 @@ include_once __DIR__.'/init.php';
|
||||
|
||||
use Plugins\ExportFE\FatturaElettronica;
|
||||
use Plugins\ExportFE\Interaction;
|
||||
use Modules\Fatture\StatoFE;
|
||||
use Util\XML;
|
||||
|
||||
if ($fattura !== null) {
|
||||
/* Per le PA EC02 e EC01 sono dei stati successivi a NE il quale a sua volta è successivo a RC. EC01 e EC02 sono definiti all'interno della ricevuta di NE che di fatto indica il rifiuto o l'accettazione. */
|
||||
$stato_fe = $database->fetchOne('SELECT * FROM fe_stati_documento WHERE codice = '.prepare($fattura->codice_stato_fe));
|
||||
$stato_fe = StatoFE::find($fattura->codice_stato_fe)->id_record;
|
||||
$abilita_genera = $fattura->stato->name != 'Bozza' && (empty($fattura->codice_stato_fe) || intval($stato_fe['is_generabile']));
|
||||
$ricevuta_principale = $fattura->getRicevutaPrincipale();
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Modules\Fatture\Fattura;
|
||||
use Modules\Fatture\StatoFE;
|
||||
use Plugins\ExportFE\Interaction;
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
@@ -47,7 +48,7 @@ foreach ($recepits as $nome) {
|
||||
$codice_stato = $pieces[2];
|
||||
|
||||
// Informazioni sullo stato indicato
|
||||
$stato_fe = $database->fetchOne('SELECT * FROM fe_stati_documento WHERE codice = '.prepare($codice_stato));
|
||||
$stato_fe = StatoFE::find($codice_stato)->id_record;
|
||||
|
||||
echo '
|
||||
<tr data-name="'.$nome.'">
|
||||
|
@@ -671,33 +671,6 @@ HAVING
|
||||
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`co_tipidocumento_lang`.`name`' WHERE `zz_modules`.`name` = 'Tipi documento' AND `zz_views`.`name` = 'Descrizione';
|
||||
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`co_tipidocumento`.`id`' WHERE `zz_modules`.`name` = 'Tipi documento' AND `zz_views`.`name` = 'id';
|
||||
|
||||
-- Allineamento vista Fatture di vendita
|
||||
UPDATE `zz_modules` SET `options` = "
|
||||
SELECT
|
||||
|select|
|
||||
FROM
|
||||
`co_documenti`
|
||||
LEFT JOIN (SELECT SUM(`totale`) AS `totale`, `iddocumento` FROM `co_movimenti` WHERE `totale` > 0 AND `primanota` = 1 GROUP BY `iddocumento`) AS `primanota` ON `primanota`.`iddocumento` = `co_documenti`.`id`
|
||||
LEFT JOIN `an_anagrafiche` ON `co_documenti`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`
|
||||
LEFT JOIN `co_tipidocumento` ON `co_documenti`.`idtipodocumento` = `co_tipidocumento`.`id`
|
||||
LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento`.`id` = `co_tipidocumento_lang`.`id_record` AND co_tipidocumento_lang.|lang|)
|
||||
LEFT JOIN (SELECT `iddocumento`, SUM(`subtotale` - `sconto`) AS `totale_imponibile`, SUM((`subtotale` - `sconto` + `rivalsainps`) * `co_iva`.`percentuale` / 100) AS `iva` FROM `co_righe_documenti` LEFT JOIN `co_iva` ON `co_iva`.`id` = `co_righe_documenti`.`idiva` GROUP BY `iddocumento`) AS `righe` ON `co_documenti`.`id` = `righe`.`iddocumento`
|
||||
LEFT JOIN (SELECT `co_banche`.`id`, CONCAT(`co_banche`.`nome`, ' - ', `co_banche`.`iban`) AS `descrizione` FROM `co_banche` GROUP BY `co_banche`.`id`) AS `banche` ON `banche`.`id` =`co_documenti`.`id_banca_azienda`
|
||||
LEFT JOIN `co_statidocumento` ON `co_documenti`.`idstatodocumento` = `co_statidocumento`.`id`
|
||||
LEFT JOIN `co_statidocumento_lang` ON (`co_statidocumento`.`id` = `co_statidocumento_lang`.`id_record` AND co_statidocumento_lang.|lang|)
|
||||
LEFT JOIN `fe_stati_documento` ON `co_documenti`.`codice_stato_fe` = `fe_stati_documento`.`codice`
|
||||
LEFT JOIN `co_ritenuta_contributi` ON `co_documenti`.`id_ritenuta_contributi` = `co_ritenuta_contributi`.`id`
|
||||
LEFT JOIN (SELECT COUNT(id) as `emails`, `em_emails`.`id_record` FROM `em_emails` INNER JOIN `zz_operations` ON `zz_operations`.`id_email` = `em_emails`.`id` WHERE `id_module` IN(SELECT `id` FROM `zz_modules` WHERE name = 'Fatture di vendita') AND `zz_operations`.`op` = 'send-email' GROUP BY `em_emails`.`id_record`) AS `email` ON `email`.`id_record` = `co_documenti`.`id`
|
||||
LEFT JOIN `co_pagamenti` ON `co_documenti`.`idpagamento` = `co_pagamenti`.`id`
|
||||
LEFT JOIN `co_pagamenti_lang` ON (`co_pagamenti`.`id` = `co_pagamenti_lang`.`id_record` AND co_pagamenti_lang.|lang|)
|
||||
LEFT JOIN (SELECT `numero_esterno`, `id_segment`, `idtipodocumento`, `data` FROM `co_documenti` WHERE `co_documenti`.`idtipodocumento` IN( SELECT `id` FROM `co_tipidocumento` WHERE `dir` = 'entrata') AND `numero_esterno` != '' GROUP BY `id_segment`, `numero_esterno`, `idtipodocumento` HAVING COUNT(`numero_esterno`) > 1 |date_period(`co_documenti`.`data`)| ) dup ON `co_documenti`.`numero_esterno` = `dup`.`numero_esterno` AND `dup`.`id_segment` = `co_documenti`.`id_segment` AND `dup`.`idtipodocumento` = `co_documenti`.`idtipodocumento`
|
||||
WHERE
|
||||
1=1 AND `dir` = 'entrata' |segment(`co_documenti`.`id_segment`)| |date_period(`co_documenti`.`data`)|
|
||||
HAVING
|
||||
2=2
|
||||
ORDER BY
|
||||
`co_documenti`.`data` DESC,
|
||||
CAST(`co_documenti`.`numero_esterno` AS UNSIGNED) DESC" WHERE `name` = 'Fatture di vendita';
|
||||
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`co_tipidocumento_lang`.`name`' WHERE `zz_modules`.`name` = 'Fatture di vendita' AND `zz_views`.`name` = 'Tipo';
|
||||
|
||||
-- Allineamento vista Fatture di acquisto
|
||||
@@ -1212,4 +1185,54 @@ ALTER TABLE `fe_regime_fiscale`
|
||||
|
||||
ALTER TABLE `fe_regime_fiscale_lang` ADD CONSTRAINT `fe_regime_fiscale_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `fe_regime_fiscale`(`codice`) ON DELETE CASCADE ON UPDATE RESTRICT;
|
||||
|
||||
UPDATE `zz_settings` SET `tipo` = 'query=SELECT `codice` AS id, CONCAT(`codice`, \' - \', `name`)as descrizione FROM fe_regime_fiscale LEFT JOIN `fe_regime_fiscale_lang` ON (`fe_regime_fiscale_lang`.`id_record`=`fe_regime_fiscale`.`codice` AND `fe_regime_fiscale_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = \'Lingua\'))' WHERE `zz_settings`.`nome` = 'Regime fiscale';
|
||||
UPDATE `zz_settings` SET `tipo` = 'query=SELECT `codice` AS id, CONCAT(`codice`, \' - \', `name`)as descrizione FROM fe_regime_fiscale LEFT JOIN `fe_regime_fiscale_lang` ON (`fe_regime_fiscale_lang`.`id_record`=`fe_regime_fiscale`.`codice` AND `fe_regime_fiscale_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = \'Lingua\'))' WHERE `zz_settings`.`nome` = 'Regime fiscale';
|
||||
|
||||
-- Aggiunta tabella fe_stati_documento_lang
|
||||
CREATE TABLE IF NOT EXISTS `fe_stati_documento_lang` (
|
||||
`id` int NOT NULL,
|
||||
`id_lang` int NOT NULL,
|
||||
`id_record` varchar(5) NOT NULL,
|
||||
`name` VARCHAR(255) NOT NULL
|
||||
);
|
||||
ALTER TABLE `fe_stati_documento_lang`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
ALTER TABLE `fe_stati_documento_lang`
|
||||
MODIFY `id` int NOT NULL AUTO_INCREMENT;
|
||||
|
||||
INSERT INTO `fe_stati_documento_lang` (`id`, `id_lang`, `id_record`, `name`) SELECT NULL, (SELECT `id` FROM `zz_langs` WHERE `iso_code` = 'it'), `codice`, `descrizione` FROM `fe_stati_documento`;
|
||||
|
||||
ALTER TABLE `fe_stati_documento`
|
||||
DROP `descrizione`;
|
||||
|
||||
ALTER TABLE `fe_stati_documento_lang` ADD CONSTRAINT `fe_stati_documento_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `fe_stati_documento`(`codice`) ON DELETE CASCADE ON UPDATE RESTRICT;
|
||||
|
||||
-- Allineamento vista Fatture di vendita
|
||||
UPDATE `zz_modules` SET `options` = "
|
||||
SELECT
|
||||
|select|
|
||||
FROM
|
||||
`co_documenti`
|
||||
LEFT JOIN (SELECT SUM(`totale`) AS `totale`, `iddocumento` FROM `co_movimenti` WHERE `totale` > 0 AND `primanota` = 1 GROUP BY `iddocumento`) AS `primanota` ON `primanota`.`iddocumento` = `co_documenti`.`id`
|
||||
LEFT JOIN `an_anagrafiche` ON `co_documenti`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`
|
||||
LEFT JOIN `co_tipidocumento` ON `co_documenti`.`idtipodocumento` = `co_tipidocumento`.`id`
|
||||
LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento`.`id` = `co_tipidocumento_lang`.`id_record` AND co_tipidocumento_lang.|lang|)
|
||||
LEFT JOIN (SELECT `iddocumento`, SUM(`subtotale` - `sconto`) AS `totale_imponibile`, SUM((`subtotale` - `sconto` + `rivalsainps`) * `co_iva`.`percentuale` / 100) AS `iva` FROM `co_righe_documenti` LEFT JOIN `co_iva` ON `co_iva`.`id` = `co_righe_documenti`.`idiva` GROUP BY `iddocumento`) AS `righe` ON `co_documenti`.`id` = `righe`.`iddocumento`
|
||||
LEFT JOIN (SELECT `co_banche`.`id`, CONCAT(`co_banche`.`nome`, ' - ', `co_banche`.`iban`) AS `descrizione` FROM `co_banche` GROUP BY `co_banche`.`id`) AS `banche` ON `banche`.`id` =`co_documenti`.`id_banca_azienda`
|
||||
LEFT JOIN `co_statidocumento` ON `co_documenti`.`idstatodocumento` = `co_statidocumento`.`id`
|
||||
LEFT JOIN `co_statidocumento_lang` ON (`co_statidocumento`.`id` = `co_statidocumento_lang`.`id_record` AND `co_statidocumento_lang`.|lang|)
|
||||
LEFT JOIN `fe_stati_documento` ON `co_documenti`.`codice_stato_fe` = `fe_stati_documento`.`codice`
|
||||
LEFT JOIN `fe_stati_documento_lang` ON (`fe_stati_documento`.`codice` = `fe_stati_documento_lang`.`id_record` AND `fe_stati_documento_lang`.|lang|)
|
||||
LEFT JOIN `co_ritenuta_contributi` ON `co_documenti`.`id_ritenuta_contributi` = `co_ritenuta_contributi`.`id`
|
||||
LEFT JOIN (SELECT COUNT(id) as `emails`, `em_emails`.`id_record` FROM `em_emails` INNER JOIN `zz_operations` ON `zz_operations`.`id_email` = `em_emails`.`id` WHERE `id_module` IN(SELECT `id` FROM `zz_modules` WHERE name = 'Fatture di vendita') AND `zz_operations`.`op` = 'send-email' GROUP BY `em_emails`.`id_record`) AS `email` ON `email`.`id_record` = `co_documenti`.`id`
|
||||
LEFT JOIN `co_pagamenti` ON `co_documenti`.`idpagamento` = `co_pagamenti`.`id`
|
||||
LEFT JOIN `co_pagamenti_lang` ON (`co_pagamenti`.`id` = `co_pagamenti_lang`.`id_record` AND co_pagamenti_lang.|lang|)
|
||||
LEFT JOIN (SELECT `numero_esterno`, `id_segment`, `idtipodocumento`, `data` FROM `co_documenti` WHERE `co_documenti`.`idtipodocumento` IN( SELECT `id` FROM `co_tipidocumento` WHERE `dir` = 'entrata') AND `numero_esterno` != '' GROUP BY `id_segment`, `numero_esterno`, `idtipodocumento` HAVING COUNT(`numero_esterno`) > 1 |date_period(`co_documenti`.`data`)| ) dup ON `co_documenti`.`numero_esterno` = `dup`.`numero_esterno` AND `dup`.`id_segment` = `co_documenti`.`id_segment` AND `dup`.`idtipodocumento` = `co_documenti`.`idtipodocumento`
|
||||
WHERE
|
||||
1=1 AND `dir` = 'entrata' |segment(`co_documenti`.`id_segment`)| |date_period(`co_documenti`.`data`)|
|
||||
HAVING
|
||||
2=2
|
||||
ORDER BY
|
||||
`co_documenti`.`data` DESC,
|
||||
CAST(`co_documenti`.`numero_esterno` AS UNSIGNED) DESC" WHERE `name` = 'Fatture di vendita';
|
||||
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`fe_stati_documento_lang`.`name`' WHERE `zz_modules`.`name` = 'Fatture di vendita' AND `zz_views`.`name` = 'icon_title_FE';
|
||||
|
@@ -98,6 +98,7 @@ return [
|
||||
'fe_regime_fiscale',
|
||||
'fe_regime_fiscale_lang',
|
||||
'fe_stati_documento',
|
||||
'fe_stati_documento_lang',
|
||||
'fe_tipi_documento',
|
||||
'fe_tipo_cassa',
|
||||
'fe_tipi_ritenuta',
|
||||
|
Reference in New Issue
Block a user