Ejemplo n.º 1
0
        public ClassPrintCheck(XDocument b, bool Duplicate)
        {
            this.Duplicate = Duplicate;
            listProduct    = new List <groupProduct>();
            tva            = new List <string>();
            foreach (var p in ClassSync.TypesPayDB.t)
            {
                XAttribute a = b.Element("check").Attribute(p.NameCourt.TrimEnd().TrimStart());

                if (a != null)
                {
                    string money = a.Value.Replace(".", ",");

                    attr.Add(new Pays(p, decimal.Parse(money)));
                }
            }

            rendu = decimal.Parse(b.Element("check").Attribute("Rendu").Value.Replace(".", ","));

            IEnumerable <XElement> xe = b.Element("check").Elements("product");

            decimal sum = 0.0m;

            decimal sumDiscounts = 0.0m;


            foreach (XElement e in xe)
            {
                decimal Discount    = decimal.Parse(e.Element("Discount").Value.Replace(".", ","));
                decimal sumDiscount = -decimal.Parse(e.Element("sumDiscount").Value.Replace(".", ","));
                string  codebare    = e.Element("CodeBare").Value.TrimEnd().TrimStart().Trim();
                decimal qty         = decimal.Parse(e.Element("qty").Value.Replace(".", ","));
                string  name        = e.Element("Name").Value;
                decimal total       = decimal.Parse(e.Element("total").Value.Replace(".", ",")) - sumDiscount;
                decimal price       = decimal.Parse(e.Element("price").Value.Replace(".", ","));
                string  categories  = ClassGroupProduct.getName(int.Parse(e.Element("grp").Value));
                int     tva_        = int.Parse(e.Element("tva").Value);
                Guid    customerId  = Guid.Parse(e.Element("CustumerId").Value);

                groupProduct.product p = new groupProduct.product(customerId, categories, codebare, name, qty, total, price, tva_, Discount, sumDiscount);


                #region DISCOUNT


                if (Discount > 0)
                {
                    string discountcategories = "Remise " + p.procentDiscount + "%";

                    int discountIndx = listProduct.FindIndex(l => l.categories == discountcategories);

                    if (discountIndx == -1)
                    {
                        groupProduct.product pn = new groupProduct.product(Guid.Empty, discountcategories, barcode, name, qty, total, price, tva_, Discount, sumDiscount);


                        listProduct.Add(new groupProduct(discountcategories, pn));
                    }
                    else
                    {
                        //  groupProduct.product pn = new groupProduct.product(Guid.Empty, discountcategories, "", name, 1, sumDiscount, 0, tva_, Discount, sumDiscount);
                        groupProduct.product pn = new groupProduct.product(Guid.Empty, discountcategories, barcode, name, qty, total, price, tva_, Discount, sumDiscount);

                        int 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
                int indx = listProduct.FindIndex(l => l.categories == p.categories);

                if (indx != -1)
                {
                    int f = -1;
                    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 groupProduct(categories, p));
                }


                sum += total;
            }

            listProduct = listProduct.OrderBy(l => l.categories).ToList();

            List <groupProduct> listProductDiscount = listProduct.FindAll(l => l.categories.IndexOf("Discount") != -1);

            listProduct.RemoveAll(l => l.categories.IndexOf("Discount") != -1);


            List <groupProduct> 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 = b.Element("check").Attribute("barcodeCheck").Value;

            totals = (sum - sumDiscounts).ToString("0.00");

            sumDiscount_ = sumDiscounts.ToString("0.00");

            #region DiscountPoints
            XAttribute a0 = b.Element("check").Attribute("DCBC");
            XAttribute a1 = b.Element("check").Attribute("DCBC_BiloPoints");
            XAttribute a2 = b.Element("check").Attribute("DCBC_DobavilePoints");
            XAttribute a3 = b.Element("check").Attribute("DCBC_OtnayliPoints");
            XAttribute a4 = b.Element("check").Attribute("DCBC_OstalosPoints");
            XAttribute a5 = b.Element("check").Attribute("DCBC_name");

            string BCDC = (a0 != null  ? a0.Value : null);

            if ((BCDC != null) && (BCDC != ""))
            {
                c = new infoOfClient
                {
                    DCBC                = a0.Value,
                    DCBC_BiloPoints     = a1.Value,
                    DCBC_DobavilePoints = a2.Value,
                    DCBC_OtnayliP       = a3.Value,
                    DCBC_OstalosPoints  = a4.Value,
                    DCBC_name           = a5.Value
                };
            }
            #endregion


            ClassDotLiquid.prt(barcode, head, listProduct, totals, sumDiscount_, attr, rendu, footer, c, Duplicate);
        }
Ejemplo n.º 2
0
        public static void xmlToDbSave(XDocument x)
        {
            ClassSync.TES Tes = new ClassSync.TES();

            Tes.CustomerId = Guid.NewGuid();

            Tes.a_CodeFournisseur = 0; //short.Parse( pro.Nclient);

            Tes.a_FRTVA = ClassSync.classPro.getFRTVA(pro);

            Tes.a_Mail = pro.Mail;

            Tes.a_Name = ClassSync.classPro.getName(pro) ?? "";

            Tes.a_Sex = ClassSync.classPro.SexToInt(ClassSync.classPro.getSex(pro));

            Tes.a_Surname = ClassSync.classPro.getSurName(pro) ?? "";

            Tes.a_NameCompany = pro.NameCompany;

            Tes.a_OfficeAddress = ClassSync.classPro.getOfficeAddress(pro);

            Tes.a_OfficeCity = ClassSync.classPro.getOfficeCity(pro);

            Tes.a_OfficeZipCode = ClassSync.classPro.getOfficeZipCode(pro);



            Tes.a_SIRET = ClassSync.classPro.getSIRET(pro);



            Tes.a_Telephone = pro.Telephone;

            Tes.CustomerId = Guid.NewGuid();

            Tes.DateTime = DateTime.Now;

            Tes.Description = "";

            Tes.Id = ClassSync.TES.maxId(0) + 1;

            Tes.Livraison = false;

            Tes.Montant = decimal.Parse(x.Element("check").Attribute("sum").Value.Replace('.', ','));

            Tes.Nclient = pro.Nclient.ToString();

            Tes.Payement = false;

            Tes.Type = 0;

            Tes.v_Adresse = ClassGlobalVar.Establishment.Adresse;

            Tes.v_CodeNAF = "0";

            Tes.v_CP = ClassGlobalVar.Establishment.CP;

            Tes.v_Fax = ClassGlobalVar.Establishment.Phone;

            Tes.v_FRTVA = "";

            Tes.v_Mail = ClassGlobalVar.Establishment.Mail;

            Tes.v_NameCompany = ClassGlobalVar.Establishment.Name;

            Tes.v_Phone = ClassGlobalVar.Establishment.Phone;

            Tes.v_SIRET = "";

            Tes.v_Ville = ClassGlobalVar.Establishment.Ville;


            IEnumerable <XElement> products = x.Element("check").Elements("product");

            string cmdSr = " ";

            List <XElement> p = new List <XElement>();

            foreach (var product in products)
            {
                var pf = p.Find(l => (l.Element("CustumerId").Value == product.Element("CustumerId").Value));


                if (pf == null || (pf.Element("price").Value != product.Element("price").Value))
                {
                    p.Add(product);
                }

                else
                {
                    decimal qty    = decimal.Parse(pf.Element("qty").Value.Replace('.', ','));
                    decimal qty_   = decimal.Parse(product.Element("qty").Value.Replace('.', ','));
                    decimal total  = decimal.Parse(pf.Element("total").Value.Replace('.', ','));
                    decimal total_ = decimal.Parse(product.Element("total").Value.Replace('.', ','));
                    pf.Element("qty").SetValue(qty + qty_);
                    pf.Element("total").SetValue(total + total_);
                }
            }

            x.Element("check").Elements("product").Remove();



            foreach (var product in p)
            {
                x.Element("check").Add(product);

                ClassSync.TESproducts prod = new ClassSync.TESproducts();

                prod.Balance = bool.Parse(product.Element("balance").Value);

                prod.CodeBar = replaceCodeBare(product.Element("CodeBare").Value);

                prod.ConditionAchat = 1;// decimal.Parse( product.Element("qty").Value);

                prod.CustomerId = -1;

                prod.CustomerIdProduct = Guid.Parse(product.Element("CustumerId").Value);

                prod.Date = DateTime.Now;

                prod.Description = ClassGlobalVar.Name;

                prod.Group = ClassGroupProduct.getName(int.Parse(product.Element("grp").Value));

                prod.NameProduct = product.Element("Name").Value;

                prod.PrixHT = Math.Round(decimal.Parse(product.Element("price").Value.Replace('.', ',')), 2);

                prod.ProductsWeb = Guid.Parse(product.Element("ProductsWeb_CustomerId").Value);

                prod.QTY = decimal.Parse(product.Element("qty").Value.Replace('.', ','));

                prod.SubGroup = ClassGroupProduct.getName(int.Parse(product.Element("grp").Value));

                prod.TESCustomerId = Tes.CustomerId;

                prod.TVA = ClassTVA.getTVA(int.Parse(product.Element("tva").Value));

                decimal tva = PrixTTCOnlyTVA(decimal.Parse(product.Element("price").Value.Replace('.', ',')), prod.TVA);

                prod.PrixHT = prod.PrixHT - tva;

                prod.TotalHT = prod.QTY * prod.PrixHT; //decimal.Parse(product.Element("total").Value.Replace('.', ',')) - totalOnlyTVA(product);

                prod.TypeID = 1;

                Tes.TESproducts.Add(prod);

                decimal qty = prod.QTY;

                Guid cusumerIdRealStock = Guid.Parse(product.Element("cusumerIdRealStock").Value.Replace('.', ','));

                cmdSr += ClassSync.ProductDB.StockReal.query_add_qty(-qty, cusumerIdRealStock);
            }

            foreach (ClassSync.TypesPayDB type in ClassSync.TypesPayDB.t)
            {
                ClassSync.TESreglement reglement = new ClassSync.TESreglement();

                var r = reglement.TypePayItems.FirstOrDefault(l => l.Text == type.NameCourt);

                var elm = x.Element("check").Attribute(type.NameCourt);

                if (elm != null && r != null)
                {
                    reglement.Caisse = ClassGlobalVar.nameTicket;

                    reglement.CustomerId = Guid.NewGuid();

                    reglement.DateTime = DateTime.Now;

                    if (r.Value == "En espèces")
                    {
                        var rendux = x.Element("check").Attribute("Rendu");

                        if (rendux != null)
                        {
                            decimal rendu = decimal.Parse(rendux.Value.Replace('.', ','));

                            reglement.Montant = decimal.Parse(elm.Value.Replace('.', ',')) + rendu;
                        }
                        else
                        {
                            reglement.Montant = decimal.Parse(elm.Value.Replace('.', ','));
                        }
                    }
                    else
                    {
                        reglement.Montant = decimal.Parse(elm.Value.Replace('.', ','));
                    }
                    reglement.TESCustomerId = Tes.CustomerId;

                    reglement.TypePay = r.Value;

                    Tes.TESreglement.Add(reglement);
                }
                Tes.Payement = (Tes.TESreglement.Sum(l => l.Montant) >= Tes.Montant);
            }


            int c_tes  = 0;
            int c_tes_ = 0;
            int c_sr   = 0;

            if (Tes.TESreglement.Count > 0)
            {
                ClassSync.TES Tes_ = new ClassSync.TES();

                Tes_.CustomerId = Guid.NewGuid();

                Tes_.a_CodeFournisseur = (short)(pro.Nclient);

                Tes_.a_FRTVA = ClassSync.classPro.getFRTVA(pro);

                Tes_.a_Mail = pro.Mail;

                Tes_.a_Name = ClassSync.classPro.getName(pro) ?? "";

                Tes_.a_Sex = ClassSync.classPro.SexToInt(ClassSync.classPro.getSex(pro));

                Tes_.a_Surname = ClassSync.classPro.getSurName(pro) ?? "";


                Tes_.a_NameCompany = pro.NameCompany;

                Tes_.a_OfficeAddress = ClassSync.classPro.getOfficeAddress(pro);

                Tes_.a_OfficeCity = ClassSync.classPro.getOfficeCity(pro);

                Tes_.a_OfficeZipCode = ClassSync.classPro.getOfficeZipCode(pro);



                Tes_.a_SIRET = ClassSync.classPro.getSIRET(pro);

                Tes_.a_Telephone = pro.Telephone;

                Tes_.CustomerId = Guid.NewGuid();

                Tes_.DateTime = DateTime.Now;

                Tes_.Description = "{" + Tes.CustomerId + "}{" + Tes.Id + "}{" + Tes.Type + "}";

                Tes_.Id = ClassSync.TES.maxId(1) + 1;


                Tes_.Livraison = Tes.Livraison;

                Tes_.Montant = decimal.Parse(x.Element("check").Attribute("sum").Value.Replace('.', ','));

                Tes_.Nclient = pro.Nclient.ToString();

                Tes_.Payement = Tes.Payement;

                Tes_.Type = 1;

                Tes_.v_Adresse = Tes.v_Adresse;

                Tes_.v_CodeNAF = Tes.v_CodeNAF;

                Tes_.v_CP = Tes.v_CP;

                Tes_.v_Fax = Tes.v_Fax;

                Tes_.v_FRTVA = Tes.v_FRTVA;

                Tes_.v_Mail = Tes.v_Mail;

                Tes_.v_NameCompany = Tes.v_NameCompany;

                Tes_.v_Phone = Tes.v_Phone;

                Tes_.v_SIRET = Tes.v_SIRET;

                Tes_.v_Ville = Tes.v_Ville;

                Tes.Description = "{" + Tes_.CustomerId + "}{" + Tes_.Id + "}{" + Tes_.Type + "}";

                foreach (var t in Tes.TESreglement)
                {
                    if (t.Montant > 0)
                    {
                        t.TESCustomerId = Tes_.CustomerId;

                        Tes_.TESreglement.Add(t);
                    }
                }

                Tes.TESreglement.Clear();
                //   foreach (var t in Tes.TESproducts)
                //     Tes_.TESproducts.Add(t);

                c_tes_ = ClassSync.TES.ins(Tes_);
            }

            c_tes = ClassSync.TES.ins(Tes);

            c_sr = ClassSync.ProductDB.StockReal.response(cmdSr);

            nfact = Tes.Id ?? -1;


            fileMove();
        }