public async Task <IActionResult> ReportAdvances(ReportMonthModel showMonth)
        {
            var user = await _userManager.GetUserAsync(User);

            //get local time at Timezone UTC 7
            DateTime localTimeUTC7 = SystemUtilites.ConvertToTimeZone(DateTime.UtcNow, "SE Asia Standard Time");
            //get timestamp 0 AM 1st day of month
            DateTime startMonth   = new DateTime(localTimeUTC7.Year, localTimeUTC7.Month, 01);
            DateTime baseDateTime = new DateTime();

            if (showMonth.Month != baseDateTime)
            {
                startMonth = showMonth.Month;
            }
            DateTime endMonth     = startMonth.AddMonths(1);
            double   TSstartMonth = SystemUtilites.ConvertToTimeStamp(startMonth);
            double   TSendMonth   = SystemUtilites.ConvertToTimeStamp(endMonth);
            List <TransInfoViewModel> transports = (await _transInfoServices.GetTransportsDoneByDriver(TSstartMonth, TSendMonth, user.Id)).ToList();
            ReportAdvancesModel       report     = new ReportAdvancesModel();

            foreach (var tr in transports)
            {
                report.Advances         += tr.AdvanceMoney;
                report.ReturnOfAdvances += tr.ReturnOfAdvances;
            }
            ViewBag.Month     = startMonth;
            ViewBag.ThisMonth = new DateTime(localTimeUTC7.Year, localTimeUTC7.Month, 01).ToString("MM/yyyy");
            return(View(report));
        }
