private void OkClick(object sender, RoutedEventArgs e) { var d = _returnedProducts.Sum(l => l.PriceHt * l.Qty); DotLiquidService.Print(GetBarcodeMoney(d), d); RepositoryCheck.ReturnCheck(_check, _returnedProducts); Close(); }
public ClassPrintCheck(XContainer rootElement, bool duplicate) { Duplicate = duplicate; var listProduct = new List <PrintGroupProduct>(); _tva = new List <string>(); foreach (var p in RepositoryTypePay.TypePays) { var money = rootElement.GetXAttribute("check", p.NameCourt.Trim()); if (money != null) { _attr.Add(new PrintTypePay(p, money.Value.ToDecimal())); } } Rendu = rootElement.GetXAttributeValue("check", "Rendu").ToDecimal(); var xe = rootElement.GetXElements("check", "product"); var sum = 0.0m; var sumDiscounts = 0.0m; foreach (var e in xe) { var discount = e.GetXElementValue("Discount").ToDecimal(); var sumDiscount = -e.GetXElementValue("sumDiscount").ToDecimal(); var codebare = e.GetXElementValue("CodeBare").Trim(); var qty = e.GetXElementValue("qty").ToDecimal(); var name = e.GetXElementValue("Name"); var total = e.GetXElementValue("total").ToDecimal() - sumDiscount; var price = e.GetXElementValue("price").ToDecimal(); var categories = RepositoryGroupProduct.GetGroupNameById(e.GetXElementValue("grp").ToInt()); var tva = e.GetXElementValue("tva").ToInt(); var customerId = e.GetXElementValue("CustomerId").ToGuid(); var p = new PrintProduct(customerId, categories, codebare, name, qty, total, price, tva, discount, sumDiscount); #region DISCOUNT if (discount > 0) { var discountcategories = "Remise " + p.ProcentDiscount + "%"; var discountIndx = listProduct.FindIndex(l => l.Categories == discountcategories); if (discountIndx == -1) { var pn = new PrintProduct(Guid.Empty, discountcategories, Barcode, name, qty, total, price, tva, discount, sumDiscount); listProduct.Add(new PrintGroupProduct(discountcategories, pn)); } else { // groupProduct.product pn = new groupProduct.product(Guid.Empty, discountcategories, "", name, 1, sumDiscount, 0, tva_, Discount, sumDiscount); var pn = new PrintProduct(Guid.Empty, discountcategories, Barcode, name, qty, total, price, tva, discount, sumDiscount); var repeat = listProduct[discountIndx].Products.FindIndex(l => l.Name == name); if (repeat != -1) { listProduct[discountIndx].Products[repeat].Total += pn.SumDiscount; listProduct[discountIndx].Products[repeat].Price = pn.Price; listProduct[discountIndx].Products[repeat].TvaTotal += pn.TvaTotal; listProduct[discountIndx].Products[repeat].Ht += pn.Ht; listProduct[discountIndx].Products[repeat].SumDiscount += pn.SumDiscount; } else { listProduct[discountIndx].Products.Add(pn); } } sumDiscounts -= sumDiscount; } #endregion var indx = listProduct.FindIndex(l => l.Categories == p.Categories); if (indx != -1) { var f = listProduct[indx].Products.FindIndex(l => (l.CustomerId == p.CustomerId) && l.Price == p.Price); if (f == -1) { listProduct[indx].Products.Add(p); } else { if (listProduct[indx].Products[f].Categories != "Remise " + p.ProcentDiscount + "%") { listProduct[indx].Products[f].Qty += p.Qty; listProduct[indx].Products[f].Total += p.Total; listProduct[indx].Products[f].Price = p.Price; listProduct[indx].Products[f].TvaTotal += p.TvaTotal; listProduct[indx].Products[f].Ht += p.Ht; listProduct[indx].Products[f].SumDiscount += p.SumDiscount; } } } else { listProduct.Add(new PrintGroupProduct(categories, p)); } sum += total; } listProduct = listProduct.OrderBy(l => l.Categories).ToList(); var listProductDiscount = listProduct.FindAll(l => l.Categories.IndexOf("Discount") != -1); listProduct.RemoveAll(l => l.Categories.IndexOf("Discount") != -1); var listProductDiscountRemise = listProduct.FindAll(l => l.Categories.IndexOf("Remise") != -1); listProduct.RemoveAll(l => l.Categories.IndexOf("Remise") != -1); listProduct.AddRange(listProductDiscount); listProduct.AddRange(listProductDiscountRemise); Head = File.ReadAllText(PathH); Footer = File.ReadAllText(PathF); Barcode = rootElement.GetXAttributeValue("check", "barcodeCheck"); Totals = (sum - sumDiscounts).ToString("0.00"); SumDiscount = sumDiscounts.ToString("0.00"); #region DiscountPoints var a0 = rootElement.GetXAttribute("check", "DCBC"); var a1 = rootElement.GetXAttribute("check", "DCBC_BiloPoints"); var a2 = rootElement.GetXAttribute("check", "DCBC_DobavilePoints"); var a3 = rootElement.GetXAttribute("check", "DCBC_OtnayliPoints"); var a4 = rootElement.GetXAttribute("check", "DCBC_OstalosPoints"); var a5 = rootElement.GetXAttribute("check", "DCBC_name"); var bcdc = a0?.Value; if (!string.IsNullOrEmpty(bcdc)) { C = new PrintClientInfo { Dcbc = a0.Value, DcbcBiloPoints = a1.Value, DcbcDobavilePoints = a2.Value, DcbcOtnayliP = a3.Value, DcbcOstalosPoints = a4.Value, DcbcName = a5.Value } } ; #endregion DotLiquidService.Print(Barcode, Head, listProduct, Totals, SumDiscount, _attr, Rendu, Footer, C, duplicate); }