private GarmentInventorySummary GenerateGarmentInventorySummary(GarmentUnitReceiptNote garmentUnitReceiptNote, GarmentUnitReceiptNoteItem garmentUnitReceiptNoteItem, GarmentInventoryMovement garmentInventoryMovement) { var garmentInventorySummary = new GarmentInventorySummary(); EntityExtension.FlagForCreate(garmentInventorySummary, identityService.Username, USER_AGENT); do { garmentInventorySummary.No = CodeGenerator.Generate(); }while (dbSetGarmentInventorySummary.Any(m => m.No == garmentInventorySummary.No)); garmentInventorySummary.ProductId = garmentUnitReceiptNoteItem.ProductId; garmentInventorySummary.ProductCode = garmentUnitReceiptNoteItem.ProductCode; garmentInventorySummary.ProductName = garmentUnitReceiptNoteItem.ProductName; garmentInventorySummary.StorageId = garmentUnitReceiptNote.StorageId; garmentInventorySummary.StorageCode = garmentUnitReceiptNote.StorageCode; garmentInventorySummary.StorageName = garmentUnitReceiptNote.StorageName; garmentInventorySummary.Quantity = garmentInventoryMovement.After; garmentInventorySummary.UomId = garmentUnitReceiptNoteItem.SmallUomId; garmentInventorySummary.UomUnit = garmentUnitReceiptNoteItem.SmallUomUnit; garmentInventorySummary.StockPlanning = 0; return(garmentInventorySummary); }
async Task <string> GenerateNo(GarmentUnitDeliveryOrder model, int clientTimeZoneOffset) { GarmentUnitReceiptNote garmentUnitReceiptNote = (from data in dbContext.GarmentUnitReceiptNotes select data).FirstOrDefault(); DateTimeOffset dateTimeOffsetNow = garmentUnitReceiptNote.ReceiptDate; string Month = dateTimeOffsetNow.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("MM"); string Year = dateTimeOffsetNow.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("yy"); string Day = dateTimeOffsetNow.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd"); string no = string.Concat("DO", garmentUnitReceiptNote.UnitCode, Year, Month, Day); int Padding = 4; var lastNo = await this.dbSet.Where(w => w.UnitDONo.StartsWith(no) && !w.IsDeleted).OrderByDescending(o => o.UnitDONo).FirstOrDefaultAsync(); if (lastNo == null) { return(no + "1".PadLeft(Padding, '0')); } else { //int lastNoNumber = Int32.Parse(lastNo.INNo.Replace(no, "")) + 1; int.TryParse(lastNo.UnitDONo.Replace(no, ""), out int lastno1); int lastNoNumber = lastno1 + 1; return(no + lastNoNumber.ToString().PadLeft(Padding, '0')); } }
public async Task <GarmentReceiptCorrection> GetTestData(GarmentUnitReceiptNote unit) { var data = await GetNewData(unit); await garmentReceiptCorrectionFacade.Create(data.GarmentReceiptCorrection, "unit-test"); return(data.GarmentReceiptCorrection); }
public async Task <GarmentUnitDeliveryOrder> GetNewData(GarmentUnitReceiptNote unitReceiptNote1 = null) { DateTimeOffset now = DateTimeOffset.Now; long nowTicks = now.Ticks; var garmentUnitReceiptNote = unitReceiptNote1 ?? await Task.Run(() => UNDataUtil.GetTestDataWithStorage(nowTicks)); GarmentUnitDeliveryOrder garmentUnitDeliveryOrder = new GarmentUnitDeliveryOrder { UnitDOType = "SAMPLE", UnitDODate = DateTimeOffset.Now, UnitSenderId = garmentUnitReceiptNote.UnitId, UnitRequestCode = garmentUnitReceiptNote.UnitCode, UnitRequestName = garmentUnitReceiptNote.UnitName, UnitRequestId = garmentUnitReceiptNote.UnitId, UnitSenderCode = garmentUnitReceiptNote.UnitCode, UnitSenderName = garmentUnitReceiptNote.UnitName, StorageId = garmentUnitReceiptNote.StorageId, StorageCode = garmentUnitReceiptNote.StorageCode, StorageName = garmentUnitReceiptNote.StorageName, RONo = garmentUnitReceiptNote.Items.Select(i => i.RONo).FirstOrDefault(), Article = $"Article{nowTicks}", Items = new List <GarmentUnitDeliveryOrderItem>() }; foreach (var item in garmentUnitReceiptNote.Items) { var garmentDOItems = UNDataUtil.ReadDOItemsByURNItemId((int)item.Id); garmentUnitDeliveryOrder.Items.Add( new GarmentUnitDeliveryOrderItem { IsSave = true, DODetailId = item.DODetailId, EPOItemId = item.EPOItemId, POItemId = item.POItemId, PRItemId = item.PRItemId, FabricType = "FABRIC", URNId = garmentUnitReceiptNote.Id, URNItemId = item.Id, URNNo = garmentUnitReceiptNote.URNNo, POSerialNumber = item.POSerialNumber, RONo = item.RONo, ProductId = item.ProductId, ProductCode = item.ProductCode, ProductName = item.ProductName, Quantity = (double)(item.SmallQuantity - item.OrderQuantity), UomId = item.UomId, UomUnit = item.UomUnit, ReturUomId = item.UomId, ReturUomUnit = item.UomUnit, DOItemsId = (int)garmentDOItems.Id, DOCurrencyRate = 1 }); } return(garmentUnitDeliveryOrder); }
public void SetDataWithStorage(GarmentUnitReceiptNote garmentUnitReceiptNote, long?unitId = null) { long nowTicks = unitId ?? DateTimeOffset.Now.Ticks; garmentUnitReceiptNote.IsStorage = true; garmentUnitReceiptNote.StorageId = nowTicks; garmentUnitReceiptNote.StorageCode = string.Concat("StorageCode", nowTicks); garmentUnitReceiptNote.StorageName = string.Concat("StorageName", nowTicks); }
public async Task <int> Create(GarmentUnitDeliveryOrder garmentUnitDeliveryOrder) { int Created = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { garmentUnitDeliveryOrder.Items = garmentUnitDeliveryOrder.Items.Where(x => x.IsSave).ToList(); EntityExtension.FlagForCreate(garmentUnitDeliveryOrder, identityService.Username, USER_AGENT); garmentUnitDeliveryOrder.UnitDONo = await GenerateNo(garmentUnitDeliveryOrder); foreach (var garmentUnitDeliveryOrderItem in garmentUnitDeliveryOrder.Items) { EntityExtension.FlagForCreate(garmentUnitDeliveryOrderItem, identityService.Username, USER_AGENT); GarmentUnitReceiptNote garmentUnitReceiptNote = dbContext.GarmentUnitReceiptNotes.Single(s => s.Id == garmentUnitDeliveryOrderItem.URNId); garmentUnitDeliveryOrderItem.DOCurrencyRate = garmentUnitReceiptNote.DOCurrencyRate; if (garmentUnitDeliveryOrderItem.DOCurrencyRate == 0) { throw new Exception("garmentUnitDeliveryOrderItem.DOCurrencyRate tidak boleh 0"); } garmentUnitReceiptNote.IsUnitDO = true; GarmentUnitReceiptNoteItem garmentUnitReceiptNoteItem = dbContext.GarmentUnitReceiptNoteItems.Single(s => s.Id == garmentUnitDeliveryOrderItem.URNItemId); garmentUnitDeliveryOrderItem.DOCurrencyRate = garmentUnitReceiptNoteItem.DOCurrencyRate; EntityExtension.FlagForUpdate(garmentUnitReceiptNoteItem, identityService.Username, USER_AGENT); garmentUnitReceiptNoteItem.OrderQuantity = garmentUnitReceiptNoteItem.OrderQuantity + (decimal)garmentUnitDeliveryOrderItem.Quantity; // GarmentDOItems GarmentDOItems garmentDOItems = dbSetGarmentDOItems.FirstOrDefault(w => w.Id == garmentUnitDeliveryOrderItem.DOItemsId); if (garmentDOItems != null) { EntityExtension.FlagForUpdate(garmentDOItems, identityService.Username, USER_AGENT); garmentDOItems.RemainingQuantity = garmentDOItems.RemainingQuantity - (decimal)garmentUnitDeliveryOrderItem.Quantity; } } dbSet.Add(garmentUnitDeliveryOrder); Created = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
private GarmentInventoryDocument GenerateGarmentInventoryDocument(GarmentUnitReceiptNote garmentUnitReceiptNote, string type = "IN") { var garmentInventoryDocument = new GarmentInventoryDocument { Items = new List <GarmentInventoryDocumentItem>() }; EntityExtension.FlagForCreate(garmentInventoryDocument, identityService.Username, USER_AGENT); do { garmentInventoryDocument.No = CodeGenerator.Generate(); }while (dbSetGarmentInventoryDocument.Any(m => m.No == garmentInventoryDocument.No)); garmentInventoryDocument.ReferenceNo = garmentUnitReceiptNote.URNNo; garmentInventoryDocument.ReferenceType = string.Concat("Bon Terima Unit - ", garmentUnitReceiptNote.UnitName); garmentInventoryDocument.Type = (type ?? "").ToUpper() == "IN" ? "IN" : "OUT"; garmentInventoryDocument.StorageId = garmentUnitReceiptNote.StorageId; garmentInventoryDocument.StorageCode = garmentUnitReceiptNote.StorageCode; garmentInventoryDocument.StorageName = garmentUnitReceiptNote.StorageName; garmentInventoryDocument.Remark = garmentUnitReceiptNote.Remark; garmentInventoryDocument.Date = DateTimeOffset.Now; foreach (var garmentUnitReceiptNoteItem in garmentUnitReceiptNote.Items) { var garmentInventoryDocumentItem = new GarmentInventoryDocumentItem(); EntityExtension.FlagForCreate(garmentInventoryDocumentItem, identityService.Username, USER_AGENT); garmentInventoryDocumentItem.ProductId = garmentUnitReceiptNoteItem.ProductId; garmentInventoryDocumentItem.ProductCode = garmentUnitReceiptNoteItem.ProductCode; garmentInventoryDocumentItem.ProductName = garmentUnitReceiptNoteItem.ProductName; garmentInventoryDocumentItem.Quantity = garmentUnitReceiptNoteItem.SmallQuantity; garmentInventoryDocumentItem.UomId = garmentUnitReceiptNoteItem.SmallUomId; garmentInventoryDocumentItem.UomUnit = garmentUnitReceiptNoteItem.SmallUomUnit; garmentInventoryDocumentItem.ProductRemark = garmentUnitReceiptNoteItem.ProductRemark; garmentInventoryDocument.Items.Add(garmentInventoryDocumentItem); } return(garmentInventoryDocument); }
private async Task <string> GenerateNo(GarmentUnitReceiptNote garmentUnitReceiptNote) { string Year = garmentUnitReceiptNote.ReceiptDate.ToOffset(new TimeSpan(identityService.TimezoneOffset, 0, 0)).ToString("yy"); string Month = garmentUnitReceiptNote.ReceiptDate.ToOffset(new TimeSpan(identityService.TimezoneOffset, 0, 0)).ToString("MM"); string Day = garmentUnitReceiptNote.ReceiptDate.ToOffset(new TimeSpan(identityService.TimezoneOffset, 0, 0)).ToString("dd"); string no = string.Concat("BUM", garmentUnitReceiptNote.UnitCode, Year, Month, Day); int Padding = 3; var lastNo = await dbSet.Where(w => w.URNNo.StartsWith(no) && !w.IsDeleted).OrderByDescending(o => o.URNNo).FirstOrDefaultAsync(); if (lastNo == null) { return(no + "1".PadLeft(Padding, '0')); } else { int lastNoNumber = Int32.Parse(lastNo.URNNo.Replace(no, string.Empty)) + 1; return(no + lastNoNumber.ToString().PadLeft(Padding, '0')); } }
private GarmentInventoryMovement GenerateGarmentInventoryMovement(GarmentUnitReceiptNote garmentUnitReceiptNote, GarmentUnitReceiptNoteItem garmentUnitReceiptNoteItem, GarmentInventorySummary garmentInventorySummary, string type = "IN") { var garmentInventoryMovement = new GarmentInventoryMovement(); EntityExtension.FlagForCreate(garmentInventoryMovement, identityService.Username, USER_AGENT); do { garmentInventoryMovement.No = CodeGenerator.Generate(); }while (dbSetGarmentInventoryMovement.Any(m => m.No == garmentInventoryMovement.No)); garmentInventoryMovement.Date = garmentInventoryMovement.CreatedUtc; garmentInventoryMovement.ReferenceNo = garmentUnitReceiptNote.URNNo; garmentInventoryMovement.ReferenceType = string.Concat("Bon Terima Unit - ", garmentUnitReceiptNote.UnitName); garmentInventoryMovement.ProductId = garmentUnitReceiptNoteItem.ProductId; garmentInventoryMovement.ProductCode = garmentUnitReceiptNoteItem.ProductCode; garmentInventoryMovement.ProductName = garmentUnitReceiptNoteItem.ProductName; garmentInventoryMovement.StorageId = garmentUnitReceiptNote.StorageId; garmentInventoryMovement.StorageCode = garmentUnitReceiptNote.StorageCode; garmentInventoryMovement.StorageName = garmentUnitReceiptNote.StorageName; garmentInventoryMovement.StockPlanning = 0; garmentInventoryMovement.Before = garmentInventorySummary == null ? 0 : garmentInventorySummary.Quantity; garmentInventoryMovement.Quantity = garmentUnitReceiptNoteItem.SmallQuantity * ((type ?? "").ToUpper() == "OUT" ? -1 : 1); garmentInventoryMovement.After = garmentInventoryMovement.Before + garmentInventoryMovement.Quantity; garmentInventoryMovement.UomId = garmentUnitReceiptNoteItem.SmallUomId; garmentInventoryMovement.UomUnit = garmentUnitReceiptNoteItem.SmallUomUnit; garmentInventoryMovement.Remark = garmentUnitReceiptNoteItem.ProductRemark; garmentInventoryMovement.Type = (type ?? "").ToUpper() == "IN" ? "IN" : "OUT"; return(garmentInventoryMovement); }
public GarmentUnitReceiptNote GetNewData() { long nowTicks = DateTimeOffset.Now.Ticks; var gdo = Task.Run(() => garmentDeliveryOrderDataUtil.GetTestData()).Result; var garmentUnitReceiptNote = new GarmentUnitReceiptNote { UnitId = nowTicks, UnitCode = string.Concat("UnitCode", nowTicks), UnitName = string.Concat("UnitName", nowTicks), SupplierId = gdo.SupplierId, SupplierCode = gdo.SupplierCode, SupplierName = gdo.SupplierName, DOId = gdo.Id, DONo = gdo.DONo, ReceiptDate = DateTimeOffset.Now, Items = new List <GarmentUnitReceiptNoteItem>() }; foreach (var item in gdo.Items) { foreach (var detail in item.Details) { var garmentUnitReceiptNoteItem = new GarmentUnitReceiptNoteItem { DODetailId = detail.Id, EPOItemId = detail.EPOItemId, PRId = detail.PRId, PRNo = detail.PRNo, PRItemId = detail.PRItemId, POId = detail.POId, POItemId = detail.POItemId, POSerialNumber = detail.POSerialNumber, ProductId = detail.ProductId, ProductCode = detail.ProductCode, ProductName = detail.ProductName, ProductRemark = detail.ProductRemark, RONo = detail.RONo, ReceiptQuantity = (decimal)detail.ReceiptQuantity, UomId = long.Parse(detail.UomId), UomUnit = detail.UomUnit, PricePerDealUnit = (decimal)detail.PricePerDealUnit, DesignColor = string.Concat("DesignColor", nowTicks), SmallQuantity = (decimal)detail.SmallQuantity, SmallUomId = long.Parse(detail.SmallUomId), SmallUomUnit = detail.SmallUomUnit, }; garmentUnitReceiptNote.Items.Add(garmentUnitReceiptNoteItem); } } return(garmentUnitReceiptNote); }
public async Task <int> Update(int id, GarmentUnitReceiptNote garmentUnitReceiptNote) { int Updated = 0; using (var transaction = dbContext.Database.BeginTransaction()) { try { var oldGarmentUnitReceiptNote = dbSet .Include(d => d.Items) .Single(m => m.Id == id); // Gudang berubah if (garmentUnitReceiptNote.StorageId != oldGarmentUnitReceiptNote.StorageId) { foreach (var oldGarmentUnitReceiptNoteItem in oldGarmentUnitReceiptNote.Items) { // Buat OUT untuk Gudang yang lama var oldGarmentInventorySummary = dbSetGarmentInventorySummary.Single(s => s.ProductId == oldGarmentUnitReceiptNoteItem.ProductId && s.StorageId == oldGarmentUnitReceiptNote.StorageId && s.UomId == oldGarmentUnitReceiptNoteItem.SmallUomId); var garmentInventoryMovementOut = GenerateGarmentInventoryMovement(oldGarmentUnitReceiptNote, oldGarmentUnitReceiptNoteItem, oldGarmentInventorySummary, "OUT"); dbSetGarmentInventoryMovement.Add(garmentInventoryMovementOut); EntityExtension.FlagForUpdate(oldGarmentInventorySummary, identityService.Username, USER_AGENT); oldGarmentInventorySummary.Quantity = garmentInventoryMovementOut.After; // Buat IN untuk Gudang yang baru var garmentInventorySummaryExisting = dbSetGarmentInventorySummary.SingleOrDefault(s => s.ProductId == oldGarmentUnitReceiptNoteItem.ProductId && s.StorageId == garmentUnitReceiptNote.StorageId && s.UomId == oldGarmentUnitReceiptNoteItem.SmallUomId); var garmentInventoryMovementIn = GenerateGarmentInventoryMovement(garmentUnitReceiptNote, oldGarmentUnitReceiptNoteItem, garmentInventorySummaryExisting, "IN"); dbSetGarmentInventoryMovement.Add(garmentInventoryMovementIn); if (garmentInventorySummaryExisting == null) { var garmentInventorySummary = GenerateGarmentInventorySummary(garmentUnitReceiptNote, oldGarmentUnitReceiptNoteItem, garmentInventoryMovementIn); dbSetGarmentInventorySummary.Add(garmentInventorySummary); } else { EntityExtension.FlagForUpdate(garmentInventorySummaryExisting, identityService.Username, USER_AGENT); garmentInventorySummaryExisting.Quantity = garmentInventoryMovementIn.After; } await dbContext.SaveChangesAsync(); } var garmentInventoryDocumentOut = GenerateGarmentInventoryDocument(oldGarmentUnitReceiptNote, "OUT"); dbSetGarmentInventoryDocument.Add(garmentInventoryDocumentOut); var garmentInventoryDocumentIn = GenerateGarmentInventoryDocument(garmentUnitReceiptNote, "IN"); dbSetGarmentInventoryDocument.Add(garmentInventoryDocumentIn); oldGarmentUnitReceiptNote.StorageId = garmentUnitReceiptNote.StorageId; oldGarmentUnitReceiptNote.StorageCode = garmentUnitReceiptNote.StorageCode; oldGarmentUnitReceiptNote.StorageName = garmentUnitReceiptNote.StorageName; } EntityExtension.FlagForUpdate(oldGarmentUnitReceiptNote, identityService.Username, USER_AGENT); foreach (var oldGarmentUnitReceiptNoteItem in oldGarmentUnitReceiptNote.Items) { EntityExtension.FlagForUpdate(oldGarmentUnitReceiptNoteItem, identityService.Username, USER_AGENT); } oldGarmentUnitReceiptNote.Remark = garmentUnitReceiptNote.Remark; var garmentDeliveryOrder = dbsetGarmentDeliveryOrder.First(d => d.Id == garmentUnitReceiptNote.DOId); garmentUnitReceiptNote.DOCurrencyRate = garmentDeliveryOrder.DOCurrencyRate; Updated = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Updated); }
public async Task <int> Update(int id, GarmentUnitDeliveryOrder garmentUnitDeliveryOrder) { int Updated = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { garmentUnitDeliveryOrder.Items = garmentUnitDeliveryOrder.Items.Where(x => x.IsSave).ToList(); var oldGarmentUnitDeliveryOrder = dbSet .Include(d => d.Items) //.AsNoTracking() .Single(m => m.Id == id); EntityExtension.FlagForUpdate(oldGarmentUnitDeliveryOrder, identityService.Username, USER_AGENT); foreach (var garmentUnitDeliveryOrderItem in garmentUnitDeliveryOrder.Items) { if (garmentUnitDeliveryOrderItem.Id != 0) { var oldGarmentUnitDeliveryOrderItem = oldGarmentUnitDeliveryOrder.Items.FirstOrDefault(i => i.Id == garmentUnitDeliveryOrderItem.Id); EntityExtension.FlagForUpdate(oldGarmentUnitDeliveryOrderItem, identityService.Username, USER_AGENT); GarmentUnitReceiptNoteItem garmentUnitReceiptNoteItem = dbContext.GarmentUnitReceiptNoteItems.Single(s => s.Id == oldGarmentUnitDeliveryOrderItem.URNItemId); EntityExtension.FlagForUpdate(garmentUnitReceiptNoteItem, identityService.Username, USER_AGENT); garmentUnitReceiptNoteItem.OrderQuantity = garmentUnitReceiptNoteItem.OrderQuantity - (decimal)oldGarmentUnitDeliveryOrderItem.Quantity + (decimal)garmentUnitDeliveryOrderItem.Quantity; oldGarmentUnitDeliveryOrderItem.Quantity = garmentUnitDeliveryOrderItem.Quantity; oldGarmentUnitDeliveryOrderItem.DefaultDOQuantity = garmentUnitDeliveryOrderItem.Quantity; // Jumlah DO awal mengikuti Jumlah yang diubah (reset) oldGarmentUnitDeliveryOrderItem.FabricType = garmentUnitDeliveryOrderItem.FabricType; } else { EntityExtension.FlagForCreate(garmentUnitDeliveryOrderItem, identityService.Username, USER_AGENT); oldGarmentUnitDeliveryOrder.Items.Add(garmentUnitDeliveryOrderItem); GarmentUnitReceiptNoteItem garmentUnitReceiptNoteItem = dbContext.GarmentUnitReceiptNoteItems.Single(s => s.Id == garmentUnitDeliveryOrderItem.URNItemId); EntityExtension.FlagForUpdate(garmentUnitReceiptNoteItem, identityService.Username, USER_AGENT); garmentUnitReceiptNoteItem.OrderQuantity = garmentUnitReceiptNoteItem.OrderQuantity + (decimal)garmentUnitDeliveryOrderItem.Quantity; } } foreach (var oldGarmentUnitDeliveryOrderItem in oldGarmentUnitDeliveryOrder.Items) { var newGarmentUnitDeliveryOrderItem = garmentUnitDeliveryOrder.Items.FirstOrDefault(i => i.Id == oldGarmentUnitDeliveryOrderItem.Id); if (newGarmentUnitDeliveryOrderItem == null) { EntityExtension.FlagForDelete(oldGarmentUnitDeliveryOrderItem, identityService.Username, USER_AGENT); GarmentUnitReceiptNote garmentUnitReceiptNote = dbContext.GarmentUnitReceiptNotes.Single(s => s.Id == oldGarmentUnitDeliveryOrderItem.URNId); oldGarmentUnitDeliveryOrderItem.DOCurrencyRate = garmentUnitReceiptNote.DOCurrencyRate; GarmentUnitReceiptNoteItem garmentUnitReceiptNoteItem = dbContext.GarmentUnitReceiptNoteItems.Single(s => s.Id == oldGarmentUnitDeliveryOrderItem.URNItemId); EntityExtension.FlagForUpdate(garmentUnitReceiptNoteItem, identityService.Username, USER_AGENT); garmentUnitReceiptNoteItem.OrderQuantity = garmentUnitReceiptNoteItem.OrderQuantity - (decimal)oldGarmentUnitDeliveryOrderItem.Quantity; } } //dbSet.Update(garmentUnitDeliveryOrder); Updated = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Updated); }
public async Task <int> Update(int id, GarmentUnitReceiptNote garmentUnitReceiptNote) { int Updated = 0; using (var transaction = dbContext.Database.BeginTransaction()) { try { var oldGarmentUnitReceiptNote = dbSet .Include(d => d.Items) .AsNoTracking() .Single(m => m.Id == id); EntityExtension.FlagForUpdate(garmentUnitReceiptNote, identityService.Username, USER_AGENT); foreach (var garmentUnitReceiptNoteItem in garmentUnitReceiptNote.Items) { EntityExtension.FlagForUpdate(garmentUnitReceiptNoteItem, identityService.Username, USER_AGENT); var oldGarmentUnitReceiptNoteItem = oldGarmentUnitReceiptNote.Items.Single(i => i.Id == garmentUnitReceiptNoteItem.Id); var garmentDeliveryOrderDetail = dbSetGarmentDeliveryOrderDetail.First(d => d.Id == garmentUnitReceiptNoteItem.DODetailId); EntityExtension.FlagForUpdate(garmentDeliveryOrderDetail, identityService.Username, USER_AGENT); garmentDeliveryOrderDetail.ReceiptQuantity = (double)((decimal)garmentDeliveryOrderDetail.ReceiptQuantity - oldGarmentUnitReceiptNoteItem.ReceiptQuantity + garmentUnitReceiptNoteItem.ReceiptQuantity); var garmentExternalPurchaseOrderItem = dbSetGarmentExternalPurchaseOrderItems.First(d => d.Id == garmentUnitReceiptNoteItem.EPOItemId); EntityExtension.FlagForUpdate(garmentExternalPurchaseOrderItem, identityService.Username, USER_AGENT); garmentExternalPurchaseOrderItem.ReceiptQuantity = (double)((decimal)garmentExternalPurchaseOrderItem.ReceiptQuantity - oldGarmentUnitReceiptNoteItem.ReceiptQuantity + garmentUnitReceiptNoteItem.ReceiptQuantity); } // Sebelumnya disimpan di Gudang if (oldGarmentUnitReceiptNote.IsStorage) { // Tetap disimpan tapi Gudang berubah if (garmentUnitReceiptNote.IsStorage && garmentUnitReceiptNote.StorageId != oldGarmentUnitReceiptNote.StorageId) { var garmentInventoryDocumentOut = GenerateGarmentInventoryDocument(oldGarmentUnitReceiptNote, "OUT"); dbSetGarmentInventoryDocument.Add(garmentInventoryDocumentOut); var garmentInventoryDocumentIn = GenerateGarmentInventoryDocument(garmentUnitReceiptNote, "IN"); dbSetGarmentInventoryDocument.Add(garmentInventoryDocumentIn); foreach (var garmentUnitReceiptNoteItem in garmentUnitReceiptNote.Items) { // Buat OUT untuk Gudang yang lama var oldGarmentUnitReceiptNoteItem = oldGarmentUnitReceiptNote.Items.Single(i => i.Id == garmentUnitReceiptNoteItem.Id); var oldGarmentInventorySummaryExisting = dbSetGarmentInventorySummary.Single(s => s.ProductId == oldGarmentUnitReceiptNoteItem.ProductId && s.StorageId == oldGarmentUnitReceiptNote.StorageId && s.UomId == oldGarmentUnitReceiptNoteItem.UomId); var garmentInventoryMovementOut = GenerateGarmentInventoryMovement(oldGarmentUnitReceiptNote, oldGarmentUnitReceiptNoteItem, oldGarmentInventorySummaryExisting, "OUT"); dbSetGarmentInventoryMovement.Add(garmentInventoryMovementOut); EntityExtension.FlagForUpdate(oldGarmentInventorySummaryExisting, identityService.Username, USER_AGENT); oldGarmentInventorySummaryExisting.Quantity = garmentInventoryMovementOut.After; // Buat IN untuk Gudang yang baru var garmentInventorySummaryExisting = dbSetGarmentInventorySummary.SingleOrDefault(s => s.ProductId == garmentUnitReceiptNoteItem.ProductId && s.StorageId == garmentUnitReceiptNote.StorageId && s.UomId == garmentUnitReceiptNoteItem.UomId); var garmentInventoryMovementIn = GenerateGarmentInventoryMovement(garmentUnitReceiptNote, garmentUnitReceiptNoteItem, garmentInventorySummaryExisting, "IN"); dbSetGarmentInventoryMovement.Add(garmentInventoryMovementIn); if (garmentInventorySummaryExisting == null) { var garmentInventorySummary = GenerateGarmentInventorySummary(garmentUnitReceiptNote, garmentUnitReceiptNoteItem, garmentInventoryMovementIn); dbSetGarmentInventorySummary.Add(garmentInventorySummary); } else { EntityExtension.FlagForUpdate(garmentInventorySummaryExisting, identityService.Username, USER_AGENT); garmentInventorySummaryExisting.Quantity = garmentInventoryMovementIn.After; } } } // kemudian tidak disimpan di Gudang else if (!garmentUnitReceiptNote.IsStorage) { var garmentInventoryDocumentOut = GenerateGarmentInventoryDocument(oldGarmentUnitReceiptNote, "OUT"); dbSetGarmentInventoryDocument.Add(garmentInventoryDocumentOut); foreach (var garmentUnitReceiptNoteItem in garmentUnitReceiptNote.Items) { var oldGarmentUnitReceiptNoteItem = oldGarmentUnitReceiptNote.Items.Single(i => i.Id == garmentUnitReceiptNoteItem.Id); var garmentInventorySummaryExisting = dbSetGarmentInventorySummary.Single(s => s.ProductId == oldGarmentUnitReceiptNoteItem.ProductId && s.StorageId == oldGarmentUnitReceiptNote.StorageId && s.UomId == oldGarmentUnitReceiptNoteItem.UomId); var garmentInventoryMovementOut = GenerateGarmentInventoryMovement(oldGarmentUnitReceiptNote, oldGarmentUnitReceiptNoteItem, garmentInventorySummaryExisting, "OUT"); dbSetGarmentInventoryMovement.Add(garmentInventoryMovementOut); EntityExtension.FlagForUpdate(garmentInventorySummaryExisting, identityService.Username, USER_AGENT); garmentInventorySummaryExisting.Quantity = garmentInventoryMovementOut.After; } } } // Sebelumnya tidak disimpan di Gudang kemudian disimpan else if (garmentUnitReceiptNote.IsStorage) { var garmentInventoryDocumentIn = GenerateGarmentInventoryDocument(garmentUnitReceiptNote, "IN"); dbSetGarmentInventoryDocument.Add(garmentInventoryDocumentIn); foreach (var garmentUnitReceiptNoteItem in garmentUnitReceiptNote.Items) { var garmentInventorySummaryExisting = dbSetGarmentInventorySummary.SingleOrDefault(s => s.ProductId == garmentUnitReceiptNoteItem.ProductId && s.StorageId == garmentUnitReceiptNote.StorageId && s.UomId == garmentUnitReceiptNoteItem.UomId); var garmentInventoryMovementIn = GenerateGarmentInventoryMovement(garmentUnitReceiptNote, garmentUnitReceiptNoteItem, garmentInventorySummaryExisting, "IN"); dbSetGarmentInventoryMovement.Add(garmentInventoryMovementIn); if (garmentInventorySummaryExisting == null) { var garmentInventorySummary = GenerateGarmentInventorySummary(garmentUnitReceiptNote, garmentUnitReceiptNoteItem, garmentInventoryMovementIn); dbSetGarmentInventorySummary.Add(garmentInventorySummary); } else { EntityExtension.FlagForUpdate(garmentInventorySummaryExisting, identityService.Username, USER_AGENT); garmentInventorySummaryExisting.Quantity = garmentInventoryMovementIn.After; } } } dbSet.Update(garmentUnitReceiptNote); Updated = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Updated); }
public List <GarmentDispositionPaymentReportDto> GetReportByDate(DateTimeOffset startDate, DateTimeOffset endDate) { var dispositions = _dbContext.GarmentDispositionPurchases.Where(entity => entity.CreatedUtc >= startDate.DateTime && entity.CreatedUtc <= endDate.DateTime).ToList(); var result = new List <GarmentDispositionPaymentReportDto>(); if (dispositions.Count > 0) { var dispositionIds = dispositions.Select(element => element.Id).ToList(); var dispositionItems = _dbContext.GarmentDispositionPurchaseItems.Where(entity => dispositionIds.Contains(entity.GarmentDispositionPurchaseId)).ToList(); var dispositionItemIds = dispositionItems.Select(element => element.Id).ToList(); var dispositionDetails = _dbContext.GarmentDispositionPurchaseDetailss.Where(entity => dispositionItemIds.Contains(entity.GarmentDispositionPurchaseItemId)).ToList(); var epoIds = dispositionItems.Select(element => (long)element.EPOId).ToList(); var externalPurchaseOrders = _dbContext.GarmentExternalPurchaseOrders.Where(entity => epoIds.Contains(entity.Id)).ToList(); var deliveryOrderItems = _dbContext.GarmentDeliveryOrderItems.Where(entity => epoIds.Contains(entity.EPOId)).ToList(); var deliveryOrderItemIds = deliveryOrderItems.Select(element => element.Id).ToList(); var deliveryOrderIds = deliveryOrderItems.Select(element => element.GarmentDOId).ToList(); var deliveryOrderDetails = _dbContext.GarmentDeliveryOrderDetails.Where(entity => deliveryOrderItemIds.Contains(entity.GarmentDOItemId)).ToList(); var deliveryOrderDetailIds = deliveryOrderDetails.Select(entity => entity.Id).ToList(); var deliveryOrders = _dbContext.GarmentDeliveryOrders.Where(entity => deliveryOrderIds.Contains(entity.Id)).ToList(); var customItems = _dbContext.GarmentBeacukaiItems.Where(entity => deliveryOrderIds.Contains(entity.GarmentDOId)).ToList(); var customIds = customItems.Select(entity => entity.BeacukaiId).ToList(); var customs = _dbContext.GarmentBeacukais.Where(entity => customIds.Contains(entity.Id)).ToList(); var unitReceiptNoteItems = _dbContext.GarmentUnitReceiptNoteItems.Where(entity => deliveryOrderDetailIds.Contains(entity.DODetailId)).ToList(); var unitReceiptNoteIds = unitReceiptNoteItems.Select(element => element.URNId).ToList(); var unitReceiptNotes = _dbContext.GarmentUnitReceiptNotes.Where(entity => unitReceiptNoteIds.Contains(entity.Id)).ToList(); var internalNoteDetails = _dbContext.GarmentInternNoteDetails.Where(entity => deliveryOrderIds.Contains(entity.DOId)).ToList(); var internalNoteItemIds = internalNoteDetails.Select(element => element.GarmentItemINId).ToList(); var internalNoteItems = _dbContext.GarmentInternNoteItems.Where(entity => internalNoteItemIds.Contains(entity.Id)).ToList(); var internalNoteIds = internalNoteItems.Select(element => element.GarmentINId).ToList(); var internalNotes = _dbContext.GarmentInternNotes.Where(entity => internalNoteIds.Contains(entity.Id)).ToList(); foreach (var dispositionItem in dispositionItems) { var disposition = dispositions.FirstOrDefault(element => element.Id == dispositionItem.GarmentDispositionPurchaseId); var externalPurchaseOrder = externalPurchaseOrders.FirstOrDefault(element => element.Id == dispositionItem.EPOId); var selectedDispoositionDetails = dispositionDetails.Where(element => element.GarmentDispositionPurchaseItemId == dispositionItem.Id).ToList(); var deliveryOrderItem = deliveryOrderItems.FirstOrDefault(element => element.EPOId == dispositionItem.EPOId); if (deliveryOrderItem == null) { deliveryOrderItem = new GarmentDeliveryOrderItem(); } var deliveryOrder = deliveryOrders.FirstOrDefault(element => deliveryOrderItem.GarmentDOId == element.Id); if (deliveryOrder == null) { deliveryOrder = new GarmentDeliveryOrder(); } var selectedDeliveryOrderDetails = deliveryOrderDetails.Where(element => element.GarmentDOItemId == deliveryOrderItem.Id).ToList(); var selectedDeliveryOrderDetailIds = selectedDeliveryOrderDetails.Select(element => element.Id).ToList(); var customItem = customItems.FirstOrDefault(element => element.GarmentDOId == deliveryOrder.Id); if (customItem == null) { customItem = new GarmentBeacukaiItem(); } var custom = customs.FirstOrDefault(element => customItem.BeacukaiId == element.Id); if (custom == null) { custom = new GarmentBeacukai(); } var unitReceiptNoteItem = unitReceiptNoteItems.FirstOrDefault(element => selectedDeliveryOrderDetailIds.Contains(element.DODetailId)); if (unitReceiptNoteItem == null) { unitReceiptNoteItem = new GarmentUnitReceiptNoteItem(); } var unitReceiptNote = unitReceiptNotes.FirstOrDefault(element => element.Id == unitReceiptNoteItem.URNId); if (unitReceiptNote == null) { unitReceiptNote = new GarmentUnitReceiptNote(); } var internalNoteDetail = internalNoteDetails.FirstOrDefault(element => element.DOId == deliveryOrder.Id); if (internalNoteDetail == null) { internalNoteDetail = new GarmentInternNoteDetail(); } var internalNoteItem = internalNoteItems.FirstOrDefault(element => element.Id == internalNoteDetail.GarmentItemINId); if (internalNoteItem == null) { internalNoteItem = new GarmentInternNoteItem(); } var internalNote = internalNotes.FirstOrDefault(element => element.Id == internalNoteItem.GarmentINId); if (internalNote == null) { internalNote = new GarmentInternNote(); } var customDate = (DateTimeOffset?)null; if (custom.Id > 0) { customDate = custom.BeacukaiDate; } var internalNoteDate = (DateTimeOffset?)null; if (internalNote.Id > 0) { internalNoteDate = internalNote.INDate; } result.Add(new GarmentDispositionPaymentReportDto( disposition.Id, disposition.DispositionNo, disposition.CreatedUtc, disposition.DueDate, disposition.InvoiceProformaNo, disposition.SupplierId, disposition.SupplierCode, disposition.SupplierName, disposition.CurrencyId, dispositionItem.CurrencyCode, dispositionItem.CurrencyRate, disposition.Dpp, disposition.VAT, disposition.IncomeTax, disposition.OtherCost, disposition.Amount, 0, disposition.Category, disposition.Category, externalPurchaseOrder != null? (int)externalPurchaseOrder.Id:0, externalPurchaseOrder != null? externalPurchaseOrder.EPONo:string.Empty, selectedDispoositionDetails.Sum(sum => sum.QTYPaid), deliveryOrder.Id > 0 ? (int)deliveryOrder.Id : 0, deliveryOrder.Id > 0 ? deliveryOrder.DONo : "", deliveryOrder.Id > 0 ? selectedDeliveryOrderDetails.Sum(sum => sum.DOQuantity) : 0, deliveryOrder.Id > 0 ? deliveryOrder.PaymentBill : "", deliveryOrder.Id > 0 ? deliveryOrder.BillNo : "", custom.Id > 0 ? (int)custom.Id : 0, custom.Id > 0 ? custom.BeacukaiNo : "", customDate, unitReceiptNote.Id > 0 ? (int)unitReceiptNote.Id : 0, unitReceiptNote.Id > 0 ? unitReceiptNote.URNNo : "", internalNote.Id > 0 ? (int)internalNote.Id : 0, internalNote.Id > 0 ? internalNote.INNo : "", internalNoteDate, disposition.CreatedBy )); } } return(result); }
public async Task <(GarmentReceiptCorrection GarmentReceiptCorrection, GarmentUnitReceiptNote GarmentUnitReceiptNote)> GetNewData(GarmentUnitReceiptNote unitReceiptNote = null) { var garmentUnitReceiptNote = unitReceiptNote ?? await Task.Run(() => garmentUnitReceiptNoteDataUtil.GetTestData()); GarmentReceiptCorrection garmentReceiptCorrection = new GarmentReceiptCorrection { CorrectionDate = DateTimeOffset.Now, UnitCode = garmentUnitReceiptNote.UnitCode, UnitId = garmentUnitReceiptNote.UnitId, UnitName = garmentUnitReceiptNote.UnitName, URNId = garmentUnitReceiptNote.Id, URNNo = garmentUnitReceiptNote.URNNo, StorageCode = garmentUnitReceiptNote.StorageCode, StorageId = garmentUnitReceiptNote.StorageId, StorageName = garmentUnitReceiptNote.StorageName, Remark = "Remark", Items = new List <GarmentReceiptCorrectionItem>() }; foreach (var detail in garmentUnitReceiptNote.Items) { garmentReceiptCorrection.Items.Add( new GarmentReceiptCorrectionItem { DODetailId = detail.Id, EPOItemId = detail.EPOItemId, POItemId = detail.POItemId, PricePerDealUnit = (double)detail.PricePerDealUnit, PRItemId = detail.PRItemId, Conversion = (double)detail.Conversion, POSerialNumber = detail.POSerialNumber, RONo = detail.RONo, ProductId = detail.ProductId, ProductCode = detail.ProductCode, ProductName = detail.ProductName, Quantity = (double)detail.ReceiptCorrection, UomId = Convert.ToInt32(detail.UomId), UomUnit = detail.UomUnit, DesignColor = detail.DesignColor, ProductRemark = detail.ProductRemark, SmallQuantity = (double)detail.SmallQuantity, SmallUomId = detail.SmallUomId, SmallUomUnit = detail.SmallUomUnit, URNItemId = detail.Id }); } return(garmentReceiptCorrection, garmentUnitReceiptNote); }
public async Task <GarmentUnitReceiptNote> GetNewData(long?ticks = null, GarmentDeliveryOrder garmentDeliveryOrder = null) { long nowTicks = ticks ?? DateTimeOffset.Now.Ticks; garmentDeliveryOrder = garmentDeliveryOrder ?? await Task.Run(() => garmentDeliveryOrderDataUtil.GetTestData()); var garmentUnitReceiptNote = new GarmentUnitReceiptNote { URNType = "PEMBELIAN", UnitId = nowTicks, UnitCode = string.Concat("UnitCode", nowTicks), UnitName = string.Concat("UnitName", nowTicks), SupplierId = garmentDeliveryOrder.SupplierId, SupplierCode = garmentDeliveryOrder.SupplierCode, SupplierName = garmentDeliveryOrder.SupplierName, DOId = garmentDeliveryOrder.Id, DONo = garmentDeliveryOrder.DONo, DeletedReason = nowTicks.ToString(), DOCurrencyRate = garmentDeliveryOrder.DOCurrencyRate, ReceiptDate = DateTimeOffset.Now, Items = new List <GarmentUnitReceiptNoteItem>() }; foreach (var item in garmentDeliveryOrder.Items) { foreach (var detail in item.Details) { var garmentUnitReceiptNoteItem = new GarmentUnitReceiptNoteItem { DODetailId = detail.Id, EPOItemId = detail.EPOItemId, PRId = detail.PRId, PRNo = detail.PRNo, PRItemId = detail.PRItemId, POId = detail.POId, POItemId = detail.POItemId, POSerialNumber = detail.POSerialNumber, ProductId = detail.ProductId, ProductCode = detail.ProductCode, ProductName = detail.ProductName, ProductRemark = detail.ProductRemark, RONo = detail.RONo, ReceiptQuantity = (decimal)detail.ReceiptQuantity, UomId = long.Parse(detail.UomId), UomUnit = detail.UomUnit, PricePerDealUnit = (decimal)detail.PricePerDealUnit, DesignColor = string.Concat("DesignColor", nowTicks), SmallQuantity = (decimal)detail.SmallQuantity, SmallUomId = long.Parse(detail.SmallUomId), SmallUomUnit = detail.SmallUomUnit, Conversion = (decimal)detail.Conversion, CorrectionConversion = (decimal)detail.Conversion, DOCurrencyRate = 1 }; garmentUnitReceiptNote.Items.Add(garmentUnitReceiptNoteItem); } } return(garmentUnitReceiptNote); }
public async Task <int> Create(GarmentUnitReceiptNote garmentUnitReceiptNote) { int Created = 0; using (var transaction = dbContext.Database.BeginTransaction()) { try { EntityExtension.FlagForCreate(garmentUnitReceiptNote, identityService.Username, USER_AGENT); garmentUnitReceiptNote.URNNo = await GenerateNo(garmentUnitReceiptNote); garmentUnitReceiptNote.IsStorage = true; var garmentDeliveryOrder = dbsetGarmentDeliveryOrder.First(d => d.Id == garmentUnitReceiptNote.DOId); garmentUnitReceiptNote.DOCurrencyRate = garmentDeliveryOrder.DOCurrencyRate; foreach (var garmentUnitReceiptNoteItem in garmentUnitReceiptNote.Items) { EntityExtension.FlagForCreate(garmentUnitReceiptNoteItem, identityService.Username, USER_AGENT); garmentUnitReceiptNoteItem.ReceiptCorrection = garmentUnitReceiptNoteItem.ReceiptQuantity; var garmentDeliveryOrderDetail = dbSetGarmentDeliveryOrderDetail.First(d => d.Id == garmentUnitReceiptNoteItem.DODetailId); EntityExtension.FlagForUpdate(garmentDeliveryOrderDetail, identityService.Username, USER_AGENT); garmentDeliveryOrderDetail.ReceiptQuantity = (double)((decimal)garmentDeliveryOrderDetail.ReceiptQuantity + garmentUnitReceiptNoteItem.ReceiptQuantity); var garmentExternalPurchaseOrderItem = dbSetGarmentExternalPurchaseOrderItems.First(d => d.Id == garmentUnitReceiptNoteItem.EPOItemId); EntityExtension.FlagForUpdate(garmentExternalPurchaseOrderItem, identityService.Username, USER_AGENT); garmentExternalPurchaseOrderItem.ReceiptQuantity = (double)((decimal)garmentExternalPurchaseOrderItem.ReceiptQuantity + garmentUnitReceiptNoteItem.ReceiptQuantity); var garmentInternalPurchaseOrderItem = dbSetGarmentInternalPurchaseOrderItems.First(d => d.Id == garmentUnitReceiptNoteItem.POItemId); EntityExtension.FlagForUpdate(garmentInternalPurchaseOrderItem, identityService.Username, USER_AGENT); garmentInternalPurchaseOrderItem.Status = "Barang sudah diterima Unit"; var garmentInventorySummaryExisting = dbSetGarmentInventorySummary.SingleOrDefault(s => s.ProductId == garmentUnitReceiptNoteItem.ProductId && s.StorageId == garmentUnitReceiptNote.StorageId && s.UomId == garmentUnitReceiptNoteItem.SmallUomId); var garmentInventoryMovement = GenerateGarmentInventoryMovement(garmentUnitReceiptNote, garmentUnitReceiptNoteItem, garmentInventorySummaryExisting); dbSetGarmentInventoryMovement.Add(garmentInventoryMovement); if (garmentInventorySummaryExisting == null) { var garmentInventorySummary = GenerateGarmentInventorySummary(garmentUnitReceiptNote, garmentUnitReceiptNoteItem, garmentInventoryMovement); dbSetGarmentInventorySummary.Add(garmentInventorySummary); } else { EntityExtension.FlagForUpdate(garmentInventorySummaryExisting, identityService.Username, USER_AGENT); garmentInventorySummaryExisting.Quantity = garmentInventoryMovement.After; } await dbContext.SaveChangesAsync(); } var garmentInventoryDocument = GenerateGarmentInventoryDocument(garmentUnitReceiptNote); dbSetGarmentInventoryDocument.Add(garmentInventoryDocument); dbSet.Add(garmentUnitReceiptNote); Created = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }