public async Task <GarmentFinanceMemorialDetailLocalModel> GetTestData()
        {
            GarmentFinanceMemorialDetailLocalModel model = GetNewData();
            await Service.CreateAsync(model);

            return(await Service.ReadByIdAsync(model.Id));
        }
        public async Task <ActionResult> Post([FromBody] GarmentFinanceMemorialDetailLocalViewModel viewModel)
        {
            try
            {
                VerifyUser();

                ValidateService.Validate(viewModel);
                GarmentFinanceMemorialDetailLocalModel model = Mapper.Map <GarmentFinanceMemorialDetailLocalModel>(viewModel);
                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] GarmentFinanceMemorialDetailLocalViewModel viewModel)
        {
            try
            {
                VerifyUser();

                ValidateService.Validate(viewModel);
                GarmentFinanceMemorialDetailLocalModel model = Mapper.Map <GarmentFinanceMemorialDetailLocalModel>(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));
            }
        }
Beispiel #4
0
        public async Task Should_Success_Create_Data()
        {
            GarmentFinanceMemorialDetailLocalService service = new GarmentFinanceMemorialDetailLocalService(GetServiceProvider().Object, _dbContext(GetCurrentAsyncMethod()));
            GarmentFinanceMemorialDetailLocalModel   model   = _dataUtil(service, GetCurrentAsyncMethod()).GetNewData();
            var Response = await service.CreateAsync(model);

            Assert.NotEqual(0, Response);
        }
Beispiel #5
0
        public async Task Should_Success_Get_Data_By_Id()
        {
            GarmentFinanceMemorialDetailLocalService service = new GarmentFinanceMemorialDetailLocalService(GetServiceProvider().Object, _dbContext(GetCurrentAsyncMethod()));
            GarmentFinanceMemorialDetailLocalModel   model   = await _dataUtil(service, GetCurrentAsyncMethod()).GetTestData();

            var Response = await service.ReadByIdAsync(model.Id);

            Assert.NotNull(Response);
        }
        public async Task Should_Error_Get_Local_Sales_Data()
        {
            var serviceProviderMock = GetServiceProvider();

            var dbContext = GetDbContext(GetCurrentAsyncMethod());

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(FinanceDbContext)))
            .Returns(dbContext);

            var serviceProvider1 = new Mock <IServiceProvider>();

            var httpClientService = new Mock <IHttpClientService>();

            serviceProviderMock
            .Setup(x => x.GetService(typeof(IIdentityService)))
            .Returns(new IdentityService()
            {
                Token = "Token", Username = "******", TimezoneOffset = 7
            });

            HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError);

            message.Content = new StringContent("{\"data\":[{\"salesContractNo\":null,\"localSalesContractId\":0,\"noteNo\":\"21/LBJ/00003\",\"date\":\"2021-08-31T17:00:00+00:00\",\"transactionType\":null,\"buyer\":{\"id\":63,\"code\":\"IJA\",\"name\":\"PT INDORENZA JAYA ABADI\",\"address\":null,\"npwp\":null,\"country\":null,\"nik\":null,\"kaberType\":null},\"tempo\":0,\"expenditureNo\":null,\"dispositionNo\":null,\"useVat\":false,\"remark\":null,\"isUsed\":false,\"paymentType\":null,\"amount\":55000000.0,\"items\":null,\"id\":29,\"active\":false,\"createdUtc\":\"0001 - 01 - 01T00: 00:00\",\"createdBy\":null,\"createdAgent\":null,\"lastModifiedUtc\":\"0001 - 01 - 01T00: 00:00\",\"lastModifiedBy\":null,\"lastModifiedAgent\":null,\"isDeleted\":false,\"deletedUtc\":\"0001 - 01 - 01T00: 00:00\",\"deletedBy\":null,\"deletedAgent\":null},]}");

            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("garment-shipping/local-sales-notes/localSalesDebtor"))))
            .ReturnsAsync(message);

            serviceProvider1
            .Setup(x => x.GetService(typeof(IHttpClientService)))
            .Returns(new HttpClientTestService());


            serviceProvider1
            .Setup(x => x.GetService(typeof(IIdentityService)))
            .Returns(new IdentityService()
            {
                Token = "Token", Username = "******", TimezoneOffset = 7
            });

            serviceProvider1
            .Setup(x => x.GetService(typeof(IHttpClientService)))
            .Returns(httpClientService.Object);

            GarmentFinanceMemorialDetailLocalService serviceMemo = new GarmentFinanceMemorialDetailLocalService(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            GarmentFinanceMemorialDetailLocalModel   modelMemo   = _dataUtilMemo(serviceMemo, GetCurrentMethod()).GetNewData();

            GarmentFinanceBankCashReceiptDetailLocalService serviceBankCash        = new GarmentFinanceBankCashReceiptDetailLocalService(serviceProviderMock.Object);
            GarmentFinanceBankCashReceiptDetailLocalModel   cashReceiptDetailModel = await _dataUtilBankCash(serviceBankCash).GetTestData();

            LocalSalesDebtorReportService service = new LocalSalesDebtorReportService(serviceProvider1.Object, _dbContext(GetCurrentMethod()));

            var response = await service.GetMonitoring(DateTimeOffset.Now.Month, DateTimeOffset.Now.Year, 7);

            Assert.Empty(response);
        }
Beispiel #7
0
        public async Task <int> UpdateAsync(int id, GarmentFinanceMemorialDetailLocalModel model)
        {
            var exist = DbSet
                        .Include(d => d.Items)
                        .Include(d => d.OtherItems)
                        .Single(o => o.Id == id && !o.IsDeleted);

            foreach (var item in exist.Items)
            {
                GarmentFinanceMemorialDetailLocalItemModel itemModel = model.Items.FirstOrDefault(prop => prop.Id.Equals(item.Id));

                if (itemModel == null)
                {
                    EntityExtension.FlagForDelete(item, IdentityService.Username, UserAgent, true);
                }
                else
                {
                    item.Amount = itemModel.Amount;
                    EntityExtension.FlagForUpdate(item, IdentityService.Username, UserAgent);
                }
            }
            foreach (var newItem in model.Items)
            {
                if (newItem.Id <= 0)
                {
                    EntityExtension.FlagForCreate(newItem, IdentityService.Username, UserAgent);
                    exist.Items.Add(newItem);
                }
            }

            foreach (var otherItem in exist.OtherItems)
            {
                GarmentFinanceMemorialDetailLocalOtherItemModel otherItemModel = model.OtherItems.FirstOrDefault(prop => prop.Id.Equals(otherItem.Id));

                if (otherItemModel == null)
                {
                    EntityExtension.FlagForDelete(otherItem, IdentityService.Username, UserAgent, true);
                }
                else
                {
                    otherItem.Amount     = otherItemModel.Amount;
                    otherItem.TypeAmount = otherItemModel.TypeAmount;
                    EntityExtension.FlagForUpdate(otherItem, IdentityService.Username, UserAgent);
                }
            }
            foreach (var newOtherItem in model.OtherItems)
            {
                if (newOtherItem.Id <= 0)
                {
                    EntityExtension.FlagForCreate(newOtherItem, IdentityService.Username, UserAgent);
                    exist.OtherItems.Add(newOtherItem);
                }
            }
            EntityExtension.FlagForUpdate(exist, IdentityService.Username, UserAgent);
            return(await DbContext.SaveChangesAsync());
        }
