Пример #1
0
        public string GetPriceZoneReturn(Boking booking, bool leverera)
        {
            var priceDetails = new StringBuilder();

            try
            {
                var price = leverera ? Zones.PriceForDelivery(booking.WayOfDelivery, booking.Zone, booking.Distance,
                                                              booking.NbrItems, booking.PayBySupplier, booking.BookingDay.DayOfWeek, booking.BookingDay) : 0;

                if (leverera)
                {
                    priceDetails.AppendLine("Pris för hämtning:          " + price);
                }

                decimal pickup = 0;
                if (booking.Pickup)
                {
                    priceDetails.AppendLine("Pris för leverans:     " + (pickup = Zones.PriceForPicups(booking.WayOfDelivery, booking.Zone, booking.Distance, booking.NbrItemsPickup, true, booking.BookingDay)));
                }

                priceDetails.AppendLine("----------------------------------");
                priceDetails.AppendLine("Totalpris:                  " + (price + pickup));
            }
            catch (Exception e)
            {
                ViewBag.Error = $"{e.Message}. {e.InnerException?.Message}";
            }

            return(priceDetails.ToString());
        }
Пример #2
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Boking boking = _db.BokingSet.Find(id);

            if (boking == null)
            {
                return(HttpNotFound());
            }

            if (boking.Type == BookingTypes.Return.ToString())
            {
                return(View("EditReturn", boking));
            }

            if (boking.Type == BookingTypes.Monting.ToString())
            {
                Session["products"] = new List <StandarProduct>(boking.Product.Select(p => new StandarProduct
                {
                    Name  = p.Name,
                    Price = decimal.Parse(p.Price),
                    Text  = p.Type,
                    Time  = int.Parse(p.Quantity)
                }));
                return(View("EditMonting", boking));
            }

            boking.Remarks = boking.Remarks ?? "";

            return(View(boking));
        }
Пример #3
0
        public ActionResult CreateMonting(Boking boking)
        {
            if (ModelState.IsValid)
            {
                var id = AdminAuthenticationHelper.Current.GetAdminUserData().Id;
                try
                {
                    var driverId = boking.WayOfDelivery == Delivery.Home.ToString() ? 1 : 2;
                    var user     = _db.UserSet.First(u => u.Id == id);
                    var userFor  = _db.UserSet.First(dr => dr.Role == Role.qt.ToString() && dr.Order == driverId);

                    boking.CreatedBy = user;
                    boking.Car       = userFor;

                    var productList = (List <StandarProduct>)Session["products"] ?? new List <StandarProduct>();
                    if (productList != null && productList.Any())
                    {
                        boking.Product = productList.Select(p => new Product
                        {
                            Name     = p.Name,
                            Price    = p.Price.ToString(CultureInfo.InvariantCulture),
                            Type     = p.Text,
                            Quantity = p.Time.ToString()
                        }).ToList();
                    }

                    //var nbrItems = boking.NbrItems > 0 ? boking.NbrItems - 1 : 0;

                    //boking.DeliveryCost = GetPriceFrMonting(productList).ToString();
                    boking.DeliveryCost = GetPrices(boking.Zone, boking.WayOfDelivery, boking.Distance, boking.Pickup, false, boking.NbrItems, boking.NbrItemsPickup, boking.BookingDay, boking.Canceled).ToString(CultureInfo.InvariantCulture);//use unused cancel property as delivery.
                    boking.Status       = Status.New.ToString();

                    if (boking.Remarks == null)
                    {
                        boking.Remarks = "";
                    }

                    _db.BokingSet.Add(boking);

                    _db.SaveChanges();

                    if (!SendNotificationsToCustomer(boking))
                    {
                        ViewBag.Error = "Misslyckades att skicka avisering till kunden.";
                    }

                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    ViewBag.Error  = "Please check the inforamtions and try again. ";
                    ViewBag.Error += e.Message + ". " + e.InnerException?.Message;
                }
            }

            ViewBag.Delivery = boking.WayOfDelivery;

            return(View(boking));
        }
Пример #4
0
        public ActionResult Edit(Boking boking)
        {
            if (!ModelState.IsValid)
            {
                return(View(boking));
            }

            if (boking.BookingDay >= DateTime.Today)
            {
                var booking = _db.BokingSet.Find(boking.Id);
                if (booking == null)
                {
                    return(View());
                }

                booking.NbrItems     = boking.NbrItems;
                booking.Customer     = boking.Customer;
                booking.DeliveryCost = GetPrices(boking.Zone, boking.WayOfDelivery, boking.Distance, boking.Pickup,
                                                 boking.PayBySupplier, boking.NbrItems, boking.NbrItemsPickup, boking.BookingDay).ToString(CultureInfo.InvariantCulture);
                booking.Distance       = boking.Distance;
                booking.NbrItemsPickup = boking.NbrItemsPickup;
                booking.OrderAmount    = boking.OrderAmount;
                booking.OrderNbr       = boking.OrderNbr;
                booking.Pickup         = boking.Pickup;
                booking.Remarks        = boking.Remarks ?? "";
                booking.WayOfDelivery  = boking.WayOfDelivery;
                booking.Zone           = boking.Zone;
                booking.Type           = boking.Type;


                //if (boking.Remarks == null)
                //    boking.Remarks = "";

                //db.BokingSet.Attach(boking);

                //db.Entry(boking).Property(p => p.Customer.PortCode).IsModified = true;
                //db.Entry(boking).State = EntityState.Modified;

                try
                {
                    _db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    ViewBag.Error = $"{e.Message}. {e.InnerException?.Message}";
                }
            }
            else
            {
                ViewBag.Error = "Nya datummet ska vara f.o.m idag.";
            }
            return(View(boking));
        }
Пример #5
0
        public string GetPriceZone(Boking booking, bool leverera = true)
        {
            var user = AdminAuthenticationHelper.Current.GetAdminUserData().Role;

            if (user == Role.LogisticAdministrator.ToString())
            {
                return(GetPriceZoneReturn(booking, leverera));
            }

            var priceDetails = new StringBuilder();

            try
            {
                //var nbrItems = booking.NbrItems
                //    - (booking.Type == BookingTypes.Monting.ToString()
                //    && booking.NbrItems > 0 ? 1 : 0);

                var price = Zones.PriceForDelivery(booking.WayOfDelivery, booking.Zone, booking.Distance,
                                                   booking.NbrItems, booking.PayBySupplier, booking.BookingDay.DayOfWeek, booking.BookingDay);

                if (booking.Type == BookingTypes.Monting.ToString() && !booking.Canceled)//use unused cancel property as delivery.
                {
                    price = 0;
                }

                priceDetails.AppendLine("Pris för leverans:          " + price);
                //priceDetails.AppendLine("");
                if (booking.Type == BookingTypes.Monting.ToString())
                {
                    var productList  = (List <StandarProduct>)Session["products"] ?? new List <StandarProduct>();
                    var priceMonting = GetPriceFrMonting(productList);
                    price += priceMonting;
                    priceDetails.AppendLine("Pris för montering:          " + priceMonting);
                }

                decimal pickup = 0;
                if (booking.Pickup)
                {
                    priceDetails.AppendLine("Pris för bortforsling:     " + (pickup = Zones.PriceForPicups(booking.WayOfDelivery, booking.Zone, booking.Distance, booking.NbrItemsPickup, false, booking.BookingDay)));
                }

                priceDetails.AppendLine("----------------------------------");
                priceDetails.AppendLine("Totalpris:                  " + (price + pickup));
            }
            catch (Exception e)
            {
                ViewBag.Error = $"{e.Message}. {e.InnerException?.Message}";
            }

            return(priceDetails.ToString());
            //return JsonConvert.SerializeObject(priceDetails, Formatting.Indented);
        }
