/// <summary> /// 正版软件 /// </summary> public JsonResult ZBApi() { var sReturnModel = new ReturnDetailModel(); var cBll = new BLL_GenuineSoftware(); var list = cBll.GetObjectAll(); list = list.OrderByDescending(o => o.ID).Distinct().ToList(); sReturnModel.ErrorType = 1; if (list != null) { sReturnModel.Entity = from a in list select new { name = a.Dept_Name, value = a.czxtlx.Count() }; } return(Json(sReturnModel)); }
/// <summary> /// 资源编码——资源编码数量 /// </summary> /// <returns></returns> public JsonResult ZYApi() { var sReturnModel = new ReturnDetailModel(); var cBll = new BLL_ResourceCatalog(); var list = cBll.GetObjectAll(); list = list.OrderByDescending(o => o.ID).Distinct().ToList(); sReturnModel.ErrorType = 1; if (list != null) { sReturnModel.Entity = from a in list select new { name = a.Dept_Name, value = a.zymlsl }; } return(Json(sReturnModel)); }
/// <summary> /// 建设项目——项目预算 /// </summary> /// <returns></returns> public JsonResult JSApi() { var sReturnModel = new ReturnDetailModel(); var cBll = new BLL_ConstructionProject(); var list = cBll.GetObjectAll(); list = list.OrderByDescending(o => o.ID).Distinct().ToList(); sReturnModel.ErrorType = 1; if (list != null) { sReturnModel.Entity = from a in list select new { name = a.Dept_Name, value = a.xmys }; } return(Json(sReturnModel)); }
/// <summary> /// 终端情况 /// </summary> /// <returns></returns> public JsonResult ZDApi() { var sReturnModel = new ReturnDetailModel(); var cBll = new BLL_Terminal(); var list = cBll.GetObjectAll(); list = list.OrderByDescending(o => o.zdsl).Take(5).ToList(); sReturnModel.ErrorType = 1; if (list != null) { sReturnModel.Entity = from a in list select new { name = a.Dept_Name, value = a.zdsl }; } return(Json(sReturnModel)); }
/// <summary> /// 网络情况(光纤) /// </summary> /// <returns></returns> public JsonResult WlApi() { var sReturnModel = new ReturnDetailModel(); var cBll = new BLL_Network(); var list = cBll.GetObjectAll(); list = list.OrderByDescending(o => o.gx).Take(5).ToList(); sReturnModel.ErrorType = 1; if (list != null) { sReturnModel.Entity = from a in list select new { wlAxisData = a.Dept_Name, wlseriesData = a.gx }; } return(Json(sReturnModel)); }
/// <summary> /// 接入外网数量排行 /// </summary> /// <returns></returns> public JsonResult JrwwsjphApi() { var sReturnModel = new ReturnDetailModel(); var cBll = new BLL_Terminal(); var list = cBll.GetObjectAll(); list = list.OrderByDescending(o => o.jrzwwwsl).Take(10).ToList(); sReturnModel.ErrorType = 1; if (list != null) { sReturnModel.Entity = from a in list select new { jrwwsjphAxisData = a.Dept_Name, jrwwsjphseriesData = a.jrzwwwsl }; } return(Json(sReturnModel)); }
public ActionResult InitSingle() { var sReturnModel = new ReturnDetailModel(); #region 登录验证 if (!Utits.IsLogin) { sReturnModel.ErrorType = 3; sReturnModel.MessageContent = "登录状态已失效."; return(Json(sReturnModel)); } #endregion var idcode = RequestParameters.Pint("Code"); if (idcode != 1 && idcode != 0) { sReturnModel.ErrorType = 0; sReturnModel.MessageContent = "参数错误."; return(Json(sReturnModel)); } int id = RequestParameters.Pint("ID"); if (id < 1) { sReturnModel.ErrorType = 0; sReturnModel.MessageContent = "参数错误."; return(Json(sReturnModel)); } var cBll = new BLL_Service(); sReturnModel.ErrorType = 1; if (idcode == 0) { sReturnModel.Entity = cBll.GetObjectSer1ById(id); } else { sReturnModel.Entity = cBll.GetObjectSer2ById(id); } return(Json(sReturnModel)); }
public JsonResult InitSingle() { var sReturnModel = new ReturnDetailModel(); #region 登录验证 if (!Utits.IsLogin) { sReturnModel.ErrorType = 3; sReturnModel.MessageContent = "登录状态已失效."; return(Json(sReturnModel)); } #endregion int id = RequestParameters.Pint("ID"); if (id < 1) { sReturnModel.ErrorType = 0; sReturnModel.MessageContent = "参数错误."; return(Json(sReturnModel)); } var cBll = new BLL_Security(); sReturnModel.ErrorType = 1; sReturnModel.Entity = cBll.GetObjectDeptById(id); return(Json(sReturnModel)); }
public ActionResult Save(ReturnMasterModel model, List <ReturnDetailViewModel> detail, decimal?GuestAmountPaid, int CreateReceipt = 1) { if (ModelState.IsValid) { try { using (TransactionScope ts = new TransactionScope()) { var currentTime = DateTime.Now; #region Lưu ReturnMaster model.CreatedDate = currentTime; model.CreatedAccount = currentAccount.UserName; AccountModel Account = _context.AccountModel.Where(p => p.UserName == model.CreatedAccount).FirstOrDefault(); model.CreatedEmployeeId = Account.EmployeeId; model.InventoryTypeId = EnumInventoryType.XC; //Xuất - Trả hàng cho nhà cung cấp model.Paid = GuestAmountPaid.HasValue ? GuestAmountPaid : 0; model.ReturnMasterCode = GetReturnCode(); model.Actived = true; #endregion var importModel = _context.ImportMasterModel.Where(p => p.ImportMasterId == model.ImportMasterId).FirstOrDefault(); #region Tính số dư còn lại decimal?SuplierOldDebt = _context.AM_DebtModel .Where(p => p.SupplierId == importModel.SupplierId) .OrderByDescending(p => p.TimeOfDebt) .Select(p => p.RemainingAmountAccrued) .FirstOrDefault(); SuplierOldDebt = (SuplierOldDebt == null) ? 0 : SuplierOldDebt.Value; model.RemainingAmount = (model.RemainingAmount == null) ? 0 : model.RemainingAmount.Value; model.RemainingAmountAccrued = SuplierOldDebt.Value - model.RemainingAmount.Value; _context.Entry(model).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); // LƯU TẠM ĐỂ LẤY ReturnMASTERID (SẼ BỊ SCROLLBACK KHI XẢY RA LỖI) #endregion if (CreateReceipt == 1) { #region Thêm vào giao dịch kế toán AM_TransactionModel AMmodel; #region TH1 : nhận đủ if (model.TotalPrice == GuestAmountPaid) { AMmodel = new AM_TransactionModel() { StoreId = model.StoreId, AMAccountId = (_context.AM_AccountModel.Where(p => p.Code == EnumAccountCode.TM && p.AMAccountTypeCode == EnumAM_AccountType.TIENMAT && p.StoreId == model.StoreId).Select(p => p.AMAccountId)).FirstOrDefault(), TransactionTypeCode = EnumTransactionType.NXXUAT, ContactItemTypeCode = EnumContactType.NCC, CustomerId = null, SupplierId = model.SupplierId, EmployeeId = null, OtherId = null, Amount = GuestAmountPaid, OrderId = null, ImportMasterId = model.ImportMasterId, IEOtherMasterId = null, Note = model.Note, CreateDate = currentTime, CreateEmpId = currentEmployee.EmployeeId, RemainingAmountAccrued = model.RemainingAmountAccrued }; _context.Entry(AMmodel).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); } #endregion #region TH2 : Không nhận lưu vào công nợ else if (GuestAmountPaid == 0 || GuestAmountPaid == null) { AMmodel = new AM_TransactionModel() { StoreId = model.StoreId, AMAccountId = (_context.AM_AccountModel.Where(p => p.Code == EnumAccountCode.PTNCC && p.AMAccountTypeCode == EnumAM_AccountType.CONGNO && p.StoreId == model.StoreId).Select(p => p.AMAccountId)).FirstOrDefault(), TransactionTypeCode = EnumTransactionType.NXXUAT, ContactItemTypeCode = EnumContactType.NCC, CustomerId = null, SupplierId = model.SupplierId, EmployeeId = null, OtherId = null, Amount = model.TotalPrice, OrderId = null, ImportMasterId = model.ImportMasterId, IEOtherMasterId = null, Note = model.Note, CreateDate = currentTime, CreateEmpId = currentEmployee.EmployeeId, RemainingAmountAccrued = model.RemainingAmountAccrued }; _context.Entry(AMmodel).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); } #endregion #region TH3 : nhận 1 phần else { #region 1 phần (Tiền mặt hoặc chuyển khoản) AMmodel = new AM_TransactionModel() { StoreId = model.StoreId, AMAccountId = (_context.AM_AccountModel.Where(p => p.Code == EnumAccountCode.TM && p.AMAccountTypeCode == EnumAM_AccountType.TIENMAT && p.StoreId == model.StoreId).Select(p => p.AMAccountId)).FirstOrDefault(), TransactionTypeCode = EnumTransactionType.NXXUAT, ContactItemTypeCode = EnumContactType.NCC, CustomerId = null, SupplierId = model.SupplierId, EmployeeId = null, OtherId = null, Amount = GuestAmountPaid, OrderId = null, ImportMasterId = model.ImportMasterId, IEOtherMasterId = null, Note = model.Note, CreateDate = currentTime, CreateEmpId = currentEmployee.EmployeeId, RemainingAmountAccrued = model.RemainingAmountAccrued }; _context.Entry(AMmodel).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); #endregion #region 1 phần đưa vào công nợ AMmodel = new AM_TransactionModel() { StoreId = model.StoreId, AMAccountId = (_context.AM_AccountModel.Where(p => p.Code == EnumAccountCode.PTNCC && p.AMAccountTypeCode == EnumAM_AccountType.CONGNO && p.StoreId == model.StoreId).Select(p => p.AMAccountId)).FirstOrDefault(), TransactionTypeCode = EnumTransactionType.NXXUAT, ContactItemTypeCode = EnumContactType.NCC, CustomerId = null, SupplierId = model.SupplierId, EmployeeId = null, OtherId = null, Amount = model.TotalPrice - GuestAmountPaid, OrderId = null, ImportMasterId = model.ImportMasterId, IEOtherMasterId = null, Note = model.Note, CreateDate = currentTime, CreateEmpId = currentEmployee.EmployeeId, RemainingAmountAccrued = model.RemainingAmountAccrued }; _context.Entry(AMmodel).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); #endregion } #endregion #endregion } #region Thêm AM_DebtModel (Số nợ còn lại) if (model.RemainingAmount > 0) { var AMDebModel = new AM_DebtModel() { SupplierId = importModel.SupplierId, TimeOfDebt = currentTime, RemainingAmountAccrued = model.RemainingAmountAccrued, ReturnMasterId = model.ReturnMasterId, TransactionTypeCode = EnumTransactionType.NXXUAT }; _context.Entry(AMDebModel).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); } #endregion #region Lưu InventoryMaster InventoryMasterModel InvenMaster = new InventoryMasterModel(); InvenMaster.WarehouseModelId = model.WarehouseId; InvenMaster.InventoryCode = model.ReturnMasterCode; InvenMaster.InventoryTypeId = EnumInventoryType.XC; //Xuất - Trả hàng cho nhà cung cấp InvenMaster.CreatedDate = model.CreatedDate; InvenMaster.CreatedAccount = model.CreatedAccount; InvenMaster.CreatedEmployeeId = model.CreatedEmployeeId; InvenMaster.Actived = true; InvenMaster.BusinessId = model.ReturnMasterId; // Id nghiệp vụ InvenMaster.BusinessName = "ReturnMasterModel"; // Tên bảng nghiệp vụ InvenMaster.ActionUrl = "/ReturnMaster/Details/"; // Đường dẫn ( cộng ID cho truy xuất) InvenMaster.StoreId = model.StoreId; _context.Entry(InvenMaster).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); // insert tạm để lấy InvenMasterID #endregion #region duyệt list lưu ReturnDetail và InvenrotyDetail decimal TotalQty = 0; foreach (var item in detail) { if (item.ReturnQty > 0) // Chỉ tính Số lượng trả > 0 { TotalQty += item.ReturnQty.Value; #region Lưu ReturnDetailModel //// Lấy ReturnedQty mới nhất //var tempLanDaTraCuoi = (from detal in _context.ReturnDetailModel // join master in _context.ReturnMasterModel on detal.ReturnMasterId equals master.ReturnMasterId // orderby detal.ReturnDetailId descending // where master.Actived == true && detal.ProductId == item.ProductId // select new // { // LanDaTraCuoi = detal.ReturnedQty.Value // }).FirstOrDefault(); decimal CogsInOd = _context.ImportDetailModel.Where(p => p.ImportMasterId == model.ImportMasterId && p.ProductId == item.ProductId).Select(p => p.UnitCOGS.Value).FirstOrDefault(); item.UnitCOGS = CogsInOd; ReturnDetailModel detailmodel = new ReturnDetailModel() { ReturnMasterId = model.ReturnMasterId, ProductId = item.ProductId, ImportQty = item.ImportQty, //ReturnedQty = (tempLanDaTraCuoi == null ? 0 + (item.ReturnQty.HasValue ? item.ReturnQty : 0) : tempLanDaTraCuoi.LanDaTraCuoi + (item.ReturnQty.HasValue ? item.ReturnQty : 0)), ReturnedQty = item.ReturnedQty, InventoryQty = item.InventoryQty, ReturnQty = item.ReturnQty.HasValue ? item.ReturnQty : 0, Price = item.Price, UnitShippingWeight = item.UnitShippingWeight, UnitPrice = item.UnitPrice, Note = item.Note, ShippingFee = item.ShippingFee, UnitCOGS = item.UnitCOGS }; //_context.Entry(detailmodel).State = System.Data.Entity.EntityState.Added; model.ReturnDetailModel.Add(detailmodel); _context.SaveChanges(); #endregion #region Lưu InventoryDetail //var temp = _context.InventoryDetailModel.OrderByDescending(p => p.InventoryDetailId).Where(p => p.ProductId == item.ProductId).Select(p => p.EndInventoryQty).FirstOrDefault(); //var temp = (from detal in _context.InventoryDetailModel // join master in _context.InventoryMasterModel on detal.InventoryMasterId equals master.InventoryMasterId // orderby detal.InventoryDetailId descending // where master.Actived == true && detal.ProductId == item.ProductId // select new // { // TonCuoi = detal.EndInventoryQty.Value // }).FirstOrDefault(); //decimal tondau; //if (temp != null) //{ // tondau = Convert.ToInt32(temp.TonCuoi); //} //else //{ // tondau = 0; //} EndInventoryRepository EndInventoryRepo = new EndInventoryRepository(_context); decimal tondau = EndInventoryRepo.GetQty(item.ProductId.Value); var tempt2 = _context.ProductModel.Where(p => p.ProductId == item.ProductId).FirstOrDefault(); decimal GiaVon = tempt2.COGS.HasValue ? tempt2.COGS.Value : 0; InventoryDetailModel InvenDetail = new InventoryDetailModel() { InventoryMasterId = InvenMaster.InventoryMasterId, ProductId = item.ProductId, BeginInventoryQty = tondau, //COGS = GiaVon, Price = item.Price, //ImportQty = 0, ExportQty = item.ReturnQty.HasValue ? item.ReturnQty : 0,// Xuất //UnitCOGS = GiaVon * (item.ReturnQty.HasValue ? item.ReturnQty : 0), UnitPrice = item.UnitPrice.HasValue ? item.UnitPrice : 0, EndInventoryQty = tondau - (item.ReturnQty.HasValue ? item.ReturnQty : 0) }; _context.Entry(InvenDetail).State = System.Data.Entity.EntityState.Added; // _context.SaveChanges(); } #endregion } #endregion // Cập nhật lại Tổng giá vốn model.SumCOGSOfOrderDetail = detail.Where(p => p.ReturnQty > 0).Sum(p => p.UnitCOGS * p.ReturnQty); model.TotalQty = TotalQty; _context.Entry(model).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); ts.Complete(); // hoàn tất và thực sự lưu vào db return(Json("success", JsonRequestBehavior.AllowGet)); } } catch { return(Json(Resources.LanguageResource.AddErrorMessage, JsonRequestBehavior.AllowGet)); } } else { return(Json(Resources.LanguageResource.AddErrorMessage, JsonRequestBehavior.AllowGet)); } }