strSql.Append("SELECT GID,(case when ISLOCK=1 then '是' else '' end) as ISLOCK,DUINO,CUSTOMERNAME,CONVERT(char(10), STARTBILLINGDATE, 20) as STARTBILLINGDATE,CONVERT(char(10), ENDBILLINGDATE, 20) as ENDBILLINGDATE,REMARK,CORPID,CREATEUSER,CREATETIME,ISMAKEOUT,MAKEOUTUSER,MAKEOUTTIME,(select top 1 SHOWNAME from [user] where gid=wms_settlement_list.CREATEUSER) as CREATEUSER_NAME,(select top 1 SHOWNAME from [user] where gid=wms_settlement_list.MAKEOUTUSER) as MAKEOUTUSER_NAME from wms_settlement_list where CORPID='"+strCompanyID+"' and ISDELETE=0");//CREATEUSER='" + strUserID + "' and
if(!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and "+strCondition);
}
//
varsortstring=DatasetSort.Getsortstring(sort);
if(!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by "+sortstring);
}
else{
strSql.Append(" order by DUINO desc,CREATETIME desc");
stringstrWSD="select top 1 * from wms_settlement_date where LINKGID='"+dr["GID"].ToString().Trim()+"' and TABLENAME='wms' and ISDELETE=0 order by ENDBILLINGDATE desc";
// + " from [wms_settlement_detail_rate_detail_temp] where ASSOCIATEDNO='" + dr["GID"].ToString().Trim() + "' and OUTFEE<>0 ORDER BY ASSOCIATEDNO,FEETYPE,FEEGRADE,CREATETIME";
strSql="insert into [wms_settlement_detail_temp]([GID],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],[CREATETIME],[ISMAKEOUT],[MAKEOUTUSER],[MAKEOUTTIME],[CORPID],[LINENUM],[GID_LINK]) "
+" from [wms_settlement_detail_rate_detail_temp] as r INNER JOIN ["+TableName_ls+"] as t on r.ASSOCIATEDNO=t.GID where r.OUTFEE<>0 and t.hj_GOODSSTOCK<>0";
// + " where 1=1 and NID not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='wms_out_detail')"
// + " and WMS_OUT_GID not in (select isnull(WMSOUTBSNO,'') as WMSOUTBSNO from ch_fee)"
// + " and (gid in (select ASSOCIATEDNO from wms_settlement_detail_rate_detail_temp) or WMS_OUT_GID in (select ASSOCIATEDNO from wms_settlement_detail_rate_detail_temp))"
// + " and gid='" + dr["GID"].ToString().Trim() + "'"
// + strCondition + strCondition2 + strCondition3
// + " group by GID,BLNO,CUSTOMNO,CONTRACTNO,WMSNO,CUSTOMERNAME,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSSTANDARD,GOODSGRADE,WMSDATE,STARTBILLINGDATE,GOODSPACK,GOODSPACKACTUAL,GOODSRKSL,GOODSRKSLACTUAL,CHARGEUNIT";
strSql="select *,isChFee=isnull((select top 1 gid from ch_fee where WMSOUTBSNO=VW_WMS_DETAIL_INNER.WMS_OUT_GID and FEENAME='仓储费'),'0') from VW_WMS_DETAIL_INNER where CUSTOMERNAME=ARCLIENTWMSOUT and NID not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='wms_out_detail')"
//+ " and WMS_OUT_GID not in (select isnull(WMSOUTBSNO,'') as WMSOUTBSNO from ch_fee) "
stringstrWSD="select top 1 * from wms_settlement_date where LINKGID='"+dr["WMS_OUT_GID"].ToString().Trim()+"' and TABLENAME='wms_out' and ISDELETE=0 order by ENDBILLINGDATE desc";
stringstrWSD_IN="select top 1 * from wms_settlement_date where LINKGID='"+dr["GID"].ToString().Trim()+"' and TABLENAME='wms' and ISDELETE=0 order by ENDBILLINGDATE desc";
stringstrWSD_IN="select top 1 * from wms_settlement_date where LINKGID='"+dr["GID"].ToString().Trim()+"' and TABLENAME='wms' and ISDELETE=0 order by ENDBILLINGDATE desc";
strSql="insert into [wms_settlement_detail_temp]([GID],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],[CREATETIME],[ISMAKEOUT],[MAKEOUTUSER],[MAKEOUTTIME],[CORPID],[LINENUM],[GID_LINK]) "
+" select newid() as GID,i.BLNO,i.CUSTOMNO,i.CONTRACTNO,i.WMSNO,i.OUTBSNO_OUT,i.CUSTOMERNAME,i.STORAGENAME,i.GOODSNAME,i.GOODSMODEL,i.GOODSSTANDARD,i.GOODSGRADE,i.WMSDATE,i.DODATE as DODATE_OUT,i.WMSDAYS,i.STARTBILLINGDATE,i.ENDBILLINGDATE,i.GOODSOUTFEE_OUT,i.GOODSPACK,i.GOODSPACKACTUAL,i.GOODSPACKPFSL_OUT,i.GOODSPACKSTOCK,0 as GOODSRKSL,i.GOODSRKSLACTUAL,i.GOODSPFSL_OUT,0 as GOODSSTOCK,i.CHARGEUNIT,i.REMARK_OUT"
+",isnull(r.FEETYPE,1) as FEETYPE,isnull(r.FEEGRADE,1) as FEEGRADE,isnull(r.FEESCALE,0) as FEESCALE,isnull(r.FEEPRICE,0) as FEEPRICE,isnull(r.STARTBILLINGDATE,i.STARTBILLINGDATE) as STARTBILLINGDATE,isnull(r.ENDBILLINGDATE,i.ENDBILLINGDATE) as ENDBILLINGDATE,isnull(r.FEESCALE,0) as FEESCALE,(case when isChFee<>'0' then 0 else isnull(r.OUTFEE,0) end) as OUTFEE,0"
+" from (select *,isChFee=isnull((select top 1 gid from ch_fee where WMSOUTBSNO=VW_WMS_DETAIL_INNER.WMS_OUT_GID and FEENAME='仓储费'),'0') from VW_WMS_DETAIL_INNER where CUSTOMERNAME=ARCLIENTWMSOUT and NID not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='wms_out_detail')"
//+ " and WMS_OUT_GID not in (select isnull(WMSOUTBSNO,'') as WMSOUTBSNO from ch_fee) "
+strCondition+strCondition2+strCondition3+") as i LEFT JOIN [wms_settlement_detail_rate_detail_temp] as r on i.GID_OUT=r.ASSOCIATEDNO"
+" where isnull(r.FEETYPE,1)=1 and r.CREATEUSER='"+strUserID+"'"
+" ORDER BY r.ASSOCIATEDNO,r.FEETYPE,r.FEEGRADE,r.CREATETIME";
strSql="select *,isChFee=isnull((select top 1 gid from ch_fee where WMSOUTBSNO=VW_WMS_DETAIL_INNER.WMS_OUT_GID and FEENAME='仓储费'),'0') from VW_WMS_DETAIL_INNER where CUSTOMERNAME<>ARCLIENTWMSOUT and NID not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='wms_out_detail')"
//+ " and WMS_OUT_GID not in (select isnull(WMSOUTBSNO,'') as WMSOUTBSNO from ch_fee) "
stringstrWSD="select top 1 * from wms_settlement_date where LINKGID='"+dr["WMS_OUT_GID"].ToString().Trim()+"' and TABLENAME='wms_out' and ISDELETE=0 order by ENDBILLINGDATE desc";
stringstrWSD_IN="select top 1 * from wms_settlement_date where LINKGID='"+dr["GID"].ToString().Trim()+"' and TABLENAME='wms' and ISDELETE=0 order by ENDBILLINGDATE desc";
stringstrWSD_IN="select top 1 * from wms_settlement_date where LINKGID='"+dr["GID"].ToString().Trim()+"' and TABLENAME='wms' and ISDELETE=0 order by ENDBILLINGDATE desc";
strSql="insert into [wms_settlement_detail_temp]([GID],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],[CREATETIME],[ISMAKEOUT],[MAKEOUTUSER],[MAKEOUTTIME],[CORPID],[LINENUM],[GID_LINK]) "
+" select newid() as GID,i.BLNO,i.CUSTOMNO,i.CONTRACTNO,i.WMSNO,i.OUTBSNO_OUT,i.CUSTOMERNAME,i.STORAGENAME,i.GOODSNAME,i.GOODSMODEL,i.GOODSSTANDARD,i.GOODSGRADE,i.WMSDATE,i.DODATE as DODATE_OUT,i.WMSDAYS,i.STARTBILLINGDATE,i.ENDBILLINGDATE,i.GOODSOUTFEE_OUT,i.GOODSPACK,i.GOODSPACKACTUAL,i.GOODSPACKPFSL_OUT,i.GOODSPACKSTOCK,0 as GOODSRKSL,i.GOODSRKSLACTUAL,i.GOODSPFSL_OUT,0 as GOODSSTOCK,i.CHARGEUNIT,(i.REMARK_OUT+' 由 '+i.ARCLIENTWMSOUT+' 代收仓储费;') as REMARK_OUT"
+",isnull(r.FEETYPE,1) as FEETYPE,isnull(r.FEEGRADE,1) as FEEGRADE,isnull(r.FEESCALE,0) as FEESCALE,isnull(r.FEEPRICE,0) as FEEPRICE,isnull(r.STARTBILLINGDATE,i.STARTBILLINGDATE) as STARTBILLINGDATE,isnull(r.ENDBILLINGDATE,i.ENDBILLINGDATE) as ENDBILLINGDATE,isnull(r.FEESCALE,0) as FEESCALE,0,0"
+" from (select *,isChFee=isnull((select top 1 gid from ch_fee where WMSOUTBSNO=VW_WMS_DETAIL_INNER.WMS_OUT_GID and FEENAME='仓储费'),'0') from VW_WMS_DETAIL_INNER where CUSTOMERNAME<>ARCLIENTWMSOUT and NID not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='wms_out_detail')"
//+ " and WMS_OUT_GID not in (select isnull(WMSOUTBSNO,'') as WMSOUTBSNO from ch_fee) "
+strCondition+strCondition2+strCondition3+") as i LEFT JOIN [wms_settlement_detail_rate_detail_temp] as r on i.GID_OUT=r.ASSOCIATEDNO"
+" where isnull(r.FEETYPE,1)=1 and r.CREATEUSER='"+strUserID+"'"
+" ORDER BY r.ASSOCIATEDNO,r.FEETYPE,r.FEEGRADE,r.CREATETIME";
strSql="select *,isChFee=isnull((select top 1 gid from ch_fee where WMSOUTBSNO=VW_WMS_DETAIL_INNER.WMS_OUT_GID and FEENAME='仓储费'),'0') from VW_WMS_DETAIL_INNER where CUSTOMERNAME<>ARCLIENTWMSOUT and NID not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='wms_out_detail')"
//+ " and WMS_OUT_GID not in (select isnull(WMSOUTBSNO,'') as WMSOUTBSNO from ch_fee) "
stringstrWSD="select top 1 * from wms_settlement_date where LINKGID='"+dr["WMS_OUT_GID"].ToString().Trim()+"' and TABLENAME='wms_out' and ISDELETE=0 order by ENDBILLINGDATE desc";
stringstrWSD_IN="select top 1 * from wms_settlement_date where LINKGID='"+dr["GID"].ToString().Trim()+"' and TABLENAME='wms' and ISDELETE=0 order by ENDBILLINGDATE desc";
stringstrWSD_IN="select top 1 * from wms_settlement_date where LINKGID='"+dr["GID"].ToString().Trim()+"' and TABLENAME='wms' and ISDELETE=0 order by ENDBILLINGDATE desc";
strSql="insert into [wms_settlement_detail_temp]([GID],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],[CREATETIME],[ISMAKEOUT],[MAKEOUTUSER],[MAKEOUTTIME],[CORPID],[LINENUM],[GID_LINK]) "
+" select newid() as GID,i.BLNO,i.CUSTOMNO,i.CONTRACTNO,i.WMSNO,i.OUTBSNO_OUT,i.ARCLIENTWMSOUT,i.STORAGENAME,i.GOODSNAME,i.GOODSMODEL,i.GOODSSTANDARD,i.GOODSGRADE,i.WMSDATE,i.DODATE as DODATE_OUT,i.WMSDAYS,i.STARTBILLINGDATE,i.ENDBILLINGDATE,i.GOODSOUTFEE_OUT,i.GOODSPACK,i.GOODSPACKACTUAL,i.GOODSPACKPFSL_OUT,i.GOODSPACKSTOCK,0 as GOODSRKSL,i.GOODSRKSLACTUAL,i.GOODSPFSL_OUT,0 as GOODSSTOCK,i.CHARGEUNIT,(i.REMARK_OUT+' 代 '+i.CUSTOMERNAME+' 付仓储费;') as REMARK_OUT"
+",isnull(r.FEETYPE,1) as FEETYPE,isnull(r.FEEGRADE,1) as FEEGRADE,isnull(r.FEESCALE,0) as FEESCALE,isnull(r.FEEPRICE,0) as FEEPRICE,isnull(r.STARTBILLINGDATE,i.STARTBILLINGDATE) as STARTBILLINGDATE,isnull(r.ENDBILLINGDATE,i.ENDBILLINGDATE) as ENDBILLINGDATE,isnull(r.FEESCALE,0) as FEESCALE,(case when isChFee<>'0' then 0 else isnull(r.OUTFEE,0) end) as OUTFEE,0"
+" from (select *,isChFee=isnull((select top 1 gid from ch_fee where WMSOUTBSNO=VW_WMS_DETAIL_INNER.WMS_OUT_GID and FEENAME='仓储费'),'0') from VW_WMS_DETAIL_INNER where CUSTOMERNAME<>ARCLIENTWMSOUT and NID not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='wms_out_detail')"
//+ " and WMS_OUT_GID not in (select isnull(WMSOUTBSNO,'') as WMSOUTBSNO from ch_fee) "
+strCondition_ls+strCondition2_ls+strCondition3_ls+") as i LEFT JOIN [wms_settlement_detail_rate_detail_temp] as r on i.GID_OUT=r.ASSOCIATEDNO"
+" where isnull(r.FEETYPE,1)=1 and r.CREATEUSER='"+strUserID+"'"
+" ORDER BY r.ASSOCIATEDNO,r.FEETYPE,r.FEEGRADE,r.CREATETIME";
//strSql = "insert into [wms_settlement_detail_temp]([GID],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[STARTBILLINGDATE_OUT],[GOODSPACK],[GOODSPACKACTUAL],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSSTOCK],[CHARGEUNIT],[CREATEUSER],[CREATETIME],[ISMAKEOUT],[MAKEOUTUSER],[MAKEOUTTIME],[CORPID],[LINENUM],[GID_LINK]) "
//+ " select newid() as GID,BLNO,CUSTOMNO,CONTRACTNO,WMSNO,CUSTOMERNAME,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSSTANDARD,GOODSGRADE,WMSDATE,STARTBILLINGDATE,GOODSPACK,GOODSPACKACTUAL,GOODSRKSL,GOODSRKSLACTUAL,isnull(sum(GOODSPFSL_OUT),0) as GOODSSTOCK,CHARGEUNIT,'" + strUserID + "',getdate(),0,'" + strUserID + "',getdate(),'" + strCompanyID + "',1,GID from VW_WMS_DETAIL_INNER where 1=1 and NID not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='wms_out_detail') and WMS_OUT_GID not in (select isnull(WMSOUTBSNO,'') as WMSOUTBSNO from ch_fee) and (gid in (select ASSOCIATEDNO from wms_settlement_detail_rate_detail_temp) or WMS_OUT_GID in (select ASSOCIATEDNO from wms_settlement_detail_rate_detail_temp))" + strCondition + strCondition2 + strCondition3
//+ " group by GID,BLNO,CUSTOMNO,CONTRACTNO,WMSNO,CUSTOMERNAME,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSSTANDARD,GOODSGRADE,WMSDATE,STARTBILLINGDATE,GOODSPACK,GOODSPACKACTUAL,GOODSRKSL,GOODSRKSLACTUAL,CHARGEUNIT order by WMSNO";
strSql="update [wms_settlement_detail_temp] set ARFEE=isnull((select sum(isnull(AMOUNT,0)) as AMOUNT from ch_fee where isnull(WMSOUTBSNO,'')=[wms_settlement_detail_temp].GID_LINK and isnull(CUSTOMERNAME,'')=[wms_settlement_detail_temp].CUSTOMERNAME and feename<>'仓储费' and gid not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='ch_fee')),0) where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"' and (LINENUM=2 or LINENUM=3 or LINENUM=4) and FEETYPE=1 and FEEGRADE=1";
strSql="select * from [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"' and (LINENUM=2 or LINENUM=3 or LINENUM=4) and FEETYPE=1 and FEEGRADE=1 and ARFEE<>0";
strSql="select * from ch_fee where isnull(WMSOUTBSNO,'')='"+dr["GID_LINK"].ToString().Trim()+"' and isnull(CUSTOMERNAME,'')='"+dr["CUSTOMERNAME"].ToString().Trim()+"' and feename<>'仓储费' and gid not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='ch_fee')";
strSql="update [wms_settlement_detail_temp] set REMARK_OUT=REMARK_OUT+' "+ls+"' where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"' and gid='"+dr["GID"].ToString().Trim()+"'";
strSql="insert into [wms_settlement_detail_temp]([GID],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[STARTBILLINGDATE_OUT],[GOODSPACK],[GOODSPACKACTUAL],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSSTOCK],[CHARGEUNIT],[CREATEUSER],[CREATETIME],[ISMAKEOUT],[MAKEOUTUSER],[MAKEOUTTIME],[CORPID],[LINENUM],[GID_LINK]) "
+" select newid() as GID,BLNO,CUSTOMNO,CONTRACTNO,WMSNO,CUSTOMERNAME,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSSTANDARD,GOODSGRADE,WMSDATE,STARTBILLINGDATE,GOODSPACK,GOODSPACKACTUAL,GOODSRKSL,GOODSRKSLACTUAL"
+",GOODSSTOCK=(select isnull((hj_GOODSPFSL_MONTH+hj_GOODSSTOCK),0) as ls_GOODSSTOCK from ["+TableName_ls+"] where GID=VW_WMS_DETAIL_INNER.GID and hj_GOODSRKSL<>hj_GOODSSTOCK)"
+" where 1=1 and NID not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='wms_out_detail')"
//+ " and WMS_OUT_GID not in (select isnull(WMSOUTBSNO,'') as WMSOUTBSNO from ch_fee)"
+" and (gid in (select ASSOCIATEDNO from wms_settlement_detail_rate_detail_temp) or WMS_OUT_GID in (select ASSOCIATEDNO from wms_settlement_detail_rate_detail_temp))"
+" and WMSNO in (select WMSNO from wms_settlement_detail_temp where WMSNO=VW_WMS_DETAIL_INNER.WMSNO and (LINENUM=2 or LINENUM=3 or LINENUM=4))"//因此查询条件所以必须放到最后
+strCondition+strCondition2+strCondition3
+" group by GID,BLNO,CUSTOMNO,CONTRACTNO,WMSNO,CUSTOMERNAME,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSSTANDARD,GOODSGRADE,WMSDATE,STARTBILLINGDATE,GOODSPACK,GOODSPACKACTUAL,GOODSRKSL,GOODSRKSLACTUAL,CHARGEUNIT";
stringstrSql2="SELECT newid() as GID,DUIGID,DUINO,BLNO,CUSTOMNO,CONTRACTNO,CUSTOMERNAME,GOODSNAME FROM [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"' group by DUIGID,DUINO,BLNO,CUSTOMNO,CONTRACTNO,CUSTOMERNAME,GOODSNAME,CREATEUSER,CORPID";
StringstrSql="insert into wms_settlement_list(GID,DUINO,CUSTOMERNAME,{0}{2}REMARK,CORPID,CREATEUSER,CREATETIME,ISMAKEOUT,MAKEOUTUSER,MAKEOUTTIME) values (@GID,@DUINO,@CUSTOMERNAME,{1}{3}@REMARK,@CORPID,@CREATEUSER,getdate(),@ISMAKEOUT,@MAKEOUTUSER,getdate())";
strSql="insert into wms_settlement_detail([GID],[DUIGID],[DUINO],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],[CREATETIME],[ISMAKEOUT],[MAKEOUTUSER],[MAKEOUTTIME],[CORPID],[LINENUM],[GID_LINK]) "
+"select [GID],'"+model.GID.ToString().Trim()+"' as DUIGID,'"+model.DUINO.ToString().Trim()+"' as [DUINO],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],getdate(),[ISMAKEOUT],[MAKEOUTUSER],getdate(),[CORPID],[LINENUM],[GID_LINK]"
+" from [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"'"+condition;
strSql="insert into wms_settlement_date([GID],[DUIGID],[DUINO],[LINKGID],[TABLENAME],[STARTBILLINGDATE],[ENDBILLINGDATE],[CREATEUSER],[CREATETIME]) "
+"select newid() as GID,'"+model.GID.ToString().Trim()+"' as DUIGID,'"+model.DUINO.ToString().Trim()+"' as DUINO,GID_LINK as LINKGID,'wms' as TABLENAME,"+strSTARTBILLINGDATE+strENDBILLINGDATE+"CREATEUSER,getdate() from [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"' and (LINENUM=1 or LINENUM=5) "+condition+" group by LINENUM,GID_LINK,CREATEUSER,CORPID";
strSql="insert into wms_settlement_date([GID],[DUIGID],[DUINO],[LINKGID],[TABLENAME],[STARTBILLINGDATE],[ENDBILLINGDATE],[CREATEUSER],[CREATETIME]) "
+"select newid() as GID,'"+model.GID.ToString().Trim()+"' as DUIGID,'"+model.DUINO.ToString().Trim()+"' as DUINO,GID_LINK as LINKGID,'wms_out' as TABLENAME,"+strSTARTBILLINGDATE+strENDBILLINGDATE+"CREATEUSER,getdate() from [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"' and (LINENUM=2 or LINENUM=3 or LINENUM=4) "+condition+" group by LINENUM,GID_LINK,CREATEUSER,CORPID";
strSql="insert into wms_settlement_date([GID],[DUIGID],[DUINO],[LINKGID],[TABLENAME],[STARTBILLINGDATE],[ENDBILLINGDATE],[CREATEUSER],[CREATETIME]) "
+"select newid() as GID,'"+model.GID.ToString().Trim()+"' as DUIGID,'"+model.DUINO.ToString().Trim()+"' as DUINO,GID as LINKGID,'ch_fee' as TABLENAME,"+strSTARTBILLINGDATE+strENDBILLINGDATE+"'"+strUserID+"' as CREATEUSER,getdate() from ch_fee where isnull(WMSOUTBSNO,'') in (select GID_LINK from [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"' and (LINENUM=2 or LINENUM=3 or LINENUM=4) "+condition+") and (FEESTATUS<>9 or FEESTATUS<>8)";
//strSql = "insert into ch_fee(GID,BSNO,FEETYPE,FEENAME,CUSTOMERNAME,UNIT,UNITPRICE,QUANTITY,AMOUNT,EXCHANGERATE,CURRENCY,COMMISSIONRATE,FEEFRT,REMARK,ISADVANCEDPAY,ENTEROPERATOR,ENTERDATE,FEESTATUS,WMSOUTBSNO,LINENUM) "
//+ "select newid() as GID,bsno=(select top 1 bsno from op_seai where mblno=[wms_settlement_detail_temp].blno),1,'仓储费',CUSTOMERNAME,'单票',sum(isnull(OUTFEE,0)),1,sum(isnull(OUTFEE,0)),1,'RMB',0,'PP','仓储结算清单“" + model.DUINO.ToString().Trim() + "”中的单票仓储费汇总',0,'" + strUserID + "',getdate(),1,'" + model.GID.ToString().Trim() + "',LINENUM=(select top 1 LINENUM+1 from ch_fee where bsno=(select top 1 bsno from op_seai where mblno=[wms_settlement_detail_temp].blno) and feetype=1 order by LINENUM desc)"
//+ " from [wms_settlement_detail_temp] where CREATEUSER='" + strUserID + "' and CORPID='" + strCompanyID + "' and isnull(OUTFEE,0)<>0 " + condition + " group by blno,CUSTOMERNAME,CREATEUSER,CORPID";
stringstrSql="select CUSTOMERNAME from [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"'"+condition+" group by CUSTOMERNAME";
strSql="insert into wms_settlement_list(GID,DUINO,CUSTOMERNAME,{0}{2}REMARK,CORPID,CREATEUSER,CREATETIME,ISMAKEOUT,MAKEOUTUSER,MAKEOUTTIME) values (@GID,@DUINO,@CUSTOMERNAME,{1}{3}@REMARK,@CORPID,@CREATEUSER,getdate(),@ISMAKEOUT,@MAKEOUTUSER,getdate())";
strSql="insert into wms_settlement_detail([GID],[DUIGID],[DUINO],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],[CREATETIME],[ISMAKEOUT],[MAKEOUTUSER],[MAKEOUTTIME],[CORPID],[LINENUM],[GID_LINK]) "
+"select [GID],'"+model.GID.ToString().Trim()+"' as DUIGID,'"+model.DUINO.ToString().Trim()+"' as [DUINO],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],getdate(),[ISMAKEOUT],[MAKEOUTUSER],getdate(),[CORPID],[LINENUM],[GID_LINK]"
+" from [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"'"+condition+condition2;
strSql="insert into wms_settlement_date([GID],[DUIGID],[DUINO],[LINKGID],[TABLENAME],[STARTBILLINGDATE],[ENDBILLINGDATE],[CREATEUSER],[CREATETIME]) "
+"select newid() as GID,'"+model.GID.ToString().Trim()+"' as DUIGID,'"+model.DUINO.ToString().Trim()+"' as DUINO,GID_LINK as LINKGID,'wms' as TABLENAME,"+strSTARTBILLINGDATE+strENDBILLINGDATE+"CREATEUSER,getdate() from [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"' and (LINENUM=1 or LINENUM=5) "+condition+condition2+" group by LINENUM,GID_LINK,CREATEUSER,CORPID";
strSql="insert into wms_settlement_date([GID],[DUIGID],[DUINO],[LINKGID],[TABLENAME],[STARTBILLINGDATE],[ENDBILLINGDATE],[CREATEUSER],[CREATETIME]) "
+"select newid() as GID,'"+model.GID.ToString().Trim()+"' as DUIGID,'"+model.DUINO.ToString().Trim()+"' as DUINO,GID_LINK as LINKGID,'wms_out' as TABLENAME,"+strSTARTBILLINGDATE+strENDBILLINGDATE+"CREATEUSER,getdate() from [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"' and (LINENUM=2 or LINENUM=3 or LINENUM=4) "+condition+condition2+" group by LINENUM,GID_LINK,CREATEUSER,CORPID";
strSql="insert into wms_settlement_date([GID],[DUIGID],[DUINO],[LINKGID],[TABLENAME],[STARTBILLINGDATE],[ENDBILLINGDATE],[CREATEUSER],[CREATETIME]) "
+"select newid() as GID,'"+model.GID.ToString().Trim()+"' as DUIGID,'"+model.DUINO.ToString().Trim()+"' as DUINO,GID as LINKGID,'ch_fee' as TABLENAME,"+strSTARTBILLINGDATE+strENDBILLINGDATE+"'"+strUserID+"' as CREATEUSER,getdate() from ch_fee where isnull(WMSOUTBSNO,'') in (select GID_LINK from [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"' and (LINENUM=2 or LINENUM=3 or LINENUM=4) "+condition+condition2+") and (FEESTATUS<>9 or FEESTATUS<>8)";
//strSql = "insert into ch_fee(GID,BSNO,FEETYPE,FEENAME,CUSTOMERNAME,UNIT,UNITPRICE,QUANTITY,AMOUNT,EXCHANGERATE,CURRENCY,COMMISSIONRATE,FEEFRT,REMARK,ISADVANCEDPAY,ENTEROPERATOR,ENTERDATE,FEESTATUS,WMSOUTBSNO,LINENUM) "
//+ "select newid() as GID,bsno=(select top 1 bsno from op_seai where mblno=[wms_settlement_detail_temp].blno),1,'仓储费',CUSTOMERNAME,'单票',sum(isnull(OUTFEE,0)),1,sum(isnull(OUTFEE,0)),1,'RMB',0,'PP','仓储结算清单“" + model.DUINO.ToString().Trim() + "”中的单票仓储费汇总',0,'" + strUserID + "',getdate(),1,'" + model.GID.ToString().Trim() + "',LINENUM=(select top 1 LINENUM+1 from ch_fee where bsno=(select top 1 bsno from op_seai where mblno=[wms_settlement_detail_temp].blno) and feetype=1 order by LINENUM desc)"
//+ " from [wms_settlement_detail_temp] where CREATEUSER='" + strUserID + "' and CORPID='" + strCompanyID + "' and isnull(OUTFEE,0)<>0 " + condition + condition2 + " group by blno,CUSTOMERNAME,CREATEUSER,CORPID";
stringstrSql="SELECT * from ch_fee where gid not in (select LINKGID from wms_settlement_date where ISDELETE=0 and TABLENAME='ch_fee')";// ISDEBIT=0 and
stringstrSql2="SELECT GID,BLNO,CUSTOMNO,CONTRACTNO,WMSNO,OUTBSNO,CUSTOMERNAME,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSSTANDARD,GOODSGRADE,dbo.trimdate(WMSDATE) as WMSDATE,dbo.trimdate(DODATE) as DODATE,WMSDAYS,dbo.trimdate(STARTBILLINGDATE_OUT) as STARTBILLINGDATE_OUT,dbo.trimdate(ENDBILLINGDATE_OUT) as ENDBILLINGDATE_OUT,GOODSOUTFEE,GOODSPACK,GOODSPACKACTUAL,GOODSPACKPFSL,GOODSPACKSTOCK,GOODSRKSL,GOODSRKSLACTUAL,GOODSPFSL,GOODSSTOCK,CHARGEUNIT,REMARK_OUT,FEETYPE,FEEGRADE,FEESCALE,FEEPRICE,dbo.trimdate(STARTBILLINGDATE) as STARTBILLINGDATE,dbo.trimdate(ENDBILLINGDATE) as ENDBILLINGDATE,FEEDAYS,OUTFEE,[ARFEE],CREATEUSER,CREATETIME,ISMAKEOUT,MAKEOUTUSER,MAKEOUTTIME,CORPID,LINENUM,GID_LINK FROM [wms_settlement_detail_temp] where CREATEUSER='"+strUserID+"' and CORPID='"+strCompanyID+"'"+strCondition;
varsortstring=DatasetSort.Getsortstring(sort);
if(!string.IsNullOrEmpty(sortstring))
{
strSql2+=" order by "+sortstring;
}
else
{
strSql2+=" order by CUSTOMERNAME,BLNO,WMSNO,LINENUM,OUTBSNO,STARTBILLINGDATE,FEEGRADE";
stringstrSql2="SELECT GID,BLNO,CUSTOMNO,CONTRACTNO,WMSNO,OUTBSNO,CUSTOMERNAME,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSSTANDARD,GOODSGRADE,dbo.trimdate(WMSDATE) as WMSDATE,dbo.trimdate(DODATE) as DODATE,WMSDAYS,dbo.trimdate(STARTBILLINGDATE_OUT) as STARTBILLINGDATE_OUT,dbo.trimdate(ENDBILLINGDATE_OUT) as ENDBILLINGDATE_OUT,GOODSOUTFEE,GOODSPACK,GOODSPACKACTUAL,GOODSPACKPFSL,GOODSPACKSTOCK,GOODSRKSL,GOODSRKSLACTUAL,GOODSPFSL,GOODSSTOCK,CHARGEUNIT,REMARK_OUT,FEETYPE,FEEGRADE,FEESCALE,FEEPRICE,dbo.trimdate(STARTBILLINGDATE) as STARTBILLINGDATE,dbo.trimdate(ENDBILLINGDATE) as ENDBILLINGDATE,FEEDAYS,OUTFEE,[ARFEE],CREATEUSER,CREATETIME,ISMAKEOUT,MAKEOUTUSER,MAKEOUTTIME,CORPID,LINENUM,GID_LINK FROM wms_settlement_detail where CORPID='"+strCompanyID+"' and ISDELETE=0"+strCondition;//CREATEUSER='" + strUserID + "' and
varsortstring=DatasetSort.Getsortstring(sort);
if(!string.IsNullOrEmpty(sortstring))
{
strSql2+=" order by "+sortstring;
}
else
{
strSql2+=" order by CUSTOMERNAME,BLNO,WMSNO,LINENUM,OUTBSNO,STARTBILLINGDATE,FEEGRADE";
stringstrSql="SELECT newid() as GID,DUIGID,DUINO,BLNO,CUSTOMNO,CONTRACTNO,CUSTOMERNAME,GOODSNAME FROM wms_settlement_detail where CORPID='"+strCompanyID+"' and ISDELETE=0";// CREATEUSER='" + strUserID + "' and
if(!string.IsNullOrEmpty(strCondition))
{
strSql+=" and "+strCondition;
}
strSql+="group by DUIGID,DUINO,BLNO,CUSTOMNO,CONTRACTNO,CUSTOMERNAME,GOODSNAME,CREATEUSER,CORPID,ISDELETE";
stringstrSql="SELECT newid() as GID, '"+hjname+"'as CUSTOMERNAME, isnull(sum(OUTFEE),0) as OUTFEE, isnull(sum(ARFEE),0) as ARFEE FROM "+tablename+" where CORPID='"+strCompanyID+"' and ISDELETE=0 "+condition+" group by CREATEUSER,CORPID,DUIGID";//CREATEUSER='" + strUserID + "' and
stringls="select count(gid) nums from ch_fee where WMSOUTBSNO in ("+gids+") and (ISINVOICE=1 or AUDITSTATUS=1 or ORDERINVOICE<>0.00 or DEBITNO is not null or FEESTATUS<>1)";
sbool=T_ALL_DA.GetStrSQL("nums",ls);
if(sbool.Trim()=="0")
{
ls="select count(gid) nums from ch_fee_do where feeid in (select gid from ch_fee where WMSOUTBSNO in ("+gids+"))";
stringstrSql="select *,STARTBILLINGDATE_MAIN=(select top 1 STARTBILLINGDATE from wms_settlement_list where gid=wms_settlement_detail.DUIGID),ENDBILLINGDATE_MAIN=(select top 1 ENDBILLINGDATE from wms_settlement_list where gid=wms_settlement_detail.DUIGID) from wms_settlement_detail where ISDELETE=0 and DUIGID in ("+gids+")";
strSql="select count(*) from wms_settlement_detail where ISDELETE=0 and BLNO='"+dr["BLNO"].ToString().Trim()+"' and DUIGID in (select gid from wms_settlement_list where STARTBILLINGDATE>'"+dr["ENDBILLINGDATE_MAIN"].ToString().Trim()+"')";
//string ls = "select count(gid) nums from ch_fee where WMSOUTBSNO=(select top 1 GID_LINK from wms_settlement_detail where ISDELETE=0 " + strBLNOs + ") and (ISINVOICE=1 or AUDITSTATUS=1 or ORDERINVOICE<>0.00 or DEBITNO is not null or FEESTATUS<>1)";
//sbool = T_ALL_DA.GetStrSQL("nums", ls);
//if (sbool.Trim() == "0")
//{
// ls = "select count(gid) nums from ch_fee_do where feeid in (select gid from ch_fee where WMSOUTBSNO=(select top 1 GID_LINK from wms_settlement_detail where ISDELETE=0 " + strBLNOs + "))";
stringstrSql="select *,STARTBILLINGDATE_MAIN=(select top 1 STARTBILLINGDATE from wms_settlement_list where gid=wms_settlement_detail.DUIGID),ENDBILLINGDATE_MAIN=(select top 1 ENDBILLINGDATE from wms_settlement_list where gid=wms_settlement_detail.DUIGID) from wms_settlement_detail where ISDELETE=0 "+strBLNOs;
strSql="select count(*) from wms_settlement_detail where ISDELETE=0 and BLNO='"+dr["BLNO"].ToString().Trim()+"' and DUIGID in (select gid from wms_settlement_list where STARTBILLINGDATE>'"+dr["ENDBILLINGDATE_MAIN"].ToString().Trim()+"')";
strSql="update wms_settlement_date set ISDELETE=1,DELETEUSER='"+strUserID+"',DELETETIME=getdate() where 1=1"+DUIGID+" and LINKGID in (select GID_LINK from wms_settlement_detail where ISDELETE=0 "+strBLNOs+")";
strSql="insert into ch_fee(GID,BSNO,FEETYPE,FEENAME,CUSTOMERNAME,UNIT,UNITPRICE,QUANTITY,AMOUNT,EXCHANGERATE,CURRENCY,COMMISSIONRATE,FEEFRT,REMARK,ISADVANCEDPAY,ENTEROPERATOR,ENTERDATE,FEESTATUS,WMSOUTBSNO,LINENUM,[TAXRATE],[NOTAXAMOUNT],[TAX],[ORDERSETTLEMENT],[TAXUNITPRICE],[ORDERINVSETTLEMENT]) "
+"select newid() as GID,bsno=(select top 1 bsno from V_op_bill where mblno=[wms_settlement_detail].blno),1,'仓储费',CUSTOMERNAME,'单票',sum(isnull(OUTFEE,0)),1,sum(isnull(OUTFEE,0)),1,'RMB',0,'PP',((select top 1 CONVERT(char(10), STARTBILLINGDATE, 20) AS STARTBILLINGDATE from wms_settlement_detail where blno=wms_settlement_detail.blno and STARTBILLINGDATE is not null and CORPID='"+strCompanyID+"' and ISLOCK=0 and ISDELETE=0 and isnull(OUTFEE,0)<>0 and DUIGID in ("+feegids+")"+strRange+" order by STARTBILLINGDATE)+'至'+(select top 1 CONVERT(char(10), ENDBILLINGDATE, 20) AS ENDBILLINGDATE from wms_settlement_detail where blno=wms_settlement_detail.blno and ENDBILLINGDATE is not null and CORPID='"+strCompanyID+"' and ISLOCK=0 and ISDELETE=0 and isnull(OUTFEE,0)<>0 and DUIGID in ("+feegids+")"+strRange+" order by ENDBILLINGDATE desc)+'仓储结算清单'+DUINO+'”中的单票仓储费汇总'),0,'"+strUserID+"',getdate(),1,DUIGID,LINENUM=(select top 1 LINENUM=isnull((select top 1 LINENUM from ch_fee where bsno=(select top 1 bsno from v_op_bill where mblno=[wms_settlement_detail].blno) and feetype=1 order by LINENUM desc),0)+1),0,sum(isnull(OUTFEE,0)),0,0,sum(isnull(OUTFEE,0)),0"
+" from [wms_settlement_detail] where CORPID='"+strCompanyID+"' and ISLOCK=0 and ISDELETE=0 and isnull(OUTFEE,0)<>0 and DUIGID in ("+feegids+")"+strRange+" group by blno,CUSTOMERNAME,CREATEUSER,CORPID,DUINO,DUIGID";//CREATEUSER='" + strUserID + "' and
//string ls = "select count(gid) nums from ch_fee where WMSOUTBSNO in (select gid from wms_settlement_list where ISLOCK=1 and gid in(" + gids + ") " + strRange + ") and (ISINVOICE=1 or AUDITSTATUS=1 or ORDERINVOICE<>0.00 or DEBITNO is not null or FEESTATUS<>1)";
stringls="select count(gid) nums from ch_fee where WMSOUTBSNO in (select gid from wms_settlement_list where ISLOCK=1 and gid in("+gids+") "+strRange+") and (ISINVOICE=1 or ORDERINVOICE<>0.00 or DEBITNO is not null or (FEESTATUS<>1 and FEESTATUS<>6))";
sbool=T_ALL_DA.GetStrSQL("nums",ls);
if(sbool.Trim()=="0")
{
ls="select count(gid) nums from ch_fee_do where feeid in (select gid from ch_fee where WMSOUTBSNO in (select gid from wms_settlement_list where ISLOCK=1 and gid in("+gids+") "+strRange+"))";
Sqlstr="SELECT GID,FEEGRADE,FEETYPE,FEESCALE,FEEPRICE,ADDPRICE,FEEUNIT,convert(char(10),ENDBILLINGDATE,20) AS ENDBILLINGDATE,REMARK,CREATEUSER,CREATETIME,BSNO,CAPPRICE FROM wms_rate where (BSNO='"+strINBSNO+"' or BSNO in (select ASSOCIATEDNO from wms_in where gid='"+strINBSNO+"')) and FEETYPE="+strFEETYPE+" order by FEEGRADE ";
Sqlstr=String.Format("insert into [wms_settlement_detail_rate_detail_temp](GID,FEEPRICE,GOODSPFSL,OUTFEE,REMARK,CREATEUSER,CREATETIME,ASSOCIATEDNO,CUSTOMERNAME,FEETYPE,FEEGRADE,STARTBILLINGDATE,ENDBILLINGDATE,FEESCALE,FEEUNIT,MODIFIEDUSER)"
Sqlstr="SELECT GID,FEEGRADE,FEETYPE,FEESCALE,FEEPRICE,ADDPRICE,FEEUNIT,convert(char(10),ENDBILLINGDATE,20) AS ENDBILLINGDATE,REMARK,CREATEUSER,CREATETIME,BSNO,CAPPRICE FROM wms_rate where (BSNO='"+strINBSNO+"' or BSNO in (select ASSOCIATEDNO from wms_in where gid='"+strINBSNO+"')) and FEETYPE="+strFEETYPE+" order by FEEGRADE ";
Sqlstr=String.Format("insert into [wms_settlement_detail_rate_detail_temp](GID,FEEPRICE,GOODSPFSL,OUTFEE,REMARK,CREATEUSER,CREATETIME,ASSOCIATEDNO,CUSTOMERNAME,FEETYPE,FEEGRADE,STARTBILLINGDATE,ENDBILLINGDATE,FEESCALE,FEEUNIT,MODIFIEDUSER)"