You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

303 lines
18 KiB
C#

9 months ago
using System;
using System.Data;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsCtInitialBalanceDAL;
using DSWeb.MvcShipping.DAL.MsCtBankJournalDAL;
using DSWeb.MvcShipping.Models.MsCtBankJournal;
using DSWeb.MvcShipping.Models.MsCwVouchersGl;
using DSWeb.MvcShipping.Models.MsCwVouitemsGl;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using HcUtility.Comm;
using HcUtility.Core;
using System.Collections.Generic;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.DAL;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsCtBankJournalController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
#region 查询
public ContentResult GetDataList(int start, int limit, string sort, string condition, string condition3)
{
var dataList = MsCtBankJournalDAL.GetDataList(condition, condition3, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition)
{
MsCtBankJournal head = null;
head = MsCtBankJournalDAL.GetData(condition, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult GetDetailList(string condition)
{
var dataList = MsCtBankJournalDAL.GetDetailList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
#endregion
#region 返回出纳当前账套和会计期间
public ContentResult GetInitData(string isInitial)
{
var strList = MsCtBankJournalDAL.GetInitData(isInitial, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
if (strList.Trim() == "-1")
{
var json = JsonConvert.Serialize(new { Success = false, Message = "请先设置对应的出纳账套信息!", data = "" });
return new ContentResult() { Content = json };
}
else
{
var json = JsonConvert.Serialize(new { Success = true, Message = "操作成功!", data = strList });
return new ContentResult() { Content = json };
}
}
#endregion
#region 明细表保存
public ContentResult SaveEdit(string body)//, string DelBody, string data_v
{
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
string strACCDATE = BasicDataRefDAL.GetCtACCDATE(Convert.ToString(Session["USERID"]));
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(Convert.ToString(Session["USERID"]));
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var bodyList = JsonConvert.Deserialize<List<MsCtBankJournal>>(body.Replace("T00:00:00", ""));
//var DelBodyList = JsonConvert.Deserialize<List<MsCtBankJournal>>(DelBody.Replace("T00:00:00", ""));
var isPost = true;
var errorstr = "";
var sVOUDATE = "";
MsCtBankJournal headRowLS = new MsCtBankJournal();
//
if (isPost)
{
//删除列表中的多余数据
//if (DelBodyList != null)
//{
// foreach (var enumValue in DelBodyList)
// {
// MsCtBankJournalDAL.DeleteDetail(enumValue, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
// }
//}
//添加、修改数据
DBResult result = new DBResult();
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
MsCtBankJournal headRow = new MsCtBankJournal();
headRowLS = headRow;
#region 默认值
headRow.ISINITIAL = enumValue.ISINITIAL;//是否期初
headRow.ACCGID = enumValue.ACCGID == null ? "" : enumValue.ACCGID.ToString().Trim();//科目GID
headRow.FCYNO = enumValue.FCYNO == null ? "" : enumValue.FCYNO.ToString().Trim();//外币编号usd
headRow.VOUDATE = enumValue.VOUDATE;//凭证日期
sVOUDATE = headRow.VOUDATE.ToString();
string sMonth = headRow.VOUDATE.Month.ToString();
if (sMonth.Length == 1)
{
sMonth = "0" + sMonth;
}
int iITEMNO = int.Parse(T_ALL_DA.GetStrSQL("iITEMNO", "select isnull((select top 1 isnull(ITEMNO,0) as iITEMNO from ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + sVOUDATE + "' order by VOUDATE desc,convert(decimal(10),ITEMNO) desc),0) as iITEMNO"));
headRow.ITEMNO = iITEMNO+1;//当日序号
headRow.VGID = enumValue.VGID == null ? "" : enumValue.VGID.ToString().Trim();//凭证明细GID
headRow.VKNO = enumValue.VKNO == null ? "" : enumValue.VKNO.ToString().Trim();//凭证字
headRow.VOUNO = enumValue.VOUNO == null ? "" : enumValue.VOUNO.ToString().Trim();//凭证号
headRow.FENTRYID = enumValue.FENTRYID;//分录号
headRow.ACCDATE = enumValue.ACCDATE == null ? "" : enumValue.ACCDATE.ToString().Trim();//会计期间
if (headRow.ISINITIAL)
{
headRow.ACCDATE = headRow.VOUDATE.Year + "-" + sMonth;//会计期间
}
headRow.SETTLETYPE = enumValue.SETTLETYPE;//结算方式
headRow.BILLNO = enumValue.BILLNO == null ? "" : enumValue.BILLNO.ToString().Trim();//结算号
headRow.SVOUDATE = enumValue.SVOUDATE;//结算日期
headRow.DC = enumValue.DC == null ? "" : enumValue.DC.ToString().Trim();//余额方向
headRow.DR = enumValue.DR;//原币借方金额(互斥)
headRow.CR = enumValue.CR;//原币贷方金额(互斥)
headRow.FCYEXRATE = enumValue.FCYEXRATE;//汇率
headRow.QTYDR = Math.Round((headRow.DR * headRow.FCYEXRATE), 2, MidpointRounding.AwayFromZero);//折合本位币借方
headRow.QTYCR = Math.Round((headRow.CR * headRow.FCYEXRATE), 2, MidpointRounding.AwayFromZero);//折合本位币贷方
headRow.BLC = 0;//原币余额
headRow.EXPLAN = enumValue.EXPLAN == null ? "" : enumValue.EXPLAN.ToString().Trim();//摘要,规则生成
headRow.ENTERED = enumValue.ENTERED == null ? "" : enumValue.ENTERED.ToString().Trim();//经手人
headRow.CHECKINGGID = "";//对账GID
headRow.STARTGID = strCtSTARTGID;//账套启用GID
headRow.CORPID = Convert.ToString(Session["COMPANYID"]);//分公司GID
headRow.CREATEUSER = Convert.ToString(Session["USERID"]);//制单人GID
headRow.CREATETIME = DateTime.Now;//创建时间
headRow.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//最后一次更改操作人GID
headRow.MODIFIEDTIME = DateTime.Now;//最后一次更改操作时间
#endregion
if (enumValue.GID.ToString().Trim() == "*")//"add"
{
headRow.GID = Guid.NewGuid().ToString();
headRow.DbOperationType = DbOperationType.DbotIns;
}
else//"edit"
{
headRow.GID = enumValue.GID.ToString().Trim();//唯一编码
headRow.DbOperationType = DbOperationType.DbotUpd;
headRow.ModelUIStatus = "E";
}
var modb = new ModelObjectDB();
result = modb.Save(headRow);
if (result.Message.ToString().IndexOf("插入重复键") > -1)
{
errorstr += "重复数据不再重复插入!";
}
if (result.Success)
{
//更新期初余额
if (headRow.ISINITIAL)
{
MsCtBankJournalDAL.onINITIAL(headRow, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
}
}
}
//更新期初余额
if (!headRowLS.ISINITIAL)
{
#region 插入更新余额
//插入更新余额
MsCtBankJournalDAL.onBLC(headRowLS, true, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
#endregion
#region 插入更新总账表
string lsSql = "SELECT ACCGID,FCYNO,VOUDATE"
+ " from ct_bank_journal WITH(NOLOCK)"
// + " where STARTGID='" + headRowLS.STARTGID + "' and (CHECKINGGID='' or CHECKINGGID is null) "
+ " where STARTGID='" + headRowLS.STARTGID + "' "
+ " and ACCGID='" + headRowLS.ACCGID.ToString() + "' and FCYNO='" + headRowLS.FCYNO.ToString() + "'"
+ " and ACCDATE>='" + headRowLS.VOUDATE.ToString("yyyy-MM") + "'"
+ " group by ACCGID,FCYNO,VOUDATE order by ACCGID,FCYNO,VOUDATE";
DataSet ds3 = T_ALL_DA.GetAllSQL(lsSql);
if (ds3 != null)
{
if (ds3.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds3.Tables[0].Rows)
{
MsCtBankJournal headRow = new MsCtBankJournal();
headRow.ACCGID = dr["ACCGID"].ToString();//科目GID
headRow.FCYNO = dr["FCYNO"].ToString();//外币编号usd
headRow.VOUDATE = DateTime.Parse(dr["VOUDATE"].ToString());//凭证日期
//插入更新总账表
MsCtBankJournalDAL.onCtGenlegAccitems(headRow, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
}
}
}
#endregion
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsCtBankJournalDAL.GetData("CONVERT(varchar(100), VOUDATE, 23)='" + sVOUDATE + "'", Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var jsonRespose = new JsonResponse { Success = false, Message = errorstr + "重复,不允许保存!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
#endregion
#region 删除
public ContentResult Delete(string gids)
{
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
DBResult result = MsCtBankJournalDAL.Delete(gids, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 导入
//判断是否有重复数据
public ContentResult isImportExcelGID(string condition)
{
DBResult result = MsCtBankJournalDAL.isImportExcelGID(condition, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//获取符合条件的所有GID的字符串
public ContentResult onImportExcelData(string condition, string sTYPE)
{
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
DBResult result = MsCtBankJournalDAL.onImportExcelData(condition, sTYPE, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//获取符合条件的所有GID的字符串
public ContentResult onImportExcelData2(string condition)
{
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
DBResult result = MsCtBankJournalDAL.onImportExcelData2(condition, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//判断是否有重复数据
public ContentResult isImportExcelGID2(string gids)
{
DBResult result = MsCtBankJournalDAL.isImportExcelGID2(gids, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//按条导入或覆盖数据
public ContentResult onImportExcelGID2(string gids, string sTYPE, string sCtGID)
{
DBResult result = MsCtBankJournalDAL.onImportExcelGID2(gids, sTYPE, sCtGID, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
}
}