private void OnOpenInvoice(object sender, EventArgs e) { var invCtrl = (UI.InvoiceListItem)sender; SelectedInvoice = invCtrl.ProformaInvoice; OpenInvoice?.Invoke(this, e); }
public InvoiceFrm(DataModels.ProformaInvoice invoice) { InitializeComponent(); _proformaInvoice = invoice; if (invoice == null) { this.Close(); } }
public InvoiceCtrl(DataModels.ProformaInvoice proformaInvoice, bool edit = false) { InitializeComponent(); ProformaInvoice = proformaInvoice; _edit = edit; _printProInvoiceTT.SetToolTip(this.buttonPrintProformaInvoice, "Stampa la fattura proforma"); _printInvoiceTT.SetToolTip(this.buttonPrintInvoice, "Stampa la fattura"); ProformaInvoice.Visitsproformainvoiceidfkeys = ProformaInvoice.Visitsproformainvoiceidfkeys.Where(x => x.Deleted == false).ToList(); using (var db = new Db.PhisioDB()) { ProformaInvoice.Invoice = db.Invoices.LoadWith(e1 => e1.Visitsinvoiceidfkeys.First().Treatmentsvisitidfkeys.First().Treatment).LoadWith(e1 => e1.Visitsinvoiceidfkeys.First().Customer.Address).FirstOrDefault(inv => inv.ProformaInvoiceId == ProformaInvoice.Id); if (ProformaInvoice.Invoice?.Visitsinvoiceidfkeys != null) { ProformaInvoice.Invoice.Visitsinvoiceidfkeys = ProformaInvoice.Invoice.Visitsinvoiceidfkeys.Where(x => x.Deleted == false); } _therapist = db.Therapists.FirstOrDefault(); } }
public static DataModels.ProformaInvoice CreateNewProformaInvoice(List <DataModels.Visit> visits, out string message) { if (visits.Any(x => x.Invoiced)) { message = "Una delle visite selezionate è già stata fatturata!"; return(null); } if (visits.Any(x => x.Payed) && !visits.All(x => x.Payed)) { message = "Non è possibile fatturare un insieme di visite dove solo alcune sono state già pagate"; return(null); } var invoiceTile = ""; Therapist therapist = null; using (var db = new Db.PhisioDB()) { var proformaInvoices = db.ProformaInvoices.Where(x => x.Date >= new NpgsqlTypes.NpgsqlDate(DateTime.Now.Year, 1, 1)).ToList(); invoiceTile = $"{(proformaInvoices.Count + 1).ToString("0000")}/{DateTime.Now.Year}"; therapist = db.Therapists.FirstOrDefault(); } var newProformaInvoice = new DataModels.ProformaInvoice { Date = new NpgsqlTypes.NpgsqlDate(DateTime.Now), Discount = 0, Payed = false, Text = "", Visitsproformainvoiceidfkeys = visits, Title = invoiceTile, TaxStamp = false, TherapistId = therapist.Id, Deleted = false, GroupVisits = false }; message = ""; return(newProformaInvoice); }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } var id = dataGridView1[9, e.RowIndex].Value; if (e.RowIndex + 1 >= dataGridView1.RowCount) { return; } SelectedInvoice = _proformaInvoices.FirstOrDefault(x => x.Id == new Guid(id.ToString())); if (e.ColumnIndex == 7) //fatture { if (SelectedInvoice.Invoice == null) { MessageBox.Show("La fattura non è ancora disponibile"); } else { var basePath = _therapist.InvoicesFolder; var date = $"{SelectedInvoice.Invoice.Date.Year}{SelectedInvoice.Invoice.Date.Month}"; basePath = Path.Combine(basePath, date); if (Directory.Exists(basePath)) { System.Diagnostics.Process.Start(basePath); } else { MessageBox.Show("La cartella non esiste ancora stampare prima la fattura"); } } } else if (e.ColumnIndex == 8) //dettagli { OpenInvoice?.Invoke(this, e); } }
private void PrintProforma(DataModels.ProformaInvoice invoice) { if (invoice.Id == null || invoice.Id == Guid.Empty) { invoice.TaxStamp = checkBox1.Checked; if (double.TryParse(textBoxDiscount.Text, out double disc)) { invoice.Discount = disc; } MessageBox.Show("Si sta visualizzando un anteprima, ricordarsi di salvare la fattura!", "Salvataggio", MessageBoxButtons.OK, MessageBoxIcon.Information); } DataModels.Therapist therapist = null; using (var db = new Db.PhisioDB()) { therapist = db.Therapists.FirstOrDefault(); } if (therapist == null) { MessageBox.Show("Qualcosa è andato storto non trovo i parametri generali", "Stampa", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(therapist.InvoicesFolder)) { MessageBox.Show("Prima di proseguire bisogna impostare la cartella di salvataggio delle fatture", "Salvataggio", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } string html = ""; if (_customer.Language == "german") { html = File.ReadAllText("Template/templateProformaInvoice_de.html"); } else { html = File.ReadAllText("Template/templateProformaInvoice_it.html"); } var groupVisits = checkBoxGroup.Checked; html = Helper.Helper.ReplaceProformaInvoicePlaceHolder(html, _customer, invoice, groupVisits); var basePath = therapist.InvoicesFolder + "_Proforma"; var date = $"{ProformaInvoice.Date.Year}{ProformaInvoice.Date.Month}"; basePath = Path.Combine(basePath, date); Directory.CreateDirectory(basePath); var pdfPath = $@"{basePath}\{invoice.Title.Replace(@"/", "_")}_{_customer.FullName.Replace(" ", "_").Replace("'", "")}.pdf"; var htmlPath = $@"{basePath}\{invoice.Title.Replace("/", "_")}_{_customer.FullName.Replace(" ", "_").Replace("'", "")}.html"; try { File.WriteAllText(htmlPath, html); Helper.PdfManager.CreatePdf(pdfPath, htmlPath); } catch (Exception ee) { MessageBox.Show("Il file è già aperto, chiuderlo", "Stampa", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Helper.DriveManagement.InsertFilePdf(pdfPath, new List<string> { "Invoice", date }); File.Delete(htmlPath); if (File.Exists(pdfPath)) { System.Diagnostics.Process.Start(pdfPath); } else { MessageBox.Show("ERRORE! Non risco a visualizzare il PDF per il file: " + Environment.NewLine + pdfPath + Environment.NewLine + "Dillo a Davide"); } }