Exemplo n.º 1
0
        private void ImpostaQuadroIVa(List <FatturaRiga> righeFatt, Fattura fattura)
        {
            decimal importoIvaTot    = 0;
            decimal imponibileIVaTot = 0;
            var     rigaIniziale     = 1;

            if (fattura.TipoDocumento == EnTipoDocumento.FatturaDiCortesia ||
                fattura.TipoDocumento == EnTipoDocumento.RicevutaFiscale ||
                fattura.TipoDocumento == EnTipoDocumento.NotaDiCredito)
            {
                foreach (var item in righeFatt.Where(a => a.Importo > 0 && a.IvaApplicata.Length > 0).GroupBy(a => a.IvaApplicata).OrderBy(a => a.Key))
                {
                    var imponibileIVa = item.Select(a => a.Importo).DefaultIfEmpty(0).Sum();
                    ImpostaRigaIva(rigaIniziale, 1, item.Key);
                    ImpostaRigaIva(rigaIniziale, 2, imponibileIVa.ToString("C2"));
                    decimal importoIva = 0;
                    decimal val;
                    if (decimal.TryParse(item.Key, out val))
                    {
                        importoIva = imponibileIVa * ((decimal)val) / ((decimal)100);
                    }
                    ImpostaRigaIva(rigaIniziale, 3, importoIva.ToString("C2"));
                    importoIvaTot    += importoIva;
                    imponibileIVaTot += imponibileIVa;
                    rigaIniziale++;
                }

                _excel.Range("ImportoIVa").Value    = (importoIvaTot).ToString("C2");
                _excel.Range("ImportoTotale").Value = (imponibileIVaTot).ToString("C2");
                var tot = "Totale Fattura";
                if (fattura.TipoDocumento == EnTipoDocumento.NotaDiCredito)
                {
                    tot = "Totale Nota";
                }
                _excel.Range("Totale").Value = tot + ":  " +
                                               (imponibileIVaTot + importoIvaTot).ToString("C2");
            }
            else
            {
                _excel.Range("QuadroDDTDaCancellare").Clear(ClosedXML.Excel.XLClearOptions.Contents);
            }
        }