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.

2904 lines
164 KiB
C#

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden 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.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.RptMng.Comm;
using HcUtility.Comm;
using HcUtility.Core;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using DSWeb.Areas.Account.Models.BSNOLB;
using DSWeb.Areas.Account.Models.MsOpBill;
using DSWeb.MvcShipping.DAL.ChMonthCloseDAL;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.EntityDA;
using DSWeb.Models;
namespace DSWeb.Areas.Account.Controllers
{
/// <summary>
/// 业务费用封帐
/// </summary>
[JsonRequestBehavior]
public class Chfee_lockController : Controller
{
//
// GET:
public ActionResult Index()
{
return View();
}
public ActionResult FeeLockIndex()
{
return View();
}
public ActionResult Chfee_lockDetail()
{
return View();
}
public ActionResult BsVoucherIndex()
{
return View();
}
//
// GET
public ContentResult BsListData(int start, int limit, string condition,string sort,string type,string printstr)
{
var strDa = GetRangDAStr("index",type, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and isnull(B.ISCANCEL,0)<>1 ";
}
else
{
condition = " isnull(B.ISCANCEL,0)<>1 ";
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT B.BSNO, B.OPLB, B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS,B.FEESTATUS,B.SALE, B.OP, B.DOC");
strSql.Append(",case B.BSSTATUS when 1 then '已锁定' else '未锁定' end as BSSTATUSREF");
strSql.Append(",case B.FEESTATUS when 1 then '已锁定' else '未锁定' end as FEESTATUSREF");
strSql.Append(",case B.ETD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.ETD,23) end as ETD");
strSql.Append(",case B.OPDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.OPDATE,23) end as OPDATE,B.ENTERP");
strSql.Append(",case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS,B.ISPRINTPR");
strSql.Append(",G.RMBDR,G.RMBCR,G.STLRMBDR,G.STLRMBCR,G.USDDR,G.USDCR,G.STLUSDDR,G.STLUSDCR,G.OTDR,G.OTCR,G.STLOTDR,G.STLOTCR,G.TTLDR,G.TTLCR,G.STLTTLDR,G.STLTTLCR");
strSql.Append(",G.USDDR-G.USDCR AS USDPROFIT,G.RMBDR-G.RMBCR AS RMBPROFIT,G.OTDR-G.OTCR AS OTPROFIT,G.TTLDR-G.TTLCR AS TTLPROFIT ");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (G.TTLDR)= 0 THEN '无法计算' ELSE ltrim(str((G.TTLDR-G.TTLCR) / (G.TTLDR) * 100, 10, 2)) + '%' END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (G.TTLCR)= 0 THEN '无法计算' ELSE ltrim(str((G.TTLDR-G.TTLCR) / (G.TTLCR) * 100, 10, 2)) + '%' END) AS PROFITRATE");
strSql.Append(",(SELECT TOP 1 STATUS FROM OP_STATUS WHERE BSNO=B.BSNO ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS ");
strSql.Append(",dbo.F_GetBillDrFeeStatus(B.BSNO) DRFEESTATUS");
strSql.Append(",dbo.F_GetBillCrFeeStatus(B.BSNO) CRFEESTATUS,B.CONTRACTNO,B.SERVICECONTRACTNO,C.BSCLOSETIME,C.BSCLOSEOP,C.FEECLOSETIME,C.FEECLOSEOP,B.ISVOU,B.VOUNO,B.BillFeeStatus ");
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append("LEFT JOIN op_close c ON (c.BSNO=B.BSNO) ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where " + condition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else {
strSql.Append(" order by B.CUSTOMERNAME,B.OPLB,B.CREATETIME DESC");
}
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public static string GetRangDAStr(string tb,string type, string userid, string usercode, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
//strSql.Append(" where [NAME]='modBlockBSSTATUS' and USERID='" + userid + "' and ISDELETE=0");
if (type == "BS")
{
strSql.Append(" where [NAME]='modBlockBSSTATUS' and USERID='" + userid + "' and ISDELETE=0");
}
else if (type == "FEE")
{
strSql.Append(" where [NAME]='modBlockFEESTATUS' and USERID='" + userid + "' and ISDELETE=0");
}
else if (type == "BSVOUCHER")
{
strSql.Append(" where [NAME]='modBSVOUCHER' and USERID='" + userid + "' and ISDELETE=0");
}
else if (type == "YJFEE")
{
var YJFeeConnectOPSeae = MsSysParamSetDAL.GetData("PARAMNAME='YJFeeConnectOPSeae'");
if (YJFeeConnectOPSeae.PARAMVALUE=="0")
{
strSql.Append(" where [NAME]='modYJFEE' and USERID='" + userid + "' and ISDELETE=0");
}
else
{
strSql.Append(" where [NAME]='modOrderManagement' and USERID='" + userid + "' and ISDELETE=0");
}
}
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = "1=2";
}
else if (visiblerange == "3")
{
// str = " (B.OP='" + usercode + "' OR B.SALE='" + usercode + "')";
str = " (B.OP='" + usercode + "' OR B.SALE='" + usercode + "' OR B.CUSTSERVICE = '"+usercode+"')";
}
else if (visiblerange == "2")
{
if (tb == "index")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
var userstr = new StringBuilder();
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " (B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
}
else
{
str = str + " or B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
};
}
str =str+ ")";
reader.Close();
}
}
else
{
str = " UPPER(B.Corpid)='" + companyid + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(B.Corpid)='" + companyid + "'";
}
return str;
}
public ContentResult SelLock(string data,int type)
{
var billData = JsonConvert.Deserialize<List<BSNOLB>>(data);
var json = JsonConvert.Serialize(new { Success = true, Message = "锁定成功" });
Database db = DatabaseFactory.CreateDatabase();
var i = 0;
var j = 0;
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var enumValue in billData)
{
if (type == 2)
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET BSSTATUS=1 WHERE BSNO=@BSNO ");
//2017年4月10日16:50:29 需求编号:SR2017041000009
//Start
if (enumValue.OPLB.Equals("tMsWlPcHead"))
{
cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET BillStatus=1 WHERE gid=@BSNO ");
}
//End
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
updateclose(enumValue.BSNO,type);
i = i + 1;
}
else if (type == 1)
{
var FeeCount = db.ExecuteScalar(CommandType.Text, "SELECT COUNT(GID) as FeeCount from ch_fee where FEESTATUS NOT IN (0,8,9) and BSNO='" + enumValue.BSNO + "'");
var IntFeeCount = Convert.ToInt16(FeeCount);
if (IntFeeCount == 0)
{
if (enumValue.OPLB=="tMsWlPcHead")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=1 WHERE GID=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
} else {
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
}
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdateamend, tran);
i = i + 1;
updateclose(enumValue.BSNO, type);
}
else { j = j + 1; }
}
}
var msg = "";
if (type == 2)
{
msg = "成功锁定" + i.ToString() + "票业务!";
}
else if (type == 1)
{
msg = "成功锁定" + i.ToString() + "票业务费用锁定," + j.ToString() + "票业务未锁定!";
}
json = JsonConvert.Serialize(new { Success = true, Message = msg });
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
json = JsonConvert.Serialize(new { Success = false, Message = "锁定失败" });
}
}
return new ContentResult() { Content = json };
}
public ContentResult SelFeeLock(string data, string isAccDate, string AccDate)
{
var billData = JsonConvert.Deserialize<List<BSNOLB>>(data);
var json = JsonConvert.Serialize(new { Success = true, Message = "锁定成功" });
Database db = DatabaseFactory.CreateDatabase();
var i = 0;
var j = 0;
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var enumValue in billData)
{
var FeeCount = db.ExecuteScalar(CommandType.Text, "SELECT COUNT(GID) as FeeCount from ch_fee where FEESTATUS NOT IN (0,8,9) and BSNO='" + enumValue.BSNO + "'");
var IntFeeCount = Convert.ToInt16(FeeCount);
if (IntFeeCount == 0)
{
if (isAccDate == "1")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=1,ACCDATE=@ACCDATE WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdUpdate, "@ACCDATE", DbType.String,AccDate);
db.ExecuteNonQuery(cmdUpdate, tran);
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=1,ACCDATE=@ACCDATE WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdUpdateamend, "@ACCDATE", DbType.String, AccDate);
db.ExecuteNonQuery(cmdUpdateamend, tran);
updateclose(enumValue.BSNO,1);
}
else
{
if (enumValue.OPLB == "tMsWlPcHead")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=1 WHERE GID=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
}
else
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
}
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdateamend, tran);
updateclose(enumValue.BSNO,1);
}
i = i + 1;
}
else { j = j + 1; }
}
var msg = "";
msg = "成功锁定" + i.ToString() + "票业务费用锁定," + j.ToString() + "票业务未锁定!";
json = JsonConvert.Serialize(new { Success = true, Message = msg });
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
json = JsonConvert.Serialize(new { Success = false, Message = "锁定失败" });
}
}
return new ContentResult() { Content = json };
}
public ContentResult SelDownMonth(string data, string AccDate)
{
var newDate = Convert.ToDateTime(AccDate+"-01");
var nextmonth = newDate.AddMonths(1);
var newperiod = nextmonth.ToString("yyyy-MM");
var billData = JsonConvert.Deserialize<List<BSNOLB>>(data);
var json = JsonConvert.Serialize(new { Success = true, Message = "修改成功" });
Database db = DatabaseFactory.CreateDatabase();
var i = 0;
var j = 0;
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var enumValue in billData)
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET ACCDATE=@ACCDATE WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdUpdate, "@ACCDATE", DbType.String, newperiod);
db.ExecuteNonQuery(cmdUpdate, tran);
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET ACCDATE=@ACCDATE WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdUpdateamend, "@ACCDATE", DbType.String, newperiod);
db.ExecuteNonQuery(cmdUpdateamend, tran);
i = i + 1;
}
var msg = "";
msg = "成功修改" + i.ToString() + "票业务!";
json = JsonConvert.Serialize(new { Success = true, Message = msg });
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
json = JsonConvert.Serialize(new { Success = false, Message = "锁定失败" });
}
}
return new ContentResult() { Content = json };
}
public ContentResult SelLockBsNo(string bsno, int type,string oplb)
{
var json = JsonConvert.Serialize(new { Success = true, Message = "锁定成功" });
Database db = DatabaseFactory.CreateDatabase();
var i = 0;
var j = 0;
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (type == 2)
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + oplb + " SET BSSTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, bsno);
db.ExecuteNonQuery(cmdUpdate, tran);
i = i + 1;
updateclose(bsno, type);
}
else if (type == 1)
{
var FeeCount = db.ExecuteScalar(CommandType.Text, "SELECT COUNT(GID) as FeeCount from ch_fee where FEESTATUS NOT IN (0,8,9) and BSNO='" +bsno+ "'");
var IntFeeCount = Convert.ToInt16(FeeCount);
if (IntFeeCount == 0)
{
if (oplb == "tMsWlPcHead")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + oplb + " SET FEESTATUS=1 WHERE GID=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, bsno);
db.ExecuteNonQuery(cmdUpdate, tran);
}
else
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + oplb + " SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, bsno);
db.ExecuteNonQuery(cmdUpdate, tran);
}
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, bsno);
db.ExecuteNonQuery(cmdUpdateamend, tran);
i = i + 1;
updateclose(bsno, type);
}
else { j = j + 1; }
}
var msg = "";
if (type == 2)
{
msg = "成功锁定" + i.ToString() + "票业务!";
}
else if (type == 1)
{
msg = "成功锁定" + i.ToString() + "票业务费用锁定," + j.ToString() + "票业务未锁定!";
}
json = JsonConvert.Serialize(new { Success = true, Message = msg });
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
json = JsonConvert.Serialize(new { Success = false, Message = "锁定失败" });
}
}
return new ContentResult() { Content = json };
}
public ContentResult SelFeeLockBsNo(string bsno, string isAccDate, string AccDate,string oplb)
{
var json = JsonConvert.Serialize(new { Success = true, Message = "锁定成功" });
Database db = DatabaseFactory.CreateDatabase();
var i = 0;
var j = 0;
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var FeeCount = db.ExecuteScalar(CommandType.Text, "SELECT COUNT(GID) as FeeCount from ch_fee where FEESTATUS NOT IN (0,8,9) and BSNO='" +bsno+ "'");
var IntFeeCount = Convert.ToInt16(FeeCount);
if (IntFeeCount == 0)
{
if (isAccDate == "1")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " +oplb + " SET FEESTATUS=1,ACCDATE=@ACCDATE WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, bsno);
db.AddInParameter(cmdUpdate, "@ACCDATE", DbType.String, AccDate);
db.ExecuteNonQuery(cmdUpdate, tran);
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=1,ACCDATE=@ACCDATE WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, bsno);
db.AddInParameter(cmdUpdateamend, "@ACCDATE", DbType.String, AccDate);
db.ExecuteNonQuery(cmdUpdateamend, tran);
updateclose(bsno, 1);
}
else
{
if (oplb == "tMsWlPcHead")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + oplb + " SET FEESTATUS=1 WHERE GID=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, bsno);
db.ExecuteNonQuery(cmdUpdate, tran);
}
else
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + oplb + " SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, bsno);
db.ExecuteNonQuery(cmdUpdate, tran);
}
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, bsno);
db.ExecuteNonQuery(cmdUpdateamend, tran);
updateclose(bsno, 1);
}
i = i + 1;
}
else { j = j + 1; }
var msg = "";
msg = "成功锁定" + i.ToString() + "票业务费用锁定," + j.ToString() + "票业务未锁定!";
json = JsonConvert.Serialize(new { Success = true, Message = msg });
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
json = JsonConvert.Serialize(new { Success = false, Message = "锁定失败" });
}
}
return new ContentResult() { Content = json };
}
public ContentResult AllLock(string billsql, int type)
{
var billData=GetFeeDataList(billsql,Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "锁定成功" });
Database db = DatabaseFactory.CreateDatabase();
var i = 0;
var j = 0;
var msg = "";
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var enumValue in billData)
{
if (type == 2)
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET BSSTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
//var cmdUpdateamend = db.GetSqlStringCommand(
// @"UPDATE OP_AMEND SET BSSTATUS=1 WHERE BSNO=@BSNO ");
//cmdUpdateamend.Parameters.Clear();
//db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, enumValue.BSNO);
//db.ExecuteNonQuery(cmdUpdateamend, tran);
updateclose(enumValue.BSNO, type);
i = i + 1;
}
else if (type == 1)
{
var FeeCount = db.ExecuteScalar(CommandType.Text, "SELECT COUNT(GID) as FeeCount from ch_fee where FEESTATUS NOT IN (0,8,9) and BSNO='" + enumValue.BSNO + "'");
var IntFeeCount = Convert.ToInt16(FeeCount);
if (IntFeeCount == 0)
{
if (enumValue.OPLB == "tMsWlPcHead")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=1 WHERE GID=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
}
else
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
}
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdateamend, tran);
updateclose(enumValue.BSNO, type);
i = i + 1;
}
else { j = j + 1; }
}
}
if (type == 2)
{
msg = "成功锁定" + i.ToString() + "票业务!";
}
else if (type == 1)
{
msg = "成功锁定" + i.ToString() + "票业务费用锁定," + j.ToString() + "票业务未锁定!";
}
json = JsonConvert.Serialize(new { Success = true, Message = msg });
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
json = JsonConvert.Serialize(new { Success = false, Message = "锁定失败" });
}
}
return new ContentResult() { Content = json };
}
public ContentResult onFeeLockAll(string billsql, string isAccDate, string AccDate)
{
var billData = GetFeeDataList(billsql, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "锁定成功" });
Database db = DatabaseFactory.CreateDatabase();
var i = 0;
var j = 0;
var msg = "";
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var enumValue in billData)
{
var FeeCount = db.ExecuteScalar(CommandType.Text, "SELECT COUNT(GID) as FeeCount from ch_fee where FEESTATUS NOT IN (0,8,9) and BSNO='" + enumValue.BSNO + "'");
var IntFeeCount = Convert.ToInt16(FeeCount);
if (IntFeeCount == 0)
{
if (isAccDate == "1")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=1,ACCDATE=@ACCDATE WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdUpdate, "@ACCDATE", DbType.String, AccDate);
db.ExecuteNonQuery(cmdUpdate, tran);
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=1,ACCDATE=@ACCDATE WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdUpdateamend, "@ACCDATE", DbType.String, AccDate);
db.ExecuteNonQuery(cmdUpdateamend, tran);
updateclose(enumValue.BSNO,1);
}
else
{
if (enumValue.OPLB == "tMsWlPcHead")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=1 WHERE GID=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
}
else
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
}
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=1 WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdateamend, tran);
updateclose(enumValue.BSNO, 1);
}
i = i + 1;
}
else { j = j + 1; }
}
msg = "成功锁定" + i.ToString() + "票业务费用锁定," + j.ToString() + "票业务未锁定!";
json = JsonConvert.Serialize(new { Success = true, Message = msg });
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
json = JsonConvert.Serialize(new { Success = false, Message = "锁定失败" });
}
}
return new ContentResult() { Content = json };
}
public ContentResult SelUnLock(string data, int type)
{
var billData = JsonConvert.Deserialize<List<BSNOLB>>(data);
var json = JsonConvert.Serialize(new { Success = true, Message = "撤销锁定成功" });
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var enumValue in billData)
{
if (type == 2)
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET BSSTATUS=0 WHERE BSNO=@BSNO ");
//2017年4月10日17:26:51 需求编号:SR2017041000009
//Start
if (enumValue.OPLB.Equals("tMsWlPcHead"))
{
cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET BillStatus=0 WHERE gid=@BSNO ");
}
//End
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
updateUnclose(enumValue.BSNO,type);
}
else if (type == 1)
{
if (enumValue.OPLB == "tMsWlPcHead")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=0 WHERE GID=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
}
else
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=0 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
}
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=0 WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdateamend, tran);
updateUnclose(enumValue.BSNO, type);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
json = JsonConvert.Serialize(new { Success = false, Message = "撤销锁定失败" });
}
}
return new ContentResult() { Content = json };
}
public ContentResult SelUnLockBsNo(string bsno, int type,string oplb)
{
var json = JsonConvert.Serialize(new { Success = true, Message = "撤销锁定成功" });
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (type == 2)
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + oplb + " SET BSSTATUS=0 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, bsno);
db.ExecuteNonQuery(cmdUpdate, tran);
updateUnclose(bsno, type);
}
else if (type == 1)
{
if (oplb == "tMsWlPcHead")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + oplb + " SET FEESTATUS=0 WHERE GID=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String,bsno);
db.ExecuteNonQuery(cmdUpdate, tran);
}
else
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + oplb + " SET FEESTATUS=0 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, bsno);
db.ExecuteNonQuery(cmdUpdate, tran);
}
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=0 WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, bsno);
db.ExecuteNonQuery(cmdUpdateamend, tran);
updateUnclose(bsno, type);
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
json = JsonConvert.Serialize(new { Success = false, Message = "撤销锁定失败" });
}
}
return new ContentResult() { Content = json };
}
public ContentResult AllUnLock(string billsql, int type)
{
var period = ChMonthCloseDAL.GetData("1=1", Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(billsql))
{
billsql = billsql + " and ACCDATE>='"+period.PERIOD+"'" ;
}
else
{
billsql = " and ACCDATE>='" + period.PERIOD + "'";
}
var billData = GetFeeDataList(billsql, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "锁定成功" });
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var enumValue in billData)
{
if (type == 2)
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET BSSTATUS=0 WHERE BSNO=@BSNO ");
//2017年4月10日16:50:29 需求编号:SR2017041000009
//Start
if (enumValue.OPLB.Equals("tMsWlPcHead"))
{
cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET BillStatus=0 WHERE gid=@BSNO ");
}
//End
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
updateUnclose(enumValue.BSNO, type);
}
else if (type == 1)
{
if (enumValue.OPLB == "tMsWlPcHead")
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=1 WHERE GID=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
}
else
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE " + enumValue.OPLB + " SET FEESTATUS=0 WHERE BSNO=@BSNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdate, tran);
}
var cmdUpdateamend = db.GetSqlStringCommand(
@"UPDATE OP_AMEND SET FEESTATUS=0 WHERE BSNO=@BSNO ");
cmdUpdateamend.Parameters.Clear();
db.AddInParameter(cmdUpdateamend, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdUpdateamend, tran);
updateUnclose(enumValue.BSNO, type);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
json = JsonConvert.Serialize(new { Success = false, Message = "锁定失败" });
}
}
return new ContentResult() { Content = json };
}
public bool updateclose(string bsno, int type)
{
var result = true;
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (type == 2)
{
var cmdUpdate = db.GetSqlStringCommand(
@"if (select bsno from op_close where bsno='" + bsno + "') is null insert into op_close values(newid(),'" + bsno + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "','" + Convert.ToString(Session["SHOWNAME"]) + "',null,'') else update op_close set BSCLOSETIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "',BSCLOSEOP='" + Convert.ToString(Session["SHOWNAME"]) + "' where BSNO='"+bsno+"' ");
db.ExecuteNonQuery(cmdUpdate, tran);
}
else if (type == 1)
{
var cmdUpdate = db.GetSqlStringCommand(
@"if (select bsno from op_close where bsno='" + bsno + "') is null insert into op_close values(newid(),'" + bsno + "',null,'','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "','" + Convert.ToString(Session["SHOWNAME"]) + "') else update op_close set FEECLOSETIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "',FEECLOSEOP='" + Convert.ToString(Session["SHOWNAME"]) + "' where BSNO='" + bsno + "' ");
db.ExecuteNonQuery(cmdUpdate, tran);
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
}
}
return result;
}
public bool updateUnclose(string bsno, int type)
{
var result = true;
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (type == 2)
{
var cmdUpdate = db.GetSqlStringCommand(
@" update op_close set BSCLOSETIME=null,BSCLOSEOP='' where BSNO='" + bsno + "' ");
db.ExecuteNonQuery(cmdUpdate, tran);
var cmdUpdate2 = db.GetSqlStringCommand(
@"insert into op_unclose values(newid(),'" + bsno + "','2','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "','" + Convert.ToString(Session["SHOWNAME"]) + "') ");
db.ExecuteNonQuery(cmdUpdate2, tran);
}
else if (type == 1)
{
var cmdUpdate = db.GetSqlStringCommand(
@" update op_close set FEECLOSETIME=null,FEECLOSEOP='' where BSNO='" + bsno + "' ");
db.ExecuteNonQuery(cmdUpdate, tran);
var cmdUpdate2 = db.GetSqlStringCommand(
@"insert into op_unclose values(newid(),'" + bsno + "','1','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "','" + Convert.ToString(Session["SHOWNAME"]) + "') ");
db.ExecuteNonQuery(cmdUpdate2, tran);
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
}
}
return result;
}
public ContentResult CreateVouSel(string data, bool ISRATE, string tbRATE, string strVOUDATE, string strPREPARED)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var billData = JsonConvert.Deserialize<List<BSNOLB>>(data);
var json = JsonConvert.Serialize(new { Success = true, Message = "锁定成功" });
Database db = DatabaseFactory.CreateDatabase();
var i = 0;
var j = 0;
var sSQL = "SELECT top 1 * from cw_design";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds == null)
{
json = JsonConvert.Serialize(new { Success = false, Message = "请先设置帐套信息!" });
return new ContentResult() { Content = json };
}
int iResult = 0;
string zt = "";
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["AR"].ToString().Trim() + "'";
DataSet ds2 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 应付RMB
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["AP"].ToString().Trim() + "'";
DataSet ds3 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 应收USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["ARFC"].ToString().Trim() + "'";
DataSet ds6 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 应付USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["APFC"].ToString().Trim() + "'";
DataSet ds7 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 收入RMB
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() + "'";
DataSet ds8 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 支出RMB
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["MBSPENDING"].ToString().Trim() + "'";
DataSet ds9 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 收入USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["TMFCI"].ToString().Trim() + "'";
DataSet ds10 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 支出USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["TMSFC"].ToString().Trim() + "'";
DataSet ds11 = T_ALL_DA.GetAllSQL(sSQL);
foreach (var enumValue in billData)
{
var strEXPLAN = "";
sSQL = "select *";
sSQL += ", FAPCODE=(select top 1 FAPCODE from info_client where SHORTNAME=v_op_bill.CUSTOMERNAME)";
sSQL += ", FARCODE=(select top 1 FARCODE from info_client where SHORTNAME=v_op_bill.CUSTOMERNAME)";
sSQL += ", DEPTID=(select top 1 FINANCESOFTCODE from sys_dept where DEPTNAME=v_op_bill.SALEDEPT and LINKID='" + Convert.ToString(Session["COMPANYID"]) + "')";
sSQL += ", EMPLID=(select top 1 FINANCESOFTCODE from user_baseinfo where USERID in (select gid from [user] where ISDELETED=0 and SHOWNAME=v_op_bill.SALE) and COMPANYNAME=(select [NAME] from [company] where GID='" +Convert.ToString(Session["COMPANYID"])+ "'))";
sSQL += " from v_op_bill where ISNULL(ISVOU,0)=0 AND bsno in ('" + enumValue.BSNO + "')";
DataSet ds5 = T_ALL_DA.GetAllSQL(sSQL);
if (ds5 != null)
{
if (ds.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["CUSTOMERNAME"].ToString().Trim();
}
if (ds.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["CUSTNO"].ToString().Trim();
}
if (ds.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["MBLNO"].ToString().Trim();
}
if (ds.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["VESSEL"].ToString().Trim();
}
if (ds.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["VOYNO"].ToString().Trim();
}
iResult = getSCHxt(ds,"'"+enumValue.BSNO+"'", "", strEXPLAN, ds5.Tables[0].Rows[0]["DEPTID"].ToString().Trim(), ds5.Tables[0].Rows[0]["EMPLID"].ToString().Trim(), ds5.Tables[0].Rows[0]["SALE"].ToString().Trim(), ds5.Tables[0].Rows[0]["MBLNO"].ToString().Trim(), ds2, ds3, ds6, ds7, ds8, ds9, ds10, ds11, Convert.ToString(Session["USERID"]),ISRATE,tbRATE,strVOUDATE,strPREPARED);
}
}
var msg = "";
msg = "成功生成凭证" + i.ToString() + "票业务!";
json = JsonConvert.Serialize(new { Success = true, Message = msg });
return new ContentResult() { Content = json };
}
public ContentResult CreateVouAll(string billsql, bool ISRATE, string tbRATE, string strVOUDATE, string strPREPARED)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
//var billData = JsonConvert.Deserialize<List<BSNOLB>>(data);
var billData = GetVouDataList(billsql, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "锁定成功" });
Database db = DatabaseFactory.CreateDatabase();
var i = 0;
var j = 0;
var sSQL = "SELECT top 1 * from cw_design";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds == null)
{
json = JsonConvert.Serialize(new { Success = false, Message = "请先设置帐套信息!" });
return new ContentResult() { Content = json };
}
int iResult = 0;
string zt = "";
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["AR"].ToString().Trim() + "'";
DataSet ds2 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 应付RMB
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["AP"].ToString().Trim() + "'";
DataSet ds3 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 应收USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["ARFC"].ToString().Trim() + "'";
DataSet ds6 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 应付USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["APFC"].ToString().Trim() + "'";
DataSet ds7 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 收入RMB
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() + "'";
DataSet ds8 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 支出RMB
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["MBSPENDING"].ToString().Trim() + "'";
DataSet ds9 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 收入USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["TMFCI"].ToString().Trim() + "'";
DataSet ds10 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 支出USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["TMSFC"].ToString().Trim() + "'";
DataSet ds11 = T_ALL_DA.GetAllSQL(sSQL);
foreach (var enumValue in billData)
{
var strEXPLAN = "";
sSQL = "select *";
sSQL += ", FAPCODE=(select top 1 FAPCODE from info_client where SHORTNAME=v_op_bill.CUSTOMERNAME)";
sSQL += ", FARCODE=(select top 1 FARCODE from info_client where SHORTNAME=v_op_bill.CUSTOMERNAME)";
sSQL += ", DEPTID=(select top 1 FINANCESOFTCODE from sys_dept where DEPTNAME=v_op_bill.SALEDEPT and LINKID='" + Convert.ToString(Session["COMPANYID"]) + "')";
sSQL += ", EMPLID=(select top 1 FINANCESOFTCODE from user_baseinfo where USERID in (select gid from [user] where ISDELETED=0 and SHOWNAME=v_op_bill.SALE) and COMPANYNAME=(select [NAME] from [company] where GID='" + Convert.ToString(Session["COMPANYID"]) + "'))";
sSQL += " from v_op_bill where ISNULL(ISVOU,0)=0 AND bsno in ('" + enumValue.BSNO + "')";
DataSet ds5 = T_ALL_DA.GetAllSQL(sSQL);
if (ds5 != null)
{
if (ds.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["CUSTOMERNAME"].ToString().Trim();
}
if (ds.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["CUSTNO"].ToString().Trim();
}
if (ds.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["MBLNO"].ToString().Trim();
}
if (ds.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["VESSEL"].ToString().Trim();
}
if (ds.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["VOYNO"].ToString().Trim();
}
iResult = getSCHxt(ds, "'" + enumValue.BSNO + "'", "", strEXPLAN, ds5.Tables[0].Rows[0]["DEPTID"].ToString().Trim(), ds5.Tables[0].Rows[0]["EMPLID"].ToString().Trim(), ds5.Tables[0].Rows[0]["SALE"].ToString().Trim(), ds5.Tables[0].Rows[0]["MBLNO"].ToString().Trim(), ds2, ds3, ds6, ds7, ds8, ds9, ds10, ds11, Convert.ToString(Session["USERID"]), ISRATE, tbRATE, strVOUDATE, strPREPARED);
if (iResult == 1)
i = i + 1;
}
}
var msg = "";
msg = "成功生成凭证" + i.ToString() + "票业务!";
json = JsonConvert.Serialize(new { Success = true, Message = msg });
return new ContentResult() { Content = json };
}
public static int getSCHxt(DataSet ds, string sGids, string strVESSEL, string strEXPLAN, string strDEPTID, string strEMPLID, string strSALE, string strBLNO, DataSet ds2, DataSet ds3, DataSet ds6, DataSet ds7, DataSet ds8, DataSet ds9, DataSet ds10, DataSet ds11, string strUserID, bool ISRATE, string tbRATE, string strVOUDATE, string strPREPARED)
{
#region 基本设置
string sSQL = "";
Decimal iAMTDR = 0;
Decimal iAMTCR = 0;
int iResult = 0;
//差额主营业务收入
Decimal dRMBS = 0;
Decimal dRMBF = 0;
Decimal dUSDS = 0;
Decimal dUSDF = 0;
int n = 0;
Decimal usdRATES = 0;
Decimal usdRATEF = 0;
//Decimal dEXCHANGERATE =0;
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
#endregion
#region 摘要
//ISRPCLIENTNAME 是否收付客户名称
//ISRPCOTCODE 是否收付业务编号
//ISRPETD 是否收付航期
//ISRPMBLNO 是否收付主提单号
//ISRPCUSTNO 是否收付委托编号
//ISRPVESSEL 是否收付船名
//ISRPVOYNO 是否收付航次
string strISEXPLAN = "";
//if (ds.Tables[0].Rows[0]["ISRPCLIENTNAME"].ToString().Trim() == "True")
//{
// strISEXPLAN += " " + ds.Tables[0].Rows[0]["CUSTOMERNAME"].ToString().Trim();
//}
if (ds.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strISEXPLAN += ",CUSTNO";
}
if (ds.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strISEXPLAN += ",MBLNO";
}
if (ds.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
{
strISEXPLAN += ",VESSEL";
}
if (ds.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
{
strISEXPLAN += ",VOYNO";
}
#endregion
string strORDNO = getBSNO();
CwVouchersDA CwVouchersDA = new CwVouchersDA();
IList<CwVouitemsEntity> CwVouitemsEntities = new List<CwVouitemsEntity>();
#region 基本语句
//
//(CASE WHEN FEETYPE = 1 THEN '应收账款' ELSE '应付账款' END) as 类型
//,CUSTOMERNAME 客户名称
//,EXCHANGERATE 汇率
//,CURRENCY 币别`
//,ISADVANCEDPAY 是否垫付
//,SUM(AMOUNT) AS 金额
//,SUM(AMOUNT*EXCHANGERATE) AS 合计金额
if (ISRATE == true)
{
if (ds.Tables[0].Rows[0]["AR"].ToString().Trim() == ds.Tables[0].Rows[0]["ARFC"].ToString().Trim())
{
sSQL = "SELECT (CASE WHEN FEETYPE = 1 THEN '应收账款' ELSE '应付账款' END) as FEETYPE";
sSQL += ", FAPCODE=(select top 1 FAPCODE from info_client where SHORTNAME=VW_ch_fee_op.CUSTOMERNAME)";
sSQL += ", FARCODE=(select top 1 FARCODE from info_client where SHORTNAME=VW_ch_fee_op.CUSTOMERNAME)";
sSQL += ",CUSTOMERNAME,1 EXCHANGERATE,'RMB' CURRENCY,ISADVANCEDPAY,SUM(AMOUNT*EXCHANGERATE) AS je,SUM(AMOUNT*EXCHANGERATE) AS hj " + strISEXPLAN;
sSQL += " From VW_ch_fee_op WHERE 1=1 and bsno in (select BSNO from v_op_bill where isnull(isvou,0)=0 and bsno in(" + sGids.Trim() + ") " + strVESSEL + ")";
sSQL += " GROUP BY FEETYPE,CUSTOMERNAME,ISADVANCEDPAY" + strISEXPLAN;
sSQL += " ORDER BY FEETYPE desc,CUSTOMERNAME" + strISEXPLAN;
}
else
{
sSQL = "SELECT (CASE WHEN FEETYPE = 1 THEN '应收账款' ELSE '应付账款' END) as FEETYPE";
sSQL += ", FAPCODE=(select top 1 FAPCODE from info_client where SHORTNAME=VW_ch_fee_op.CUSTOMERNAME)";
sSQL += ", FARCODE=(select top 1 FARCODE from info_client where SHORTNAME=VW_ch_fee_op.CUSTOMERNAME)";
sSQL += ",CUSTOMERNAME,EXCHANGERATE,CURRENCY,ISADVANCEDPAY,SUM(AMOUNT) AS je,SUM(AMOUNT*EXCHANGERATE) AS hj " + strISEXPLAN;
sSQL += " From VW_ch_fee_op WHERE 1=1 and bsno in (select BSNO from v_op_bill where isnull(isvou,0)=0 and bsno in(" + sGids.Trim() + ") " + strVESSEL + ")";
sSQL += " GROUP BY FEETYPE,CUSTOMERNAME,EXCHANGERATE,CURRENCY,ISADVANCEDPAY" + strISEXPLAN;
sSQL += " ORDER BY FEETYPE desc,CURRENCY,CUSTOMERNAME" + strISEXPLAN;
}
}
else
{
sSQL = "SELECT (CASE WHEN FEETYPE = 1 THEN '应收账款' ELSE '应付账款' END) as FEETYPE";
sSQL += ", FAPCODE=(select top 1 FAPCODE from info_client where SHORTNAME=VW_ch_fee_op.CUSTOMERNAME)";
sSQL += ", FARCODE=(select top 1 FARCODE from info_client where SHORTNAME=VW_ch_fee_op.CUSTOMERNAME)";
sSQL += ",CUSTOMERNAME,EXCHANGERATE,CURRENCY,ISADVANCEDPAY,SUM(AMOUNT) AS je,SUM(AMOUNT*" + tbRATE.Trim() + ") AS hj " + strISEXPLAN;
sSQL += " From VW_ch_fee_op WHERE 1=1 and bsno in (select BSNO from v_op_bill where isnull(isvou,0)=0 and bsno in(" + sGids.Trim() + ") " + strVESSEL + ")";
sSQL += " GROUP BY FEETYPE,CUSTOMERNAME,EXCHANGERATE,CURRENCY,ISADVANCEDPAY" + strISEXPLAN;
sSQL += " ORDER BY FEETYPE desc,CURRENCY,CUSTOMERNAME" + strISEXPLAN;
}
#endregion
DataSet ds1 = T_ALL_DA.GetAllSQL(sSQL);
if (ds1 != null)
{
#region 应收、应付账款
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
n = i;// +1;
if (Math.Round(Decimal.Parse(ds1.Tables[0].Rows[i]["hj"].ToString().Trim()), 2) != 0)
{
CwVouitemsEntity CwVouitemsEntity = new CwVouitemsEntity();
//CwVouitemsEntity.GID 唯一编码 newid()
CwVouitemsEntity.ORDNO = strORDNO.Trim();
CwVouitemsEntity.ITEMNO = n;// 行号
CwVouitemsEntity.PACCID = "";//父级科目贷码
CwVouitemsEntity.PROPERTY = 0;//科目属性
CwVouitemsEntity.GRADE = 0;//科目级别
if (ds1.Tables[0].Rows[i]["FEETYPE"].ToString().Trim() == "应收账款")
{
#region 应收账款
iAMTDR = iAMTDR + Math.Round(Decimal.Parse(ds1.Tables[0].Rows[i]["hj"].ToString().Trim()), 2);
//
if (ds1.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() == "RMB")
{
#region RMB
CwVouitemsEntity.ACCID = ds.Tables[0].Rows[0]["AR"].ToString().Trim();//应收账款科目贷码
CwVouitemsEntity.AMTDR = Math.Round(Decimal.Parse(ds1.Tables[0].Rows[i]["hj"].ToString().Trim()), 2);//本位币借方金额(互斥)
CwVouitemsEntity.AMTCR = 0;//本位币贷方金额(互斥)
CwVouitemsEntity.ISFCY = false;//是否外币
CwVouitemsEntity.FCYNO = "RMB";//外币编号usd
CwVouitemsEntity.FCYDR = 0;//外币借方金额
CwVouitemsEntity.FCYCR = 0;//外币贷方金额
dRMBS += Decimal.Parse(ds1.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
if (ds2 == null)
{
CwVouitemsEntity.ACCNAME = "";//科目名称
CwVouitemsEntity.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.ACCNAME = ds2.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity.ISDEPTACC = Boolean.Parse(ds2.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = Boolean.Parse(ds2.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = Boolean.Parse(ds2.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = Boolean.Parse(ds2.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds2.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.DC = "C";//贷方向
}
}
#endregion
}
else if (ds1.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() != "RMB")
{
#region 外币
CwVouitemsEntity.ACCID = ds.Tables[0].Rows[0]["ARFC"].ToString().Trim();//应收账款外币科目贷码
CwVouitemsEntity.AMTDR = Math.Round(Decimal.Parse(ds1.Tables[0].Rows[i]["hj"].ToString().Trim()), 2);//本位币借方金额(互斥)
CwVouitemsEntity.AMTCR = 0;//本位币贷方金额(互斥)
CwVouitemsEntity.ISFCY = true;//是否外币
CwVouitemsEntity.FCYNO = "USD";//外币编号usd
CwVouitemsEntity.FCYDR = Decimal.Parse(ds1.Tables[0].Rows[i]["je"].ToString().Trim());//外币借方金额
CwVouitemsEntity.FCYCR = 0;//外币贷方金额
dUSDS += Decimal.Parse(ds1.Tables[0].Rows[i]["je"].ToString().Trim());//本位币借方金额(互斥)
if (ds6 == null)
{
CwVouitemsEntity.ACCNAME = "";//科目名称
CwVouitemsEntity.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.ACCNAME = ds6.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity.ISDEPTACC = Boolean.Parse(ds6.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = Boolean.Parse(ds6.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = Boolean.Parse(ds6.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = Boolean.Parse(ds6.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds6.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.DC = "C";//贷方向
}
}
usdRATES = Decimal.Parse(ds1.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
#endregion
}
if (ds2.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
CwVouitemsEntity.CORPID = ds1.Tables[0].Rows[i]["FAPCODE"].ToString().Trim();//客户(系统)
CwVouitemsEntity.CUSTOMERNAME = ds1.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
}
else
{
CwVouitemsEntity.CORPID = "";//客户(系统)
CwVouitemsEntity.CUSTOMERNAME = "";//客户(系统)
}
#endregion
}
else if (ds1.Tables[0].Rows[i]["FEETYPE"].ToString().Trim() == "应付账款")
{
#region 应付账款
iAMTCR = iAMTCR + Math.Round(Decimal.Parse(ds1.Tables[0].Rows[i]["hj"].ToString().Trim()), 2);
//
if (ds1.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() == "RMB")
{
#region RMB
CwVouitemsEntity.ACCID = ds.Tables[0].Rows[0]["AP"].ToString().Trim();//应付账款科目贷码
CwVouitemsEntity.AMTDR = 0;//本位币借方金额(互斥)
CwVouitemsEntity.AMTCR = Math.Round(Decimal.Parse(ds1.Tables[0].Rows[i]["je"].ToString().Trim()), 2);//本位币贷方金额(互斥)
CwVouitemsEntity.ISFCY = false;//是否外币
CwVouitemsEntity.FCYNO = "RMB";//外币编号usd
CwVouitemsEntity.FCYDR = 0;//外币借方金额
CwVouitemsEntity.FCYCR = 0;//外币贷方金额
dRMBF += Decimal.Parse(ds1.Tables[0].Rows[i]["je"].ToString().Trim());//本位币贷方金额(互斥)
if (ds3 == null)
{
CwVouitemsEntity.ACCNAME = "";//科目名称
CwVouitemsEntity.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity.DC = "C";//贷方向
}
else
{
CwVouitemsEntity.ACCNAME = ds3.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity.ISDEPTACC = Boolean.Parse(ds3.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = Boolean.Parse(ds3.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = Boolean.Parse(ds3.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = Boolean.Parse(ds3.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds3.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.DC = "C";//贷方向
}
}
#endregion
}
else if (ds1.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() != "RMB")
{
#region 外币
CwVouitemsEntity.ACCID = ds.Tables[0].Rows[0]["APFC"].ToString().Trim();//应付账款外币科目贷码
CwVouitemsEntity.AMTDR = 0;//本位币借方金额(互斥)
CwVouitemsEntity.AMTCR = Math.Round(Decimal.Parse(ds1.Tables[0].Rows[i]["hj"].ToString().Trim()), 2);//本位币贷方金额(互斥)
CwVouitemsEntity.ISFCY = true;//是否外币
CwVouitemsEntity.FCYNO = "USD";//外币编号usd
CwVouitemsEntity.FCYDR = 0;//外币借方金额
CwVouitemsEntity.FCYCR = Decimal.Parse(ds1.Tables[0].Rows[i]["je"].ToString().Trim());//外币贷方金额
dUSDF += Decimal.Parse(ds1.Tables[0].Rows[i]["je"].ToString().Trim());//本位币贷方金额(互斥)
if (ds7 == null)
{
CwVouitemsEntity.ACCNAME = "";//科目名称
CwVouitemsEntity.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity.DC = "C";//贷方向
}
else
{
CwVouitemsEntity.ACCNAME = ds7.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity.ISDEPTACC = Boolean.Parse(ds7.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = Boolean.Parse(ds7.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = Boolean.Parse(ds7.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = Boolean.Parse(ds7.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds7.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.DC = "C";//贷方向
}
}
usdRATEF = Decimal.Parse(ds1.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
#endregion
}
if (ds3.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
CwVouitemsEntity.CORPID = ds1.Tables[0].Rows[i]["FAPCODE"].ToString().Trim();//客户(系统)
CwVouitemsEntity.CUSTOMERNAME = ds1.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
}
else
{
CwVouitemsEntity.CORPID = "";//客户(系统)
CwVouitemsEntity.CUSTOMERNAME = "";//客户(系统)
}
#endregion
}
CwVouitemsEntity.FCYEXRATE = Decimal.Parse(ds1.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
CwVouitemsEntity.QTYUNIT = "";//数量包装单位
CwVouitemsEntity.QTYDR = 0;//借方数量
CwVouitemsEntity.QTYCR = 0;//贷方数量
CwVouitemsEntity.EXPLAN = strEXPLAN + " " + ds1.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//摘要,规则生成 "转运费" +
CwVouitemsEntity.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity.SALE = strSALE;//人员名称
CwVouitemsEntity.PITEMID = 0;//父级项目编号
CwVouitemsEntity.ITEMID = "0";//项目编号
CwVouitemsEntity.FIELD1 = "";//预留字段1
CwVouitemsEntity.FIELD2 = "";//预留字段2
CwVouitemsEntity.FIELD3 = "";//预留字段3
CwVouitemsEntity.FIELD4 = "";//预留字段4
CwVouitemsEntity.FIELD5 = "";//预留字段5
CwVouitemsEntity.FIELD6 = "";//预留字段6
CwVouitemsEntity.FIELD7 = "";//预留字段7
CwVouitemsEntity.FIELD8 = "";//预留字段8
CwVouitemsEntity.FIELD9 = "";//预留字段9
CwVouitemsEntity.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity.ISSYS = true;//是否手动录入
}
CwVouitemsEntity.FSETTLCODE = "";//结算方式
CwVouitemsEntity.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity.BLNO = strBLNO;//
if (strBLNO.Trim() == "")
{
if (ds.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
CwVouitemsEntity.BLNO = ds1.Tables[0].Rows[i]["mblno"].ToString().Trim();//
}
}
CwVouitemsEntities.Add(CwVouitemsEntity);
}
}
#endregion
#region 收入\成本 生成 全额\差额
Decimal dRMB = dRMBS - dRMBF;
Decimal dUSD = dUSDS - dUSDF;
//收入\成本 生成 全额\差额
Decimal strJie = dRMBS + dUSDS * usdRATES;
Decimal strDai = dRMBF + dUSDF * usdRATEF;
if (ds.Tables[0].Rows[0]["ISTCOIIED"].ToString().Trim() == "True")//是否核算外币
{
if (ds.Tables[0].Rows[0]["AMCODE"].ToString().Trim() == "1")//全额
{
//for (int j = 0; j < ds1.Tables[0].Rows.Count; j++)
//{
#region 全额
#endregion
//}
#region 全额
Decimal dlSR = dRMBS;
if (dlSR != 0)
{
#region 收入RMB
n = n + 1;
CwVouitemsEntity CwVouitemsEntity2 = new CwVouitemsEntity();
//CwVouitemsEntity2.GID 唯一编码 newid()
CwVouitemsEntity2.ORDNO = strORDNO.Trim();
CwVouitemsEntity2.ITEMNO = n;// 行号
CwVouitemsEntity2.PACCID = "";//父级科目贷码
CwVouitemsEntity2.PROPERTY = 0;//科目属性
CwVouitemsEntity2.GRADE = 0;//科目级别
CwVouitemsEntity2.ACCID = ds.Tables[0].Rows[0]["MBINCOME"].ToString().Trim();//主营业务收入科目贷码
CwVouitemsEntity2.AMTDR = 0;//本位币借方金额(互斥)
CwVouitemsEntity2.AMTCR = dRMBS;//本位币贷方金额(互斥)
strDai = strDai + dRMBS;
CwVouitemsEntity2.ISFCY = false;//是否外币
CwVouitemsEntity2.FCYNO = "RMB";//外币编号usd
CwVouitemsEntity2.FCYDR = 0;//外币借方金额
CwVouitemsEntity2.FCYCR = 0;//外币贷方金额
if (ds8 == null)
{
CwVouitemsEntity2.ACCNAME = "";//科目名称
CwVouitemsEntity2.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
}
else
{
CwVouitemsEntity2.ACCNAME = ds8.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity2.ISDEPTACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds8.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity2.DC = "D";//借方向
}
else
{
CwVouitemsEntity2.DC = "C";//贷方向
}
}
CwVouitemsEntity2.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
CwVouitemsEntity2.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
CwVouitemsEntity2.FCYEXRATE = 1;//汇率
//dEXCHANGERATE = Decimal.Parse(ds1.Tables[0].Rows[j]["EXCHANGERATE"].ToString().Trim());//汇率
CwVouitemsEntity2.QTYUNIT = "";//数量包装单位
CwVouitemsEntity2.QTYDR = 0;//借方数量
CwVouitemsEntity2.QTYCR = 0;//贷方数量
CwVouitemsEntity2.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
CwVouitemsEntity2.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity2.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity2.SALE = strSALE;//人员名称
CwVouitemsEntity2.PITEMID = 0;//父级项目编号
CwVouitemsEntity2.ITEMID = "0";//项目编号
CwVouitemsEntity2.FIELD1 = "";//预留字段1
CwVouitemsEntity2.FIELD2 = "";//预留字段2
CwVouitemsEntity2.FIELD3 = "";//预留字段3
CwVouitemsEntity2.FIELD4 = "";//预留字段4
CwVouitemsEntity2.FIELD5 = "";//预留字段5
CwVouitemsEntity2.FIELD6 = "";//预留字段6
CwVouitemsEntity2.FIELD7 = "";//预留字段7
CwVouitemsEntity2.FIELD8 = "";//预留字段8
CwVouitemsEntity2.FIELD9 = "";//预留字段9
CwVouitemsEntity2.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity2.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity2.ISSYS = true;//是否手动录入
}
CwVouitemsEntity2.FSETTLCODE = "";//结算方式
CwVouitemsEntity2.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity2.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity2.BLNO = strBLNO;//
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity2);
}
dlSR = dUSDS * usdRATES;
if (dlSR != 0)
{
#region 收入USD
n = n + 1;
CwVouitemsEntity CwVouitemsEntity2 = new CwVouitemsEntity();
//CwVouitemsEntity2.GID 唯一编码 newid()
CwVouitemsEntity2.ORDNO = strORDNO.Trim();
CwVouitemsEntity2.ITEMNO = n;// 行号
CwVouitemsEntity2.PACCID = "";//父级科目贷码
CwVouitemsEntity2.PROPERTY = 0;//科目属性
CwVouitemsEntity2.GRADE = 0;//科目级别
CwVouitemsEntity2.ACCID = ds.Tables[0].Rows[0]["MBINCOME"].ToString().Trim();//主营业务收入科目贷码
CwVouitemsEntity2.AMTDR = 0;//本位币借方金额(互斥)
CwVouitemsEntity2.AMTCR = (dUSDS * usdRATES);//本位币贷方金额(互斥)
strDai = strDai + (dUSDS * usdRATES);
CwVouitemsEntity2.ISFCY = true;//是否外币
CwVouitemsEntity2.FCYNO = "USD";//外币编号usd
CwVouitemsEntity2.FCYDR = 0;//外币借方金额
CwVouitemsEntity2.FCYCR = dUSDS;//外币贷方金额
CwVouitemsEntity2.FCYEXRATE = usdRATES;//汇率
if (ds8 == null)
{
CwVouitemsEntity2.ACCNAME = "";//科目名称
CwVouitemsEntity2.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
}
else
{
CwVouitemsEntity2.ACCNAME = ds8.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity2.ISDEPTACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds8.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity2.DC = "D";//借方向
}
else
{
CwVouitemsEntity2.DC = "C";//贷方向
}
}
CwVouitemsEntity2.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
CwVouitemsEntity2.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
//dEXCHANGERATE = Decimal.Parse(ds1.Tables[0].Rows[j]["EXCHANGERATE"].ToString().Trim());//汇率
CwVouitemsEntity2.QTYUNIT = "";//数量包装单位
CwVouitemsEntity2.QTYDR = 0;//借方数量
CwVouitemsEntity2.QTYCR = 0;//贷方数量
CwVouitemsEntity2.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
CwVouitemsEntity2.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity2.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity2.SALE = strSALE;//人员名称
CwVouitemsEntity2.PITEMID = 0;//父级项目编号
CwVouitemsEntity2.ITEMID = "0";//项目编号
CwVouitemsEntity2.FIELD1 = "";//预留字段1
CwVouitemsEntity2.FIELD2 = "";//预留字段2
CwVouitemsEntity2.FIELD3 = "";//预留字段3
CwVouitemsEntity2.FIELD4 = "";//预留字段4
CwVouitemsEntity2.FIELD5 = "";//预留字段5
CwVouitemsEntity2.FIELD6 = "";//预留字段6
CwVouitemsEntity2.FIELD7 = "";//预留字段7
CwVouitemsEntity2.FIELD8 = "";//预留字段8
CwVouitemsEntity2.FIELD9 = "";//预留字段9
CwVouitemsEntity2.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity2.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity2.ISSYS = true;//是否手动录入
}
CwVouitemsEntity2.FSETTLCODE = "";//结算方式
CwVouitemsEntity2.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity2.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity2.BLNO = strBLNO;//
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity2);
}
Decimal dlZC = dRMBF;
if (dlZC != 0)
{
#region 支出RMB
n = n + 1;
CwVouitemsEntity CwVouitemsEntity4 = new CwVouitemsEntity();
//CwVouitemsEntity4.GID 唯一编码 newid()
CwVouitemsEntity4.ORDNO = strORDNO.Trim();
CwVouitemsEntity4.ITEMNO = n;// 行号
CwVouitemsEntity4.PACCID = "";//父级科目贷码
CwVouitemsEntity4.PROPERTY = 0;//科目属性
CwVouitemsEntity4.GRADE = 0;//科目级别
CwVouitemsEntity4.ACCID = ds.Tables[0].Rows[0]["MBSPENDING"].ToString().Trim();//主营业务支出科目贷码
CwVouitemsEntity4.AMTDR = dRMBF;//本位币借方金额(互斥)
strJie = strJie + dRMBF;
CwVouitemsEntity4.AMTCR = 0;//本位币贷方金额(互斥)
CwVouitemsEntity4.ISFCY = false;//是否外币
CwVouitemsEntity4.FCYNO = "RMB";//外币编号usd
CwVouitemsEntity4.FCYDR = 0;//外币借方金额
CwVouitemsEntity4.FCYCR = 0;//外币贷方金额
if (ds9 == null)
{
CwVouitemsEntity4.ACCNAME = "";//科目名称
CwVouitemsEntity4.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity4.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity4.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity4.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity4.DC = "D";//借方向
}
else
{
CwVouitemsEntity4.ACCNAME = ds9.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity4.ISDEPTACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity4.ISEMPLACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity4.ISCORPACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity4.ISITEMACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds9.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity4.DC = "D";//借方向
}
else
{
CwVouitemsEntity4.DC = "C";//贷方向
}
}
CwVouitemsEntity4.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
CwVouitemsEntity4.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
CwVouitemsEntity4.FCYEXRATE = 1;//汇率
//dEXCHANGERATE = Decimal.Parse(ds1.Tables[0].Rows[j]["EXCHANGERATE"].ToString().Trim());//汇率
CwVouitemsEntity4.QTYUNIT = "";//数量包装单位
CwVouitemsEntity4.QTYDR = 0;//借方数量
CwVouitemsEntity4.QTYCR = 0;//贷方数量
CwVouitemsEntity4.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
CwVouitemsEntity4.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity4.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity4.SALE = strSALE;//人员名称
CwVouitemsEntity4.PITEMID = 0;//父级项目编号
CwVouitemsEntity4.ITEMID = "0";//项目编号
CwVouitemsEntity4.FIELD1 = "";//预留字段1
CwVouitemsEntity4.FIELD2 = "";//预留字段2
CwVouitemsEntity4.FIELD3 = "";//预留字段3
CwVouitemsEntity4.FIELD4 = "";//预留字段4
CwVouitemsEntity4.FIELD5 = "";//预留字段5
CwVouitemsEntity4.FIELD6 = "";//预留字段6
CwVouitemsEntity4.FIELD7 = "";//预留字段7
CwVouitemsEntity4.FIELD8 = "";//预留字段8
CwVouitemsEntity4.FIELD9 = "";//预留字段9
CwVouitemsEntity4.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity4.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity4.ISSYS = true;//是否手动录入
}
CwVouitemsEntity4.FSETTLCODE = "";//结算方式
CwVouitemsEntity4.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity4.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity4.BLNO = strBLNO;//
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity4);
}
dlZC = dUSDF * usdRATEF;
if (dlZC != 0)
{
#region 支出USD
n = n + 1;
CwVouitemsEntity CwVouitemsEntity4 = new CwVouitemsEntity();
//CwVouitemsEntity4.GID 唯一编码 newid()
CwVouitemsEntity4.ORDNO = strORDNO.Trim();
CwVouitemsEntity4.ITEMNO = n;// 行号
CwVouitemsEntity4.PACCID = "";//父级科目贷码
CwVouitemsEntity4.PROPERTY = 0;//科目属性
CwVouitemsEntity4.GRADE = 0;//科目级别
CwVouitemsEntity4.ACCID = ds.Tables[0].Rows[0]["MBSPENDING"].ToString().Trim();//主营业务支出科目贷码
CwVouitemsEntity4.AMTDR = (dUSDF * usdRATEF);//本位币借方金额(互斥)
strJie = strJie + (dUSDF * usdRATEF);
CwVouitemsEntity4.AMTCR = 0;//本位币贷方金额(互斥)
CwVouitemsEntity4.ISFCY = true;//是否外币
CwVouitemsEntity4.FCYNO = "USD";//外币编号usd
CwVouitemsEntity4.FCYDR = dUSDF;//外币借方金额
CwVouitemsEntity4.FCYCR = 0;//外币贷方金额
CwVouitemsEntity4.FCYEXRATE = usdRATEF;//汇率
if (ds9 == null)
{
CwVouitemsEntity4.ACCNAME = "";//科目名称
CwVouitemsEntity4.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity4.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity4.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity4.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity4.DC = "D";//借方向
}
else
{
CwVouitemsEntity4.ACCNAME = ds9.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity4.ISDEPTACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity4.ISEMPLACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity4.ISCORPACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity4.ISITEMACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds9.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity4.DC = "D";//借方向
}
else
{
CwVouitemsEntity4.DC = "C";//贷方向
}
}
CwVouitemsEntity4.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
CwVouitemsEntity4.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
//dEXCHANGERATE = Decimal.Parse(ds1.Tables[0].Rows[j]["EXCHANGERATE"].ToString().Trim());//汇率
CwVouitemsEntity4.QTYUNIT = "";//数量包装单位
CwVouitemsEntity4.QTYDR = 0;//借方数量
CwVouitemsEntity4.QTYCR = 0;//贷方数量
CwVouitemsEntity4.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
CwVouitemsEntity4.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity4.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity4.SALE = strSALE;//人员名称
CwVouitemsEntity4.PITEMID = 0;//父级项目编号
CwVouitemsEntity4.ITEMID = "0";//项目编号
CwVouitemsEntity4.FIELD1 = "";//预留字段1
CwVouitemsEntity4.FIELD2 = "";//预留字段2
CwVouitemsEntity4.FIELD3 = "";//预留字段3
CwVouitemsEntity4.FIELD4 = "";//预留字段4
CwVouitemsEntity4.FIELD5 = "";//预留字段5
CwVouitemsEntity4.FIELD6 = "";//预留字段6
CwVouitemsEntity4.FIELD7 = "";//预留字段7
CwVouitemsEntity4.FIELD8 = "";//预留字段8
CwVouitemsEntity4.FIELD9 = "";//预留字段9
CwVouitemsEntity4.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity4.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity4.ISSYS = true;//是否手动录入
}
CwVouitemsEntity4.FSETTLCODE = "";//结算方式
CwVouitemsEntity4.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity4.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity4.BLNO = strBLNO;//
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity4);
}
#endregion
}
else if (ds.Tables[0].Rows[0]["AMCODE"].ToString().Trim() == "2")//差额
{
#region 差额
if (dRMB != 0)
{
#region dRMB != 0
CwVouitemsEntity CwVouitemsEntity1 = new CwVouitemsEntity();
//CwVouitemsEntity1.GID 唯一编码 newid()
CwVouitemsEntity1.ORDNO = strORDNO.Trim();
n = n + 1;
CwVouitemsEntity1.ITEMNO = n;// 行号
CwVouitemsEntity1.PACCID = "";//父级科目贷码
CwVouitemsEntity1.PROPERTY = 0;//科目属性
CwVouitemsEntity1.GRADE = 0;//科目级别
CwVouitemsEntity1.ACCID = ds.Tables[0].Rows[0]["MBINCOME"].ToString().Trim();//主营业务收入科目贷码
CwVouitemsEntity1.AMTDR = 0;//本位币借方金额(互斥)
CwVouitemsEntity1.AMTCR = Decimal.Parse(dRMB.ToString().Trim());//本位币贷方金额(互斥)
strDai = strDai + Decimal.Parse(dRMB.ToString().Trim());
CwVouitemsEntity1.ISFCY = false;//是否外币
CwVouitemsEntity1.FCYNO = "RMB";//外币编号usd
CwVouitemsEntity1.FCYDR = 0;//外币借方金额
CwVouitemsEntity1.FCYCR = 0;//外币贷方金额
if (ds8 == null)
{
CwVouitemsEntity1.ACCNAME = "";//科目名称
CwVouitemsEntity1.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity1.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity1.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity1.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity1.DC = "C";//贷方向
}
else
{
CwVouitemsEntity1.ACCNAME = ds8.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity1.ISDEPTACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity1.ISEMPLACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity1.ISCORPACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity1.ISITEMACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds8.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity1.DC = "D";//借方向
}
else
{
CwVouitemsEntity1.DC = "C";//贷方向
}
}
CwVouitemsEntity1.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
CwVouitemsEntity1.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
CwVouitemsEntity1.FCYEXRATE = 1;//汇率
CwVouitemsEntity1.QTYUNIT = "";//数量包装单位
CwVouitemsEntity1.QTYDR = 0;//借方数量
CwVouitemsEntity1.QTYCR = 0;//贷方数量
CwVouitemsEntity1.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
CwVouitemsEntity1.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity1.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity1.SALE = strSALE;//人员名称
CwVouitemsEntity1.PITEMID = 0;//父级项目编号
CwVouitemsEntity1.ITEMID = "0";//项目编号
CwVouitemsEntity1.FIELD1 = "";//预留字段1
CwVouitemsEntity1.FIELD2 = "";//预留字段2
CwVouitemsEntity1.FIELD3 = "";//预留字段3
CwVouitemsEntity1.FIELD4 = "";//预留字段4
CwVouitemsEntity1.FIELD5 = "";//预留字段5
CwVouitemsEntity1.FIELD6 = "";//预留字段6
CwVouitemsEntity1.FIELD7 = "";//预留字段7
CwVouitemsEntity1.FIELD8 = "";//预留字段8
CwVouitemsEntity1.FIELD9 = "";//预留字段9
CwVouitemsEntity1.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity1.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity1.ISSYS = true;//是否手动录入
}
CwVouitemsEntity1.FSETTLCODE = "";//结算方式
CwVouitemsEntity1.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity1.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity1.BLNO = strBLNO;//
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity1);
}
if (dUSD != 0)
{
#region dUSD != 0
CwVouitemsEntity CwVouitemsEntity3 = new CwVouitemsEntity();
CwVouitemsEntity3.ORDNO = strORDNO.Trim();
n = n + 1;
CwVouitemsEntity3.ITEMNO = n;// 行号
CwVouitemsEntity3.PACCID = "";//父级科目贷码
CwVouitemsEntity3.PROPERTY = 0;//科目属性
CwVouitemsEntity3.GRADE = 0;//科目级别
CwVouitemsEntity3.ACCID = ds.Tables[0].Rows[0]["TMFCI"].ToString().Trim();//应收账款外币科目贷码
CwVouitemsEntity3.AMTDR = 0;//本位币借方金额(互斥)
CwVouitemsEntity3.AMTCR = Decimal.Parse(dUSD.ToString().Trim()) * (usdRATEF == 0 ? usdRATES : usdRATEF);//本位币贷方金额(互斥)
strDai = strDai + Decimal.Parse(dUSD.ToString().Trim()) * (usdRATEF == 0 ? usdRATES : usdRATEF);
CwVouitemsEntity3.ISFCY = true;//是否外币
CwVouitemsEntity3.FCYNO = "USD";//外币编号usd
CwVouitemsEntity3.FCYDR = 0;//外币借方金额
CwVouitemsEntity3.FCYCR = Decimal.Parse(dUSD.ToString().Trim());//外币贷方金额
if (ds10 == null)
{
CwVouitemsEntity3.ACCNAME = "";//科目名称
CwVouitemsEntity3.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity3.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity3.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity3.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity3.DC = "C";//贷方向
}
else
{
CwVouitemsEntity3.ACCNAME = ds10.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity3.ISDEPTACC = Boolean.Parse(ds10.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity3.ISEMPLACC = Boolean.Parse(ds10.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity3.ISCORPACC = Boolean.Parse(ds10.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity3.ISITEMACC = Boolean.Parse(ds10.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds10.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity3.DC = "D";//借方向
}
else
{
CwVouitemsEntity3.DC = "C";//贷方向
}
}
CwVouitemsEntity3.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
CwVouitemsEntity3.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
CwVouitemsEntity3.FCYEXRATE = (usdRATEF == 0 ? usdRATES : usdRATEF);//汇率
CwVouitemsEntity3.QTYUNIT = "";//数量包装单位
CwVouitemsEntity3.QTYDR = 0;//借方数量
CwVouitemsEntity3.QTYCR = 0;//贷方数量
CwVouitemsEntity3.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
CwVouitemsEntity3.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity3.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity3.SALE = strSALE;//人员名称
CwVouitemsEntity3.PITEMID = 0;//父级项目编号
CwVouitemsEntity3.ITEMID = "0";//项目编号
CwVouitemsEntity3.FIELD1 = "";//预留字段1
CwVouitemsEntity3.FIELD2 = "";//预留字段2
CwVouitemsEntity3.FIELD3 = "";//预留字段3
CwVouitemsEntity3.FIELD4 = "";//预留字段4
CwVouitemsEntity3.FIELD5 = "";//预留字段5
CwVouitemsEntity3.FIELD6 = "";//预留字段6
CwVouitemsEntity3.FIELD7 = "";//预留字段7
CwVouitemsEntity3.FIELD8 = "";//预留字段8
CwVouitemsEntity3.FIELD9 = "";//预留字段9
CwVouitemsEntity3.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity3.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity3.ISSYS = true;//是否手动录入
}
CwVouitemsEntity3.FSETTLCODE = "";//结算方式
CwVouitemsEntity3.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity3.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity3.BLNO = strBLNO;//
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity3);
}
#endregion
}
}
else
{
if (ds.Tables[0].Rows[0]["AMCODE"].ToString().Trim() == "1")//全额
{
#region 全额
// Decimal dlSR = dRMBS + (dUSDS * usdRATES);
Decimal dlSR = iAMTDR;
if (dlSR != 0)
{
#region 收入
n = n + 1;
CwVouitemsEntity CwVouitemsEntity2 = new CwVouitemsEntity();
//CwVouitemsEntity2.GID 唯一编码 newid()
CwVouitemsEntity2.ORDNO = strORDNO.Trim();
CwVouitemsEntity2.ITEMNO = n;// 行号
CwVouitemsEntity2.PACCID = "";//父级科目贷码
CwVouitemsEntity2.PROPERTY = 0;//科目属性
CwVouitemsEntity2.GRADE = 0;//科目级别
CwVouitemsEntity2.ACCID = ds.Tables[0].Rows[0]["MBINCOME"].ToString().Trim();//主营业务收入科目贷码
CwVouitemsEntity2.AMTDR = 0;//本位币借方金额(互斥)
//CwVouitemsEntity2.AMTCR = dRMBS + (dUSDS * usdRATES);//本位币贷方金额(互斥)
//strDai = strDai + dRMBS + (dUSDS * usdRATES);
CwVouitemsEntity2.AMTCR = iAMTDR;//本位币贷方金额(互斥)
strDai = strDai + iAMTDR;
CwVouitemsEntity2.ISFCY = false;//是否外币
CwVouitemsEntity2.FCYNO = "RMB";//外币编号usd
CwVouitemsEntity2.FCYDR = 0;//外币借方金额
CwVouitemsEntity2.FCYCR = 0;//外币贷方金额
if (ds8 == null)
{
CwVouitemsEntity2.ACCNAME = "";//科目名称
CwVouitemsEntity2.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
}
else
{
CwVouitemsEntity2.ACCNAME = ds8.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity2.ISDEPTACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds8.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity2.DC = "D";//借方向
}
else
{
CwVouitemsEntity2.DC = "C";//贷方向
}
}
CwVouitemsEntity2.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
CwVouitemsEntity2.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
CwVouitemsEntity2.FCYEXRATE = 1;//汇率
//dEXCHANGERATE = Decimal.Parse(ds1.Tables[0].Rows[j]["EXCHANGERATE"].ToString().Trim());//汇率
CwVouitemsEntity2.QTYUNIT = "";//数量包装单位
CwVouitemsEntity2.QTYDR = 0;//借方数量
CwVouitemsEntity2.QTYCR = 0;//贷方数量
CwVouitemsEntity2.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
CwVouitemsEntity2.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity2.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity2.SALE = strSALE;//人员名称
CwVouitemsEntity2.PITEMID = 0;//父级项目编号
CwVouitemsEntity2.ITEMID = "0";//项目编号
CwVouitemsEntity2.FIELD1 = "";//预留字段1
CwVouitemsEntity2.FIELD2 = "";//预留字段2
CwVouitemsEntity2.FIELD3 = "";//预留字段3
CwVouitemsEntity2.FIELD4 = "";//预留字段4
CwVouitemsEntity2.FIELD5 = "";//预留字段5
CwVouitemsEntity2.FIELD6 = "";//预留字段6
CwVouitemsEntity2.FIELD7 = "";//预留字段7
CwVouitemsEntity2.FIELD8 = "";//预留字段8
CwVouitemsEntity2.FIELD9 = "";//预留字段9
CwVouitemsEntity2.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity2.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity2.ISSYS = true;//是否手动录入
}
CwVouitemsEntity2.FSETTLCODE = "";//结算方式
CwVouitemsEntity2.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity2.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity2.BLNO = strBLNO;//
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity2);
}
Decimal dlZC = dRMBF + (dUSDF * usdRATEF);
if (dlZC != 0)
{
#region 支出
n = n + 1;
CwVouitemsEntity CwVouitemsEntity4 = new CwVouitemsEntity();
//CwVouitemsEntity4.GID 唯一编码 newid()
CwVouitemsEntity4.ORDNO = strORDNO.Trim();
CwVouitemsEntity4.ITEMNO = n;// 行号
CwVouitemsEntity4.PACCID = "";//父级科目贷码
CwVouitemsEntity4.PROPERTY = 0;//科目属性
CwVouitemsEntity4.GRADE = 0;//科目级别
CwVouitemsEntity4.ACCID = ds.Tables[0].Rows[0]["MBSPENDING"].ToString().Trim();//主营业务支出科目贷码
//CwVouitemsEntity4.AMTDR = dRMBF + (dUSDF * usdRATEF);//本位币借方金额(互斥)
//strJie = strJie + dRMBF + (dUSDF * usdRATEF);
CwVouitemsEntity4.AMTDR = iAMTCR;//本位币借方金额(互斥)
strJie = strJie + iAMTCR;
CwVouitemsEntity4.AMTCR = 0;//本位币贷方金额(互斥)
CwVouitemsEntity4.ISFCY = false;//是否外币
CwVouitemsEntity4.FCYNO = "RMB";//外币编号usd
CwVouitemsEntity4.FCYDR = 0;//外币借方金额
CwVouitemsEntity4.FCYCR = 0;//外币贷方金额
if (ds9 == null)
{
CwVouitemsEntity4.ACCNAME = "";//科目名称
CwVouitemsEntity4.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity4.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity4.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity4.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity4.DC = "D";//借方向
}
else
{
CwVouitemsEntity4.ACCNAME = ds9.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity4.ISDEPTACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity4.ISEMPLACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity4.ISCORPACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity4.ISITEMACC = Boolean.Parse(ds9.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds9.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity4.DC = "D";//借方向
}
else
{
CwVouitemsEntity4.DC = "C";//贷方向
}
}
CwVouitemsEntity4.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
CwVouitemsEntity4.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
CwVouitemsEntity4.FCYEXRATE = 1;//汇率
//dEXCHANGERATE = Decimal.Parse(ds1.Tables[0].Rows[j]["EXCHANGERATE"].ToString().Trim());//汇率
CwVouitemsEntity4.QTYUNIT = "";//数量包装单位
CwVouitemsEntity4.QTYDR = 0;//借方数量
CwVouitemsEntity4.QTYCR = 0;//贷方数量
CwVouitemsEntity4.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
CwVouitemsEntity4.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity4.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity4.SALE = strSALE;//人员名称
CwVouitemsEntity4.PITEMID = 0;//父级项目编号
CwVouitemsEntity4.ITEMID = "0";//项目编号
CwVouitemsEntity4.FIELD1 = "";//预留字段1
CwVouitemsEntity4.FIELD2 = "";//预留字段2
CwVouitemsEntity4.FIELD3 = "";//预留字段3
CwVouitemsEntity4.FIELD4 = "";//预留字段4
CwVouitemsEntity4.FIELD5 = "";//预留字段5
CwVouitemsEntity4.FIELD6 = "";//预留字段6
CwVouitemsEntity4.FIELD7 = "";//预留字段7
CwVouitemsEntity4.FIELD8 = "";//预留字段8
CwVouitemsEntity4.FIELD9 = "";//预留字段9
CwVouitemsEntity4.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity4.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity4.ISSYS = true;//是否手动录入
}
CwVouitemsEntity4.FSETTLCODE = "";//结算方式
CwVouitemsEntity4.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity4.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity4.BLNO = strBLNO;//
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity4);
}
#endregion
}
else if (ds.Tables[0].Rows[0]["AMCODE"].ToString().Trim() == "2")//差额
{
if (dRMB != 0 || dUSD != 0)
{
#region 差额
CwVouitemsEntity CwVouitemsEntity1 = new CwVouitemsEntity();
//CwVouitemsEntity1.GID 唯一编码 newid()
CwVouitemsEntity1.ORDNO = strORDNO.Trim();
n = n + 1;
CwVouitemsEntity1.ITEMNO = n;// 行号
CwVouitemsEntity1.PACCID = "";//父级科目贷码
CwVouitemsEntity1.PROPERTY = 0;//科目属性
CwVouitemsEntity1.GRADE = 0;//科目级别
CwVouitemsEntity1.ACCID = ds.Tables[0].Rows[0]["MBINCOME"].ToString().Trim();//主营业务收入科目贷码
CwVouitemsEntity1.AMTDR = 0;//本位币借方金额(互斥)
CwVouitemsEntity1.AMTCR = Decimal.Parse(dRMB.ToString().Trim()) + (Decimal.Parse(dUSD.ToString().Trim()) * (usdRATEF == 0 ? usdRATES : usdRATEF));//本位币贷方金额(互斥)
strDai = strDai + Decimal.Parse(dRMB.ToString().Trim()) + (Decimal.Parse(dUSD.ToString().Trim()) * (usdRATEF == 0 ? usdRATES : usdRATEF));
CwVouitemsEntity1.ISFCY = false;//是否外币
CwVouitemsEntity1.FCYNO = "RMB";//外币编号usd
CwVouitemsEntity1.FCYDR = 0;//外币借方金额
CwVouitemsEntity1.FCYCR = 0;//外币贷方金额
if (ds8 == null)
{
CwVouitemsEntity1.ACCNAME = "";//科目名称
CwVouitemsEntity1.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity1.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity1.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity1.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity1.DC = "C";//贷方向
}
else
{
CwVouitemsEntity1.ACCNAME = ds8.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity1.ISDEPTACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity1.ISEMPLACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity1.ISCORPACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity1.ISITEMACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds8.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity1.DC = "D";//借方向
}
else
{
CwVouitemsEntity1.DC = "C";//贷方向
}
}
CwVouitemsEntity1.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
CwVouitemsEntity1.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
CwVouitemsEntity1.FCYEXRATE = 1;//汇率
CwVouitemsEntity1.QTYUNIT = "";//数量包装单位
CwVouitemsEntity1.QTYDR = 0;//借方数量
CwVouitemsEntity1.QTYCR = 0;//贷方数量
CwVouitemsEntity1.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
CwVouitemsEntity1.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity1.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity1.SALE = strSALE;//人员名称
CwVouitemsEntity1.PITEMID = 0;//父级项目编号
CwVouitemsEntity1.ITEMID = "0";//项目编号
CwVouitemsEntity1.FIELD1 = "";//预留字段1
CwVouitemsEntity1.FIELD2 = "";//预留字段2
CwVouitemsEntity1.FIELD3 = "";//预留字段3
CwVouitemsEntity1.FIELD4 = "";//预留字段4
CwVouitemsEntity1.FIELD5 = "";//预留字段5
CwVouitemsEntity1.FIELD6 = "";//预留字段6
CwVouitemsEntity1.FIELD7 = "";//预留字段7
CwVouitemsEntity1.FIELD8 = "";//预留字段8
CwVouitemsEntity1.FIELD9 = "";//预留字段9
CwVouitemsEntity1.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity1.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity1.ISSYS = true;//是否手动录入
}
CwVouitemsEntity1.FSETTLCODE = "";//结算方式
CwVouitemsEntity1.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity1.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity1.BLNO = strBLNO;//
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity1);
}
}
}
#endregion
#region 插入主表
string rq = strVOUDATE;
CwVouchersEntity CwVouchersEntity = new CwVouchersEntity();
CwVouchersEntity.ORDNO = strORDNO.Trim();//唯一编码 newid() varchar (36)
CwVouchersEntity.VOUDATE = DateTime.Parse(rq.Trim());//凭证日期="";//datetime="";// 
CwVouchersEntity.ACCYEAR = rq.Trim().Substring(0, 4);//年="";//int="";// 
int iM1 = rq.Trim().IndexOf("-") + 1;
int iM2 = rq.Trim().LastIndexOf("-");
CwVouchersEntity.ACCMONTH = rq.Trim().Substring(iM1, iM2 - iM1);//月="";//int="";// 
string strVOUNO = getVOUNO(rq.Trim().Substring(0, 4), rq.Trim().Substring(iM1, iM2 - iM1));
CwVouchersEntity.VOUNO = strVOUNO;//月初清零 varchar (16)
if (iM2 - iM1 == 1)
{
strVOUNO = rq.Trim().Substring(0, 4) + "0" + rq.Trim().Substring(iM1, iM2 - iM1) + strVOUNO;
}
else
{
strVOUNO = rq.Trim().Substring(0, 4) + rq.Trim().Substring(iM1, iM2 - iM1) + strVOUNO;
}
CwVouchersEntity.VOUALLNO = strVOUNO;//月初清零 varchar (16)
CwVouchersEntity.VKNO = ds.Tables[0].Rows[0]["TVW"].ToString().Trim();//凭证字="";//varchar="";//(8)
CwVouchersEntity.ATTACHS = int.Parse(ds.Tables[0].Rows[0]["AFFIXNO"].ToString().Trim());//附件(单据)数="";//int="";// 
CwVouchersEntity.AMTDR = strJie;// iAMTDR;//本位币借方="";//numeric(18, 2)="";// 
CwVouchersEntity.AMTCR = strDai;//iAMTDR;// iAMTCR;//本位币贷方="";//numeric(18, 2)="";// 
CwVouchersEntity.FCY = "";//是否含有外币科目="";//varchar="";//(1)
CwVouchersEntity.QTY = "";//是否含有数量科目="";//varchar="";//(1)
CwVouchersEntity.VOUPROP = "";//凭证属性="";//varchar="";//(1)
//CwVouchersEntity.PREPARED = T_ALL_DA.GetStrSQL("FINANCESOFTCODE", "select top 1 FINANCESOFTCODE from user_baseinfo where USERID in (select top 1 gid from [user] where SHOWNAME='" + this.hd_comboPREPARED.Value.Trim() + "' and ISDELETED=0)");//制单人="";//varchar="";//(10)
CwVouchersEntity.PREPARED = strPREPARED;//制单人="";//varchar="";//(10)
CwVouchersEntity.CHECKED = "";//审核人="";//varchar="";//(10)
CwVouchersEntity.ENTERED = "";//记账人="";//varchar="";//(10)
CwVouchersEntity.ERRMSG = "";//错误信息="";//varchar="";//(6)
CwVouchersEntity.ISDELETE = false;//是否废除="";//bit="";//Y
CwVouchersEntity.DELETEUSER = "";//废除操作人="";//Varchar(36)="";//Y
//CwVouchersEntity.DELETETIME="";//废除时间="";//Datetime="";//Y
#endregion
//生成入库
string strSel = " and bsno in(" + sGids + ") " + strVESSEL;
if (CwVouitemsEntities.Count == 0)
{
iResult = 2;
}
else
iResult = CwVouchersDA.setInsertAll(CwVouchersEntity, CwVouitemsEntities,"v_op_bill", strVOUNO, strSel, strUserID, 1);
}
return iResult;
}
static public String getBSNO()
{
string strBSNO = Guid.NewGuid().ToString();
strBSNO = strBSNO.Replace("-", "");
strBSNO = "VOU" + strBSNO;
return strBSNO;
}
static public String getVOUNO(string strY, string strM)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sVOUNO = "";
string strVOUNO = "select top 1 VOUNO from cw_vouchers where ACCYEAR='" + strY + "' and ACCMONTH='" + strM + "' order by convert(decimal(10),VOUNO) desc";
strVOUNO = T_ALL_DA.GetStrSQL("VOUNO", strVOUNO);
if (strVOUNO.Trim() == "")
{
strVOUNO = "0001";
}
else
{
sVOUNO = (int.Parse(strVOUNO) + 1).ToString().Trim();
strVOUNO = sVOUNO;
for (int i = 0; i < 4 - sVOUNO.Length; i++)
{
strVOUNO = "0" + strVOUNO;
}
}
return strVOUNO;
}
static public List<MsOpBill> GetVouDataList(string condition, string userid, string username, string companyid)
{
var strDa = GetRangDAStr("index", "BSVOUCHER", userid, username, companyid);
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and isnull(B.ISCANCEL,0)<>1 ";
}
else
{
condition = " isnull(B.ISCANCEL,0)<>1 ";
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BSNO,OPLB,OPLBNAME,ACCDATE,MBLNO,HBLNO,CUSTNO");
strSql.Append(",CUSTOMERNAME");
strSql.Append(",VESSEL,VOYNO,ETD,PORTLOAD");
strSql.Append(",PORTDISCHARGE,INPUTBY,OP,CUSTSERVICE");
strSql.Append(",DOC,SALE,BSSTATUS,FEESTATUS");
strSql.Append(" from v_op_bill b where ISNULL(b.ISVOU,0)=0 ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" AND " + condition);
}
strSql.Append(" order by BsNo");
return SetFeeData(strSql);
}
static public List<MsOpBill> GetFeeDataList(string strCondition,string userid,string username,string companyid)
{
var rangstr = GetRangDAStr("index","FEE",userid,username,companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BSNO,OPLB,OPLBNAME,ACCDATE,MBLNO,HBLNO,CUSTNO");
strSql.Append(",CUSTOMERNAME");
strSql.Append(",VESSEL,VOYNO,ETD,PORTLOAD");
strSql.Append(",PORTDISCHARGE,INPUTBY,OP,CUSTSERVICE");
strSql.Append(",DOC,SALE,BSSTATUS,FEESTATUS");
strSql.Append(" from v_op_bill b ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by BsNo");
return SetFeeData(strSql);
}
private static List<MsOpBill> SetFeeData(StringBuilder strSql)
{
var headList = new List<MsOpBill>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpBill data = new MsOpBill();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToString(reader["ETD"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.OPLB = Convert.ToString(reader["OPLB"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
data.FEESTATUS = Convert.ToBoolean(reader["FEESTATUS"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#region 判断是否允许费用全部解锁,并返回出错问题的委托单号
public ContentResult isAllUnLock(string billsql, int type)
{
string sError = "";
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var json = JsonConvert.Serialize(new { Success = true, Message = "锁定成功" });
//
var rangstr = GetRangDAStr("index", "FEE", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(billsql))
{
billsql = " and " + billsql + " and " + rangstr;
}
else
{
billsql = " and " + rangstr;
}
}
else
{
if (!string.IsNullOrEmpty(billsql))
{
billsql = " and " + billsql;
}
}
//
string sSQL = "SELECT * from v_op_bill as b where bsno in (select bsno from ch_fee where VOUALLNO is not null and VOUALLNO<>'' group by bsno)" + billsql;
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
sError += "、" + ds.Tables[0].Rows[i]["OPLBNAME"].ToString().Trim() + ds.Tables[0].Rows[i]["CUSTNO"].ToString().Trim();
}
}
}
//
if (sError.Trim() != "")
{
sError = sError.Substring(1);
sError = "已经生成总账凭证的数据不允许解锁费用,委托编号:" + sError + "!";
json = JsonConvert.Serialize(new { Success = false, Message = sError });
}
return new ContentResult() { Content = json };
}
#endregion
#region 判断是否允许费用选中解锁,并返回出错问题的委托单号
public ContentResult isSelUnLock(string strGids)
{
string sError = "";
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var json = JsonConvert.Serialize(new { Success = true, Message = "撤销锁定成功" });
//
if (!string.IsNullOrEmpty(strGids))
{
strGids = " and bsno in('" + strGids.Replace(",","','") + "')";
}
//
string sSQL = "SELECT * from v_op_bill as b where bsno in (select bsno from ch_fee where VOUALLNO is not null and VOUALLNO<>'' group by bsno)" + strGids;
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
sError += "、" + ds.Tables[0].Rows[i]["OPLBNAME"].ToString().Trim() + ds.Tables[0].Rows[i]["CUSTNO"].ToString().Trim();
}
}
}
//
if (sError.Trim() != "")
{
sError = sError.Substring(1);
sError = "已经生成总账凭证的数据不允许解锁费用,委托编号:" + sError + "!";
json = JsonConvert.Serialize(new { Success = false, Message = sError });
}
return new ContentResult() { Content = json };
}
#endregion
//2017年4月13日 Add By 张义伟
#region 判断是否具有业务解锁权限
/// <summary>
///
/// </summary>
/// <param name="autype">1:费用解锁 2业务解锁 3费用锁定 4业务锁定</param>
/// <returns></returns>
public ContentResult CheckAuthority (int autype) {
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var cookies = new Cookies();
var auid = "04B61245-C3A8-46D4-9FE4-746A805244B5";//费用解锁权限id
if (autype==2)
{
auid = "04B61145-C3A8-46D4-9FE4-746A805244B5";//业务解锁权限id
}
else if (autype==4)
{
auid = "04B61145-C3A8-46D4-9FE4-746A805244A1";//业务锁定权限id
}
else if (autype==3)
{
auid = "04B61245-C3A8-46D4-9FE4-746A805244A2";//费用锁定权限id
}
var uid = cookies.getCookie(DSWeb.TruckMng.Comm.Cookie.CookieConstant.UserId);//登录组织
string sSQL = "select * from user_action where USERID = '" + uid + "' AND ACTIONID ='"+auid+"'";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
int rstCnt = 0;
if (ds != null)
{
rstCnt = ds.Tables[0].Rows.Count;
}
var json = JsonConvert.Serialize(new { Success = true, Message = "有操作权限" });
if (rstCnt<=0)
{
json = JsonConvert.Serialize(new { Success = false, Message = "无操作权限" });
}
return new ContentResult() { Content = json };
}
#endregion
}
}