Beispiel #8
0
 public async Task <int> CreateAsync(GarmentFinanceMemorialDetailLocalModel model)
 {
     EntityExtension.FlagForCreate(model, IdentityService.Username, UserAgent);
     foreach (var item in model.Items)
     {
         EntityExtension.FlagForCreate(item, IdentityService.Username, UserAgent);
     }
     foreach (var otherItem in model.OtherItems)
     {
         EntityExtension.FlagForCreate(otherItem, IdentityService.Username, UserAgent);
     }
     DbSet.Add(model);
     return(await DbContext.SaveChangesAsync());
 }
        public async Task Should_Success_Get_All_DataExcel()
        {
            var serviceProviderMock = GetServiceProvider();

            var dbContext = GetDbContext(GetCurrentAsyncMethod());

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(FinanceDbContext)))
            .Returns(dbContext);

            var serviceProvider1 = new Mock <IServiceProvider>();

            var httpClientService       = new Mock <IHttpClientService>();
            HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.OK);

            message.Content = new StringContent("{\"apiVersion\":\"1.0\",\"statusCode\":200,\"message\":\"Ok\",\"data\":[{\"SalesNoteNo\":\"no\",\"amount\":1,\"balanceAmount\":1,\"Date\":\"2018/10/20\",\"truckingDate\":\"2018/10/20\"}],\"info\":{\"count\":1,\"page\":1,\"size\":1,\"total\":2,\"order\":{\"date\":\"desc\"},\"select\":[\"Id\",\"CustomsType\",\"BeacukaiDate\",\"BeacukaiNo\",,\"POSerialNumber\"]}}");

            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("garment-shipping/local-sales-notes/finance-reports"))))
            .ReturnsAsync(message);

            serviceProvider1
            .Setup(x => x.GetService(typeof(IHttpClientService)))
            .Returns(new HttpClientTestService());


            serviceProvider1
            .Setup(x => x.GetService(typeof(IIdentityService)))
            .Returns(new IdentityService()
            {
                Token = "Token", Username = "******", TimezoneOffset = 7
            });

            serviceProvider1
            .Setup(x => x.GetService(typeof(IHttpClientService)))
            .Returns(httpClientService.Object);

            GarmentFinanceMemorialDetailLocalService serviceMemo = new GarmentFinanceMemorialDetailLocalService(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            GarmentFinanceMemorialDetailLocalModel   modelMemo   = await _dataUtilMemo(serviceMemo, GetCurrentMethod()).GetTestData();

            GarmentFinanceBankCashReceiptDetailLocalService serviceBankCash        = new GarmentFinanceBankCashReceiptDetailLocalService(serviceProviderMock.Object);
            GarmentFinanceBankCashReceiptDetailLocalModel   cashReceiptDetailModel = await _dataUtilBankCash(serviceBankCash, GetCurrentAsyncMethod()).GetTestData();

            GarmentFinanceLocalDebtorCardReportService service = new GarmentFinanceLocalDebtorCardReportService(serviceProvider1.Object, _dbContext(GetCurrentMethod()));


            var response = service.GenerateExcel(DateTimeOffset.Now.Month, DateTimeOffset.Now.Year, modelMemo.Items.First().BuyerCode, 7);

            Assert.NotNull(response);
        }
Beispiel #10
0
        public async Task <int> DeleteAsync(int id)
        {
            var existingModel = DbSet
                                .Include(d => d.Items)
                                .Include(d => d.OtherItems)
                                .Single(o => o.Id == id && !o.IsDeleted);

            GarmentFinanceMemorialDetailLocalModel model = await ReadByIdAsync(id);

            foreach (var item in model.Items)
            {
                EntityExtension.FlagForDelete(item, IdentityService.Username, UserAgent, true);
            }
            foreach (var otherItem in model.OtherItems)
            {
                EntityExtension.FlagForDelete(otherItem, IdentityService.Username, UserAgent, true);
            }
            EntityExtension.FlagForDelete(model, IdentityService.Username, UserAgent, true);
            DbSet.Update(model);
            return(await DbContext.SaveChangesAsync());
        }
