protected void grdFatture_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { e.Row.Cells[3].Text = "Imponibile"; e.Row.Cells[6].Text = "Valore Iva"; e.Row.Cells[7].Text = "Valore Rit. Acc."; e.Row.Cells[8].Text = "Imp. Fattura"; e.Row.Cells[9].Text = "Reverse Charge"; e.Row.Cells[10].Text = "Nota Credito"; } else if (e.Row.RowType == DataControlRowType.DataRow) { long rowIdFattura = Convert.ToInt64((e.Row.FindControl("hfRowIdFattura") as HiddenField).Value); FatturaAcquisto fattura = FattureAcquistoDAO.GetSingle(rowIdFattura); double imponibile = fattura.Imponibile; double valoreIva = imponibile * fattura.Iva / 100; double valoreRitenutaAcconto = imponibile * fattura.RitenutaAcconto / 100; (e.Row.FindControl("lblValoreIva") as Label).Text = valoreIva.ToString("N2"); (e.Row.FindControl("lblValoreRitenutaAcconto") as Label).Text = valoreRitenutaAcconto.ToString("N2"); double importoFattura = imponibile + valoreIva - valoreRitenutaAcconto; (e.Row.FindControl("lblImportoFattura") as Label).Text = importoFattura.ToString("N2"); // Scrivo i totali generali totaleImporto += importoFattura; } }
protected void btnInsFattura_Click(object sender, EventArgs e) { try { if (ddlScegliFornitore.SelectedIndex > 0 && txtImponibile.Text != "" && txtData.Text != "") { // Inserisco la fattura FattureAcquistoDAO.Insert(PopolaFatturaObj()); lblMessaggio.ForeColor = Color.Blue; lblMessaggio.Text = "Fattura Acquisto inserita con successo"; ResetToInitial(); } else { lblMessaggio.ForeColor = Color.Red; lblMessaggio.Text = "I campi Fornitore e Imponibile devono essere compilati"; } } catch (Exception ex) { lblMessaggio.ForeColor = Color.Red; lblMessaggio.Text = $"Errore durante l'inserimento della Fattura Acquisto ===> {ex.Message}"; } }
private void PopolaCampi(int idFatturaAcquisto, bool isModifica) { FatturaAcquisto fatt = FattureAcquistoDAO.GetSingle(idFatturaAcquisto); txtNumeroFattura.Text = fatt.Numero.ToString(); ddlScegliFornitore.SelectedValue = fatt.IdFornitore.ToString(); txtData.Text = fatt.Data.ToString("yyyy-MM-dd"); txtData.TextMode = TextBoxMode.Date; txtImponibile.Text = fatt.Imponibile.ToString(); txtRitenutaAcconto.Text = fatt.RitenutaAcconto.ToString(); txtIva.Text = fatt.Iva.ToString(); chkNotaCredito.Checked = fatt.IsNotaDiCredito; chkReverseCharge.Checked = fatt.ReverseCharge; txtConcatenazione.Text = $"Fat. {fatt.Numero.ToString()} del {fatt.Data.ToString("dd/MM/yyyy")}"; // Accessibilità campi txtNumeroFattura.ReadOnly = txtData.ReadOnly = !isModifica; txtImponibile.ReadOnly = txtRitenutaAcconto.ReadOnly = txtIva.ReadOnly = !isModifica; txtFiltroFornitore.ReadOnly = !isModifica; chkNotaCredito.Enabled = chkReverseCharge.Enabled = isModifica; ddlScegliFornitore.Enabled = isModifica; // Visibilità pannelli pnlInsFatture.Visible = true; pnlRicercaFatture.Visible = !pnlInsFatture.Visible; }
private void BindGrid(int anno) { grdTotaleIvaPerQuarter.DataSource = FattureAcquistoDAO.GetTotaliFatture(anno).Select(s => new { Trimestre = s.quarter, TotaleIvaAcquisto = s.totaleAcquisto, TotaleIvaEmesso = s.totaleEmesso, Saldo = s.saldo }); grdTotaleIvaPerQuarter.DataBind(); }
public IHttpActionResult GetFattureAcquisto([FromUri] string year, [FromUri] string numFattura) { try { List <FatturaAcquisto> items = FattureAcquistoDAO.GetByAnnoNumero(Convert.ToInt32(year), Convert.ToInt32(numFattura)); return(Ok(items)); } catch (Exception ex) { string messaggio = $"Errore durante la GetFattureEmesse in FattureController --- {ex}"; log.Error(messaggio); return(BadRequest(messaggio)); } }
protected void grdFatture_RowCommand(object sender, GridViewCommandEventArgs e) { int idFattura = Convert.ToInt32(e.CommandArgument.ToString()); if (e.CommandName == "Visualizza") { ResetToInitial(); PopolaCampi(idFattura, false); btnInsFattura.Visible = btnModFattura.Visible = false; } else if (e.CommandName == "Modifica") { ResetToInitial(); PopolaCampi(idFattura, true); btnInsFattura.Visible = false; btnModFattura.Visible = !btnInsFattura.Visible; hfIdFattura.Value = idFattura.ToString(); } else if (e.CommandName == "Elimina") { bool isDeleted = false; try { FattureAcquistoDAO.Delete(idFattura); isDeleted = true; } catch (Exception) { lblMessaggio.Text = "Errore durante l'eliminazione di una fattura acquisto"; lblMessaggio.ForeColor = Color.Red; } if (isDeleted) { lblMessaggio.ForeColor = Color.Blue; lblMessaggio.Text = "Fattura eliminato con successo"; } else { lblMessaggio.ForeColor = Color.Red; lblMessaggio.Text = "Errore durante l'eliminazione della Fattura acquisto"; } ResetToInitial(); } }
private void SetLabels() { double totaleImponibileEmesso = 0, totaleFatturatoEmesso = 0, totaleImponibileAcquisto = 0, totaleFatturatoAcquisto = 0; int anno = txtFiltroAnno.Text != "" ? Convert.ToInt32(txtFiltroAnno.Text) : 0; List <Fattura> fatture = FattureDAO.GetAll(); List <FatturaAcquisto> fattureAcquisto = FattureAcquistoDAO.GetAll(); if (anno != 0) { fatture = fatture.Where(w => w.Data.Year == anno).ToList(); fattureAcquisto = fattureAcquisto.Where(w => w.Data.Year == anno).ToList(); } if (fatture.Count() > 0) { totaleImponibileEmesso = fatture.Sum(s => s.Imponibile); totaleFatturatoEmesso = fatture.Sum(s => s.Imponibile + (s.Imponibile * s.Iva / 100) - (s.Imponibile * s.RitenutaAcconto / 100)); } if (fatture.Count() > 0) { totaleImponibileAcquisto = fattureAcquisto.Sum(s => s.Imponibile); totaleFatturatoAcquisto = fattureAcquisto.Sum(s => s.Imponibile + (s.Imponibile * s.Iva / 100) - (s.Imponibile * s.RitenutaAcconto / 100)); } decimal totaleBollette = BolletteDAO.GetTotale(anno); // Fatture Emesse lblFattureEmesseTotaleImponibile.Text = $"Totale imponibile emesso: <strong>{totaleImponibileEmesso:N2}</strong>"; lblFattureEmesseTotaleFatturato.Text = $"Totale fatturato emesso: <strong>{totaleFatturatoEmesso:N2}</strong>"; // Fatture Acquisto lblFattureAcquistoTotaleImponibile.Text = $"Totale imponibile acquisto: <strong>{totaleImponibileAcquisto:N2}</strong>"; lblFattureAcquistoTotaleFatturato.Text = $"Totale fatturato acquisto: <strong>{totaleFatturatoAcquisto:N2}</strong>"; //Differenze lblDifferenzaTotaleImponibile.Text = $"Differenza totale imponibile: <strong>{totaleImponibileEmesso - totaleImponibileAcquisto:N2}</strong>"; lblDifferenzaTotaleFatturato.Text = $"Differenza totale fatturato: <strong>{totaleFatturatoEmesso - totaleFatturatoAcquisto:N2}</strong>"; // Bollette e Utile lblTotaleBollette.Text = $"Totale bollette: <strong>{totaleBollette:N2}</strong>"; lblUtile.Text = $"Utile: <strong>{totaleImponibileEmesso - totaleImponibileAcquisto - Convert.ToDouble(totaleBollette / 2):N2}</strong>"; hfUtile.Value = (totaleImponibileEmesso - totaleImponibileAcquisto - Convert.ToDouble(totaleBollette / 2)).ToString("N2"); BindGrid(anno); }
protected void BindGrid(bool needToUpdateGrid) { if (needToUpdateGrid) { int numeroFattura = txtFiltroGrdNumeroFattura.Text != "" ? Convert.ToInt32(txtFiltroGrdNumeroFattura.Text) : 0; int anno = txtFiltroGrdAnno.Text == "" ? DateTime.Now.Year : Convert.ToInt32(txtFiltroGrdAnno.Text); List <FatturaAcquisto> fatture = FattureAcquistoDAO.GetFattureAcquisto(txtFiltroGrdAnno.Text, txtFiltroGrdDataDa.Text, txtFiltroGrdDataA.Text, txtFiltroGrdFornitore.Text, numeroFattura); grdFatture.DataSource = fatture; grdFatture.DataBind(); grdTotaleIvaPerQuarter.DataSource = FattureAcquistoDAO.GetTotaliIvaPerQuarter(anno).Select(s => new { Trimestre = s.quarter, TotaleIva = s.totaleIva.ToString("N2") }); grdTotaleIvaPerQuarter.DataBind(); grdTotaleImponibilePerQuarter.DataSource = FattureAcquistoDAO.GetTotaliImponibilePerQuarter(anno).Select(s => new { Trimestre = s.quarter, TotaleIva = s.totaleIva.ToString("N2") }); grdTotaleImponibilePerQuarter.DataBind(); grdTotaleImportoPerQuarter.DataSource = FattureAcquistoDAO.GetTotaliImportoPerQuarter(anno).Select(s => new { Trimestre = s.quarter, TotaleIva = s.totaleIva.ToString("N2") }); grdTotaleImportoPerQuarter.DataBind(); grdTotali.DataSource = FattureAcquistoDAO.GetTotaliFatture(txtFiltroGrdFornitore.Text, txtFiltroGrdAnno.Text, numeroFattura, txtFiltroGrdDataDa.Text, txtFiltroGrdDataA.Text).Select(s => new { Titolo = s.titolo, Valore = s.valore.ToString("N2") }); grdTotali.DataBind(); } }
protected void btnModFattura_Click(object sender, EventArgs e) { try { if (FattureAcquistoDAO.Update(PopolaFatturaObj())) { lblMessaggio.ForeColor = Color.Blue; lblMessaggio.Text = "Fattura Acquisto aggiornata con successo"; } else { lblMessaggio.ForeColor = Color.Red; lblMessaggio.Text = "Errore durante l'aggiornamento della Fattura"; } } catch (Exception ex) { lblMessaggio.ForeColor = Color.Red; lblMessaggio.Text = $"Errore durante l'aggiornamento del Fattura Acquisto ===> {ex.Message}"; } ResetToInitial(); }
private void SetNumeroFattura(int year = 0) { string numeroFattura = ""; string nuovoNumeroFattura = ""; List <FatturaAcquisto> fatture = FattureAcquistoDAO.GetAll().Where(w => w.Data.Year == (year > 0 ? year : DateTime.Now.Year)).ToList(); if (fatture.Count() == 0) { numeroFattura = "001"; } else { nuovoNumeroFattura = (fatture.Select(s => s.Numero).Max() + 1).ToString(); if (nuovoNumeroFattura.Length == 1) { numeroFattura = "00"; } if (nuovoNumeroFattura.Length == 2) { numeroFattura = "0"; } } txtNumeroFattura.Text = $"{numeroFattura}{nuovoNumeroFattura}"; }