Ejemplo n.º 1
0
        public bool DeleteNode(string Id, string TableNo, string Path, string KotFilePath, string ItemName)
        {
            int oulte = getOutletId();
            AdminCallOfferRepository offer = new AdminCallOfferRepository();

            offer.RemoveOffer(Id, Path, TableNo);
            XDocument xd = XDocument.Load(Path);

            if (Convert.ToInt32(Id) > 0)
            {
                var items = (from item in xd.Descendants("Items")
                             where item.Element("UserId").Value == oulte.ToString() && item.Element("ItemId").Value == Id && item.Element("TableNo").Value == TableNo
                             select item);
                items.Remove();
                xd.Save(Path);
                int       ItemId   = Convert.ToInt32(Id);
                var       Name     = _entities.tblItems.Where(o => o.ItemId == ItemId).Select(o => o.Name).FirstOrDefault();
                XDocument Kot      = XDocument.Load(KotFilePath);
                var       KotItems = (from item in Kot.Descendants("Items")
                                      where item.Element("UserId").Value == oulte.ToString() && item.Element("TableNo").Value == TableNo && item.Element("ItemName").Value == Name
                                      select item);
                KotItems.Remove();
                Kot.Save(KotFilePath);
            }
            else
            {
                var items = (from item in xd.Descendants("Items")
                             where item.Element("UserId").Value == oulte.ToString() && item.Element("ItemName").Value == ItemName && item.Element("TableNo").Value == TableNo
                             select item);
                items.Remove();
                xd.Save(Path);

                XDocument Kot      = XDocument.Load(KotFilePath);
                var       KotItems = (from item in Kot.Descendants("Items")
                                      where item.Element("UserId").Value == oulte.ToString() && item.Element("TableNo").Value == TableNo && item.Element("ItemName").Value == ItemName
                                      select item);
                KotItems.Remove();
                Kot.Save(KotFilePath);
            }
            return(true);
            //return FillFromXmlData(TableNo, Path, KotFilePath);
        }
        public bool CheckBillItem(GetBillItemModel model, string filepath, string KotFilePath)
        {
            XDocument xd = XDocument.Load(filepath);

            int     oulte          = getOutletId();
            var     result         = entities.tblBasePriceItems.Where(o => o.ItemId == model.ItemId).FirstOrDefault();
            var     QtyValue       = Convert.ToInt32(model.Qty);
            decimal finalfullamout = result.FullPrice * QtyValue;

            //decimal finalhalfamout = result.HalfPrice * QtyValue;
            if (model.Type == "Half")
            {
                xml.UpdateKotXmlData(filepath, KotFilePath, model.RunningTable.ToString(), result.tblItem.Name, "0", QtyValue.ToString());
            }
            else
            {
                xml.UpdateKotXmlData(filepath, KotFilePath, model.RunningTable.ToString(), result.tblItem.Name, QtyValue.ToString(), "0");
            }
            var items = from item in xd.Descendants("Items")
                        where item.Element("UserId").Value == oulte.ToString() && item.Element("TableNo").Value == model.RunningTable.ToString() && item.Element("ItemId").Value == model.ItemId.ToString()
                        select item;

            if (items.Count() > 0)
            {
                if (model.Type == "Half")
                {
                    foreach (XElement itemElement in items)
                    {
                        var totalamount = Convert.ToDecimal(finalfullamout) + Convert.ToDecimal(itemElement.Element("Amount").Value); //finalhalfamout
                        var vatamtchrg  = (totalamount * Convert.ToDecimal(Convert.ToDecimal(result.Vat)) / 100);                     //
                        itemElement.SetElementValue("UserId", oulte.ToString());
                        itemElement.SetElementValue("TableNo", model.RunningTable.ToString());
                        itemElement.SetElementValue("ItemId", result.ItemId);
                        itemElement.SetElementValue("ItemName", result.tblItem.Name);
                        itemElement.SetElementValue("FullQty", itemElement.Element("FullQty").Value);
                        itemElement.SetElementValue("Fullprice", result.FullPrice);
                        //itemElement.SetElementValue("HalfPrice", result.HalfPrice);
                        itemElement.SetElementValue("VatAmt", result.Vat);
                        itemElement.SetElementValue("HalfQty", Convert.ToInt32(QtyValue) + Convert.ToInt32(itemElement.Element("HalfQty").Value));
                        itemElement.SetElementValue("Amount", totalamount);
                        itemElement.SetElementValue("VatAmountCharges", vatamtchrg);
                        itemElement.SetElementValue("OfferQty", itemElement.Element("OfferQty").Value);
                    }
                }
                else
                {
                    foreach (XElement itemElement in items)
                    {
                        var totalamount = Convert.ToDecimal(finalfullamout) + Convert.ToDecimal(itemElement.Element("Amount").Value);
                        var vatamtchrg  = (totalamount * Convert.ToDecimal(Convert.ToDecimal(result.Vat)) / 100);
                        itemElement.SetElementValue("UserId", oulte.ToString());
                        itemElement.SetElementValue("TableNo", model.RunningTable.ToString());
                        itemElement.SetElementValue("ItemId", result.ItemId);
                        itemElement.SetElementValue("ItemName", result.tblItem.Name);
                        itemElement.SetElementValue("HalfQty", itemElement.Element("HalfQty").Value);
                        itemElement.SetElementValue("Fullprice", result.FullPrice);
                        //itemElement.SetElementValue("HalfPrice", result.HalfPrice);
                        itemElement.SetElementValue("VatAmt", result.Vat);
                        itemElement.SetElementValue("FullQty", Convert.ToInt32(QtyValue) + Convert.ToInt32(itemElement.Element("FullQty").Value));
                        itemElement.SetElementValue("Amount", totalamount);
                        itemElement.SetElementValue("VatAmountCharges", vatamtchrg);
                        itemElement.SetElementValue("OfferQty", itemElement.Element("OfferQty").Value);
                    }
                }
                xd.Save(filepath);
            }
            else
            {
                if (model.Type == "Half")
                {
                    //var totalamount = Convert.ToDecimal(finalhalfamout);
                    //var vatamtchrg = (totalamount * Convert.ToDecimal(Convert.ToDecimal(result.Vat)) / 100);
                    //var newElement = new XElement("Items",
                    //     new XElement("UserId", oulte.ToString()),
                    //     new XElement("TableNo", model.RunningTable),
                    //     new XElement("ItemId", result.ItemId),
                    //     new XElement("ItemName", result.tblItem.Name),
                    //     new XElement("FullQty", "0"),
                    //     new XElement("HalfQty", QtyValue),
                    //     new XElement("Fullprice", result.FullPrice),
                    //     new XElement("HalfPrice", result.HalfPrice),
                    //     new XElement("Amount", totalamount),
                    //     new XElement("VatAmt", result.Vat),
                    //     new XElement("VatAmountCharges", vatamtchrg),
                    //     new XElement("OfferQty", "0"));
                    //xd.Element("Item").Add(newElement);
                }
                else
                {
                    var totalamount = Convert.ToDecimal(finalfullamout);
                    var vatamtchrg  = (totalamount * Convert.ToDecimal(Convert.ToDecimal(result.Vat)) / 100);
                    var newElement  = new XElement("Items",
                                                   new XElement("UserId", oulte.ToString()),
                                                   new XElement("TableNo", model.RunningTable),
                                                   new XElement("ItemId", result.ItemId),
                                                   new XElement("ItemName", result.tblItem.Name),
                                                   new XElement("FullQty", QtyValue),
                                                   new XElement("HalfQty", "0"),
                                                   new XElement("Fullprice", result.FullPrice),
                                                   //new XElement("HalfPrice", result.HalfPrice),
                                                   new XElement("Amount", totalamount),
                                                   new XElement("VatAmt", result.Vat),
                                                   new XElement("VatAmountCharges", vatamtchrg),
                                                   new XElement("OfferQty", "0"));
                    xd.Element("Item").Add(newElement);
                }


                xd.Save(filepath);
            }
            if (model.Type == "Full")
            {
                SameItemOfferRepository same = new SameItemOfferRepository();
                bool s = same.CallSameBuyOneGetOne(model.ItemId.ToString(), filepath, model.RunningTable.ToString(), model.Qty.ToString(), KotFilePath);
                if (!s)
                {
                    return(true);
                }
                AdminCallHappyHoursRepository hh = new AdminCallHappyHoursRepository();;
                bool Happy = hh.CallHappyHoursDaysOffer(model.ItemId.ToString(), model.RunningTable.ToString(), filepath, KotFilePath);
                if (Happy == true)
                {
                    AdminCallOfferRepository offer = new AdminCallOfferRepository();
                    CallBuyOneGetOneANDBuyTwoGetOneRepository buy = new CallBuyOneGetOneANDBuyTwoGetOneRepository();
                    bool B1g1AndB2G1 = buy.CallOffer(model.ItemId.ToString(), filepath, model.RunningTable.ToString(), model.Qty.ToString(), KotFilePath);
                    if (B1g1AndB2G1)
                    {
                        bool Combo = offer.CallComboOffer(model.ItemId.ToString(), model.RunningTable.ToString(), filepath, KotFilePath);
                        if (Combo == true)
                        {
                            offer.CallAmountBasisOffer(model.ItemId.ToString(), model.RunningTable.ToString(), filepath, KotFilePath, model.Qty.ToString());
                        }
                    }
                    //bool Data = offer.CallOffer(model.ItemId.ToString(), filepath, model.RunningTable.ToString(), model.Qty.ToString(), KotFilePath);
                    //if (Data == true)
                    //{

                    //}
                }
            }
            return(true);
        }