public string DispatchOrder(OrderDispatchHomeModel model, string Path)
        {
            try
            {
                int           oulte = getOutletId();
                tblBillMaster tb    = new tblBillMaster();
                tb.BillDate            = DateTime.Now.Date;
                tb.BillingType         = "Door Delivery Hall";
                tb.CustomerName        = model.CustomerName;
                tb.DiscountAmount      = model.DiscountAmount;
                tb.NetAmount           = model.NetAmount;
                tb.ServicChargesAmount = model.ServiceCharge;
                tb.TotalAmount         = model.TotalAmount;
                tb.VatAmount           = model.VatAmount;
                tb.Address             = model.Address;
                tb.OutletId            = oulte;
                tb.TokenNo             = model.TokenNo;
                _entities.tblBillMasters.Add(tb);
                _entities.SaveChanges();
                var       Id = _entities.tblBillMasters.Where(o => o.OutletId == oulte && o.BillingType == "Door Delivery Hall").Select(x => x.BillId).Max();
                XDocument xd = XDocument.Load(Path);

                var result = from item in xd.Descendants("Items")
                             where item.Element("UserId").Value == oulte.ToString()
                             select item;
                foreach (var item in result)
                {
                    tblBillDetail bill = new tblBillDetail();
                    bill.Amount  = Convert.ToDecimal(item.Element("TotalAmount").Value);
                    bill.FullQty = Convert.ToInt32(item.Element("FullQty").Value);
                    bill.HalfQty = Convert.ToInt32(item.Element("HalfQty").Value);
                    bill.ItemId  = Convert.ToInt32(item.Element("ItemId").Value);
                    bill.BillId  = Id;
                    _entities.tblBillDetails.Add(bill);
                    _entities.SaveChanges();
                }
                var items = from item in xd.Descendants("Items")
                            where item.Element("UserId").Value == oulte.ToString()
                            select item;
                items.Remove();
                xd.Save(Path);
                return(PrintData(Id.ToString(), model.TokenNo.ToString()));
            }
            catch
            {
                return("0");
            }
        }
        public bool DispatchOrder(GetBillingModel model, string Path)
        {
            try
            {
                int       oulte  = xml.getOutletId();
                XDocument xd     = XDocument.Load(Path);
                var       result = (from item in xd.Descendants("Items")
                                    where item.Element("UserId").Value == oulte.ToString()
                                    select item).ToList();

                tblBillMaster tb = new tblBillMaster();
                tb.BillDate            = DateTime.Now.Date;
                tb.BillingType         = "T";
                tb.CustomerName        = model.CustomerName;
                tb.DiscountAmount      = model.DiscountAmount;
                tb.NetAmount           = Math.Round(model.NetAmount, 2);
                tb.ServicChargesAmount = Math.Round(model.ServicesCharge, 2);
                tb.TotalAmount         = Math.Round(model.TotalAmount, 2);
                tb.VatAmount           = Math.Round(model.VatAmount, 2);
                tb.TokenNo             = Convert.ToInt32(model.TableNo);
                tb.PaymentType         = model.PaymentType;
                tb.ChequeNo            = model.ChequeNo;
                tb.ChequeDate          = model.CheckDate;
                tb.OutletId            = oulte;
                tb.Discount            = model.Discount;
                _entities.tblBillMasters.Add(tb);
                _entities.SaveChanges();
                //var Id = _entities.tblBillMasters.Where(o => o.OutletId == oulte && o.BillingType == "R").Select(x => x.BillId).Max();

                foreach (var item in result)
                {
                    tblBillDetail bill = new tblBillDetail();
                    bill.Amount  = Convert.ToDecimal(item.Element("TotalAmount").Value);
                    bill.FullQty = Convert.ToInt32(item.Element("FullQty").Value);
                    bill.HalfQty = Convert.ToInt32(item.Element("HalfQty").Value);
                    bill.ItemId  = Convert.ToInt32(item.Element("ItemId").Value);
                    bill.Vat     = Convert.ToDecimal(item.Element("Vat").Value);
                    decimal VatAmt = 0;
                    if (model.Discount > 0)
                    {
                        decimal dis = Convert.ToDecimal(item.Element("VatAmt").Value);
                        decimal vat = (model.Discount * dis) / 100;
                        VatAmt = dis - vat;
                    }
                    else
                    {
                        VatAmt = Convert.ToDecimal(item.Element("VatAmt").Value);
                    }
                    bill.VatAmount = VatAmt * Convert.ToInt32(item.Element("FullQty").Value);
                    bill.BillId    = tb.BillId;
                    _entities.tblBillDetails.Add(bill);
                    _entities.SaveChanges();
                    // call auto inventory start..
                    AutoInventoryRepository auto = new AutoInventoryRepository();
                    auto.AutoInventory(Convert.ToInt32(item.Element("ItemId").Value), Convert.ToInt32(item.Element("FullQty").Value), Convert.ToInt32(item.Element("HalfQty").Value), oulte);
                }

                var items = (from item in xd.Descendants("Items")
                             where item.Element("UserId").Value == oulte.ToString()
                             select item);

                items.Remove();
                xd.Save(Path);
                CheckStockItemRepository check = new CheckStockItemRepository();
                string chk = check.OutStockItems(tb.BillId);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #3
0
        public int DispatchOrder(GetBillingModel model, string Path)
        {
            try
            {
                int       oulte  = getOutletId();
                XDocument xd     = XDocument.Load(Path);
                var       result = (from item in xd.Descendants("Items")
                                    where item.Element("UserId").Value == oulte.ToString()
                                    select item).ToList();
                decimal totalVat = 0;
                foreach (var item in result)
                {
                    decimal VatAmt = 0;
                    if (model.Discount > 0)
                    {
                        decimal dis = Convert.ToDecimal(item.Element("VatAmountCharges").Value);
                        decimal vat = (model.Discount * dis) / 100;
                        VatAmt = dis - vat;
                    }
                    else
                    {
                        VatAmt = Convert.ToDecimal(item.Element("VatAmountCharges").Value);
                    }
                    totalVat = totalVat + VatAmt;
                }
                tblBillMaster tb = new tblBillMaster();
                tb.BillDate            = DateTime.Now;
                tb.BillingType         = model.OrderType;
                tb.CustomerName        = model.CustomerName;
                tb.Address             = model.CustomerAddress;
                tb.PackingCharges      = model.PackingCharges;
                tb.ContactNo           = model.ContactNo;
                tb.DiscountAmount      = model.DiscountAmount;
                tb.NetAmount           = model.NetAmount;
                tb.ServicChargesAmount = model.ServicesCharge;
                tb.TotalAmount         = model.TotalAmount;
                tb.Isprinted           = true;
                //tb.VatAmount = model.VatAmount;
                tb.VatAmount   = totalVat;
                tb.ServiceTax  = model.ServiceTax;
                tb.TableNo     = (model.TableNo);
                tb.PaymentType = model.PaymentType;
                tb.ChequeNo    = model.ChequeNo;
                tb.ChequeDate  = model.CheckDate;
                tb.OutletId    = oulte;
                tb.Discount    = model.Discount;
                tb.NetAmountWithoutDiscount = model.NetAmountWithoutDiscount;
                tb.ContactNo = model.ContactNo;
                _entities.tblBillMasters.Add(tb);
                _entities.SaveChanges();


                foreach (var item in result)
                {
                    int ItemId = Convert.ToInt32(item.Element("ItemId").Value);
                    if (ItemId == 0)
                    {
                        //OpenFood food = new OpenFood();
                        //food.Date = DateTime.Now.Date;
                        //food.ItemName = item.Element("ItemName").Value;
                        //food.OutletId = oulte;
                        //food.Price = Convert.ToDecimal(item.Element("Fullprice").Value);
                        //food.Quantity = Convert.ToInt32(item.Element("FullQty").Value);
                        //food.Amount = Convert.ToDecimal(item.Element("Amount").Value);
                        //food.Vat = Convert.ToInt32(item.Element("VatAmt").Value);
                        //_entities.OpenFoods.Add(food);
                        //_entities.SaveChanges();
                    }
                    else
                    {
                        tblBillDetail bill = new tblBillDetail();
                        bill.Amount  = Convert.ToDecimal(item.Element("Amount").Value);
                        bill.FullQty = Convert.ToInt32(item.Element("FullQty").Value);
                        bill.HalfQty = Convert.ToInt32(item.Element("HalfQty").Value);
                        bill.ItemId  = Convert.ToInt32(item.Element("ItemId").Value);
                        bill.Vat     = Convert.ToDecimal(item.Element("VatAmt").Value);
                        decimal VatAmt = 0;
                        if (model.Discount > 0)
                        {
                            decimal dis = Convert.ToDecimal(item.Element("VatAmountCharges").Value);
                            decimal vat = (model.Discount * dis) / 100;
                            VatAmt = dis - vat;
                        }
                        else
                        {
                            VatAmt = Convert.ToDecimal(item.Element("VatAmountCharges").Value);
                        }
                        bill.VatAmount = Math.Truncate(VatAmt * 100) / 100;
                        bill.BillId    = tb.BillId;
                        _entities.tblBillDetails.Add(bill);
                        _entities.SaveChanges();
                        // call auto inventory start..
                        AutoInventoryRepository auto = new AutoInventoryRepository();
                        auto.AutoInventory(Convert.ToInt32(item.Element("ItemId").Value), Convert.ToInt32(item.Element("FullQty").Value), Convert.ToInt32(item.Element("HalfQty").Value), oulte);
                    }
                }

                //var items = (from item in xd.Descendants("Items")
                //             where item.Element("UserId").Value == oulte.ToString()
                //             select item);

                //items.Remove();
                //xd.Save(Path);
                CheckStockItemRepository check = new CheckStockItemRepository();
                // string chk = check.OutStockItems(Id);
                return(tb.BillId);
            }
            catch (Exception ex)
            {
                //Error error = new Error();
                //error.ErrorMessage = ex.Message;
                //_entities.Errors.Add(error);
                //_entities.SaveChanges();
                return(0);
            }
        }
Beispiel #4
0
        public JsonResult  syncKot()
        {
            DateTime dt         = Convert.ToDateTime(DateTime.Today.ToString("dd-MMM-yyyy"));
            var      billsKOT   = (from p in kot_entities.vwBillMsts where p.BillDate >= dt select p).ToList();
            var      billsCount = (from p in entities.tblBillMasters where p.BillDate >= dt select p).ToList().Count;

            if (billsKOT.Count > billsCount)
            {
                foreach (var item in billsKOT)
                {
                    var itemcheck = (from p in entities.tblBillMasters where p.TokenNo == item.BillNo && p.BillingType == item.Description && p.BillDate == item.BillDate select p).FirstOrDefault();


                    if (itemcheck == null)
                    {
                        var           waiterid = (from p in kot_entities.BillTrans where p.UID >= item.UID select p).FirstOrDefault();
                        var           waiter   = (from p in kot_entities.VW_GetEmployee where p.AccountM_UID >= waiterid.Waiter_UID select p.EmployeeName).FirstOrDefault();
                        tblBillMaster tb       = new tblBillMaster();
                        tb.BillDate                 = item.BillDate;
                        tb.TotalAmount              = item.Total;
                        tb.VatAmount                = Convert.ToDecimal(item.taxamount);
                        tb.ServicChargesAmount      = item.serviceChrge;
                        tb.DiscountAmount           = item.Discount;
                        tb.NetAmount                = item.NettValue;
                        tb.TableNo                  = item.tableNo == null ? "" : item.tableNo;
                        tb.CustomerName             = "";
                        tb.OutletId                 = item.outlet;
                        tb.BillingType              = item.Description;
                        tb.TokenNo                  = Convert.ToInt32(item.BillNo);
                        tb.Address                  = item.address;
                        tb.PaymentType              = item.paymenttype;
                        tb.ChequeNo                 = item.chqno;
                        tb.ChequeDate               = Convert.ToDateTime("01-Jan-1900");// item.chqdate
                        tb.Discount                 = item.disPer;
                        tb.ContactNo                = item.contactNo;
                        tb.PackingCharges           = item.packingChags;
                        tb.ServiceTax               = item.Servicetax;
                        tb.Isprinted                = Convert.ToBoolean(item.isprnt);
                        tb.NetAmountWithoutDiscount = item.befDisc;
                        tb.CreateDateTime           = waiterid.CreatedDate;
                        tb.Waiter = waiter;
                        entities.tblBillMasters.Add(tb);
                        entities.SaveChanges();

                        var billsDetKOT = (from p in kot_entities.vwBillDets where p.BillTrans_UID.Equals(item.UID) select p).ToList();
                        foreach (var itemDet in billsDetKOT)
                        {
                            tblBillDetail tbDet  = new tblBillDetail();
                            int           billid = (from p in entities.tblBillMasters select p.BillId).Max();
                            var           itemid = (from p in entities.tblItems where p.Name == itemDet.ItemName && p.ItemCode == itemDet.ItemCode select p.ItemId).SingleOrDefault();
                            tbDet.BillId  = billid;
                            tbDet.ItemId  = itemid;
                            tbDet.FullQty = (Int32)itemDet.Qty;
                            tbDet.HalfQty = 0;
                            tbDet.Amount  = itemDet.Value;

                            if (item.Description == "Ac Hall")
                            {
                                tbDet.VatAmount = itemDet.Value + (itemDet.Value * (decimal)0.05);
                            }
                            else
                            {
                                tbDet.VatAmount = itemDet.Value + (itemDet.Value * (decimal)0.05);
                            }

                            if (item.Description == "Ac Hall")
                            {
                                tbDet.Vat = Convert.ToDecimal("5");
                            }
                            else
                            {
                                tbDet.Vat = Convert.ToDecimal("5");
                            }

                            entities.tblBillDetails.Add(tbDet);
                            entities.SaveChanges();

                            var chkSub = (from p in entities.tblAssignSubMenuItems where p.Mainitemid == tbDet.ItemId select p).ToList();
                            if (chkSub.Count > 0)
                            {
                                var RawList1 = entities.getSubItemsRaw(tbDet.ItemId).ToList();

                                if (RawList1 != null)
                                {
                                    if (RawList1.Count > 0)
                                    {
                                        foreach (var li in RawList1)
                                        {
                                            decimal qty   = itemDet.Qty * Convert.ToDecimal(li.Qty / li.Portion);
                                            string  pUnit = entities.tbl_RawMaterials.Where(x => x.RawMaterialId == li.RawMaterialId).Select(x => x.units).SingleOrDefault();
                                            string  cUnit = li.Unit;
                                            // Convert cUnit (Consumption Unit)  from pUnit (Purchase Unit)
                                            if (pUnit != cUnit)
                                            {
                                                qty = unitConvert(qty, cUnit, pUnit);
                                            }
                                            qty = Math.Round(qty, 2, MidpointRounding.AwayFromZero);
                                            if (qty == 0)
                                            {
                                                qty = (decimal)0.01;
                                            }
                                            string qry = "  select Id,MaterialId,Rate,Date,Qty,IssQty,ConsumptionQty=isnull(ConsumptionQty,0),table1='os' from tblOpStckRate where IssQty > isnull(ConsumptionQty,0)   and MaterialId = " + li.RawMaterialId;
                                            qry = qry + " union all ";
                                            qry = qry + " select Id,MaterialId,Rate,Date,Qty,IssQty,ConsumptionQty=isnull(ConsumptionQty,0),table1='gs' from tblGRNStock where IssQty > isnull(ConsumptionQty,0)   and MaterialId = " + li.RawMaterialId + " order by date ";
                                            string         webconnection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
                                            SqlConnection  con           = new SqlConnection(webconnection);
                                            SqlCommand     cmd           = new SqlCommand(qry, con);
                                            DataTable      dt1           = new DataTable();
                                            SqlDataAdapter sda           = new SqlDataAdapter(cmd);
                                            sda.Fill(dt1);
                                            qry = "";
                                            foreach (DataRow dr in dt1.Rows)
                                            {
                                                if (qty > 0)
                                                {
                                                    if (dr["table1"].ToString() == "os")
                                                    {
                                                        if (qty <= Convert.ToDecimal(dr["IssQty"]) - Convert.ToDecimal(dr["ConsumptionQty"]))
                                                        {
                                                            qry  = qry + " update tblOpStckRate  set ConsumptionQty = isnull(ConsumptionQty,0) + " + qty + " where MaterialId = " + li.RawMaterialId + " and id=" + dr["id"];
                                                            qry  = qry + " insert into  tblConsumption values( " + tbDet.BillDetailsId + ", '" + li.RawMaterialId + "', " + qty + "," + dr["Rate"].ToString() + " ) ";
                                                            qty -= qty;
                                                        }
                                                        else
                                                        {
                                                            qry  = qry + " update tblOpStckRate  set ConsumptionQty = isnull(ConsumptionQty,0) + " + (Convert.ToDecimal(dr["IssQty"]) - Convert.ToDecimal(dr["ConsumptionQty"])) + " where MaterialId = " + li.RawMaterialId + " and id=" + dr["id"];
                                                            qry  = qry + " insert into  tblConsumption values( " + tbDet.BillDetailsId + ", '" + li.RawMaterialId + "', " + Convert.ToDecimal(dr["ConsumptionQty"]) + "," + dr["Rate"].ToString() + " ) ";
                                                            qty -= Convert.ToDecimal(dr["ConsumptionQty"]);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (qty <= Convert.ToDecimal(dr["IssQty"]) - Convert.ToDecimal(dr["ConsumptionQty"]))
                                                        {
                                                            qry  = qry + " update tblGRNStock  set ConsumptionQty = isnull(ConsumptionQty,0) + " + qty + " where MaterialId = " + li.RawMaterialId + " and id=" + dr["id"];
                                                            qry  = qry + " insert into  tblConsumption values( " + tbDet.BillDetailsId + ", '" + li.RawMaterialId + "', " + qty + "," + dr["Rate"].ToString() + " ) ";
                                                            qty -= qty;
                                                        }
                                                        else
                                                        {
                                                            qry  = qry + " update tblGRNStock  set ConsumptionQty = isnull(ConsumptionQty,0) + " + (Convert.ToDecimal(dr["IssQty"]) - Convert.ToDecimal(dr["ConsumptionQty"])) + " where MaterialId = " + li.RawMaterialId + " and id=" + dr["id"];
                                                            qry  = qry + " insert into  tblConsumption values( " + tbDet.BillDetailsId + ", '" + li.RawMaterialId + "', " + Convert.ToDecimal(dr["ConsumptionQty"]) + "," + dr["Rate"].ToString() + " ) ";
                                                            qty -= Convert.ToDecimal(dr["ConsumptionQty"]);
                                                        }
                                                    }
                                                }
                                            }
                                            con = new SqlConnection(webconnection);
                                            con.Open();
                                            cmd = new SqlCommand(qry, con);
                                            cmd.ExecuteNonQuery();
                                            con.Close();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                var RawList = (from p in entities.tbl_KitchenRawIndent where p.ItemId == tbDet.ItemId select p).ToList();


                                if (RawList != null)
                                {
                                    if (RawList.Count > 0)
                                    {
                                        foreach (var li in RawList)
                                        {
                                            decimal qty   = itemDet.Qty * Convert.ToDecimal(li.Quantity / li.Portion);
                                            string  pUnit = li.tbl_RawMaterials.units;
                                            string  cUnit = li.Unit;
                                            // Convert cUnit (Consumption Unit)  from pUnit (Purchase Unit)
                                            if (pUnit != cUnit)
                                            {
                                                qty = unitConvert(qty, cUnit, pUnit);
                                            }
                                            qty = Math.Round(qty, 2, MidpointRounding.AwayFromZero);
                                            if (qty == 0)
                                            {
                                                qty = (decimal)0.01;
                                            }
                                            string qry = "  select Id,MaterialId,Rate,Date,Qty,IssQty,ConsumptionQty=isnull(ConsumptionQty,0),table1='os' from tblOpStckRate where IssQty > isnull(ConsumptionQty,0)   and MaterialId = " + li.RawMaterialId;
                                            qry = qry + " union all ";
                                            qry = qry + " select Id,MaterialId,Rate,Date,Qty,IssQty,ConsumptionQty=isnull(ConsumptionQty,0),table1='gs' from tblGRNStock where IssQty > isnull(ConsumptionQty,0)   and MaterialId = " + li.RawMaterialId + " order by date ";
                                            string         webconnection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
                                            SqlConnection  con           = new SqlConnection(webconnection);
                                            SqlCommand     cmd           = new SqlCommand(qry, con);
                                            DataTable      dt1           = new DataTable();
                                            SqlDataAdapter sda           = new SqlDataAdapter(cmd);
                                            sda.Fill(dt1);
                                            qry = "";
                                            foreach (DataRow dr in dt1.Rows)
                                            {
                                                if (qty > 0)
                                                {
                                                    if (dr["table1"].ToString() == "os")
                                                    {
                                                        if (qty <= Convert.ToDecimal(dr["IssQty"]) - Convert.ToDecimal(dr["ConsumptionQty"]))
                                                        {
                                                            qry  = qry + " update tblOpStckRate  set ConsumptionQty = isnull(ConsumptionQty,0) + " + qty + " where MaterialId = " + li.RawMaterialId + " and id=" + dr["id"];
                                                            qry  = qry + " insert into  tblConsumption values( " + tbDet.BillDetailsId + ", '" + li.RawMaterialId + "', " + qty + "," + dr["Rate"].ToString() + " ) ";
                                                            qty -= qty;
                                                        }
                                                        else
                                                        {
                                                            qry  = qry + " update tblOpStckRate  set ConsumptionQty = isnull(ConsumptionQty,0) + " + (Convert.ToDecimal(dr["IssQty"]) - Convert.ToDecimal(dr["ConsumptionQty"])) + " where MaterialId = " + li.RawMaterialId + " and id=" + dr["id"];
                                                            qry  = qry + " insert into  tblConsumption values( " + tbDet.BillDetailsId + ", '" + li.RawMaterialId + "', " + Convert.ToDecimal(dr["ConsumptionQty"]) + "," + dr["Rate"].ToString() + " ) ";
                                                            qty -= Convert.ToDecimal(dr["ConsumptionQty"]);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (qty <= Convert.ToDecimal(dr["IssQty"]) - Convert.ToDecimal(dr["ConsumptionQty"]))
                                                        {
                                                            qry  = qry + " update tblGRNStock  set ConsumptionQty = isnull(ConsumptionQty,0) + " + qty + " where MaterialId = " + li.RawMaterialId + " and id=" + dr["id"];
                                                            qry  = qry + " insert into  tblConsumption values( " + tbDet.BillDetailsId + ", '" + li.RawMaterialId + "', " + qty + "," + dr["Rate"].ToString() + " ) ";
                                                            qty -= qty;
                                                        }
                                                        else
                                                        {
                                                            qry  = qry + " update tblGRNStock  set ConsumptionQty = isnull(ConsumptionQty,0) + " + (Convert.ToDecimal(dr["IssQty"]) - Convert.ToDecimal(dr["ConsumptionQty"])) + " where MaterialId = " + li.RawMaterialId + " and id=" + dr["id"];
                                                            qry  = qry + " insert into  tblConsumption values( " + tbDet.BillDetailsId + ", '" + li.RawMaterialId + "', " + Convert.ToDecimal(dr["ConsumptionQty"]) + "," + dr["Rate"].ToString() + " ) ";
                                                            qty -= Convert.ToDecimal(dr["ConsumptionQty"]);
                                                        }
                                                    }
                                                }
                                            }
                                            con = new SqlConnection(webconnection);
                                            con.Open();
                                            cmd = new SqlCommand(qry, con);
                                            cmd.ExecuteNonQuery();
                                            con.Close();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(Json(JsonRequestBehavior.AllowGet));
        }