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(",(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(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0)-ISNULL(DEBITAMOUNT,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)-ISNULL(DEBITAMOUNT,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)-ISNULL(DEBITAMOUNT,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)-ISNULL(DEBITAMOUNT,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)-ISNULL(DEBITAMOUNT,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)-ISNULL(DEBITAMOUNT,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("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(DEBITAMOUNT,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(DEBITAMOUNT,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.DEBITAMOUNT-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.DEBITAMOUNT-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(DEBITAMOUNT,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(DEBITAMOUNT,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("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+"')");
strSql.Append(",f.feeName,f.customerName,f.amount,f.DEBITAMOUNT,f.amount-f.Settlement as balamount,f.currency,f.exChangerate,f.notaxamount,f.Remark,f.UNITPRICE");
varcmdinsertdetail=db.GetSqlStringCommand("insert into ch_dui_detail(DUINO,BSNO,CH_ID,DEBITAMOUNT,ISDEBIT) values (@DUINO,@BSNO,@CH_ID,@DEBITAMOUNT,@ISDEBIT)");
varcmdupdatechfee=db.GetSqlStringCommand("update ch_fee set DEBITAMOUNT=isnull(DEBITAMOUNT,0)+@DEBITAMOUNT where GID=@CH_ID");
custstr=" AND (CUSTOMERNAME='"+duicust+"' or exists (select 1 from info_client where f.CUSTOMERNAME=info_client.SHORTNAME AND PCORPNAME='"+custgroup+"'))";
varcmdinsertdetail=db.GetSqlStringCommand("insert ch_dui_detail(DUINO,BSNO,CH_ID,DEBITAMOUNT) SELECT @DUINO,BSNO,GID,AMOUNT-ISNULL(DEBITAMOUNT,0) from ch_fee F "
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='"+username+"' OR b.SALE='"+username+"' OR b.DOC='"+username+"' OR b.CUSTSERVICE='"+username+"')";
}
elseif(visiblerange=="3")
{
str=" (b.OP='"+username+"' OR b.SALE='"+username+"' OR b.DOC='"+username+"' OR b.CUSTSERVICE='"+username+"' )";
}
elseif(visiblerange=="2")
{
varrangeDa=newRangeDA();
vardeptname=rangeDa.GetDEPTNAME(userid);
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+"'))"
+" )";
}
elseif(visiblerange=="1")
{
str=" (b.OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='"+companyid+"'))"
+" OR b.SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='"+companyid+"'))"
+" OR b.DOC in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='"+companyid+"'))"
+" OR b.CUSTSERVICE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='"+companyid+"'))"
+" )";
}
elseif(visiblerange=="5")
{
if(tb=="index")
{
varuserstr=newStringBuilder();
userstr.Append(" select COMPANYID from user_authority_range_company where userid='"+userid+"' and AUTHORITYID='"+AUTHORITYID+"' and VISIBLERANGE=1");
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");