Beispiel #11
0
        public async Task Should_Success_Update_Data()
        {
            GarmentFinanceMemorialDetailLocalService service = new GarmentFinanceMemorialDetailLocalService(GetServiceProvider().Object, _dbContext(GetCurrentAsyncMethod()));


            GarmentFinanceMemorialDetailLocalModel model = await _dataUtil(service, GetCurrentMethod()).GetTestData();

            var newModel = await service.ReadByIdAsync(model.Id);

            //newModel.BGCheckNumber = "newBG";
            var Response1 = await service.UpdateAsync(newModel.Id, newModel);

            Assert.NotEqual(0, Response1);

            GarmentFinanceMemorialDetailLocalModel model2 = await _dataUtil(service, GetCurrentMethod()).GetTestData();

            //var newModel2 = await service.ReadByIdAsync(model.Id);
            GarmentFinanceMemorialDetailLocalModel newModel2 = new GarmentFinanceMemorialDetailLocalModel();

            newModel2.Id = model2.Id;

            newModel2.Items = new List <GarmentFinanceMemorialDetailLocalItemModel> {
                model2.Items.First()
            };
            newModel2.OtherItems = new List <GarmentFinanceMemorialDetailLocalOtherItemModel> {
                model2.OtherItems.First()
            };
            var Response = await service.UpdateAsync(model2.Id, newModel2);

            Assert.NotEqual(0, Response);

            GarmentFinanceMemorialDetailLocalItemModel newItem = new GarmentFinanceMemorialDetailLocalItemModel
            {
                LocalSalesNoteId = 3,
                LocalSalesNoteNo = "no3",
                BuyerName        = "Name",
                BuyerCode        = "code",
                BuyerId          = 3,
                CurrencyId       = 1,
                CurrencyCode     = "code",
                CurrencyRate     = 1,
                Amount           = 1
            };


            newModel2.Items.Add(newItem);

            GarmentFinanceMemorialDetailLocalOtherItemModel newOtherItem = new GarmentFinanceMemorialDetailLocalOtherItemModel
            {
                ChartOfAccountId   = 1,
                ChartOfAccountName = "Name",
                ChartOfAccountCode = "code",
                CurrencyId         = 1,
                CurrencyCode       = "code",
                CurrencyRate       = 1,
                Amount             = 1,
                TypeAmount         = "DEBIT"
            };

            newModel2.OtherItems.Add(newOtherItem);
            var Response3 = await service.UpdateAsync(model2.Id, newModel2);

            Assert.NotEqual(0, Response);

            // delete item and other item
            GarmentFinanceMemorialDetailLocalModel newModel3 = new GarmentFinanceMemorialDetailLocalModel();

            newModel3.Id = model2.Id;

            newModel3.Items      = new List <GarmentFinanceMemorialDetailLocalItemModel>();
            newModel3.OtherItems = new List <GarmentFinanceMemorialDetailLocalOtherItemModel>();
            var Response4 = await service.UpdateAsync(model2.Id, newModel3);

            Assert.NotEqual(0, Response4);
        }
        public async Task Should_Success_Get_Empty_DataExcelSummary()
        {
            var serviceProviderMock = GetServiceProvider();

            var dbContext = GetDbContext(GetCurrentAsyncMethod());

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(FinanceDbContext)))
            .Returns(dbContext);

            var serviceProvider1 = new Mock <IServiceProvider>();

            var httpClientService = new Mock <IHttpClientService>();

            serviceProviderMock
            .Setup(x => x.GetService(typeof(IIdentityService)))
            .Returns(new IdentityService()
            {
                Token = "Token", Username = "******", TimezoneOffset = 7
            });

            HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.OK);

            message.Content = new StringContent("{\"data\":[]}");

            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("garment-shipping/local-sales-notes/localSalesDebtor"))))
            .ReturnsAsync(message);

            serviceProvider1
            .Setup(x => x.GetService(typeof(IHttpClientService)))
            .Returns(new HttpClientTestService());


            serviceProvider1
            .Setup(x => x.GetService(typeof(IIdentityService)))
            .Returns(new IdentityService()
            {
                Token = "Token", Username = "******", TimezoneOffset = 7
            });

            serviceProvider1
            .Setup(x => x.GetService(typeof(IHttpClientService)))
            .Returns(httpClientService.Object);

            GarmentFinanceMemorialDetailLocalService serviceMemo = new GarmentFinanceMemorialDetailLocalService(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            GarmentFinanceMemorialDetailLocalModel   modelMemo   = _dataUtilMemo(serviceMemo, GetCurrentMethod()).GetNewData();

            GarmentFinanceBankCashReceiptDetailLocalService serviceBankCash        = new GarmentFinanceBankCashReceiptDetailLocalService(serviceProviderMock.Object);
            GarmentFinanceBankCashReceiptDetailLocalModel   cashReceiptDetailModel = await _dataUtilBankCash(serviceBankCash).GetTestData();

            LocalSalesDebtorReportService service = new LocalSalesDebtorReportService(serviceProvider1.Object, _dbContext(GetCurrentMethod()));

            var response1 = service.GenerateExcelSummary(1, DateTimeOffset.Now.Year);

            Assert.NotNull(response1);

            var response2 = service.GenerateExcelSummary(2, DateTimeOffset.Now.Year);

            Assert.NotNull(response2);

            var response3 = service.GenerateExcelSummary(3, DateTimeOffset.Now.Year);

            Assert.NotNull(response3);

            var response4 = service.GenerateExcelSummary(4, DateTimeOffset.Now.Year);

            Assert.NotNull(response4);

            var response5 = service.GenerateExcelSummary(5, DateTimeOffset.Now.Year);

            Assert.NotNull(response5);

            var response6 = service.GenerateExcelSummary(6, DateTimeOffset.Now.Year);

            Assert.NotNull(response6);

            var response7 = service.GenerateExcelSummary(7, DateTimeOffset.Now.Year);

            Assert.NotNull(response7);

            var response8 = service.GenerateExcelSummary(8, DateTimeOffset.Now.Year);

            Assert.NotNull(response8);

            var response9 = service.GenerateExcelSummary(9, DateTimeOffset.Now.Year);

            Assert.NotNull(response9);

            var response10 = service.GenerateExcelSummary(10, DateTimeOffset.Now.Year);

            Assert.NotNull(response10);

            var response11 = service.GenerateExcelSummary(11, DateTimeOffset.Now.Year);

            Assert.NotNull(response11);

            var response12 = service.GenerateExcelSummary(12, DateTimeOffset.Now.Year);

            Assert.NotNull(response12);
        }