public async Task<ActionResult> LoadDetailCategoryProducts(string dataDetail, string act) { string[] data = dataDetail.Split('|'); var model = new journalHeader(); for (int i = 0; i < data.Count(); i++ ) { string[] value = data[i].Split(';'); if (value[1].ToString() == "") break; int idCoa = Convert.ToInt32(value[1].ToString()); string othrAccountName = value[2].ToString(); string remak = value[3].ToString(); decimal debt = value[4].ToString() != "" ? Convert.ToDecimal(Convert.ToDouble(value[4].ToString().Replace('.', ','))) : 0; decimal credt = value[5].ToString() != "" ? Convert.ToDecimal(Convert.ToDouble(value[5].ToString().Replace('.', ','))) : 0; var editor = new journalHeader.journalDetail() { coaId = idCoa, accountNameOther = othrAccountName, remarks = remak, debit = debt, credit = credt }; model.detailJournal.Add(editor); ViewData["ddlAccount" + (i + 1)] = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { x.id, accountName = x.accountName + " [" + x.accountNo + "]" }), "id", "accountName", idCoa); } ViewData["dataDetail"] = model.detailJournal.ToList(); //ViewBag.ddlAccount = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { x.id, accountName = /*"[" + */x.accountNo/* + "] " + x.accountName */ }), "id", "accountName"); ViewBag.ddlAccount = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { id = x.id + "-" + x.accountName, accountName = x.accountName + " [" + x.accountNo + "]" }), "id", "accountName"); //var lookupId = int.Parse(categoryId); ////var model = await this.GetFullAndPartialViewModel(lookupId); return PartialView("_PartialPage1"); }
// GET: /JournalAdjustment/Delete/5 public ActionResult Delete(string id) { 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() }); if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } journalHeader journalheader = db.journalHeaders.Find(id); if (journalheader == null) { return HttpNotFound(); } #region getDataDetail var data = db.journalDetails.Where(x => x.voucherNo == id).ToList(); var model = new journalHeader(); for (int i = 0; i < data.Count(); i++) { int idCoa = Convert.ToInt32(data[i].coaId.ToString()); string othrAccountName = data[i].accountNameOther.ToString(); string remak = data[i].remarks.ToString(); decimal debt = Convert.ToDecimal(data[i].debit.ToString()); decimal credt = Convert.ToDecimal(data[i].credit.ToString()); var coaName = db.chartOfAccounts.Where(x => x.id == idCoa).ToList(); var editor = new journalHeader.journalDetail() { coaId = idCoa, accountNameOther = coaName[0].accountName/*othrAccountName*/, remarks = remak, debit = debt, credit = credt }; model.detailJournal.Add(editor); //ViewData["ddlAccount" + (i + 1)] = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { x.id, accountName = /*"[" + */x.accountNo/* + "] " + x.accountName */ }), "id", "accountName", idCoa); ViewData["ddlAccount" + (i + 1)] = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { id = x.id + "-" + x.accountName, accountName = x.accountNo }), "id", "accountName", (idCoa + "-" + coaName[0].accountName)); } ViewData["dataDetail"] = model.detailJournal.ToList(); //ViewBag.ddlAccount = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { x.id, accountName = /*"[" + */x.accountNo/* + "] " + x.accountName */ }), "id", "accountName"); ViewBag.ddlAccount = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { id = x.id + "-" + x.accountName, accountName = x.accountNo }), "id", "accountName"); #endregion return View(journalheader); }
public ActionResult Edit([Bind(Include = "voucherNo,voucherDate,journalType,remark,createdDate,createdUser,modifiedDate,modifiedUser")] journalHeader journalheader, string hdnTotalRows) { 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 journal var countChk = 0; for (int i = 0; i < Request.Form.Count; i++) { if (Request.Form.AllKeys.ToList()[i].Contains("ddlAccount_")) countChk++; } var model = new journalHeader(); for (int i = 1; i <= countChk; i++) { var ddlValue = Request.Form["ddlAccount_" + i]; if (ddlValue == "") break; var acctName = Request.Form["txtAccountName_" + i]; var remark = Request.Form["txtRemark_" + i]; var debit = Request.Form["txtDebit_" + i].Trim() == "" ? "0" : Request.Form["txtDebit_" + i]; var credit = Request.Form["txtCredit_" + i].Trim() == "" ? "0" : Request.Form["txtCredit_" + i]; string[] ddlVal = ddlValue.ToString().Split('-'); var editor = new journalHeader.journalDetail() { coaId = Convert.ToInt32(ddlVal[0].ToString()), accountNameOther = acctName.ToString(), remarks = remark.ToString(), debit = Convert.ToDecimal(Convert.ToDouble(debit.ToString().Replace('.', ','))), credit = Convert.ToDecimal(Convert.ToDouble(credit.ToString().Replace('.', ','))) }; model.detailJournal.Add(editor); ViewData["ddlAccount_" + i] = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { x.id, accountName = /*"[" + */x.accountNo/* + "] " + x.accountName */ }), "id", "accountName", ddlValue); } ViewData["dataDetail"] = model.detailJournal.ToList(); #endregion ViewBag.ddlAccount = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { id = x.id + "-" + x.accountName, accountName = x.accountName + " [" + x.accountNo + "]" }), "id", "accountName"); if (ModelState.IsValid) { lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin; try { using (TransactionScope ts = new TransactionScope()) { var ids = db.journalHeaders.AsNoTracking().Where(x => x.voucherNo == journalheader.voucherNo).ToList(); long id = ids[0].id; journalheader.id = id; journalheader.modifiedDate = DateTime.Now; journalheader.modifiedUser = lvm.userID; db.Entry(journalheader).State = EntityState.Modified; //db.SaveChanges(); #region insertDetail bool runFirst = true; for (int i = 1; i <= countChk; i++) { if (runFirst == true) { db.journalDetails.RemoveRange(db.journalDetails.Where(x => x.voucherNo == journalheader.voucherNo)); //db.SaveChanges(); runFirst = false; } var ddlValue = Request.Form["ddlAccount_" + i]; if (ddlValue == "" || ddlValue == null) break; var acctName = Request.Form["txtAccountName_" + i]; var remark = Request.Form["txtRemark_" + i]; var debit = Request.Form["txtDebit_" + i].Trim() == "" ? "0" : Request.Form["txtDebit_" + i]; var credit = Request.Form["txtCredit_" + i].Trim() == "" ? "0" : Request.Form["txtCredit_" + i]; string[] ddlVal = ddlValue.ToString().Split('-'); db.journalDetails.Add(new journalHeader.journalDetail() { voucherNo = journalheader.voucherNo, //coaId = Convert.ToInt32(ddlValue.ToString()), coaId = Convert.ToInt32(ddlVal[0].ToString()), accountNameOther = acctName.ToString(), remarks = remark.ToString(), debit = Convert.ToDecimal(Convert.ToDouble(debit.ToString().Replace('.', ','))), credit = Convert.ToDecimal(Convert.ToDouble(credit.ToString().Replace('.', ','))) }); } #endregion db.SaveChanges(); ts.Complete(); } return RedirectToAction("Index"); } catch(Exception exc) { } } return View(journalheader); }
public ActionResult Create([Bind(Include = "voucherNo,voucherDate,journalType,remark,createdDate,createdUser,modifiedDate,modifiedUser")] journalHeader journalheader, string hdnTotalRows) { 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() }); //ViewBag.ddlAccount = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { x.id, accountName = x.accountName + " [" + x.accountNo + "]" }), "id", "accountName"); ViewBag.ddlAccount = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { id = x.id + "-" + x.accountName, accountName = x.accountName + " [" + x.accountNo + "]" }), "id", "accountName"); #region collect detail journal var countChk = 0; for (int i = 0; i < Request.Form.Count; i++) { if (Request.Form.AllKeys.ToList()[i].Contains("ddlAccount_")) countChk++; } var model = new journalHeader(); for (int i = 1; i <= countChk; i++) { var ddlValue = Request.Form["ddlAccount_"+i]; if (ddlValue == "") break; var acctName = Request.Form["txtAccountName_" + i]; var remark = Request.Form["txtRemark_" + i]; var debit = Request.Form["txtDebit_" + i].Trim() == "" ? "0" : Request.Form["txtDebit_" + i]; var credit = Request.Form["txtCredit_" + i].Trim() == "" ? "0" : Request.Form["txtCredit_" + i]; string[] ddlVal = ddlValue.ToString().Split('-'); var editor = new journalHeader.journalDetail() { coaId = Convert.ToInt32(ddlVal[0].ToString()), accountNameOther = acctName.ToString(), remarks = remark.ToString(), debit = Convert.ToDecimal(Convert.ToDouble(debit.ToString().Replace('.', ','))), credit = Convert.ToDecimal(Convert.ToDouble(credit.ToString().Replace('.', ','))) }; model.detailJournal.Add(editor); ViewData["ddlAccount_" + i] = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { x.id, accountName = /*"[" + */x.accountNo/* + "] " + x.accountName */ }), "id", "accountName", ddlValue); } ViewData["dataDetail"] = model.detailJournal.ToList(); #endregion if (ModelState.IsValid) { lvm = Session["sessionUserLogin"] as LoginViewModel.userLogin; try { using(TransactionScope ts = new TransactionScope()) { string vouchNo = "ADJ" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("d2"); //var voucherNoCreated = db.journalHeaders.Where(x => x.voucherNo.Contains("ADJ")).OrderByDescending(x => x.id).Select(x => x.id).ToList(); var voucherNoCreated = db.journalHeaders.Where(x => x.voucherNo.Contains(vouchNo)).OrderByDescending(x => x.id).Select(x => x.voucherNo).ToList(); if (voucherNoCreated.Count == 0) { journalheader.voucherNo = "ADJ" + DateTime.Now.Year + DateTime.Now.Month.ToString("d2") + "0001"; } else { journalheader.voucherNo = "ADJ" + DateTime.Now.Year + DateTime.Now.Month.ToString("d2") + (Convert.ToInt32(voucherNoCreated[0].Substring((voucherNoCreated[0].Length - 4))) + 1).ToString().PadLeft(4, '0'); } journalheader.createdDate = DateTime.Now; journalheader.createdUser = ""; db.journalHeaders.Add(journalheader); db.SaveChanges(); if (journalheader.id > 0)//var groupIdH = db.UserGroupHs.OrderByDescending(x => x.id).Select(x => x.id).First(); <--cara lain { #region insertDetail for (int i = 1; i <= countChk; i++) { var ddlValue = Request.Form["ddlAccount_" + i]; if (ddlValue == "" || ddlValue == null) break; var acctName = Request.Form["txtAccountName_" + i]; var remark = Request.Form["txtRemark_" + i]; var debit = Request.Form["txtDebit_" + i].Trim() == "" ? "0" : Request.Form["txtDebit_" + i]; var credit = Request.Form["txtCredit_" + i].Trim() == "" ? "0" : Request.Form["txtCredit_" + i]; string[] ddlVal = ddlValue.ToString().Split('-'); db.journalDetails.Add(new journalHeader.journalDetail() { voucherNo = journalheader.voucherNo, //coaId = Convert.ToInt32(ddlValue.ToString()), coaId = Convert.ToInt32(ddlVal[0].ToString()), accountNameOther = acctName.ToString(), remarks = remark.ToString(), debit = Convert.ToDecimal(Convert.ToDouble(debit.ToString().Replace('.', ','))), credit = Convert.ToDecimal(Convert.ToDouble(credit.ToString().Replace('.', ',')))//Convert.ToInt32(credit.ToString()) }); } db.SaveChanges(); #endregion } ts.Complete(); } return RedirectToAction("Index"); } catch(Exception exc) { string a = exc.Message; } } return View(journalheader); }
// GET: /JournalAdjustment/Create public ActionResult Create() { 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() }); journalHeader jh = new journalHeader(); jh.voucherDate = DateTime.Now; ViewBag.dataDetail = null; //ViewBag.ddlAccount = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { x.id, accountName = x.accountName + " [" + x.accountNo + "]" }), "id", "accountName"); ViewBag.ddlAccount = new SelectList(db.chartOfAccounts.Where(x => x.levelID == 3 && x.accountNo != "").Select(x => new { id = x.id+"-"+x.accountName , accountName = x.accountName + " [" + x.accountNo + "]" }), "id", "accountName"); return View(jh); }