Example #1
0
        public static void MegaSync()
        {
            // check tables
            var syncTask = Task <bool> .Factory.StartNew(
                () =>
            {
                RepositoryActionHashBox.Sync();
                //RepositoryCheck
                RepositoryCheckTicket.Sync();
                RepositoryCheckTicketTmp.Sync();
                RepositoryPro.Sync();
                RepositoryClientInfo.Sync();
                RepositoryCloseTicket.Sync();
                RepositoryCloseTicketCheckDiscount.Sync();
                RepositoryCloseTicketG.Sync();
                RepositoryCloseTicketTmp.Sync();
                RepositoryCountry.Sync();
                RepositoryCurrency.Sync();
                //RepositoryCurrencyRelations
                RepositoryDevisId.Sync();
                RepositoryDevisWeb.Sync();
                //RepositoryDiscount
                RepositoryDiscountCard.Sync();
                RepositoryEstablishment.Sync();
                RepositoryGeneral.Sync();
                RepositoryGroupProduct.Sync();
                //RepositoryHistoryChangeProduct
                RepositoryInfoClientsDiscountsType.Sync();
                RepositoryLastUpdate.Sync();
                RepositoryOpenTicketWindow.Sync();
                RepositoryPayProduct.Sync();
                RepositoryPayProductTmp.Sync();
                //RepositoryPriceGros
                RepositoryProduct.Sync();
                RepositoryProductBc.Sync();
                RepositoryStatNation.Sync();
                RepositoryStatNationPopup.Sync();
                RepositoryStatPlaceArrond.Sync();
                //RepositoryStockLogs
                RepositoryStockReal.Sync();
                RepositorySyncPlus.Sync();
                RepositorySyncPlusProduct.Sync();
                //RepositoryTes
                RepositoryTva.Sync();
                RepositoryTypePay.Sync();
                //RepositoryXmlFile
                return(true);
            });

            syncTask.ContinueWith(
                s => { });
        }
        private void BtnAdd1Click(object sender, RoutedEventArgs e)
        {
            var window = new TextWindow();

            if (window.ShowDialog() == true)
            {
                var group = new GroupProduct(RepositoryGroupProduct.GroupProducts.Count + 1, window.NameText);
                RepositoryGroupProduct.Add(group);

                DataGridGroups.ItemsSource = null;
                DataGridGroups.ItemsSource = RepositoryGroupProduct.GroupProducts;
            }
        }
        private void BtnDel1Click(object sender, RoutedEventArgs e)
        {
            var selected = DataGridGroups.SelectedItem as GroupProduct;

            if (selected != null)
            {
                var result = MessageBox.Show(Properties.Resources.MessageDeleteQuestion, Properties.Resources.LabelQuestion, MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    RepositoryGroupProduct.Delete(selected);

                    DataGridGroups.ItemsSource = null;
                    DataGridGroups.ItemsSource = RepositoryGroupProduct.GroupProducts;
                }
            }
        }
        private void BtnAdd2Click(object sender, RoutedEventArgs e)
        {
            var selectedGroup = DataGridGroups.SelectedItem as GroupProduct;

            if (selectedGroup != null)
            {
                var window = new TextWindow();
                if (window.ShowDialog() == true)
                {
                    var subgroup = new SubGroupProduct(RepositorySubGroupProduct.SubGroupProducts.Count + 1, window.NameText, selectedGroup.Id)
                    {
                        Group = selectedGroup
                    };
                    RepositoryGroupProduct.AddSubgroup(subgroup);

                    DataGridSubgroups.ItemsSource = null;
                    DataGridSubgroups.ItemsSource = selectedGroup.SubGroups;
                }
            }
        }
Example #5
0
        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);
        }