Beispiel #2
0
        public async Task <bool> DoneTransInfo(TransportInformation trans, string userId)
        {
            _context.TransportInformations.Attach(trans);
            trans.IsCompleted = true;
            DateTime localTimeUTC7 = SystemUtilites.ConvertToTimeZone(DateTime.UtcNow, "SE Asia Standard Time");

            trans.DateCompletedLocal = SystemUtilites.ConvertToTimeStamp(localTimeUTC7);
            trans.DateCompletedUTC   = SystemUtilites.ConvertToTimeStamp(DateTime.UtcNow);
            try
            {
                EditTransportInformation newEdit = new EditTransportInformation()
                {
                    DateEditLocal = SystemUtilites.ConvertToTimeStamp(localTimeUTC7),
                    DateEditUTC   = SystemUtilites.ConvertToTimeStamp(DateTime.UtcNow),
                    EditContent   = "Kết thúc chuyến vận chuyển",
                    EditId        = Guid.NewGuid().ToString(),
                    TimeZone      = "SE Asia Standard Time",
                    TransportId   = trans.TransportId,
                    UserEditId    = userId
                };
                _context.EditTransportInformations.Add(newEdit);
                var result = await _context.SaveChangesAsync();

                return(result > 0);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Index()
        {
            DateTime localTimeUTC7   = SystemUtilites.ConvertToTimeZone(DateTime.UtcNow, "SE Asia Standard Time");
            DateTime monthTimeUTC7   = new DateTime(localTimeUTC7.Year, localTimeUTC7.Month, 01);
            double   TSlocalTimeUTC7 = SystemUtilites.ConvertToTimeStamp(localTimeUTC7);
            double   TSmonthTimeUTC7 = SystemUtilites.ConvertToTimeStamp(monthTimeUTC7);
            var      transports      = await _transInfoServices.GetTransports(TSmonthTimeUTC7, TSlocalTimeUTC7, "");

            HomeViewModel model = new HomeViewModel()
            {
                DriversCount               = _userServices.GetDriverActiveUsers().Count,
                DriverBusyCount            = _userServices.GetDriverActiveBusyUsers().Count,
                VehiclesCount              = (await _vehicleServices.GetAllNotDeletedVehicles()).Count,
                VehiclesBusyCount          = (await _vehicleServices.GetInUseVehicles()).Count,
                TransportInMonth           = transports.Count,
                TransportCompeletedInMonth = (await _transInfoServices.GetTransportsCompeleted(TSmonthTimeUTC7, TSlocalTimeUTC7, "")).Count,
            };

            foreach (var tr in transports)
            {
                model.AdvancesInMonth += tr.AdvanceMoney;
            }
            var user = await _userManager.GetUserAsync(User);

            if (user != null && await _userManager.IsInRoleAsync(user, "Lái xe"))
            {
                return(RedirectToAction(actionName: "Index", controllerName: "Home", new { area = "Driver" }));
            }
            if (user == null)
            {
                return(RedirectToAction(actionName: "Login", controllerName: "Account"));
            }
            return(View(model));
        }
        public async Task <IActionResult> Manage(FilterTransPortModel filter)
        {
            //get local time at Timezone UTC 7
            DateTime localTimeUTC7 = SystemUtilites.ConvertToTimeZone(DateTime.UtcNow, "SE Asia Standard Time");
            //get timestamp of day at 0 AM
            double TSNowUTC7 = SystemUtilites.ConvertToTimeStamp(localTimeUTC7);
            //get timestamp 0 AM 1st day of month
            DateTime startMonth  = new DateTime(localTimeUTC7.Year, localTimeUTC7.Month, 01);
            double   TSMonthUTC7 = SystemUtilites.ConvertToTimeStamp(startMonth);
            double   TSstartDate = 0;
            double   TSendDate   = 0;
            PaginationViewModel <TransInfoViewModel> model = new PaginationViewModel <TransInfoViewModel>();

            if (SystemUtilites.ConvertToTimeStamp(filter.StartDate) == -62135596800)
            {
                TSstartDate = TSMonthUTC7;
            }
            else
            {
                TSstartDate = SystemUtilites.ConvertToTimeStamp(filter.StartDate);
            }
            if (SystemUtilites.ConvertToTimeStamp(filter.EndDate) == -62135596800)
            {
                TSendDate = TSNowUTC7;
            }
            else
            {
                TSendDate = SystemUtilites.ConvertToTimeStamp(filter.EndDate.AddDays(1));
            }
            if (filter.Page == 0)
            {
                filter.Page = 1;
            }
            if (filter.PageSize == 0)
            {
                filter.PageSize = model.PageSizeItem.Min();
            }
            if (String.IsNullOrEmpty(filter.Search))
            {
                filter.Search = "";
            }

            model.Items = await _transInfoServices.GetTransports(TSstartDate, TSendDate, filter.Search.ToLower());

            int countItems = 0;

            if (model.Items != null)
            {
                if (model.Items.Any())
                {
                    countItems = model.Items.Count();
                }
            }
            model.Search    = filter.Search;
            model.StartDate = filter.StartDate;
            model.EndDate   = filter.EndDate;
            model.Items     = model.Items.Skip((filter.Page - 1) * filter.PageSize).Take(filter.PageSize);
            model.Pager     = new Pager(countItems, filter.Page, filter.PageSize);
            return(View(model));
        }
        public async Task <IActionResult> Edit(EditTransInfoViewModel model)
        {
            //get data for select elements if error
            model.Drivers  = _userServices.GetAvailableUsers().ToList();
            model.Routes   = _routeServices.GetAllRoutes().ToList();
            model.Vehicles = (await _vehicleServices.GetAllNotDeletedAndAvailableVehicles()).ToList();
            string message = String.Empty;

            if (ModelState.IsValid)
            {
                //check the vehicle is used
                string driverIdUseVehicle = await _vehicleServices.IsVehicleInUsedByAnotherDriver(model.DriverId, model.VehicleId);

                if (!String.IsNullOrEmpty(driverIdUseVehicle))
                {
                    var driverUseVehicle = _userServices.GetUser(driverIdUseVehicle);
                    message = $"Xe đang được sử dụng bởi {driverUseVehicle.FullName}";
                    TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message);
                    return(View(model));
                }
                //check cancel option and reason cancel
                if (model.IsCancel && String.IsNullOrEmpty(model.ReasonCancel))
                {
                    message = "Không thể để trống lý do hủy khi chọn hủy";
                    TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message);
                    return(View(model));
                }
                if (!model.IsCancel && !String.IsNullOrEmpty(model.ReasonCancel))
                {
                    message = "Không thể điền lý do hủy nếu chưa chọn hủy";
                    TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message);
                    return(View(model));
                }
                //if cancel and have reason cancel, write date complete transport
                if (model.IsCancel && !String.IsNullOrEmpty(model.ReasonCancel))
                {
                    DateTime localTimeUTC7 = SystemUtilites.ConvertToTimeZone(DateTime.UtcNow, "SE Asia Standard Time");
                    model.DateCompletedLocal = SystemUtilites.ConvertToTimeStamp(localTimeUTC7);
                    model.DateCompletedUTC   = SystemUtilites.ConvertToTimeStamp(DateTime.UtcNow);
                }
                var transInfo = _transInfoServices.GetTransport(model.TransportId);
                if (transInfo != null)
                {
                    var user = await _userManager.GetUserAsync(User);

                    if (user != null)
                    {
                        if (await _transInfoServices.EditTransInfo(model, user.Id))
                        {
                            message = "Đơn vận chuyển đã được điều chỉnh thông tin";
                            TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Success, message);
                            return(RedirectToAction(actionName: "Manage"));
                        }
                    }
                }
            }
            message = "Lỗi không xác định, xin mời thao tác lại";
            TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message);
            return(View(model));
        }
        public async Task <IActionResult> Index()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user != null)
            {
                DateTime localTimeUTC7 = SystemUtilites.ConvertToTimeZone(DateTime.UtcNow, "SE Asia Standard Time");
                var      dayJob        = _dayJobServices.GetDayJob(user.Id, SystemUtilites.ConvertToTimeStamp(localTimeUTC7.Date));
                if (dayJob == null)
                {
                    dayJob = new DayJob()
                    {
                        DayJobId   = Guid.NewGuid().ToString(),
                        Date       = SystemUtilites.ConvertToTimeStamp(localTimeUTC7.Date),
                        DriverId   = user.Id,
                        Transports = new List <TransportInformation>()
                    };
                    await _dayJobServices.Create(dayJob);
                }
                dayJob.Transports = dayJob.Transports.OrderByDescending(t => t.DateStartLocal).ToList();
                return(View(dayJob));
            }
            return(RedirectToAction(actionName: "Login", controllerName: "Account", new { area = "" }));
        }
