コード例 #1
0
        public async Task <IActionResult> GetAll([FromQuery] PageParams pageParams, VoucherDetailModel getVoucherDetailModel)
        {
            ServiceResponseModel <IEnumerable <VoucherDetail> > response = new ServiceResponseModel <IEnumerable <VoucherDetail> >();

            try
            {
                if (string.IsNullOrWhiteSpace(getVoucherDetailModel.CompCode))
                {
                    throw new ArgumentNullException("CompCode is required");
                }
                if (string.IsNullOrWhiteSpace(getVoucherDetailModel.AccYear))
                {
                    throw new ArgumentNullException("AccYear is required");
                }
                var vouDetailList = await _voucherDetailService.GetAll(pageParams, getVoucherDetailModel);

                Response.AddPaginationHeader(vouDetailList.CurrentPage, vouDetailList.PageSize, vouDetailList.TotalCount, vouDetailList.TotalPages);
                response.Data = vouDetailList;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.StackTrace);
                response.Success = false;
                response.Message = ex.Message;
            }
            return(Ok(response));
        }
コード例 #2
0
        public ActionResult HeadVoucher(string ids)
        {
            string method = Request.HttpMethod;

            if (!String.IsNullOrEmpty(ids))
            {
                string[] productList = ids.Split(',');

                for (int i = 0; i < productList.Count(); i++)
                {
                    var id = new Guid(productList[i]);
                    idProducts.Add(id);
                }
            }

            var voucherModel = Factory.VoucherFactory.CreateVoucherHeadModel();

            voucherDetailModel = Factory.VoucherFactory.CreateVoucherDetailModel();

            TempData["idProducts"] = idProducts;

            ViewData["listTipoComprobante"] = VoucherDetailManager.GetTipoComprobante();
            ViewData["listFormaPAgo"]       = VoucherDetailManager.GetFormaDePago();


            return(View("~/Views/Voucher/Voucher.cshtml"));
        }
コード例 #3
0
        public JsonResult GetProduct(string term)
        {
            voucherDetailModel = Factory.VoucherFactory.CreateVoucherDetailModel();
            var listProduct = VoucherDetailManager.GetProduct(term);

            var Descripcion1 = (from N in listProduct
                                select new { N.Descripcion1, N.Marca, N.kg, N.SubCategoryName, N.IdProducto }).ToList();

            return(Json(Descripcion1, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public async Task <ServiceResponseModel <VoucherDetailModel> > Add(VoucherDetailModel newVoucherDetailModel)
        {
            ServiceResponseModel <VoucherDetailModel> serviceResponse = new ServiceResponseModel <VoucherDetailModel>();
            VoucherDetail newVoucherDetail = _mapper.Map <VoucherDetail>(newVoucherDetailModel);
            await UnitOfWork.VoucherDetails.AddAsync(newVoucherDetail);

            await UnitOfWork.Complete();

            serviceResponse.Data = newVoucherDetailModel;
            return(serviceResponse);
        }
        public async Task <ApiResponse> Handle(GetVoucherDetailByVoucherNoQuery request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                var voucherDetail = await _dbContext.VoucherDetail
                                    .Include(o => o.OfficeDetails)
                                    .Include(j => j.JournalDetails)
                                    .Include(c => c.CurrencyDetail)
                                    .Include(f => f.FinancialYearDetails)
                                    .FirstOrDefaultAsync(v => v.IsDeleted == false && v.VoucherNo == request.VoucherId);

                if (voucherDetail != null)
                {
                    VoucherDetailModel obj = new VoucherDetailModel();

                    obj.VoucherNo                 = voucherDetail.VoucherNo;
                    obj.CurrencyCode              = voucherDetail.CurrencyDetail?.CurrencyCode ?? null;
                    obj.CurrencyId                = voucherDetail.CurrencyDetail?.CurrencyId ?? 0;
                    obj.VoucherDate               = voucherDetail.VoucherDate;
                    obj.ChequeNo                  = voucherDetail.ChequeNo;
                    obj.ReferenceNo               = voucherDetail.ReferenceNo;
                    obj.Description               = voucherDetail.Description;
                    obj.JournalName               = voucherDetail.JournalDetails?.JournalName ?? null;
                    obj.JournalCode               = voucherDetail.JournalDetails?.JournalCode ?? null;
                    obj.VoucherTypeId             = voucherDetail.VoucherTypeId;
                    obj.OfficeId                  = voucherDetail.OfficeId;
                    obj.ProjectId                 = voucherDetail.ProjectId;
                    obj.BudgetLineId              = voucherDetail.BudgetLineId;
                    obj.OfficeName                = voucherDetail.OfficeDetails?.OfficeName ?? null;
                    obj.FinancialYearId           = voucherDetail.FinancialYearId;
                    obj.FinancialYearName         = voucherDetail.FinancialYearDetails?.FinancialYearName ?? null;
                    obj.IsVoucherVerified         = voucherDetail.IsVoucherVerified;
                    obj.IsExchangeGainLossVoucher = voucherDetail.IsExchangeGainLossVoucher;

                    response.data.VoucherDetail = obj;
                    response.StatusCode         = StaticResource.successStatusCode;
                    response.Message            = StaticResource.SuccessText;
                }
                else
                {
                    response.StatusCode = StaticResource.failStatusCode;
                    response.Message    = StaticResource.VoucherNotPresent;
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = ex.Message;
            }
            return(response);
        }
コード例 #6
0
        public ActionResult HeadVoucher()
        {
            var voucherModel = Factory.VoucherFactory.CreateVoucherHeadModel();

            voucherDetailModel = Factory.VoucherFactory.CreateVoucherDetailModel();


            ViewData["listTipoComprobante"] = VoucherDetailManager.GetTipoComprobante();
            ViewData["listFormaPAgo"]       = VoucherDetailManager.GetFormaDePago();


            return(View("~/Views/Voucher/Voucher.cshtml"));
        }
コード例 #7
0
        public async Task <ServiceResponseModel <VoucherDetailModel> > GetByVouNoItemSr(VoucherDetailModel getVoucherDetailModel)
        {
            ServiceResponseModel <VoucherDetailModel> serviceResponse = new ServiceResponseModel <VoucherDetailModel>();
            VoucherDetail getVoucherDetail = await UnitOfWork.VoucherDetails.SingleOrDefaultAsync(t =>
                                                                                                  t.CompCode == getVoucherDetailModel.CompCode &&
                                                                                                  t.AccYear == getVoucherDetailModel.AccYear &&
                                                                                                  t.VouNo == getVoucherDetailModel.VouNo &&
                                                                                                  t.ItemSr == getVoucherDetailModel.ItemSr);

            VoucherDetailModel editVoucherDetailModelAll = _mapper.Map <VoucherDetailModel>(getVoucherDetail);

            serviceResponse.Data = editVoucherDetailModelAll;

            return(serviceResponse);
        }
コード例 #8
0
        public async Task <ServiceResponseModel <VoucherDetailModel> > Delete(VoucherDetailModel delVoucherDetailModel)
        {
            ServiceResponseModel <VoucherDetailModel> serviceResponse = new ServiceResponseModel <VoucherDetailModel>();
            VoucherDetail delVoucherDetail = await UnitOfWork.VoucherDetails.SingleOrDefaultAsync(t =>
                                                                                                  t.CompCode == delVoucherDetailModel.CompCode &&
                                                                                                  t.AccYear == delVoucherDetailModel.AccYear &&
                                                                                                  t.VouNo == delVoucherDetailModel.VouNo &&
                                                                                                  t.ItemSr == delVoucherDetailModel.ItemSr);

            UnitOfWork.VoucherDetails.Remove(delVoucherDetail);
            await UnitOfWork.Complete();

            serviceResponse.Data = delVoucherDetailModel;
            return(serviceResponse);
        }
コード例 #9
0
        public async Task <IActionResult> GetAll(VoucherDetailModel editVoucherDetailModel)
        {
            ServiceResponseModel <IEnumerable <VoucherDetailModel> > response = new ServiceResponseModel <IEnumerable <VoucherDetailModel> >();

            try
            {
                response = await _voucherDetailService.GetAll(editVoucherDetailModel);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.StackTrace);
                response.Success = false;
                response.Message = ex.Message;
            }
            return(Ok(response));
        }
コード例 #10
0
        public JsonResult GetProductDetail(int?page, int?limit, string term, Guid?idProducto, decimal cantidad = 0, decimal descuento = 0)
        {
            var detailGridTemp = TempData["DetailGrid"] as List <DetailGrid>;
            var detailGridList = new List <DetailGrid>();
            int total;
            var isDelete = TempData["isDelete"] as string;

            if (String.IsNullOrEmpty(term) || isDelete == "true")
            {
                term = string.Empty;
                TempData["isDelete"] = "false";
            }

            voucherDetailModel = Factory.VoucherFactory.CreateVoucherDetailModel();
            var listProduct = VoucherDetailManager.GetProduct();

            voucherDetailModel.ProductModel = listProduct;

            if (TempData["idProducts"] != null)
            {
                idProducts = TempData["idProducts"] as List <Guid>;

                foreach (var itemProduct in idProducts)
                {
                    detailGridTemp = AgregarProductosGrilla(detailGridTemp, detailGridList, listProduct, term, itemProduct, cantidad, descuento);
                }

                TempData["idProducts"] = null;
            }

            else
            {
                if (!String.IsNullOrEmpty(term))
                {
                    detailGridTemp = AgregarProductosGrilla(detailGridTemp, detailGridList, listProduct, term, idProducto, cantidad, descuento);
                }
            }

            TempData["DetailGrid"] = (detailGridTemp != null) ?  detailGridTemp : detailGridList;

            var records = (detailGridTemp != null) ? detailGridTemp: detailGridList;

            total = (detailGridTemp != null) ? detailGridTemp.Count() : detailGridList.Count();


            return(Json(new { records, total }, JsonRequestBehavior.AllowGet));
        }
コード例 #11
0
        public async Task <ServiceResponseModel <VoucherDetailModel> > Edit(VoucherDetailModel editVoucherDetailModel)
        {
            ServiceResponseModel <VoucherDetailModel> serviceResponse = new ServiceResponseModel <VoucherDetailModel>();
            VoucherDetail editVoucherDetail = await UnitOfWork.VoucherDetails.SingleOrDefaultAsync(t =>
                                                                                                   t.CompCode == editVoucherDetailModel.CompCode &&
                                                                                                   t.AccYear == editVoucherDetailModel.AccYear &&
                                                                                                   t.VouNo == editVoucherDetailModel.VouNo &&
                                                                                                   t.ItemSr == editVoucherDetailModel.ItemSr);

            _mapper.Map <VoucherDetailModel, VoucherDetail>(editVoucherDetailModel, editVoucherDetail);
            UnitOfWork.VoucherDetails.Update(editVoucherDetail);
            await UnitOfWork.Complete();

            serviceResponse.Data = editVoucherDetailModel;

            return(serviceResponse);
        }
コード例 #12
0
        public async Task <PagedList <VoucherDetail> > GetAll(PageParams pageParams, VoucherDetailModel getVoucherDetailModel)
        {
            var query = _context.VoucherDetails
                        .Where(a => a.CompCode == getVoucherDetailModel.CompCode && a.AccYear == getVoucherDetailModel.AccYear)
                        .AsQueryable();

            switch (getVoucherDetailModel.OrderBy)
            {
            case "vouNo":
                query = query.OrderBy(c => c.CompCode).ThenBy(c => c.AccYear).ThenBy(c => c.VouNo).ThenBy(c => c.ItemSr);
                break;

            case "accountId":
                query = query.OrderBy(c => c.CompCode).ThenBy(c => c.AccYear).ThenBy(c => c.AccountId).ThenBy(c => c.VouNo);
                break;

            default:
                query = query.OrderBy(c => c.CompCode).ThenBy(c => c.AccYear).ThenBy(c => c.VouNo).ThenBy(c => c.ItemSr);
                break;
            }

            return(await PagedList <VoucherDetail> .CreateAsync(query, pageParams.PageNumber, pageParams.PageSize));
        }
コード例 #13
0
        public async Task <IActionResult> Delete(VoucherDetailModel delVoucherDetailModel)
        {
            ServiceResponseModel <VoucherDetailModel> response = new ServiceResponseModel <VoucherDetailModel>();

            try
            {
                if (string.IsNullOrWhiteSpace(delVoucherDetailModel.CompCode))
                {
                    throw new ArgumentNullException("CompCode is required");
                }
                if (string.IsNullOrWhiteSpace(delVoucherDetailModel.AccYear))
                {
                    throw new ArgumentNullException("AccYear is required");
                }
                if (string.IsNullOrWhiteSpace(delVoucherDetailModel.VouNo))
                {
                    throw new ArgumentNullException("VouNo is required");
                }
                if (delVoucherDetailModel.ItemSr < 0)
                {
                    throw new ArgumentNullException("UserPassword is required");
                }
                response = await _voucherDetailService.Delete(delVoucherDetailModel);

                if (response.Data == null)
                {
                    return(NotFound(response));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.StackTrace);
                response.Success = false;
                response.Message = ex.Message;
            }
            return(Ok(response));
        }
コード例 #14
0
        public async Task <ApiResponse> Handle(VerifyPurchaseCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                if (request != null)
                {
                    var purchaseRecord = await _dbContext.StoreItemPurchases.FirstOrDefaultAsync(x => x.PurchaseId == request.PurchaseId);

                    if (purchaseRecord != null)
                    {
                        _mapper.Map(request, purchaseRecord);

                        if (!string.IsNullOrEmpty(request.ImageFileName))
                        {
                            if (request.ImageFileName.Contains(","))
                            {
                                string[] str      = request.ImageFileName.Split(",");
                                byte[]   filepath = Convert.FromBase64String(str[1]);
                                string   ex       = str[0].Split("/")[1].Split(";")[0];
                                string   guidname = Guid.NewGuid().ToString();
                                string   filename = guidname + "." + ex;
                                var      pathFile = Path.Combine(Directory.GetCurrentDirectory(), @"Documents/") + filename;
                                File.WriteAllBytes(@"Documents/" + filename, filepath);

                                purchaseRecord.ImageFileName = guidname;
                                purchaseRecord.ImageFileType = "." + ex;
                            }
                        }

                        if (request.InvoiceFileName != null && request.InvoiceFileName != "")
                        {
                            if (request.InvoiceFileName.Contains(","))
                            {
                                string[] str      = request.InvoiceFileName.Split(",");
                                byte[]   filepath = Convert.FromBase64String(str[1]);
                                string   ex       = str[0].Split("/")[1].Split(";")[0];
                                string   guidname = Guid.NewGuid().ToString();
                                string   filename = guidname + "." + ex;
                                var      pathFile = Path.Combine(Directory.GetCurrentDirectory(), @"Documents/") + filename;
                                File.WriteAllBytes(@"Documents/" + filename, filepath);

                                purchaseRecord.InvoiceFileName = guidname;
                                purchaseRecord.InvoiceFileType = "." + ex;
                            }
                        }

                        purchaseRecord.IsDeleted = false;


                        //List<ExchangeRate> exchangeRate = new List<ExchangeRate>();

                        if (request.IsPurchaseVerified.HasValue && request.IsPurchaseVerified.Value)
                        {
                            var financialYearDetails = _dbContext.FinancialYearDetail.FirstOrDefault(x => x.IsDeleted == false && x.StartDate.Date.Year == DateTime.Now.Year);
                            var inventory            = _dbContext.InventoryItems.Include(x => x.Inventory).FirstOrDefault(x => x.ItemId == request.InventoryItem);
                            var paymentTypes         = _dbContext.PaymentTypes.FirstOrDefault(x => x.PaymentId == request.PaymentTypeId);

                            #region "Generate Voucher"
                            VoucherDetailModel voucherModel = new VoucherDetailModel
                            {
                                CurrencyId                = request.Currency,
                                Description               = StaticResource.PurchaseVoucherCreated,
                                JournalCode               = request.JournalCode,
                                VoucherTypeId             = (int)VoucherTypes.Journal,
                                OfficeId                  = request.OfficeId,
                                ProjectId                 = request.ProjectId,
                                BudgetLineId              = request.BudgetLineId,
                                IsExchangeGainLossVoucher = false,
                                CreatedById               = request.CreatedById,
                                CreatedDate               = DateTime.UtcNow,
                                IsDeleted                 = false,
                                FinancialYearId           = financialYearDetails.FinancialYearId,
                                VoucherDate               = DateTime.UtcNow,
                                TimezoneOffset            = request.TimezoneOffset
                            };

                            var responseVoucher = await _iStoreServices.AddVoucherNewDetail(voucherModel);

                            #endregion

                            if (responseVoucher.StatusCode == 200)
                            {
                                purchaseRecord.VerifiedPurchaseVoucher = responseVoucher.data.VoucherDetailEntity.VoucherNo;
                                await _dbContext.SaveChangesAsync();

                                List <VoucherTransactionsModel> transactions = new List <VoucherTransactionsModel>();

                                // Credit
                                transactions.Add(new VoucherTransactionsModel
                                {
                                    TransactionId = 0,
                                    VoucherNo     = responseVoucher.data.VoucherDetailEntity.VoucherNo,
                                    AccountNo     = paymentTypes.ChartOfAccountNewId,
                                    Debit         = 0,
                                    Credit        = request.UnitCost * request.Quantity,
                                    Description   = StaticResource.PurchaseVoucherCreated,
                                    IsDeleted     = false
                                });

                                // Debit
                                transactions.Add(new VoucherTransactionsModel
                                {
                                    TransactionId = 0,
                                    VoucherNo     = responseVoucher.data.VoucherDetailEntity.VoucherNo,
                                    AccountNo     = inventory.Inventory.InventoryDebitAccount,
                                    Debit         = request.UnitCost * request.Quantity,
                                    Credit        = 0,
                                    Description   = StaticResource.PurchaseVoucherCreated,
                                    IsDeleted     = false
                                });

                                AddEditTransactionModel transactionVoucherDetail = new AddEditTransactionModel
                                {
                                    VoucherNo           = responseVoucher.data.VoucherDetailEntity.VoucherNo,
                                    VoucherTransactions = transactions
                                };
                                var responseTransaction = _iStoreServices.AddEditTransactionList(transactionVoucherDetail, request.CreatedById);

                                if (responseTransaction.StatusCode == 200)
                                {
                                    response.StatusCode = StaticResource.successStatusCode;
                                    response.Message    = StaticResource.SuccessText;
                                }
                                else
                                {
                                    throw new Exception(responseTransaction.Message);
                                }
                            }
                            else
                            {
                                response.StatusCode = StaticResource.failStatusCode;
                                response.Message    = responseVoucher.Message;
                            }
                        }
                    }
                    else
                    {
                        response.StatusCode = StaticResource.failStatusCode;
                        response.Message    = "Record cannot be updated";
                        return(response);
                    }
                }
                else
                {
                    response.StatusCode = StaticResource.failStatusCode;
                    response.Message    = "request values are inappropriate";
                    return(response);
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
                return(response);
            }
            return(response);
        }
コード例 #15
0
        public async Task <ServiceResponseModel <IEnumerable <VoucherDetailModel> > > GetAll(VoucherDetailModel editVoucherDetailModel)
        {
            ServiceResponseModel <IEnumerable <VoucherDetailModel> > serviceResponse = new ServiceResponseModel <IEnumerable <VoucherDetailModel> >();
            IEnumerable <VoucherDetail> getVoucherDetail = await UnitOfWork.VoucherDetails.FindAsync(t =>
                                                                                                     t.CompCode == editVoucherDetailModel.CompCode &&
                                                                                                     t.AccYear == editVoucherDetailModel.AccYear);

            IEnumerable <VoucherDetailModel> editVoucherDetailModelAll = _mapper.Map <IEnumerable <VoucherDetailModel> >(getVoucherDetail);

            serviceResponse.Data = editVoucherDetailModelAll;

            return(serviceResponse);
        }
コード例 #16
0
        public async Task <ServiceResponseModel <VoucherMasterModel> > Edit(VoucherMasterModel editVoucherMasterModel)
        {
            ServiceResponseModel <VoucherMasterModel> serviceResponse = new ServiceResponseModel <VoucherMasterModel>();
            int                itemSr             = 1;
            decimal            mtot               = 0;
            Ledger             ledger             = null;
            List <Ledger>      ledgersRec         = new List <Ledger>();
            VoucherDetailModel voucherDetailModel = null;
            AccountMaster      accountMaster      = null;


            try
            {
                //Delete existing records
                //=======================

                IEnumerable <Ledger> ledgerRecords = await UnitOfWork.Ledgers.FindAsync(t =>
                                                                                        t.CompCode == editVoucherMasterModel.CompCode &&
                                                                                        t.AccYear == editVoucherMasterModel.AccYear &&
                                                                                        t.VouNo == editVoucherMasterModel.VouNo);

                foreach (Ledger ledgerTmp in ledgerRecords)
                {
                    accountMaster = await UnitOfWork.AccountMasters.SingleOrDefaultAsync(a =>
                                                                                         a.CompCode == ledgerTmp.CompCode &&
                                                                                         a.AccYear == ledgerTmp.AccYear &&
                                                                                         a.AccountId == ledgerTmp.AccountId);

                    if (ledgerTmp.DrCr == "1")
                    {
                        accountMaster.CurDr   = accountMaster.CurDr.GetValueOrDefault() - ledgerTmp.Amount;
                        accountMaster.Closing = accountMaster.Opening.GetValueOrDefault() - accountMaster.CurDr.GetValueOrDefault() + accountMaster.CurCr.GetValueOrDefault();
                    }
                    else
                    {
                        accountMaster.CurCr   = accountMaster.CurCr.GetValueOrDefault() - ledgerTmp.Amount;
                        accountMaster.Closing = accountMaster.Opening.GetValueOrDefault() - accountMaster.CurDr.GetValueOrDefault() + accountMaster.CurCr.GetValueOrDefault();
                    }
                    UnitOfWork.AccountMasters.Update(accountMaster);
                }

                VoucherMaster delVoucherMaster = await _context.VoucherMasters
                                                 .Include(vm => vm.VoucherDetails)
                                                 .Include(vm => vm.Ledgers)
                                                 .Include(vm => vm.Sgst)
                                                 .Include(vm => vm.Cgst)
                                                 .Include(vm => vm.Igst)
                                                 .Where(t =>
                                                        t.CompCode == editVoucherMasterModel.CompCode &&
                                                        t.AccYear == editVoucherMasterModel.AccYear &&
                                                        t.VouNo == editVoucherMasterModel.VouNo)
                                                 .SingleAsync();

                UnitOfWork.Ledgers.RemoveRange(delVoucherMaster.Ledgers);
                UnitOfWork.VoucherDetails.RemoveRange(delVoucherMaster.VoucherDetails);
                UnitOfWork.VoucherMasters.Remove(delVoucherMaster);
                await UnitOfWork.Complete();

                //Create new record
                //=================
                //Validate Debit / Credit
                mtot = editVoucherMasterModel.DrCr == "1" ? mtot - (decimal)editVoucherMasterModel.VouAmount : mtot + (decimal)editVoucherMasterModel.VouAmount;

                //Set corresponding voucher details
                voucherDetailModel = editVoucherMasterModel.VoucherDetails.FirstOrDefault();
                if (null == voucherDetailModel)
                {
                    throw new Exception(string.Format("{0}{1}", "Incomplete transaction. Dr/Cr mismatch:", editVoucherMasterModel.VouNo));
                }

                //Check Dr/CR
                foreach (VoucherDetailModel items in editVoucherMasterModel.VoucherDetails)
                {
                    mtot = items.DrCr == "1" ? mtot - (decimal)items.Amount : mtot + (decimal)items.Amount;
                }

                if (mtot != 0)
                {
                    throw new Exception(string.Format("{0}{1}", "Debit/Credit total mismatch for voucher :", editVoucherMasterModel.VouNo));
                }

                VoucherMaster newVoucherMaster = _mapper.Map <VoucherMaster>(editVoucherMasterModel);
                await UnitOfWork.VoucherMasters.AddAsync(newVoucherMaster);

                //First ledger record
                ledger = new Ledger {
                    CompCode      = editVoucherMasterModel.CompCode,
                    AccYear       = editVoucherMasterModel.AccYear,
                    VouNo         = editVoucherMasterModel.VouNo,
                    VouDate       = editVoucherMasterModel.VouDate,
                    TrxType       = editVoucherMasterModel.TrxType,
                    BilChq        = editVoucherMasterModel.BilChq,
                    ItemSr        = itemSr,
                    AccountId     = editVoucherMasterModel.AccountId,
                    DrCr          = editVoucherMasterModel.DrCr,
                    Amount        = editVoucherMasterModel.VouAmount,
                    CorrAccountId = voucherDetailModel.AccountId,
                    VouDetail     = voucherDetailModel.VouDetail,
                    VoucherMaster = newVoucherMaster
                };
                ledgersRec.Add(ledger);

                //Remaining ledger record
                foreach (VoucherDetailModel items in editVoucherMasterModel.VoucherDetails)
                {
                    itemSr       = itemSr + 1;
                    items.ItemSr = itemSr;

                    ledger = new Ledger
                    {
                        CompCode      = items.CompCode,
                        AccYear       = items.AccYear,
                        VouNo         = editVoucherMasterModel.VouNo,
                        VouDate       = editVoucherMasterModel.VouDate,
                        TrxType       = editVoucherMasterModel.TrxType,
                        BilChq        = editVoucherMasterModel.BilChq,
                        ItemSr        = itemSr,
                        AccountId     = items.AccountId,
                        DrCr          = items.DrCr,
                        Amount        = items.Amount,
                        CorrAccountId = editVoucherMasterModel.AccountId,
                        VouDetail     = items.VouDetail,
                        VoucherMaster = newVoucherMaster
                    };
                    //await UnitOfWork.Ledgers.AddAsync(ledger);
                    ledgersRec.Add(ledger);
                }
                await UnitOfWork.Ledgers.AddRangeAsync(ledgersRec);

                //Update Voucher Master accountID Balance
                accountMaster = await UnitOfWork.AccountMasters.SingleOrDefaultAsync(a =>
                                                                                     a.CompCode == editVoucherMasterModel.CompCode &&
                                                                                     a.AccYear == editVoucherMasterModel.AccYear &&
                                                                                     a.AccountId == editVoucherMasterModel.AccountId);

                if (editVoucherMasterModel.DrCr == "1")
                {
                    accountMaster.CurDr   = accountMaster.CurDr.GetValueOrDefault() + editVoucherMasterModel.VouAmount;
                    accountMaster.Closing = accountMaster.Opening.GetValueOrDefault() - accountMaster.CurDr.GetValueOrDefault() + accountMaster.CurCr.GetValueOrDefault();
                }
                else
                {
                    accountMaster.CurCr   = accountMaster.CurCr.GetValueOrDefault() + editVoucherMasterModel.VouAmount;
                    accountMaster.Closing = accountMaster.Opening.GetValueOrDefault() - accountMaster.CurDr.GetValueOrDefault() + accountMaster.CurCr.GetValueOrDefault();
                }
                UnitOfWork.AccountMasters.Update(accountMaster);

                foreach (VoucherDetailModel items in editVoucherMasterModel.VoucherDetails)
                {
                    accountMaster = await UnitOfWork.AccountMasters.SingleOrDefaultAsync(a =>
                                                                                         a.CompCode == items.CompCode &&
                                                                                         a.AccYear == items.AccYear &&
                                                                                         a.AccountId == items.AccountId);

                    if (items.DrCr == "1")
                    {
                        accountMaster.CurDr   = accountMaster.CurDr.GetValueOrDefault() + items.Amount;
                        accountMaster.Closing = accountMaster.Opening.GetValueOrDefault() - accountMaster.CurDr.GetValueOrDefault() + accountMaster.CurCr.GetValueOrDefault();
                    }
                    else
                    {
                        accountMaster.CurCr   = accountMaster.CurCr.GetValueOrDefault() + items.Amount;
                        accountMaster.Closing = accountMaster.Opening.GetValueOrDefault() - accountMaster.CurDr.GetValueOrDefault() + accountMaster.CurCr.GetValueOrDefault();
                    }
                    UnitOfWork.AccountMasters.Update(accountMaster);
                }
                await UnitOfWork.Complete();

                serviceResponse.Data = editVoucherMasterModel;

                serviceResponse.Data = editVoucherMasterModel;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.StackTrace);
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }
            return(serviceResponse);
        }
コード例 #17
0
        /// <summary>
        /// Save voucher with detail
        /// </summary>
        /// <param name="newVoucherMasterModel"></param>
        /// <returns></returns>
        public async Task <ServiceResponseModel <VoucherMasterModel> > Add(VoucherMasterModel newVoucherMasterModel)
        {
            String             autoVoucher        = null;
            string             voucherNo          = null;
            int                vouno              = 1;
            int                itemSr             = 1;
            decimal            mtot               = 0;
            Ledger             ledger             = null;
            List <Ledger>      ledgersRec         = new List <Ledger>();
            VoucherDetailModel voucherDetailModel = null;
            AccountMaster      accountMaster      = null;
            ServiceResponseModel <VoucherMasterModel> serviceResponse = new ServiceResponseModel <VoucherMasterModel>();

            try
            {
                // autovoucher?
                CompInfo compInfo = await UnitOfWork.Companies.SingleOrDefaultAsync(c => c.CompCode == newVoucherMasterModel.CompCode);

                if (null != compInfo)
                {
                    autoVoucher = compInfo.AutoVoucher;
                }
                else
                {
                    throw new Exception(string.Format("{0}{1}", "Company object missing from table CompInfo:", newVoucherMasterModel.CompCode));
                }

                if (autoVoucher.ToUpper() == "Y")
                {
                    //Generate auto voucher
                    TypeMaster typeMaster = await UnitOfWork.TypeMasters.SingleOrDefaultAsync(t =>
                                                                                              t.CompCode == newVoucherMasterModel.CompCode &&
                                                                                              t.AccYear == newVoucherMasterModel.AccYear &&
                                                                                              t.TrxCd == newVoucherMasterModel.TrxType);

                    if (null != typeMaster)
                    {
                        vouno             = typeMaster.ItemSr == null ? 1 : (int)typeMaster.ItemSr + 1;
                        typeMaster.ItemSr = vouno;
                        UnitOfWork.TypeMasters.Update(typeMaster);
                    }
                    else
                    {
                        throw new Exception(string.Format("{0}{1}", "TypeMasters object missing from table TypeMasters:", newVoucherMasterModel.TrxType));
                    }
                    //padding '0' char with len
                    voucherNo = string.Format("{0}{1}", typeMaster.TrxCd, vouno.ToString().PadLeft(7, '0'));
                }
                else
                {
                    voucherNo = newVoucherMasterModel.VouNo;
                }

                //Validate Debit / Credit
                mtot = newVoucherMasterModel.DrCr == "1" ? mtot - (decimal)newVoucherMasterModel.VouAmount : mtot + (decimal)newVoucherMasterModel.VouAmount;

                //Set corresponding voucher details
                voucherDetailModel = newVoucherMasterModel.VoucherDetails.FirstOrDefault();
                if (null == voucherDetailModel)
                {
                    throw new Exception(string.Format("{0}{1}", "Incomplete transaction. Dr/Cr mismatch:", voucherNo));
                }

                //Check Dr/CR
                newVoucherMasterModel.VouNo = voucherNo;
                foreach (VoucherDetailModel items in newVoucherMasterModel.VoucherDetails)
                {
                    mtot        = items.DrCr == "1" ? mtot - (decimal)items.Amount : mtot + (decimal)items.Amount;
                    items.VouNo = voucherNo;
                }

                if (mtot != 0)
                {
                    throw new Exception(string.Format("{0}{1}", "Debit/Credit total mismatch for voucher :", voucherNo));
                }

                VoucherMaster newVoucherMaster = _mapper.Map <VoucherMaster>(newVoucherMasterModel);
                await UnitOfWork.VoucherMasters.AddAsync(newVoucherMaster);

                //First ledger record
                ledger = new Ledger {
                    CompCode      = newVoucherMasterModel.CompCode,
                    AccYear       = newVoucherMasterModel.AccYear,
                    VouNo         = voucherNo,
                    VouDate       = newVoucherMasterModel.VouDate,
                    TrxType       = newVoucherMasterModel.TrxType,
                    BilChq        = newVoucherMasterModel.BilChq,
                    ItemSr        = itemSr,
                    AccountId     = newVoucherMasterModel.AccountId,
                    DrCr          = newVoucherMasterModel.DrCr,
                    Amount        = newVoucherMasterModel.VouAmount,
                    CorrAccountId = voucherDetailModel.AccountId,
                    VouDetail     = voucherDetailModel.VouDetail,
                    VoucherMaster = newVoucherMaster
                };
                ledgersRec.Add(ledger);

                //Remaining ledger record
                foreach (VoucherDetailModel items in newVoucherMasterModel.VoucherDetails)
                {
                    itemSr       = itemSr + 1;
                    items.ItemSr = itemSr;

                    ledger = new Ledger
                    {
                        CompCode      = items.CompCode,
                        AccYear       = items.AccYear,
                        VouNo         = voucherNo,
                        VouDate       = newVoucherMasterModel.VouDate,
                        TrxType       = newVoucherMasterModel.TrxType,
                        BilChq        = newVoucherMasterModel.BilChq,
                        ItemSr        = itemSr,
                        AccountId     = items.AccountId,
                        DrCr          = items.DrCr,
                        Amount        = items.Amount,
                        CorrAccountId = newVoucherMasterModel.AccountId,
                        VouDetail     = items.VouDetail,
                        VoucherMaster = newVoucherMaster
                    };
                    //await UnitOfWork.Ledgers.AddAsync(ledger);
                    ledgersRec.Add(ledger);
                }
                await UnitOfWork.Ledgers.AddRangeAsync(ledgersRec);

                //Update Voucher Master accountID Balance
                accountMaster = await UnitOfWork.AccountMasters.SingleOrDefaultAsync(a =>
                                                                                     a.CompCode == newVoucherMasterModel.CompCode &&
                                                                                     a.AccYear == newVoucherMasterModel.AccYear &&
                                                                                     a.AccountId == newVoucherMasterModel.AccountId);

                if (newVoucherMasterModel.DrCr == "1")
                {
                    accountMaster.CurDr   = accountMaster.CurDr.GetValueOrDefault() + newVoucherMasterModel.VouAmount;
                    accountMaster.Closing = accountMaster.Opening.GetValueOrDefault() - accountMaster.CurDr.GetValueOrDefault() + accountMaster.CurCr.GetValueOrDefault();
                }
                else
                {
                    accountMaster.CurCr   = accountMaster.CurCr.GetValueOrDefault() + newVoucherMasterModel.VouAmount;
                    accountMaster.Closing = accountMaster.Opening.GetValueOrDefault() - accountMaster.CurDr.GetValueOrDefault() + accountMaster.CurCr.GetValueOrDefault();
                }
                UnitOfWork.AccountMasters.Update(accountMaster);

                foreach (VoucherDetailModel items in newVoucherMasterModel.VoucherDetails)
                {
                    accountMaster = await UnitOfWork.AccountMasters.SingleOrDefaultAsync(a =>
                                                                                         a.CompCode == items.CompCode &&
                                                                                         a.AccYear == items.AccYear &&
                                                                                         a.AccountId == items.AccountId);

                    if (items.DrCr == "1")
                    {
                        accountMaster.CurDr   = accountMaster.CurDr.GetValueOrDefault() + items.Amount;
                        accountMaster.Closing = accountMaster.Opening.GetValueOrDefault() - accountMaster.CurDr.GetValueOrDefault() + accountMaster.CurCr.GetValueOrDefault();
                    }
                    else
                    {
                        accountMaster.CurCr   = accountMaster.CurCr.GetValueOrDefault() + items.Amount;
                        accountMaster.Closing = accountMaster.Opening.GetValueOrDefault() - accountMaster.CurDr.GetValueOrDefault() + accountMaster.CurCr.GetValueOrDefault();
                    }
                    UnitOfWork.AccountMasters.Update(accountMaster);
                }
                await UnitOfWork.Complete();

                serviceResponse.Data = newVoucherMasterModel;
            }
            catch (Exception ex)
            {
                UnitOfWork.Dispose();
                _logger.LogError(ex.StackTrace);
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }
            return(serviceResponse);
        }
コード例 #18
0
        public async Task <ApiResponse> AddVoucherNewDetail(VoucherDetailModel model)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                model.TimezoneOffset = model.TimezoneOffset > 0 ? model.TimezoneOffset * -1 : Math.Abs(model.TimezoneOffset.Value);

                DateTime filterVoucherDate = model.VoucherDate.AddMinutes(model.TimezoneOffset.Value);

                Task <List <CurrencyDetails> > currencyListTask = _dbContext.CurrencyDetails.Where(x => x.IsDeleted == false).ToListAsync();

                if (model.IsExchangeGainLossVoucher)
                {
                    model.VoucherDate = DateTime.UtcNow;
                }

                Task <List <ExchangeRateDetail> > exchangeRatePresentTask = _dbContext.ExchangeRateDetail.Where(x => x.Date.Date == model.VoucherDate.Date && x.IsDeleted == false).ToListAsync();

                List <CurrencyDetails> currencyList = await currencyListTask;

                List <int> currencyIds = currencyList.Select(x => x.CurrencyId).ToList();

                string currencyCode = currencyList.FirstOrDefault(x => x.CurrencyId == model.CurrencyId).CurrencyCode;

                List <ExchangeRateDetail> exchangeRatePresent = await exchangeRatePresentTask;

                if (CheckExchangeRateIsPresent(currencyIds, exchangeRatePresent))
                {
                    var officeDetail = await _dbContext.OfficeDetail.FirstOrDefaultAsync(o => o.OfficeId == model.OfficeId); //use OfficeCode

                    if (officeDetail != null)
                    {
                        Task <FinancialYearDetail> fincancialYearTask = _dbContext.FinancialYearDetail.FirstOrDefaultAsync(o => o.IsDefault);
                        Task <CurrencyDetails>     currencyDetailTask = _dbContext.CurrencyDetails.FirstOrDefaultAsync(o => o.CurrencyId == model.CurrencyId);
                        // NOTE: Dont remove this as we will need journal details in response
                        Task <JournalDetail> journaldetailTask = _dbContext.JournalDetail.FirstOrDefaultAsync(o => o.JournalCode == model.JournalCode);
                        int voucherCount = await _dbContext.VoucherDetail.Where(x => x.VoucherDate.Month == model.VoucherDate.Month && x.VoucherDate.Year == filterVoucherDate.Year && x.OfficeId == model.OfficeId && x.CurrencyId == model.CurrencyId).CountAsync();

                        FinancialYearDetail fincancialYear = await fincancialYearTask;

                        if (fincancialYear != null)
                        {
                            CurrencyDetails currencyDetail = await currencyDetailTask;

                            if (currencyDetail != null)
                            {
                                JournalDetail journaldetail = await journaldetailTask;

                                VoucherDetail obj = _mapper.Map <VoucherDetail>(model);
                                obj.JournalCode     = journaldetail != null ? journaldetail.JournalCode : model.JournalCode;
                                obj.FinancialYearId = fincancialYear.FinancialYearId;
                                obj.CreatedById     = model.CreatedById;
                                obj.VoucherDate     = model.VoucherDate;
                                obj.CreatedDate     = DateTime.UtcNow;
                                obj.IsDeleted       = false;

                                // Pattern: Office Code - Currency Code - Month Number - voucher count on selected month - Year
                                string referenceNo = AccountingUtility.GenerateVoucherReferenceCode(model.VoucherDate, voucherCount, currencyDetail.CurrencyCode, officeDetail.OfficeCode);

                                int sameVoucherReferenceNoCount = 0;

                                if (!string.IsNullOrEmpty(referenceNo))
                                {
                                    do
                                    {
                                        sameVoucherReferenceNoCount = await _dbContext.VoucherDetail.Where(x => x.ReferenceNo == referenceNo).CountAsync();

                                        if (sameVoucherReferenceNoCount == 0)
                                        {
                                            obj.ReferenceNo = referenceNo;
                                        }
                                        else
                                        {
                                            //DO NOT REMOVE: This is used to get the latest voucher and then we will get the count of vouhcer sequence from it
                                            // VoucherDetail voucherDetail = _uow.GetDbContext().VoucherDetail.OrderByDescending(x => x.VoucherDate).FirstOrDefault(x => x.VoucherDate.Month == filterVoucherDate.Month && x.OfficeId == model.OfficeId && x.VoucherDate.Year == filterVoucherDate.Year);

                                            var refNo = referenceNo.Split('-');
                                            int count = Convert.ToInt32(refNo[3]);
                                            referenceNo = AccountingUtility.GenerateVoucherReferenceCode(model.VoucherDate, count, currencyCode, officeDetail.OfficeCode);
                                        }
                                    }while (sameVoucherReferenceNoCount != 0);
                                }

                                await _dbContext.VoucherDetail.AddAsync(obj);

                                VoucherDetailEntityModel voucherModel = _mapper.Map <VoucherDetail, VoucherDetailEntityModel>(obj);

                                response.data.VoucherDetailEntity = voucherModel;
                                response.StatusCode = StaticResource.successStatusCode;
                                response.Message    = "Success";
                            }
                            else
                            {
                                response.StatusCode = StaticResource.failStatusCode;
                                response.Message    = StaticResource.CurrencyNotFound;
                            }
                        }
                        else
                        {
                            response.StatusCode = StaticResource.failStatusCode;
                            response.Message    = StaticResource.defaultFinancialYearIsNotSet;
                        }
                    }
                    else
                    {
                        response.StatusCode = StaticResource.failStatusCode;
                        response.Message    = StaticResource.officeCodeNotFound;
                    }
                }
                else
                {
                    response.StatusCode = StaticResource.failStatusCode;
                    response.Message    = StaticResource.ExchagneRateNotDefined;
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }
コード例 #19
0
        public JsonResult GetProductDetail(int?page, int?limit, string term, Guid?idProducto, decimal cantidad = 0, decimal descuento = 0)
        {
            var detailGridTemp = TempData["DetailGrid"] as List <DetailGrid>;
            var detailGridList = new List <DetailGrid>();
            int total;
            var isDelete = TempData["isDelete"] as string;

            if (String.IsNullOrEmpty(term) || isDelete == "true")
            {
                term = string.Empty;
                TempData["isDelete"] = "false";
            }

            if (!String.IsNullOrEmpty(term))
            {
                voucherDetailModel = Factory.VoucherFactory.CreateVoucherDetailModel();
                var listProduct = VoucherDetailManager.GetProduct();
                voucherDetailModel.ProductModel = listProduct;

                var Descripcion1 = (from N in listProduct
                                    where (N.IdProducto == idProducto)
                                    select new { N }).ToList();

                var detailGrid = new DetailGrid();

                if (listProduct.Count != 0 && term != string.Empty)
                {
                    if (Descripcion1.Count > 0)
                    {
                        detailGrid.IdProduct       = Descripcion1[0].N.IdProducto;
                        detailGrid.Codigo          = Descripcion1[0].N.Codigo;
                        detailGrid.Descripcion1    = Descripcion1[0].N.Descripcion1;
                        detailGrid.PrecioVenta     = Descripcion1[0].N.PrecioVenta;
                        detailGrid.PrecioCosto     = Descripcion1[0].N.PrecioCosto;
                        detailGrid.CategoryItem    = Descripcion1[0].N.CategoryItem.IdCategory;
                        detailGrid.SubCategoryItem = Descripcion1[0].N.SubCategoryItem.IdSubCategory;
                        detailGrid.Category        = Descripcion1[0].N.CategoryItem.Name;
                        detailGrid.SubCategory     = Descripcion1[0].N.SubCategoryItem.Name;
                        detailGrid.Marca           = Descripcion1[0].N.Marca;
                        detailGrid.kg = Descripcion1[0].N.kg;
                    }


                    detailGrid = VoucherDetailManager.SetValuesNewRowTable(detailGrid, cantidad, descuento);
                }

                if (detailGridTemp != null)
                {
                    var newRowExist = detailGridTemp.Find(x => x.IdProduct == detailGrid.IdProduct);

                    if (newRowExist == null)
                    {
                        detailGridTemp.Add(detailGrid);
                    }
                }
                else if (!String.IsNullOrEmpty(term))
                {
                    detailGridTemp = new List <DetailGrid>();
                    detailGridTemp.Add(detailGrid);
                }

                if (detailGridTemp != null)
                {
                    TempData["DetailGrid"] = detailGridTemp;
                }

                if (detailGridTemp != null)
                {
                    detailGridTemp.Last().Total = 0;
                    var totalRow = new decimal();
                    foreach (var item in detailGridTemp)
                    {
                        totalRow += Convert.ToDecimal(item.Subtotal);
                    }

                    detailGridTemp.Last().Total = Decimal.Round(totalRow, 2);
                }
            }

            TempData["DetailGrid"] = (detailGridTemp != null) ?  detailGridTemp : detailGridList;

            var records = (detailGridTemp != null) ? detailGridTemp: detailGridList;

            total = (detailGridTemp != null) ? detailGridTemp.Count() : detailGridList.Count();
            return(Json(new { records, total }, JsonRequestBehavior.AllowGet));
        }