Ejemplo n.º 1
0
        public async Task Sent_KTV(TemporaryBill inputModel)
        {
            try
            {
                await _unitOfWork.TemporaryBillRepository.Update(inputModel);

                var listAccessories = (await _unitOfWork.TemporaryBill_AccesaryRepository.FindBy(c => c.TemporaryBillId == inputModel.Id)).ToList();
                if (listAccessories != null)
                {
                    foreach (var item in listAccessories)
                    {
                        if (inputModel.Status == (int)BillStatus.TemporaryKTV)
                        {
                            var acc = await _unitOfWork.AccessoriesRepository.Get(c => c.Id == item.AccesaryId);

                            acc.Quantity = acc.Quantity + item.Quantity;
                            await _unitOfWork.AccessoriesRepository.Update(acc);
                        }
                    }
                }
                await _unitOfWork.SaveChange();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public async Task Create(TemporaryBill inputModel)
        {
            try
            {
                var data = await _unitOfWork.TemporaryBillRepository.Add(inputModel);

                if (inputModel.ListBill_Services != null)
                {
                    await CreateBill_Service(data, inputModel.ListBill_Services);
                }
                if (inputModel.ListBill_Accessories != null)
                {
                    await CreateBill_Accessories(data, inputModel.ListBill_Accessories);
                }
                var motorLift = await _unitOfWork.MotorLiftsRepository.Get(c => c.Id == inputModel.MotorLiftId);

                motorLift.Status = (byte)MotorLiftEnum.Acting;
                await _unitOfWork.MotorLiftsRepository.Update(motorLift);

                if (inputModel.UpdatedBy > 0)
                {
                    var ktv = await _unitOfWork.AccountsRepository.Get(c => c.Id == inputModel.UpdatedBy);

                    ktv.StatusActing = (byte)AccountStatusEnum.Acting;
                    await _unitOfWork.AccountsRepository.Update(ktv);
                }
                await _unitOfWork.SaveChange();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        private async Task CreateBill_Service(TemporaryBill inputModel, List <TemporaryBill_Service> list)
        {
            try
            {
                foreach (var item in list)
                {
                    item.TemporaryBillId = inputModel.Id;
                    await _unitOfWork.TemporaryBill_ServiceRepository.Add(item);

                    await _unitOfWork.SaveChange();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create_Or_Update(TemporaryBill inputModel)
        {
            try
            {
                if (inputModel.Id == 0)
                {
                    var session = _httpContextAccessor.HttpContext.Session;
                    var account = Portal.Utils.SessionExtensions.Get <Accounts>(session, Portal.Utils.SessionExtensions.SessionAccount);
                    inputModel.CreatedBy = account.Id;
                    await _temporaryBillManager.Create(inputModel);

                    return(Json(new { Result = true, Message = "Thêm mới dữ liệu thành công" }));
                }
                else
                {
                    //if(inputModel.Status == (byte)BillStatus.TemporaryTN)
                    //{
                    //    inputModel.TimeOut = DateTime.Now;
                    //    var session = _httpContextAccessor.HttpContext.Session;
                    //    var account = Portal.Utils.SessionExtensions.Get<Accounts>(session, Portal.Utils.SessionExtensions.SessionAccount);
                    //    inputModel.PrintedBy = account.Id;
                    //}
                    //else
                    //{
                    //    inputModel.UpdatedTime = DateTime.Now;
                    //}
                    await _temporaryBillManager.Update(inputModel);

                    return(Json(new { Result = true, Message = "Cập nhật dữ liệu thành công" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = false, Message = ex.Message }));
            }
        }
Ejemplo n.º 5
0
        private async Task CreateBill_Accessories(TemporaryBill inputModel, List <TemporaryBill_Accesary> list)
        {
            try
            {
                foreach (var item in list)
                {
                    item.TemporaryBillId = inputModel.Id;
                    await _unitOfWork.TemporaryBill_AccesaryRepository.Add(item);

                    if (inputModel.Status == (int)BillStatus.TemporaryTN)
                    {
                        var acc = await _unitOfWork.AccessoriesRepository.Get(c => c.Id == item.AccesaryId);

                        acc.Quantity = acc.Quantity - item.Quantity;
                        await _unitOfWork.AccessoriesRepository.Update(acc);
                    }
                    await _unitOfWork.SaveChange();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 6
0
        public async Task Update_Status(TemporaryBill inputModel)
        {
            try
            {
                await _unitOfWork.TemporaryBillRepository.Update(inputModel);

                if (inputModel.Status == (byte)BillStatus.TemporaryLT)
                {
                    var oldBill = await _unitOfWork.TemporaryBillRepository.Get(c => c.Id == inputModel.Id);

                    if (inputModel.UpdatedBy != oldBill.UpdatedBy)
                    {
                        var oldktv = await _unitOfWork.AccountsRepository.Get(c => c.Id == oldBill.UpdatedBy);

                        oldktv.StatusActing = (byte)AccountStatusEnum.Active;
                        await _unitOfWork.AccountsRepository.Update(oldktv);
                    }
                    if (inputModel.MotorLiftId != oldBill.MotorLiftId)
                    {
                        var oldmotorLift = await _unitOfWork.MotorLiftsRepository.Get(c => c.Id == oldBill.MotorLiftId);

                        oldmotorLift.Status = (byte)MotorLiftEnum.Active;
                        await _unitOfWork.MotorLiftsRepository.Update(oldmotorLift);
                    }
                    var ktv = await _unitOfWork.AccountsRepository.Get(c => c.Id == inputModel.UpdatedBy);

                    ktv.StatusActing = (byte)AccountStatusEnum.Acting;
                    await _unitOfWork.AccountsRepository.Update(ktv);

                    var motorLift = await _unitOfWork.MotorLiftsRepository.Get(c => c.Id == inputModel.MotorLiftId);

                    motorLift.Status = (byte)MotorLiftEnum.Acting;
                    await _unitOfWork.MotorLiftsRepository.Update(motorLift);
                }
                if (inputModel.Status == (byte)BillStatus.TemporaryKTV)
                {
                    var oldBill = await _unitOfWork.TemporaryBillRepository.Get(c => c.Id == inputModel.Id);

                    if (inputModel.UpdatedBy != oldBill.UpdatedBy)
                    {
                        var oldktv = await _unitOfWork.AccountsRepository.Get(c => c.Id == oldBill.UpdatedBy);

                        oldktv.StatusActing = (byte)AccountStatusEnum.Active;
                        await _unitOfWork.AccountsRepository.Update(oldktv);
                    }
                    if (inputModel.MotorLiftId != oldBill.MotorLiftId)
                    {
                        var oldmotorLift = await _unitOfWork.MotorLiftsRepository.Get(c => c.Id == oldBill.MotorLiftId);

                        oldmotorLift.Status = (byte)MotorLiftEnum.Active;
                        await _unitOfWork.MotorLiftsRepository.Update(oldmotorLift);
                    }
                    var ktv = await _unitOfWork.AccountsRepository.Get(c => c.Id == inputModel.UpdatedBy);

                    ktv.StatusActing = (byte)AccountStatusEnum.Acting;
                    await _unitOfWork.AccountsRepository.Update(ktv);

                    var motorLift = await _unitOfWork.MotorLiftsRepository.Get(c => c.Id == inputModel.MotorLiftId);

                    motorLift.Status = (byte)MotorLiftEnum.Acting;
                    await _unitOfWork.MotorLiftsRepository.Update(motorLift);
                }
                if (inputModel.Status == (byte)BillStatus.TemporaryTN)
                {
                    inputModel.UpdatedTime = DateTime.Now;
                    var ktv = await _unitOfWork.AccountsRepository.Get(c => c.Id == inputModel.UpdatedBy);

                    ktv.StatusActing = (byte)AccountStatusEnum.Active;
                    await _unitOfWork.AccountsRepository.Update(ktv);

                    var motorLift = await _unitOfWork.MotorLiftsRepository.Get(c => c.Id == inputModel.MotorLiftId);

                    motorLift.Status = (byte)MotorLiftEnum.Active;
                    await _unitOfWork.MotorLiftsRepository.Update(motorLift);

                    var listAccessories = (await _unitOfWork.TemporaryBill_AccesaryRepository.FindBy(c => c.TemporaryBillId == inputModel.Id)).ToList();
                    if (listAccessories != null)
                    {
                        foreach (var item in listAccessories)
                        {
                            if (inputModel.Status == (int)BillStatus.TemporaryTN)
                            {
                                var acc = await _unitOfWork.AccessoriesRepository.Get(c => c.Id == item.AccesaryId);

                                acc.Quantity = acc.Quantity - item.Quantity;
                                await _unitOfWork.AccessoriesRepository.Update(acc);
                            }
                        }
                    }
                }
                await _unitOfWork.SaveChange();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 7
0
        public async Task Update(TemporaryBill inputModel)
        {
            try
            {
                await _unitOfWork.TemporaryBillRepository.Update(inputModel);

                if (inputModel.ListBill_Services != null)
                {
                    await DeleteBill_Service(inputModel.Id);
                    await CreateBill_Service(inputModel, inputModel.ListBill_Services);
                }
                else
                {
                    await DeleteBill_Service(inputModel.Id);
                }
                if (inputModel.ListBill_Accessories != null)
                {
                    await DeleteBill_Accessories(inputModel.Id);
                    await CreateBill_Accessories(inputModel, inputModel.ListBill_Accessories);
                }
                else
                {
                    await DeleteBill_Accessories(inputModel.Id);
                }
                if (inputModel.Status == (byte)BillStatus.TemporaryLT)
                {
                    var oldBill = await _unitOfWork.TemporaryBillRepository.Get(c => c.Id == inputModel.Id);

                    if (inputModel.UpdatedBy != oldBill.UpdatedBy)
                    {
                        var oldktv = await _unitOfWork.AccountsRepository.Get(c => c.Id == oldBill.UpdatedBy);

                        oldktv.StatusActing = (byte)AccountStatusEnum.Active;
                        await _unitOfWork.AccountsRepository.Update(oldktv);
                    }
                    if (inputModel.MotorLiftId != oldBill.MotorLiftId)
                    {
                        var oldmotorLift = await _unitOfWork.MotorLiftsRepository.Get(c => c.Id == oldBill.MotorLiftId);

                        oldmotorLift.Status = (byte)MotorLiftEnum.Active;
                        await _unitOfWork.MotorLiftsRepository.Update(oldmotorLift);
                    }
                    var ktv = await _unitOfWork.AccountsRepository.Get(c => c.Id == inputModel.UpdatedBy);

                    ktv.StatusActing = (byte)AccountStatusEnum.Acting;
                    await _unitOfWork.AccountsRepository.Update(ktv);

                    var motorLift = await _unitOfWork.MotorLiftsRepository.Get(c => c.Id == inputModel.MotorLiftId);

                    motorLift.Status = (byte)MotorLiftEnum.Acting;
                    await _unitOfWork.MotorLiftsRepository.Update(motorLift);
                }
                if (inputModel.Status == (byte)BillStatus.TemporaryKTV)
                {
                    var oldBill = await _unitOfWork.TemporaryBillRepository.Get(c => c.Id == inputModel.Id);

                    if (inputModel.UpdatedBy != oldBill.UpdatedBy)
                    {
                        var oldktv = await _unitOfWork.AccountsRepository.Get(c => c.Id == oldBill.UpdatedBy);

                        oldktv.StatusActing = (byte)AccountStatusEnum.Active;
                        await _unitOfWork.AccountsRepository.Update(oldktv);
                    }
                    if (inputModel.MotorLiftId != oldBill.MotorLiftId)
                    {
                        var oldmotorLift = await _unitOfWork.MotorLiftsRepository.Get(c => c.Id == oldBill.MotorLiftId);

                        oldmotorLift.Status = (byte)MotorLiftEnum.Active;
                        await _unitOfWork.MotorLiftsRepository.Update(oldmotorLift);
                    }
                    var ktv = await _unitOfWork.AccountsRepository.Get(c => c.Id == inputModel.UpdatedBy);

                    ktv.StatusActing = (byte)AccountStatusEnum.Acting;
                    await _unitOfWork.AccountsRepository.Update(ktv);

                    var motorLift = await _unitOfWork.MotorLiftsRepository.Get(c => c.Id == inputModel.MotorLiftId);

                    motorLift.Status = (byte)MotorLiftEnum.Acting;
                    await _unitOfWork.MotorLiftsRepository.Update(motorLift);
                }
                if (inputModel.Status == (byte)BillStatus.TemporaryTN)
                {
                    inputModel.UpdatedTime = DateTime.Now;
                    var ktv = await _unitOfWork.AccountsRepository.Get(c => c.Id == inputModel.UpdatedBy);

                    ktv.StatusActing = (byte)AccountStatusEnum.Active;
                    await _unitOfWork.AccountsRepository.Update(ktv);

                    var motorLift = await _unitOfWork.MotorLiftsRepository.Get(c => c.Id == inputModel.MotorLiftId);

                    motorLift.Status = (byte)MotorLiftEnum.Active;
                    await _unitOfWork.MotorLiftsRepository.Update(motorLift);
                }
                await _unitOfWork.SaveChange();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }