public async Task<ActionResult> LoadDetailBankCashPaymentVoucher(string dataDetail, string act, string voucherNo)
        {
            string[] data = dataDetail.Split('|');

            var model = new bankCashPaymentVoucher();
            for (int i = 0; i < data.Count(); i++)
            {
                string[] value = data[i].Split(';');

                if (value[1].ToString() == "")
                    break;

                string idxRows = value[0].ToString();
                string t_accountNo = value[1].ToString();
                //string t_accountName = value[2].ToString();
                decimal t_amount = value[2].ToString() != "" ? Convert.ToDecimal(value[2].ToString()) : 0;

                var editor = new bankCashPaymentVoucher.bankCashPaymentVoucherDetail()
                {
                    voucherNo = voucherNo,
                    accountNo = t_accountNo,
                    amount = t_amount
                };
                model.detailBankCashPaymentVoucher.Add(editor);
            }
            ViewData["dataDetail"] = model.detailBankCashPaymentVoucher.ToList();
            ViewBag.COA = ccm.ddlAccountCOA(string.Empty);

            return PartialView("_PartialPageBCP1");
        }
        protected void loadDetail(string id)
        {
            var model = new bankCashPaymentVoucher();
            var tempDetail = db.bankCashPaymentVoucherDetails.Where(x => x.voucherNo == id).ToList();
            foreach (var a in tempDetail)
            {
                string t_accountNo = a.accountNo;
                decimal t_amount = Convert.ToDecimal(a.amount);

                var editor = new bankCashPaymentVoucher.bankCashPaymentVoucherDetail()
                {
                    accountNo = t_accountNo,
                    amount = t_amount
                };
                model.detailBankCashPaymentVoucher.Add(editor);
            }
            ViewData["dataDetail"] = model.detailBankCashPaymentVoucher.ToList();
        }
        public ActionResult Edit([Bind(Include="voucherNo,voucherDate,bankID,remarks,says,preparedBy,preparedDate,preparedStatus,checkedBy,checkedDate,checkedStatus,approvedBy,approvedDate,approvedStatus,acknowledgeBy,acknowledgeDate,acknowledgeStatus,createdUser,createdDate,modifiedUser,modifiedDate")] bankCashPaymentVoucher bankcashpaymentvoucher)
        {
            if (acm.cekSession() == false)
                return RedirectToAction("Logout", "Account");

            lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
            if (acm.cekValidation(Url.Action().ToString()) == false && lvm.isAdmin == false)
                return RedirectToAction("NotAuthorized", "Account", new { menu = Url.Action().ToString() });

            #region collect detail purchase request
            var countChk = 0;
            for (int i = 0; i < Request.Form.Count; i++)
            {
                if (Request.Form.AllKeys.ToList()[i].Contains("txtAccountNo_"))
                    countChk++;
            }

            var model = new bankCashPaymentVoucher();
            for (int i = 1; i <= countChk; i++)
            {
                var colVal = Request.Form["txtAccountNo_" + i];
                if (colVal == "")
                    break;

                string t_accountNo = Request.Form["txtAccountNo_" + i].ToString();
                decimal t_amount = Request.Form["txtAmount_" + i].ToString() != "" ? Convert.ToDecimal(Request.Form["txtAmount_" + i].ToString().Replace('.', ',')) : 0;

                var editor = new bankCashPaymentVoucher.bankCashPaymentVoucherDetail()
                {
                    voucherNo = "",
                    accountNo = t_accountNo,
                    amount = t_amount
                };
                model.detailBankCashPaymentVoucher.Add(editor);
            }
            ViewData["dataDetail"] = model.detailBankCashPaymentVoucher.ToList();
            #endregion

            ViewBag.Bank = ccm.ddlBank(bankcashpaymentvoucher.bankID.ToString());
            ViewBag.COA = ccm.ddlAccountCOA(string.Empty);
            if (ModelState.IsValid)
            {
                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
                        bankcashpaymentvoucher.modifiedUser = lvm.userID;
                        bankcashpaymentvoucher.modifiedDate = DateTime.Now;
                        db.Entry(bankcashpaymentvoucher).State = EntityState.Modified;

                        #region insertDetail
                        bool runFirst = true;
                        for (int i = 1; i <= countChk; i++)
                        {
                            if (runFirst == true)
                            {
                                db.bankCashPaymentVoucherDetails.RemoveRange(db.bankCashPaymentVoucherDetails.Where(x => x.voucherNo == bankcashpaymentvoucher.voucherNo));
                                runFirst = false;
                            }

                            var colVal = Request.Form["txtAccountNo_" + i];
                            if (colVal == "")
                                break;

                            string t_accountNo = Request.Form["txtAccountNo_" + i].ToString();
                            decimal t_amount = Request.Form["txtAmount_" + i].ToString() != "" ? Convert.ToDecimal(Request.Form["txtAmount_" + i].ToString().Replace('.', ',')) : 0;

                            var editor = new bankCashPaymentVoucher.bankCashPaymentVoucherDetail()
                            {
                                voucherNo = bankcashpaymentvoucher.voucherNo,
                                accountNo = t_accountNo,
                                amount = t_amount
                            };
                            db.bankCashPaymentVoucherDetails.Add(editor);
                        }
                        #endregion

                        db.SaveChanges();
                        ts.Complete();
                    }

                    return RedirectToAction("Index");
                }
                catch (Exception exc)
                {
                    string a = exc.Message;
                }
            }
            return View(bankcashpaymentvoucher);
        }
        public ActionResult Create([Bind(Include="voucherNo,voucherDate,bankID,remarks,says,preparedBy,preparedDate,preparedStatus,checkedBy,checkedDate,checkedStatus,approvedBy,approvedDate,approvedStatus,acknowledgeBy,acknowledgeDate,acknowledgeStatus,createdUser,createdDate,modifiedUser,modifiedDate")] bankCashPaymentVoucher bankcashpaymentvoucher)
        {
            if (acm.cekSession() == false)
                return RedirectToAction("Logout", "Account");

            lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
            if (acm.cekValidation(Url.Action().ToString()) == false && lvm.isAdmin == false)
                return RedirectToAction("NotAuthorized", "Account", new { menu = Url.Action().ToString() });

            #region collect detail bank cash
            var countChk = 0;
            for (int i = 0; i < Request.Form.Count; i++)
            {
                if (Request.Form.AllKeys.ToList()[i].Contains("txtAccountNo_"))
                    countChk++;
            }

            var model = new bankCashPaymentVoucher();
            for (int i = 1; i <= countChk; i++)
            {
                var colVal = Request.Form["txtAccountNo_" + i];
                if (colVal == "")
                    break;

                string t_accountNo = Request.Form["txtAccountNo_" + i].ToString();
                decimal t_amount = Request.Form["txtAmount_" + i].ToString() != "" ? Convert.ToDecimal(Request.Form["txtAmount_" + i].ToString().Replace('.', ',')) : 0;

                var editor = new bankCashPaymentVoucher.bankCashPaymentVoucherDetail()
                {
                    voucherNo = "",
                    accountNo = t_accountNo,
                    amount = t_amount
                };
                model.detailBankCashPaymentVoucher.Add(editor);
            }
            ViewData["dataDetail"] = model.detailBankCashPaymentVoucher.ToList();
            #endregion 

            ViewBag.Bank = ccm.ddlBank(bankcashpaymentvoucher.bankID.ToString());
            ViewBag.COA = ccm.ddlAccountCOA(string.Empty);
            if (ModelState.IsValid)
            {
                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        string generateID = prefix + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("d2");
                        var apvCreated = db.bankCashPaymentVouchers.Where(x => x.voucherNo.Contains(generateID)).OrderByDescending(x => x.createdDate).Select(x => x.voucherNo).ToList();
                        if (apvCreated.Count == 0)
                        {
                            generateID = generateID + "0001";
                        }
                        else
                        {
                            generateID = generateID + (Convert.ToInt32(apvCreated[0].Substring((apvCreated[0].Length - 4))) + 1).ToString().PadLeft(4, '0');
                        }

                        bankcashpaymentvoucher.voucherNo = generateID;
                        lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin;
                        bankcashpaymentvoucher.createdUser = lvm.userID;
                        bankcashpaymentvoucher.createdDate = DateTime.Now;
                        bankcashpaymentvoucher.preparedBy = lvm.userID;
                        bankcashpaymentvoucher.preparedDate = DateTime.Now;
                        bankcashpaymentvoucher.preparedStatus = true;
                        db.bankCashPaymentVouchers.Add(bankcashpaymentvoucher);

                        #region insertDetail
                        for (int i = 1; i <= countChk; i++)
                        {
                            var colVal = Request.Form["txtAccountNo_" + i];
                            if (colVal == "")
                                break;

                            string t_accountNo = Request.Form["txtAccountNo_" + i].ToString();
                            decimal t_amount = Request.Form["txtAmount_" + i].ToString() != "" ? Convert.ToDecimal(Request.Form["txtAmount_" + i].ToString().Replace('.', ',')) : 0;

                            var editor = new bankCashPaymentVoucher.bankCashPaymentVoucherDetail()
                            {
                                voucherNo = bankcashpaymentvoucher.voucherNo,
                                accountNo = t_accountNo,
                                amount = t_amount
                            };
                            db.bankCashPaymentVoucherDetails.Add(editor);
                        }
                        #endregion

                        db.SaveChanges();
                        ts.Complete();
                    }

                    return RedirectToAction("Index");
                }
                catch (Exception exc)
                {
                    string a = exc.Message;
                }
            }
            return View(bankcashpaymentvoucher);
        }