public ReportIndexDto(GarmentDeliveryOrder garmentDeliveryOrders, GarmentBeacukaiItem deliveryOrderCustoms, GarmentDeliveryOrderItem deliveryOrderItems, GarmentInvoiceItem deliveryOrderInvoiceItems, GarmentInvoice deliveryOrderInvoices, GarmentExternalPurchaseOrder deliveryOrderExternalPurchaseOrders, GarmentInternNoteDetail deliveryOrderInternalNoteDetails, GarmentInternNoteItem deliveryOrderInternalNoteItems, GarmentInternNote deliveryOrderInternalNotes) { if (deliveryOrderCustoms != null) { CustomsArrivalDate = deliveryOrderCustoms.ArrivalDate; } if (deliveryOrderExternalPurchaseOrders != null) { SupplierId = deliveryOrderExternalPurchaseOrders.SupplierId; SupplierName = deliveryOrderExternalPurchaseOrders.SupplierName; IsImportSupplier = deliveryOrderExternalPurchaseOrders.SupplierImport; AccountingCategoryName = deliveryOrderExternalPurchaseOrders.Category; PurchasingCategoryName = deliveryOrderExternalPurchaseOrders.Category; } var dppAmount = 0.0; if (deliveryOrderInternalNoteDetails != null) { ProductName = deliveryOrderInternalNoteDetails.ProductName; InternalNoteQuantity = deliveryOrderInternalNoteDetails.Quantity; dppAmount = deliveryOrderInternalNoteDetails.PriceTotal; Total = dppAmount; } if (garmentDeliveryOrders != null) { GarmentDeliveryOrderId = (int)garmentDeliveryOrders.Id; GarmentDeliveryOrderNo = garmentDeliveryOrders.DONo; BillNo = garmentDeliveryOrders.BillNo; PaymentBill = garmentDeliveryOrders.PaymentBill; } if (deliveryOrderInvoices != null) { InvoiceId = (int)deliveryOrderInvoices.Id; InvoiceNo = deliveryOrderInvoices.InvoiceNo; VATNo = deliveryOrderInvoices.VatNo; var vatAmount = 0.0; if (deliveryOrderInvoices.UseVat && deliveryOrderInvoices.IsPayVat) { vatAmount = dppAmount * 0.1; Total += vatAmount; } var incomeTaxAmount = 0.0; if (deliveryOrderInvoices.UseIncomeTax && deliveryOrderInvoices.IsPayTax) { incomeTaxAmount = dppAmount * deliveryOrderInvoices.IncomeTaxRate / 100; Total += incomeTaxAmount; } VATAmount = vatAmount; IncomeTaxAmount = incomeTaxAmount; } }
public async Task Should_Success_Update_Data() { var facade = new GarmentBeacukaiFacade(_dbContext(GetCurrentMethod()), ServiceProvider); var facadeDO = new GarmentDeliveryOrderFacade(ServiceProvider, _dbContext(GetCurrentMethod())); GarmentBeacukai data = await dataUtil(facade, GetCurrentMethod()).GetTestData1(USERNAME); GarmentBeacukaiViewModel viewModel = await dataUtil(facade, GetCurrentMethod()).GetViewModel(USERNAME); var newModelItem = new GarmentBeacukaiItem { GarmentDOId = viewModel.items.First().deliveryOrder.Id, TotalQty = 1, TotalAmount = 1 }; data.Items.Add(newModelItem); List <GarmentBeacukaiItemViewModel> Newitems = new List <GarmentBeacukaiItemViewModel>(); foreach (GarmentBeacukaiItem i in data.Items) { var newItem = new GarmentBeacukaiItemViewModel { selected = true, deliveryOrder = new Lib.ViewModels.GarmentDeliveryOrderViewModel.GarmentDeliveryOrderViewModel { Id = i.GarmentDOId, }, Id = i.Id, billNo = null, quantity = 0 }; Newitems.Add(newItem); } viewModel.Id = data.Id; viewModel.items = Newitems; var ResponseUpdate1 = await facade.Update((int)data.Id, viewModel, data, USERNAME); Assert.NotEqual(0, ResponseUpdate1); var ResponseUpdate2 = await facade.Update((int)data.Id, viewModel, data, USERNAME); Assert.NotEqual(0, ResponseUpdate2); }
public async Task <int> Update(int id, GarmentBeacukaiViewModel vm, GarmentBeacukai model, string user, int clientTimeZoneOffset = 7) { int Updated = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { EntityExtension.FlagForUpdate(model, user, USER_AGENT); foreach (GarmentBeacukaiItemViewModel itemViewModel in vm.items) { GarmentBeacukaiItem item = model.Items.FirstOrDefault(s => s.Id.Equals(itemViewModel.Id)); if (itemViewModel.selected == true) { EntityExtension.FlagForUpdate(item, user, USER_AGENT); } else { EntityExtension.FlagForDelete(item, user, USER_AGENT); GarmentDeliveryOrder deleteDO = dbContext.GarmentDeliveryOrders.FirstOrDefault(s => s.Id == itemViewModel.deliveryOrder.Id); deleteDO.BillNo = null; deleteDO.PaymentBill = null; deleteDO.CustomsId = 0; } } this.dbSet.Update(model); 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, GarmentBeacukaiViewModel vm, GarmentBeacukai model, string user, int clientTimeZoneOffset = 7) { int Updated = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { GarmentBeacukai modelBC = dbSet.AsNoTracking().Include(a => a.Items).FirstOrDefault(s => s.Id == model.Id); EntityExtension.FlagForUpdate(model, user, USER_AGENT); var lastPaymentBill = GeneratePaymentBillNo(); foreach (GarmentBeacukaiItem item in model.Items) { GarmentBeacukaiItem oldItem = modelBC.Items.FirstOrDefault(s => s.Id.Equals(item.Id)); GarmentBeacukaiItemViewModel itemVM = vm.items.FirstOrDefault(s => s.deliveryOrder.Id.Equals(item.GarmentDOId)); if (itemVM.selected) { if (oldItem == null) { GarmentDeliveryOrder deliveryOrder = dbSetDeliveryOrder.Include(m => m.Items) .ThenInclude(i => i.Details).FirstOrDefault(s => s.Id == item.GarmentDOId); if (deliveryOrder != null) { var deliveryOrderEPOIds = deliveryOrder.Items.Select(s => s.EPOId); var garmentExternalOrder = dbContext.GarmentExternalPurchaseOrders.Where(s => deliveryOrderEPOIds.Contains(s.Id)); if (model.BillNo == "" | model.BillNo == null) { deliveryOrder.BillNo = GenerateBillNo(); } else { deliveryOrder.BillNo = model.BillNo; } deliveryOrder.PaymentBill = string.Concat(lastPaymentBill.format, (lastPaymentBill.counterId++).ToString("D3")); //deliveryOrder.CustomsId = model.Id; double qty = 0; foreach (var deliveryOrderItem in deliveryOrder.Items) { foreach (var detail in deliveryOrderItem.Details) { qty += detail.DOQuantity; } } item.TotalAmount = Convert.ToDecimal(deliveryOrder.TotalAmount); item.TotalQty = qty; EntityExtension.FlagForCreate(item, user, USER_AGENT); deliveryOrder.CustomsId = model.Id; var dppAmount = 0.0; var currencyDPPAmount = 0.0; if (deliveryOrder.DOCurrencyCode == "IDR") { dppAmount = deliveryOrder.TotalAmount; } else { currencyDPPAmount = deliveryOrder.TotalAmount; dppAmount = deliveryOrder.TotalAmount * deliveryOrder.DOCurrencyRate.GetValueOrDefault(); } var categories = string.Join(',', garmentExternalOrder.Select(s => s.Category).ToList().GroupBy(s => s).Select(s => s.Key)); var paymentMethod = garmentExternalOrder.FirstOrDefault().PaymentType; var productNames = string.Join(", ", deliveryOrder.Items.SelectMany(doItem => doItem.Details).Select(doDetail => doDetail.ProductName).ToList()); await _garmentDebtBalanceService.CreateFromCustoms(new CustomsFormDto(0, string.Join("\n", categories), deliveryOrder.BillNo, deliveryOrder.PaymentBill, (int)deliveryOrder.Id, deliveryOrder.DONo, (int)model.SupplierId, model.SupplierCode, model.SupplierName, deliveryOrder.SupplierIsImport, (int)deliveryOrder.DOCurrencyId.GetValueOrDefault(), deliveryOrder.DOCurrencyCode, deliveryOrder.DOCurrencyRate.GetValueOrDefault(), productNames, deliveryOrder.ArrivalDate, dppAmount, currencyDPPAmount, paymentMethod)); } } else if (oldItem != null) { item.TotalAmount = oldItem.TotalAmount; item.TotalQty = oldItem.TotalQty; EntityExtension.FlagForUpdate(item, user, USER_AGENT); } } else { EntityExtension.FlagForDelete(item, user, USER_AGENT); GarmentDeliveryOrder deleteDO = dbContext.GarmentDeliveryOrders.FirstOrDefault(s => s.Id == item.GarmentDOId); deleteDO.BillNo = null; deleteDO.PaymentBill = null; deleteDO.CustomsId = 0; await _garmentDebtBalanceService.RemoveCustoms((int)deleteDO.Id); } } this.dbSet.Update(model); 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 <int> Update(int id, GarmentBeacukaiViewModel vm, GarmentBeacukai model, string user, int clientTimeZoneOffset = 7) { int Updated = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { GarmentBeacukai modelBC = dbSet.AsNoTracking().Include(a => a.Items).FirstOrDefault(s => s.Id == model.Id); EntityExtension.FlagForUpdate(model, user, USER_AGENT); var lastPaymentBill = GeneratePaymentBillNo(); foreach (GarmentBeacukaiItem item in model.Items) { GarmentBeacukaiItem oldItem = modelBC.Items.FirstOrDefault(s => s.Id.Equals(item.Id)); GarmentBeacukaiItemViewModel itemVM = vm.items.FirstOrDefault(s => s.deliveryOrder.Id.Equals(item.GarmentDOId)); if (itemVM.selected) { if (oldItem == null) { GarmentDeliveryOrder deliveryOrder = dbSetDeliveryOrder.Include(m => m.Items) .ThenInclude(i => i.Details).FirstOrDefault(s => s.Id == item.GarmentDOId); if (deliveryOrder != null) { if (model.BillNo == "" | model.BillNo == null) { deliveryOrder.BillNo = GenerateBillNo(); } else { deliveryOrder.BillNo = model.BillNo; } deliveryOrder.PaymentBill = string.Concat(lastPaymentBill.format, (lastPaymentBill.counterId++).ToString("D3")); //deliveryOrder.CustomsId = model.Id; double qty = 0; foreach (var deliveryOrderItem in deliveryOrder.Items) { foreach (var detail in deliveryOrderItem.Details) { qty += detail.DOQuantity; } } item.TotalAmount = Convert.ToDecimal(deliveryOrder.TotalAmount); item.TotalQty = qty; EntityExtension.FlagForCreate(item, user, USER_AGENT); deliveryOrder.CustomsId = model.Id; } } else if (oldItem != null) { item.TotalAmount = oldItem.TotalAmount; item.TotalQty = oldItem.TotalQty; EntityExtension.FlagForUpdate(item, user, USER_AGENT); } } else { EntityExtension.FlagForDelete(item, user, USER_AGENT); GarmentDeliveryOrder deleteDO = dbContext.GarmentDeliveryOrders.FirstOrDefault(s => s.Id == item.GarmentDOId); deleteDO.BillNo = null; deleteDO.PaymentBill = null; deleteDO.CustomsId = 0; } } this.dbSet.Update(model); Updated = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Updated); }