Exemple #1
0
        public async Task <IActionResult> Get(long id)
        {
            try
            {
                var result = await _repo.GetJournalEntryById(id);

                //Mapping FROM database entity to Dto
                var dto = new JournalEntryHeaderDto();
                dto.Id          = result.Id;
                dto.Date        = result.Date;
                dto.ReferenceNo = result.ReferenceNo;
                dto.Memo        = result.Memo;
                dto.Posted      = result.Posted;

                //lines
                foreach (var lineItem in result.JournalEntryLines)
                {
                    var line = new JournalEntryLineDto();
                    line.AccountId = lineItem.AccountId;
                    line.DrCrId    = (int)lineItem.DrCr;
                    line.Amount    = lineItem.Amount;
                    line.Memo      = lineItem.Memo;

                    //add to master
                    dto.Lines.Add(line);
                }


                return(Ok(dto));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemple #2
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));
        }