strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97006 and EnumValueID=ch_dui.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",SUM(f.RMBDR) AS RMBDR,SUM(f.RMBCR) RMBCR,SUM(f.RMBDR-f.STLRMBDR) AS BALRMBDR,SUM(f.RMBCR-f.STLRMBCR) AS BALRMBCR,");
strSql.Append("SUM(f.USDDR) AS USDDR,SUM(f.USDCR) USDCR");
strSql.Append(",SUM(f.USDDR-f.STLUSDDR) AS BALUSDDR,SUM(f.USDCR-f.STLUSDCR) AS BALUSDCR,SUM(f.OTDR) OTDR,SUM(f.OTCR) OTCR,");
strSql.Append("SUM(f.OTDR-f.STLOTDR) AS BALOTDR,SUM(f.OTCR-f.STLOTCR) as BALOTCR");
strSql.Append(",SUM(f.TTLDR) AS TTLDR,SUM(f.TTLCR) AS TTLCR,SUM(f.TTLDR-f.STLTTLDR) AS BALTTLDR,SUM(f.TTLCR-f.STLTTLCR) as BALTTLCR,SUM(f.NOINVOICE) as NOINVOICE");
strSql.Append(" from ch_dui ");
strSql.Append(" left join v_dui_allfee_sum f on (f.DEBITNO=ch_dui.DUINO)");
if(!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where "+strCondition);
}
strSql.Append("GROUP BY DUINO,CUSTNAME");
strSql.Append(",DUIDATE");
strSql.Append(",OP,DUINAME");
strSql.Append(",DM_ID,REMARKS,DC,ISNOSTL,BILLSTATUS,ISNOTAX) as v ");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97006 and EnumValueID=ch_dui.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",SUM(f.RMBDR) AS RMBDR,SUM(f.RMBCR) RMBCR,SUM(f.RMBDR-f.STLRMBDR) AS BALRMBDR,SUM(f.RMBCR-f.STLRMBCR) AS BALRMBCR,");
strSql.Append("SUM(f.USDDR) AS USDDR,SUM(f.USDCR) USDCR");
strSql.Append(",SUM(f.USDDR-f.STLUSDDR) AS BALUSDDR,SUM(f.USDCR-f.STLUSDCR) AS BALUSDCR,SUM(f.OTDR) OTDR,SUM(f.OTCR) OTCR,");
strSql.Append("SUM(f.OTDR-f.STLOTDR) AS BALOTDR,SUM(f.OTCR-f.STLOTCR) as BALOTCR");
strSql.Append(",SUM(f.TTLDR) AS TTLDR,SUM(f.TTLCR) AS TTLCR,SUM(f.TTLDR-f.STLTTLDR) AS BALTTLDR,SUM(f.TTLCR-f.STLTTLCR) as BALTTLCR,SUM(f.NOINVOICE) as NOINVOICE");
strSql.Append(" from ch_dui ");
strSql.Append(" left join v_dui_allfee_sum f on (f.DEBITNO=ch_dui.DUINO)");
strSql.Append(",b.ACCDATE,b.SALE,b.OP,b.CNTRTOTAL,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
strSql.Append(",f.RMBDR,f.RMBCR,f.RMBDR-f.STLRMBDR AS BALRMBDR,f.RMBCR-f.STLRMBCR AS BALRMBCR,f.USDDR,f.USDCR");
strSql.Append(",f.USDDR-f.STLUSDDR AS BALUSDDR,f.USDCR-f.STLUSDCR AS BALUSDCR,f.OTDR,f.OTCR,f.OTDR-f.STLOTDR AS BALOTDR,f.OTCR-f.STLOTCR as BALOTCR");
strSql.Append(",f.TTLDR,f.TTLCR,f.TTLDR-f.STLTTLDR AS BALTTLDR,f.TTLCR-f.STLTTLCR as BALTTLCR,f.RMBORDERINVOICEDR,f.USDORDERINVOICEDR,f.RMBORDERAMOUNTCR,f.USDORDERAMOUNTCR");
strSql.Append(" from ch_dui_bill d ");
strSql.Append(" left join v_op_bill b on (b.BSNO=d.BSNO)");
strSql.Append(" left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO)");
if(!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where "+strCondition);
}
strSql.Append(" ) as V ");
strSql.Append(@")as t ");
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ",start,start+limit));//
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR");
strSql.Append(" FROM CH_FEE f ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
if(!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where "+strCondition);
}
strSql.Append(" GROUP BY b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR");
strSql.Append(" FROM CH_FEE F ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
if(!string.IsNullOrEmpty(strduiCondition))
{
strSql.Append(" where F.ISDEBIT=1 AND "+strduiCondition);
}
else{
strSql.Append(" where F.ISDEBIT=1 ");
}
strSql.Append(" GROUP BY F.DEBITNO,b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
strSql.Append("SELECT A.CURRENCY,SUM(A.DR) DR,SUM(A.CR) CR,SUM(A.NODR) NODR,SUM(A.NOCR) NOCR FROM ");
strSql.Append("(SELECT CURRENCY,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS DR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS CR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NODR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NOCR from ch_fee F WHERE "+feesql+" AND (ISDEBIT=0 or ISDEBIT IS NULL) ");
strSql.Append(" GROUP BY CURRENCY");
strSql.Append(" UNION ");
strSql.Append("SELECT CURRENCY,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS DR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS CR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NODR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NOCR from v_dui_fee F WHERE "+duisql+"and GID NOT IN (SELECT GID from v_dui_fee where duino='"+duino+"')");
custstr=" AND (CUSTOMERNAME='"+duicust+"' or exists (select 1 from info_client where f.CUSTOMERNAME=info_client.SHORTNAME AND PCORPNAME='"+custgroup+"'))";
}
//feesql = feesql.Replace("", custstr);
varcmdfee=db.GetSqlStringCommand("update ch_fee set ISDEBIT=1,DEBITNO=@DUINO from ch_fee f WHERE "+feesql+custstr+" AND (ISDEBIT=0 or ISDEBIT IS NULL) ");
//var cmd = db.GetSqlStringCommand("insert ch_dui_bill(DUINO,BSNO) SELECT @DUINO,BSNO from v_op_bill where EXISTS (select 1 FROM ch_fee where DEBITNO=@DUINO and ch_fee.BSNO=v_op_bill.BSNO)"
//+ " and not EXISTS (select 1 from ch_dui_bill where duino=@DUINO2 and ch_dui_bill.BSNO=v_op_bill.BSNO)");
//var feelist = MsChFeeDAL.MsChFeeDAL.GetAllDataList(" exists(select 1 from V_dui_fee where duino='" + duino + "') ");
//var nofeelist = MsChFeeDAL.MsChFeeDAL.GetAllDataList(" exists(select 1 from V_dui_fee where duino='" + duino + "') ");
//var makeNewDUINO = db.GetSqlStringCommand("update ch_fee set DEBITNO=(select min(duino) from ch_dui_detail where CH_ID=ch_fee.GID and DUINO<>ch_fee.DEBITNO) where EXISTS(select 1 from v_dui_fee where gid=ch_fee.gid and DUINO='" + duino + "') and DEBITNO='" + duino + "'");
varsqlstr=" SELECT d.DB_ID,d.DUINO,b.*,dbo.GetOtherFee(b.bsno,d.DUINO,u.DM_ID,1,'"+headData.ISNOSTL+"') as OTHERDRFEESTR,dbo.GetOtherFee(b.bsno,d.DUINO,u.DM_ID,2,'"+headData.ISNOSTL+"') as OTHERCRFEESTR"
+",f.RMBDR,f.RMBCR,f.RMBDR-f.STLRMBDR AS BALRMBDR,f.RMBCR-f.STLRMBCR AS BALRMBCR,f.USDDR,f.USDCR"
+",f.USDDR-f.STLUSDDR AS BALUSDDR,f.USDCR-f.STLUSDCR AS BALUSDCR,f.OTDR,f.OTCR,f.OTDR-f.STLOTDR AS BALOTDR,f.OTCR-f.STLOTCR as BALOTCR"
fieldnamesumstr=fieldnamesumstr+",isnull(SUM(CASE FEENAME WHEN '"+Convert.ToString(reader["FEENAME"])+"' THEN (CASE FEETYPE WHEN "+Convert.ToString(reader["FEETYPE"])+" THEN "
+"(CASE CURRENCY WHEN '"+Convert.ToString(reader["CURRENCY"])+"' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS "+fieldname;
}
reader.Close();
}
sqlstr=sqlstr+fieldnamestr+" from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) "
+"left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join ("+fieldnamesumstr
+" from v_dui_fee where DUINO='"+headData.DUINO+"'group by bsno) as m on (m.BSNO=d.bsno) left join ("
+" SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) "
+" ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END)"
+" ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END) "
+" ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(BALAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR,"
+" isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(BALAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR"
+" from v_dui_fee f where f.DUINO='"+headData.DUINO+"' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='"+headData.DM_ID+"' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)"
+" group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='"+headData.DUINO+"'";
fieldnamesumstr=fieldnamesumstr+",isnull(SUM(CASE FEENAME WHEN '"+Convert.ToString(reader["FEENAME"])+"' THEN (CASE FEETYPE WHEN "+Convert.ToString(reader["FEETYPE"])+" THEN "
+"(CASE CURRENCY WHEN '"+Convert.ToString(reader["CURRENCY"])+"' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS "+fieldname;
}
reader.Close();
}
sqlstr=sqlstr+fieldnamestr+" from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) "
+"left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join ("+fieldnamesumstr
+" from v_dui_fee where DUINO='"+headData.DUINO+"'group by bsno) as m on (m.BSNO=d.bsno) left join ("
+" SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) "
+" ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)"
+" ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END) "
+" ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR,"
+" isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR"
+" from v_dui_fee f where f.DUINO='"+headData.DUINO+"' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='"+headData.DM_ID+"' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)"
+" group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='"+headData.DUINO+"'";
}
varsortSql=newStringBuilder();
sortSql.Append("Select FIELDNAME,SORTTYPE ");
sortSql.Append(" from code_dui_format_sort ");
sortSql.Append(" where DM_ID='"+headData.DM_ID+"'");
varsqlstr=" SELECT d.DB_ID,d.DUINO,b.*,dbo.GetNoTaxOtherFee(b.bsno,d.DUINO,u.DM_ID,1,'"+headData.ISNOSTL+"') as OTHERDRFEESTR,dbo.GetNoTaxOtherFee(b.bsno,d.DUINO,u.DM_ID,2,'"+headData.ISNOSTL+"') as OTHERCRFEESTR"
+",f.NOTAXRMBDR RMBDR,f.NOTAXRMBCR RMBCR,f.RMBDR-f.STLRMBDR AS BALRMBDR,f.RMBCR-f.STLRMBCR AS BALRMBCR,f.NOTAXUSDDR USDDR,f.NOTAXUSDCR USDCR"
+",f.USDDR-f.STLUSDDR AS BALUSDDR,f.USDCR-f.STLUSDCR AS BALUSDCR,f.NOTAXOTDR OTDR,f.NOTAXOTCR OTCR,f.OTDR-f.STLOTDR AS BALOTDR,f.OTCR-f.STLOTCR as BALOTCR"
fieldnamesumstr=fieldnamesumstr+",isnull(SUM(CASE FEENAME WHEN '"+Convert.ToString(reader["FEENAME"])+"' THEN (CASE FEETYPE WHEN "+Convert.ToString(reader["FEETYPE"])+" THEN "
+"(CASE CURRENCY WHEN '"+Convert.ToString(reader["CURRENCY"])+"' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS "+fieldname;
}
reader.Close();
}
sqlstr=sqlstr+fieldnamestr+" from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) "
+"left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join ("+fieldnamesumstr
+" from v_dui_fee where DUINO='"+headData.DUINO+"'group by bsno) as m on (m.BSNO=d.bsno) left join ("
+" SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) "
+" ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END)"
+" ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END) "
+" ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(BALAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR,"
+" isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(BALAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR"
+" from v_dui_fee f where f.DUINO='"+headData.DUINO+"' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='"+headData.DM_ID+"' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)"
+" group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='"+headData.DUINO+"'";
fieldnamesumstr=fieldnamesumstr+",isnull(SUM(CASE FEENAME WHEN '"+Convert.ToString(reader["FEENAME"])+"' THEN (CASE FEETYPE WHEN "+Convert.ToString(reader["FEETYPE"])+" THEN "
+"(CASE CURRENCY WHEN '"+Convert.ToString(reader["CURRENCY"])+"' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS "+fieldname;
}
reader.Close();
}
sqlstr=sqlstr+fieldnamestr+" from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) "
+"left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join ("+fieldnamesumstr
+" from v_dui_fee where DUINO='"+headData.DUINO+"'group by bsno) as m on (m.BSNO=d.bsno) left join ("
+" SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) "
+" ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END)"
+" ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END) "
+" ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END)"
+" ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(NOTAXAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR,"
+" isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(NOTAXAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR"
+" from v_dui_fee f where f.DUINO='"+headData.DUINO+"' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='"+headData.DM_ID+"' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)"
+" group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='"+headData.DUINO+"'";
}
varsortSql=newStringBuilder();
sortSql.Append("Select FIELDNAME,SORTTYPE ");
sortSql.Append(" from code_dui_format_sort ");
sortSql.Append(" where DM_ID='"+headData.DM_ID+"'");
//str = " (b.OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"
//+ " OR b.SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"
//+ " OR b.DOC in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"
//+ " OR b.CUSTSERVICE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"
//+ " )";
vardeptid=rangeDa.GetDEPTGID(userid);
str=$" exists(select 1 from vw_user where deptgid='{deptid}' and SHOWNAME in(B.OP,B.SALE,B.CUSTSERVICE,B.DOC)) ";
str=" (B.Corpid='"+Convert.ToString(reader["COMPANYID"])+"' or B.SALECORPID='"+Convert.ToString(reader["COMPANYID"])+"' ";
}
else
{
str=str+" or B.Corpid='"+Convert.ToString(reader["COMPANYID"])+"' or B.SALECORPID='"+Convert.ToString(reader["COMPANYID"])+"'";
};
}
str=str+")";
reader.Close();
}
}
else
{
str=" (UPPER(B.Corpid)='"+companyid+"' or B.SALECORPID='"+companyid+"') ";
}
}
elseif(visiblerange=="6")
{
if(tb=="index")
{
str=" EXISTS (select 1 from user_authority_range_op P left join [user] u on (u.GID=P.OPID) where (B.OP=U.SHOWNAME OR B.SALE=U.SHOWNAME OR B.CUSTSERVICE=U.SHOWNAME OR B.DOC=U.SHOWNAME OR B.FRCUSTSERVICE=U.SHOWNAME OR B.INPUTBY=U.SHOWNAME) AND P.userid='"+userid+"' and P.AUTHORITYID='"+AUTHORITYID+"' and P.VISIBLERANGE=1) ";
}
else
{
str=" (UPPER(B.Corpid)='"+companyid+"' or B.SALECORPID='"+companyid+"') ";
str=" (OP='"+username/*+ "' OR INPUTBY='" + username*/+"')";
}
elseif(visiblerange=="3")
{
str=" (OP='"+username/*+ "' OR INPUTBY='" + username*/+"')";
}
elseif(visiblerange=="2")
{
varrangeDa=newRangeDA();
vardeptname=rangeDa.GetDEPTNAME(userid);
str=" (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID=(select GID from [company] where codename='"+companyid+"')) and GID in (select userid from user_baseinfo where DEPTNAME='"+deptname+"')))";
//+ " OR INPUTBY in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')))";
}
elseif(visiblerange=="1")
{
str=" (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID=(select GID from [company] where codename='"+companyid+"'))))";
//+ " OR INPUTBY in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "')))";
}
elseif(visiblerange=="5")
{
varuserstr=newStringBuilder();
userstr.Append(" select COMPANYID from user_authority_range_company where userid='"+userid+"' and AUTHORITYID='"+AUTHORITYID+"' and VISIBLERANGE=1");
str=str+" or COMPANYID='"+Convert.ToString(reader["COMPANYID"])+"'";
};
}
str=str+")";
reader.Close();
}
}
elseif(visiblerange=="6")
{
varuserstr=newStringBuilder();
userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='"+userid+"' and AUTHORITYID='"+AUTHORITYID+"' and VISIBLERANGE=1");