Пример #6
0
        public ActionResult CreateRetur(Boking boking, bool leverera)
        {
            if (ModelState.IsValid)
            {
                var id = AdminAuthenticationHelper.Current.GetAdminUserData().Id;
                try
                {
                    var driverId = boking.WayOfDelivery == Delivery.Home.ToString() ? 1 : 2;
                    var user     = _db.UserSet.First(u => u.Id == id);
                    var userFor  = _db.UserSet.First(dr => dr.Role == Role.qt.ToString() && dr.Order == driverId);

                    boking.CreatedBy = user;
                    boking.Car       = userFor;

                    boking.DeliveryCost = GetPrices(boking.Zone, boking.WayOfDelivery, boking.Distance, boking.Pickup, true, boking.NbrItems, boking.NbrItemsPickup, boking.BookingDay, leverera).ToString(CultureInfo.InvariantCulture);
                    boking.Status       = Status.New.ToString();

                    if (boking.Remarks == null)
                    {
                        boking.Remarks = "";
                    }
                    if (boking.OrderNbr == null)
                    {
                        boking.OrderNbr = "";
                    }

                    boking.Email = leverera;

                    _db.BokingSet.Add(boking);

                    _db.SaveChanges();

                    if (!SendNotificationsToCustomer(boking))
                    {
                        ViewBag.Error = "Misslyckades att skicka avisering till kunden.";
                    }

                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    ViewBag.Error  = "Please check the inforamtions and try again. ";
                    ViewBag.Error += e.Message + ". " + e.InnerException?.Message;
                }
            }

            ViewBag.Delivery = boking.WayOfDelivery;

            return(View(boking));
        }
Пример #7
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Boking boking = _db.BokingSet.Find(id);

            if (boking == null)
            {
                return(HttpNotFound());
            }
            return(View(boking));
        }
Пример #8
0
        public ActionResult EditReturn(Boking boking, bool leverera)
        {
            if (!ModelState.IsValid)
            {
                return(View(boking));
            }

            if (boking.BookingDay >= DateTime.Today)
            {
                var booking = _db.BokingSet.Find(boking.Id);
                if (booking == null)
                {
                    ViewBag.Error = "Validation error.";
                    return(View(boking));
                }

                booking.NbrItems     = boking.NbrItems;
                booking.Customer     = boking.Customer;
                booking.DeliveryCost = GetPrices(boking.Zone, boking.WayOfDelivery, boking.Distance, boking.Pickup,
                                                 boking.PayBySupplier, boking.NbrItems, boking.NbrItemsPickup, boking.BookingDay, leverera).ToString(CultureInfo.InvariantCulture);
                booking.Distance       = boking.Distance;
                booking.NbrItemsPickup = boking.NbrItemsPickup;
                booking.OrderAmount    = boking.OrderAmount;
                booking.OrderNbr       = boking.OrderNbr;
                booking.Pickup         = boking.Pickup;
                booking.Remarks        = boking.Remarks ?? "";
                booking.WayOfDelivery  = boking.WayOfDelivery;
                booking.Zone           = boking.Zone;
                booking.Type           = boking.Type;
                booking.Email          = leverera;

                try
                {
                    _db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    ViewBag.Error = $"{e.Message}. {e.InnerException?.Message}";
                }
            }
            else
            {
                ViewBag.Error = "Nya datummet ska vara f.o.m idag.";
            }
            return(View(boking));
        }
Пример #9
0
        public ActionResult CreateRetur(DateTime time, int part, Delivery delivery)
        {
            Session["products"] = new List <StandarProduct>();
            var booking = new Boking()
            {
                Type           = BookingTypes.Return.ToString(),
                BookingDay     = time,
                PartOfTheDay   = (short)part,
                WayOfDelivery  = delivery.ToString(),
                Remarks        = "",
                NbrItems       = 0,
                Pickup         = false,
                NbrItemsPickup = 0,
                PayBySupplier  = true
            };

            return(View(booking));
        }
