strSql.Append(",EMAIL,GOODSNAME,(Select GOODNAME from code_goods_inv where GID=ch_fee_invoiceapplication_detail.GOODSNAME) AS GOODSNAMEREF");
strSql.Append(",(SELECT TOP 1 INVOICENO FROM ch_fee_invoice WHERE BILLNO = ch_fee_invoiceapplication_detail.INVBILLNO) INVOICENO ");
strSql.Append(",(SELECT TOP 1 INVOICENO FROM ch_fee_invoice WHERE BILLNO = ch_fee_invoiceapplication_detail.INVBILLNO) INVOICENO,INVOICELINE ");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=80003 and EnumValueID=ch_fee_invoiceapplication_detail.INVOICELINE) as INVOICELINEREF");
strSql.Append(" FROM ch_fee_invoiceapplication_detail ");
@"insert into ch_fee_invoiceapplication_detail (GID,BILLSTATUS,LINKGID,CUSTOMERNAME,INVOICECUSTNAME,AMOUNT,CURRENCY,REMARK,CUSTRATENO,CUSTADDRTEL,CUSTBANK,CUSTTEL,CUSTADDR,EMAIL,GOODSNAME)
@"insert into ch_fee_invoiceapplication_detail (GID,BILLSTATUS,LINKGID,CUSTOMERNAME,INVOICECUSTNAME,AMOUNT,CURRENCY,REMARK,CUSTRATENO,CUSTADDRTEL,CUSTBANK,CUSTTEL,CUSTADDR,EMAIL,GOODSNAME,INVOICELINE)
@"update ch_fee_invoiceapplication_detail set CUSTOMERNAME=@CUSTOMERNAME,INVOICECUSTNAME=@INVOICECUSTNAME,AMOUNT=@AMOUNT,CURRENCY=@CURRENCY,REMARK=@REMARK,CUSTRATENO=@CUSTRATENO
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN v_op_gain_cust_sum g ON (g.BSNO=B.BSNO and g.CUSTOMERNAME=f.CUSTOMERNAME) ");
strSql.Append(" left join ch_dui_detail d on (d.CH_ID=f.GID) WHERE D.DUINO='"+duino+"' AND ISNULL(D.INVNO,'')='' ");
strSql.Append(" and f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
strSql.Append(" and f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN v_op_gain_cust_sum g ON (g.BSNO=B.BSNO and g.CUSTOMERNAME=f.CUSTOMERNAME) ");
strSql.Append(" where f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
strSql.Append(" where f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" left join ch_dui_detail d on (d.CH_ID=f.GID) WHERE D.DUINO='"+duino+"' AND ISNULL(D.INVNO,'')='' ");
strSql.Append(" and f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
strSql.Append(" and f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
strSql.Append("SELECT COUNT(*) FROM (select b.BSNO,f.CUSTOMERNAME ");
strSql.Append(" FROM CH_FEE f ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" where f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
strSql.Append(" where f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
strSql.Append(",(select ShowName from [user] where GID=f.EnteroPerator) as OpName");
strSql.Append(",f.INPUTMODE,f.UNIT,f.UNITPRICE,f.QUANTITY,d.DEBITAMOUNT from ch_fee f ");
strSql.Append(" left join ch_dui_detail d on (d.CH_ID=f.GID) WHERE D.DUINO='"+duino+"' AND ISNULL(D.INVNO,'')='' ");
strSql.Append(" and f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
strSql.Append(" and f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
strSql.Append(",f.feeName,f.customerName,f.amount,f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) as balamount,f.currency,f.exChangerate,f.AccTaxRate,f.remark");
strSql.Append(",(select ShowName from [user] where GID=f.EnteroPerator) as OpName");
strSql.Append(",f.INPUTMODE,f.UNIT,f.UNITPRICE,f.QUANTITY,0 DEBITAMOUNT from ch_fee f ");
strSql.Append(" where f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
strSql.Append(" where f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
@"UPDATE CH_FEE SET ORDERAMOUNT=ISNULL(ORDERAMOUNT,0)+@ORDERAMOUNT,ORDERINVOICE=isnull(ORDERINVOICE,0)+@ORDERAMOUNT WHERE GID=@GID AND ((AMOUNT>=0 AND ((AMOUNT-SETTLEMENT)-@ORDERAMOUNT2)>=0)
@"UPDATE CH_FEE SET ORDERAMOUNT=ISNULL(ORDERAMOUNT,0)+@ORDERAMOUNT,ORDERINVOICE=isnull(ORDERINVOICE,0)+@ORDERAMOUNT WHERE GID=@GID AND ((AMOUNT>=0 AND ((AMOUNT-SETTLEMENT)-@ORDERAMOUNT2)>=0)
varcmdupdate=db.GetSqlStringCommand("update ch_fee set ORDERAMOUNT=isnull((select sum(Amount) from ch_fee_do where GID<>@FEEDOID and feeid=ch_fee.gid and CATEGORY in(2,5) ),0) where GID=@GID");
if(headdata.SETTLEMODE==3){
cmdupdate=db.GetSqlStringCommand("update ch_fee set ORDERAMOUNT=isnull((select sum(Amount) from ch_fee_do where GID<>@FEEDOID and feeid=ch_fee.gid and CATEGORY in(2,5) ),0),ORDERINVOICE=ORDERINVOICE-@ORDERINVOICE where GID=@GID");
}
varcmddelete=db.GetSqlStringCommand("delete from ch_fee_do where GID=@FEEDOID");
tempstr+=GetSpaceStr(bill.CONTRACTNO,10);//10//Service Contract #//C//X(10)//31//40//Applicable to US shipments only//"mandtory for US shpts---Service Contract Nbr/TAA Nbr"//美国线的S/C,TAA//服务合同#//只适用于美国装运
tempstr+=GetSpaceStr(bill.SERVICECONTRACTNO,10);//10//Service Contract #//C//X(10)//31//40//Applicable to US shipments only//"mandtory for US shpts---Service Contract Nbr/TAA Nbr"//美国线的S/C,TAA//服务合同#//只适用于美国装运
}
else
{
tempstr+=GetSpaceStr(bill.CONTRACTNO,10);//10//Service Contract #//C//X(10)//31//40//Applicable to US shipments only//"mandtory for US shpts---Service Contract Nbr/TAA Nbr"//美国线的S/C,TAA//服务合同#//只适用于美国装运
tempstr+=GetSpaceStr(bill.SERVICECONTRACTNO,10);//10//Service Contract #//C//X(10)//31//40//Applicable to US shipments only//"mandtory for US shpts---Service Contract Nbr/TAA Nbr"//美国线的S/C,TAA//服务合同#//只适用于美国装运
}
tempstr+=GetSpaceStr("",5);//11//Prepaid at (Port code)//M//X(5)//41//45//Ocean Freight Payment Location//预付(港码)//海运付款地点
tempstr+=GetSpaceStr("",5);//12//Payable at (Port Code)//M//X(5)//46//50//1st Collect Charge Payment Location//按(港口代码)支付//第一收取缴费地点