public void Should_Success_Get_Data_PaymentOrderMemoLoader()
        {
            var dbContext = _dbContext(GetCurrentMethod());
            var facade    = new PurchasingDispositionFacade(ServiceProvider, dbContext);

            var bankExpenditureNote = new BankExpenditureNoteModel()
            {
                Id = 1, SupplierImport = false, CurrencyCode = "IDR"
            };
            var bankExpenditureNoteDetail = new BankExpenditureNoteDetailModel()
            {
                Id = 1, BankExpenditureNoteId = 1, UnitPaymentOrderNo = "Test"
            };
            var unitPaymentOrder = new UnitPaymentOrder()
            {
                Id = 1, UPONo = "Test", CurrencyCode = "IDR", DivisionId = "1", UseVat = true, UseIncomeTax = true
            };

            dbContext.BankExpenditureNotes.Add(bankExpenditureNote);
            dbContext.BankExpenditureNoteDetails.Add(bankExpenditureNoteDetail);
            dbContext.UnitPaymentOrders.Add(unitPaymentOrder);
            dbContext.SaveChanges();

            var Response  = facade.GetUnitPaymentOrderMemoLoader("Test", 1, false, "IDR");
            var Response2 = facade.GetUnitPaymentOrderMemoLoader("", 1, false, "");

            Assert.NotNull(Response);
            Assert.NotNull(Response2);
        }
Esempio n. 2
0
        public async void Should_Success_Update_Data()
        {
            var numberGeneratorMock          = new Mock <IBankDocumentNumberGenerator>();
            BankExpenditureNoteFacade facade = new BankExpenditureNoteFacade(_dbContext(GetCurrentMethod()), numberGeneratorMock.Object);
            BankExpenditureNoteModel  model  = await _dataUtil(facade, GetCurrentMethod()).GetTestData();

            BankExpenditureNoteDetailModel modelDetail = _dataUtil(facade, GetCurrentMethod()).GetNewDetailData();

            model.Details.Clear();
            model.Details.Add(modelDetail);
            var Response = await facade.Update((int)model.Id, model, "Unit Test");

            Assert.NotEqual(Response, 0);
        }
        public async Task Should_Success_Update_Data()
        {
            var numberGeneratorMock          = new Mock <IBankDocumentNumberGenerator>();
            BankExpenditureNoteFacade facade = new BankExpenditureNoteFacade(_dbContext(GetCurrentMethod()), numberGeneratorMock.Object, GetServiceProviderMock().Object);
            BankExpenditureNoteModel  model  = await _dataUtil(facade, GetCurrentMethod()).GetTestData();

            IdentityService identityService = new IdentityService()
            {
                Token = "Token",

                Username = "******"
            };
            BankExpenditureNoteDetailModel modelDetail = _dataUtil(facade, GetCurrentMethod()).GetNewDetailData();

            model.Details.Clear();
            model.Details.Add(modelDetail);
            var Response = await facade.Update((int)model.Id, model, identityService);

            Assert.NotEqual(Response, 0);
        }
Esempio n. 4
0
        public async Task <int> Update(int id, BankExpenditureNoteModel model, IdentityService identityService)
        {
            int    Updated  = 0;
            string username = identityService.Username;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    EntityExtension.FlagForUpdate(model, username, USER_AGENT);
                    dbContext.Entry(model).Property(x => x.GrandTotal).IsModified        = true;
                    dbContext.Entry(model).Property(x => x.LastModifiedAgent).IsModified = true;
                    dbContext.Entry(model).Property(x => x.LastModifiedBy).IsModified    = true;
                    dbContext.Entry(model).Property(x => x.LastModifiedUtc).IsModified   = true;

                    foreach (var detail in model.Details)
                    {
                        if (detail.Id == 0)
                        {
                            EntityExtension.FlagForCreate(detail, username, USER_AGENT);
                            dbContext.BankExpenditureNoteDetails.Add(detail);

                            PurchasingDocumentExpedition pde = new PurchasingDocumentExpedition
                            {
                                Id     = (int)detail.UnitPaymentOrderId,
                                IsPaid = true,
                                BankExpenditureNoteNo   = model.DocumentNo,
                                BankExpenditureNoteDate = model.Date
                            };

                            EntityExtension.FlagForUpdate(pde, username, USER_AGENT);
                            //dbContext.Attach(pde);
                            dbContext.Entry(pde).Property(x => x.IsPaid).IsModified = true;
                            dbContext.Entry(pde).Property(x => x.BankExpenditureNoteNo).IsModified   = true;
                            dbContext.Entry(pde).Property(x => x.BankExpenditureNoteDate).IsModified = true;
                            dbContext.Entry(pde).Property(x => x.LastModifiedAgent).IsModified       = true;
                            dbContext.Entry(pde).Property(x => x.LastModifiedBy).IsModified          = true;
                            dbContext.Entry(pde).Property(x => x.LastModifiedUtc).IsModified         = true;

                            foreach (var item in detail.Items)
                            {
                                EntityExtension.FlagForCreate(item, username, USER_AGENT);
                            }
                        }
                    }

                    foreach (var detail in dbContext.BankExpenditureNoteDetails.AsNoTracking().Where(p => p.BankExpenditureNoteId == model.Id))
                    {
                        BankExpenditureNoteDetailModel detailModel = model.Details.FirstOrDefault(prop => prop.Id.Equals(detail.Id));

                        if (detailModel == null)
                        {
                            EntityExtension.FlagForDelete(detail, username, USER_AGENT);

                            foreach (var item in dbContext.BankExpenditureNoteItems.AsNoTracking().Where(p => p.BankExpenditureNoteDetailId == detail.Id))
                            {
                                EntityExtension.FlagForDelete(item, username, USER_AGENT);
                                dbContext.BankExpenditureNoteItems.Update(item);
                            }

                            dbContext.BankExpenditureNoteDetails.Update(detail);

                            PurchasingDocumentExpedition pde = new PurchasingDocumentExpedition
                            {
                                Id     = (int)detail.UnitPaymentOrderId,
                                IsPaid = false,
                                BankExpenditureNoteNo   = null,
                                BankExpenditureNoteDate = null
                            };

                            EntityExtension.FlagForUpdate(pde, username, USER_AGENT);
                            //dbContext.Attach(pde);
                            dbContext.Entry(pde).Property(x => x.IsPaid).IsModified = true;
                            dbContext.Entry(pde).Property(x => x.BankExpenditureNoteNo).IsModified   = true;
                            dbContext.Entry(pde).Property(x => x.BankExpenditureNoteDate).IsModified = true;
                            dbContext.Entry(pde).Property(x => x.LastModifiedAgent).IsModified       = true;
                            dbContext.Entry(pde).Property(x => x.LastModifiedBy).IsModified          = true;
                            dbContext.Entry(pde).Property(x => x.LastModifiedUtc).IsModified         = true;
                        }
                    }

                    Updated = await dbContext.SaveChangesAsync();

                    DeleteDailyBankTransaction(model.DocumentNo, identityService);
                    CreateDailyBankTransaction(model, identityService);
                    UpdateCreditorAccount(model, identityService);
                    ReverseJournalTransaction(model);
                    CreateJournalTransaction(model, identityService);
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Updated);
        }