public IActionResult Create(Guid id, Guid idtype) { var sal = User._getuserSalMaliDef(); var x = db.TblContracts.Find(id); if (x != null) { idtype = (Guid)x.FkContractType; if (x.FkSalmali != sal) { return(RedirectToAction(nameof(Index), new { idtype = idtype })); } } else { x = new web_db._Weighing.TblContract(); var s = db.TblSalMalis.Find(sal); if (s != null) { x.Azdate = s.SalAz.Date; x.Tadate = s.SalTa.Date; } x.Code = Convert.ToInt64((db.TblContracts.Where(a => a.FkSalmali == sal).Max(a => (long?)a.Code) ?? 0) + 1); } ViewData["type"] = db.TblContractTypes.Find(idtype); x.FkContractType = idtype; ViewData["listcustumer"] = db.TblCustomers.Include(a => a.TblContracts).Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.IsEnable).OrderBy(a => a.Code).Select(a => new web_sard.Models.tbls.customer.customer(a, db, web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad, false)).ToList(); return(View(new Models.tbls.contract.contract(x, db, true))); }
public contract(web_db._Weighing.TblContract row, web_db.sardweb_Context db, bool isProductsPackings = false, bool mohasebeMande = false, Guid?fkportageadd = null, bool kiloview = true) { var cus = db.TblCustomers.Find(row.FkCustomer) ?? new web_db.TblCustomer(); this.Azdate = row.Azdate.ToPersianDate(); this.Code = Convert.ToDouble(row.Code); this.Date = row.Date; this.FkContractType = row.FkContractType; this.FkCustomer = row.FkCustomer; this.FkSalmali = row.FkSalmali; this.Id = row.Id; this.Tadate = row.Tadate.ToPersianDate(); this.Txt = row.Txt; this.CountMaxIn = row.CountMaxIn; this.WeightMaxIn = row.WeightMaxIn; this.PercentForOut = row.PercentForOut; this.CountMaxOut = row.CountMaxOut; this.WeightMaxOut = row.WeightMaxOut; this.PriceOfBoxIn = row.PriceOfBoxIn; this.PriceOfKiloIn = row.PriceOfKiloIn; this.PriceOfBoxOut = row.PriceOfBoxOut; this.PriceOfKiloOut = row.PriceOfKiloOut; this.dateadd = row.Dateadd.ToPersianDatenull(); this.dateedit = row.Dateedit.ToPersianDatenull(); this.useradd = (db.TblUsers.Find(row.FkUsAdd) ?? new web_db.TblUser()).Title; this.useredit = (db.TblUsers.Find(row.FkUsEdit) ?? new web_db.TblUser()).Title; this.Custumer = cus.Title + " (" + cus.Code + ")"; this._WeightIn = row.SumInWeight; this._WeightOut = row.SumOutWeight; this._CountOut = -row.SumOutCount; this._CountIn = -row.SumInCount; prodocts = new List <Models.tbls.alltbl>(); prodoctsId = new List <Guid>(); packings = new List <Models.tbls.alltbl>(); packingsId = new List <Guid>(); this.ContractType = new ContractType(db.TblContractTypes.Find(row.FkContractType)); if (isProductsPackings) { var listp = db.TblContractProducts.Where(a => a.FkContract == this.Id).Include(a => a.FkProductNavigation); foreach (var item in listp) { prodoctsId.Add(item.FkProduct); prodocts.Add(new alltbl { code = item.FkProductNavigation.Code, key = item.FkProduct, title = item.FkProductNavigation.Title }); } var listpp = db.TblContractPackings.Where(a => a.FkContract == this.Id).Include(a => a.FkPackingNavigation); foreach (var item in listpp) { packingsId.Add(item.FkPacking); packings.Add(new alltbl { code = item.FkPackingNavigation.Code, key = item.FkPacking, title = item.FkPackingNavigation.Title }); } } this.mandeHesab = new List <mandeHesabclass>(); if (mohasebeMande) { var x = from n in db.TblPortageRows.Include(a => a.FkPortageNavigation) where n.FkContract == row.Id && ( (n.FkPortage.HasValue ? n.FkPortageNavigation.IsEnd : true) || n.FkPortage == fkportageadd ) select n; mandeHesab.Add(new mandeHesabclass(x, this, db, true, kiloview)); var t = x.AsEnumerable().GroupBy(a => new { a.FkPacking, a.FkProduct }).ToList(); foreach (var item in t) { var str = (db.TblProducts.SingleOrDefault(a => a.Id == item.Key.FkProduct) ?? new web_db._Weighing.TblProduct()).Title + " " + (db.TblPackings.SingleOrDefault(a => a.Id == item.Key.FkPacking) ?? new web_db._Weighing.TblPacking()).Title; mandeHesab.Add(new mandeHesabclass(item.Select(a => a), this, db, false, kiloview) { txt = str }); } } }
public IActionResult Create(Models.tbls.contract.contract model, bool sendSMS) { var sal = User._getuserSalMaliDef(); var ContractType = db.TblContractTypes.Find(model.FkContractType); var x = db.TblContracts.Find(model.Id); if (ContractType.KindCotractType == web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad) { var conf = ContractType.ConfigASabad(); ModelState.Remove("WeightMaxIn"); ModelState.Remove("WeightMaxOut"); ModelState.Remove("prodoctsId"); if (conf.IsEntry == false) { ModelState.Remove("CountMaxIn"); } if (conf.IsExit == false) { ModelState.Remove("CountMaxOut"); } { ModelState.Remove("WeightMaxOut"); ModelState.Remove("PercentForOut"); } if (ModelState.IsValid) { { var x2 = db.TblContracts.Where(a => a.Code == model.Code && a.FkSalmali == sal); if (x2.Any() && x2.Single().Id != x.Id) { x.Code = Convert.ToInt64((db.TblContracts.Where(a => a.FkSalmali == sal).Max(a => (long?)a.Code) ?? 0) + 1); } } if (x == null) { x = new web_db._Weighing.TblContract { Date = DateTime.Now.Date, Dateadd = DateTime.Now, FkContractType = model.FkContractType, FkSalmali = User._getuserSalMaliDef(), FkUsAdd = User._getuserid().Value, Id = Guid.NewGuid(), FkCustomer = model.FkCustomer }; db.TblContracts.Add(x); } else { x.FkUsEdit = User._getuserid(); x.Dateedit = DateTime.Now; } x.Code = model.Code; x.Azdate = model.Azdate.ToDate(); x.Tadate = model.Tadate.ToDate(); x.WeightMaxIn = model.WeightMaxIn; x.CountMaxIn = model.CountMaxIn; x.WeightMaxOut = model.WeightMaxOut; x.CountMaxOut = model.CountMaxOut; x.PercentForOut = model.PercentForOut; x.IsEndVrud = model.isEndVrud; x.IsEndXroj = model.isEndXroj; x.Txt = model.Txt ?? ""; x.PriceOfBoxIn = model.PriceOfBoxIn ?? 0; x.PriceOfBoxOut = model.PriceOfBoxOut ?? 0; x.PriceOfKiloIn = model.PriceOfKiloIn ?? 0; x.PriceOfKiloOut = model.PriceOfKiloOut ?? 0; db.TblContractPackings.RemoveRange(db.TblContractPackings.Where(a => a.FkContract == x.Id)); foreach (var item in model.packingsId) { db.TblContractPackings.Add(new web_db._Weighing.TblContractPacking { FkContract = x.Id, FkPacking = item }); } if (sendSMS) { x.SendSms = true; } db.SaveChanges(); ViewBag.txt = "ثبت انجام شد"; return(RedirectToAction(nameof(Index), new { idtype = model.FkContractType })); } ViewData["listcustumer"] = db.TblCustomers.Include(a => a.TblContracts).Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.IsEnable).OrderBy(a => a.Code).Select(a => new web_sard.Models.tbls.customer.customer(a, db, web_db._Weighing.TblContractType.KindCotractTypeEnum.ASabad, true)).ToList(); ViewData["type"] = ContractType; ViewBag.error = "لطفا موارد را درست پر کنید"; return(View(model)); } return(null); }
private bool CloneContract(Guid id, int setYear) { var con = db.TblContracts.Find(id); var contype = db.TblContractTypes.Find(con.FkContractType); var contypeclone = db.TblContractTypes.Single(a => a.Code == contype.Code && a.FkSalmali == setYear); var conClone = db.TblContracts.SingleOrDefault(a => a.Code == con.Code && a.FkSalmali == setYear); var customer = db.TblCustomers.Find(con.FkCustomer); var customerClone = db.TblCustomers.SingleOrDefault(a => a.Code == customer.Code && a.FkSalmali == setYear);; #region Clone Contract { if (conClone == null) { conClone = new web_db._Weighing.TblContract { FkSalmali = setYear, Id = Guid.NewGuid(), FkContractType = contypeclone.Id, FkCustomer = customerClone.Id }; db.TblContracts.Add(conClone); } { conClone.Azdate = con.Azdate; conClone.Code = con.Code; conClone.CountMaxIn = con.CountMaxIn; conClone.CountMaxOut = con.CountMaxOut; conClone.Date = con.Date; conClone.Dateadd = con.Dateadd; conClone.Dateedit = con.Dateedit; conClone.FkContractType = contypeclone.Id; conClone.FkCustomer = customerClone.Id; conClone.FkSalmali = setYear; conClone.FkUsAdd = con.FkUsAdd; conClone.FkUsEdit = con.FkUsEdit; conClone.IsEndVrud = con.IsEndVrud; conClone.IsEndXroj = con.IsEndXroj; conClone.PercentForOut = con.PercentForOut; conClone.PriceOfBoxIn = con.PriceOfBoxIn; conClone.PriceOfBoxOut = con.PriceOfBoxOut; conClone.PriceOfKiloIn = con.PriceOfKiloIn; conClone.PriceOfKiloOut = con.PriceOfKiloOut; conClone.Tadate = con.Tadate; conClone.WeightMaxIn = con.WeightMaxIn; conClone.WeightMaxOut = con.WeightMaxOut; conClone.Txt = con.Txt; } } #endregion #region Clone ContractRows { db.TblContractPackings.RemoveRange(db.TblContractPackings.Where(a => a.FkContract == conClone.Id)); db.TblContractProducts.RemoveRange(db.TblContractProducts.Where(a => a.FkContract == conClone.Id)); foreach (var item in db.TblContractPackings.Where(a => a.FkContract == con.Id)) { db.TblContractPackings.Add(new web_db._Weighing.TblContractPacking { FkContract = conClone.Id, FkPacking = item.FkPacking }); } foreach (var item in db.TblContractProducts.Where(a => a.FkContract == con.Id)) { db.TblContractProducts.Add(new web_db._Weighing.TblContractProduct { FkContract = conClone.Id, FkProduct = item.FkProduct }); } } #endregion return(true); }
public IActionResult Create(Guid id, Guid idtype, Guid?idreq) { var sal = User._getuserSalMaliDef(); var x = db.TblContracts.Find(id); Models.tbls.contract.contract model; if (x != null) { idtype = (Guid)x.FkContractType; if (x.FkSalmali != sal) { return(RedirectToAction(nameof(Index), new { idtype = idtype })); } model = new Models.tbls.contract.contract(x, db, true); } else { x = new web_db._Weighing.TblContract(); var s = db.TblSalMalis.Find(sal); if (s != null) { x.Azdate = s.SalAz.Date; x.Tadate = s.SalTa.Date; } model = new Models.tbls.contract.contract(x, db, true); model.Code = Convert.ToInt64((db.TblContracts.Where(a => a.FkSalmali == sal).Max(a => (long?)a.Code) ?? 0) + 1); model.FkContractType = idtype; if (idreq.IsEmpty() == false) { var dbcus = new web_CusDB.db_Context(); var req = dbcus.tblReqContracts.Include(a => a.tblCus).SingleOrDefault(a => a.Id == idreq); if (req == null || req.ContractId.HasValue) { return(Redirect(this.HttpContext.Request.UrlReferer())); } else { var cus = req.tblCus.checkCodeCusMain(); if (cus == null) { ViewBag.ret = this.Request.UrlReferer(); return(View("NoUser")); } var reqrow = dbcus.tblReqContractRows.Where(a => a.TblReqContractId == req.Id).OrderByDescending(a => a.Date).First(); var zarib = (web_sard.Models.cl._conf.SingleOrDefault(a => a.Key == web_db.TblConf.KeyEnum.US_WeightZarib) ?? new web_db.TblConf()).Value.ToInt(1); model.WeightMaxIn = ((int)reqrow.WeightCount) * zarib; var CodeMahsuls = reqrow.CodeMahsuls.FromJson <Guid[]>(); model.prodocts = web_sard.Models.cl._ListProduct.Where(a => CodeMahsuls.Contains(a.Id)).Select( a => new web_sard.Models.tbls.alltbl { code = a.Code, key = a.Id, title = a.Title }).ToList(); model.prodoctsId = model.prodocts.Select(a => a.key).ToList(); idtype = db.TblContractTypes. FirstOrDefault(a => a.FkSalmali == User._getuserSalMaliDef() && a.KindCotractType == req.KindContract).Id; model.FkContractType = idtype; model.FkCustomer = cus.Id; model.TblCustumer = cus; model.Custumer = cus.Title; } } } ViewData["type"] = db.TblContractTypes.Find(idtype); ViewData["idreq"] = idreq; ViewData["listcustumer"] = db.TblCustomers.Include(a => a.TblContracts).Where(a => a.FkSalmali == User._getuserSalMaliDef() && a.IsEnable).OrderBy(a => a.Code).Select(a => new web_sard.Models.tbls.customer.customer(a, db, web_db._Weighing.TblContractType.KindCotractTypeEnum.ASardKhane, false)).ToList(); return(View(model)); }