Example #6
0
        public static void XmlToDbSave(XDocument x)
        {
            var tes = new Tes
            {
                CustomerId       = Guid.NewGuid(),
                ACodeFournisseur = 0,
                AFrtva           = Pro.Frtva ?? string.Empty,
                AMail            = Pro.Mail,
                AName            = Pro.Name ?? string.Empty,
                ASex             = Pro.SexToInt(Pro.Sex),
                ASurname         = Pro.Surname ?? string.Empty,
                ANameCompany     = Pro.NameCompany,
                AOfficeAddress   = Pro.OfficeAddress ?? string.Empty,
                AOfficeCity      = Pro.OfficeCity ?? string.Empty,
                AOfficeZipCode   = Pro.OfficeZipCode ?? string.Empty,
                ASiret           = Pro.Siret ?? string.Empty,
                ATelephone       = Pro.Telephone
            };

            tes.CustomerId   = Guid.NewGuid();
            tes.DateTime     = DateTime.Now;
            tes.Description  = string.Empty;
            tes.Id           = RepositoryTes.MaxId(0) + 1;
            tes.Livraison    = false;
            tes.Montant      = x.GetXAttributeValue("check", "sum").ToDecimal();
            tes.Nclient      = Pro.Nclient.ToString();
            tes.Payement     = false;
            tes.Type         = 0;
            tes.VAdresse     = RepositoryEstablishment.Establishment.Adress;
            tes.VCodeNaf     = "0";
            tes.VCp          = RepositoryEstablishment.Establishment.Cp;
            tes.VFax         = RepositoryEstablishment.Establishment.Phone;
            tes.VFrtva       = "";
            tes.VMail        = RepositoryEstablishment.Establishment.Mail;
            tes.VNameCompany = RepositoryEstablishment.Establishment.Name;
            tes.VPhone       = RepositoryEstablishment.Establishment.Phone;
            tes.VSiret       = "";
            tes.VVille       = RepositoryEstablishment.Establishment.Ville;
            var products = x.GetXElements("check", "product");

            var p = new List <XElement>();

            foreach (var product in products)
            {
                var pf = p.Find(l => l.GetXElementValue("CustomerId") == product.GetXElementValue("CustomerId"));

                if (pf == null || (pf.GetXElementValue("price") != product.GetXElementValue("price")))
                {
                    p.Add(product);
                }
                else
                {
                    var qty    = pf.GetXElementValue("qty").ToDecimal();
                    var qty1   = product.GetXElementValue("qty").ToDecimal();
                    var total  = pf.GetXElementValue("total").ToDecimal();
                    var total1 = product.GetXElementValue("total").ToDecimal();
                    pf.GetXElement("qty").SetValue(qty + qty1);
                    pf.GetXElement("total").SetValue(total + total1);
                }
            }
            x.GetXElements("check", "product").Remove();

            foreach (var product in p)
            {
                x.GetXElement("check").Add(product);
                var prod = new TesProduct
                {
                    Balance           = product.GetXElementValue("balance").ToBool(),
                    CodeBar           = ReplaceCodeBare(product.GetXElementValue("CodeBare")),
                    ConditionAchat    = 1,
                    CustomerId        = -1,
                    CustomerIdProduct = product.GetXElementValue("CustomerId").ToGuid(),
                    Date          = DateTime.Now,
                    Description   = Config.Name,
                    Group         = RepositoryGroupProduct.GetGroupNameById(product.GetXElementValue("grp").ToInt()),
                    NameProduct   = product.GetXElementValue("Name"),
                    PrixHt        = Math.Round(product.GetXElementValue("price").ToDecimal(), 2),
                    ProductsWeb   = product.GetXElementValue("ProductsWeb_CustomerId").ToGuid(),
                    Qty           = product.GetXElementValue("qty").Replace('.', ',').ToDecimal(),
                    SubGroup      = RepositoryGroupProduct.GetGroupNameById(product.GetXElementValue("grp").ToInt()),
                    TesCustomerId = tes.CustomerId,
                    Tva           = RepositoryTva.GetById(product.GetXElementValue("tva").ToInt())
                };

                var tva = PrixTtcOnlyTva(product.GetXElementValue("price").ToDecimal(), prod.Tva);
                prod.PrixHt  = prod.PrixHt - tva;
                prod.TotalHt = prod.Qty * prod.PrixHt;
                prod.TypeId  = 1;
                tes.TesProducts.Add(prod);

                var qty = prod.Qty;
                var cusumerIdRealStock = product.GetXElementValue("cusumerIdRealStock").ToGuid();

                RepositoryStockReal.AddProductCount(-qty, cusumerIdRealStock);
            }

            foreach (var type in RepositoryTypePay.TypePays)
            {
                var reglement = new TesReglament();
                var r         = RepositoryTypePay.TypePays.FirstOrDefault(l => l.NameCourt == type.NameCourt);
                var elm       = x.GetXAttribute("check", type.NameCourt);

                if (elm != null && r != null)
                {
                    reglement.Caisse     = Config.NameTicket;
                    reglement.CustomerId = Guid.NewGuid();
                    reglement.DateTime   = DateTime.Now;

                    if (r.Name == "En espèces")
                    {
                        var rendux = x.GetXAttribute("check", "Rendu");

                        if (rendux != null)
                        {
                            var rendu = rendux.Value.ToDecimal();
                            reglement.Montant = elm.Value.ToDecimal() + rendu;
                        }
                        else
                        {
                            reglement.Montant = elm.Value.ToDecimal();
                        }
                    }
                    else
                    {
                        reglement.Montant = elm.Value.ToDecimal();
                    }

                    reglement.TesCustomerId = tes.CustomerId;
                    reglement.TypePay       = r.Name;
                    tes.TesReglaments.Add(reglement);
                }
                tes.Payement = (tes.TesReglaments.Sum(l => l.Montant) >= tes.Montant);
            }

            if (tes.TesReglaments.Count > 0)
            {
                var newTes = new Tes
                {
                    CustomerId       = Guid.NewGuid(),
                    ACodeFournisseur = (short)(Pro.Nclient),
                    AFrtva           = Pro.Frtva ?? string.Empty,
                    AMail            = Pro.Mail,
                    AName            = Pro.Name ?? string.Empty,
                    ASex             = Pro.SexToInt(Pro.Sex),
                    ASurname         = Pro.Surname ?? string.Empty,
                    ANameCompany     = Pro.NameCompany,
                    AOfficeAddress   = Pro.OfficeAddress ?? string.Empty,
                    AOfficeCity      = Pro.OfficeCity ?? string.Empty,
                    AOfficeZipCode   = Pro.OfficeZipCode ?? string.Empty,
                    ASiret           = Pro.Siret ?? string.Empty,
                    ATelephone       = Pro.Telephone,
                    DateTime         = DateTime.Now,
                    Description      = "{" + tes.CustomerId + "}{" + tes.Id + "}{" + tes.Type + "}",
                    Id           = RepositoryTes.MaxId(1) + 1,
                    Livraison    = tes.Livraison,
                    Montant      = decimal.Parse(x.Element("check").Attribute("sum").Value.Replace('.', ',')),
                    Nclient      = Pro.Nclient.ToString(),
                    Payement     = tes.Payement,
                    Type         = 1,
                    VAdresse     = tes.VAdresse,
                    VCodeNaf     = tes.VCodeNaf,
                    VCp          = tes.VCp,
                    VFax         = tes.VFax,
                    VFrtva       = tes.VFrtva,
                    VMail        = tes.VMail,
                    VNameCompany = tes.VNameCompany,
                    VPhone       = tes.VPhone,
                    VSiret       = tes.VSiret,
                    VVille       = tes.VVille
                };
                tes.Description = "{" + newTes.CustomerId + "}{" + newTes.Id + "}{" + newTes.Type + "}";

                foreach (var t in tes.TesReglaments)
                {
                    if (t.Montant > 0)
                    {
                        t.TesCustomerId = newTes.CustomerId;
                        newTes.TesReglaments.Add(t);
                    }
                }
                tes.TesReglaments.Clear();

                RepositoryTes.AddToDb(newTes);
            }

            RepositoryTes.AddToDb(tes);

            Nfact = tes.Id ?? -1;
            FileMove();
        }