|
|
|
|
using System;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using DSWeb.Areas.TruckMng.Models.RPT_ly;
|
|
|
|
|
using DSWeb.Areas.TruckMng.Models.RPT_zb_lrbb;
|
|
|
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
|
|
|
|
|
|
|
|
namespace DSWeb.Areas.TruckMng.DAL.RPT_ly
|
|
|
|
|
{
|
|
|
|
|
public partial class RPT_lyDAL
|
|
|
|
|
{
|
|
|
|
|
#region Inquery DataList
|
|
|
|
|
|
|
|
|
|
static public List<RPT_lymb> GetDataList(string strCondition)
|
|
|
|
|
{
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
strSql.Append("select X.bstype , ");
|
|
|
|
|
strSql.Append("sum(case when LEFT(Y.ContainerType,2) in ('40','45') then Y.ContainerQty else 0 end) as C40, ");
|
|
|
|
|
strSql.Append("sum(case when LEFT(Y.ContainerType,2) in ('20') then Y.ContainerQty else 0 end) as C20, ");
|
|
|
|
|
strSql.Append("X.CUSTOMERNAME , ");
|
|
|
|
|
strSql.Append("sum(X.zong) as 'zong', sum(X.lyf) as 'lyf', sum(X.zf) as 'zf' ");
|
|
|
|
|
strSql.Append("from (select M.BillNo, case M.bstype when 2 then '空箱' else '重箱' end as bstype, ");
|
|
|
|
|
strSql.Append("M.FEETYPE,M.CUSTOMERNAME, ");
|
|
|
|
|
strSql.Append("N.CustLikeManName as ContactName,N.CustDate,N.MblNo,N.VoyVeg, ");
|
|
|
|
|
strSql.Append("SUM(M.lyf+M.zf) as zong, SUM(M.lyf) as lyf,SUM(M.zf) as zf, ");
|
|
|
|
|
strSql.Append("N.Gid,N.SendYardName,N.DstArea ");
|
|
|
|
|
strSql.Append("from ( select bs.BillNo,A.bstype,B.FeeType, ");
|
|
|
|
|
strSql.Append(" bs.CustName as CustomerName, ");
|
|
|
|
|
strSql.Append(" case B.feename when '陆运费' then B.Amount else 0 end as lyf, ");
|
|
|
|
|
strSql.Append(" case B.feename when '陆运费' then 0 else B.Amount end as zf ");
|
|
|
|
|
strSql.Append(" from tMsWlPcHead A ");
|
|
|
|
|
strSql.Append(" left join ch_fee b on b.bsno = a.gid ");
|
|
|
|
|
strSql.Append(" left join code_fee C on B.FEENAME = C.name ");
|
|
|
|
|
strSql.Append(" left join tMsWlBsHead bs on bs.billno = A.refbillno ");
|
|
|
|
|
strSql.Append(" where A.Gid=B.BsNo and B.FeeStatus in (0,8) ");
|
|
|
|
|
strSql.Append(" ) M inner join tMsWlBsHead N on M.BillNo=N.BillNo ");
|
|
|
|
|
|
|
|
|
|
// where N.CustDate between '2013-06-27' and '2013-07-26'
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
|
|
{
|
|
|
|
|
strSql.Append(" where " + strCondition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strSql.Append(" group by M.BillNo,M.bstype,M.FEETYPE,M.CUSTOMERNAME,N.CustDate,N.MblNo,N.VoyVeg,N.Gid,N.SendYardName,N.DstArea,N.CustLikeManName ");
|
|
|
|
|
strSql.Append(") X left join tMsWlBsCtn Y on Y.BillNo=X.GId ");
|
|
|
|
|
strSql.Append("group by X.bstype,X.CUSTOMERNAME ");
|
|
|
|
|
strSql.Append("order by X.CUSTOMERNAME ");
|
|
|
|
|
return SetData(strSql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public RPT_lymb GetData(string condition)
|
|
|
|
|
{
|
|
|
|
|
var list = GetDataList(condition);
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
return list[0];
|
|
|
|
|
|
|
|
|
|
return new RPT_lymb();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<RPT_lymb> SetData(StringBuilder strSql)
|
|
|
|
|
{
|
|
|
|
|
var headList = new List<RPT_lymb>();
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
RPT_lymb data = new RPT_lymb();
|
|
|
|
|
#region Set DB data to Object
|
|
|
|
|
|
|
|
|
|
data.bstype = Convert.ToString(reader["bstype"]);
|
|
|
|
|
data.C20 = Convert.ToString(reader["C20"]);
|
|
|
|
|
data.C40 = Convert.ToString(reader["C40"]);
|
|
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
|
|
data.zong = Convert.ToString(reader["zong"]);
|
|
|
|
|
data.lyf = Convert.ToString(reader["lyf"]);
|
|
|
|
|
data.zf = Convert.ToString(reader["zf"]);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
headList.Add(data);
|
|
|
|
|
}
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
return headList;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 参照部分
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace DSWeb.Areas.TruckMng.DAL.RPT_zb_lrbb
|
|
|
|
|
{
|
|
|
|
|
public partial class RPT_zb_lrbbDAL
|
|
|
|
|
{
|
|
|
|
|
#region Inquery DataList
|
|
|
|
|
|
|
|
|
|
static public List<RPT_zb_lrbbmb> GetDataList(string strCondition)
|
|
|
|
|
{
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
/*
|
|
|
|
|
strSql.Append("select identity(int,1,1) id,* into #tt from (select ");
|
|
|
|
|
strSql.Append("mblno=case when grouping(tt.billno)=0 then mblno else '' end, ");
|
|
|
|
|
strSql.Append("custdate=case when grouping(tt.billno)=0 then custdate else '' end, ");
|
|
|
|
|
strSql.Append("custname=case when grouping(tt.billno)=0 then custname else '' end, ");
|
|
|
|
|
strSql.Append("containernos=case when grouping(tt.billno)=0 then containernos else '' end, ");
|
|
|
|
|
strSql.Append("username=case when grouping(tt.username)=0 then username else '' end, ");
|
|
|
|
|
strSql.Append("detination=case when grouping(tt.detination)=0 then detination else '' end, ");
|
|
|
|
|
strSql.Append("billno=case when grouping(tt.billno)=0 and grouping(custname)=0 and grouping(mblno)=0 then tt.billno ");
|
|
|
|
|
strSql.Append(" when grouping(tt.billno)=1 and grouping(custname)=0 and grouping(mblno)=1 then '小计' ");
|
|
|
|
|
strSql.Append(" when grouping(tt.billno)=1 and grouping(custname)=1 then '合计' else '' end, ");
|
|
|
|
|
strSql.Append("ys=sum(ys),yf=sum(yf),lr=sum(ys-yf), ");
|
|
|
|
|
strSql.Append("lrl=case when grouping(tt.billno)=1 and grouping(custname)=1 and sum(ys)<>0 then ");
|
|
|
|
|
strSql.Append(" convert(varchar(50),(sum(ys-yf)/sum(ys))*100)+'%' else '' end ");
|
|
|
|
|
strSql.Append("from ( ");
|
|
|
|
|
strSql.Append("(select h.billno,h.custname,h.custdate,h.mblno,h.containernos,f.amount as ys,0 as yf ");
|
|
|
|
|
strSql.Append(",h.username,h.detination ");
|
|
|
|
|
strSql.Append("from tMsWlBsHead h ");
|
|
|
|
|
strSql.Append("left join ch_fee f on h.gid=f.bsno ");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
|
|
{strSql.Append(" where " + strCondition);}
|
|
|
|
|
|
|
|
|
|
strSql.Append(")union all ");
|
|
|
|
|
strSql.Append("(select h.billno,h.custname,h.custdate,h.mblno,h.containernos,0 as ys,f.amount as yf ");
|
|
|
|
|
strSql.Append(",h.username,h.detination ");
|
|
|
|
|
strSql.Append("from tmswlpchead p ");
|
|
|
|
|
strSql.Append("left join tmswlbshead h on h.billno=p.refbillno ");
|
|
|
|
|
strSql.Append("left join ch_fee f on f.bsno=p.gid ");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
|
|
{ strSql.Append(" where " + strCondition); }
|
|
|
|
|
|
|
|
|
|
strSql.Append("))tt ");
|
|
|
|
|
// strSql.Append("where customername is not null ");
|
|
|
|
|
strSql.Append("group by ");
|
|
|
|
|
strSql.Append("tt.custname,tt.billno,tt.mblno,tt.custdate ");
|
|
|
|
|
strSql.Append(",tt.containernos,tt.username,tt.detination ");
|
|
|
|
|
strSql.Append("with rollup ");
|
|
|
|
|
strSql.Append(") t2 ");
|
|
|
|
|
strSql.Append("where billno<>'' and custdate is not null ");
|
|
|
|
|
strSql.Append("and containernos is not null ");
|
|
|
|
|
strSql.Append("and username is not null ");
|
|
|
|
|
strSql.Append("and ((username<>'' and containernos<>'')or (username='' and containernos='')) ");
|
|
|
|
|
strSql.Append("and ((detination<>'' and containernos<>'')or (detination='' and containernos='')) ");
|
|
|
|
|
strSql.Append("select * from #tt ");
|
|
|
|
|
strSql.Append("drop table #tt ");
|
|
|
|
|
*/
|
|
|
|
|
strSql.Append("select p.billno,p.VoyVeg,h.custname,h.custdate,h.mblno,h.containernos,sum(case when f.feetype=1 then f.amount else 0 end) as ys,sum(case when f.feetype=2 then f.amount else 0 end) as yf ");
|
|
|
|
|
strSql.Append(",sum((case when f.feetype=1 then f.amount else 0 end)-(case when f.feetype=2 then f.amount else 0 end)) as lr,h.username,h.detination,dbo.trimdate(p.ExpDate) ExpDate,p.ContainerType,(select CtnName from vMsTruckCtn where CtnCode=p.ContainerType) as ContainerType_Ref,p.ContainerNo ");
|
|
|
|
|
strSql.Append("from tmswlpchead p ");
|
|
|
|
|
strSql.Append("left join tmswlbshead h on h.billno=p.refbillno ");
|
|
|
|
|
strSql.Append("left join ch_fee f on f.bsno=p.gid ");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
|
|
{ strSql.Append(" where " + strCondition); }
|
|
|
|
|
|
|
|
|
|
strSql.Append("group by ");
|
|
|
|
|
strSql.Append("p.billno,p.VoyVeg,h.custname,h.custdate,h.mblno ");
|
|
|
|
|
strSql.Append(",h.containernos,h.username,h.detination,p.ExpDate,p.ContainerType,p.ContainerNo ");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return SetData(strSql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public RPT_zb_lrbbmb GetData(string condition)
|
|
|
|
|
{
|
|
|
|
|
var list = GetDataList(condition);
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
return list[0];
|
|
|
|
|
|
|
|
|
|
return new RPT_zb_lrbbmb();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<RPT_zb_lrbbmb> SetData(StringBuilder strSql)
|
|
|
|
|
{
|
|
|
|
|
var headList = new List<RPT_zb_lrbbmb>();
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
RPT_zb_lrbbmb data = new RPT_zb_lrbbmb();
|
|
|
|
|
#region Set DB data to Object
|
|
|
|
|
//data.id = Convert.ToDecimal(reader["id"]);
|
|
|
|
|
data.mblno = Convert.ToString(reader["mblno"]);
|
|
|
|
|
data.custdate = Convert.ToString(reader["custdate"]);
|
|
|
|
|
data.ExpDate = Convert.ToString(reader["ExpDate"]);
|
|
|
|
|
data.custname = Convert.ToString(reader["custname"]);
|
|
|
|
|
data.ContainerType = Convert.ToString(reader["ContainerType_Ref"]);
|
|
|
|
|
data.ContainerNo = Convert.ToString(reader["ContainerNo"]);
|
|
|
|
|
data.username = Convert.ToString(reader["username"]);
|
|
|
|
|
data.detination = Convert.ToString(reader["detination"]);
|
|
|
|
|
data.billno = Convert.ToString(reader["billno"]);
|
|
|
|
|
data.VoyVeg = Convert.ToString(reader["VoyVeg"]);
|
|
|
|
|
data.ys = Convert.ToString(reader["ys"]);
|
|
|
|
|
data.yf = Convert.ToString(reader["yf"]);
|
|
|
|
|
data.lr = Convert.ToString(reader["lr"]);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
headList.Add(data);
|
|
|
|
|
}
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
return headList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 参照部分
|
|
|
|
|
|
|
|
|
|
public static List<MsCorpDept> GetDeptName(string orgcode)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
strSql.Append("SELECT ");
|
|
|
|
|
strSql.Append(" Distinct DEPTNAME ");
|
|
|
|
|
strSql.Append(" from user_baseinfo");
|
|
|
|
|
// strSql.Append(" where COMPANYNAME in (select name from company where codename='"+orgcode+"')");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dataList = new List<MsCorpDept>();
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
var data = new MsCorpDept();
|
|
|
|
|
|
|
|
|
|
#region Set DB data to Object
|
|
|
|
|
|
|
|
|
|
data.DeptName = Convert.ToString(reader["DEPTNAME"]);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
dataList.Add(data);
|
|
|
|
|
}
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dataList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|