示例#1
0
        //Stampa PDF

        public void ExportToPdfPerContoFinCli(List <MaterialiCantieri> matCantList)
        {
            decimal           totale     = 0m;
            int               idCantiere = Convert.ToInt32(ddlScegliCant.SelectedValue);
            Cantieri          cant       = CantieriDAO.GetSingle(idCantiere);
            MaterialiCantieri mc         = new MaterialiCantieri
            {
                RagSocCli     = cant.RagSocCli,
                CodCant       = cant.CodCant,
                DescriCodCant = cant.DescriCodCant
            };

            //Apro lo stream verso il file PDF
            Document pdfDoc = new Document(PageSize.A4, 8f, 2f, 2f, 2f);

            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();

            PdfPTable table = RicalcoloContiManager.InitializePdfTableDDT();

            Phrase title = new Phrase($"Ragione Sociale Cliente: {mc.RagSocCli}", FontFactory.GetFont("Arial", 16, iTextSharp.text.Font.BOLD, BaseColor.BLACK));

            pdfDoc.Add(title);

            RicalcoloContiManager.GeneraPDFPerContoFinCli(pdfDoc, mc, table, matCantList, totale, idCantiere, ddlScegliTipoNote.SelectedValue);

            pdfDoc.Close();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=" + mc.RagSocCli + ".pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Write(pdfDoc);
            Response.End();
        }
