public MainViewModel() { _contoData = new ContoData(); var settings = _contoData.GetSettings(); if (settings != null) { InvoiceOwnerAddress = settings.InvoiceOwnerAddress; InvoiceOwnerCity = settings.InvoiceOwnerCity; InvoiceOwnerFiscalCode = settings.InvoiceOwnerFiscalCode; InvoiceOwnerName = settings.InvoiceOwnerName; InvoiceOwnerPostalCode = settings.InvoiceOwnerPostalCode; InvoiceOwnerVatCode = settings.InvoiceOwnerVatCode; InvoiceMaxCost = settings.MaxInvoiceValue; } SelfInvoiceButtonStyle = Application.Current.Resources["MainMenuButtonStyle"] as Style; InvoiceButtonStyle = Application.Current.Resources["InvoiceMenuButtonStyle"] as Style; CashButtonStyle = Application.Current.Resources["CashMenuButtonStyle"] as Style; MaterialsButtonStyle = Application.Current.Resources["MaterialsMenuButtonStyle"] as Style; ClientsButtonStyle = Application.Current.Resources["ClientsMenuButtonStyle"] as Style; SelfInvoiceCommand = new RelayCommand(SelfInvoice_Executed); InvoiceCommand = new RelayCommand(InvoiceCommand_Executed); CashFlowCommand = new RelayCommand(CashFlowCommand_Executed); ClientsCommand = new RelayCommand(ClientsCommand_Executed); MaterialsCommand = new RelayCommand(MaterialsCommand_Executed); }
public static void CreateFirstPdf() { var contoData = new ContoData(); //FileStream fs = new FileStream("Chapter1_example.pdf", FileMode.Create, FileAccess.Write, FileShare.None); //Document doc = new Document(); //PdfWriter writer = PdfWriter.GetInstance(doc, fs); using (FileStream fs = new FileStream("Chapter1_example.pdf", FileMode.Create, FileAccess.Write, FileShare.None)) using (Document doc = new Document(PageSize.A4, 25, 25, 30, 30)) using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) { doc.Open(); PdfReader templateReader = new PdfReader(PdfResources.Autofattura_Template); PdfTemplate background = writer.GetImportedPage(templateReader, 1); doc.NewPage(); var pcb = writer.DirectContentUnder; pcb.AddTemplate(background, 0, 0); pcb = writer.DirectContent; pcb.BeginText(); pcb.SetFontAndSize(Font, 10); pcb.SetTextMatrix(469, 650); pcb.ShowText(DateTime.Now.ToString("dd/MM/yyyy")); pcb.SetTextMatrix(469, 613); pcb.ShowText("6306/13"); /* ANAGRAFICA CLIENTE AUTOFATTURA */ SelfInvoiceOwner(pcb, contoData.GetSettings()); SelfInvoiceDescription(pcb, "Rottame rame"); SelfInvoiceQuantity(pcb, 0.18M); SelfInvoiceMaterialPrice(pcb, 4720.02M); SelfInvoiceAmount(pcb, 849.60M); TaxableAmount(pcb, 849.60M); TotalAmount(pcb, 849.60M); pcb.EndText(); doc.Close(); writer.Close(); fs.Close(); string path = Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%"); string pathToExecutable = @"\Adobe\Adobe Reader\Reader\AcroRd32.exe"; RunExecutable(string.Concat(path, pathToExecutable), @"/p ""Chapter1_example.pdf"""); } }
public SettingsViewModel() { _contoData = new ContoData(); var settings = _contoData.GetSettings(); if (settings != null) { InvoiceOwnerAddress = settings.InvoiceOwnerAddress; InvoiceOwnerCity = settings.InvoiceOwnerCity; InvoiceOwnerFiscalCode = settings.InvoiceOwnerFiscalCode; InvoiceOwnerName = settings.InvoiceOwnerName; InvoiceOwnerPostalCode = settings.InvoiceOwnerPostalCode; InvoiceOwnerVatCode = settings.InvoiceOwnerVatCode; InvoiceMaxCost = settings.MaxInvoiceValue; } }
private static void ExportPdfSelfInvoice(SelfInvoices selfInvoices, ContoData contoData, Document doc, PdfWriter writer, PdfTemplate background) { var material = contoData.MaterialGet(selfInvoices.MaterialId); doc.NewPage(); var pcb = writer.DirectContentUnder; pcb.AddTemplate(background, 0, 0); pcb = writer.DirectContent; pcb.BeginText(); pcb.SetFontAndSize(Font, 10); // invoice date pcb.SetTextMatrix(469, 650); pcb.ShowText(selfInvoices.InvoiceDate.ToString("dd/MM/yyyy")); // invoice number pcb.SetTextMatrix(469, 613); pcb.ShowText(string.Format("{0}/{1}", selfInvoices.InvoiceNumber, selfInvoices.InvoiceYear.ToString(CultureInfo.InvariantCulture).Substring(2))); // invoice owner SelfInvoiceOwner(pcb, contoData.GetSettings()); // material description SelfInvoiceDescription(pcb, material.Description); SelfInvoiceQuantity(pcb, selfInvoices.Quantity); SelfInvoiceMaterialPrice(pcb, material.Price.HasValue ? material.Price.Value : 0); SelfInvoiceAmount(pcb, selfInvoices.InvoiceCost); TaxableAmount(pcb, selfInvoices.InvoiceCost); TotalAmount(pcb, selfInvoices.InvoiceCost); pcb.EndText(); }
public void AddSelfInvoice_Executed(object sender) { if (AppProperties.FormHaveModifications) { if (SelectedMaterial == null || !SelectedMaterial.Price.HasValue) { MessageBox.Show("Selezionare un materiale"); return; } if (!Quantity.HasValue) { MessageBox.Show("Selezionare una quantità "); return; } if (SelectedMeasure == null) { MessageBox.Show("Selezionare una misura"); return; } if (!MaterialPrice.HasValue) { MessageBox.Show("Selezionare un costo"); return; } //var invoiceNumber = 1; var invoiceGroup = Guid.NewGuid(); var settings = _contoData.GetSettings(); var maxInvoiceValue = settings != null ? settings.MaxInvoiceValue : 990; maxInvoiceValue = maxInvoiceValue.HasValue ? maxInvoiceValue.Value : 990; var measure = _contoData.MeasureGet(SelectedMaterial.MeasureId); decimal invoiceCost = (Quantity.Value * SelectedMaterial.Price.Value) / measure.Grams * SelectedMeasure.Grams; //decimal quantityAtMaxInvoiceValue = (measure.Grams / SelectedMeasure.Grams); decimal quantityAtMaxInvoiceValue = maxInvoiceValue.Value * (Quantity.Value * SelectedMeasure.Grams) / invoiceCost / SelectedMeasure.Grams; var invoices = (int)Math.Truncate(invoiceCost / maxInvoiceValue.Value) + (invoiceCost % maxInvoiceValue.Value == 0 ? 0 : 1); var quantityTot = Quantity.Value; for (int i = 0; i < invoices; i++) { var invoiceCurrentCost = invoiceCost > maxInvoiceValue ? maxInvoiceValue.Value : invoiceCost; invoiceCost = invoiceCost - maxInvoiceValue.Value; var quantity = quantityTot > quantityAtMaxInvoiceValue ? quantityAtMaxInvoiceValue : quantityTot; quantityTot = quantityTot - quantityAtMaxInvoiceValue; _contoData.SelfInvoicesAdd(new SelfInvoices { MaterialId = SelectedMaterial.Id, Quantity = quantity, VatExcept = VatExempt, //InvoiceNumber = invoiceNumber++, InvoiceYear = InvoiceYear, MeasureId = SelectedMeasure.Id, InCashFlow = false, InvoiceDate = InvoiceDate, InvoiceCost = invoiceCurrentCost, InvoiceGroupId = invoiceGroup }); } SelectedMaterial = null; MaterialPrice = null; SelectedMeasure = null; Quantity = null; UpdateList(); AppProperties.FormHaveModifications = false; } else { MessageBox.Show("AddSelfInvoice"); } }