public async Task <IActionResult> UpdateEntry([FromBody] JournalEntryDto entryDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new CreateEntryResponseDto
                {
                    Errors = ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage))
                }));
            }

            var updatedEntry = _mapper.Map <JournalEntry>(entryDto);
            await _entryService.UpdateEntry(updatedEntry);

            return(StatusCode(200));
        }
        void IJournalEntryProvider.UpdateJournalEntry(JournalEntryDto journalEntry)
        {
            const string sql = @"
				UPDATE journal_entry SET
					tx_date = @date,
					currency = @currency,
					doc_number = @documentNumber,
					private_note = @privateNote
				WHERE tenant = @tenant 
					AND tx_num = @num;
			"            ;

            m_dataRepository.Execute(
                sql,
                journalEntry
                );
        }
        int IJournalEntryProvider.InsertJournalEntry(JournalEntryDto journalEntry)
        {
            const string sql = @"
				SET @newId := (SELECT coalesce(MAX(tx_num), 0) + 1 FROM journal_entry WHERE tenant = @tenant);

				INSERT INTO journal_entry (tenant, tx_date, tx_num, currency, doc_number, private_note)
				VALUES (@tenant, @date, @newId, @currency, @documentNumber, @privateNote);

				SELECT @newId;
			"            ;
            var          res = m_dataRepository.ExecuteScalar <int>(
                sql,
                journalEntry
                );

            return(res);
        }
        public void CreateUpdateDelete_Pass()
        {
            string documentNumber  = $"test{Guid.NewGuid().ToString().Substring( 12 )}";
            string documentNumber2 = $"{documentNumber}2";
            var    date            = new DateTime(2019, 05, 11);

            //Create
            var dtoToInsert = new JournalEntryDto(m_tenantId, date, 0, "USD", documentNumber, $"{documentNumber} notes.");
            int num         = m_sut.InsertJournalEntry(dtoToInsert);

            Assert.True(num > 0, "failed on InsertJournalEntry");

            //Get
            JournalEntryDto journalEntry = m_sut.GetJournalEntry(m_tenantId, num);

            Assert.NotNull(journalEntry);
            Assert.Equal(m_tenantId, journalEntry.Tenant);
            Assert.Equal(date, journalEntry.Date);
            Assert.Equal("USD", journalEntry.Currency);
            Assert.Equal(documentNumber, journalEntry.DocumentNumber);
            Assert.Equal($"{documentNumber} notes.", journalEntry.PrivateNote);

            try {
                //Update
                var dtoToUpdate = new JournalEntryDto(m_tenantId, date, num, "EUR", documentNumber2, $"{documentNumber2} notes.");
                m_sut.UpdateJournalEntry(dtoToUpdate);
                JournalEntryDto updatedJournalEntry = m_sut.GetJournalEntry(m_tenantId, num);
                Assert.NotNull(updatedJournalEntry);
                Assert.Equal(m_tenantId, updatedJournalEntry.Tenant);
                Assert.Equal(date, updatedJournalEntry.Date);
                Assert.Equal("EUR", updatedJournalEntry.Currency);
                Assert.Equal(documentNumber2, updatedJournalEntry.DocumentNumber);
                Assert.Equal($"{documentNumber2} notes.", updatedJournalEntry.PrivateNote);
            }
            finally {
                //Cleanup
                m_sut.DeleteJournalEntry(m_tenantId, num);
                journalEntry = m_sut.GetJournalEntry(m_tenantId, num);
                Assert.Null(journalEntry);
            }
        }
        JournalEntryDto IJournalEntryProvider.GetJournalEntry(int tenant, int num)
        {
            const string    sql          = @"
				SELECT 
					tenant,
					tx_date as date,
					tx_num as num,
					currency,
					doc_number as documentNumber,
					private_note as privateNote
				FROM journal_entry
				WHERE tenant = @tenant 
					AND tx_num = @num;
			"            ;
            JournalEntryDto journalEntry = m_dataRepository.Query <JournalEntryDto>(
                sql,
                new {
                tenant,
                num
            }
                ).FirstOrDefault();

            return(journalEntry);
        }
        public JsonResult SaveEntry(Guid userId, JournalEntryDto data)
        {
            var newEntry = JournalMan.SaveJournalEntry(data, userId);

            return(Json(newEntry));
        }
示例#7
0
        public async Task <IActionResult> Get(int includePosted = 1)
        {
            var journalEntries = await _repo.GetJournalEntries();

            var journalEntryDtosList = new List <JournalEntryHeaderDto>();

            //mapping from db entity to Dto
            foreach (var je in journalEntries)
            {
                var journalEntryDto = new JournalEntryHeaderDto()
                {
                    Id          = je.Id,
                    Date        = je.Date,
                    Memo        = je.Memo,
                    ReferenceNo = je.ReferenceNo,
                    Posted      = je.Posted
                };

                foreach (var line in je.JournalEntryLines)
                {
                    var lineDto = new JournalEntryLineDto
                    {
                        Id        = line.Id,
                        AccountId = line.AccountId,
                        Amount    = line.Amount,
                        DrCrId    = (int)line.DrCr,
                        Memo      = line.Memo
                    };

                    journalEntryDto.Lines.Add(lineDto);
                }

                // is this journal entry ready for posting?
                if (!journalEntryDto.Posted &&
                    journalEntryDto.Lines.Count >= 2 &&
                    (journalEntryDto.DebitAmount == journalEntryDto.CreditAmount) &&
                    (journalEntryDto.DebitAmount != 0))
                {
                    journalEntryDto.ReadyForPosting = true;
                }

                journalEntryDtosList.Add(journalEntryDto);
            }

            //now prepare a simple model for grid

            var entries = new List <JournalEntryDto>();

            foreach (var item in journalEntryDtosList)
            {
                var entry = new JournalEntryDto
                {
                    Id              = item.Id,
                    Date            = item.Date,
                    Debit           = item.DebitAmount,
                    Credit          = item.CreditAmount,
                    ReferenceNo     = item.ReferenceNo,
                    Memo            = item.Memo,
                    Posted          = item.Posted,
                    ReadyForPosting = item.ReadyForPosting
                };

                entries.Add(entry);
            }

            return(Ok(entries));
        }