varct2=MsRptPcHeadEditDAL.GetRdCount("Gid<>'"+headData.gId+"' AND MblNoSe='"+headData.MblNoSe+"' and BSTYPE='"+headData.BsType+"' and BLTYPE<>'派车分票' ");
varct2=MsRptPcHeadEditDAL.GetRdCount("Gid<>'"+headData.gId+"' AND MblNoSe='"+headData.MblNoSe+"' and BSTYPE='"+headData.BsType+"' and BLTYPE<>'派车分票' ");
strSql.Append(",CASE WHEN ISNULL(TTLINVCR,0)=0 THEN '未开票' WHEN ISNULL(TTLINVCR,0)=ISNULL(TTLCR,0) THEN '已开票' WHEN ISNULL(TTLINVCR,0)!=ISNULL(TTLCR,0) THEN '部分开票' END CRINVSTATUS ");
strSql.Append(",CASE WHEN ISNULL(TTLINVDR,0)=0 THEN '未开票' WHEN ISNULL(TTLINVDR,0)=ISNULL(TTLDR,0) THEN '已开票' WHEN ISNULL(TTLINVDR,0)!=ISNULL(TTLDR,0) THEN '部分开票' END DRINVSTATUS ");
strSql.Append(",CASE WHEN ISNULL(TTLDUIDR,0)=0 THEN '未对账' WHEN ISNULL(TTLDUIDR,0)=ISNULL(TTLDR,0) THEN '已对账' WHEN ISNULL(TTLDUIDR,0)!=ISNULL(TTLDR,0) THEN '部分对账' END DRDUISTATUS ");
strSql.Append(",CASE WHEN ISNULL(TTLDUICR,0)=0 THEN '未对账' WHEN ISNULL(TTLDUICR,0)=ISNULL(TTLCR,0) THEN '已对账' WHEN ISNULL(TTLDUICR,0)!=ISNULL(TTLCR,0) THEN '部分对账' END CRDUISTATUS ");
strSql.Append(",(SELECT TOP 1 STATUS FROM V_OP_STATUS WITH (NOLOCK) WHERE BSNO=t.GId ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS");
strSql.Append(",(select TOP 1 COLOR FROM code_op_status_detail WITH (NOLOCK) WHERE OPSTATUS = (CASE WHEN (SELECT TOP 1 [STATUS] FROM V_OP_STATUS WHERE BSNO=t.GId ORDER BY COMPTIME DESC,INPUTTIME DESC) is null THEN '接受委托' else (SELECT TOP 1[STATUS] FROM V_OP_STATUS WHERE BSNO =t.GId ORDER BY COMPTIME DESC, INPUTTIME DESC) end))AS COLOR");
strSql.Append(",t.SALECORPID,(select [NAME] from [company] where GID=t.SALECORPID) as SALECORP,DCLASS,DUNNO");
strSql.Append(" ,INVOICENO,KINDPKGS,CUSTNO,SalesName,GoodsName,PORTLOAD,DESTINATION,RtnDocStatus,RtnDocTime,ACCDATE,(CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,(CASE ISNULL(BillStatus,0) WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF ");
strSql.Append(" LEFT JOIN v_op_gain_dr_INV I ON (I.BSNO=t.GID) ");
if(ismaster!="1"&&ismaster!="2")
{
if(!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where (t.BLTYPE='派车主票' or t.BLTYPE='派车单票') AND EXISTS ( select 1 from tMsWlPcHead WHERE t.GID=tMsWlPcHead.PGID AND "+strCondition+" )");
}
else
{
//strSql.Append(" where 1=1 " );
strSql.Append(" where (t.BLTYPE='派车主票' or t.BLTYPE='派车单票') ");
}
}
else
{
if(ismaster=="2")
{
if(!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where (t.BLTYPE='派车分票' or t.BLTYPE='派车单票') AND "+strCondition);
}
else
{
//strSql.Append(" where 1=1 " );
strSql.Append(" where (t.BLTYPE='派车分票' or t.BLTYPE='派车单票') ");
strSql.Append(" order by "+sortstring.Replace("DRINVSTATUS"," CASE WHEN ISNULL(I.TTLINVDR,0)=0 THEN '未开票' ELSE CASE WHEN ISNULL(I.TTLINVDR,0)=ISNULL(I.TTLDR,0) THEN '已开票' ELSE '部分开票' END END "));
strSql.Append(" order by "+sortstring.Replace("DRDUISTATUS"," CASE WHEN ISNULL(I.TTLDUIDR,0)=0 THEN '未对账' ELSE CASE WHEN ISNULL(I.TTLDUIDR,0)=ISNULL(I.TTLDR,0) THEN '已对账' ELSE '部分对账' END END "));
varcmdDelete=db.GetSqlStringCommand("insert into op_status(ST_ID,BSNO,STATUS,ISCOMP,COMPTIME,INPUTTIME,STTYPE,COMPOP,INPUTBY) values(NEWID(),'" + bsno + "','"+ status + "',1,'" + DateTime.Now.ToString() + "','" + DateTime.Now.ToString() + "','1','" + op + "','" + op + "')");
db.ExecuteNonQuery(cmdDelete,tran);
// var cmdDelete = db.GetSqlStringCommand("insert into op_status(ST_ID,BSNO,STATUS,ISCOMP,COMPTIME,INPUTTIME,STTYPE,COMPOP,INPUTBY) values(NEWID(),'" + bsno + "','"+ status + "',1,'" + DateTime.Now.ToString() + "','" + DateTime.Now.ToString() + "','1','" + op + "','" + op + "')");
// db.ExecuteNonQuery(cmdDelete, tran);
if(status=="完结")
{
varcmdDelete=db.GetSqlStringCommand("insert into op_status(ST_ID,BSNO,STATUS,ISCOMP,COMPTIME,INPUTTIME,STTYPE,COMPOP,INPUTBY) SELECT "+
"NEWID(),GID,'"+status+"',1,'"+DateTime.Now.ToString()+"','"+DateTime.Now.ToString()+"','1','"+op+"','"+op+"' FROM tMsWlPcHead WHERE PGID='"+bsno+"' ");
db.ExecuteNonQuery(cmdDelete,tran);
}
else
{
varcmdDelete=db.GetSqlStringCommand("insert into op_status(ST_ID,BSNO,STATUS,ISCOMP,COMPTIME,INPUTTIME,STTYPE,COMPOP,INPUTBY) values(NEWID(),'"+bsno+"','"+status+"',1,'"+DateTime.Now.ToString()+"','"+DateTime.Now.ToString()+"','1','"+op+"','"+op+"')");
varsql21="DELETE FROM op_task where TASKTYPE='欠费待收款' and TASKSTATUS='未开始' and EXISTS (select 1 from v_op_bs where op_task.BSNO=v_op_bs.BSNO AND DATEDIFF([day],GETDATE(),ISNULL(v_op_bs.STLDATE,v_op_bs.ETD))>7) ";
SqlCommandcmd21=newSqlCommand(sql21,dbcon);
cmd21.ExecuteNonQuery();
varsql2="UPDATE op_task SET ISCOMPLETE=1,TASKSTATUS='已完成',COMPLETETYPE='自动',COMPLETETIME=GETDATE() where TASKTYPE='欠费待收款' and TASKSTATUS='未开始' and EXISTS (select 1 from v_op_gain_sum where op_task.BSNO=v_op_gain_sum.BSNO AND STLTTLDR=TTLDR and TTLDR<>0) ";
SqlCommandcmd2=newSqlCommand(sql2,dbcon);
cmd2.ExecuteNonQuery();
@ -185,9 +189,9 @@ namespace JobCreateFee
varstrSql=newStringBuilder();
strSql.Append("SELECT * FROM (");
strSql.Append("SELECT A.ALLOWAMOUNT,C.SHORTNAME,[dbo].[GetCustZq](C.SHORTNAME) ZQ,ISNULL((SELECT SUM((AMOUNT-SETTLEMENT)*EXCHANGERATE) FROM CH_FEE WHERE FEETYPE=1 AND CUSTOMERNAME=C.SHORTNAME),0) NOSTLAMOUNT");