public async Task <ApiResult <int> > Create(SupplierCreate bundle) { var supplier = _mapper.Map <Supplier>(bundle); var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.Code); var stt = 1; Location: var location = code.Location + stt; var str = code.Name + location; var checkCode = await _context.Suppliers.AnyAsync(x => x.Code == str); if (checkCode) { stt++; goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); supplier.Code = str; _context.Suppliers.Add(supplier); await _context.SaveChangesAsync(); // số bản ghi nếu return return(new ApiSuccessResult <int>(supplier.Id)); }
public async Task <ApiResult <bool> > Update(int id, UpdateProductTypeGroup bundle) { var productTypeGroup = await _context.ProductTypeGroups.FindAsync(bundle.Id); if (productTypeGroup == null) { return(new ApiErrorResult <bool>("Nhóm loại không tồn tại")); } var list = _mapper.Map(bundle, productTypeGroup); _context.ProductTypeGroups.Update(list); await _context.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
public async Task <ApiResult <bool> > Update(int id, UpdateMaterialsType bundle) { var materialsType = await _context.MaterialsTypes.FindAsync(bundle.Id); if (materialsType == null) { return(new ApiErrorResult <bool>("Loại nguyên vật liệu không tồn tại")); } var list = _mapper.Map(bundle, materialsType); _context.MaterialsTypes.Update(list); await _context.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
public async Task <ApiResult <bool> > Create(CreateNotification bundle) { var idRece = await _userManager.FindByNameAsync(bundle.NameReceiver); var notification = new Notification() { IdReceiver = idRece.Id, Name = bundle.Name, Path = bundle.Path, Time = DateTime.Now, }; _context.Notifications.Add(notification); await _context.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
public async Task <ApiResult <Guid> > Register(RegisterRequest bundle) { var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.Code); var stt = 1; Location: var location = code.Location + stt; var str = code.Name + location; var check = await _userManager.Users.AnyAsync(x => x.Code == str); if (check) { stt++; goto Location; } var userName = str; var passWord = "******" + str; var user = await _userManager.FindByNameAsync(userName); if (user != null) { goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); user = _mapper.Map(bundle, user); user.Code = userName; user.UserName = userName; user.JobStatus = JobStatus.NotWorking; var result = await _userManager.CreateAsync(user, passWord); Role: var role = await _roleManager.FindByNameAsync(RoleDecentralization.Employee.ToString()); if (role == null) { await _roleService.CreateRole(); goto Role; } if (!await _userManager.IsInRoleAsync(user, role.Name)) { await _userManager.AddToRoleAsync(user, role.Name); } if (result.Succeeded) { return(new ApiSuccessResult <Guid>(user.Id)); } return(new ApiErrorResult <Guid>("Đăng ký không thành công")); }
public async Task <ApiResult <bool> > Create(CreateCode bundle) { var check = await _context.ManageCodes.AnyAsync(x => x.Name == bundle.Name); if (check) { return(new ApiErrorResult <bool>("Mã số đã tồn tại")); } var code = _context.ManageCodes; var data = new ManageCode() { Name = bundle.Name, TypeCode = bundle.TypeCode }; _context.ManageCodes.Add(data); await _context.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
public async Task <ApiResult <long> > Create(CreateBill bundle) { int i = 0; var billDetail = new List <BillDetail>(); double total = 0; List <OrderDetail> listOrderDetails = new List <OrderDetail>(); List <Material> listMaterial = new List <Material>(); foreach (var item in bundle.IdMaterials) { if (bundle.EnterAmount[i] != 0) { double resultPrice = (bundle.EnterAmount[i] * bundle.Price[i]); double money = 0; if (bundle.Discount[i] != 0) { int percentComplete = (int)Math.Round((double)(resultPrice * bundle.Discount[i]) / 100); money = (resultPrice - percentComplete); total += money; } else { total += resultPrice; money = resultPrice; } billDetail.Add(new BillDetail() { IdMaterials = item, Amount = bundle.EnterAmount[i], Discount = bundle.Discount[i], Price = (decimal)(bundle.Price[i]), TotalPrice = (decimal)money, Unit = bundle.Unit[i] }); // cập nhật số lượng chi tiết đặt hàng var orderDetail = await _context.OrderDetails.FindAsync(bundle.IdOrderDetail[i]); var enterAmountNow = orderDetail.EnterAmount + bundle.EnterAmount[i]; if (enterAmountNow >= bundle.Amount[i]) { orderDetail.Status = true; } orderDetail.EnterAmount = enterAmountNow; listOrderDetails.Add(orderDetail); // cập nhật số lượng bên nguyên vật liệu var materials = await _context.Materials.Include(x => x.Packs) .Where(x => x.Id == item).FirstOrDefaultAsync(); var amountDefault = materials.Packs.Where(x => x.Default == true).First(); var materialsDefault = materials.Amount; if (amountDefault.Name == bundle.Unit[i]) { materials.Amount = materialsDefault + bundle.EnterAmount[i]; } else { var amountPack = materials.Packs.Where(x => x.Name == bundle.Unit[i]).First(); var resultAmount = (long)(bundle.EnterAmount[i]) * amountPack.Value; materials.Amount = materialsDefault + resultAmount; } listMaterial.Add(materials); } i++; } if (bundle.Tax != 0) { int tax = (int)Math.Round((double)(total * bundle.Tax) / 100); total += tax; } // chuyển số thành chữ var convert = ""; if (total != 0) { convert = this.NumberToText(total); } var bill = new Bill() { AmountPaid = Decimal.Parse(bundle.AmountPaid), IdPlan = bundle.IdOrderPlan, IdSupplier = bundle.IdSupliers, PurchaseDate = bundle.PurchaseDate, CodeBill = bundle.CodeBill, Tax = bundle.Tax, CreatedDate = DateTime.Now, TotalMoney = (decimal)total, ConvertNumbers = convert, BillDetails = billDetail, }; var amountPaid = Double.Parse(bundle.AmountPaid); if (amountPaid == 0) { bill.PaymentStatus = PaymentStatus.Unpaid; } if (amountPaid > 0 && amountPaid < total) { bill.PaymentStatus = PaymentStatus.PartialPayment; } if (amountPaid >= total) { bill.PaymentStatus = PaymentStatus.Paid; } // tạo code var user = await _userManager.FindByNameAsync(bundle.NameCreator); bill.IdCreator = user.Id; var stt = 1; var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.StorageCode); Location: var location = code.Location + stt; var str = code.Name + location; var checkCode = await _context.Bills.AnyAsync(x => x.StorageCode == str); if (checkCode) { stt++; goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); bill.StorageCode = str; //tạo hóa đơn _context.OrderDetails.UpdateRange(listOrderDetails); _context.Materials.UpdateRange(listMaterial); _context.Bills.Add(bill); await _context.SaveChangesAsync(); // cập nhật trạng thái kế hoạch đặt hàng var check = true; var orderPlan = await _context.OrderPlans.Include(x => x.OrderDetails) .Where(x => x.Id == bundle.IdOrderPlan).FirstOrDefaultAsync(); foreach (var item in orderPlan.OrderDetails) { if (!item.Status) { check = false; break; } } if (check) { orderPlan.Status = StatusOrderPlan.Accomplished; _context.OrderPlans.Update(orderPlan); } await _context.SaveChangesAsync(); return(new ApiSuccessResult <long>(bill.Id)); }
public async Task <ApiResult <bool> > Create(CreateProcess bundle) { List <ProcessingVoucherDetail> processVoucherDetilList = new List <ProcessingVoucherDetail>(); List <Material> materialsUpdate = new List <Material>(); List <ProcessingDetail> processingDetailUpdate = new List <ProcessingDetail>(); int i = 0; foreach (var item in bundle.Amount) { if (item != 0) { var process = await _context.ProcessingDetails .Include(x => x.Recipe).ThenInclude(x => x.RecipeDetails) .Where(x => x.Id == bundle.IdProcess[i]).FirstOrDefaultAsync(); foreach (var it in process.Recipe.RecipeDetails) { var materials = await _context.Materials.Include(x => x.Packs) .Where(x => x.Id == it.IdMaterials).FirstOrDefaultAsync(); var unit = materials.Packs.Where(x => x.Name == it.Unit).FirstOrDefault(); long recipesDetailsAmount = 0; // tính số lượng vừa nhập,ý là số lượng sẽ phát recipesDetailsAmount = item * it.Amount * unit.Value; if (recipesDetailsAmount > materials.Amount || materials.Amount == 0) { string str = $"Không thể tạo, vì số lượng {materials.Name} không đủ."; return(new ApiErrorResult <bool>(str)); } // cập nhật lại số lượng trong nguyên vật liệu var amountMaterialNew = materials.Amount - recipesDetailsAmount; materials.Amount = amountMaterialNew < 0 ? 0 : amountMaterialNew; materialsUpdate.Add(materials); } // thêm số lượng sản phẩm đã được dx nhận nguyên liệu để tạo phiếu var processVD = new ProcessingVoucherDetail() { Amount = item, IdRecipe = process.IdRecipe, Unit = process.Unit }; processVoucherDetilList.Add(processVD); // cập nhật số lượng đã thêm trong kế hoạch chi tiết chế biến. var enterOld = process.EnterAmount; var enterNew = process.EnterAmount + item; process.EnterAmount = enterNew; var total = process.Amount - enterNew; if (total <= 0) { process.Status = true; } else { process.Status = false; } processingDetailUpdate.Add(process); } i++; } // tìm id user var user = await _userManager.FindByNameAsync(bundle.NameCreator); if (user == null) { return(new ApiErrorResult <bool>()); } // tạo code var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.Code); var stt = 1; Location: var location = code.Location + stt; var strCode = code.Name + location; var checkCode = await _context.ProductTypes.AnyAsync(x => x.Code == strCode); if (checkCode) { stt++; goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); //cập nhật kế hoạch chế biến đã hoàn thành phát var processVoucher = new ProcessingVoucher() { Code = strCode, IdCreator = user.Id, IdPlan = bundle.IdPlan, ProcessingVoucherDetails = processVoucherDetilList }; // cập nhật và khởi tạo _context.Materials.UpdateRange(materialsUpdate); _context.ProcessingDetails.UpdateRange(processingDetailUpdate); _context.ProcessingVouchers.Add(processVoucher); await _context.SaveChangesAsync(); var processNew = await _context.ProcessPlans.Include(x => x.ProcessingDetails) .Where(x => x.Id == bundle.IdPlan).FirstOrDefaultAsync(); var status = true; foreach (var p in processNew.ProcessingDetails) { if (!p.Status) { status = false; break; } } if (status) { processNew.Status = StatusProcessPlan.Processed; _context.ProcessPlans.Update(processNew); await _context.SaveChangesAsync(); } return(new ApiSuccessResult <bool>()); }
public async Task <ApiResult <bool> > Create(CreatePlan bundle) { var processingDetails = new List <ProcessingDetail>(); if (bundle.Pack.Length > 0) { var i = 0; foreach (var item in bundle.Pack) { processingDetails.Add(new ProcessingDetail() { Amount = bundle.Amount[i], IdRecipe = bundle.IdMaterials[i], Unit = item }); i++; } } // lưu code var user = await _userManager.FindByNameAsync(bundle.NameCreator); var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.Code); var stt = 1; Location: var location = code.Location + stt; var str = code.Name + location; var checkCode = await _context.OrderPlans.AnyAsync(x => x.Code == str); if (checkCode) { stt++; goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); // kế hoạch var process = new ProcessPlan() { Code = str, CreatedDate = DateTime.Now, ExpectedDate = bundle.ExpectedDate, Note = bundle.Note, IdCreator = user.Id, IdResponsible = bundle.IdResponsible, ProcessingDetails = processingDetails, Name = bundle.Name }; _context.ProcessPlans.Add(process); await _context.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
public async Task <ApiResult <int> > Create(ProductCreate bundle) { var pack = new List <Pack>(); pack.Add(new Pack() { Name = bundle.NamePackDefault, Value = 1, PackType = PackType.Product, Default = true }); if (bundle.NamePack != null) { int i = 0; foreach (string item in bundle.NamePack) { pack.Add(new Pack() { Name = item, Value = bundle.ValuePack[i], PackType = PackType.Product, Default = false }); i++; } } var product = new Product() { Code = bundle.Code, Name = bundle.Name, Description = bundle.Description, IdProductType = bundle.IdProductType, Packs = pack }; if (bundle.Min != null && bundle.Max != null) { product.Reminder = true; product.Min = bundle.Min; product.Max = bundle.Max; product.ReminderStartDate = (DateTime)bundle.ReminderStartDate; product.ReminderEndDate = (DateTime)bundle.ReminderEndDate; } var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.Code); var stt = 1; Location: var location = code.Location + stt; var str = code.Name + location; var checkCode = await _context.Products.AnyAsync(x => x.Code == str); if (checkCode) { stt++; goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); product.Code = str; _context.Products.Add(product); await _context.SaveChangesAsync(); // số bản ghi nếu return return(new ApiSuccessResult <int>(product.Id)); }
public async Task <ApiResult <bool> > Create(CreateOrderPlan bundle) { var order = _context.OrderPlans.Include(x => x.OrderDetails); var orderDetails = new List <OrderDetail>(); if (bundle.Pack.Length > 0) { var i = 0; foreach (var item in bundle.Pack) { orderDetails.Add(new OrderDetail() { Amount = bundle.Amount[i], IdMaterials = bundle.IdMaterials[i], Unit = item }); i++; } } var oderPlan = new OrderPlan() { Name = bundle.Name, ExpectedDate = bundle.ExpectedDate, CreatedDate = DateTime.Now, Note = bundle.Note, IdResponsible = bundle.IdResponsible, OrderDetails = orderDetails }; var user = await _userManager.FindByNameAsync(bundle.NameCreator); oderPlan.IdCreator = user.Id; var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.Code); var stt = 1; Location: var location = code.Location + stt; var str = code.Name + location; var checkCode = await _context.OrderPlans.AnyAsync(x => x.Code == str); if (checkCode) { stt++; goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); oderPlan.Code = str; _context.OrderPlans.Add(oderPlan); await _context.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
public async Task <ApiResult <GetCreateRecipe> > Create(CreateRecipe bundle) { var count = _context.Recipes.Where(x => x.IdProduct == bundle.IdProduct).Count(); if (count < 1) { bundle.Prioritize = true; } if (bundle.Prioritize) { var check = await _context.Recipes .AnyAsync(x => x.IdProduct == bundle.IdProduct && x.Prioritize == true); if (check) { var reciper = await _context.Recipes .FirstAsync(x => x.IdProduct == bundle.IdProduct && x.Prioritize == true); reciper.Prioritize = false; _context.Recipes.Update(reciper); } } var recipeDetail = new List <RecipeDetail>(); if (bundle.IdMaterials != null) { int i = 0; foreach (int item in bundle.IdMaterials) { recipeDetail.Add(new RecipeDetail() { IdMaterials = item, Amount = bundle.Amount[i], Unit = bundle.Unit[i] }); i++; } } var recipe = new Recipe() { Name = bundle.Name, Note = bundle.Note, Prioritize = bundle.Prioritize, IdProduct = bundle.IdProduct, RecipeDetails = recipeDetail }; var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.Code); var stt = 1; Location: var location = code.Location + stt; var str = code.Name + location; var checkCode = await _context.Recipes.AnyAsync(x => x.Code == str); if (checkCode) { stt++; goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); recipe.Code = str; _context.Recipes.Add(recipe); await _context.SaveChangesAsync(); var result = new GetCreateRecipe() { IdProduct = recipe.IdProduct, NameRecipe = recipe.Name, Prioritize = recipe.Prioritize }; return(new ApiSuccessResult <GetCreateRecipe>(result)); }