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.
DS7/DSWeb/Areas/Account/Controllers/Chfee_managementController.cs

542 lines
26 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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.Account.DAL.Chfee_management;
using DSWeb.Areas.Account.Models.Chfee_management;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.TruckMng.Helper;
using DSWeb.TruckMng.Helper.Repository;
using DSWeb.Areas.TruckMng.DAL.Comm;
using HcUtility.Comm;
using HcUtility.Core;
using DSWeb.Areas.Import.Models.CwVouchers;
using DSWeb.Areas.Import.Models.CwVouitems;
using DSWeb.Areas.Import.Models.CwDesign;
using DSWeb.Areas.Import.Models.CWAccitems;
using DSWeb.Areas.Import.DAL.CwVouchersDAL;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Text;
using System.Data;
using DSWeb.EntityDA;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using DSWeb.MvcShipping.Models.MsSysBillNoSet;
using DSWeb.Areas.Account.Models.MsCwVouchersGl3;
namespace DSWeb.Areas.Account.Controllers
{
[JsonRequestBehavior]
public class Chfee_managementController : Controller
{
//
// GET: /Import/XXH
public ActionResult Index()
{
return View();
}
//
// GET: /Import/XXH/Edit
public ActionResult Edit()
{
return View();
}
public ActionResult CMView()
{
return View();
}
//
// GET/Import/XXH/GetDataList
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = Chfee_managementDAL.GetDataList(condition, Convert.ToString(Session["USERID"]),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)
{
C_Mmb head = null;
if (handle == "edit")
{
var list = Chfee_managementDAL.GetDataList(condition, Convert.ToString(Session["USERID"]));
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new C_Mmb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
//
//
public ContentResult Save(string opstatus, string data, string FeeBody, string FeeDelBody)
{
var head = JsonConvert.Deserialize<C_Mmb>(data);
var FeebodyList = JsonConvert.Deserialize<List<C_MBodymb>>(FeeBody);
var FeeDelbodyList = JsonConvert.Deserialize<List<C_MBodymb>>(FeeDelBody);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='管理费用'", Convert.ToString(Session["COMPANYID"]));
if (billnoset.BILLTYPE != "")
head.Feeid = MsSysBillNoSetDAL.GetBillNo(billnoset, head.CREATEDATE.ToString().Trim(), head.ACCDATE.ToString().Trim());
else
head.Feeid = PubSysDAL.GetBillNo("0205");
//获取管理费单号
//20131011 应客户要求,将合同号改为接单人手动填写的必填项目。不再自动生成合同号
/*自动填写接单审单人id
headData.UserCode = CookieConfig.GetCookie_UserCode(Request);
headData.UserName = CookieConfig.GetCookie_UserName(Request);
headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
headData.OrgName = CookieConfig.GetCookie_OrgName(Request);*/
//headData.LrDate = DateTime.Now;
}
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,
ModelObjectConvert<C_MBodymb>.ToModelObjectList(FeebodyList),
ModelObjectConvert<C_MBodymb>.ToModelObjectList(FeeDelbodyList)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = Chfee_managementDAL.GetData("CM.Feeid='" + head.Feeid + "'", Convert.ToString(Session["USERID"]))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Delete(string data,string USERID)
{
var head = JsonConvert.Deserialize<C_Mmb>(data);
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
if (result.Success == true) { Chfee_managementDAL.DeleteDetail(head.Feeid); MsSysBillNoSetDAL.DeleteBsNo(head.Feeid); }
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetFeeList(string condition)
{
var _condition = condition;
//var _condition = " cfm.Feeid = '" + condition + "' ";
List<C_MBodymb> list = Chfee_managementDAL.GetBodyList(_condition, Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetFeeList_Index ( string condition )
{
var _condition = condition;
//var _condition = " cfm.Feeid = '" + condition + "' ";
List<C_MBodymb_2> list = Chfee_managementDAL.GetBodyList_Index(_condition, Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult CreateVoucher(string VoucherDate, string UsdExrate, string User, string useRate, string feesql)
{
var modb = new ModelObjectDB();
DBResult result = CreateDCVoucher(VoucherDate, UsdExrate, User, useRate, feesql);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public static DBResult CreateDCVoucher(string VoucherDate, string UsdExrate, string User, string useRate, string feesql)
{
var result = new DBResult();
result.Success = true;
var Feeid = "";
var VouitemsList = new List<CwVouitems>();
var VouOrdNo = Guid.NewGuid().ToString();
CwDesign CWDesign = CwVouchersDAL.GetCwDesign();
if (CWDesign.AR == "" || CWDesign.AR == null )
{
result.Success = false;
result.Message = "请先设置帐套信息,才能生成凭证!";
}
else
{
decimal DebitAmt = Convert.ToDecimal(0.00);
decimal CreditAmt = Convert.ToDecimal(0.00);
int itemsno = 1;
CwVouchers Voucher = new CwVouchers();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var strSql = new StringBuilder();
if (useRate == "1")
{
strSql.Append("SELECT c.Feeid,c.CUSTOMERSIDE");
strSql.Append(", FAPCODE=(select top 1 FAPCODE from info_client where SHORTNAME=c.CUSTOMERSIDE) ");
strSql.Append(", FARCODE=(select top 1 FARCODE from info_client where SHORTNAME=c.CUSTOMERSIDE) ");
strSql.Append(",c.FEENAME,c.AMOUNT,cast(round(c.AMOUNT*m.EXCHANGERATE,2) as numeric(20,2)) AS mhj,m.FEETYPE,m.OPERATORSIDE,m.CURRENCY,m.AMOUNT AS je,cast(round(m.AMOUNT*m.EXCHANGERATE,2) as numeric(20,2)) AS hj");
strSql.Append(",m.EXCHANGERATE From ch_fee_Mbody c left join ch_fee_management m on (m.Feeid=c.Feeid) WHERE c.Feeid IN " + feesql);
strSql.Append(" order by c.Feeid ");
}
else
{
strSql.Append("SELECT c.Feeid,c.CUSTOMERSIDE");
strSql.Append(", FAPCODE=(select top 1 FAPCODE from info_client where SHORTNAME=c.CUSTOMERSIDE) ");
strSql.Append(", FARCODE=(select top 1 FARCODE from info_client where SHORTNAME=c.CUSTOMERSIDE) ");
strSql.Append(",c.FEENAME,c.AMOUNT,cast(round(c.AMOUNT*" + UsdExrate + ",2) as numeric(20,2)) AS mhj,m.FEETYPE,m.OPERATORSIDE,m.CURRENCY,m.AMOUNT AS je,cast(round(m.AMOUNT*" + UsdExrate + ",2) as numeric(20,2)) AS hj,");
strSql.Append(UsdExrate + " as EXCHANGERATE From ch_fee_Mbody c left join ch_fee_management m on (m.Feeid=c.Feeid) WHERE c.Feeid IN " + feesql);
strSql.Append(" order by c.Feeid ");
}
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
if (Feeid != Convert.ToString(reader["Feeid"]))
{
Feeid = Convert.ToString(reader["Feeid"]);
var BankAccitems = CwVouchersDAL.GetCwAccitems(Convert.ToString(reader["OPERATORSIDE"]));
if (BankAccitems.ACCID == "")
{
result.Success = false;
result.Message = "单号:" + Convert.ToString(reader["Feeid"]) + "费用项目没有对应的财务科目!";
}
CwVouitems bankdata = new CwVouitems();
bankdata.ACCID = BankAccitems.ACCID;
bankdata.ACCNAME = BankAccitems.ACCNAME;
bankdata.ORDNO = VouOrdNo;
bankdata.BLNO = Convert.ToString(reader["Feeid"]);
bankdata.EXPLAN = "费用单号:" + Convert.ToString(reader["Feeid"]);
bankdata.ITEMNO = itemsno;
bankdata.ISSYS = true;
if (BankAccitems.DC == "借")
{
bankdata.DC = "D";
}
else if (BankAccitems.DC == "贷")
{
bankdata.DC = "C";
}
if (Convert.ToString(reader["FEETYPE"]) == "1")
{
if (Convert.ToString(reader["CURRENCY"]) == "RMB")
{
bankdata.AMTDR = Convert.ToDecimal(reader["je"]);
bankdata.AMTCR = Convert.ToDecimal(0.00);
bankdata.FCYCR = Convert.ToDecimal(0.00);
bankdata.FCYDR = Convert.ToDecimal(0.00);
bankdata.FCYEXRATE = Convert.ToDecimal(1);
bankdata.FCYNO = "RMB";
DebitAmt = DebitAmt + Convert.ToDecimal(reader["je"]);
}
else
{
bankdata.AMTDR = Convert.ToDecimal(reader["hj"]);
bankdata.AMTCR = Convert.ToDecimal(0.00);
bankdata.FCYCR = Convert.ToDecimal(0.00);
bankdata.FCYDR = Convert.ToDecimal(reader["je"]);
bankdata.FCYEXRATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
bankdata.FCYNO = "USD";
DebitAmt = DebitAmt + Convert.ToDecimal(reader["hj"]);
}
}
else if (Convert.ToString(reader["FEETYPE"]) == "2")
{
if (Convert.ToString(reader["CURRENCY"]) == "RMB")
{
bankdata.AMTDR =Convert.ToDecimal(0.00);
bankdata.AMTCR = Convert.ToDecimal(reader["je"]);
bankdata.FCYCR = Convert.ToDecimal(0.00);
bankdata.FCYDR = Convert.ToDecimal(0.00);
bankdata.FCYEXRATE = Convert.ToDecimal(1);
bankdata.FCYNO = "RMB";
CreditAmt = CreditAmt + Convert.ToDecimal(reader["je"]);
}
else
{
bankdata.AMTDR = Convert.ToDecimal(0.00);
bankdata.AMTCR = Convert.ToDecimal(reader["hj"]);
bankdata.FCYCR = Convert.ToDecimal(reader["je"]);
bankdata.FCYDR = Convert.ToDecimal(0.00);
bankdata.FCYEXRATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
bankdata.FCYNO = "USD";
CreditAmt = CreditAmt + Convert.ToDecimal(reader["hj"]);
}
}
itemsno = itemsno + 1;
VouitemsList.Add(bankdata);
}
var Accitems = CwVouchersDAL.GetCwAccitems(Convert.ToString(reader["FEENAME"]));
if (Accitems.ACCID == "")
{
result.Success = false;
result.Message = "单号:" + Convert.ToString(reader["Feeid"]) + "费用项目没有对应的财务科目!";
}
CwVouitems data = new CwVouitems();
data.ACCID = Accitems.ACCID;
data.ACCNAME = Accitems.ACCNAME;
data.ORDNO = VouOrdNo;
data.BLNO = Convert.ToString(reader["Feeid"]);
data.EXPLAN = Accitems.ACCNAME;
data.ITEMNO = itemsno;
data.ISSYS = true;
if (Accitems.DC == "借")
{
data.DC = "D";
}
else if (Accitems.DC == "贷")
{
data.DC = "C";
}
if (Convert.ToString(reader["FEETYPE"]) == "2")
{
if (Convert.ToString(reader["CUSTOMERSIDE"]) != "")
{
if (Convert.ToString(reader["FARCODE"]) == "")
{
result.Success = false;
result.Message = "单号:" + Convert.ToString(reader["Feeid"]) + "客户没有设置对应的财务代码!";
}
else {
data.CORPID = Convert.ToString(reader["FARCODE"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERSIDE"]);
}
}
if (Convert.ToString(reader["CURRENCY"]) == "RMB")
{
data.AMTDR = Convert.ToDecimal(reader["AMOUNT"]);
data.AMTCR = Convert.ToDecimal(0.00);
data.FCYCR = Convert.ToDecimal(0.00);
data.FCYDR = Convert.ToDecimal(0.00);
data.FCYEXRATE = Convert.ToDecimal(1);
data.FCYNO = "RMB";
DebitAmt = DebitAmt + Convert.ToDecimal(reader["AMOUNT"]);
}
else
{
data.AMTDR = Convert.ToDecimal(reader["mhj"]);
data.AMTCR = Convert.ToDecimal(0.00);
data.FCYCR = Convert.ToDecimal(0.00);
data.FCYDR = Convert.ToDecimal(reader["AMOUNT"]);
data.FCYEXRATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
data.FCYNO = "USD";
DebitAmt = DebitAmt + Convert.ToDecimal(reader["mhj"]);
}
}
else if (Convert.ToString(reader["FEETYPE"]) == "1")
{
if (Convert.ToString(reader["CUSTOMERSIDE"]) != "")
{
if (Convert.ToString(reader["FAPCODE"]) == "")
{
result.Success = false;
result.Message = "单号:" + Convert.ToString(reader["Feeid"]) + "客户没有设置对应的财务代码!";
}
else
{
data.CORPID = Convert.ToString(reader["FAPCODE"]);
}
}
if (Convert.ToString(reader["CURRENCY"]) == "RMB")
{
data.AMTDR = Convert.ToDecimal(0.00);
data.AMTCR = Convert.ToDecimal(reader["AMOUNT"]);
data.FCYCR = Convert.ToDecimal(0.00);
data.FCYDR = Convert.ToDecimal(0.00);
data.FCYEXRATE = Convert.ToDecimal(1);
data.FCYNO = "RMB";
CreditAmt = CreditAmt + Convert.ToDecimal(reader["AMOUNT"]);
}
else
{
data.AMTDR = Convert.ToDecimal(0.00);
data.AMTCR = Convert.ToDecimal(reader["mhj"]);
data.FCYCR = Convert.ToDecimal(reader["AMOUNT"]);
data.FCYDR = Convert.ToDecimal(0.00);
data.FCYEXRATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
data.FCYNO = "USD";
CreditAmt = CreditAmt + Convert.ToDecimal(reader["mhj"]);
}
}
itemsno = itemsno + 1;
VouitemsList.Add(data);
}
reader.Close();
}
Voucher.ORDNO = VouOrdNo;
var voudate = Convert.ToDateTime(VoucherDate);
Voucher.ACCYEAR = voudate.ToString("yyyy");
Voucher.ACCMONTH = voudate.ToString("MM");
Voucher.PREPARED = User;
Voucher.VOUDATE = voudate;
Voucher.VKNO = CWDesign.TVW;
Voucher.AMTDR = DebitAmt;
Voucher.AMTCR = CreditAmt;
//帐套设置
T_ALL_DA T_ALL_DA = new T_ALL_DA();
DataSet dsCwDesign = T_ALL_DA.GetAllSQL("SELECT top 1 * from cw_design");
if (dsCwDesign == null)
{
result.Success = false;
result.Message = "没有设置账套信息!";
}
Voucher.VOUNO = CwVouchersDAL.getVOUNO(dsCwDesign, Voucher.ACCYEAR, Voucher.ACCMONTH);
Voucher.VOUALLNO = Voucher.ACCYEAR + Voucher.ACCMONTH + Voucher.VOUNO;
Voucher.ATTACHS = CWDesign.AFFIXNO;
Voucher.FCY = "";
Voucher.QTY = "";//是否含有数量科目="";//varchar="";//(1)
Voucher.VOUPROP = "";//凭证属性="";//varchar="";//(1)
Voucher.CHECKED = "";//审核人="";//varchar="";//(10)
Voucher.ENTERED = "";//记账人="";//varchar="";//(10)
Voucher.ERRMSG = "";//错误信息="";//varchar="";//(6)
Voucher.ISDELETE = false;//是否废除="";//bit="";//Y
Voucher.DELETEUSER = "";//废除操作人="";//Varchar(36)="";//Y
}
var strSel = " AND Feeid in " + feesql;
if (result.Success)
{
result = CwVouchersDAL.InsertVoucher(Voucher, VouitemsList, "ch_fee_management", Voucher.VOUALLNO, strSel, User);
}
}
return result;
}
#region 生成总账凭证
public ContentResult GetCodeCurrencyList(string strGids)
{
var dataList = Chfee_managementDAL.GetCodeCurrencyList(strGids, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult onAddCwVouchers(string strGids, string dataDiv, string jsonBody)
{
var headData = JsonConvert.Deserialize<MsCwVouchersGl3>(dataDiv);
List<MsCwVouchersGl4> bodyList = new List<MsCwVouchersGl4>();
if (jsonBody != null)
{
bodyList = JsonConvert.Deserialize<List<MsCwVouchersGl4>>(jsonBody);
}
if (bodyList == null && headData.ISRATE == false)
{
headData.ISRATE = true;
}
//
DBResult result2 = Chfee_managementDAL.GetIsVoucher(strGids, Convert.ToString(Session["USERID"]));
if (!result2.Success)
{
var jsonRespose2 = new JsonResponse { Success = result2.Success, Message = result2.Message, Data = "" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
DBResult result = Chfee_managementDAL.onAddCwVouchers(strGids, headData, bodyList, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
//
string sGids = "'" + strGids.Trim().Replace(",", "','") + "'";
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sVOUCHERNO = T_ALL_DA.GetStrSQL("VOUCHERNO", "select top 1 VOUCHERNO from ch_fee_settlement where gid in (" + sGids + ")");
//
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = sVOUCHERNO };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetIsVoucher(string strGids)
{
DBResult result = Chfee_managementDAL.GetIsVoucher(strGids, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = "" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
/// <summary>
/// 是否自动弹出结算总账凭证
/// </summary>
/// <returns></returns>
public ContentResult onIsSettlementsopen()
{
DBResult result = Chfee_managementDAL.onIsSettlementsopen(Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = "" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
}
}