Beispiel #7
0
        public async Task <bool> EditTransInfo(EditTransInfoViewModel transEdit, string userId)
        {
            var transInfo = await GetTransport(transEdit.TransportId);

            if (transInfo != null)
            {
                string editContent = String.Empty;
                _context.TransportInformations.Attach(transInfo);
                if (transInfo.AdvanceMoney != transEdit.AdvanceMoney)
                {
                    editContent           += $" Sửa tiền tạm ứng từ \"{transInfo.AdvanceMoney}\" thành \"{transEdit.AdvanceMoney}\" |";
                    transInfo.AdvanceMoney = transEdit.AdvanceMoney;
                }
                if (transInfo.CargoTonnage != transEdit.CargoTonnage)
                {
                    editContent           += $" Sửa khối lượng hàng hóa từ \"{transInfo.CargoTonnage}\" thành \"{transEdit.CargoTonnage}\" |";
                    transInfo.CargoTonnage = transEdit.CargoTonnage;
                }
                if (transInfo.CargoTypes != transEdit.CargoTypes)
                {
                    editContent         += $" Sửa loại hàng hóa từ \"{transInfo.CargoTypes}\" thành \"{transEdit.CargoTypes}\" |";
                    transInfo.CargoTypes = transEdit.CargoTypes;
                }
                if (transInfo.IsCancel != transEdit.IsCancel)
                {
                    editContent       += $" Sửa trạng thái hủy từ \"{transInfo.IsCancel}\" thành \"{transEdit.IsCancel}\" |";
                    transInfo.IsCancel = transEdit.IsCancel;
                }
                if (transInfo.Note != transEdit.Note)
                {
                    editContent   += $" Sửa ghi chú từ \"{transInfo.Note}\" thành \"{transEdit.Note}\" |";
                    transInfo.Note = transEdit.Note;
                }
                if (transInfo.ReasonCancel != transEdit.ReasonCancel)
                {
                    editContent           += $" Sửa lý do hủy từ \"{transInfo.ReasonCancel}\" thành \"{transEdit.ReasonCancel}\" |";
                    transInfo.ReasonCancel = transEdit.ReasonCancel;
                }
                if (transInfo.ReturnOfAdvances != transEdit.ReturnOfAdvances)
                {
                    editContent += $" Sửa tiền hoàn ứng từ \"{transInfo.ReturnOfAdvances}\" thành \"{transEdit.ReturnOfAdvances}\" |";
                    transInfo.ReturnOfAdvances = transEdit.ReturnOfAdvances;
                }
                if (transInfo.DateCompletedUTC != transEdit.DateCompletedUTC)
                {
                    transInfo.DateCompletedUTC = transEdit.DateCompletedUTC;
                }
                if (transInfo.DateCompletedLocal != transEdit.DateCompletedLocal)
                {
                    editContent += $"Kết thúc chuyến vận chuyển";
                    transInfo.DateCompletedLocal = transEdit.DateCompletedLocal;
                }
                try
                {
                    if (!String.IsNullOrEmpty(editContent))
                    {
                        DateTime localTimeUTC7           = SystemUtilites.ConvertToTimeZone(DateTime.UtcNow, "SE Asia Standard Time");
                        EditTransportInformation newEdit = new EditTransportInformation()
                        {
                            DateEditLocal = SystemUtilites.ConvertToTimeStamp(localTimeUTC7),
                            DateEditUTC   = SystemUtilites.ConvertToTimeStamp(DateTime.UtcNow),
                            EditContent   = editContent,
                            EditId        = Guid.NewGuid().ToString(),
                            TimeZone      = "SE Asia Standard Time",
                            TransportId   = transEdit.TransportId,
                            UserEditId    = userId
                        };
                        _context.EditTransportInformations.Add(newEdit);
                    }
                    var result = await _context.SaveChangesAsync();

                    return(result > 0);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(false);
        }
        public async Task <IActionResult> Create(CreateTransInfoViewModel model)
        {
            //get local time at Timezone UTC 7
            DateTime localTimeUTC7 = SystemUtilites.ConvertToTimeZone(DateTime.UtcNow, "SE Asia Standard Time");
            //get timestamp of day at 0 AM
            double TStodayUTC7At0Am = SystemUtilites.ConvertToTimeStamp(localTimeUTC7.Date);
            //get timestamp now at utc
            double TSUTCNow = SystemUtilites.ConvertToTimeStamp(DateTime.UtcNow);

            //get data for select elements
            model.Drivers  = _userServices.GetDriverUsers().ToList();
            model.Routes   = _routeServices.GetAllRoutes().ToList();
            model.Vehicles = (await _vehicleServices.GetAllNotDeletedAndAvailableVehicles()).ToList();
            string message = String.Empty;

            if (ModelState.IsValid)
            {
                //check the vehicle is used
                string driverIdUseVehicle = await _vehicleServices.IsVehicleInUsedByAnotherDriver(model.DriverId, model.VehicleId);

                if (!String.IsNullOrEmpty(driverIdUseVehicle))
                {
                    var driverUseVehicle = _userServices.GetUser(driverIdUseVehicle);
                    message = $"Xe đang được sử dụng bởi {driverUseVehicle.FullName}";
                    TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message);
                    return(View(model));
                }

                //create new TransportInformation
                var user = await _userManager.GetUserAsync(User);

                TransportInformation newTrans = new TransportInformation()
                {
                    TransportId    = Guid.NewGuid().ToString(),
                    AdvanceMoney   = model.AdvanceMoney,
                    DateStartUTC   = TSUTCNow,
                    DateStartLocal = SystemUtilites.ConvertToTimeStamp(localTimeUTC7),
                    TimeZone       = "SE Asia Standard Time",
                    CargoTypes     = model.CargoTypes,
                    Note           = model.Note,
                    VehicleId      = model.VehicleId,
                    RouteId        = model.RouteId,
                    UserCreateId   = user.Id
                };
                //get or create if not dayjob has date match today timeStamp
                DayJob driverDayJob = _dayJobServices.GetDayJob(model.DriverId, TStodayUTC7At0Am);
                if (driverDayJob == null)
                {
                    driverDayJob = new DayJob()
                    {
                        DayJobId = Guid.NewGuid().ToString(),
                        DriverId = model.DriverId,
                        Date     = TStodayUTC7At0Am
                    };
                    if (!(await _dayJobServices.Create(driverDayJob)))
                    {
                        message = "Lỗi không xác định, xin mời thao tác lại";
                        TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message);
                        return(View(model));
                    }
                }
                newTrans.DayJobId = driverDayJob.DayJobId;
                //create new TransInfo in SQL
                if (await _transInfoServices.CreateNewTransInfo(newTrans))
                {
                    var vehicle = await _vehicleServices.GetVehicle(newTrans.VehicleId);

                    if (vehicle != null)
                    {
                        if (!vehicle.IsInUse)
                        {
                            await _vehicleServices.MakeVehicleInUsed(vehicle);
                        }
                    }
                    var driver = await _userManager.FindByIdAsync(model.DriverId);

                    if (driver != null)
                    {
                        if (driver.IsAvailable)
                        {
                            await _userServices.MakeDriverIsBusy(driver);
                        }
                    }
                    message = "Chuyến vận chuyển đã được tạo";
                    TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Success, message);
                    return(RedirectToAction(actionName: "Manage"));
                }
            }
            message = "Lỗi không xác định, xin mời thao tác lại";
            TempData["UserMessage"] = SystemUtilites.SendSystemNotification(NotificationType.Error, message);
            return(View(model));
        }