コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }