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.

842 lines
29 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using DSWeb.Areas.TruckMng.Models.Comm;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.Import.DAL.Finance;
using DSWeb.Areas.Import.Models.Finance;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.TruckMng.Helper;
using DSWeb.TruckMng.Helper.Repository;
using HcUtility.Comm;
using HcUtility.Core;
using System.Data;
using System.Text;
using System.Web.Script.Serialization;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.SoftMng.BLL;
using DSWeb.SoftMng.Model;
namespace DSWeb.Areas.Import.Controllers
{
[JsonRequestBehavior]
public class FinanceController : Controller
{
//
// GET: /Import/FinanceOut
public ActionResult Index()
{
return View();
}
//
// GET: /Import/FinanceOut/Edit
public ActionResult Edit()
{
return View();
}
public ActionResult AppIndex()
{
return View();
}
//
// GET: /Import/FinanceOut/Edit
public ActionResult AppEdit()
{
return View();
}
public ActionResult BankStlIndex()
{
return View();
}
public ActionResult BankStlEdit()
{
return View();
}
public ActionResult RateMaintenance()
{
return View();
}
public JsonResult GetINTEREST(string ContractNo)
{
var sql = "select sum([INTEREST]) from [IMPORT_FINANCE_BODY] where [BSNO] ='" + ContractNo + "'";
var result = DSWeb.SoftMng.DBUtility.DbHelperSQL.GetObject(sql).ToString();
return Json(result);
}
/// <summary>
/// 获取融资利率
/// </summary>
/// <param name="start"></param>
/// <param name="limit"></param>
/// <param name="condition"></param>
/// <param name="sort"></param>
/// <returns></returns>
public JsonResult GetRmList(int start, int limit, string customer,string sexpiredDate, string eexpiredDate, string sort)
{
Import_Finance_RateBLL bll = new Import_Finance_RateBLL();
StringBuilder str=new StringBuilder();
if(!String.IsNullOrEmpty(customer))
str.Append(" customer like '%" + customer + "%'");
if (!String.IsNullOrEmpty(sexpiredDate))
{
if (str.Length > 0) str.Append(" And");
str.Append(" ExpiredDate >= '" + sexpiredDate + "'");
}
if (!String.IsNullOrEmpty(eexpiredDate))
{
if (str.Length > 0) str.Append(" And");
str.Append(" ExpiredDate <= '" + eexpiredDate + "'");
}
var data = bll.GetModelList(start, limit, str.ToString(), sort);
var total = bll.GetRecordCount(str.ToString());
return Json(new {total, data});
}
/// <summary>
/// 添加/修改 利率
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public JsonResult AddRmModel(Import_Finance_Rate model)
{
Import_Finance_RateBLL bll = new Import_Finance_RateBLL();
if (String.IsNullOrEmpty(model.GId))
{
model.GId = Guid.NewGuid().ToString();
return Json(new { Success = bll.Add(model) > 0 });
}
return Json(new { Success = bll.Update(model) > 0 });
}
/// <summary>
/// 批量添加利率
/// </summary>
/// <returns></returns>
public JsonResult AddRmModelList(string data)
{
try
{
JavaScriptSerializer json = new JavaScriptSerializer();
List<Import_Finance_Rate> list = json.Deserialize<List<Import_Finance_Rate>>(data);
foreach (var item in list)
AddRmModel(item);
return Json(new { Success = true });
}
catch (Exception e)
{
return Json(new { Success = false ,Msg=e.Message});
}
}
/// <summary>
/// 删除利率
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public JsonResult DelRmModel(string id)
{
Import_Finance_RateBLL bll = new Import_Finance_RateBLL();
return Json(bll.Delete(id) > 0);
}
public JsonResult DelRmModelList(string data)
{
Import_Finance_RateBLL bll = new Import_Finance_RateBLL();
return Json(bll.DeleteListWhere("GId in("+data+")") > 0);
}
/// <summary>
/// 获取实例
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public JsonResult GetRmModel(string name)
{
Import_Finance_RateBLL bll = new Import_Finance_RateBLL();
var list = bll.GetModelList("Customer='" + name + "'").OrderBy(p => p.ExtendedDays)
.Select(p => new
{
p.ExtendedDays,
p.Rate
}).ToList();
return Json(list);
}
// Get:/Import/FinanceOut/GetDataList
public ContentResult GetDataList(int start, int limit, string condition, string sort)
{
var _condition = condition;
var rangstr = " (f.CORPID='" + Convert.ToString(Session["COMPANYID"]) + "' OR ISNULL(f.CORPID,'')='' )";
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(_condition))
{
_condition = _condition + " and " + rangstr;
}
else
{
_condition = rangstr;
}
}
List<Financemb> list = FinanceDAL.GetDataList(_condition, sort);
var listpage = list.Skip(start).Take(limit);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = listpage.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition)
{
Financemb head = null;
if (handle == "edit")
{
var _condition = condition;
List<Financemb> list = FinanceDAL.GetDataList(_condition, "");
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new Financemb();
head.OP = Convert.ToString(Session["USERID"]);
head.OPREF = Convert.ToString(Session["SHOWNAME"]);
}
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult Delete(string data)
{
var head = JsonConvert.Deserialize<Financemb>(data);
var isfee = FinanceDAL.GetFeeCount(head.F_NO);
if (isfee)
{
var jsonRespose = new JsonResponse { Success = false, Message = "此票业务存在费用,请先删除费用才能删除此票业务!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var BSNO = head.F_NO;
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
if (result.Success == true) {
FinanceDAL.DeleteDetail(BSNO);
var dataList = FinanceDAL.GetBodyList("c.F_NO='" + BSNO + "'");
result = FinanceDAL.DelBill(BSNO, dataList);
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult Save(string opstatus, string data, string FinanceFee, string FinanceBank)
{
Financemb head = JsonConvert.Deserialize<Financemb>(data);
var FinanceFeeList = JsonConvert.Deserialize<List<MsChFee>>(FinanceFee);
var FinanceFeeDelList = JsonConvert.Deserialize<List<MsChFee>>("");
var FinanceBankList = JsonConvert.Deserialize<List<FinanceBank>>(FinanceBank);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.CORPID = Convert.ToString(Session["COMPANYID"]);
head.F_NO = PubSysDAL.GetBillNo("0206"); //获取GID
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
if (head.STARTDATE == "") head.STARTDATE = null;
if (head.ENDDATE == "") head.ENDDATE = null;
if (head.BANKENDDATE == "") head.BANKENDDATE = null;
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<MsChFee>.ToModelObjectList(FinanceFeeList),
ModelObjectConvert<MsChFee>.ToModelObjectList(FinanceFeeDelList)
);
if (result.Success == true) FinanceDAL.SaveBank(head.F_NO, FinanceBankList);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = FinanceDAL.GetData("F_NO='" + head.F_NO + "'","")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AuditSave(string opstatus, string data, string FinanceFee,string FinanceBank)
{
Financemb head = JsonConvert.Deserialize<Financemb>(data);
var FinanceFeeList = JsonConvert.Deserialize<List<MsChFee>>(FinanceFee);
var FinanceFeeDelList = JsonConvert.Deserialize<List<MsChFee>>("");
var FinanceBankList = JsonConvert.Deserialize<List<FinanceBank>>(FinanceBank);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.CORPID = Convert.ToString(Session["COMPANYID"]);
head.F_NO = PubSysDAL.GetBillNo("0206"); //获取GID
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
head.F_STATUS = "已融出";
if (head.STARTDATE == "") head.STARTDATE = null;
if (head.ENDDATE == "") head.ENDDATE = null;
if (head.BANKENDDATE == "") head.BANKENDDATE = null;
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<MsChFee>.ToModelObjectList(FinanceFeeList),
ModelObjectConvert<MsChFee>.ToModelObjectList(FinanceFeeDelList)
);
if (result.Success == true) FinanceDAL.SaveBank(head.F_NO, FinanceBankList);
//if (result.Success == true) FinanceDAL.SaveFinanceFee(head,Convert.ToString(Session["USERID"]));
//if (result.Success == true) FinanceDAL.CreateBankFee(head.F_NO, FinanceBankList,Convert.ToString(Session["USERID"]));
if (result.Success == true) FinanceDAL.AuditFinancelStatus(head.F_NO);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = FinanceDAL.GetData("F_NO='" + head.F_NO + "'", "")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//融资的业务
public ContentResult GetFinanceBody(int start, int limit, string condition, string sort = "")
{
var _condition = condition;
List<FinanceBodymb> list = FinanceDAL.GetFinanceList(_condition, sort);
var listpage = list.Skip(start).Take(limit);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = listpage.ToList() });
return new ContentResult() { Content = json };
}
#region 查询待融资的业务
public ContentResult GetBodyList(string condition)
{
var _condition = condition;
List<FinanceTradeBody> list = FinanceDAL.GetBodyList(_condition);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetBodyAddList(string condition)
{
var _condition = condition;
// var rangstr = " (M.CORPID='" + Convert.ToString(Session["COMPANYID"]) + "' OR ISNULL(M.CORPID,'')='' )";
var rangstr = FinanceDAL.GetRangAddFeeDAStr(Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(_condition))
{
_condition = _condition + " and " + rangstr;
}
else
{
_condition = rangstr;
}
}
List<FinanceTradeBody> list = FinanceDAL.GetBodyAddList(_condition);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult AddBill(string billno, string addbody)
{
var bodyList = JsonConvert.Deserialize<List<FinanceTradeBody>>(addbody);
var result = new DBResult();
if (bodyList != null)
{
result = FinanceDAL.AddBill(billno, bodyList);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DelBill(string data, string billno)
{
var bodyList = JsonConvert.Deserialize<List<FinanceTradeBody>>(data);
DBResult result = FinanceDAL.DelBill(billno,bodyList);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 提交和撤销融资申请
public ContentResult SubmitAudit(string bill)
{
DBResult result = FinanceDAL.SubmitAudit(Convert.ToString(Session["USERID"]), bill);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult SubmitAuditBack(string bill)
{
DBResult result = FinanceDAL.SubmitAuditBack( Convert.ToString(Session["USERID"]), bill);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult SubmitAuditList(string bills)
{
DBResult result = FinanceDAL.SubmitAuditList( Convert.ToString(Session["USERID"]), bills);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult SubmitAuditBackList(string bills)
{
DBResult result = FinanceDAL.SubmitAuditBackList( Convert.ToString(Session["USERID"]), bills);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
#endregion
#region 银行明细
public ContentResult GetBankList(string condition)
{
var _condition = condition;
List<FinanceBank> list = FinanceDAL.GetBankList(_condition);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult DeleteBank(string F_NO, string data)
{
int iResult = 0;
var result = new DBResult();
if (data != "" || data != null)
{
iResult = FinanceDAL.DeleteBank(data);
}
if (iResult == 1)
{
result.Success = true;
result.Message = "删除成功!";
}
else if (iResult == 0)
{
result.Success = false;
result.Message = "出现错误,未删除!";
}
else if (iResult == -1)
{
result.Success = false;
result.Message = "有异常,删除失败!";
}
else if (iResult == -2)
{
result.Success = false;
result.Message = "删除异常,事务已回滚成功!";
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
// Data = MsChFeeDAL.GetDataList(headData.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 融资银行核销
public ContentResult GetBankStlData(string handle, string condition)
{
FinanceBodymb head = null;
if (handle == "edit")
{
var _condition = condition;
List<FinanceBodymb> list = FinanceDAL.GetFinanceList(_condition, "");
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new FinanceBodymb();
head.GID = Guid.NewGuid().ToString();
head.OP = Convert.ToString(Session["USERID"]);
head.OPREF = Convert.ToString(Session["SHOWNAME"]);
head.F_TYPE = "3";
}
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult SaveBankStl(string opstatus, string data)
{
FinanceBodymb head = JsonConvert.Deserialize<FinanceBodymb>(data);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.F_NO = PubSysDAL.GetBillNo("0206"); //获取GID
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = FinanceDAL.GetFinanceData("F_NO='" + head.F_NO + "'", "")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteBankStl(string data)
{
var head = JsonConvert.Deserialize<FinanceBodymb>(data);
var BSNO = head.F_NO;
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
if (result.Success == true)
{
var dataList = FinanceDAL.GetBankStlDetailList(" d.F_NO='" + BSNO + "'","");
result = FinanceDAL.DelBankStlBill(BSNO, dataList);
if (dataList != null)
{
foreach (var enumValue in dataList)
{
FinanceDAL.p_update_Finance(enumValue.F_NO);
}
}
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AddBankStlBill(string billno, string addbody)
{
var bodyList = JsonConvert.Deserialize<List<Financemb>>(addbody);
var result = new DBResult();
if (bodyList != null)
{
result = FinanceDAL.AddBankStlBill(billno, bodyList);
if (result.Success == true) {
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
FinanceDAL.p_update_Finance(enumValue.F_NO);
}
}
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DelBankStlBill(string data, string billno)
{
var bodyList = JsonConvert.Deserialize<List<Financemb>>(data);
DBResult result = FinanceDAL.DelBankStlBill(billno, bodyList);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetAddBankFinalList(int start, int limit, string condition, string sort)
{
var _condition = condition;
List<Financemb> list = FinanceDAL.GetAddBankFinalList(_condition, sort);
var listpage = list.Skip(start).Take(limit);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = listpage.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetBankStlDetailList(int start, int limit, string condition, string sort)
{
var _condition = condition;
List<Financemb> list = FinanceDAL.GetBankStlDetailList(_condition, sort);
var listpage = list.Skip(start).Take(limit);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = listpage.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult SubmitBankStl(string bill,string body)
{
var head = JsonConvert.Deserialize<FinanceBodymb>(bill);
var bodyList = JsonConvert.Deserialize<List<Financemb>>(body);
DBResult result = FinanceDAL.SubmitBankStl(head,bodyList,Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult SubmitBackBankStl(string bill)
{
var head = JsonConvert.Deserialize<FinanceBodymb>(bill);
DBResult result = FinanceDAL.SubmitBackBankStl(head);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
#endregion
#region 增加业务到import_finance_body
public ContentResult SaveBody(string F_NO, string body)
{
var bodyList = JsonConvert.Deserialize<List<FinanceBodymb>>(body);
var result = new DBResult();
if (bodyList != null)
{
result = FinanceDAL.SaveBody(F_NO,bodyList,false);
if (result.Success)
{
FinanceDAL.p_update_Finance(F_NO);
//融资银行更新记录
var list = FinanceDAL.GetBankList("F_NO='" + F_NO + "'");
foreach (var item in list)
{
item.DOAMOUNT =Convert.ToDecimal(DSWeb.SoftMng.DBUtility.DbHelperSQL.GetObject("select isnull((select sum(F_AMOUNT) from IMPORT_FINANCE_BODY where F_NO='"+ F_NO + "' and F_TYPE='2'),0)"));
}
FinanceDAL.SaveBank(F_NO,list);
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult CreateBodyFee(string F_NO, string body)
{
var buildtype = MsSysParamSetDAL.GetData("PARAMNAME='FinanceBuild'").PARAMVALUE;//"true" 默认,融资单独核算。"false",不单独核算
var bodyList = JsonConvert.Deserialize<List<FinanceBodymb>>(body);
var result = new DBResult();
if (bodyList != null)
{
var iresult = FinanceDAL.CreateBodyFee(F_NO, bodyList, Convert.ToString(Session["USERID"]), buildtype);
if (iresult == 1) result=FinanceDAL.SaveBody(F_NO, bodyList, true);
if (result.Success) { FinanceDAL.p_update_Finance(F_NO); }
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public int AddFinance(string F_NO, string feesql)
{
var strSql = new StringBuilder();
strSql.Append(" insert into import_finance_body select newid() GID, '" + F_NO + "' as F_NO,contractno from import_main where " + feesql );
//strSql.Append(" where " + feesql);
return setAddFinance(strSql);//ExecuteNonQuery
}
private static int setAddFinance(StringBuilder strSql)
{
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
return _count;
}
#endregion
#region 从import_finance_body删除业务
public ContentResult DeleteBody(string F_NO, string data)
{
int iResult = 0;
var bodyList = data;
var result = new DBResult();
if (bodyList != "" || bodyList != null)
{
iResult = FinanceDAL.DeleteBody(bodyList);
}
if (iResult == 1)
{
FinanceDAL.p_update_Finance(F_NO);
result.Success = true;
result.Message = "删除成功!";
}
else if (iResult == 0)
{
result.Success = false;
result.Message = "出现错误,未删除!";
}
else if (iResult == -1)
{
result.Success = false;
result.Message = "有异常,删除失败!";
}
else if (iResult == -2)
{
result.Success = false;
result.Message = "删除异常,事务已回滚成功!";
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
// Data = MsChFeeDAL.GetDataList(headData.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
private static int setDelFinance(StringBuilder strSql)
{
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
return _count;
}
#endregion
#region 参照部分
#endregion
}
}