public ActionResult MasterGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] MasterCompta item) { var model = db.MasterComptas; int modelId = (int)Session["Modelid"]; ViewBag.MasterCompta = item; if (ModelState.IsValid) { try { var modelItem = model.FirstOrDefault(it => it.id == item.id); if (model != null) { this.UpdateModel(modelItem); db.SubmitChanges(); } } catch (Exception e) { ViewData["GenericError"] = e.Message; } } else { ViewData["GenericError"] = IWSLookUp.GetModelSateErrors(ModelState); } return(PartialView("MasterGridViewPartial", IWSLookUp.GetMasterCompta((IWSLookUp.ComptaMasterModelId)modelId))); }
public ActionResult MasterGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] MasterCompta item) { int modelId = (int)Session["Modelid"]; var model = db.MasterComptas; if (ModelState.IsValid) { item.IsValidated = false; item.CompanyId = (string)Session["CompanyID"]; int itemOID = item.oid; if (modelId.Equals((int)IWSLookUp.ComptaMasterModelId.GeneralLedger)) { item.account = "6222"; } item.ModelId = modelId; ViewBag.MasterCompta = item; bool result = false; try { model.InsertOnSubmit(item); result = IWSLookUp.CheckPeriod(item.TransDate, item.CompanyId, true, true); if (result) { db.SubmitChanges(); if (itemOID != 0) { int itemId = db.MasterComptas.Max(i => i.id); result = InsertLines(itemId, itemOID, modelId); if (result) { result = InsertDetailsDetails(itemOID, modelId); } if (result) { db.SubmitChanges(ConflictMode.FailOnFirstConflict); } } } else { ViewData["GenericError"] = $"{IWSLocalResource.GenericError}! {IWSLocalResource.CheckPeriodKeyIn}"; } ViewData["NewKeyValue"] = item.id; } catch (Exception e) { ViewData["GenericError"] = e.Message; } } else { ViewData["GenericError"] = IWSLookUp.GetModelSateErrors(ModelState); } return(PartialView("MasterGridViewPartial", IWSLookUp.GetMasterCompta((IWSLookUp.ComptaMasterModelId)modelId))); }
private void MakeGeneralLedger(string IDs) { decimal amount = 0; int newId = 0; string period = string.Empty; string IDx = string.Empty; IList <string> items = new List <string>(IDs.Split(new string[] { ";" }, StringSplitOptions.None)); foreach (string item in items) { var list = item.Split(new string[] { "," }, StringSplitOptions.None); IDx = list[1]; period = list[2]; amount = Convert.ToDecimal(list[3], CultureInfo.InvariantCulture); ImmoDetailViewModel details = IWSLookUp.GetImmoDetail(IDx, period); MasterCompta header = new MasterCompta() { CostCenter = details.CostCenter, account = "6222", HeaderText = IWSLocalResource.Depreciation, TransDate = details.TransDate, ItemDate = details.ItemDate, EntryDate = details.EntryDate, CompanyId = details.CompanyId, ModelId = (int)IWSLookUp.ComptaMasterModelId.GeneralLedger, IsValidated = false }; newId = MakeGLHeader(header); DetailCompta detailCompta = new DetailCompta() { transid = newId, account = details.OAccount, side = details.Side, oaccount = details.Account, amount = Math.Round(amount, 2), duedate = details.DueDate, Currency = details.Currency, ModelId = (int)IWSLookUp.ComptaMasterModelId.GeneralLedger, Terms = null, text = null, Balanced = false }; newId = MakeGLDetail(detailCompta); if (newId > 0) { UpdateDepreciationDetail(IDx, period); } } }
private int MakeGLHeader(MasterCompta masterCompta) { int id = 0; try { db.MasterComptas.InsertOnSubmit(masterCompta); db.SubmitChanges(ConflictMode.ContinueOnConflict); id = db.MasterComptas.Max(i => i.id); } catch (Exception ex) { IWSLookUp.LogException(ex); } return(id); }