public Object AddAuditSave(string parameters) { TableModel model = JsonConvert.DeserializeObject <TableModel>(parameters); using (DBHelper db = new DBHelper()) { //检查是否已经开账 var options = db.First("select * from option"); if (options.content["initoverdate"] == null) { return(new { message = StringHelper.GetString("系统还没有开账,不能保存单据!") }); } //单据日期不能早于开账日期 if (model.content.Value <DateTime>("billdate").CompareTo(options.content.Value <DateTime>("initoverdate")) < 0) { return(new { message = StringHelper.GetString("单据日期不能早于开账日期!") }); } //单据日期不能早于月结存日期 var lastbalance = db.FirstOrDefault("select * from monthbalance order by id desc"); if (lastbalance != null && model.content.Value <DateTime>("billdate").CompareTo(lastbalance.content.Value <DateTime>("balancedate")) <= 0) { return(new { message = StringHelper.GetString("单据日期不能早于月结存日期!") }); } //检查编号重复 int cnt = db.Count("select count(0) as cnt from bill where content->>'billname'='" + billname + "' and content->>'billcode'='" + model.content.Value <string>("billcode") + "'"); if (cnt > 0) { return(new { message = StringHelper.GetString("编号有重复") }); } foreach (var item in model.content.Value <JArray>("details").Values <JObject>()) { item.Remove("product"); } model.content["billname"] = billname; model.content["makerid"] = PluginContext.Current.Account.Id; model.content["createtime"] = DateTime.Now; model.content["auditorid"] = PluginContext.Current.Account.Id; model.content["audittime"] = DateTime.Now; model.content["auditstatus"] = 1; model.content["total"] = model.content.Value <JArray>("details").Values <JObject>().Sum(c => c.Value <decimal>("discounttotal")); string result = model.Audit(db); if (!string.IsNullOrEmpty(result)) { return new { message = "needcost", productids = result } } ; db.SaveChanges(); } return(new { message = "ok", id = model.id }); }
public Object EditAuditSave(string parameters) { TableModel model = JsonConvert.DeserializeObject <TableModel>(parameters); using (DBHelper db = new DBHelper()) { //检查是否已经审核过 if (model.content["auditorid"] != null) { return(new { message = StringHelper.GetString("单据已经审核过,不能修改!") }); } //检查是否已经开账 var options = db.First("select * from option"); if (options.content["initoverdate"] == null) { return(new { message = StringHelper.GetString("系统还没有开账,不能保存单据!") }); } //单据日期不能早于开账日期 if (model.content.Value <DateTime>("billdate").CompareTo(options.content.Value <DateTime>("initoverdate")) < 0) { return(new { message = StringHelper.GetString("单据日期不能早于开账日期!") }); } //单据日期不能早于月结存日期 var lastbalance = db.FirstOrDefault("select * from monthbalance order by id desc"); if (lastbalance != null && model.content.Value <DateTime>("billdate").CompareTo(lastbalance.content.Value <DateTime>("balancedate")) <= 0) { return(new { message = StringHelper.GetString("单据日期不能早于月结存日期!") }); } //检查编号重复 int cnt = db.Count("select count(0) as cnt from bill where id<>" + model.id + " and content->>'billname'='" + billname + "' and content->>'billcode'='" + model.content.Value <string>("billcode") + "'"); if (cnt > 0) { return(new { message = StringHelper.GetString("编号有重复") }); } //model.content["billname"] = billname; model.content["makerid"] = PluginContext.Current.Account.Id; //model.content["createtime"] = DateTime.Now; model.content["auditorid"] = PluginContext.Current.Account.Id; model.content["audittime"] = DateTime.Now; model.content["auditstatus"] = 1; db.Edit("bill", model); model.Audit(db); db.SaveChanges(); } return(new { message = "ok", id = model.id }); }
private string AuditBill(TableModel bill) { string billname = bill.content.Value <string>("billname"); bill.content["auditorid"] = PluginContext.Current.Account.Id; bill.content["audittime"] = DateTime.Now; bill.content["auditstatus"] = 1; using (DBHelper db = new DBHelper()) { db.Edit("bill", bill); string msg = ""; bill.Audit(db, out msg); if (!string.IsNullOrEmpty(msg)) { return(msg); } db.SaveChanges(); } return(string.Empty); }