public InvoiceDetail CreateInvoiceDetail(InvoiceProductModel product, Invoice invoice) { List <InvoiceProductModel> data = new List <InvoiceProductModel>(); data.Add(product); return(CreateInvoiceDetail(data, invoice).First()); }
// 2. Existing Invoice Product Initialize public InvoiceProductNewOrEdit(int invoiceProductId) { InitializeComponent(); this.existingInvoiceProduct = SqliteDAInvoiceProduct.GetInvoiceProductById(invoiceProductId); // Required to display the product information on the form when editing an invoice product. this.product = SqliteDAProduct.GetProductById(this.existingInvoiceProduct.ProductId); this.invoiceId = this.existingInvoiceProduct.InvoiceId; formTitleLabel.Text = "Edit Invoice Product"; saveButton.Text = "Edit"; this.newInvoiceProduct = false; }
// Display the captured invoice total and also calculate the sum of the total price for // all invoice products private void calculateInvoiceTotals(InvoiceModel invoiceModel) { capturedInvoiceTotalAmountLabel.Text = string.Format("${0:#,0.00}", invoiceModel.InvoiceAmount); InvoiceProductModel invoiceProduct = new InvoiceProductModel(); invoiceProduct = SqliteDAInvoiceProduct.GetInvoiceTotalById(Convert.ToInt32(invoiceModel.Id)); sumOfProductPricesAmountLabel.Text = string.Format("${0:#,0.00}", invoiceProduct.TotalPrice); //Show save button if captured invoice total and sum of invoice products are equal if (invoiceModel.InvoiceAmount == invoiceProduct.TotalPrice) { saveInvoiceButton.Enabled = true; } else { saveInvoiceButton.Enabled = false; } }
private InvoiceModel getFromForm() { string errorsproduct = string.Empty; InvoiceModel invoice = new InvoiceModel(); invoice.Number = Convert.ToString(tbNumerFaktury.Text); if (cbTypFaktury.SelectedItem == "Oryginal") { invoice.Type = 9; } if (cbTypFaktury.SelectedItem == "Kopia") { invoice.Type = 31; } if (cbTypFaktury.SelectedItem == "Duplikat") { invoice.Type = 7; } invoice.SaleDate = dtpDataSprzedazy.Value; invoice.PaymentDate = dtpTerminPlatnosci.Value; invoice.ProviderName = labelNazwaFirmy.Text; invoice.ProviderNip = labelNipFirmy.Text; invoice.BuyerName = tbNabywcaNazwaFirmy.Text; invoice.BuyerNip = tbNabywcaNip.Text; invoice.DeliveryName = tbMDostawyNazwaFirmy.Text; InvoiceAddressModel ProvAdr = new InvoiceAddressModel(); ProvAdr.City = labelMiasto.Text; ProvAdr.Street = labelUlica.Text; ProvAdr.Number = labelNumer.Text; ProvAdr.PostCode = labelKodPocztowy.Text; ProvAdr.CountryCode = labelKraj.Text; InvoiceAddressModel BuyerAdr = new InvoiceAddressModel(); BuyerAdr.City = tbNabywcaMiasto.Text; BuyerAdr.Street = tbNabywcaUlica.Text; BuyerAdr.Number = tbNabywcaNumer.Text; BuyerAdr.PostCode = tbNabywcaKodPocztowy.Text; BuyerAdr.CountryCode = tbNabywcaKraj.Text; List <ValidationResult> results3 = new List <ValidationResult>(); if (Validator.TryValidateObject(BuyerAdr, new ValidationContext(BuyerAdr, null, null), results3)) { } else { errorsproduct += String.Join("\n", results3) + "\n"; } InvoiceAddressModel DelivAdr = new InvoiceAddressModel(); DelivAdr.City = tbMDostawyMiasto.Text; DelivAdr.Street = tbMDostawyUlica.Text; DelivAdr.Number = tbMDostawyNumer.Text; DelivAdr.PostCode = tbMDostawyKodPocztowy.Text; DelivAdr.CountryCode = tbMDostawyKraj.Text; invoice.ProviderAddress = ProvAdr; invoice.BuyerAddress = BuyerAdr; invoice.DeliveryAddress = DelivAdr; for (int i = 0; i < dataGridView1.Rows.Count; i++) { InvoiceProductModel prod = new InvoiceProductModel(); prod.ItemNumber = 11111; prod.Number = Convert.ToString(Convert.ToInt16(i + 1)); prod.Name = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value); prod.Type = Convert.ToString(dataGridView1.Rows[i].Cells[2].Value); prod.QuantityType = 47; prod.Quantity = Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value); prod.SumAmountType = "66"; ////o co chodzi? prod.SumAmountNet = Convert.ToSingle(dataGridView1.Rows[i].Cells[4].Value); prod.UnitPriceNet = Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value); prod.Tax = Convert.ToInt16(Tax); List <ValidationResult> results2 = new List <ValidationResult>(); if (Validator.TryValidateObject(prod, new ValidationContext(prod, null, null), results2)) { invoice.Products.Add(prod); } else { errorsproduct += String.Join("\n", results2) + "\n"; } } invoice.ProductQuntity = dataGridView1.Rows.Count; float suma = 0; for (int i = 0; i < dataGridView1.Rows.Count; i++) { suma += Convert.ToSingle(dataGridView1.Rows[i].Cells[5].Value); } invoice.AmountGross = suma; suma = 0; for (int i = 0; i < dataGridView1.Rows.Count; i++) { suma += Convert.ToSingle(dataGridView1.Rows[i].Cells[4].Value); } invoice.AmountNet = suma; float sumaNetto = 0; float sumaBrutto = 0; for (int i = 0; i < dataGridView1.Rows.Count; i++) { sumaNetto += Convert.ToSingle(dataGridView1.Rows[i].Cells[4].Value); sumaBrutto += Convert.ToSingle(dataGridView1.Rows[i].Cells[5].Value); } invoice.AmountTax = sumaBrutto - sumaNetto; invoice.Tax = Convert.ToInt16(Tax); List <ValidationResult> results = new List <ValidationResult>(); if (Validator.TryValidateObject(invoice, new ValidationContext(invoice, null, null), results)) { } else { errorsproduct += String.Join("\n", results); } if (!string.IsNullOrEmpty(errorsproduct)) { MessageBox.Show(errorsproduct); return(null); } else { return(invoice); } }
public InvoiceModel XmlDecode(string str) { InvoiceModel invoice = new InvoiceModel(); InvoiceAddressModel address; InvoiceProductModel product; XDocument xml = XDocument.Parse(str); foreach (XAttribute attr in xml.Root.Attributes()) { switch (attr.Name.LocalName.ToString()) { case "nr": invoice.Number = attr.Value.ToString(); break; case "type": switch (attr.Value.ToString()) { case "orginal": invoice.Type = (Int16)InvoiceModel.Types.Orginal; break; case "kopia": invoice.Type = (Int16)InvoiceModel.Types.Copy; break; case "duplikat": invoice.Type = (Int16)InvoiceModel.Types.Duplicate; break; } break; } } address = new InvoiceAddressModel(); foreach (XElement el in xml.Descendants("sprzedawca").Elements()) { switch (el.Name.LocalName.ToString()) { case "nip": invoice.ProviderNip = el.Value.ToString(); break; case "nazwa": invoice.ProviderName = el.Value.ToString(); break; case "ulica": address.Street = el.Value.ToString(); break; case "nrlokalu": address.Number = el.Value.ToString(); break; case "kodpocztowy": address.PostCode = el.Value.ToString(); break; case "miasto": address.City = el.Value.ToString(); break; case "kraj": address.CountryCode = el.Value.ToString(); break; } } invoice.ProviderAddress = address; address = new InvoiceAddressModel(); foreach (XElement el in xml.Descendants("klient").Elements()) { switch (el.Name.LocalName.ToString()) { case "nip": invoice.BuyerNip = el.Value.ToString(); break; case "nazwa": invoice.BuyerName = el.Value.ToString(); break; case "ulica": address.Street = el.Value.ToString(); break; case "nrlokalu": address.Number = el.Value.ToString(); break; case "kodpocztowy": address.PostCode = el.Value.ToString(); break; case "miasto": address.City = el.Value.ToString(); break; case "kraj": address.CountryCode = el.Value.ToString(); break; } } invoice.BuyerAddress = address; address = new InvoiceAddressModel(); foreach (XElement el in xml.Descendants("dostawca").Elements()) { switch (el.Name.LocalName.ToString()) { case "nazwa": invoice.DeliveryName = el.Value.ToString(); break; case "ulica": address.Street = el.Value.ToString(); break; case "nrlokalu": address.Number = el.Value.ToString(); break; case "kodpocztowy": address.PostCode = el.Value.ToString(); break; case "miasto": address.City = el.Value.ToString(); break; case "kraj": address.CountryCode = el.Value.ToString(); break; } } invoice.DeliveryAddress = address; XElement items = xml.Descendants("pozycje").First(); invoice.ProductQuntity = int.Parse(items.Attribute("liczbapozycji").Value.ToString()); foreach (XElement item in items.Elements()) { product = new InvoiceProductModel(); foreach (XElement el in item.Elements()) { string value = el.Value.ToString(); switch (el.Name.LocalName.ToString()) { case "nazwa": product.Name = value; break; case "ilosc": product.Quantity = int.Parse(value); product.QuantityType = Int16.Parse(el.Attribute("jednostka").Value.ToString()); break; case "podatekvat": product.Tax = Int16.Parse(value); break; case "cenanetto": product.SumAmountNet = float.Parse(value); break; } } invoice.Products.Add(product); } return(invoice); }
public InvoiceModel EdiDecode(string strEdi) { InvoiceModel invoice = new InvoiceModel(); string[] segments = Edi.ParseToSegmets(strEdi); int nSegments = segments.Length; // ustawiam czy odczytywane dane należą do dostwcy czy nabywcy, lub czy są to dane dostwy // 0 - dostawca, 1 - nabywca, 2 - dane do dostwy int who = 0; string[] arguments; string[] parameters; InvoiceAddressModel address; int productIndex = -1; InvoiceProductModel product; List <InvoiceProductModel> products = new List <InvoiceProductModel>(); bool details = false; for (int i = 0; i < nSegments; i++) { if (i == 23) { } segments[i] = segments[i].Trim(); if (String.IsNullOrEmpty(segments[i])) { continue; } arguments = Edi.ParseToArguments(segments[i]); switch (arguments[0]) { case "UNH": parameters = Edi.ParseToParameters(arguments[2]); if (parameters[0] != "INVOIC") { return(null); } break; case "BGM": if (arguments[1] == "380") { invoice.Number = arguments[2]; invoice.Type = Int16.Parse(arguments[3]); } break; case "DTM": DateTime date; parameters = Edi.ParseToParameters(arguments[1]); if (parameters[2] == "102") { date = DateTime.ParseExact(parameters[1], "yyyyMMdd", null); } else { date = DateTime.Parse(parameters[1]); } switch (parameters[0]) { case "137": invoice.SaleDate = date; break; case "13": invoice.PaymentDate = date; break; } break; case "NAD": address = new InvoiceAddressModel(); parameters = Edi.ParseToParameters(arguments[5]); address.Street = parameters[0]; address.City = arguments[6]; address.PostCode = arguments[8]; address.CountryCode = arguments[9]; switch (arguments[1]) { case "SU": //dane dostawcy who = 0; parameters = Edi.ParseToParameters(arguments[4]); invoice.ProviderName = parameters[0]; invoice.ProviderAddress = address; break; case "BY": //dane nabywcy who = 1; parameters = Edi.ParseToParameters(arguments[4]); invoice.BuyerName = parameters[0]; invoice.BuyerAddress = address; break; case "DP": //dane do dostawy who = 2; parameters = Edi.ParseToParameters(arguments[4]); invoice.DeliveryName = parameters[0]; invoice.DeliveryAddress = address; break; } break; case "RFF": parameters = Edi.ParseToParameters(arguments[1]); if (parameters[0] == "VA") { switch (who) { case 0: //nip dostawcy invoice.ProviderNip = parameters[1]; break; case 1: //nip nabywcy invoice.BuyerNip = parameters[1]; break; } } break; case "PAT": details = true; break; case "LIN": productIndex++; product = new InvoiceProductModel(); product.ItemNumber = Int16.Parse(arguments[1]); parameters = Edi.ParseToParameters(arguments[3]); product.Number = parameters[0]; products.Insert(productIndex, product); break; case "IMD": product = products[productIndex]; product.Name = arguments[2]; parameters = Edi.ParseToParameters(arguments[3]); product.Type = parameters[0]; break; case "QTY": product = products[productIndex]; parameters = Edi.ParseToParameters(arguments[1]); product.QuantityType = Int16.Parse(parameters[0]); product.Quantity = int.Parse(parameters[1]); break; case "MOA": parameters = Edi.ParseToParameters(arguments[1]); if (details) { switch (parameters[0]) { case "66": case "35E": product = products[productIndex]; product.SumAmountType = parameters[0]; product.SumAmountNet = float.Parse(parameters[1]); break; } } else { float amount = float.Parse(parameters[1]); switch (parameters[0]) { case "77": invoice.AmountGross = amount; break; case "79": invoice.AmountNet = amount; break; case "124": invoice.AmountTax = amount; break; } } break; case "PRI": parameters = Edi.ParseToParameters(arguments[1]); if (parameters[0] == "AAA") { product = products[productIndex]; product.UnitPriceNet = float.Parse(parameters[1]); } break; case "TAX": if (arguments[1] == "7" && arguments[2] == "VAT") { parameters = Edi.ParseToParameters(arguments[5]); if (details) { product = products[productIndex]; product.Tax = Int16.Parse(parameters[3]); } else { invoice.Tax = Int16.Parse(parameters[3]); } } break; case "UNS": if (arguments[1] == "S") { invoice.Products = products; details = false; } break; case "CNT": parameters = Edi.ParseToParameters(arguments[1]); invoice.ProductQuntity = int.Parse(parameters[0]); break; } } return(invoice); }