public async Task Should_Success_Update_Created_Data() { var serviceProviderMock = GetServiceProvider(); var dbContext = GetDbContext(GetCurrentMethod()); var service = new GarmentInvoicePurchasingDispositionService(serviceProviderMock.Object, dbContext); var expedition = new GarmentDispositionExpeditionModel(); EntityExtension.FlagForCreate(expedition, "Test", "Test"); dbContext.GarmentDispositionExpeditions.Add(expedition); dbContext.SaveChanges(); var model = new GarmentInvoicePurchasingDispositionModel() { InvoiceNo = "Test", SupplierName = "Test", CurrencyCode = "Code", BankName = "BankName", Items = new List <GarmentInvoicePurchasingDispositionItemModel>() { new GarmentInvoicePurchasingDispositionItemModel(0, expedition.Id, "Test") } }; await service.CreateAsync(model); var result = await service.UpdateAsync(model.Id, model); Assert.NotEqual(0, result); }
public void CreateModel(GarmentInvoicePurchasingDispositionModel model) { EntityExtension.FlagForCreate(model, IdentityService.Username, UserAgent); //get last Paid var dispositionIds = model.Items.Select(s => s.DispositionId).ToList(); //var getLastDiposition = DbContext.GarmentInvoicePurchasingDispositions.Where(s => dispositionIds.Contains(s.DispositionNoteId)); foreach (var item in model.Items) { GarmentDispositionExpeditionModel expedition = DbContext.GarmentDispositionExpeditions.FirstOrDefault(ex => ex.Id.Equals(item.PurchasingDispositionExpeditionId)); //var getLastDipositionPaidAmount = getLastDiposition.Where(s=> s.DispositionNoteId == expedition.DispositionNoteId) EntityExtension.FlagForCreate(item, IdentityService.Username, UserAgent); if (item.TotalPaidBefore + item.TotalPaid >= item.TotalAmount) { expedition.IsPaid = true; } else { expedition.IsPaid = false; } expedition.BankExpenditureNoteNo = model.InvoiceNo; expedition.BankExpenditureNoteDate = model.InvoiceDate; } DbSet.Add(model); }
public Task <int> AutoCreateFromGarmentInvoicePurchasingDisposition(GarmentInvoicePurchasingDispositionModel model) { var nominal = model.Items.Sum(item => (decimal)item.TotalPaid * (decimal)model.CurrencyRate); var dailyBankTransactionModel = new DailyBankTransactionModel() { AccountBankAccountName = model.BankAccountName, AccountBankAccountNumber = model.BankAccountNo, AccountBankCode = model.BankCode, AccountBankCurrencyCode = model.CurrencyCode, AccountBankCurrencyId = model.CurrencyId, AccountBankCurrencySymbol = model.CurrencySymbol, AccountBankId = model.BankId, AccountBankName = model.BankName, Date = model.InvoiceDate, Nominal = nominal, CurrencyRate = (decimal)model.CurrencyRate, ReferenceNo = model.InvoiceNo, ReferenceType = "Bukti Pembayaran Disposisi Job Garment", Remark = model.CurrencyCode != "IDR" ? $"Pembayaran atas {model.BankCurrencyCode} dengan nominal {string.Format("{0:n}", nominal)} dan kurs {model.CurrencyCode}" : "", SourceType = model.PaymentType, SupplierCode = model.SupplierCode, SupplierId = model.SupplierId, SupplierName = model.SupplierName, Status = "OUT", IsPosted = true }; if (model.BankCurrencyCode != "IDR") { dailyBankTransactionModel.Nominal = model.Items.Sum(item => (decimal)item.TotalPaid); dailyBankTransactionModel.NominalValas = nominal; } return(_dailyBankTransactionService.CreateAsync(dailyBankTransactionModel)); }
public async Task <ActionResult> Post([FromBody] GarmentInvoicePurchasingDispositionViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); GarmentInvoicePurchasingDispositionModel model = Mapper.Map <GarmentInvoicePurchasingDispositionModel>(viewModel); //model.FixFailAutoMapper(viewModel.AccountBank.BankCode); await Service.CreateAsync(model); Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE) .Ok(); return(Created(String.Concat(Request.Path, "/", 0), Result)); } catch (ServiceValidationException e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] GarmentInvoicePurchasingDispositionViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); GarmentInvoicePurchasingDispositionModel model = Mapper.Map <GarmentInvoicePurchasingDispositionModel>(viewModel); await Service.UpdateAsync(id, model); return(NoContent()); } catch (ServiceValidationException e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public async Task <int> UpdateAsync(int id, GarmentInvoicePurchasingDispositionModel model) { var existingModel = DbSet .Include(d => d.Items) .Single(dispo => dispo.Id == id && !dispo.IsDeleted); UpdateModel(id, model); return(await DbContext.SaveChangesAsync()); }
public async Task <int> CreateAsync(GarmentInvoicePurchasingDispositionModel model) { model.InvoiceNo = await GetDocumentNo("K", model.BankCode, IdentityService.Username, model.InvoiceDate); //if (model.CurrencyCode != "IDR") //{ //var garmentCurrency = await GetGarmentCurrency(model.CurrencyCode); //model.CurrencyRate = garmentCurrency.Rate.GetValueOrDefault(); model.CurrencyRate = model.CurrencyRate; //} CreateModel(model); //await _autoDailyBankTransactionService.AutoCreateFromPaymentDisposition(model); return(await DbContext.SaveChangesAsync()); }
//private async Task<GarmentCurrency> GetGarmentCurrency(string codeCurrency) //{ // var date = DateTimeOffset.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); // var queryString = $"code={codeCurrency}&stringDate={date}"; // var http = ServiceProvider.GetService<IHttpClientService>(); // var response = await http.GetAsync(APIEndpoint.Core + $"master/garment-currencies/single-by-code-date?{queryString}"); // var responseString = await response.Content.ReadAsStringAsync(); // var jsonSerializationSetting = new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Ignore }; // var result = JsonConvert.DeserializeObject<APIDefaultResponse<GarmentCurrency>>(responseString, jsonSerializationSetting); // return result.data; //} public async Task DeleteModel(int id) { GarmentInvoicePurchasingDispositionModel model = await ReadByIdAsync(id); foreach (var item in model.Items) { GarmentDispositionExpeditionModel expedition = DbContext.GarmentDispositionExpeditions.FirstOrDefault(ex => ex.Id.Equals(item.PurchasingDispositionExpeditionId)); EntityExtension.FlagForDelete(item, IdentityService.Username, UserAgent, true); expedition.IsPaid = false; expedition.BankExpenditureNoteNo = null; expedition.BankExpenditureNoteDate = DateTimeOffset.MinValue; } EntityExtension.FlagForDelete(model, IdentityService.Username, UserAgent, true); DbSet.Update(model); }
public void UpdateModel(int id, GarmentInvoicePurchasingDispositionModel model) { GarmentInvoicePurchasingDispositionModel exist = DbSet .Include(d => d.Items) .Single(dispo => dispo.Id == id && !dispo.IsDeleted); exist.ChequeNo = model.ChequeNo; exist.InvoiceDate = model.InvoiceDate; foreach (var item in exist.Items) { GarmentInvoicePurchasingDispositionItemModel itemModel = model.Items.FirstOrDefault(prop => prop.Id.Equals(item.Id)); if (itemModel == null) { GarmentDispositionExpeditionModel expedition = DbContext.GarmentDispositionExpeditions.FirstOrDefault(ex => ex.Id.Equals(item.PurchasingDispositionExpeditionId)); expedition.IsPaid = false; expedition.BankExpenditureNoteNo = null; expedition.BankExpenditureNoteDate = DateTimeOffset.MinValue; EntityExtension.FlagForDelete(item, IdentityService.Username, UserAgent, true); } else { item.SetTotalPaid(itemModel.TotalPaid); GarmentDispositionExpeditionModel expedition = DbContext.GarmentDispositionExpeditions.FirstOrDefault(ex => ex.Id.Equals(item.PurchasingDispositionExpeditionId)); if (itemModel.TotalPaidBefore + itemModel.TotalPaid >= itemModel.TotalAmount) { expedition.IsPaid = true; } else { expedition.IsPaid = false; } EntityExtension.FlagForUpdate(item, IdentityService.Username, UserAgent); } } EntityExtension.FlagForUpdate(exist, IdentityService.Username, UserAgent); //DbSet.Update(exist); }
public void Should_Success_getLoader() { var serviceProviderMock = GetServiceProvider(); var dbContext = GetDbContext(GetCurrentMethod()); var service = new GarmentInvoicePurchasingDispositionService(serviceProviderMock.Object, dbContext); var model = new GarmentInvoicePurchasingDispositionModel() { InvoiceDate = DateTimeOffset.Now, InvoiceNo = "Test", SupplierName = "Test", CurrencyCode = "Code", BankName = "BankName", Items = new List <GarmentInvoicePurchasingDispositionItemModel>() { new GarmentInvoicePurchasingDispositionItemModel(0, 1, "Test") } }; EntityExtension.FlagForCreate(model, "Test", "Test"); dbContext.GarmentInvoicePurchasingDispositions.Add(model); dbContext.SaveChanges(); }
public void Should_Success_getMonitoringNullDate() { var serviceProviderMock = GetServiceProvider(); var dbContext = GetDbContext(GetCurrentMethod()); var service = new GarmentInvoicePurchasingDispositionService(serviceProviderMock.Object, dbContext); var model = new GarmentInvoicePurchasingDispositionModel() { InvoiceDate = DateTimeOffset.Now, InvoiceNo = "Test", SupplierName = "Test", CurrencyCode = "Code", BankName = "BankName", Items = new List <GarmentInvoicePurchasingDispositionItemModel>() { new GarmentInvoicePurchasingDispositionItemModel(0, 1, "Test") } }; var model1 = new GarmentInvoicePurchasingDispositionModel() { InvoiceDate = DateTimeOffset.Now, InvoiceNo = "Test", SupplierName = "Test", CurrencyCode = "Code", BankName = "BankName", Items = new List <GarmentInvoicePurchasingDispositionItemModel>() { new GarmentInvoicePurchasingDispositionItemModel(0, 1, "Test") } }; var model2 = new GarmentInvoicePurchasingDispositionModel() { InvoiceDate = DateTimeOffset.Now, InvoiceNo = "Test", SupplierName = "Test", CurrencyCode = "Code", BankName = "BankName", Items = new List <GarmentInvoicePurchasingDispositionItemModel>() { new GarmentInvoicePurchasingDispositionItemModel(0, 1, "Test1") } }; EntityExtension.FlagForCreate(model, "Test", "Test"); dbContext.GarmentInvoicePurchasingDispositions.Add(model); EntityExtension.FlagForCreate(model1, "Test", "Test"); dbContext.GarmentInvoicePurchasingDispositions.Add(model1); EntityExtension.FlagForCreate(model2, "Test", "Test"); dbContext.GarmentInvoicePurchasingDispositions.Add(model2); dbContext.SaveChanges(); var result = service.GetMonitoring(null, null, Convert.ToDateTime("0001-01-01 00:00:00.0000000 +00:00"), Convert.ToDateTime("0001-01-01 00:00:00.0000000 +00:00"), 7); Assert.NotNull(result); }
public async Task <int> AutoRevertFromGarmentInvoicePurchasingDisposition(GarmentInvoicePurchasingDispositionModel model) { await Task.Delay(1000); return(await Task.FromResult(1)); }
public Task <int> AutoRevertFromGarmentInvoicePurchasingDisposition(GarmentInvoicePurchasingDispositionModel model) { return(_dailyBankTransactionService.DeleteByReferenceNoAsync(model.InvoiceNo)); }