예제 #1
0
        public async Task <bool> DeleteEmpyItems(InvoiceHeaderSet invoiceHeaderSet)
        {
            await Task.Run(() =>
            {
                using (CasierContents context = new CasierContents())
                {
                    if (invoiceHeaderSet != null)
                    {
                        InvoiceHeaderSet CurrentInvoiceHeaderSet = context.InvoiceHeaderSet.Include("InvoiceHeaderDetailsSet.ItemSet").Include("ReservationSet").Where(x => x.InvoiceHeaderSetId == invoiceHeaderSet.InvoiceHeaderSetId).FirstOrDefault() ?? null;
                        if (CurrentInvoiceHeaderSet != null)
                        {
                            if (CurrentInvoiceHeaderSet.InvoiceHeaderDetailsSet.Count != 0)
                            {
                                foreach (var item in CurrentInvoiceHeaderSet.InvoiceHeaderDetailsSet.ToList())
                                {
                                    if (item.Quantity <= 0)
                                    {
                                        CurrentInvoiceHeaderSet.InvoiceHeaderDetailsSet.ToList().ForEach(p => p.InvoiceHeaderSet.InvoiceHeaderDetailsSet.Remove(item));
                                        context.Entry(item).State = EntityState.Deleted;
                                    }
                                }
                            }
                            else if (CurrentInvoiceHeaderSet.InvoiceHeaderDetailsSet.Count == 0 && CurrentInvoiceHeaderSet.ReservationSet == null)
                            {
                                context.InvoiceHeaderSet.Remove(CurrentInvoiceHeaderSet);
                            }
                            context.SaveChanges();
                        }
                    }
                }
            });

            return(true);
        }
예제 #2
0
 public async Task <InvoiceHeaderSet> InsertInvoiceDeitails(int invoiceHeader, int quantity, string number)
 {
     return(await Task.Factory.StartNew(() =>
     {
         using (CasierContents context = new CasierContents())
         {
             {
                 InvoiceHeaderSet findInvoiceHeaderSet = context.InvoiceHeaderSet.Include("InvoiceHeaderDetailsSet.ItemSet").Where(x => x.InvoiceHeaderSetId == invoiceHeader).FirstOrDefault() ?? null;
                 {
                     if (findInvoiceHeaderSet.InvoiceHeaderDetailsSet.Count == 0)
                     {
                         InvoiceHeaderDetailsSet CreateNewInvoiceHeaderDetailset = new InvoiceHeaderDetailsSet();
                         CreateNewInvoiceHeaderDetailset.OrderTime = DateTime.Now;
                         ItemSet itemSet = context.ItemSet.Where(x => x.Number == number).FirstOrDefault() ?? null;
                         CreateNewInvoiceHeaderDetailset.ItemSet = itemSet;
                         if (CreateNewInvoiceHeaderDetailset.Quantity == null)
                         {
                             CreateNewInvoiceHeaderDetailset.Quantity = (short)quantity;
                         }
                         findInvoiceHeaderSet.InvoiceHeaderDetailsSet.Add(CreateNewInvoiceHeaderDetailset);
                     }
                     // hvis der er flere items så skal der lægges sammen.
                     else if (findInvoiceHeaderSet.InvoiceHeaderDetailsSet.Count > 0)
                     {
                         var findTheCOrrectOne = findInvoiceHeaderSet.InvoiceHeaderDetailsSet.Where(x => x.ItemSet.Number == number).FirstOrDefault();
                         if (findTheCOrrectOne != null)
                         {
                             if (findTheCOrrectOne.Quantity != null)
                             {
                                 findTheCOrrectOne.Quantity += (short)quantity;
                             }
                             else
                             {
                                 findTheCOrrectOne.Quantity = (short)quantity;
                             }
                             if (findTheCOrrectOne.Quantity <= 0)
                             {
                                 context.InvoiceHeaderDetailsSet.Remove(findTheCOrrectOne);
                             }
                         }
                         else if (findTheCOrrectOne == null && quantity > 0)
                         {
                             InvoiceHeaderDetailsSet CreateNewInvoiceHeaderDetailsets = new InvoiceHeaderDetailsSet();
                             CreateNewInvoiceHeaderDetailsets.OrderTime = DateTime.Now;
                             ItemSet itemSet = context.ItemSet.Where(x => x.Number == number).FirstOrDefault() ?? null;
                             CreateNewInvoiceHeaderDetailsets.ItemSet = itemSet;
                             itemSet.InvoiceHeaderDetailsSet.Add(CreateNewInvoiceHeaderDetailsets);
                             CreateNewInvoiceHeaderDetailsets.Quantity = (short)quantity;
                             findInvoiceHeaderSet.InvoiceHeaderDetailsSet.Add(CreateNewInvoiceHeaderDetailsets);
                         }
                     }
                 }
                 context.SaveChanges();
                 context.InvoiceHeaderSet.Add(findInvoiceHeaderSet);
                 return findInvoiceHeaderSet;
             }
         }
     }));
 }
예제 #3
0
        public async Task <InvoiceHeaderSet> splitUpForV(InvoiceHeaderSet invoiceHeaderSet, List <InvoiceHeaderDetailsSet> invoiceDetails, bool takeAway, int total)
        {
            return(await Task.Factory.StartNew(() =>
            {
                using (CasierContents context = new CasierContents())
                {
                    int TakeAwayTotal = 0;
                    InvoiceHeaderSet currentInvoiceHeaderSet = new InvoiceHeaderSet();
                    currentInvoiceHeaderSet.PayDate = DateTime.Now;
                    currentInvoiceHeaderSet.Number = invoiceHeaderSet.Number;
                    //currentInvoiceHeaderSet.InvoiceHeaderDetailsSet = invoiceDetails;
                    foreach (var item in invoiceDetails)
                    {
                        InvoiceHeaderDetailsSet CreateNewInvoiceHeaderDetailsets = new InvoiceHeaderDetailsSet();
                        ItemSet itemSet = context.ItemSet.Where(x => x.Number == item.ItemSet.Number).FirstOrDefault() ?? null;
                        CreateNewInvoiceHeaderDetailsets.ItemSet = itemSet;
                        CreateNewInvoiceHeaderDetailsets.Quantity = item.Quantity;
                        CreateNewInvoiceHeaderDetailsets.OrderTime = DateTime.Now;
                        currentInvoiceHeaderSet.InvoiceHeaderDetailsSet.Add(CreateNewInvoiceHeaderDetailsets);
                        int quantity = (int)item.Quantity;
                        int price = (int)(item.ItemSet.Price);
                        int sum = quantity *price;
                        if (item.ItemSet.Discount != null)
                        {
                            int rabat = (int)item.ItemSet.Price * (int)item.ItemSet.Discount / 100;
                            sum = sum - rabat;
                        }

                        TakeAwayTotal += (int)sum;
                    }

                    if (takeAway)
                    {
                        currentInvoiceHeaderSet.Total = TakeAwayTotal;
                    }
                    else
                    {
                        currentInvoiceHeaderSet.Total = total;
                    }

                    context.InvoiceHeaderSet.Add(currentInvoiceHeaderSet);
                    //  context.SaveChanges();

                    // update newone


                    InvoiceHeaderSet currentInvoiceHeader = context.InvoiceHeaderSet.Include("InvoiceHeaderDetailsSet.ItemSet").Where(x => x.InvoiceHeaderSetId == invoiceHeaderSet.InvoiceHeaderSetId).FirstOrDefault() ?? null;
                    foreach (var item in invoiceHeaderSet.InvoiceHeaderDetailsSet)
                    {
                        context.InvoiceHeaderDetailsSet.AddOrUpdate(item);
                    }


                    context.SaveChanges();
                    return currentInvoiceHeader;
                }
            }));
        }
예제 #4
0
        public async System.Threading.Tasks.Task <JsonResult> splitUpForV(InvoiceHeaderSet invoiceHeaderSet, List <InvoiceHeaderDetailsSet> invoiceDetails, bool takeAway, int total)
        {
            var result = await catalog.splitUpForV(invoiceHeaderSet, invoiceDetails, takeAway, total);

            return(Json(JsonConvert.SerializeObject(result, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            }), JsonRequestBehavior.AllowGet));
        }
예제 #5
0
        public async System.Threading.Tasks.Task <JsonResult> DeleteReservationSet(InvoiceHeaderSet invoiceHeaderSet)
        {
            var result = await catalog.DeleteReservationSet(invoiceHeaderSet);

            return(Json(JsonConvert.SerializeObject(result, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            }), JsonRequestBehavior.AllowGet));
        }
예제 #6
0
        public async Task <InvoiceHeaderSet> CreateInvoiceAndReservation(InvoiceHeaderSet invoiceHeaderSet)
        {
            return(await Task.Factory.StartNew(() =>
            {
                using (CasierContents context = new CasierContents())
                {
                    // check the dubllicate date.
                    var existedItem = context.InvoiceHeaderSet.Include("ReservationSet").Where(u => u.InvoiceHeaderSetId == invoiceHeaderSet.InvoiceHeaderSetId).FirstOrDefault();
                    InvoiceHeaderSet addNewInvoiceHeader = null;
                    if (existedItem != null)
                    {
                        existedItem.ReservationSet.Name = invoiceHeaderSet.ReservationSet.Name;
                        existedItem.ReservationSet.Phone = invoiceHeaderSet.ReservationSet.Phone;
                        existedItem.ReservationSet.Description = invoiceHeaderSet.ReservationSet.Description;
                        existedItem.ReservationSet.Email = invoiceHeaderSet.ReservationSet.Email;
                        existedItem.ReservationSet.Amount = invoiceHeaderSet.ReservationSet.Amount;
                        existedItem.ReservationSet.DateTime = invoiceHeaderSet.ReservationSet.DateTime;
                        existedItem.Number = invoiceHeaderSet.Number;
                        context.SaveChanges();
                        return existedItem;
                    }
                    else
                    {
                        DateTime ResevationSearchDate = invoiceHeaderSet.CreateDate.Value;
                        var result = context.InvoiceHeaderSet.Include("ReservationSet").Where(u => u.Number == invoiceHeaderSet.Number && u.PayDate == null && u.Description == null && ResevationSearchDate.Date.Day == u.CreateDate.Value.Day && ResevationSearchDate.Date.Month == u.CreateDate.Value.Month && ResevationSearchDate.Date.Year == u.CreateDate.Value.Year).ToList() ?? null;
                        if (result.Count >= 1)
                        {
                            foreach (var invoiceHeaders in result)
                            {
                                DateTime reservationDate = invoiceHeaders.CreateDate.Value;

                                int one = reservationDate.TimeOfDay.Hours * 60 + reservationDate.Minute;
                                int two = ResevationSearchDate.TimeOfDay.Hours * 60 + ResevationSearchDate.Minute;

                                int diff = Math.Abs(one - two);

                                if (diff >= 180)
                                {
                                    addNewInvoiceHeader = context.InvoiceHeaderSet.Add(invoiceHeaderSet);
                                    context.SaveChanges();
                                }
                            }
                        }
                        else
                        {
                            addNewInvoiceHeader = context.InvoiceHeaderSet.Add(invoiceHeaderSet);
                            context.SaveChanges();
                        }
                    }
                    return addNewInvoiceHeader;
                }
            }));
        }
예제 #7
0
        public async Task <bool> DeleteCurrentItem(InvoiceHeaderSet invoiceHeaderSet)
        {
            using (CasierContents context = new CasierContents())
            {
                await Task.Run(() =>
                {
                    if (invoiceHeaderSet != null)
                    {
                        var CurrentInvoiceHeaderSet = context.InvoiceHeaderSet.Where(x => x.InvoiceHeaderSetId == invoiceHeaderSet.InvoiceHeaderSetId).FirstOrDefault();
                        //context.InvoiceHeaderSet.Attach(CurrentInvoiceHeaderSet);
                        CurrentInvoiceHeaderSet.Description = "" + DateTime.Now + " blev slettet";
                        context.SaveChanges();
                    }
                });

                return(true);
            }
        }
