private long saveJournalVoucher(JournalVoucherViewModel model)
        {
            JournalVoucher entity = new JournalVoucher();
            entity.CompanyId = AuthenticationHelper.User.CompanyId;
            entity.ConversionRate = model.ConversionRate;
            entity.CreateDate = DateTime.Now;
            entity.CurrencyId = model.CurrencyId;
            entity.Description = model.Description;
            entity.DocumentNo = model.DocumentNo;
            entity.GLDate = model.GLDate;
            entity.Id = model.Id;
            entity.JournalName = model.JournalName;
            entity.PeriodId = model.PeriodId;
            //entity.PostingFlag = codeCombinitionService.GetSingle(model.CodeCombinationId.ToString(), AuthenticationHelper.User.CompanyId).AllowedPosting;
            entity.PostingFlag = true;
            entity.SOBId = model.SOBId;
            entity.UpdateDate = DateTime.Now;

            if (entity.Id == 0)
            {
                entity.Id = Convert.ToInt32(service.Insert(entity));
            }
            else
            {
                entity.Id = Convert.ToInt32(service.Update(entity));
            }

            if (model.JournalVoucherDetail.Any())
            {
                foreach (var detail in model.JournalVoucherDetail)
                {
                    detail.HeaderId = entity.Id;

                    JournalVoucherDetail entityDetail = new JournalVoucherDetail();
                    entityDetail.AccountedCr = detail.AccountedCr;
                    entityDetail.AccountedDr = detail.AccountedDr;
                    entityDetail.CodeCombinationId = detail.CodeCombinationId;
                    entityDetail.CreateDate = DateTime.Now;
                    entityDetail.Description = detail.Description;
                    entityDetail.EnteredCr = detail.EnteredCr;
                    entityDetail.EnteredDr = detail.EnteredDr;
                    entityDetail.HeaderId = detail.HeaderId;
                    entityDetail.Id = detail.Id;
                    entityDetail.Qty = detail.Qty;
                    entityDetail.TaxRateCode = detail.TaxRateCode;
                    entityDetail.UpdateDate = DateTime.Now;

                    if (entityDetail.Id == 0)
                    {
                        entityDetail.Id = Convert.ToInt32(service.Insert(entityDetail));
                    }
                    else
                    {
                        entityDetail.Id = Convert.ToInt32(service.Update(entityDetail));
                    }
                }
            }

            return entity.Id;
        }
        private JournalVoucherViewModel mapModel(JournalVoucherCreateModel model, JournalVoucherViewModel jv)
        {
            jv.CompanyId = AuthenticationHelper.User.CompanyId;
            jv.ConversionRate = model.ConversionRate;
            jv.CurrencyId = model.CurrencyId;
            jv.Description = model.Description;
            jv.DocumentNo = model.DocumentNo;
            jv.GLDate = model.GLDate;
            jv.Id = model.HeaderId;
            jv.JournalName = model.JournalName;
            if (jv.JournalVoucherDetail == null)
            {
                jv.JournalVoucherDetail = new List<JournalVoucherDetailModel>();
            }
            jv.JournalVoucherDetail.Add(new JournalVoucherDetailModel
                {
                    AccountedCr = model.AccountedCr,
                    AccountedDr = model.AccountedDr,
                    CodeCombinationId = model.CodeCombinationId,
                    Description = model.GLLinesDescription,
                    EnteredCr = model.EnteredCr,
                    EnteredDr = model.EnteredDr,
                    HeaderId = model.HeaderId,
                    Id = model.Id,
                    Qty = model.Qty,
                    TaxRateCode = model.TaxRateCode
                });

            jv.PeriodId = model.PeriodId;
            jv.SOBId = model.SOBId;
            return jv;
        }