示例#2
0
        // UPDATE
        public static bool UpdateCantiere(Cantieri c)
        {
            bool          ret = false;
            StringBuilder sql = new StringBuilder();

            sql.AppendLine($"UPDATE TblCantieri");
            sql.AppendLine($"SET IdTblClienti = @IdTblClienti, Data = CONVERT(date,@Data),");
            sql.AppendLine($"CodCant = @CodCant, DescriCodCAnt = @DescriCodCAnt,");
            sql.AppendLine($"Indirizzo = @Indirizzo, Città = @Città,");
            sql.AppendLine($"Ricarico = @Ricarico, PzzoManodopera = @PzzoManodopera,");
            sql.AppendLine($"Chiuso = @Chiuso, Riscosso = @Riscosso,");
            sql.AppendLine($"Numero = @Numero, ValorePreventivo = @ValorePreventivo,");
            sql.AppendLine($"IVA = @IVA, Anno = @Anno,");
            sql.AppendLine($"Preventivo = @Preventivo, FasciaTblCantieri = @FasciaTblCantieri,");
            sql.AppendLine($"DaDividere = @DaDividere, Diviso = @Diviso,");
            sql.AppendLine($"Fatturato = @Fatturato, NonRiscuotibile = @NonRiscuotibile,");
            sql.AppendLine($"codRiferCant = @CodRiferCant, id_preventivo = @IdPreventivo");
            sql.AppendLine($"WHERE IdCantieri = @IdCantieri");
            try
            {
                using (SqlConnection cn = GetConnection())
                {
                    ret = cn.Execute(sql.ToString(), c) > 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Errore durante l'aggiornamento del cantiere {c.IdCantieri}", ex);
            }
            return(ret);
        }
示例#3
0
        /* Necessario per la creazione della GridView con intestazioni dinamiche */
        /* Definisce l'ordinamento dei dati presenti nella GridView */
        protected void grdStampaVerificaCant_Sorting(object sender, GridViewSortEventArgs e)
        {
            int      idCantiere = Convert.ToInt32(ddlScegliCant.SelectedItem.Value);
            Cantieri cant       = CantieriDAO.GetSingle(idCantiere);
            List <MaterialiCantieri> materiali = RicalcoloContiManager.GetMaterialiCantieri(idCantiere);

            BindGrid(cant, materiali.Sum(s => s.Valore));
        }
示例#4
0
        protected void BindGrid(Cantieri cant, decimal totaleValore)
        {
            decimal totMate       = 0m;
            decimal totRientro    = 0m;
            decimal totManodop    = 0m;
            decimal totOreManodop = 0m;
            decimal totOper       = 0m;
            decimal totArrot      = 0m;
            decimal totChiam      = 0m;
            decimal totSpese      = 0m;
            int     idCantiere    = Convert.ToInt32(ddlScegliCant.SelectedItem.Value);

            List <MaterialiCantieri> matCantList = MaterialiCantieriDAO.GetMaterialeCantiere(idCantiere.ToString());

            grdStampaVerificaCant.DataSource = matCantList;
            grdStampaVerificaCant.DataBind();

            lblIntestStampa.Text     = $"<strong>CodCant</strong>: {cant.CodCant} --- <strong>DescriCodCant</strong>: {cant.DescriCodCant} --- <strong>Cliente</strong>: {cant.RagSocCli}";
            lblTotContoCliente.Text  = "<strong>Tot. Conto/Preventivo</strong>: ";
            lblTotContoCliente.Text += (cant.Preventivo ? Math.Round(cant.ValorePreventivo, 2) : Math.Round(totaleValore, 2)).ToString();

            totMate             += matCantList.Where(w => w.Tipologia.ToUpper() == "MATERIALE").Sum(s => (decimal)s.Qta * s.PzzoUniCantiere);
            totRientro          += matCantList.Where(w => w.Tipologia.ToUpper() == "RIENTRO").Sum(s => (decimal)s.Qta * s.PzzoUniCantiere);
            totManodop          += matCantList.Where(w => w.Tipologia.ToUpper() == "MANODOPERA").Sum(s => (decimal)s.Qta * s.PzzoUniCantiere);
            totOreManodop       += matCantList.Where(w => w.Tipologia.ToUpper() == "MANODOPERA").Sum(s => (decimal)s.Qta);
            totOper             += matCantList.Where(w => w.Tipologia.ToUpper() == "OPERAIO").Sum(s => (decimal)s.Qta * s.PzzoUniCantiere);
            totArrot            += matCantList.Where(w => w.Tipologia.ToUpper() == "ARROTONDAMENTO").Sum(s => (decimal)s.Qta * s.PzzoUniCantiere);
            totSpese            += matCantList.Where(w => w.Tipologia.ToUpper() == "SPESA" || w.Tipologia.ToUpper() == "SPESE").Sum(s => (decimal)s.Qta * s.PzzoUniCantiere);
            totChiam            += matCantList.Where(w => w.Tipologia.ToUpper() == "A CHIAMATA").Sum(s => (decimal)s.Qta * s.PzzoUniCantiere);
            lblTotMate.Text      = $"<strong>Tot. Materiale</strong>: {totMate:n}";
            lblTotRientro.Text   = $"<strong>Tot. Rientro</strong>: {totRientro:n}";
            lblTotOper.Text      = $"<strong>Tot. Operaio</strong>: {totOper:n}";
            lblTotArrot.Text     = $"<strong>Tot. Arrotondamento</strong>: {totArrot:n}";
            lblTotAChiamata.Text = $"<strong>Tot. A Chiamata</strong>: {totChiam:n}";
            lblTotSpese.Text     = $"<strong>Tot. Spese</strong>: {totSpese:n}";

            decimal sommaTotPerTipol = totMate + totRientro + totOper;
            decimal contoFinCli      = Convert.ToDecimal(lblTotContoCliente.Text.Split(':')[1].Trim());
            decimal totGuadagno      = Convert.ToDecimal($"{contoFinCli - sommaTotPerTipol - totManodop - totSpese + totArrot + totChiam:n}");

            lblTotGuadagno.Text = $"<strong>Totale Guadagno</strong>: {totGuadagno:n}";
            lblTotManodop.Text  = $"<strong>Tot. Manodopera</strong>: {totManodop:n}";

            decimal totGuadConManodop = totGuadagno + totManodop;

            lblTotGuadagnoConManodop.Text    = $"<strong>Tot. Guadagno Con Manodopopera</strong>: {totGuadConManodop}";
            lblTotGuadagnoOrarioManodop.Text = $"<strong>Tot. Guadagno Orario Manodopopera</strong>: {totGuadConManodop / (totOreManodop == 0 ? 1 : totOreManodop):n}";
        }
        protected void CompilaCampi(int idCantiere, decimal totale)
        {
            //Popolo il campo Conto/Preventivo
            Cantieri c = CantieriDAO.GetSingle(idCantiere);

            txtContoPreventivo.Text = c.Preventivo ? string.Format("{0:n}", c.ValorePreventivo) : Math.Round(totale, 2).ToString();

            //Popolo il campo Tot. Acconti
            decimal totAcconti = 0m;

            totAcconti           = PagamentiDAO.GetAll().Where(w => w.IdTblCantieri == idCantiere).ToList().Sum(s => s.Imporo);
            txtTotPagamenti.Text = $"{totAcconti:n}";

            //Popolo il campo Tot. Finale
            decimal totContoPreventivo = Convert.ToDecimal(txtContoPreventivo.Text);
            decimal totFin             = totContoPreventivo - totAcconti;

            txtTotFinale.Text = $"{totFin:n}";
        }
示例#6
0
        private void PopolaCampi(int idFattura, bool isModifica)
        {
            Fattura fatt = FattureDAO.GetSingle(idFattura);
            List <FatturaCantiere> fatCantieri = FattureCantieriDAO.GetByIdFattura(fatt.IdFatture);
            List <FatturaAcconto>  fatAcconti  = FattureAccontiDAO.GetByIdFattura(fatt.IdFatture);
            Cantieri cantiere = null;

            if (fatCantieri.Count > 0)
            {
                cantiere = CantieriDAO.GetSingle(fatCantieri?.FirstOrDefault().IdCantieri ?? 0);
            }

            txtNumeroFattura.Text          = fatt.Numero.ToString();
            ddlScegliCliente.SelectedValue = fatt.IdClienti.ToString();
            fatCantieri.ForEach(f => lblShowCantieriAggiunti.Text += (lblShowCantieriAggiunti.Text == "" ? "" : ",") + CantieriDAO.GetSingle(f.IdCantieri).CodCant);
            txtData.Text     = fatt.Data.ToString("yyyy-MM-dd");
            txtData.TextMode = TextBoxMode.Date;
            fatAcconti.ForEach(f => lblShowAccontiAggiunti.Text += (lblShowAccontiAggiunti.Text == "" ? "" : "-") + f.ValoreAcconto.ToString());
            txtImponibile.Text       = fatt.Imponibile.ToString();
            txtRitenutaAcconto.Text  = fatt.RitenutaAcconto.ToString();
            txtIva.Text              = fatt.Iva.ToString();
            chkNotaCredito.Checked   = fatt.IsNotaDiCredito;
            chkReverseCharge.Checked = fatt.ReverseCharge;
            chkRiscosso.Checked      = fatt.Riscosso;
            txtConcatenazione.Text   = $"Fat. {fatt.Numero} del {fatt.Data:dd/MM/yyyy}";

            if (cantiere != null)
            {
                txtConcatenazione.Text += $" - {cantiere.CodCant}";
            }

            // Accessibilità campi
            txtNumeroFattura.ReadOnly = txtData.ReadOnly = txtValoreAcconto.ReadOnly = !isModifica;
            txtImponibile.ReadOnly    = txtRitenutaAcconto.ReadOnly = txtIva.ReadOnly = !isModifica;
            txtFiltroCliente.ReadOnly = txtFiltroCodCantiere.ReadOnly = txtFiltroDescrizioneCantiere.ReadOnly = !isModifica;
            chkNotaCredito.Enabled    = chkReverseCharge.Enabled = chkRiscosso.Enabled = isModifica;
            ddlScegliCantiere.Enabled = ddlScegliCliente.Enabled = isModifica;

            // Visibilità pannelli
            pnlInsFatture.Visible     = true;
            pnlRicercaFatture.Visible = !pnlInsFatture.Visible;
        }
        protected void PopolaCampiCantiere(int idCant, bool isControlEnabled)
        {
            EnableDisableFields(pnlTxtBoxCantContainer, isControlEnabled);

            //Deseleziono tutti gli elementi della dropdownlist
            foreach (ListItem item in ddlScegliClientePerCantiere.Items)
            {
                item.Selected = false;
            }

            Cantieri cant = CantieriDAO.GetSingle(idCant);

            // Seleziono il cliente con la Ragione Sociale associata al cantiere di riferimento
            ddlScegliClientePerCantiere.SelectedValue = ddlScegliClientePerCantiere.Items.FindByText(cant.RagSocCli).Value;
            ddlScegliPreventivoCant.SelectedValue     = "-1";

            //Popolo i textbox
            txtDataInserCant.Text         = cant.Data.ToString("yyyy-MM-dd");
            txtDataInserCant.TextMode     = TextBoxMode.Date;
            txtCodCant.Text               = cant.CodCant;
            txtDescrCodCant.Text          = cant.DescriCodCant;
            txtCodiceRiferimentoCant.Text = cant.CodRiferCant;
            //txtIndirizzoCant.Text = cant.Indirizzo;
            //txtCittaCant.Text = cant.Città;
            txtRicaricoCant.Text       = cant.Ricarico.ToString();
            txtPzzoManodopCant.Text    = cant.PzzoManodopera.ToString("N2");
            txtNumeroCant.Text         = cant.Numero.ToString();
            txtValPrevCant.Text        = cant.ValorePreventivo.ToString("N2");
            txtIvaCant.Text            = cant.Iva.ToString();
            txtAnnoCant.Text           = cant.Anno.ToString();
            txtFasciaCant.Text         = cant.FasciaTblCantieri.ToString();
            txtConcatenazioneCant.Text = $"{cant.CodCant}-{cant.DescriCodCant}";

            //Spunto i checkbox se necessario
            chkCantChiuso.Checked      = cant.Chiuso;
            chkCantRiscosso.Checked    = cant.Riscosso;
            chkPreventivo.Checked      = cant.Preventivo;
            chkDaDividere.Checked      = cant.DaDividere;
            chkDiviso.Checked          = cant.Diviso;
            chkFatturato.Checked       = cant.Fatturato;
            chkNonRiscuotibile.Checked = cant.NonRiscuotibile;
        }
示例#8
0
        protected void btnStampaVerificaCant_Click(object sender, EventArgs e)
        {
            //Ricreo i passaggi della "Stampa Ricalcolo Conti" per ottenere il valore del "Totale Ricalcolo"
            //MaterialiCantieri mc = new MaterialiCantieri
            //{
            //    RagSocCli = cant.RagSocCli,
            //    CodCant = cant.CodCant,
            //    DescriCodCant = cant.DescriCodCant
            //};
            //PdfPTable pTable = RicalcoloContiManager.InitializePdfTableDDT();
            //Document pdfDoc = new Document(PageSize.A4, 8f, 2f, 2f, 2f);
            //pdfDoc.Open();
            //RicalcoloContiManager.GeneraPDFPerContoFinCli(pdfDoc, mc, pTable, materiali, 0, idCantiere);
            //pdfDoc.Close();

            int      idCantiere = Convert.ToInt32(ddlScegliCant.SelectedItem.Value);
            Cantieri cant       = CantieriDAO.GetSingle(idCantiere);
            List <MaterialiCantieri> materiali = RicalcoloContiManager.GetMaterialiCantieri(idCantiere);

            pnlViewGridAndLabels.Visible = true;
            BindGrid(cant, materiali.Sum(s => s.Valore));
            GroupGridViewCells();
        }
示例#9
0
        public static Cantieri GetSingle(int idCantiere)
        {
            Cantieri      ret = new Cantieri();
            StringBuilder sql = new StringBuilder();

            sql.AppendLine($"SELECT Cant.*, Cli.RagSocCli");
            sql.AppendLine($"FROM TblCantieri AS Cant");
            sql.AppendLine($"JOIN TblClienti AS Cli ON Cant.IdTblClienti = Cli.IdCliente");
            sql.AppendLine($"WHERE Cant.IdCantieri = @idCantiere");
            sql.AppendLine($"ORDER BY Cant.CodCant");
            try
            {
                using (SqlConnection cn = GetConnection())
                {
                    ret = cn.Query <Cantieri>(sql.ToString(), new { idCantiere }).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Errore durante la GetSingle in CantieriDAO", ex);
            }
            return(ret);
        }
        protected void btnStampaContoCliente_Click(object sender, EventArgs e)
        {
            //Ricreo i passaggi della "Stampa Ricalcolo Conti" per ottenere il valore del "Totale Ricalcolo"
            int               idCantiere = Convert.ToInt32(ddlScegliCant.SelectedItem.Value);
            Cantieri          cant       = CantieriDAO.GetSingle(idCantiere);
            MaterialiCantieri mc         = new MaterialiCantieri
            {
                RagSocCli     = cant.RagSocCli,
                CodCant       = cant.CodCant,
                DescriCodCant = cant.DescriCodCant
            };

            PdfPTable pTable = RicalcoloContiManager.InitializePdfTableDDT();
            Document  pdfDoc = new Document(PageSize.A4, 8f, 2f, 2f, 2f);

            pdfDoc.Open();
            List <MaterialiCantieri> materiali = RicalcoloContiManager.GetMaterialiCantieri(idCantiere);

            RicalcoloContiManager.GeneraPDFPerContoFinCli(pdfDoc, mc, pTable, materiali, 0, idCantiere);
            pdfDoc.Close();

            //Popolo i campi di riepilogo con i dati necessari
            CompilaCampi(idCantiere, materiali.Sum(s => s.Valore));
        }
示例#11
0
        // INSERT
        public static bool InserisciCantiere(Cantieri c)
        {
            bool          ret = false;
            StringBuilder sql = new StringBuilder();

            sql.AppendLine($"INSERT INTO TblCantieri (IdTblClienti,Data,CodCant,DescriCodCAnt,Indirizzo,Città,Ricarico,");
            sql.AppendLine($"PzzoManodopera,Chiuso,Riscosso,Numero,ValorePreventivo,IVA,Anno,Preventivo,");
            sql.AppendLine($"FasciaTblCantieri,DaDividere,Diviso,Fatturato,NonRiscuotibile,CodRiferCant,id_preventivo)");
            sql.AppendLine($"VALUES (@IdTblClienti,CONVERT(date,@Data),@CodCant,@DescriCodCAnt,@Indirizzo,@Città,@Ricarico,");
            sql.AppendLine($"@PzzoManodopera,@Chiuso,@Riscosso,@Numero,@ValorePreventivo,@IVA,@Anno,@Preventivo,@FasciaTblCantieri,");
            sql.AppendLine($"@DaDividere,@Diviso,@Fatturato,@NonRiscuotibile,@CodRiferCant,@IdPreventivo)");
            try
            {
                using (SqlConnection cn = GetConnection())
                {
                    ret = cn.Execute(sql.ToString(), c) > 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Errore durante l'inserimento di un nuovo cantiere", ex);
            }
            return(ret);
        }
示例#12
0
        protected void btnStampaContoCliente_Click(object sender, EventArgs e)
        {
            try
            {
                List <Cantieri> listaCantieri = CantieriDAO.GetCantieri(txtAnno.Text, Convert.ToInt32(ddlScegliCliente.SelectedValue), chkFatturato.Checked, chkChiuso.Checked, chkRiscosso.Checked, chkNonRiscuotibile.Checked);

                if (listaCantieri.Count() > 0)
                {
                    List <MaterialiCantieri> materiali = MaterialiCantieriDAO.GetByListOfCantieri(RicalcoloContiManager.GetStringFromListForQuery(listaCantieri.Select(s => s.IdCantieri).ToList()));
                    List <Pagamenti>         pagamenti = PagamentiDAO.GetAll();
                    List <Database.Models.StampaValoriCantieriConOpzioni> gridViewItems = new List <Database.Models.StampaValoriCantieriConOpzioni>();

                    materiali.ForEach(f =>
                    {
                        Cantieri cantiere = listaCantieri.Where(w => w.IdCantieri == f.IdTblCantieri).FirstOrDefault();
                        Database.Models.StampaValoriCantieriConOpzioni objStampa = new Database.Models.StampaValoriCantieriConOpzioni
                        {
                            CodCant       = cantiere.CodCant,
                            DescriCodCAnt = cantiere.DescriCodCant,
                            RagSocCli     = cantiere.RagSocCli
                        };

                        objStampa.TotaleAcconti = objStampa.TotaleConto = objStampa.TotaleFinale = 0m;

                        //Popolo il campo Conto/Preventivo
                        objStampa.TotaleConto = cantiere.Preventivo ? cantiere.ValorePreventivo : Math.Round(RicalcoloContiManager.GetMaterialiCantieri(cantiere.IdCantieri).Sum(s => s.Valore), 2);

                        //Popolo il campo Tot. Acconti
                        decimal totAcconti      = 0m;
                        totAcconti              = pagamenti.Where(w => w.IdTblCantieri == cantiere.IdCantieri).ToList().Sum(s => s.Imporo);
                        objStampa.TotaleAcconti = totAcconti;

                        //Popolo il campo Tot. Finale
                        decimal totContoPreventivo = objStampa.TotaleConto;
                        decimal totFin             = totContoPreventivo - totAcconti;
                        objStampa.TotaleFinale     = totFin;

                        if (RicalcoloContiManager.CalcolaPercentualeTotaleMaterialiNascosti(f.IdTblCantieri) == -1)
                        {
                            objStampa.TotaleAcconti = objStampa.TotaleConto = objStampa.TotaleFinale = -999.99m;
                        }

                        //Aggiungo l'oggetto alla lista
                        gridViewItems.Add(objStampa);
                    });

                    gridViewItems = gridViewItems.GroupBy(s => new { s.CodCant, s.DescriCodCAnt, s.RagSocCli, s.TotaleConto, s.TotaleAcconti, s.TotaleFinale }).Distinct().Select(s => s.First()).ToList();
                    grdStampaConOpzioni.DataSource = gridViewItems;
                    grdStampaConOpzioni.DataBind();

                    // Metto i dati in sessione per poter successivamente creare l'excel senza dover rifare tutto il giro
                    Session["StampaValConOpzData"] = gridViewItems;

                    // Assegno il valore alla label che mostra il totale generale
                    decimal totGen = gridViewItems.Sum(s => s.TotaleFinale);

                    for (int i = 0; i < grdStampaConOpzioni.Rows.Count; i++)
                    {
                        //if (grdStampaConOpzioni.Rows[i].Cells[5].Text == "0")
                        //{
                        //    grdStampaConOpzioni.Rows[i].Visible = false;
                        //}

                        // Se il totale Conto mostra un valore palesemente errato, la cella viene modificata mostrando l'errore invece del valore del cantiere
                        if (grdStampaConOpzioni.Rows[i].Cells[3].Text == "-999,99")
                        {
                            grdStampaConOpzioni.Rows[i].Cells[3].Text      = grdStampaConOpzioni.Rows[i].Cells[4].Text = grdStampaConOpzioni.Rows[i].Cells[5].Text = "VEDI VALORI NON VISIBILI";
                            grdStampaConOpzioni.Rows[i].Cells[3].BackColor = grdStampaConOpzioni.Rows[i].Cells[4].BackColor = grdStampaConOpzioni.Rows[i].Cells[5].BackColor = Color.Red;
                        }
                    }

                    lblTotaleGeneraleStampa.Text = $"Totale: {totGen:N2} €";

                    // Nascondo eventuali alert visualizzati in precedenza
                    (Master as layout).HideAlert();
                }
                else
                {
                    Session["StampaValConOpzData"] = null;
                    (Master as layout).SetAlert("alert-warning", "Non ci sono cantieri che corrispondano ai filtri impostati");
                }
            }
            catch (Exception ex)
            {
                Session["StampaValConOpzData"] = null;
                (Master as layout).SetAlert("alert-danger", $"Errore durante la stampa del cantiere ==> {ex.Message}");
            }
        }