public async Task <GarmentLeftoverWarehouseReceiptFinishedGood> GetTestData() { GarmentLeftoverWarehouseReceiptFinishedGood data = GetNewData(); await Service.CreateAsync(data); return(data); }
public GarmentLeftoverWarehouseReceiptFinishedGood MapToModel(GarmentLeftoverWarehouseReceiptFinishedGoodViewModel viewModel) { GarmentLeftoverWarehouseReceiptFinishedGood model = new GarmentLeftoverWarehouseReceiptFinishedGood(); PropertyCopier <GarmentLeftoverWarehouseReceiptFinishedGoodViewModel, GarmentLeftoverWarehouseReceiptFinishedGood> .Copy(viewModel, model); if (viewModel.UnitFrom != null) { model.UnitFromId = long.Parse(viewModel.UnitFrom.Id); model.UnitFromCode = viewModel.UnitFrom.Code; model.UnitFromName = viewModel.UnitFrom.Name; } model.Items = new List <GarmentLeftoverWarehouseReceiptFinishedGoodItem>(); foreach (var viewModelItem in viewModel.Items) { GarmentLeftoverWarehouseReceiptFinishedGoodItem modelItem = new GarmentLeftoverWarehouseReceiptFinishedGoodItem(); PropertyCopier <GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel, GarmentLeftoverWarehouseReceiptFinishedGoodItem> .Copy(viewModelItem, modelItem); if (viewModelItem.Size != null) { modelItem.SizeId = viewModelItem.Size.Id; modelItem.SizeName = viewModelItem.Size.Name; } if (viewModelItem.Uom != null) { modelItem.UomId = long.Parse(viewModelItem.Uom.Id); modelItem.UomUnit = viewModelItem.Uom.Unit; } if (viewModelItem.LeftoverComodity != null) { modelItem.LeftoverComodityCode = viewModelItem.LeftoverComodity.Code; modelItem.LeftoverComodityId = viewModelItem.LeftoverComodity.Id; modelItem.LeftoverComodityName = viewModelItem.LeftoverComodity.Name; } if (viewModelItem.Buyer != null) { modelItem.BuyerId = viewModelItem.Buyer.Id; modelItem.BuyerCode = viewModelItem.Buyer.Code; modelItem.BuyerName = viewModelItem.Buyer.Name; } if (viewModelItem.Comodity != null) { modelItem.ComodityId = viewModelItem.Comodity.Id; modelItem.ComodityCode = viewModelItem.Comodity.Code; modelItem.ComodityName = viewModelItem.Comodity.Name; } model.Items.Add(modelItem); } return(model); }
public async Task <int> CreateAsync(GarmentLeftoverWarehouseReceiptFinishedGood model) { int Created = 0; using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction()) { try { model.FlagForCreate(IdentityService.Username, UserAgent); model.FlagForUpdate(IdentityService.Username, UserAgent); model.FinishedGoodReceiptNo = GenerateNo(model); foreach (var item in model.Items) { item.FlagForCreate(IdentityService.Username, UserAgent); item.FlagForUpdate(IdentityService.Username, UserAgent); } DbSet.Add(model); Created = await DbContext.SaveChangesAsync(); foreach (var item in model.Items) { GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock { ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.FINISHED_GOOD, UnitId = model.UnitFromId, UnitCode = model.UnitFromCode, UnitName = model.UnitFromName, RONo = item.RONo, LeftoverComodityCode = item.LeftoverComodityCode, LeftoverComodityId = item.LeftoverComodityId, LeftoverComodityName = item.LeftoverComodityName, Quantity = item.Quantity, BasicPrice = item.BasicPrice }; await StockService.StockIn(stock, model.FinishedGoodReceiptNo, model.Id, item.Id); await UpdateExpenditureGoodIsReceived(item.ExpenditureGoodId, "true"); } transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw e; } } return(Created); }
private string GenerateNo(GarmentLeftoverWarehouseReceiptFinishedGood model) { string prefix = "BMB" + model.UnitFromCode.Trim() + model._CreatedUtc.ToString("yy") + model._CreatedUtc.ToString("MM"); var lastNo = DbSet.Where(w => w.FinishedGoodReceiptNo.StartsWith(prefix)) .OrderByDescending(o => o.FinishedGoodReceiptNo) .Select(s => int.Parse(s.FinishedGoodReceiptNo.Replace(prefix, ""))) .FirstOrDefault(); var curNo = $"{prefix}{(lastNo + 1).ToString("D4")}"; return(curNo); }
public GarmentLeftoverWarehouseReceiptFinishedGood CopyData(GarmentLeftoverWarehouseReceiptFinishedGood oldData) { GarmentLeftoverWarehouseReceiptFinishedGood newData = new GarmentLeftoverWarehouseReceiptFinishedGood(); PropertyCopier <GarmentLeftoverWarehouseReceiptFinishedGood, GarmentLeftoverWarehouseReceiptFinishedGood> .Copy(oldData, newData); newData.Items = new List <GarmentLeftoverWarehouseReceiptFinishedGoodItem>(); foreach (var oldItem in oldData.Items) { GarmentLeftoverWarehouseReceiptFinishedGoodItem newItem = new GarmentLeftoverWarehouseReceiptFinishedGoodItem(); PropertyCopier <GarmentLeftoverWarehouseReceiptFinishedGoodItem, GarmentLeftoverWarehouseReceiptFinishedGoodItem> .Copy(oldItem, newItem); newData.Items.Add(newItem); } return(newData); }
public async Task <int> UpdateAsync(int id, GarmentLeftoverWarehouseReceiptFinishedGood model) { int Updated = 0; using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction()) { try { GarmentLeftoverWarehouseReceiptFinishedGood existingModel = await ReadByIdAsync(id); if (existingModel.ReceiptDate != model.ReceiptDate) { existingModel.ReceiptDate = model.ReceiptDate; } if (existingModel.Description != model.Description) { existingModel.Description = model.Description; } foreach (var existingItem in existingModel.Items) { GarmentLeftoverWarehouseStock stockOut = new GarmentLeftoverWarehouseStock { ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.FINISHED_GOOD, UnitId = existingModel.UnitFromId, UnitCode = existingModel.UnitFromCode, UnitName = existingModel.UnitFromName, RONo = existingItem.RONo, Quantity = existingItem.Quantity, LeftoverComodityCode = existingItem.LeftoverComodityCode, LeftoverComodityId = existingItem.LeftoverComodityId, LeftoverComodityName = existingItem.LeftoverComodityName, BasicPrice = existingItem.BasicPrice }; await StockService.StockOut(stockOut, model.FinishedGoodReceiptNo, model.Id, existingItem.Id); } foreach (var existingItem in existingModel.Items) { var item = model.Items.FirstOrDefault(i => i.Id == existingItem.Id); if (item == null) { existingItem.FlagForDelete(IdentityService.Username, UserAgent); await UpdateExpenditureGoodIsReceived(existingItem.ExpenditureGoodId, "false"); } else { if (existingItem.Quantity != item.Quantity) { existingItem.Quantity = item.Quantity; } existingItem.FlagForUpdate(IdentityService.Username, UserAgent); } } foreach (var item in model.Items.Where(i => i.Id == 0)) { item.FlagForCreate(IdentityService.Username, UserAgent); await UpdateExpenditureGoodIsReceived(item.ExpenditureGoodId, "true"); item.FlagForUpdate(IdentityService.Username, UserAgent); existingModel.Items.Add(item); } Updated = await DbContext.SaveChangesAsync(); foreach (var item in model.Items) { GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock { ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.FINISHED_GOOD, UnitId = existingModel.UnitFromId, UnitCode = existingModel.UnitFromCode, UnitName = existingModel.UnitFromName, RONo = item.RONo, Quantity = item.Quantity, LeftoverComodityCode = item.LeftoverComodityCode, LeftoverComodityId = item.LeftoverComodityId, LeftoverComodityName = item.LeftoverComodityName, BasicPrice = item.BasicPrice }; await StockService.StockIn(stock, model.FinishedGoodReceiptNo, model.Id, item.Id); } existingModel.FlagForUpdate(IdentityService.Username, UserAgent); Updated = await DbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw e; } } return(Updated); }
public GarmentLeftoverWarehouseReceiptFinishedGoodViewModel MapToViewModel(GarmentLeftoverWarehouseReceiptFinishedGood model) { GarmentLeftoverWarehouseReceiptFinishedGoodViewModel viewModel = new GarmentLeftoverWarehouseReceiptFinishedGoodViewModel(); PropertyCopier <GarmentLeftoverWarehouseReceiptFinishedGood, GarmentLeftoverWarehouseReceiptFinishedGoodViewModel> .Copy(model, viewModel); viewModel.UnitFrom = new UnitViewModel { Id = model.UnitFromId.ToString(), Code = model.UnitFromCode, Name = model.UnitFromName }; if (model.Items != null) { viewModel.Items = new List <GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel>(); foreach (var modelItem in model.Items) { GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel viewModelItem = new GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel(); PropertyCopier <GarmentLeftoverWarehouseReceiptFinishedGoodItem, GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel> .Copy(modelItem, viewModelItem); viewModelItem.Size = new SizeViewModel { Id = modelItem.SizeId, Name = modelItem.SizeName }; viewModelItem.Uom = new UomViewModel { Id = modelItem.UomId.ToString(), Unit = modelItem.UomUnit }; viewModelItem.LeftoverComodity = new LeftoverComodityViewModel { Id = modelItem.LeftoverComodityId, Name = modelItem.LeftoverComodityName, Code = modelItem.LeftoverComodityCode }; viewModelItem.Buyer = new BuyerViewModel { Id = modelItem.BuyerId, Code = modelItem.BuyerCode, Name = modelItem.BuyerName }; viewModelItem.Comodity = new ComodityViewModel { Id = modelItem.ComodityId, Code = modelItem.ComodityCode, Name = modelItem.ComodityName }; viewModel.Items.Add(viewModelItem); } } return(viewModel); }