예제 #8
0
        public async Task <bool> DeleteReservationSet(InvoiceHeaderSet invoiceHeaderSet)
        {
            return(await Task.Factory.StartNew(() =>
            {
                using (CasierContents context = new CasierContents())
                {
                    var deleteItemReservationSet = context.ReservationSet.Find(invoiceHeaderSet.ReservationSet.ReservationId);
                    context.ReservationSet.Remove(deleteItemReservationSet);


                    var deleteItemInvoiceHeader = context.InvoiceHeaderSet.Find(invoiceHeaderSet.InvoiceHeaderSetId);
                    context.InvoiceHeaderSet.Remove(deleteItemInvoiceHeader);
                    context.SaveChanges();



                    return true;
                }
            }));
        }
예제 #9
0
        public async System.Threading.Tasks.Task <JsonResult> DeleteEmpyItems(InvoiceHeaderSet invoiceHeaderSet, DateTime searchDate)
        {
            var result = await catalog.DeleteEmpyItems(invoiceHeaderSet);


            var searchByDate = await catalog.getInvoiceHeaderByDateAsync(searchDate);

            var initSearchByDate = Json(JsonConvert.SerializeObject(searchByDate, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            }), JsonRequestBehavior.AllowGet);


            _hubContext.Clients.All.NewInvoiceHeader(initSearchByDate);

            return(Json(JsonConvert.SerializeObject(result, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            }), JsonRequestBehavior.AllowGet));
        }
예제 #10
0
 public async Task <InvoiceHeaderSet> StartCreateInvoiceOrfindexists(string number, DateTime searchDate)
 {
     return(await Task.Factory.StartNew(() =>
     {
         using (CasierContents context = new CasierContents())
         {
             InvoiceHeaderSet result = context.InvoiceHeaderSet.Include("InvoiceHeaderDetailsSet.ItemSet").Where(u => u.Number.Equals(number) && u.PayDate == null && u.Description == null && u.ReservationSet == null && searchDate.Month.Equals(u.CreateDate.Value.Month) && searchDate.Day.Equals(u.CreateDate.Value.Day) && searchDate.Year.Equals(u.CreateDate.Value.Year)).FirstOrDefault();
             if (result != null)
             {
                 return result;
             }
             else
             {
                 InvoiceHeaderSet newOne = new InvoiceHeaderSet();
                 newOne.CreateDate = DateTime.Now;
                 newOne.Number = number;
                 newOne.Total = 0;
                 context.InvoiceHeaderSet.Add(newOne);
                 context.SaveChanges();
                 return newOne;
             }
         }
     }));
 }
예제 #11
0
 public Ticket(InvoiceHeaderSet invoice, string isCopy, Info info)
 {
     this.option      = isCopy;
     this.invoice     = invoice;
     this.currentInfo = info;
 }
예제 #12
0
        public async System.Threading.Tasks.Task <JsonResult> CreateReservationSetOrUpdate(InvoiceHeaderSet invoiceHeaderSet, DateTime searchDate)
        {
            invoiceHeaderSet.CreateDate = invoiceHeaderSet.ReservationSet.DateTime;
            var result = await catalog.CreateInvoiceAndReservation(invoiceHeaderSet);

            var searchByDate = await catalog.getOrderInvoiceHeaderByDateAsync(searchDate);

            var initSearchByDate = Json(JsonConvert.SerializeObject(searchByDate, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            }), JsonRequestBehavior.AllowGet);


            _hubContext.Clients.All.newReservations(initSearchByDate);

            return(Json(JsonConvert.SerializeObject(result, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            }), JsonRequestBehavior.AllowGet));
        }
예제 #13
0
        public async System.Threading.Tasks.Task <JsonResult> DeleteCurrentItem(InvoiceHeaderSet invoiceHeaderSet)
        {
            bool result = await catalog.DeleteCurrentItem(invoiceHeaderSet);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }