public void Insert()
        {
            //Arrange
            //voucherRepository = new Mock<IAnFVoucherRepository>();
            VoucherDateAndType t = new VoucherDateAndType();
            t.Prefix = "JV";
            t.Type = 3;
            t.Date = DateTime.Now;

            VoucherViewModel voucher = new VoucherViewModel();

            voucher.CmnCompanyId = companyId;
            voucher.CmnFinancialYearId = financialYearId;
            voucher.Type = 3;
            //voucher.VoucherNumber = controller.GetVoucherNo(t);
            voucher.Date = DateTime.Now;
            voucher.TotalAmount = 1500;

            List<VoucherDetailsViewModel> list = new List<VoucherDetailsViewModel>{
               new VoucherDetailsViewModel { AnFChartOfAccountId = 13227,AnFCostCenterId = 1322111,CmnProjectId = 13221,VoucherSerial = 1,SubVoucherNumber = voucher.VoucherNumber + "-1",Credit = 500,Debit = 500},
               new VoucherDetailsViewModel { AnFChartOfAccountId = 13228,AnFCostCenterId = 1322111,CmnProjectId = 13221,VoucherSerial = 2,SubVoucherNumber = voucher.VoucherNumber + "-2",Credit = 1000,Debit = 1000}

            };
            voucher.VouchrerDetails = list;
            //Act
            //Int64 actual = controller.InsertVoucher(voucher);

            //Assert
            //Assert.AreEqual(3112231058, actual);
        }
        public ActionResult InsertVoucher(VoucherViewModel voucher)
        {
            //Operation objOperation = new Operation { Success = false };
            //int ret = 0;

            //voucher.CmnCompanyId = companyId;
            //voucher.CmnFinancialYearId = financialYearId;
            //AnFVoucher v = new AnFVoucher();
            //v.Id = voucher.Id;
            //v.Type = voucher.Type;

            //v.VoucherNumber = voucher.VoucherNumber;
            //if (voucher.Id <= 0)
            //{
            //    v.VoucherNumber = GetVoucherNo(new VoucherDateAndType() { Date = voucher.Date, CmnBusinessId = voucher.CmnBusinessId, Type = voucher.Type, Prefix = Enum.GetName(typeof(AnFVoucherTypes), voucher.Type) });
            //}
            //v.Date = voucher.Date;
            //v.Naration = voucher.Naration;
            //v.TotalAmount = voucher.TotalAmount;
            //v.CmnCompanyId = voucher.CmnCompanyId;
            //v.CmnFinancialYearId = voucher.CmnFinancialYearId;
            //v.Status = true;
            //v.IsPosted = false;
            //v.IsCancel = false;
            //v.CreatedBy = userId;
            //v.CreatedDate = DateTime.Now;
            ////if (ModelState.IsValid)
            ////{
            //if (voucher.Id <= 0)
            //{
            //    ret = _anfVoucherService.SaveVoucher(v);
            //}
            //else
            //{
            //    ret = _anfVoucherService.UpdateVoucher(v);
            //}

            //if (ret != 0)
            //{
            //    _anfVoucherDetailsService.DeleteDetailsByVoucherId(ret);

            //    long voucherdetailsId = _anfVoucherDetailsService.GetLastId();
            //    if (voucher.VouchrerDetails != null)
            //    {
            //        foreach (VoucherDetailsViewModel details in voucher.VouchrerDetails)
            //        {
            //            AnFVoucherDetail det = new AnFVoucherDetail();
            //            det.Id = voucherdetailsId;
            //            det.AnFVoucherId = ret;
            //            det.AnFChartOfAccountId = details.AnFChartOfAccountId;
            //            //det.AnFCostCenterId = details.AnFCostCenterId;
            //            //det.CmnProjectId = details.CmnProjectId;

            //            det.Debit = details.Debit;
            //            det.Credit = details.Credit;
            //            det.ShortNarration = details.ShortNaration;
            //            det.VoucherSerial = details.VoucherSerial;
            //            if (voucher.Id == 0)
            //            {
            //                det.SubVoucherNumber = v.VoucherNumber + "-" + details.VoucherSerial;
            //            }
            //            else { det.SubVoucherNumber = details.SubVoucherNumber; }

            //            _anfVoucherDetailsService.InsertVoucherDetails(det);
            //            voucherdetailsId = voucherdetailsId + 1;
            //        }
            //    }

            //    if (voucher.Id <= 0 && voucherdetailsId > 0)
            //    {
            //        string prefix = v.VoucherNumber.Split('-')[0];
            //        CmnApprovalProcess process = _cmnApprovalProcessService.GetByShortName(prefix, moduleId);

            //        _cmnApprovalService.AutoGenerate(companyId, (int)process.Id, userId, ret);
            //    }

            //    _anfVoucherDetailsService.Commit();
            //    objOperation.Success = true; objOperation.OperationId = v.VoucherNumber;

            //}
            ////}
            ////return ret;
            //return Json(objOperation, JsonRequestBehavior.DenyGet);
            return Json(new { }, JsonRequestBehavior.DenyGet);
        }
        public ActionResult SaveApprovalComment(VoucherViewModel comment, int userId, int companyId)
        {
            int processId = 0;
            int levelId = 0;
            string urlData = Request.UrlReferrer.Query;
            string[] array = urlData.Split('=');
            if (array.Length > 0)
            {
                processId = Convert.ToInt32(array[1]);
                levelId = Convert.ToInt32(array[2]);
            }

            Operation objOperation = new Operation();
            Int64 ret = 0;

            CmnApproval apr = _ICmnApprovalService.GetApproval(comment.Id, processId, levelId);
            if (apr != null)
            {

                apr.Value = true;
                apr.DoneBy = userId;
                apr.DoneDateTime = DateTime.Now;
                //apr.CmnApprovalComments = comment;
                objOperation = _ICmnApprovalService.UpdatewithComment(apr);
                if (objOperation.Success)
                {
                    CmnApprovalComment obj = new CmnApprovalComment();
                    obj.CmnApprovalId = Convert.ToInt32(objOperation.OperationId);
                    obj.Comments = comment.Naration;
                    obj.Commentator = userId;
                    obj.CommentDate = DateTime.Now;
                    objOperation = _ICmnApprovalCommentService.SaveApprovalComment(obj);
                }
                int i = Convert.ToInt32(objOperation.OperationId);
                if (i > 0)
                {

                    //This means all is checked so make the PStatus=true
                    if (array[3] == "Approve")
                    {
                        AnFVoucher vr = _IAnFVoucherService.GetAnfVoucherById(comment.Id);
                        if (vr != null)
                        {
                            vr.IsPosted = true;
                            _IAnFVoucherService.UpdateVoucher(vr);
                        }
                    }
                }

            }
            return Json(objOperation, JsonRequestBehavior.DenyGet);
        }
        public ActionResult Reject(VoucherViewModel comment, int userId, int companyId)
        {
            int processId = 0;
            int levelId = 0;
            string urlData = Request.UrlReferrer.Query;
            string[] array = urlData.Split('=');
            if (array.Length > 0)
            {
                processId = Convert.ToInt32(array[1]);
                levelId = Convert.ToInt32(array[2]);
            }
            Operation objOperation = new Operation();

            CmnApproval apr = _ICmnApprovalService.GetApproval(comment.Id, processId, levelId);
            if (apr != null)
            {
                apr.Value = false;
                apr.DoneBy = userId;
                apr.DoneDateTime = DateTime.Now;
                //apr.Comment = comment.Naration;
                //Int64 i = 0;
                objOperation = _ICmnApprovalService.UpdatewithComment(apr);
                if (objOperation.Success)
                {
                    CmnApprovalComment obj = new CmnApprovalComment();
                    obj.CmnApprovalId = Convert.ToInt32(objOperation.OperationId);
                    obj.Comments = comment.Naration;
                    obj.Commentator = userId;
                    obj.CommentDate = DateTime.Now;
                    objOperation = _ICmnApprovalCommentService.SaveApprovalComment(obj);
                }

            }
            return Json(objOperation, JsonRequestBehavior.DenyGet);
        }