You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/DAL/MsCwVouchersGlInvoice/MsCwVouchersGlInvoiceDAL.cs

6310 lines
379 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsCwVouchersGlInvoiceEntity;
using DSWeb.MvcShipping.Models.MsCwAccitemsGl;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using HcUtility.Core;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.Account.Models.MsCwVouchersGl3;
using DSWeb.MvcShipping.Models.MsCwVouchersGl;
using DSWeb.MvcShipping.Models.MsCwVouitemsGl;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
namespace DSWeb.MvcShipping.DAL.MsCwVouchersGlInvoiceDAL
{
public class MsCwVouchersGlInvoiceDAL
{
#region 按业务_查询、导出、打印
static public List<MsCwVouchersGlInvoiceEntity> GetDataList(string strCondition, string companyid, string strUSERID, string sort = null)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
var strSql = new StringBuilder();
strSql.Append(" SELECT GID,INVOICENO,BILLNO,CUSTOMERNAME,ACTUALCUSTOMERNAME,INVOICECUSTNAME,INVOICEMAKETIME,BANK,ACCOUNT,BSNO,VESSELVOYAGE,ETD,POL,POD");
strSql.Append(" ,FEEITEM,AMOUNT,INVAMOUNT,AMOUNTCAPITAL,OTCURRAMOUNT,CURRENCY,REMARK,APPLICANT,APPLYTIME,OPERATOR,LICENSECODE,TAXCODE,INVOICETYPE,BILLSTATUS");
strSql.Append(" ,ISNEEDPRINT,ISNEEDFEE,OPERATETIME,MBLNO,EXCHANGERATE,PRINTCAPITAL,PRINTAMOUNT,PRINTTITLE,COMPANYID,VOUCHERNO ");
strSql.Append(" ,CUSTRATENO,CUSTADDRTEL,CUSTBANK,INVOICECATEGORY,ISDELETE,DELETEOPERATOR,DELETETIME,PTORRED,SETRED ");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY) as INVOICECATEGORYREF");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97009 and EnumValueID=cm.INVOICETYPE) as INVOICETYPEREF");
strSql.Append(",(case cm.billstatus when 1 then '已锁定' else '未锁定' end) as BILLSTATUSREF");
strSql.Append(",(select ShowName from [user] where GID=cm.OPERATOR) as OPERATORNAME");
strSql.Append(",(select ShowName from [user] where GID=cm.DELETEOPERATOR) as DELOPERATORNAME");
strSql.Append(",dbo.GetFeeNoStlByInvNo(cm.BILLNO) as NOSTL,FEEAMOUNT ");
strSql.Append(",VOUNO=(select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=cm.GID and BSTABLENAME='ch_fee_invoice' and STARTGID='" + strCwSTARTGID + "')");
strSql.Append(" FROM ch_fee_invoice cm where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by CURRENCY,OPERATETIME DESC");
}
return SetData(strSql);
}
private static List<MsCwVouchersGlInvoiceEntity> SetData(StringBuilder strSql)
{
var headList = new List<MsCwVouchersGlInvoiceEntity>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCwVouchersGlInvoiceEntity data = new MsCwVouchersGlInvoiceEntity();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.BILLNO = Convert.ToString(reader["BILLNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.ACTUALCUSTOMERNAME = Convert.ToString(reader["ACTUALCUSTOMERNAME"]);
if (reader["CURRENCY"] != DBNull.Value)
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
data.INVOICENO = Convert.ToString(reader["INVOICENO"]);
data.INVOICECUSTNAME = Convert.ToString(reader["INVOICECUSTNAME"]);
data.INVOICECATEGORY = Convert.ToString(reader["INVOICECATEGORY"]);
data.INVOICECATEGORYREF = Convert.ToString(reader["INVOICECATEGORYREF"]);
if (reader["INVOICETYPE"] != DBNull.Value)
data.INVOICETYPE = Convert.ToInt32(reader["INVOICETYPE"]);
data.INVOICETYPEREF = Convert.ToString(reader["INVOICETYPEREF"]);
if (reader["BILLSTATUS"] != DBNull.Value)
data.BILLSTATUS = Convert.ToInt32(reader["BILLSTATUS"]);
data.BILLSTATUSREF = Convert.ToString(reader["BILLSTATUSREF"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.VESSELVOYAGE = Convert.ToString(reader["VESSELVOYAGE"]);
data.ETD = Convert.ToString(reader["ETD"]);
data.POL = Convert.ToString(reader["POL"]);
data.POD = Convert.ToString(reader["POD"]);
if (reader["AMOUNT"] != DBNull.Value)
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
if (reader["INVAMOUNT"] != DBNull.Value)
data.INVAMOUNT = Convert.ToDecimal(reader["INVAMOUNT"]);
data.AMOUNTCAPITAL = Convert.ToString(reader["AMOUNTCAPITAL"]);
if (reader["OTCURRAMOUNT"] != DBNull.Value)
data.OTCURRAMOUNT = Convert.ToDecimal(reader["OTCURRAMOUNT"]);
if (reader["EXCHANGERATE"] != DBNull.Value)
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
else
data.EXCHANGERATE = 0;
data.APPLICANT = Convert.ToString(reader["APPLICANT"]);
// data.APPLICANTNAME = Convert.ToString(reader["APPLICANTNAME"]);
if (reader["APPLYTIME"] != DBNull.Value)
data.APPLYTIME = Convert.ToDateTime(reader["APPLYTIME"]);
if (reader["INVOICEMAKETIME"] != DBNull.Value)
data.INVOICEMAKETIME = Convert.ToDateTime(reader["INVOICEMAKETIME"]).ToString("yyyy-MM-dd");
data.OPERATOR = Convert.ToString(reader["OPERATOR"]);
data.OPERATORNAME = Convert.ToString(reader["OPERATORNAME"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
data.CUSTRATENO = Convert.ToString(reader["CUSTRATENO"]);
data.CUSTADDRTEL = Convert.ToString(reader["CUSTADDRTEL"]);
data.CUSTBANK = Convert.ToString(reader["CUSTBANK"]);
if (reader["ISNEEDPRINT"] != DBNull.Value)
data.ISNEEDPRINT = Convert.ToString(reader["ISNEEDPRINT"]);
if (reader["ISNEEDFEE"] != DBNull.Value)
data.ISNEEDFEE = Convert.ToString(reader["ISNEEDFEE"]);
if (reader["ISDELETE"] != DBNull.Value)
data.ISDELETE = Convert.ToString(reader["ISDELETE"]);
data.DELETEOPERATOR = Convert.ToString(reader["DELETEOPERATOR"]);
data.DELOPERATORNAME = Convert.ToString(reader["DELOPERATORNAME"]);
if (reader["DELETETIME"] != DBNull.Value)
data.DELETETIME = Convert.ToDateTime(reader["DELETETIME"]);
data.NOSTL = Convert.ToString(reader["NOSTL"]);
data.FEEAMOUNT = Convert.ToString(reader["FEEAMOUNT"]);
data.VOUNO = (reader["VOUNO"] == null ? "" : Convert.ToString(reader["VOUNO"]));
data.SETRED = Convert.ToString(reader["SETRED"]);
data.PTORRED = Convert.ToString(reader["PTORRED"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
//查询、导出
static public string GetDataListSQL(string strCondition, string companyid, string strUSERID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
var strSql = new StringBuilder();
strSql.Append(" SELECT GID,INVOICENO,BILLNO,CUSTOMERNAME,ACTUALCUSTOMERNAME,INVOICECUSTNAME,INVOICEMAKETIME,BANK,ACCOUNT,BSNO,VESSELVOYAGE,ETD,POL,POD");
strSql.Append(" ,FEEITEM,AMOUNT,INVAMOUNT,AMOUNTCAPITAL,OTCURRAMOUNT,CURRENCY,REMARK,APPLICANT,APPLYTIME,OPERATOR,LICENSECODE,TAXCODE,INVOICETYPE,BILLSTATUS");
strSql.Append(" ,ISNEEDPRINT,ISNEEDFEE,OPERATETIME,MBLNO,EXCHANGERATE,PRINTCAPITAL,PRINTAMOUNT,PRINTTITLE,COMPANYID,VOUCHERNO ");
strSql.Append(" ,CUSTRATENO,CUSTADDRTEL,CUSTBANK,INVOICECATEGORY,ISDELETE,DELETEOPERATOR,DELETETIME,PTORRED,SETRED ");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY) as INVOICECATEGORYREF");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97009 and EnumValueID=cm.INVOICETYPE) as INVOICETYPEREF");
strSql.Append(",(case cm.billstatus when 1 then '已锁定' else '未锁定' end) as BILLSTATUSREF");
strSql.Append(",(select ShowName from [user] where GID=cm.OPERATOR) as OPERATORNAME");
strSql.Append(",(select ShowName from [user] where GID=cm.DELETEOPERATOR) as DELOPERATORNAME");
strSql.Append(",dbo.GetFeeNoStlByInvNo(cm.BILLNO) as NOSTL,FEEAMOUNT ");
strSql.Append(",VOUNO=(select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=cm.GID and BSTABLENAME='ch_fee_invoice' and STARTGID='" + strCwSTARTGID + "')");
strSql.Append(" FROM ch_fee_invoice cm where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
return strSql.ToString();
}
#endregion
#region 生成结转凭证
#region 币别列表
static public List<MsCwVouchersGl4> GetCodeCurrencyList(string strGids, string companyid, string strUserID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
var strSql = new StringBuilder();
strSql.Append("select CURRENCY,(select top 1 BEGRATE from cw_currency_rate where ACCDATE='" + strCwACCDATE + "' and STARTGID='" + strCwSTARTGID + "' and LINKGID in (select GID from code_currency where CODENAME=v_ch_fee_invoice_pz.CURRENCY)) as FCYEXRATE from v_ch_fee_invoice_pz where CURRENCY<>'RMB'");
if (!string.IsNullOrEmpty(strGids))
{
strSql.Append(strGids);
}
else
{
strSql.Append(" and 1<0");
}
strSql.Append(" group by CURRENCY order by CURRENCY");
return SetCodeCurrencyData(strSql);
}
private static List<MsCwVouchersGl4> SetCodeCurrencyData(StringBuilder strSql)
{
var headList = new List<MsCwVouchersGl4>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCwVouchersGl4 data = new MsCwVouchersGl4();
#region Set DB data to Object
data.CURR = (reader["CURRENCY"] == null ? "" : Convert.ToString(reader["CURRENCY"]));
data.FCYEXRATE = (reader["FCYEXRATE"] == null ? "" : Convert.ToString(reader["FCYEXRATE"]));
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 按费用_判断是否生成
public static DBResult onIsCwVouchers(string strGids, string strUserID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
var result = new DBResult();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
strGids = "'" + strGids.Trim().Replace(",", "','") + "'";
string sSQL = "SELECT count(*) as iNum From VW_ch_fee_invoice WHERE 1=1 and GID in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='ch_fee_invoice' and STARTGID='" + strCwSTARTGID + "') and GID in (" + strGids.Trim() + ")";
int iNum = int.Parse(T_ALL_DA.GetStrSQL("iNum", sSQL));
result.Success = true;
result.Message = "";
if (iNum > 0)
{
result.Success = false;
result.Message = "有已经生成凭证的数据,不允许重复生成,请重新选择!";
return result;
}
result.Success = true;
result.Message = "";
return result;
}
#endregion
public static DBResult onAddCwVouchers(string strGids, MsCwVouchersGl3 headData, List<MsCwVouchersGl4> bodyList, string strUserID, string strSHOWNAME, string companyid)
{
Database db = DatabaseFactory.CreateDatabase();
var result = new DBResult();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string sSQL = "";
int iResult = 0;
string zt = "";
string sError = "操作完成!";
string sAndGids = " and GID in ('" + strGids.Trim().Replace(",", "','") + "')";
var CWSTARTUSING = MsSysParamSetDAL.GetData("PARAMNAME='CWSTARTUSING'");
if (CWSTARTUSING.PARAMVALUE != "")
{
if (strCwSTARTGID != CWSTARTUSING.PARAMVALUE)
{
result.Success = false;
result.Message = "当前账套不是设置的账套,不能生成凭证!";
return result;
}
}
var VOUAUTOCHECK = MsSysParamSetDAL.GetData("PARAMNAME='VOUAUTOCHECK'").PARAMVALUE;
#region 生成前的判断
//帐套设置
sSQL = "SELECT top 1 * from cw_design_gl where [STARTGID]='" + strCwSTARTGID + "' and AR<>'' and ARFC<>'' and MBINCOME<>'' and TMFCI<>'' and OUTPUTTAX<>''";// and CORPID='"+companyid+"'
DataSet dsCwDesign = T_ALL_DA.GetAllSQL(sSQL);
if (dsCwDesign == null)
{
result.Success = false;
result.Message = "请先设置帐套信息!" + result.Message;
return result;
}
//帐套设置_核算科目
sSQL = "SELECT [GID],[LINKGID],[ITEMGID],[OPTYPE],[MODIFIEDUSER],[MODIFIEDTIME],[MODIFIEDUSERNAME]=(select top 1 SHOWNAME from [user] where gid=[cw_design_gl_item].MODIFIEDUSER),[ITEMCODE]=(SELECT top 1 ITEMCODE from cw_item where GID=[cw_design_gl_item].[ITEMGID]),[ITEMNAME]=(SELECT top 1 ITEMNAME from cw_item where GID=[cw_design_gl_item].[ITEMGID]) FROM [cw_design_gl_item] WITH(NOLOCK) where LINKGID in (SELECT top 1 GID from cw_design_gl WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "') ORDER BY [ITEMCODE]";
DataSet dsCwDesignItem = T_ALL_DA.GetAllSQL(sSQL);
//判断总账科目是否完全配置好
//科目设置 应收USD
sSQL = "SELECT count(CURRENCY) as inum From VW_ch_fee_invoice WHERE 1=1 and GID not in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='ch_fee_invoice' and STARTGID='" + strCwSTARTGID + "')" + sAndGids + " and CURRENCY<>'RMB' and CURRENCY not in (SELECT CURRENCY from cw_accitems_currency where LINKGID in (SELECT GID from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim() + "')) GROUP BY CURRENCY ORDER BY CURRENCY";
string sNum = T_ALL_DA.GetStrSQL("inum", sSQL);
if (sNum != "" && sNum != "0")
{
result.Success = false;
result.Message = "请先设置应收账款外币科目(" + dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim() + ")的币别信息!" + result.Message;
return result;
}
//判断是否有核算项目的科目
if (dsCwDesignItem == null)
{
sSQL = "SELECT COUNT(*) as inum from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and ISITEMACC=1 and ACCID in ('" + dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim() + "','" + dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim() + "','" + dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() + "','" + dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim() + "','" + dsCwDesign.Tables[0].Rows[0]["OUTPUTTAX"].ToString().Trim() + "','" + dsCwDesign.Tables[0].Rows[0]["INPUTTAX"].ToString().Trim() + "')";
sNum = T_ALL_DA.GetStrSQL("inum", sSQL);
if (sNum != "" && sNum != "0")
{
result.Success = false;
result.Message = "请先设置帐套信息中的核算项目匹配设置!" + result.Message;
return result;
}
}
#endregion
//合并生成发票开出凭证凭证
string[] itemsGID = strGids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (dsCwDesign.Tables[0].Rows[0]["ISCTGCIC"].ToString().Trim() == "True")
{
#region 合并生成发票开出凭证凭证
#region 提前生成凭证号
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
string sACCDATE = headData.VOUDATE.Substring(0, 7);
if (DateTime.Parse(sACCDATE + "-01") < DateTime.Parse(strCwACCDATE + "-01"))
{
sACCDATE = strCwACCDATE;
}
string strBPVW = dsCwDesign.Tables[0].Rows[0]["TVW"].ToString().Trim();
string strVOUNOhj = DSWeb.MvcShipping.DAL.MsBaseInfoDAL.MsBaseInfoDAL.GetCwVOUNO(strBPVW, sACCDATE, strUserID);
string[] items = strVOUNOhj.Trim().Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
string strVOUNO = items[3].ToString().Trim();
string sACCMONTH = DateTime.Parse(headData.VOUDATE.ToString()).Month.ToString();//月
if (sACCMONTH.ToString().Length == 1)
{
sACCMONTH = "0" + sACCMONTH.ToString();//月
}
string cfVOUALLNO = strBPVW + DateTime.Parse(headData.VOUDATE.ToString()).Year.ToString() + sACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
#endregion
DBResult result2 = onIsCwVouchers(strGids, strUserID);//判断是否有已经生成凭证的数据
if (!result2.Success)
{
sError = result.Message;
}
else
{
//把凭证号更新到ch_fee_invoice
//string blSQL = "update ch_fee_invoice set VOUNO='" + cfVOUALLNO + "' where 1=1 and GID not in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='ch_fee_invoice' and STARTGID='" + strCwSTARTGID + "')" + sAndGids + " and '" + cfVOUALLNO + "' NOT in (select VOUNO from ch_fee_invoice where VOUNO<>'' and VOUNO is not NULL)";
//把凭证号和业务GID插入到凭证生成的关系表
string blSQL = "INSERT INTO [cw_vouno_bs_gl]([GID],[BSTABLENAME],[BSGID],[VOUALLNO],[ORDNO],[STARTGID],[CREATEUSER],[CREATETIME])"
+ "select newid() as [GID],'ch_fee_invoice' as [BSTABLENAME],GID as [BSGID],'" + cfVOUALLNO + "' as [VOUALLNO],'' as [ORDNO],'" + strCwSTARTGID + "' as [STARTGID],'" + strUserID + "' as [CREATEUSER],getdate() as [CREATETIME]"
+ " from ch_fee_invoice where 1=1" + sAndGids + " and gid not in (select BSGID from cw_vouno_bs_gl WITH(NOLOCK) where BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "')";
int iCount = db.ExecuteNonQuery(CommandType.Text, blSQL);
//
if (iCount != 0)
{
if (dsCwDesign.Tables[0].Rows[0]["ISINVRATESELF"].ToString().Trim() == "True")
iResult = getInvSC(dsCwDesign, dsCwDesignItem, sAndGids.Trim(), headData, bodyList, strUserID, companyid, cfVOUALLNO, VOUAUTOCHECK);
else iResult = getHxtSC(dsCwDesign, dsCwDesignItem, sAndGids.Trim(), headData, bodyList, strUserID, companyid, cfVOUALLNO, VOUAUTOCHECK);
zt += "," + iResult;
if (zt.IndexOf("-") > 0)
{
sError = "共" + itemsGID.Length + "票发票单生成0条凭证失败1条凭证";
}
else
{
sError = "共" + itemsGID.Length + "票发票单生成1条凭证失败0条凭证";
}
}
else
{
sError = "共" + itemsGID.Length + "票发票单生成1条凭证失败0条凭证";
}
}
#endregion
}
else
{
#region 不 合并生成发票开出凭证凭证
int n = 0;
if (itemsGID.Length > 0)
{
for (int k = 0; k < itemsGID.Length; k++)
{
//按业务
sAndGids = " and GID in ('" + itemsGID[k].ToString().Trim() + "')";
#region 提前生成凭证号
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
string sACCDATE = headData.VOUDATE.Substring(0, 7);
if (DateTime.Parse(sACCDATE + "-01") < DateTime.Parse(strCwACCDATE + "-01"))
{
sACCDATE = strCwACCDATE;
}
string strBPVW = dsCwDesign.Tables[0].Rows[0]["TVW"].ToString().Trim();
string strVOUNOhj = DSWeb.MvcShipping.DAL.MsBaseInfoDAL.MsBaseInfoDAL.GetCwVOUNO(strBPVW, sACCDATE, strUserID);
string[] items2 = strVOUNOhj.Trim().Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
string strVOUNO = items2[3].ToString().Trim();
string sACCMONTH = DateTime.Parse(headData.VOUDATE.ToString()).Month.ToString();//月
if (sACCMONTH.ToString().Length == 1)
{
sACCMONTH = "0" + sACCMONTH.ToString();//月
}
string cfVOUALLNO = strBPVW + DateTime.Parse(headData.VOUDATE.ToString()).Year.ToString() + sACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
#endregion
//把凭证号更新到ch_fee_invoice
//string blSQL = "update ch_fee_invoice set VOUNO='" + cfVOUALLNO + "' where 1=1 and GID not in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='ch_fee_invoice' and STARTGID='" + strCwSTARTGID + "')" + sAndGids + " and '" + cfVOUALLNO + "' NOT in (select VOUNO from ch_fee_invoice where VOUNO<>'' and VOUNO is not NULL)";
//把凭证号和业务GID插入到凭证生成的关系表
string blSQL = "INSERT INTO [cw_vouno_bs_gl]([GID],[BSTABLENAME],[BSGID],[VOUALLNO],[ORDNO],[STARTGID],[CREATEUSER],[CREATETIME])"
+ "select newid() as [GID],'ch_fee_invoice' as [BSTABLENAME],GID as [BSGID],'" + cfVOUALLNO + "' as [VOUALLNO],'' as [ORDNO],'" + strCwSTARTGID + "' as [STARTGID],'" + strUserID + "' as [CREATEUSER],getdate() as [CREATETIME]"
+ " from ch_fee_invoice where 1=1" + sAndGids + " and gid not in (select BSGID from cw_vouno_bs_gl WITH(NOLOCK) where BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "')";
int iCount = db.ExecuteNonQuery(CommandType.Text, blSQL);
//
if (iCount != 0)
{
if (dsCwDesign.Tables[0].Rows[0]["ISINVRATESELF"].ToString().Trim() == "True")
iResult = getInvSC(dsCwDesign, dsCwDesignItem, sAndGids.Trim(), headData, bodyList, strUserID, companyid, cfVOUALLNO, VOUAUTOCHECK);
else
iResult = getHxtSC(dsCwDesign, dsCwDesignItem, sAndGids, headData, bodyList, strUserID, companyid, cfVOUALLNO, VOUAUTOCHECK);
zt += "," + iResult;
if (zt.IndexOf("-") < 0)
{
n++;
}
}
else
{
sError = "有已经生成凭证的数据,不允许重复生成,请重新选择!";
continue;
}
}
}
sError = "共" + itemsGID.Length + "票发票单,生成" + n + "条凭证,失败" + (itemsGID.Length - n) + "条凭证!";
#endregion
}
//
//if (zt.IndexOf("-") > 0)
//{
// result.Success = false;
// result.Message = "操作出错" + result.Message;//部分凭证生成
// return result;
//}
result.Success = true;
result.Message = sError;//"操作完成!";
return result;
}
/// <summary>
/// 生成凭证
/// </summary>
/// <param name="ds">帐套设置数据集</param>
/// <param name="sGids">gid业务编号</param>
/// <returns></returns>
///
/* 按原币生成凭证*/
protected static int getHxtSC(DataSet dsCwDesign, DataSet dsCwDesignItem, string sAndGids, MsCwVouchersGl3 headData, List<MsCwVouchersGl4> bodyList, string strUserID, string strCompanyID, string cfVOUALLNO, string VOUAUTOCHECK)
{
var result = new DBResult();
#region 基本变量
//全部
string sSQL = "";
string strEXPLAN = "";
string strFCY = "RMB";
Decimal dEXCHANGERATE = 0;
//应收应付账款
Decimal iAMTDR = 0;
Decimal iAMTCR = 0;
//差额主营业务收入
Decimal dRMBS = 0;
Decimal dRMBF = 0;
Decimal dUSDS = 0;
Decimal dUSDF = 0;
//总合计
//Decimal strJie = 0;
//Decimal strDai = 0;
string strBPVW = dsCwDesign.Tables[0].Rows[0]["TVW"].ToString().Trim();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
#endregion
#region 科目设置
//科目设置 应收RMB
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim() + "'";
DataSet dsAR = T_ALL_DA.GetAllSQL(sSQL);
//科目设置 应收USD
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim() + "'";
DataSet dsARFC = T_ALL_DA.GetAllSQL(sSQL);
//主营业务收入 收入RMB
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() + "'";
DataSet dsMBINCOME = T_ALL_DA.GetAllSQL(sSQL);
//主营收入外币 收入USD
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim() + "'";
DataSet dsTMFCI = T_ALL_DA.GetAllSQL(sSQL);
//销项税
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["OUTPUTTAX"].ToString().Trim() + "'";
DataSet dsOUTPUTTAX = T_ALL_DA.GetAllSQL(sSQL);
#endregion
string DREXPLAN = dsCwDesign.Tables[0].Rows[0]["INVDREXPLAN"].ToString().Trim();
string CREXPLAN = dsCwDesign.Tables[0].Rows[0]["INVCREXPLAN"].ToString().Trim();
string MBINCOMEEXPLAN = dsCwDesign.Tables[0].Rows[0]["INVMBINCOMEEXPLAN"].ToString().Trim();
string MBSPENDINGEXPLAN = dsCwDesign.Tables[0].Rows[0]["INVMBSPENDINGEXPLAN"].ToString().Trim();
#region 摘要
string strISEXPLAN = "";
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strISEXPLAN += ",CUSTOMERNAME";//是否收付客户名称CUSTOMERNAME
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strISEXPLAN += ",INVOICENO";//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strISEXPLAN += ",MBLNO";//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
strISEXPLAN += ",SALE";//是否主提单号
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",VESSEL";//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",VOYNO";//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",BSSOURCE";//是否业务来源
//}
string strISEXPLANnull = "";
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strISEXPLANnull += ",CUSTOMERNAME";//是否收付客户名称CUSTOMERNAME
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strISEXPLANnull += ",INVOICENO";//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strISEXPLANnull += ",MBLNO";//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
strISEXPLANnull += ",SALE";//是否主提单号
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",VESSEL";//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",VOYNO";//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",BSSOURCE";//是否业务来源
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBILLNO"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",BILLNO_ACAD";//是否申请单号
//}
}
#endregion
#region 票号
if (strISEXPLAN.IndexOf(dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim()) < 0)
{
strISEXPLAN += "," + dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
if (strISEXPLANnull.IndexOf(dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim()) < 0)
{
strISEXPLANnull += "," + dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
}
}
#endregion
#region 核算科目_分录
//string sqlItemAR = "";
//string sqlItemARFC = "";
//string sqlItemMBINCOME = "";
//string sqlItemTMFCI = "";
#endregion
#region 基本数据集
string strORDNO = getGid();
string sqlAR = "";
string sqlARFC = "";
string sqlMBINCOME = "";
string sqlTMFCI = "";
string sqlOUTPUTTAX = "";
string sqlOUTPUTTAXUSD = "";
IList<MsCwVouitemsGl> CwVouitemsEntities = new List<MsCwVouitemsGl>();
string strCondition = sAndGids + " and GID in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='ch_fee_invoice' and VOUALLNO='" + cfVOUALLNO + "' and STARTGID='" + strCwSTARTGID + "')";
//是否按照系统录入汇率
if (headData.ISRATE == true)
{
#region 科目设置应收RMB dsAR、应收USD dsARFC
if (dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim())
{
#region 应收RMB==应收USD
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsAR.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlAR = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " GROUP BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLAN + sISEXPLAN;//
sqlAR += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
//
sqlARFC = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " GROUP BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLAN + sISEXPLAN;//
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
}
else
{
sqlAR = "SELECT INVOICECUSTNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + "";
sqlAR += " GROUP BY INVOICECUSTNAME,VOUNO" + strISEXPLAN + sISEXPLAN;//
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
}
#endregion
}
else
{
#region 应收RMB!=应收USD
//应收RMB
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlAR = "SELECT INVOICECUSTNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " GROUP BY INVOICECUSTNAME,VOUNO" + strISEXPLAN + sISEXPLAN;//
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
//应收USD
#region 核算项目
sISEXPLAN = "";
//是否核算客户
if (dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlARFC = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " GROUP BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLAN + sISEXPLAN;//
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
#endregion
}
#endregion
#region 科目设置主营业务收入RMB dsMBINCOME、主营收入外币USD dsTMFCI
if (dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim())
{
#region 主营业务收入RMB==主营收入外币USD
string sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsMBINCOME.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlMBINCOME = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlMBINCOME += " group BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
//
sqlTMFCI = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlTMFCI += " group BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
}
else
{
sqlMBINCOME = "SELECT INVOICECUSTNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + "";
sqlMBINCOME += " group BY INVOICECUSTNAME,VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
}
#endregion
}
else
{
#region 主营业务收入RMB!=主营收入外币USD
//主营业务收入RMB
string sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlMBINCOME = "SELECT INVOICECUSTNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlMBINCOME += " group BY INVOICECUSTNAME,VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
//主营收入外币USD
sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlTMFCI = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlTMFCI += " group BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
#endregion
}
#endregion
}
else
{
#region 提取费率
string tbRATE = "";
if (bodyList != null)
{
if (bodyList.Count > 0)
{
for (int i = 0; i < bodyList.Count; i++)
{
tbRATE += " WHEN CURRENCY='" + bodyList[i].CURR.ToString().Trim() + "' THEN " + bodyList[i].FCYEXRATE.ToString().Trim();
}
}
}
#endregion
#region 科目设置应收RMB dsAR、应收USD dsARFC
if (dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim())
{
#region 应收RMB==应收USD
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsAR.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlAR = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " group BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLAN + sISEXPLAN;
sqlAR += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
//
sqlARFC = "SELECT INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " group BY INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END),CURRENCY" + strISEXPLAN + sISEXPLAN;
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
}
else
{
sqlAR = "SELECT INVOICECUSTNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + "";
sqlAR += " group BY INVOICECUSTNAME,VOUNO" + strISEXPLAN + sISEXPLAN;
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
}
#endregion
}
else
{
#region 应收RMB!=应收USD
//应收RMB
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlAR = "SELECT INVOICECUSTNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " group BY INVOICECUSTNAME,VOUNO" + strISEXPLAN + sISEXPLAN;
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
//应收USD
#region 核算项目
sISEXPLAN = "";
//是否核算客户
if (dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlARFC = "SELECT INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " group BY INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END),CURRENCY" + strISEXPLAN + sISEXPLAN;
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
#endregion
}
#endregion
#region 科目设置主营业务收入RMB dsMBINCOME、主营收入外币USD dsTMFCI
if (dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim())
{
#region 主营业务收入RMB==主营收入外币USD
string sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsMBINCOME.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlMBINCOME = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlMBINCOME += " group BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
//
sqlTMFCI = "SELECT INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlTMFCI += " group BY INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END),CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
}
else
{
sqlMBINCOME = "SELECT INVOICECUSTNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + "";
sqlMBINCOME += " group BY INVOICECUSTNAME,VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
}
#endregion
}
else
{
#region 主营业务收入RMB!=主营收入外币USD
//主营业务收入RMB
string sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlMBINCOME = "SELECT INVOICECUSTNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlMBINCOME += " group BY INVOICECUSTNAME,VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
//主营收入外币USD
sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlTMFCI = "SELECT INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlTMFCI += " group BY INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END),CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
#endregion
}
#endregion
}
DataSet dsVWChFeeInvoiceAR = T_ALL_DA.GetAllSQL(sqlAR);
DataSet dsVWChFeeInvoiceARFC = null;
if (sqlARFC.Trim() != "")
{
dsVWChFeeInvoiceARFC = T_ALL_DA.GetAllSQL(sqlARFC);
}
DataSet dsVWChFeeInvoiceMBINCOME = T_ALL_DA.GetAllSQL(sqlMBINCOME);
DataSet dsVWChFeeInvoiceTMFCI = null;
if (sqlTMFCI.Trim() != "")
{
dsVWChFeeInvoiceTMFCI = T_ALL_DA.GetAllSQL(sqlTMFCI);
}
#endregion
sqlARFC = "SELECT * from ch_fee_invoice WHERE 1=1" + strCondition + " and NOT EXISTS (SELECT 1 FROM CH_FEE_DO D WHERE D.BILLNO=ch_fee_invoice.BILLNO) ";
DataSet dsVWChFeeAR = T_ALL_DA.GetAllSQL(sqlARFC);
Decimal strJie = 0;
Decimal strDai = 0;
if (dsVWChFeeInvoiceAR != null || dsVWChFeeInvoiceARFC != null)
{
#region 明细表_实体类
#region 插入明细表应收RMB dsAR
if (dsVWChFeeInvoiceAR != null)
{
for (int i = 0; i < dsVWChFeeInvoiceAR.Tables[0].Rows.Count; i++)
{
#region 摘要内容
strEXPLAN = "";
strEXPLAN = DREXPLAN;
var ISEXPLAN = false;
if (strEXPLAN != "") ISEXPLAN = true;
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[客户名称]", dsVWChFeeInvoiceAR.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[发票号]", dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[主提单号]", dsVWChFeeInvoiceAR.Tables[0].Rows[i]["MBLNO"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[揽货人]", dsVWChFeeInvoiceAR.Tables[0].Rows[i]["SALE"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["SALE"].ToString().Trim();//是否主提单号
}
strEXPLAN = strEXPLAN.Replace("[发票抬头]", dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim());
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否收付船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
#endregion
#region 插入明细表 应收账款
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;// 行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
#region 应收账款
iAMTDR = iAMTDR + Decimal.Parse(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["hj"].ToString().Trim());
//
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim();//应收账款科目贷码
MsCwVouitemsGl.AMTDR = Decimal.Parse(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = "RMB";//外币编号usd
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
dRMBS += Decimal.Parse(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
//
MsCwVouitemsGl.ACCNAME = dsAR.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsAR.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
//是否核算客户
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = "";//客户(系统)
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceAR.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsAR.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要
MsCwVouitemsGl.FCYEXRATE = 1;//汇率
dEXCHANGERATE = 1;//汇率
MsCwVouitemsGl.BLNO = "";
string strBLNONAME = dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
if (strBLNONAME.Trim() != "")
{
MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceAR.Tables[0].Rows[i][strBLNONAME].ToString().Trim();
}
//if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
//{
// MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["MBLNO"].ToString().Trim();
//}
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
#endregion
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
#endregion
#region 插入明细表:应收外币 dsARFC
if (dsVWChFeeInvoiceARFC != null)
{
for (int i = 0; i < dsVWChFeeInvoiceARFC.Tables[0].Rows.Count; i++)
{
#region 摘要内容
strEXPLAN = "";
strEXPLAN = DREXPLAN;
var ISEXPLAN = false;
if (strEXPLAN != "") ISEXPLAN = true;
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[客户名称]", dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[发票号]", dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICENO"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("主提单号]", dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["MBLNO"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("揽货人]", dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["SALE"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["SALE"].ToString().Trim();//是否主提单号
}
strEXPLAN = strEXPLAN.Replace("[发票抬头]", dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim());
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否收付船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否收付航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
#endregion
#region 插入明细表 应收账款
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;// 行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
#region 应收账款
iAMTDR = iAMTDR + Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["hj"].ToString().Trim());
//
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim();//应收账款科目贷码
MsCwVouitemsGl.AMTDR = Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CURRENCY"].ToString().Trim();//外币
strFCY = MsCwVouitemsGl.FCYNO;
MsCwVouitemsGl.FCYDR = Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["je"].ToString().Trim());//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
dRMBS += Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
//
MsCwVouitemsGl.ACCNAME = dsARFC.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsARFC.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
//是否核算客户
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = "";//客户(系统)
if (dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceARFC.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsARFC.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要
MsCwVouitemsGl.FCYEXRATE = Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
dEXCHANGERATE = MsCwVouitemsGl.FCYEXRATE;//汇率
MsCwVouitemsGl.BLNO = "";
string strBLNONAME = dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
if (strBLNONAME.Trim() != "")
{
MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceARFC.Tables[0].Rows[i][strBLNONAME].ToString().Trim();
}
//if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
//{
// MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["MBLNO"].ToString().Trim();
//}
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
#endregion
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
#endregion
#region 插入明细表:主营业务收入
Decimal dRMB = dRMBS - dRMBF;
Decimal dUSD = dUSDS - dUSDF;
//收入\成本 生成 全额\差额
strJie = dRMBS + dUSDS * dEXCHANGERATE;
strDai = dRMBF + dUSDF * dEXCHANGERATE;
//
#region 全额
if (dsVWChFeeInvoiceMBINCOME != null)
{
for (int i = 0; i < dsVWChFeeInvoiceMBINCOME.Tables[0].Rows.Count; i++)
{
#region 摘要内容
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
strEXPLAN = "";
strEXPLAN = MBINCOMEEXPLAN;
var ISEXPLAN = false;
if (strEXPLAN != "") ISEXPLAN = true;
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[客户名称]", dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[发票号]", dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["INVOICENO"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[主提单号]", dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["MBLNO"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[揽货人]", dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["SALE"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["SALE"].ToString().Trim();//是否主提单号
}
strEXPLAN = strEXPLAN.Replace("[发票抬头]", dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim());
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
}
else {
strEXPLAN = dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim();
}
#endregion
#region 收入
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;//行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim();//主营业务收入科目贷码
MsCwVouitemsGl.AMTDR = 0;//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币贷方金额(互斥)
strDai = strDai + MsCwVouitemsGl.AMTCR;
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = "RMB";//外币
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
MsCwVouitemsGl.ACCNAME = dsMBINCOME.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsMBINCOME.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
MsCwVouitemsGl.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
MsCwVouitemsGl.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsMBINCOME.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.FCYEXRATE = 1;//汇率
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
MsCwVouitemsGl.BLNO = "";//
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
if (dsVWChFeeInvoiceTMFCI != null)
{
for (int i = 0; i < dsVWChFeeInvoiceTMFCI.Tables[0].Rows.Count; i++)
{
#region 摘要内容
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
strEXPLAN = "";
strEXPLAN = MBINCOMEEXPLAN;
var ISEXPLAN = false;
if (strEXPLAN != "") ISEXPLAN = true;
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[客户名称]", dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[发票号]", dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["INVOICENO"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[主提单号]", dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["MBLNO"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
if (ISEXPLAN)
strEXPLAN = strEXPLAN.Replace("[揽货人]", dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["SALE"].ToString().Trim());
else
strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["SALE"].ToString().Trim();//是否主提单号
}
strEXPLAN = strEXPLAN.Replace("[发票抬头]", dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim());
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
}
else {
strEXPLAN = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim();
}
#endregion
#region 收入_外币
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;//行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim();//主营业务收入科目贷码
MsCwVouitemsGl.AMTDR = 0;//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币贷方金额(互斥)
strDai = strDai + MsCwVouitemsGl.AMTCR;
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["CURRENCY"].ToString().Trim();//外币
strFCY = MsCwVouitemsGl.FCYNO;
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = Decimal.Parse(dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["je"].ToString().Trim());//外币贷方金额
MsCwVouitemsGl.ACCNAME = dsTMFCI.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsTMFCI.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
MsCwVouitemsGl.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
MsCwVouitemsGl.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
if (dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceTMFCI.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsTMFCI.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.FCYEXRATE = Decimal.Parse(dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
MsCwVouitemsGl.BLNO = "";//
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
#endregion
#endregion
#endregion
}
if (dsVWChFeeAR != null)
{
for (int i = 0; i < dsVWChFeeAR.Tables[0].Rows.Count; i++)
{
#region 摘要内容
strEXPLAN = "";
strEXPLAN = DREXPLAN;
var ISEXPLAN = false;
if (strEXPLAN != "") ISEXPLAN = true;
if (ISEXPLAN)
{
strEXPLAN = strEXPLAN.Replace("[发票抬头]", dsVWChFeeAR.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim());
strEXPLAN = strEXPLAN.Replace("[发票号]", dsVWChFeeAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim());
}
else {
strEXPLAN += "开票 " + dsVWChFeeAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();
}
#endregion
#region 应收账款
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;// 行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
#region 应收账款
if (dsVWChFeeAR.Tables[0].Rows[i]["OTCURRAMOUNT"].ToString().Trim() == "0")
{
iAMTDR = iAMTDR + Decimal.Parse(dsVWChFeeAR.Tables[0].Rows[i]["INVAMOUNT"].ToString().Trim());
//
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim();//应收账款科目贷码
MsCwVouitemsGl.AMTDR = Decimal.Parse(dsVWChFeeAR.Tables[0].Rows[i]["INVAMOUNT"].ToString().Trim());//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = "RMB";//外币编号usd
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
dRMBS += Decimal.Parse(dsVWChFeeAR.Tables[0].Rows[i]["INVAMOUNT"].ToString().Trim());//本位币借方金额(互斥)
MsCwVouitemsGl.ACCNAME = dsAR.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsAR.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
}
else
{
iAMTDR = iAMTDR + Decimal.Parse(dsVWChFeeAR.Tables[0].Rows[i]["INVAMOUNT"].ToString().Trim());
//
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim();//应收账款科目贷码
MsCwVouitemsGl.AMTDR = Decimal.Parse(dsVWChFeeAR.Tables[0].Rows[i]["INVAMOUNT"].ToString().Trim());//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.ISFCY = true;//是否外币
MsCwVouitemsGl.FCYNO = dsVWChFeeAR.Tables[0].Rows[i]["RECVCURR"].ToString();//外币编号usd
MsCwVouitemsGl.FCYDR = Decimal.Parse(dsVWChFeeAR.Tables[0].Rows[i]["OTCURRAMOUNT"].ToString().Trim());//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
dRMBS += Decimal.Parse(dsVWChFeeAR.Tables[0].Rows[i]["INVAMOUNT"].ToString().Trim());//本位币借方金额(互斥)
MsCwVouitemsGl.ACCNAME = dsARFC.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsARFC.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
}
//
string strACCALL = "";
//是否核算客户
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = "";//客户(系统)
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeAR.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要
MsCwVouitemsGl.FCYEXRATE = 1;//汇率
dEXCHANGERATE = 1;//汇率
MsCwVouitemsGl.BLNO = "";
//string strBLNONAME = dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
//if (strBLNONAME.Trim() != "")
//{
// MsCwVouitemsGl.BLNO = dsVWChFeeAR.Tables[0].Rows[i][strBLNONAME].ToString().Trim();
//}
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
if (dsVWChFeeAR.Tables[0].Rows[i]["OTCURRAMOUNT"].ToString().Trim() == "0")
{
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsAR.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
}
else
{
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsARFC.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
}
#endregion
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
Decimal dRMB = dRMBS - dRMBF;
Decimal dUSD = dUSDS - dUSDF;
//收入\成本 生成 全额\差额
strJie = dRMBS + dUSDS * dEXCHANGERATE;
strDai = dRMBF + dUSDF * dEXCHANGERATE;
for (int i = 0; i < dsVWChFeeAR.Tables[0].Rows.Count; i++)
{
#region 摘要内容
strEXPLAN = "";
strEXPLAN = MBINCOMEEXPLAN;
var ISEXPLAN = false;
if (strEXPLAN != "") ISEXPLAN = true;
if (ISEXPLAN)
{
strEXPLAN = strEXPLAN.Replace("[发票抬头]", dsVWChFeeAR.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim());
strEXPLAN = strEXPLAN.Replace("[发票号]", dsVWChFeeAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim());
}
else
{
strEXPLAN += "开票 " + dsVWChFeeAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim() + " 发票抬头:" + dsVWChFeeAR.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString();
}
#endregion
#region 收入
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;//行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim();//主营业务收入科目贷码
MsCwVouitemsGl.AMTDR = 0;//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVWChFeeAR.Tables[0].Rows[i]["INVAMOUNT"].ToString().Trim());//本位币贷方金额(互斥)
strDai = strDai + MsCwVouitemsGl.AMTCR;
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = "RMB";//外币
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
MsCwVouitemsGl.ACCNAME = dsMBINCOME.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsMBINCOME.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
MsCwVouitemsGl.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
MsCwVouitemsGl.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeAR.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsMBINCOME.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.FCYEXRATE = 1;//汇率
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
MsCwVouitemsGl.BLNO = "";//
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
if (CwVouitemsEntities.Count == 0)
{
//删除ch_fee_invoice中未生成的凭证号
//string blSQL = "update ch_fee_invoice set VOUNO='' where VOUNO='" + cfVOUALLNO + "'" + sAndGids.Trim();
//删除凭证生成关系表中的ch_fee_invoice的GID数据
string strLS = sAndGids.Replace("GID", "BSGID");
string blSQL = "delete from [cw_vouno_bs_gl] where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
return -3;//结算无明细数据
}
else {
#region 插入主表
MsCwVouchersGl MsCwVouchersGl = new MsCwVouchersGl();
MsCwVouchersGl.ORDNO = strORDNO.Trim();//唯一编码 newid() varchar (36)
MsCwVouchersGl.VOUDATE = headData.VOUDATE;//凭证日期
//strY + "~" + strM + "~" + sVOUNO + "~" + strVOUNO + "~" + strVOUDATE + "~" + strACCDATE;
//string sACCDATE = headData.VOUDATE.Substring(0, 7);
//if (DateTime.Parse(sACCDATE + "-01") < DateTime.Parse(strACCDATE + "-01"))
//{
// sACCDATE = strACCDATE;
//}
//string strVOUNOhj = DSWeb.MvcShipping.DAL.MsBaseInfoDAL.MsBaseInfoDAL.GetCwVOUNO(strBPVW.Trim(), sACCDATE);
//string[] items = strVOUNOhj.Trim().Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
//string sVOUNO = items[2].ToString().Trim();
//string strVOUNO = items[3].ToString().Trim();
MsCwVouchersGl.VOUNO = int.Parse(cfVOUALLNO.Substring(cfVOUALLNO.Length - 4)).ToString();//sVOUNO;//月初清零 varchar (16)
MsCwVouchersGl.ACCYEAR = DateTime.Parse(headData.VOUDATE.ToString()).Year.ToString();//年
MsCwVouchersGl.ACCMONTH = DateTime.Parse(headData.VOUDATE.ToString()).Month.ToString();//月
if (MsCwVouchersGl.ACCMONTH.ToString().Length == 1)
{
MsCwVouchersGl.ACCMONTH = "0" + MsCwVouchersGl.ACCMONTH.ToString();//月
}
MsCwVouchersGl.VKNO = strBPVW.Trim();//凭证字
//MsCwVouchersGl.VOUALLNO = MsCwVouchersGl.VKNO + MsCwVouchersGl.ACCYEAR + MsCwVouchersGl.ACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
MsCwVouchersGl.VOUALLNO = cfVOUALLNO.Replace("记", strBPVW.Trim());//年+月+自动生成编号=凭证号
MsCwVouchersGl.ATTACHS = 1;// int.Parse(dsCwDesign.Tables[0].Rows[0]["AFFIXNO"].ToString().Trim());//附件(单据)数
MsCwVouchersGl.AMTDR = strJie;// iAMTDR;//本位币借方
MsCwVouchersGl.AMTCR = strDai;//iAMTDR;// iAMTCR;//本位币贷方
MsCwVouchersGl.FCY = strFCY;//是否含有外币科目
MsCwVouchersGl.QTY = "";//是否含有数量科目
MsCwVouchersGl.VOUPROP = "";//凭证属性
MsCwVouchersGl.PREPARED = headData.PREPARED.ToString().Trim();//制单人
MsCwVouchersGl.CHECKED = "";//审核人
MsCwVouchersGl.ENTERED = "";//记账人
MsCwVouchersGl.ERRMSG = "";//错误信息
MsCwVouchersGl.ISDELETE = false;//是否废除
MsCwVouchersGl.DELETEUSER = "";//废除操作人
MsCwVouchersGl.STARTGID = strCwSTARTGID;
MsCwVouchersGl.DbOperationType = DbOperationType.DbotIns;
MsCwVouchersGl.CREATEUSER = strUserID;//创建人
MsCwVouchersGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouchersGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouchersGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
MsCwVouchersGl.ISAUTO = true;
#endregion
#region 生成入库
var modb = new ModelObjectDB();
result = modb.Save(MsCwVouchersGl);
if (result.Success == true)
{
2 years ago
//int n = 1;
2 years ago
BasicDataRefDAL.SetGLOrder(ref CwVouitemsEntities);
3 years ago
foreach (var enumValue in CwVouitemsEntities)
{
enumValue.GID = Guid.NewGuid().ToString();
2 years ago
//enumValue.ITEMNO = n;
3 years ago
enumValue.DbOperationType = DbOperationType.DbotIns;
var modb2 = new ModelObjectDB();
DBResult result2 = modb2.Save(enumValue);
2 years ago
//n++;
3 years ago
}
//更新凭证生成关系表中的ORDNO数据
string strLS = sAndGids.Replace("GID", "BSGID");
string blSQL = "update [cw_vouno_bs_gl] set ORDNO='" + MsCwVouchersGl.ORDNO + "' where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
blSQL = "update code_fill_serialno set ISDELETE=1,DELETEUSER='" + strUserID + "',DELETETIME=GETDATE() where TABLENAME='cw_vouchers_gl' and SERIALNO='" + cfVOUALLNO + "' and STARTGID='" + strCwSTARTGID + "'";
bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
if (VOUAUTOCHECK == "1")
{
string blSQL2 = "update cw_vouchers_gl set ISCHECKED=1,CHECKED='" + strUserID + "',CHECKEDTIME=getdate() where VOUALLNO='" + cfVOUALLNO + "' and [STARTGID]='" + strCwSTARTGID + "'";
bool bl2 = T_ALL_DA.GetExecuteSqlCommand(blSQL2);
}
}
else
{
//result.Success = false;
//result.Message = result.Message;
//return result;
//删除ch_fee_invoice中未生成的凭证号
//string blSQL = "update ch_fee_invoice set VOUNO='' where VOUNO='" + cfVOUALLNO + "'" + sAndGids.Trim();
//删除凭证生成关系表中的ch_fee_invoice的GID数据
string strLS = sAndGids.Replace("GID", "BSGID");
string blSQL = "delete from [cw_vouno_bs_gl] where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
return -2;//重复数据
}
#endregion
}
//result.Success = true;
//result.Message = result.Message;
//return result;
return 1;
}
protected static int getInvSC(DataSet dsCwDesign, DataSet dsCwDesignItem, string sAndGids, MsCwVouchersGl3 headData, List<MsCwVouchersGl4> bodyList, string strUserID, string strCompanyID, string cfVOUALLNO, string VOUAUTOCHECK)
{
var result = new DBResult();
#region 基本变量
//全部
string sSQL = "";
string strEXPLAN = "";
string strFCY = "RMB";
Decimal dEXCHANGERATE = 0;
//应收应付账款
Decimal iAMTDR = 0;
Decimal iAMTCR = 0;
//差额主营业务收入
Decimal dRMBS = 0;
Decimal dRMBF = 0;
Decimal dUSDS = 0;
Decimal dUSDF = 0;
//总合计
//Decimal strJie = 0;
//Decimal strDai = 0;
string strBPVW = dsCwDesign.Tables[0].Rows[0]["TVW"].ToString().Trim();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
#endregion
#region 科目设置
//科目设置 应收RMB
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim() + "'";
DataSet dsAR = T_ALL_DA.GetAllSQL(sSQL);
//科目设置 应收USD
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim() + "'";
DataSet dsARFC = T_ALL_DA.GetAllSQL(sSQL);
//主营业务收入 收入RMB
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() + "'";
DataSet dsMBINCOME = T_ALL_DA.GetAllSQL(sSQL);
//主营收入外币 收入USD
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim() + "'";
DataSet dsTMFCI = T_ALL_DA.GetAllSQL(sSQL);
//销项税
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["OUTPUTTAX"].ToString().Trim() + "'";
DataSet dsOUTPUTTAX = T_ALL_DA.GetAllSQL(sSQL);
#endregion
#region 摘要
string DREXPLAN = dsCwDesign.Tables[0].Rows[0]["INVDREXPLAN"].ToString().Trim();
string CREXPLAN = dsCwDesign.Tables[0].Rows[0]["INVCREXPLAN"].ToString().Trim();
string MBINCOMEEXPLAN = dsCwDesign.Tables[0].Rows[0]["INVMBINCOMEEXPLAN"].ToString().Trim();
string MBSPENDINGEXPLAN = dsCwDesign.Tables[0].Rows[0]["INVMBSPENDINGEXPLAN"].ToString().Trim();
string strISEXPLAN = "";
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strISEXPLAN += ",CUSTOMERNAME";//是否收付客户名称CUSTOMERNAME
}
//if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",INVOICENO";//是否委托编号CUSTNO//发票号
//}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strISEXPLAN += ",MBLNO";//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
strISEXPLAN += ",SALE";//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISINVEXPLANONRATE"].ToString().Trim() == "True")
{
strISEXPLAN += ",INVRATE,INVOICENO";//是否主提单号
}else
{
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strISEXPLAN += ",INVOICENO";//是否委托编号CUSTNO//发票号
}
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",VESSEL";//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",VOYNO";//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",BSSOURCE";//是否业务来源
//}
string strISEXPLANnull = "";
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strISEXPLANnull += ",CUSTOMERNAME";//是否收付客户名称CUSTOMERNAME
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strISEXPLANnull += ",INVOICENO";//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strISEXPLANnull += ",MBLNO";//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
strISEXPLANnull += ",SALE";//是否主提单号
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",VESSEL";//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",VOYNO";//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",BSSOURCE";//是否业务来源
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBILLNO"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",BILLNO_ACAD";//是否申请单号
//}
}
#endregion
#region 票号
if (strISEXPLAN.IndexOf(dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim()) < 0)
{
strISEXPLAN += "," + dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
if (strISEXPLANnull.IndexOf(dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim()) < 0)
{
strISEXPLANnull += "," + dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
}
}
#endregion
#region 核算科目_分录
//string sqlItemAR = "";
//string sqlItemARFC = "";
//string sqlItemMBINCOME = "";
//string sqlItemTMFCI = "";
#endregion
#region 基本数据集
string strORDNO = getGid();
string sqlAR = "";
string sqlARFC = "";
string sqlMBINCOME = "";
string sqlTMFCI = "";
string sqlOUTPUTTAX = "";
string sqlOUTPUTTAXUSD = "";
IList<MsCwVouitemsGl> CwVouitemsEntities = new List<MsCwVouitemsGl>();
string strCondition = sAndGids + " and GID in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='ch_fee_invoice' and VOUALLNO='" + cfVOUALLNO + "' and STARTGID='" + strCwSTARTGID + "')";
//是否按照系统录入汇率
if (headData.ISRATE == true)
{
#region 科目设置应收RMB dsAR、应收USD dsARFC
if (dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim())
{
#region 应收RMB==应收USD
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsAR.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlAR = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,MAX(GOODSNAME) AS GOODSNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " GROUP BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLAN + sISEXPLAN;//
sqlAR += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
//
sqlARFC = "SELECT EXCHANGERATE,CURRENCY,MAX(GOODSNAME) AS GOODSNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " GROUP BY EXCHANGERATE,CURRENCY" + strISEXPLAN + sISEXPLAN;//
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
}
else
{
sqlAR = "SELECT INVOICECUSTNAME,'RMB' CURRENCY,MAX(GOODSNAME) AS GOODSNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + "";
sqlAR += " GROUP BY INVOICECUSTNAME,VOUNO" + strISEXPLAN + sISEXPLAN;//
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
}
#endregion
}
else
{
#region 应收RMB!=应收USD
//应收RMB
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlAR = "SELECT INVOICECUSTNAME,MAX(GOODSNAME) AS GOODSNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " GROUP BY INVOICECUSTNAME,VOUNO" + strISEXPLAN + sISEXPLAN;//
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
//应收USD
#region 核算项目
sISEXPLAN = "";
//是否核算客户
if (dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlARFC = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,MAX(GOODSNAME) AS GOODSNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " GROUP BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLAN + sISEXPLAN;//
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
#endregion
}
#endregion
#region 科目设置主营业务收入RMB dsMBINCOME、主营收入外币USD dsTMFCI
if (dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim())
{
#region 主营业务收入RMB==主营收入外币USD
string sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
sISEXPLAN += ",INVOICECUSTNAME";//是否核算项目
}
#endregion
//ISFCY 是否核算外币
if (dsMBINCOME.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlMBINCOME = "SELECT EXCHANGERATE,CURRENCY,(SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlMBINCOME += " group BY EXCHANGERATE,CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
//
sqlTMFCI = "SELECT EXCHANGERATE,CURRENCY,(SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlTMFCI += " group BY EXCHANGERATE,CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
}
else
{
sqlMBINCOME = "SELECT (SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + "";
sqlMBINCOME += " group BY VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
}
#endregion
}
else
{
#region 主营业务收入RMB!=主营收入外币USD
//主营业务收入RMB
string sISEXPLAN = "";
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
#region 核算项目
//是否核算客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
}
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlMBINCOME = "SELECT INVOICECUSTNAME,(SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlMBINCOME += " group BY INVOICECUSTNAME,VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
//主营收入外币USD
sISEXPLAN = "";
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
#region 核算项目
//是否核算客户
if (dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
}
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlTMFCI = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,(SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlTMFCI += " group BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
#endregion
}
#endregion
#region 科目设置:销项税 dsOUTPUTTAX
#region 核算项目
string ssISEXPLAN = "";
//是否核算客户
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
ssISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
ssISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
ssISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
ssISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
ssISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlOUTPUTTAX = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,SUM(TAX) AS je,SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE))) AS hj " + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " From v_ch_fee_invoice_pz WHERE 1=1 and TAX<>0" + strCondition + " and CURRENCY='RMB'";
sqlOUTPUTTAX += " group BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " ORDER BY CURRENCY" + strISEXPLANnull + ssISEXPLAN;
//
sqlOUTPUTTAXUSD = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,SUM(TAX) AS je,SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE))) AS hj " + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAXUSD += " From v_ch_fee_invoice_pz WHERE 1=1 and TAX<>0" + strCondition + " and CURRENCY<>'RMB'";
sqlOUTPUTTAXUSD += " group BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAXUSD += " ORDER BY CURRENCY" + strISEXPLANnull + ssISEXPLAN;
}
else
{
sqlOUTPUTTAX = "SELECT INVOICECUSTNAME,SUM(TAX) AS je,SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE))) AS hj " + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " From v_ch_fee_invoice_pz WHERE 1=1 and TAX<>0" + strCondition;
sqlOUTPUTTAX += " group BY INVOICECUSTNAME,VOUNO" + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " ORDER BY VOUNO" + strISEXPLANnull + ssISEXPLAN;
}
#endregion
}
else
{
#region 提取费率
string tbRATE = "";
if (bodyList != null)
{
if (bodyList.Count > 0)
{
for (int i = 0; i < bodyList.Count; i++)
{
tbRATE += " WHEN CURRENCY='" + bodyList[i].CURR.ToString().Trim() + "' THEN " + bodyList[i].FCYEXRATE.ToString().Trim();
}
}
}
#endregion
#region 科目设置应收RMB dsAR、应收USD dsARFC
if (dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim())
{
#region 应收RMB==应收USD
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsAR.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlAR = "SELECT INVOICECUSTNAME,EXCHANGERATE,CURRENCY,MAX(GOODSNAME) AS GOODSNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " group BY INVOICECUSTNAME,EXCHANGERATE,CURRENCY" + strISEXPLAN + sISEXPLAN;
sqlAR += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
//
sqlARFC = "SELECT INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,MAX(GOODSNAME) AS GOODSNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " group BY INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END),CURRENCY" + strISEXPLAN + sISEXPLAN;
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
}
else
{
sqlAR = "SELECT INVOICECUSTNAME,MAX(GOODSNAME) AS GOODSNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + "";
sqlAR += " group BY INVOICECUSTNAME,VOUNO" + strISEXPLAN + sISEXPLAN;
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
}
#endregion
}
else
{
#region 应收RMB!=应收USD
//应收RMB
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlAR = "SELECT INVOICECUSTNAME,MAX(GOODSNAME) AS GOODSNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " group BY INVOICECUSTNAME,VOUNO" + strISEXPLAN + sISEXPLAN;
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
//应收USD
#region 核算项目
sISEXPLAN = "";
//是否核算客户
if (dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLAN.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlARFC = "SELECT INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,MAX(GOODSNAME) AS GOODSNAME,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " group BY INVOICECUSTNAME,(CASE" + tbRATE + " ELSE EXCHANGERATE END),CURRENCY" + strISEXPLAN + sISEXPLAN;
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
#endregion
}
#endregion
#region 科目设置主营业务收入RMB dsMBINCOME、主营收入外币USD dsTMFCI
if (dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim())
{
#region 主营业务收入RMB==主营收入外币USD
string sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
sISEXPLAN += ",INVOICECUSTNAME";//是否核算项目
}
#endregion
//ISFCY 是否核算外币
sqlMBINCOME = "SELECT SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + "";
sqlMBINCOME += " group BY VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
#endregion
}
else
{
#region 主营业务收入RMB!=主营收入外币USD
//主营业务收入RMB
string sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
sISEXPLAN += ",INVOICECUSTNAME";//是否核算项目
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlMBINCOME = "SELECT SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlMBINCOME += " group BY VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
//主营收入外币USD
sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
if (dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
if (strISEXPLANnull.IndexOf("SALE") < 0)
{
sISEXPLAN += ",SALE";//是否揽货人
}
}
//是否核算部门
if (dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
sISEXPLAN += ",INVOICECUSTNAME";//是否核算项目
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlTMFCI = "SELECT (CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " From v_ch_fee_invoice_pz WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlTMFCI += " group BY (CASE" + tbRATE + " ELSE EXCHANGERATE END),CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
#endregion
}
#endregion
#region 科目设置:销项税 dsOUTPUTTAX
#region 核算项目
string ssISEXPLAN = "";
//是否核算客户
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
ssISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
ssISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
ssISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
ssISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
ssISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
sqlOUTPUTTAX = "SELECT INVOICECUSTNAME,SUM(TAX) AS je,SUM(Convert(decimal(18,2),(TAX*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " From v_ch_fee_invoice_pz WHERE 1=1 and TAX<>0" + strCondition + "";
sqlOUTPUTTAX += " group BY INVOICECUSTNAME,VOUNO" + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " ORDER BY VOUNO" + strISEXPLANnull + ssISEXPLAN;
#endregion
}
DataSet dsVWChFeeInvoiceAR = T_ALL_DA.GetAllSQL(sqlAR);
DataSet dsVWChFeeInvoiceARFC = null;
if (sqlARFC.Trim() != "")
{
dsVWChFeeInvoiceARFC = T_ALL_DA.GetAllSQL(sqlARFC);
}
DataSet dsVWChFeeInvoiceMBINCOME = T_ALL_DA.GetAllSQL(sqlMBINCOME);
DataSet dsVWChFeeInvoiceTMFCI = null;
if (sqlTMFCI.Trim() != "")
{
dsVWChFeeInvoiceTMFCI = T_ALL_DA.GetAllSQL(sqlTMFCI);
}
DataSet dsVWChFeeInvoiceOUTPUTTAX = T_ALL_DA.GetAllSQL(sqlOUTPUTTAX);
DataSet dsVWChFeeInvoiceOUTPUTTAXUSD = null;
if (sqlOUTPUTTAXUSD.Trim() != "")
{
dsVWChFeeInvoiceOUTPUTTAXUSD = T_ALL_DA.GetAllSQL(sqlOUTPUTTAXUSD);
}
#endregion
if (dsVWChFeeInvoiceAR != null || dsVWChFeeInvoiceARFC != null)
{
#region 明细表_实体类
#region 插入明细表应收RMB dsAR
if (dsVWChFeeInvoiceAR != null)
{
for (int i = 0; i < dsVWChFeeInvoiceAR.Tables[0].Rows.Count; i++)
{
#region 摘要内容
strEXPLAN = "";
strEXPLAN = DREXPLAN;
var ISEXPLAN = false;
if (strEXPLAN != "") ISEXPLAN = true;
if (ISEXPLAN)
{
strEXPLAN = strEXPLAN.Replace("[发票抬头]", dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim());
strEXPLAN = strEXPLAN.Replace("[发票号]", dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim());
}
else
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["SALE"].ToString().Trim();//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISINVEXPLANONRATE"].ToString().Trim() == "True")
{
if (dsVWChFeeInvoiceAR.Tables[0].Rows[i]["GOODSNAME"].ToString().Trim() == "仓储费")
{
strEXPLAN += " 应收仓储费(" + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim() + ")";
}
else
{
if (Convert.ToDecimal(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVRATE"].ToString()) == 0)
{
if (dsVWChFeeInvoiceAR.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() == "RMB")
{
strEXPLAN += " 应收代理运杂费(" + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim() + ")";
}
else if (dsVWChFeeInvoiceAR.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() == "USD")
{
strEXPLAN += " 应收代理海运费(" + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim() + ")";
}
}
else if (Convert.ToDecimal(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVRATE"].ToString()) == 6)
{
strEXPLAN += " 应收代理杂费(" + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim() + ")";
}
else if (Convert.ToDecimal(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVRATE"].ToString()) == 10)
{
strEXPLAN += " 应收陆运费(" + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim() + ")";
}
}
}
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否收付船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
#endregion
#region 插入明细表 应收账款
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;// 行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
#region 应收账款
iAMTDR = iAMTDR + Decimal.Parse(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["hj"].ToString().Trim());
//
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim();//应收账款科目贷码
MsCwVouitemsGl.AMTDR = Decimal.Parse(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = "RMB";//外币编号usd
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
dRMBS += Decimal.Parse(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
//
MsCwVouitemsGl.ACCNAME = dsAR.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsAR.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
//是否核算客户
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = "";//客户(系统)
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceAR.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsAR.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要
MsCwVouitemsGl.FCYEXRATE = 1;//汇率
dEXCHANGERATE = 1;//汇率
MsCwVouitemsGl.BLNO = "";
string strBLNONAME = dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
if (strBLNONAME.Trim() != "")
{
MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceAR.Tables[0].Rows[i][strBLNONAME].ToString().Trim();
}
//if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
//{
// MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["MBLNO"].ToString().Trim();
//}
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
#endregion
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
#endregion
#region 插入明细表:应收外币 dsARFC
if (dsVWChFeeInvoiceARFC != null)
{
for (int i = 0; i < dsVWChFeeInvoiceARFC.Tables[0].Rows.Count; i++)
{
#region 摘要内容
strEXPLAN = "";
strEXPLAN = DREXPLAN;
var ISEXPLAN = false;
if (strEXPLAN != "") ISEXPLAN = true;
if (ISEXPLAN)
{
strEXPLAN = strEXPLAN.Replace("[发票抬头]", dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim());
strEXPLAN = strEXPLAN.Replace("[发票号]", dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICENO"].ToString().Trim());
}
else
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["SALE"].ToString().Trim();//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISINVEXPLANONRATE"].ToString().Trim() == "True")
{
if (dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["GOODSNAME"].ToString().Trim() == "仓储费")
{
strEXPLAN += " 应收仓储费(" + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICENO"].ToString().Trim() + ")";
}
else
{
if (Convert.ToDecimal(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVRATE"].ToString()) == 0)
{
if (dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() == "RMB")
{
strEXPLAN += " 应收代理运杂费(" + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICENO"].ToString().Trim() + ")";
}
else if (dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() == "USD")
{
strEXPLAN += " 应收代理海运费(" + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICENO"].ToString().Trim() + ")";
}
}
else if (Convert.ToDecimal(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVRATE"].ToString()) == 6)
{
strEXPLAN += " 应收代理杂费(" + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICENO"].ToString().Trim() + ")";
}
else if (Convert.ToDecimal(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVRATE"].ToString()) == 10)
{
strEXPLAN += " 应收陆运费(" + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICENO"].ToString().Trim() + ")";
}
}
}
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否收付船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否收付航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
#endregion
#region 插入明细表 应收账款
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;// 行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
#region 应收账款
iAMTDR = iAMTDR + Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["hj"].ToString().Trim());
//
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim();//应收账款科目贷码
MsCwVouitemsGl.AMTDR = Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CURRENCY"].ToString().Trim();//外币
strFCY = MsCwVouitemsGl.FCYNO;
MsCwVouitemsGl.FCYDR = Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["je"].ToString().Trim());//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
dRMBS += Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
//
MsCwVouitemsGl.ACCNAME = dsARFC.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsARFC.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
//是否核算客户
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = "";//客户(系统)
if (dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceARFC.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsARFC.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要
MsCwVouitemsGl.FCYEXRATE = Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
dEXCHANGERATE = MsCwVouitemsGl.FCYEXRATE;//汇率
MsCwVouitemsGl.BLNO = "";
string strBLNONAME = dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
if (strBLNONAME.Trim() != "")
{
MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceARFC.Tables[0].Rows[i][strBLNONAME].ToString().Trim();
}
//if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
//{
// MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["MBLNO"].ToString().Trim();
//}
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
#endregion
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
#endregion
#region 插入明细表:主营业务收入
Decimal dRMB = dRMBS - dRMBF;
Decimal dUSD = dUSDS - dUSDF;
//收入\成本 生成 全额\差额
Decimal strJie = dRMBS + dUSDS * dEXCHANGERATE;
Decimal strDai = dRMBF + dUSDF * dEXCHANGERATE;
//
#region 全额
if (dsVWChFeeInvoiceMBINCOME != null)
{
for (int i = 0; i < dsVWChFeeInvoiceMBINCOME.Tables[0].Rows.Count; i++)
{
#region 摘要内容
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
strEXPLAN = "";
strEXPLAN = MBINCOMEEXPLAN;
var ISEXPLAN = false;
if (strEXPLAN != "") ISEXPLAN = true;
if (ISEXPLAN)
{
strEXPLAN = strEXPLAN.Replace("[发票抬头]", dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim());
strEXPLAN = strEXPLAN.Replace("[发票号]", dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["INVOICENO"].ToString().Trim());
}
else
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["SALE"].ToString().Trim();//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
}
//else
//{
// strEXPLAN = dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim();
//}
#endregion
#region 收入
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;//行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim();//主营业务收入科目贷码
MsCwVouitemsGl.AMTDR = 0;//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币贷方金额(互斥)
strDai = strDai + MsCwVouitemsGl.AMTCR;
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = "RMB";//外币
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
MsCwVouitemsGl.ACCNAME = dsMBINCOME.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsMBINCOME.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
MsCwVouitemsGl.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
MsCwVouitemsGl.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsMBINCOME.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.FCYEXRATE = 1;//汇率
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
MsCwVouitemsGl.BLNO = "";//
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
if (dsVWChFeeInvoiceTMFCI != null)
{
for (int i = 0; i < dsVWChFeeInvoiceTMFCI.Tables[0].Rows.Count; i++)
{
#region 摘要内容
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
strEXPLAN = "";
strEXPLAN = MBINCOMEEXPLAN;
var ISEXPLAN = false;
if (strEXPLAN != "") ISEXPLAN = true;
if (ISEXPLAN)
{
strEXPLAN = strEXPLAN.Replace("[发票抬头]", dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim());
strEXPLAN = strEXPLAN.Replace("[发票号]", dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["INVOICENO"].ToString().Trim());
}
else
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
if (dsCwDesign.Tables[0].Rows[0]["ISSALE"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["SALE"].ToString().Trim();//是否主提单号
}
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
}
//else
//{
// strEXPLAN = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim();
//}
#endregion
#region 收入_外币
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;//行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim();//主营业务收入科目贷码
MsCwVouitemsGl.AMTDR = 0;//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币贷方金额(互斥)
strDai = strDai + MsCwVouitemsGl.AMTCR;
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["CURRENCY"].ToString().Trim();//外币
strFCY = MsCwVouitemsGl.FCYNO;
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = Decimal.Parse(dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["je"].ToString().Trim());//外币贷方金额
MsCwVouitemsGl.ACCNAME = dsTMFCI.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsTMFCI.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
MsCwVouitemsGl.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
MsCwVouitemsGl.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
if (dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceTMFCI.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsTMFCI.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.FCYEXRATE = Decimal.Parse(dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
MsCwVouitemsGl.BLNO = "";//
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
#endregion
#endregion
#region 插入明细表:销项税
if (dsVWChFeeInvoiceOUTPUTTAX != null)
{
for (int i = 0; i < dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows.Count; i++)
{
#region 摘要内容
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
strEXPLAN = "";
strEXPLAN = MBINCOMEEXPLAN;
var ISEXPLAN = false;
if (strEXPLAN != "") ISEXPLAN = true;
if (ISEXPLAN)
{
strEXPLAN = strEXPLAN.Replace("[发票抬头]", dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["INVOICECUSTNAME"].ToString().Trim());
strEXPLAN = strEXPLAN.Replace("[发票号]", dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["INVOICENO"].ToString().Trim());
}
else
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
}
#endregion
#region 收入
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;//行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["OUTPUTTAX"].ToString().Trim();//主营业务收入科目贷码
MsCwVouitemsGl.AMTDR = 0;//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币贷方金额(互斥)
strDai = strDai + MsCwVouitemsGl.AMTCR;
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = "RMB";//外币
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
MsCwVouitemsGl.ACCNAME = dsOUTPUTTAX.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsOUTPUTTAX.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
MsCwVouitemsGl.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
MsCwVouitemsGl.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsOUTPUTTAX.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.FCYEXRATE = 1;//汇率
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
MsCwVouitemsGl.BLNO = "";//
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
#endregion
#endregion
#region 插入主表
MsCwVouchersGl MsCwVouchersGl = new MsCwVouchersGl();
MsCwVouchersGl.ORDNO = strORDNO.Trim();//唯一编码 newid() varchar (36)
MsCwVouchersGl.VOUDATE = headData.VOUDATE;//凭证日期
MsCwVouchersGl.ISAUTO = true;
//strY + "~" + strM + "~" + sVOUNO + "~" + strVOUNO + "~" + strVOUDATE + "~" + strACCDATE;
//string sACCDATE = headData.VOUDATE.Substring(0, 7);
//if (DateTime.Parse(sACCDATE + "-01") < DateTime.Parse(strACCDATE + "-01"))
//{
// sACCDATE = strACCDATE;
//}
//string strVOUNOhj = DSWeb.MvcShipping.DAL.MsBaseInfoDAL.MsBaseInfoDAL.GetCwVOUNO(strBPVW.Trim(), sACCDATE);
//string[] items = strVOUNOhj.Trim().Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
//string sVOUNO = items[2].ToString().Trim();
//string strVOUNO = items[3].ToString().Trim();
MsCwVouchersGl.VOUNO = int.Parse(cfVOUALLNO.Substring(cfVOUALLNO.Length - 4)).ToString();//sVOUNO;//月初清零 varchar (16)
MsCwVouchersGl.ACCYEAR = DateTime.Parse(headData.VOUDATE.ToString()).Year.ToString();//年
MsCwVouchersGl.ACCMONTH = DateTime.Parse(headData.VOUDATE.ToString()).Month.ToString();//月
if (MsCwVouchersGl.ACCMONTH.ToString().Length == 1)
{
MsCwVouchersGl.ACCMONTH = "0" + MsCwVouchersGl.ACCMONTH.ToString();//月
}
MsCwVouchersGl.VKNO = strBPVW.Trim();//凭证字
//MsCwVouchersGl.VOUALLNO = MsCwVouchersGl.VKNO + MsCwVouchersGl.ACCYEAR + MsCwVouchersGl.ACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
MsCwVouchersGl.VOUALLNO = cfVOUALLNO.Replace("记", strBPVW.Trim());//年+月+自动生成编号=凭证号
MsCwVouchersGl.ATTACHS = 1;// int.Parse(dsCwDesign.Tables[0].Rows[0]["AFFIXNO"].ToString().Trim());//附件(单据)数
MsCwVouchersGl.AMTDR = strJie;// iAMTDR;//本位币借方
MsCwVouchersGl.AMTCR = strDai;//iAMTDR;// iAMTCR;//本位币贷方
MsCwVouchersGl.FCY = strFCY;//是否含有外币科目
MsCwVouchersGl.QTY = "";//是否含有数量科目
MsCwVouchersGl.VOUPROP = "";//凭证属性
MsCwVouchersGl.PREPARED = headData.PREPARED.ToString().Trim();//制单人
MsCwVouchersGl.CHECKED = "";//审核人
MsCwVouchersGl.ENTERED = "";//记账人
MsCwVouchersGl.ERRMSG = "";//错误信息
MsCwVouchersGl.ISDELETE = false;//是否废除
MsCwVouchersGl.DELETEUSER = "";//废除操作人
MsCwVouchersGl.STARTGID = strCwSTARTGID;
MsCwVouchersGl.DbOperationType = DbOperationType.DbotIns;
MsCwVouchersGl.CREATEUSER = strUserID;//创建人
MsCwVouchersGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouchersGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouchersGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
#region 生成入库
var modb = new ModelObjectDB();
result = modb.Save(MsCwVouchersGl);
var strexplan = "";
if (result.Success == true)
{
2 years ago
//int n = 1;
2 years ago
BasicDataRefDAL.SetGLOrder(ref CwVouitemsEntities);
3 years ago
foreach (var enumValue in CwVouitemsEntities)
{
if (!string.IsNullOrEmpty(enumValue.EXPLAN)) strexplan = enumValue.EXPLAN;
else {
if (!string.IsNullOrEmpty(strexplan)) enumValue.EXPLAN = strexplan;
else enumValue.EXPLAN = "发票";
}
enumValue.GID = Guid.NewGuid().ToString();
2 years ago
//enumValue.ITEMNO = n;
3 years ago
enumValue.DbOperationType = DbOperationType.DbotIns;
var modb2 = new ModelObjectDB();
DBResult result2 = modb2.Save(enumValue);
2 years ago
//n++;
3 years ago
}
//更新凭证生成关系表中的ORDNO数据
string strLS = sAndGids.Replace("GID", "BSGID");
string blSQL = "update [cw_vouno_bs_gl] set ORDNO='" + MsCwVouchersGl.ORDNO + "' where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
blSQL = "update code_fill_serialno set ISDELETE=1,DELETEUSER='" + strUserID + "',DELETETIME=GETDATE() where TABLENAME='cw_vouchers_gl' and SERIALNO='" + cfVOUALLNO + "' and STARTGID='" + strCwSTARTGID + "'";
bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
if (VOUAUTOCHECK == "1")
{
string blSQL2 = "update cw_vouchers_gl set ISCHECKED=1,CHECKED='" + strUserID + "',CHECKEDTIME=getdate() where VOUALLNO='" + cfVOUALLNO + "' and [STARTGID]='" + strCwSTARTGID + "'";
bool bl2 = T_ALL_DA.GetExecuteSqlCommand(blSQL2);
}
}
else
{
//result.Success = false;
//result.Message = result.Message;
//return result;
//删除ch_fee_invoice中未生成的凭证号
//string blSQL = "update ch_fee_invoice set VOUNO='' where VOUNO='" + cfVOUALLNO + "'" + sAndGids.Trim();
//删除凭证生成关系表中的ch_fee_invoice的GID数据
string strLS = sAndGids.Replace("GID", "BSGID");
string blSQL = "delete from [cw_vouno_bs_gl] where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
return -2;//重复数据
}
#endregion
}
else
{
//删除ch_fee_invoice中未生成的凭证号
//string blSQL = "update ch_fee_invoice set VOUNO='' where VOUNO='" + cfVOUALLNO + "'" + sAndGids.Trim();
//删除凭证生成关系表中的ch_fee_invoice的GID数据
string strLS = sAndGids.Replace("GID", "BSGID");
string blSQL = "delete from [cw_vouno_bs_gl] where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
return -3;//结算无明细数据
}
//result.Success = true;
//result.Message = result.Message;
//return result;
return 1;
}
protected static int getSC(DataSet dsCwDesign, DataSet dsCwDesignItem, string sAndGids, MsCwVouchersGl3 headData, List<MsCwVouchersGl4> bodyList, string strUserID, string strCompanyID, string cfVOUALLNO)
{
var result = new DBResult();
#region 基本变量
//全部
string sSQL = "";
string strEXPLAN = "";
string strFCY = "RMB";
Decimal dEXCHANGERATE = 0;
//应收应付账款
Decimal iAMTDR = 0;
Decimal iAMTCR = 0;
//差额主营业务收入
Decimal dRMBS = 0;
Decimal dRMBF = 0;
Decimal dUSDS = 0;
Decimal dUSDF = 0;
//总合计
//Decimal strJie = 0;
//Decimal strDai = 0;
string strBPVW = dsCwDesign.Tables[0].Rows[0]["TVW"].ToString().Trim();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
#endregion
#region 科目设置
//科目设置 应收RMB
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim() + "'";
DataSet dsAR = T_ALL_DA.GetAllSQL(sSQL);
//科目设置 应收USD
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim() + "'";
DataSet dsARFC = T_ALL_DA.GetAllSQL(sSQL);
//主营业务收入 收入RMB
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() + "'";
DataSet dsMBINCOME = T_ALL_DA.GetAllSQL(sSQL);
//主营收入外币 收入USD
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim() + "'";
DataSet dsTMFCI = T_ALL_DA.GetAllSQL(sSQL);
//销项税
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign.Tables[0].Rows[0]["OUTPUTTAX"].ToString().Trim() + "'";
DataSet dsOUTPUTTAX = T_ALL_DA.GetAllSQL(sSQL);
#endregion
#region 摘要
string strISEXPLAN = "";
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strISEXPLAN += ",CUSTOMERNAME";//是否收付客户名称CUSTOMERNAME
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strISEXPLAN += ",INVOICENO";//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strISEXPLAN += ",MBLNO";//是否主提单号
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",VESSEL";//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",VOYNO";//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",BSSOURCE";//是否业务来源
//}
string strISEXPLANnull = "";
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strISEXPLANnull += ",CUSTOMERNAME";//是否收付客户名称CUSTOMERNAME
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strISEXPLANnull += ",INVOICENO";//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strISEXPLANnull += ",MBLNO";//是否主提单号
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",VESSEL";//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",VOYNO";//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",BSSOURCE";//是否业务来源
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBILLNO"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",BILLNO_ACAD";//是否申请单号
//}
}
#endregion
#region 票号
if (strISEXPLAN.IndexOf(dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim()) < 0)
{
strISEXPLAN += "," + dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
if (strISEXPLANnull.IndexOf(dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim()) < 0)
{
strISEXPLANnull += "," + dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
}
}
#endregion
#region 核算科目_分录
//string sqlItemAR = "";
//string sqlItemARFC = "";
//string sqlItemMBINCOME = "";
//string sqlItemTMFCI = "";
#endregion
#region 基本数据集
string strORDNO = getGid();
string sqlAR = "";
string sqlARFC = "";
string sqlMBINCOME = "";
string sqlTMFCI = "";
string sqlOUTPUTTAX = "";
string sqlOUTPUTTAXUSD = "";
IList<MsCwVouitemsGl> CwVouitemsEntities = new List<MsCwVouitemsGl>();
string strCondition = sAndGids + " and GID in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='ch_fee_invoice' and VOUALLNO='" + cfVOUALLNO + "' and STARTGID='" + strCwSTARTGID + "')";
//是否按照系统录入汇率
if (headData.ISRATE == true)
{
#region 科目设置应收RMB dsAR、应收USD dsARFC
if (dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim())
{
#region 应收RMB==应收USD
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsAR.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlAR = "SELECT EXCHANGERATE,CURRENCY,AMOUNT AS je,Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
//
sqlARFC = "SELECT EXCHANGERATE,CURRENCY,AMOUNT AS je,Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
}
else
{
sqlAR = "SELECT AMOUNT AS je,Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + "";
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
}
#endregion
}
else
{
#region 应收RMB!=应收USD
//应收RMB
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlAR = "SELECT AMOUNT AS je,Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
//应收USD
#region 核算项目
sISEXPLAN = "";
//是否核算客户
if (dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlARFC = "SELECT EXCHANGERATE,CURRENCY,AMOUNT AS je,Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
#endregion
}
#endregion
#region 科目设置主营业务收入RMB dsMBINCOME、主营收入外币USD dsTMFCI
if (dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim())
{
#region 主营业务收入RMB==主营收入外币USD
string sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsMBINCOME.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlMBINCOME = "SELECT EXCHANGERATE,CURRENCY,(SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlMBINCOME += " group BY EXCHANGERATE,CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
//
sqlTMFCI = "SELECT EXCHANGERATE,CURRENCY,(SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlTMFCI += " group BY EXCHANGERATE,CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
}
else
{
sqlMBINCOME = "SELECT (SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + "";
sqlMBINCOME += " group BY VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
}
#endregion
}
else
{
#region 主营业务收入RMB!=主营收入外币USD
//主营业务收入RMB
string sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlMBINCOME = "SELECT (SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlMBINCOME += " group BY VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
//主营收入外币USD
sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlTMFCI = "SELECT EXCHANGERATE,CURRENCY,(SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlTMFCI += " group BY EXCHANGERATE,CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
#endregion
}
#endregion
#region 科目设置:销项税 dsOUTPUTTAX
#region 核算项目
string ssISEXPLAN = "";
//是否核算客户
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
ssISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
ssISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
ssISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
ssISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
ssISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlOUTPUTTAX = "SELECT EXCHANGERATE,CURRENCY,SUM(TAX) AS je,SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE))) AS hj " + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " From VW_ch_fee_invoice WHERE 1=1 and TAX<>0" + strCondition + " and CURRENCY='RMB'";
sqlOUTPUTTAX += " group BY EXCHANGERATE,CURRENCY" + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " ORDER BY CURRENCY" + strISEXPLANnull + ssISEXPLAN;
//
sqlOUTPUTTAXUSD = "SELECT EXCHANGERATE,CURRENCY,SUM(TAX) AS je,SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE))) AS hj " + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAXUSD += " From VW_ch_fee_invoice WHERE 1=1 and TAX<>0" + strCondition + " and CURRENCY<>'RMB'";
sqlOUTPUTTAXUSD += " group BY EXCHANGERATE,CURRENCY" + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAXUSD += " ORDER BY CURRENCY" + strISEXPLANnull + ssISEXPLAN;
}
else
{
sqlOUTPUTTAX = "SELECT SUM(TAX) AS je,SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE))) AS hj " + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " From VW_ch_fee_invoice WHERE 1=1 and TAX<>0" + strCondition;
sqlOUTPUTTAX += " group BY VOUNO" + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " ORDER BY VOUNO" + strISEXPLANnull + ssISEXPLAN;
}
#endregion
}
else
{
#region 提取费率
string tbRATE = "";
if (bodyList != null)
{
if (bodyList.Count > 0)
{
for (int i = 0; i < bodyList.Count; i++)
{
tbRATE += " WHEN CURRENCY='" + bodyList[i].CURR.ToString().Trim() + "' THEN " + bodyList[i].FCYEXRATE.ToString().Trim();
}
}
}
#endregion
#region 科目设置应收RMB dsAR、应收USD dsARFC
if (dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim())
{
#region 应收RMB==应收USD
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsAR.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlAR = "SELECT EXCHANGERATE,CURRENCY,AMOUNT AS je,Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
//
sqlARFC = "SELECT (CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,AMOUNT AS je,Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
}
else
{
sqlAR = "SELECT AMOUNT AS je,Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + "";
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
}
#endregion
}
else
{
#region 应收RMB!=应收USD
//应收RMB
#region 核算项目
string sISEXPLAN = "";
//是否核算客户
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlAR = "SELECT AMOUNT AS je,Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)) AS hj " + strISEXPLAN + sISEXPLAN;
sqlAR += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlAR += " ORDER BY VOUNO" + strISEXPLAN + sISEXPLAN;
//应收USD
#region 核算项目
sISEXPLAN = "";
//是否核算客户
if (dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLAN.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlARFC = "SELECT (CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,AMOUNT AS je,Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END))) AS hj " + strISEXPLAN + sISEXPLAN;
sqlARFC += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlARFC += " ORDER BY CURRENCY" + strISEXPLAN + sISEXPLAN;
#endregion
}
#endregion
#region 科目设置主营业务收入RMB dsMBINCOME、主营收入外币USD dsTMFCI
if (dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() == dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim())
{
#region 主营业务收入RMB==主营收入外币USD
string sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsMBINCOME.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlMBINCOME = "SELECT EXCHANGERATE,CURRENCY,(SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlMBINCOME += " group BY EXCHANGERATE,CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
//
sqlTMFCI = "SELECT (CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,(SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END))))-SUM(Convert(decimal(18,2),(TAX*(CASE" + tbRATE + " ELSE EXCHANGERATE END))))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlTMFCI += " group BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
}
else
{
sqlMBINCOME = "SELECT (SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END))))-SUM(Convert(decimal(18,2),(TAX*(CASE" + tbRATE + " ELSE EXCHANGERATE END))))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + "";
sqlMBINCOME += " group BY VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
}
#endregion
}
else
{
#region 主营业务收入RMB!=主营收入外币USD
//主营业务收入RMB
string sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlMBINCOME = "SELECT (SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*EXCHANGERATE)))-SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE)))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY='RMB'";
sqlMBINCOME += " group BY VOUNO" + strISEXPLANnull + sISEXPLAN;
sqlMBINCOME += " ORDER BY VOUNO" + strISEXPLANnull + sISEXPLAN;
//主营收入外币USD
sISEXPLAN = "";
#region 核算项目
//是否核算客户
if (dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币,因 应收RMB!=应收USD所以此处不需核算外币
sqlTMFCI = "SELECT (CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,(SUM(AMOUNT)-SUM(TAX)) AS je,(SUM(Convert(decimal(18,2),(AMOUNT*(CASE" + tbRATE + " ELSE EXCHANGERATE END))))-SUM(Convert(decimal(18,2),(TAX*(CASE" + tbRATE + " ELSE EXCHANGERATE END))))) AS hj " + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " From VW_ch_fee_invoice WHERE 1=1" + strCondition + " and CURRENCY<>'RMB'";
sqlTMFCI += " group BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
sqlTMFCI += " ORDER BY CURRENCY" + strISEXPLANnull + sISEXPLAN;
#endregion
}
#endregion
#region 科目设置:销项税 dsOUTPUTTAX
#region 核算项目
string ssISEXPLAN = "";
//是否核算客户
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() != "True")
{
ssISEXPLAN += ",CUSTOMERNAME";//是否发票单位
}
else
{
if (strISEXPLANnull.IndexOf("CUSTOMERNAME") < 0)
{
ssISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
}
}
//是否核算人员
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
ssISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
ssISEXPLAN += ",DEPTGID";//是否揽货人的部门
}
//是否核算项目
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
ssISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsOUTPUTTAX.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlOUTPUTTAX = "SELECT EXCHANGERATE,CURRENCY,SUM(TAX) AS je,SUM(Convert(decimal(18,2),(TAX*EXCHANGERATE))) AS hj " + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " From VW_ch_fee_invoice WHERE 1=1 and TAX<>0" + strCondition + " and CURRENCY='RMB'";
sqlOUTPUTTAX += " group BY EXCHANGERATE,CURRENCY" + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " ORDER BY CURRENCY" + strISEXPLANnull + ssISEXPLAN;
//
sqlOUTPUTTAXUSD = "SELECT (CASE" + tbRATE + " ELSE EXCHANGERATE END) as EXCHANGERATE,CURRENCY,SUM(TAX) AS je,SUM(Convert(decimal(18,2),(TAX*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAXUSD += " From VW_ch_fee_invoice WHERE 1=1 and TAX<>0" + strCondition + " and CURRENCY<>'RMB'";
sqlOUTPUTTAXUSD += " group BY EXCHANGERATE,CURRENCY" + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAXUSD += " ORDER BY CURRENCY" + strISEXPLANnull + ssISEXPLAN;
}
else
{
sqlOUTPUTTAX = "SELECT SUM(TAX) AS je,SUM(Convert(decimal(18,2),(TAX*(CASE" + tbRATE + " ELSE EXCHANGERATE END)))) AS hj " + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " From VW_ch_fee_invoice WHERE 1=1 and TAX<>0" + strCondition + "";
sqlOUTPUTTAX += " group BY VOUNO" + strISEXPLANnull + ssISEXPLAN;
sqlOUTPUTTAX += " ORDER BY VOUNO" + strISEXPLANnull + ssISEXPLAN;
}
#endregion
}
DataSet dsVWChFeeInvoiceAR = T_ALL_DA.GetAllSQL(sqlAR);
DataSet dsVWChFeeInvoiceARFC = null;
if (sqlARFC.Trim() != "")
{
dsVWChFeeInvoiceARFC = T_ALL_DA.GetAllSQL(sqlARFC);
}
DataSet dsVWChFeeInvoiceMBINCOME = T_ALL_DA.GetAllSQL(sqlMBINCOME);
DataSet dsVWChFeeInvoiceTMFCI = null;
if (sqlTMFCI.Trim() != "")
{
dsVWChFeeInvoiceTMFCI = T_ALL_DA.GetAllSQL(sqlTMFCI);
}
DataSet dsVWChFeeInvoiceOUTPUTTAX = T_ALL_DA.GetAllSQL(sqlOUTPUTTAX);
DataSet dsVWChFeeInvoiceOUTPUTTAXUSD = null;
if (sqlOUTPUTTAXUSD.Trim() != "")
{
dsVWChFeeInvoiceOUTPUTTAXUSD = T_ALL_DA.GetAllSQL(sqlOUTPUTTAXUSD);
}
#endregion
if (dsVWChFeeInvoiceAR != null || dsVWChFeeInvoiceARFC != null)
{
#region 明细表_实体类
#region 插入明细表应收RMB dsAR
if (dsVWChFeeInvoiceAR != null)
{
for (int i = 0; i < dsVWChFeeInvoiceAR.Tables[0].Rows.Count; i++)
{
#region 摘要内容
strEXPLAN = "";
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否收付船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
#endregion
#region 插入明细表 应收账款
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;// 行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
#region 应收账款
iAMTDR = iAMTDR + Decimal.Parse(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["hj"].ToString().Trim());
//
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["AR"].ToString().Trim();//应收账款科目贷码
MsCwVouitemsGl.AMTDR = Decimal.Parse(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = "RMB";//外币编号usd
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
dRMBS += Decimal.Parse(dsVWChFeeInvoiceAR.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
//
MsCwVouitemsGl.ACCNAME = dsAR.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsAR.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
//是否核算客户
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = "";//客户(系统)
if (dsAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceAR.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceAR.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsAR.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要
MsCwVouitemsGl.FCYEXRATE = 1;//汇率
dEXCHANGERATE = 1;//汇率
MsCwVouitemsGl.BLNO = "";
string strBLNONAME = dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
if (strBLNONAME.Trim() != "")
{
MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceAR.Tables[0].Rows[i][strBLNONAME].ToString().Trim();
}
//if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
//{
// MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceAR.Tables[0].Rows[i]["MBLNO"].ToString().Trim();
//}
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
#endregion
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
#endregion
#region 插入明细表:应收外币 dsARFC
if (dsVWChFeeInvoiceARFC != null)
{
for (int i = 0; i < dsVWChFeeInvoiceARFC.Tables[0].Rows.Count; i++)
{
#region 摘要内容
strEXPLAN = "";
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否收付船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否收付航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
#endregion
#region 插入明细表 应收账款
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;// 行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
#region 应收账款
iAMTDR = iAMTDR + Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["hj"].ToString().Trim());
//
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["ARFC"].ToString().Trim();//应收账款科目贷码
MsCwVouitemsGl.AMTDR = Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CURRENCY"].ToString().Trim();//外币
strFCY = MsCwVouitemsGl.FCYNO;
MsCwVouitemsGl.FCYDR = Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["je"].ToString().Trim());//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
dRMBS += Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
//
MsCwVouitemsGl.ACCNAME = dsARFC.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsARFC.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
//是否核算客户
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = "";//客户(系统)
if (dsARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceARFC.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsARFC.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要
MsCwVouitemsGl.FCYEXRATE = Decimal.Parse(dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
dEXCHANGERATE = MsCwVouitemsGl.FCYEXRATE;//汇率
MsCwVouitemsGl.BLNO = "";
string strBLNONAME = dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
if (strBLNONAME.Trim() != "")
{
MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceARFC.Tables[0].Rows[i][strBLNONAME].ToString().Trim();
}
//if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
//{
// MsCwVouitemsGl.BLNO = dsVWChFeeInvoiceARFC.Tables[0].Rows[i]["MBLNO"].ToString().Trim();
//}
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
#endregion
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
#endregion
#region 插入明细表:主营业务收入
Decimal dRMB = dRMBS - dRMBF;
Decimal dUSD = dUSDS - dUSDF;
//收入\成本 生成 全额\差额
Decimal strJie = dRMBS + dUSDS * dEXCHANGERATE;
Decimal strDai = dRMBF + dUSDF * dEXCHANGERATE;
//
#region 全额
if (dsVWChFeeInvoiceMBINCOME != null)
{
for (int i = 0; i < dsVWChFeeInvoiceMBINCOME.Tables[0].Rows.Count; i++)
{
#region 摘要内容
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
strEXPLAN = "";
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
}
#endregion
#region 收入
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;//行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["MBINCOME"].ToString().Trim();//主营业务收入科目贷码
MsCwVouitemsGl.AMTDR = 0;//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币贷方金额(互斥)
strDai = strDai + MsCwVouitemsGl.AMTCR;
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = "RMB";//外币
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
MsCwVouitemsGl.ACCNAME = dsMBINCOME.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsMBINCOME.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
MsCwVouitemsGl.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
MsCwVouitemsGl.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
if (dsMBINCOME.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsMBINCOME.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsMBINCOME.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsMBINCOME.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceMBINCOME.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsMBINCOME.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.FCYEXRATE = 1;//汇率
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
MsCwVouitemsGl.BLNO = "";//
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
if (dsVWChFeeInvoiceTMFCI != null)
{
for (int i = 0; i < dsVWChFeeInvoiceTMFCI.Tables[0].Rows.Count; i++)
{
#region 摘要内容
if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
{
strEXPLAN = "";
if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
}
if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
}
if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strEXPLAN += " " + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
//}
}
#endregion
#region 收入_外币
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;//行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["TMFCI"].ToString().Trim();//主营业务收入科目贷码
MsCwVouitemsGl.AMTDR = 0;//本位币借方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币贷方金额(互斥)
strDai = strDai + MsCwVouitemsGl.AMTCR;
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYNO = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["CURRENCY"].ToString().Trim();//外币
strFCY = MsCwVouitemsGl.FCYNO;
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = Decimal.Parse(dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["je"].ToString().Trim());//外币贷方金额
MsCwVouitemsGl.ACCNAME = dsTMFCI.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsTMFCI.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
MsCwVouitemsGl.DC = "D";//借方向
}
else
{
MsCwVouitemsGl.DC = "C";//贷方向
}
//
string strACCALL = "";
MsCwVouitemsGl.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
MsCwVouitemsGl.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
if (dsTMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsTMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsTMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsTMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVWChFeeInvoiceTMFCI.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsTMFCI.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.FCYEXRATE = Decimal.Parse(dsVWChFeeInvoiceTMFCI.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ISSYS = false;//是否手动录入
}
else
{
MsCwVouitemsGl.ISSYS = true;//是否手动录入
}
MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
MsCwVouitemsGl.BLNO = "";//
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//部门(系统)
MsCwVouitemsGl.EMPLID = "";//人员(系统)
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
#endregion
#endregion
//#region 插入明细表:销项税
//if (dsVWChFeeInvoiceOUTPUTTAX != null)
//{
// for (int i = 0; i < dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows.Count; i++)
// {
// #region 摘要内容
// if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
// {
// strEXPLAN = "";
// if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
// {
// strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
// }
// if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
// {
// strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
// }
// if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
// {
// strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
// }
// //if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
// //{
// // strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否船名
// //}
// //if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
// //{
// // strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
// //}
// //if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
// //{
// // strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
// //}
// }
// #endregion
// #region 收入
// MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
// //MsCwVouitemsGl.GID 唯一编码 newid()
// MsCwVouitemsGl.ORDNO = strORDNO.Trim();
// MsCwVouitemsGl.ITEMNO = 0;//行号
// MsCwVouitemsGl.PACCID = "";//父级科目贷码
// MsCwVouitemsGl.PROPERTY = 0;//科目属性
// MsCwVouitemsGl.GRADE = 0;//科目级别
// MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["OUTPUTTAX"].ToString().Trim();//主营业务收入科目贷码
// MsCwVouitemsGl.AMTDR = 0;//本位币借方金额(互斥)
// MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币贷方金额(互斥)
// strDai = strDai + MsCwVouitemsGl.AMTCR;
// MsCwVouitemsGl.ISFCY = false;//是否外币
// MsCwVouitemsGl.FCYNO = "RMB";//外币
// MsCwVouitemsGl.FCYDR = 0;//外币借方金额
// MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
// MsCwVouitemsGl.ACCNAME = dsOUTPUTTAX.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
// MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
// MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
// MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
// MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
// if (dsOUTPUTTAX.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
// {
// MsCwVouitemsGl.DC = "D";//借方向
// }
// else
// {
// MsCwVouitemsGl.DC = "C";//贷方向
// }
// //
// string strACCALL = "";
// MsCwVouitemsGl.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
// MsCwVouitemsGl.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
// if (dsOUTPUTTAX.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
// {
// MsCwVouitemsGl.CORPID = "";//客户(系统)
// MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
// strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
// }
// //是否核算人员_揽货人
// if (dsOUTPUTTAX.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
// {
// MsCwVouitemsGl.SALE = dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
// strACCALL += "▁" + MsCwVouitemsGl.SALE;
// }
// //是否核算部门
// if (dsOUTPUTTAX.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
// {
// MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
// strACCALL += "▁" + dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
// }
// //是否核算项目
// if (dsOUTPUTTAX.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
// {
// MsCwVouitemsGl.ITEMGID = "";
// if (dsCwDesignItem != null)
// {
// for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
// {
// if (dsVWChFeeInvoiceOUTPUTTAX.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
// {
// MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
// strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
// }
// }
// }
// }
// MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsOUTPUTTAX.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
// MsCwVouitemsGl.FCYEXRATE = 1;//汇率
// if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
// {
// MsCwVouitemsGl.ISSYS = false;//是否手动录入
// }
// else
// {
// MsCwVouitemsGl.ISSYS = true;//是否手动录入
// }
// MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
// MsCwVouitemsGl.BLNO = "";//
// MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
// MsCwVouitemsGl.QTYDR = 0;//借方数量
// MsCwVouitemsGl.QTYCR = 0;//贷方数量
// MsCwVouitemsGl.DEPTID = "";//部门(系统)
// MsCwVouitemsGl.EMPLID = "";//人员(系统)
// MsCwVouitemsGl.PITEMID = 0;//父级项目编号
// MsCwVouitemsGl.ITEMID = "";//项目编号
// MsCwVouitemsGl.FIELD1 = "";//预留字段1
// MsCwVouitemsGl.FIELD2 = "";//预留字段2
// MsCwVouitemsGl.FIELD3 = "";//预留字段3
// MsCwVouitemsGl.FIELD4 = "";//预留字段4
// MsCwVouitemsGl.FIELD5 = "";//预留字段5
// MsCwVouitemsGl.FIELD6 = "";//预留字段6
// MsCwVouitemsGl.FIELD7 = "";//预留字段7
// MsCwVouitemsGl.FIELD8 = "";//预留字段8
// MsCwVouitemsGl.FIELD9 = "";//预留字段9
// MsCwVouitemsGl.FIELD10 = "";//预留字段10
// MsCwVouitemsGl.FSETTLCODE = "";//结算方式
// MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
// MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
// MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
// MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
// MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
// MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
// #endregion
// CwVouitemsEntities.Add(MsCwVouitemsGl);
// }
//}
//if (dsVWChFeeInvoiceOUTPUTTAXUSD != null)
//{
// for (int i = 0; i < dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows.Count; i++)
// {
// #region 摘要内容
// if (dsCwDesign.Tables[0].Rows[0]["ISMBINCOME"].ToString().Trim() == "False")//是否合并生成发票开出凭证中的主营业务科目
// {
// strEXPLAN = "";
// if (dsCwDesign.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
// {
// strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();
// }
// if (dsCwDesign.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
// {
// strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//是否委托编号CUSTNO//发票号
// }
// if (dsCwDesign.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
// {
// strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["MBLNO"].ToString().Trim();//是否主提单号
// }
// //if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
// //{
// // strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["VESSEL"].ToString().Trim();//是否船名
// //}
// //if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
// //{
// // strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["VOYNO"].ToString().Trim();//是否航次
// //}
// //if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
// //{
// // strEXPLAN += " " + dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim();//是否业务来源
// //}
// }
// #endregion
// #region 收入_外币
// MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
// //MsCwVouitemsGl.GID 唯一编码 newid()
// MsCwVouitemsGl.ORDNO = strORDNO.Trim();
// MsCwVouitemsGl.ITEMNO = 0;//行号
// MsCwVouitemsGl.PACCID = "";//父级科目贷码
// MsCwVouitemsGl.PROPERTY = 0;//科目属性
// MsCwVouitemsGl.GRADE = 0;//科目级别
// MsCwVouitemsGl.ACCID = dsCwDesign.Tables[0].Rows[0]["OUTPUTTAX"].ToString().Trim();//主营业务收入科目贷码
// MsCwVouitemsGl.AMTDR = 0;//本位币借方金额(互斥)
// MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币贷方金额(互斥)
// strDai = strDai + MsCwVouitemsGl.AMTCR;
// MsCwVouitemsGl.ISFCY = false;//是否外币
// MsCwVouitemsGl.FCYNO = dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["CURRENCY"].ToString().Trim();//外币
// strFCY = MsCwVouitemsGl.FCYNO;
// MsCwVouitemsGl.FCYDR = 0;//外币借方金额
// MsCwVouitemsGl.FCYCR = Decimal.Parse(dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["je"].ToString().Trim());//外币贷方金额
// MsCwVouitemsGl.ACCNAME = dsOUTPUTTAX.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
// MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
// MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
// MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
// MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsOUTPUTTAX.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
// if (dsOUTPUTTAX.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
// {
// MsCwVouitemsGl.DC = "D";//借方向
// }
// else
// {
// MsCwVouitemsGl.DC = "C";//贷方向
// }
// //
// string strACCALL = "";
// MsCwVouitemsGl.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
// MsCwVouitemsGl.CUSTOMERNAME = "";// strSALE;//人员(系统)本来应该放客户
// if (dsOUTPUTTAX.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
// {
// MsCwVouitemsGl.CORPID = "";//客户(系统)
// MsCwVouitemsGl.CUSTOMERNAME = dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
// strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
// }
// //是否核算人员_揽货人
// if (dsOUTPUTTAX.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
// {
// MsCwVouitemsGl.SALE = dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
// strACCALL += "▁" + MsCwVouitemsGl.SALE;
// }
// //是否核算部门
// if (dsOUTPUTTAX.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
// {
// MsCwVouitemsGl.DEPTGID = dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
// strACCALL += "▁" + dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
// }
// //是否核算项目
// if (dsOUTPUTTAX.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
// {
// MsCwVouitemsGl.ITEMGID = "";
// if (dsCwDesignItem != null)
// {
// for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
// {
// if (dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
// {
// MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
// strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
// }
// }
// }
// }
// MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsOUTPUTTAX.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
// MsCwVouitemsGl.FCYEXRATE = Decimal.Parse(dsVWChFeeInvoiceOUTPUTTAXUSD.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
// if (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
// {
// MsCwVouitemsGl.ISSYS = false;//是否手动录入
// }
// else
// {
// MsCwVouitemsGl.ISSYS = true;//是否手动录入
// }
// MsCwVouitemsGl.EXPLAN = strEXPLAN;//摘要,规则生成 "转运费" +
// MsCwVouitemsGl.BLNO = "";//
// MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
// MsCwVouitemsGl.QTYDR = 0;//借方数量
// MsCwVouitemsGl.QTYCR = 0;//贷方数量
// MsCwVouitemsGl.DEPTID = "";//部门(系统)
// MsCwVouitemsGl.EMPLID = "";//人员(系统)
// MsCwVouitemsGl.PITEMID = 0;//父级项目编号
// MsCwVouitemsGl.ITEMID = "";//项目编号
// MsCwVouitemsGl.FIELD1 = "";//预留字段1
// MsCwVouitemsGl.FIELD2 = "";//预留字段2
// MsCwVouitemsGl.FIELD3 = "";//预留字段3
// MsCwVouitemsGl.FIELD4 = "";//预留字段4
// MsCwVouitemsGl.FIELD5 = "";//预留字段5
// MsCwVouitemsGl.FIELD6 = "";//预留字段6
// MsCwVouitemsGl.FIELD7 = "";//预留字段7
// MsCwVouitemsGl.FIELD8 = "";//预留字段8
// MsCwVouitemsGl.FIELD9 = "";//预留字段9
// MsCwVouitemsGl.FIELD10 = "";//预留字段10
// MsCwVouitemsGl.FSETTLCODE = "";//结算方式
// MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
// MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
// MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
// MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
// MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
// MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
// #endregion
// CwVouitemsEntities.Add(MsCwVouitemsGl);
// }
//}
//#endregion
#endregion
#region 插入主表
MsCwVouchersGl MsCwVouchersGl = new MsCwVouchersGl();
MsCwVouchersGl.ORDNO = strORDNO.Trim();//唯一编码 newid() varchar (36)
MsCwVouchersGl.VOUDATE = headData.VOUDATE;//凭证日期
//strY + "~" + strM + "~" + sVOUNO + "~" + strVOUNO + "~" + strVOUDATE + "~" + strACCDATE;
//string sACCDATE = headData.VOUDATE.Substring(0, 7);
//if (DateTime.Parse(sACCDATE + "-01") < DateTime.Parse(strACCDATE + "-01"))
//{
// sACCDATE = strACCDATE;
//}
//string strVOUNOhj = DSWeb.MvcShipping.DAL.MsBaseInfoDAL.MsBaseInfoDAL.GetCwVOUNO(strBPVW.Trim(), sACCDATE);
//string[] items = strVOUNOhj.Trim().Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
//string sVOUNO = items[2].ToString().Trim();
//string strVOUNO = items[3].ToString().Trim();
MsCwVouchersGl.VOUNO = int.Parse(cfVOUALLNO.Substring(cfVOUALLNO.Length-4)).ToString();//sVOUNO;//月初清零 varchar (16)
MsCwVouchersGl.ACCYEAR = DateTime.Parse(headData.VOUDATE.ToString()).Year.ToString();//年
MsCwVouchersGl.ACCMONTH = DateTime.Parse(headData.VOUDATE.ToString()).Month.ToString();//月
if (MsCwVouchersGl.ACCMONTH.ToString().Length == 1)
{
MsCwVouchersGl.ACCMONTH = "0" + MsCwVouchersGl.ACCMONTH.ToString();//月
}
MsCwVouchersGl.VKNO = strBPVW.Trim();//凭证字
//MsCwVouchersGl.VOUALLNO = MsCwVouchersGl.VKNO + MsCwVouchersGl.ACCYEAR + MsCwVouchersGl.ACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
MsCwVouchersGl.VOUALLNO = cfVOUALLNO.Replace("记", strBPVW.Trim());//年+月+自动生成编号=凭证号
MsCwVouchersGl.ATTACHS = 1;// int.Parse(dsCwDesign.Tables[0].Rows[0]["AFFIXNO"].ToString().Trim());//附件(单据)数
MsCwVouchersGl.AMTDR = strJie;// iAMTDR;//本位币借方
MsCwVouchersGl.AMTCR = strDai;//iAMTDR;// iAMTCR;//本位币贷方
MsCwVouchersGl.FCY = strFCY;//是否含有外币科目
MsCwVouchersGl.QTY = "";//是否含有数量科目
MsCwVouchersGl.VOUPROP = "";//凭证属性
MsCwVouchersGl.PREPARED = headData.PREPARED.ToString().Trim();//制单人
MsCwVouchersGl.CHECKED = "";//审核人
MsCwVouchersGl.ENTERED = "";//记账人
MsCwVouchersGl.ERRMSG = "";//错误信息
MsCwVouchersGl.ISDELETE = false;//是否废除
MsCwVouchersGl.DELETEUSER = "";//废除操作人
MsCwVouchersGl.STARTGID = strCwSTARTGID;
MsCwVouchersGl.DbOperationType = DbOperationType.DbotIns;
MsCwVouchersGl.CREATEUSER = strUserID;//创建人
MsCwVouchersGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouchersGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouchersGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
MsCwVouchersGl.ISAUTO = true;
#endregion
#region 生成入库
var modb = new ModelObjectDB();
result = modb.Save(MsCwVouchersGl);
if (result.Success == true)
{
2 years ago
//int n = 1;
2 years ago
BasicDataRefDAL.SetGLOrder(ref CwVouitemsEntities);
3 years ago
foreach (var enumValue in CwVouitemsEntities)
{
enumValue.GID = Guid.NewGuid().ToString();
2 years ago
//enumValue.ITEMNO = n;
3 years ago
enumValue.DbOperationType = DbOperationType.DbotIns;
var modb2 = new ModelObjectDB();
DBResult result2 = modb2.Save(enumValue);
2 years ago
//n++;
3 years ago
}
//更新凭证生成关系表中的ORDNO数据
string strLS = sAndGids.Replace("GID", "BSGID");
string blSQL = "update [cw_vouno_bs_gl] set ORDNO='" + MsCwVouchersGl.ORDNO + "' where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
blSQL = "update code_fill_serialno set ISDELETE=1,DELETEUSER='" + strUserID + "',DELETETIME=GETDATE() where TABLENAME='cw_vouchers_gl' and SERIALNO='" + cfVOUALLNO + "' and STARTGID='" + strCwSTARTGID + "'";
bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
}
else
{
//result.Success = false;
//result.Message = result.Message;
//return result;
//删除ch_fee_invoice中未生成的凭证号
//string blSQL = "update ch_fee_invoice set VOUNO='' where VOUNO='" + cfVOUALLNO + "'" + sAndGids.Trim();
//删除凭证生成关系表中的ch_fee_invoice的GID数据
string strLS = sAndGids.Replace("GID", "BSGID");
string blSQL = "delete from [cw_vouno_bs_gl] where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
return -2;//重复数据
}
#endregion
}
else
{
//删除ch_fee_invoice中未生成的凭证号
//string blSQL = "update ch_fee_invoice set VOUNO='' where VOUNO='" + cfVOUALLNO + "'" + sAndGids.Trim();
//删除凭证生成关系表中的ch_fee_invoice的GID数据
string strLS = sAndGids.Replace("GID", "BSGID");
string blSQL = "delete from [cw_vouno_bs_gl] where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
return -3;//结算无明细数据
}
//result.Success = true;
//result.Message = result.Message;
//return result;
return 1;
}
public static String getGid()
{
string strgid = Guid.NewGuid().ToString();
strgid = strgid.Replace("-", "");
strgid = "VOU" + strgid;
return strgid;
}
#endregion
}
}