Пример #10
0
        private bool SendNotificationsToCustomer(Boking boking, bool leverera = true)
        {
            //var name = boking.Customer.Name;
            var partOfDay = GetBookingPartOfTheDay(boking.PartOfTheDay, boking.BookingDay.DayOfWeek);

            var message = $"Leveranstyp: {LanguageDictionary.Translate[boking.WayOfDelivery]}\n" +
                          $" Datum: {boking.BookingDay.ToShortDateString()}\n" +
                          $"Tid: {partOfDay}\n" +
                          $"Adress: {boking.Customer.Address1}\n\n\n";

            if (boking.Type != BookingTypes.Return.ToString())
            {
                message += $"{GetPriceZone(boking, leverera)}\n\n";
            }

            if (boking.Type == BookingTypes.Monting.ToString())
            {
                message += $"{GetPriceMonting()}\n\n";
            }

            message += "Mvh Q Transport";

            if (boking.Type == BookingTypes.Return.ToString())
            {
                message += $"\n\n" +
                           "För ytterligare frågor angående\n" +
                           "Leveransen vänligen ring:\n" +
                           "040-6555 000";
            }

            var pdf = boking.Type == BookingTypes.Return.ToString()
                ? "LEVERANSVILLKOR REKLA Qtransport"
                : boking.Type == BookingTypes.Monting.ToString()
                ? "LEVERANSVILLKOR Qtransport 2"
                : "LEVERANSVILLKOR Qtransport";
            var status = Helpers.MailHandler.SendEmail(message, boking.Customer.Email, "Orderbekräftelse från XXXLutz", true, pdf);

            return(string.IsNullOrEmpty(status));

            //message += "Detta sms kan du inte svara på.\nFör ytligare frågor kontakta oss på 040-191319";
            //string resultStr;
            //return Helpers.SmsHandler.SendSms(boking.Customer.Phone1, message, out resultStr) || status;
        }
Пример #11
0
 public ActionResult MarkAsDone(int?id, string status)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     try
     {
         Boking boking = _db.BokingSet.Find(id);
         if (boking == null)
         {
             return(HttpNotFound());
         }
         boking.Status           = Status.Done.ToString();
         _db.Entry(boking).State = EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         ViewBag.Error = $"{e.Message}. {e.InnerException?.Message}";
         return(HttpNotFound());
     }
 }
Пример #12
0
        public ActionResult EditMonting(Boking boking)
        {
            if (!ModelState.IsValid)
            {
                return(View(boking));
            }

            if (boking.BookingDay >= DateTime.Today)
            {
                var booking = _db.BokingSet.Find(boking.Id);
                if (booking == null)
                {
                    return(View(boking));
                }

                var cpt = booking.Product.Count;
                for (var i = cpt - 1; i >= 0; i--)
                {
                    var prod = _db.ProductSet.Find(booking.Product.ToList()[i].Id);
                    if (prod != null)
                    {
                        _db.ProductSet.Remove(prod);
                    }
                    _db.SaveChanges();
                }
                booking.Product.Clear();
                _db.SaveChanges();

                booking = _db.BokingSet.Find(boking.Id);
                if (booking == null)
                {
                    return(View(boking));
                }

                booking.NbrItems       = boking.NbrItems;
                booking.Customer       = boking.Customer;
                booking.Distance       = boking.Distance;
                booking.NbrItemsPickup = boking.NbrItemsPickup;
                booking.OrderAmount    = boking.OrderAmount;
                booking.OrderNbr       = boking.OrderNbr;
                booking.Pickup         = boking.Pickup;
                booking.Remarks        = boking.Remarks ?? "";
                booking.WayOfDelivery  = boking.WayOfDelivery;
                booking.Zone           = boking.Zone;
                booking.Type           = boking.Type;
                booking.Canceled       = boking.Canceled;

                var productList = (List <StandarProduct>)Session["products"] ?? new List <StandarProduct>();

                if (productList.Any())
                {
                    booking.Product = productList.Select(p => new Product
                    {
                        Name     = p.Name,
                        Price    = p.Price.ToString(CultureInfo.InvariantCulture),
                        Type     = p.Text,
                        Quantity = p.Time.ToString()
                    }).ToList();
                }

                booking.DeliveryCost = GetPrices(boking.Zone, boking.WayOfDelivery, boking.Distance, boking.Pickup, false, boking.NbrItems, boking.NbrItemsPickup, boking.BookingDay, boking.Canceled).ToString(CultureInfo.InvariantCulture);//use unused cancel property as delivery.

                _db.BokingSet.AddOrUpdate(booking);
                try
                {
                    _db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    ViewBag.Error = $"{e.Message}. {e.InnerException?.Message}";
                }
            }
            else
            {
                ViewBag.Error = "Nya datummet ska vara f.o.m idag.";
            }
            return(View(boking));
        }