|
50 | 50 | SUM(`subtotale`) as subtotale, |
51 | 51 | SUM(`totale`) as totale, |
52 | 52 | SUM(`iva`) AS iva, |
53 | | - `ragione_sociale`, |
54 | | - `codice_anagrafica` |
| 53 | + `ragione_sociale` |
55 | 54 | FROM |
56 | 55 | ( |
57 | 56 | SELECT |
|
70 | 69 | IF(`numero` = "", `numero_esterno`, `numero`) AS numero, |
71 | 70 | SUM((`subtotale`-`sconto`+`co_righe_documenti`.`rivalsainps`)*(IF(`co_tipidocumento`.`reversed` = 0, 1,-1 ))) AS subtotale, |
72 | 71 | SUM((`subtotale`-`sconto`+`co_righe_documenti`.`rivalsainps`+`iva`+`co_righe_documenti`.`rivalsainps` * `percentuale`/100)*(IF(`co_tipidocumento`.`reversed` = 0, 1,-1 ))) AS totale, |
73 | | - SUM((`subtotale`-`sconto`+`co_righe_documenti`.`rivalsainps`) *`percentuale`/100 *(100-`indetraibile`)/100 *(IF(`co_tipidocumento`.`reversed` = 0, 1,-1 ))) AS iva, |
74 | | - `an_anagrafiche`.`ragione_sociale`, |
75 | | - `an_anagrafiche`.`codice` AS codice_anagrafica |
| 72 | + SUM((`subtotale`-`sconto`+`co_righe_documenti`.`rivalsainps`) *`percentuale`/100 *(100-`indetraibile`)/100 *(IF(`co_tipidocumento`.`reversed` = 0, 1,-1 ))) AS iva_detraibile, |
| 73 | + SUM((`subtotale`-`sconto`+`co_righe_documenti`.`rivalsainps`) *`percentuale`/100 *`indetraibile`/100 *(IF(`co_tipidocumento`.`reversed` = 0, 1,-1 ))) AS iva_indetraibile, |
| 74 | + `an_anagrafiche`.`ragione_sociale` |
76 | 75 | FROM |
77 | 76 | `co_iva` |
78 | 77 | LEFT JOIN `co_iva_lang` ON (`co_iva`.`id` = `co_iva_lang`.`id_record` AND `co_iva_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') |
|
85 | 84 | GROUP BY |
86 | 85 | `co_iva`.`id`, `co_documenti`.`id` |
87 | 86 | HAVING |
88 | | - data_competenza_iva BETWEEN '.prepare($date_start).' AND '.prepare($date_end).' |
| 87 | + data_competenza_iva BETWEEN '.prepare($date_start).' AND '.prepare($date_end).', totale > 0 |
89 | 88 | UNION |
90 | 89 | SELECT |
91 | 90 | `vb_venditabanco`.`data` as data_competenza_iva, |
|
99 | 98 | `vb_venditabanco`.`numero` AS numero, |
100 | 99 | SUM(`vb_righe_venditabanco`.`subtotale`) as subtotale, |
101 | 100 | SUM(`subtotale`-`sconto` + `iva`) as totale, |
102 | | - SUM(`iva`) as iva, |
103 | | - `an_anagrafiche`.`ragione_sociale`, |
104 | | - `an_anagrafiche`.`codice` AS codice_anagrafica |
| 101 | + SUM(`iva`) AS iva_detraibile, |
| 102 | + 0 AS `iva_indetraibile`, |
| 103 | + `an_anagrafiche`.`ragione_sociale` |
105 | 104 | FROM `co_iva` |
106 | 105 | LEFT JOIN `co_iva_lang` ON (`co_iva`.`id` = `co_iva_lang`.`id_record` AND `co_iva_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') |
107 | 106 | INNER JOIN `vb_righe_venditabanco` ON `vb_righe_venditabanco`.`idiva` = `co_iva`.`id` |
|
117 | 116 | data_competenza_iva BETWEEN '.prepare($date_start).' AND '.prepare($date_end).' |
118 | 117 | ) AS tabella |
119 | 118 | GROUP BY |
120 | | - `data_competenza_iva`, `iva`, `id`, `data_registrazione`, `data`, `numero_esterno`, `codice_tipo_documento_fe`, `percentuale`, `descrizione`, `numero`, `ragione_sociale`, `codice_anagrafica` |
| 119 | + `data_competenza_iva`, `iva`, `id`, `data_registrazione`, `data`, `numero_esterno`, `codice_tipo_documento_fe`, `percentuale`, `descrizione`, `numero`, `ragione_sociale` |
121 | 120 | ORDER BY CAST(`numero_esterno` AS UNSIGNED)'; |
122 | 121 | } else { |
123 | 122 | $query = ' |
|
134 | 133 | `co_iva`.`percentuale`, |
135 | 134 | `co_iva_lang`.`title` as descrizione, |
136 | 135 | `co_documenti`.`id` AS id, |
| 136 | + `co_documenti`.`split_payment`, |
137 | 137 | IF(`numero` = "", `numero_esterno`, `numero`) AS numero, |
138 | 138 | SUM((`subtotale`-`sconto`+`co_righe_documenti`.`rivalsainps`)*(IF(`co_tipidocumento`.`reversed` = 0, 1,-1 ))) AS subtotale, |
139 | 139 | SUM((`subtotale`-`sconto`+`co_righe_documenti`.`rivalsainps`+`iva`+`co_righe_documenti`.`rivalsainps` * `percentuale`/100)*(IF(`co_tipidocumento`.`reversed` = 0, 1,-1 ))) AS totale, |
140 | | - SUM((`subtotale`-`sconto`+`co_righe_documenti`.`rivalsainps`) *`percentuale`/100 *(100-`indetraibile`)/100 *(IF(`co_tipidocumento`.`reversed` = 0, 1,-1 ))) AS iva, |
141 | | - `an_anagrafiche`.`ragione_sociale`, |
142 | | - `an_anagrafiche`.`codice` AS codice_anagrafica |
| 140 | + SUM((`subtotale`-`sconto`+`co_righe_documenti`.`rivalsainps`) *`percentuale`/100 *(100-`indetraibile`)/100 *(IF(`co_tipidocumento`.`reversed` = 0, 1,-1 ))) AS iva_detraibile, |
| 141 | + SUM((`subtotale`-`sconto`+`co_righe_documenti`.`rivalsainps`) *`percentuale`/100 *`indetraibile`/100 *(IF(`co_tipidocumento`.`reversed` = 0, 1,-1 ))) AS iva_indetraibile, |
| 142 | + `an_anagrafiche`.`ragione_sociale` |
143 | 143 | FROM |
144 | 144 | `co_iva` |
145 | 145 | LEFT JOIN `co_iva_lang` ON (`co_iva`.`id` = `co_iva_lang`.`id_record` AND `co_iva_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') |
|
152 | 152 | GROUP BY |
153 | 153 | `co_iva`.`id`, `co_documenti`.`id` |
154 | 154 | HAVING |
155 | | - data_competenza_iva BETWEEN '.prepare($date_start).' AND '.prepare($date_end).' |
| 155 | + data_competenza_iva BETWEEN '.prepare($date_start).' AND '.prepare($date_end).', totale > 0 |
156 | 156 | ORDER BY |
157 | 157 | CAST( IF(`dir`="entrata", `co_documenti`.`numero_esterno`, `co_documenti`.`numero`) AS UNSIGNED)'; |
158 | 158 | } |
|
0 commit comments