using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Services; using NetLibrary.Data; using TradeData; using TradeModel; using System.Web.Script.Serialization; using NetLibrary.ReportPrint; using NetLibrary; using System.Text; using NetLibrary.Log; namespace TradeManageNew.TongJi { /// /// TJ_CountServer 的摘要说明 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 [System.Web.Script.Services.ScriptService] public class TJ_CountServer : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } #region 首页订单统计 [WebMethod(EnableSession = true)] public DT_OrderNum GetDefaultOrderCount(List listshop) { PagesNew.Login(this.Session); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var obj = new DD_OrderData(); string Ids = ""; if (listshop != null) { foreach (var shopmd in listshop) { Ids += shopmd.Id + ","; } } string[] categories = null; DT_OrderNum md = new DT_OrderNum(); var list = new List(); DateTime SDate=DateTime.Today.AddDays(-10); DateTime EDate=DateTime.Today; TimeSpan ts = EDate- SDate; int days = ts.Days + 1; List countlist = new List(); countlist = obj.GetDefaultCountListFromDay(1, Ids.Trim(','), SDate, EDate.AddDays(1), CompanyId); categories = new string[days]; if (days > 0) { for (int i = 0; i < days; i++) { categories[i] = (SDate.AddDays(i)).ToString("MM月dd日"); } } if (listshop != null && listshop.Count > 0) { for (int i = 0; i < listshop.Count; i++) { decimal[] data = new decimal[days]; if (days > 0) { for (int j = 0; j < days; j++) { if (countlist != null) { var countmd = countlist.Find(n => n.PlatId == listshop[i].Id && n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd")); if (countmd != null) data[j] = countmd.Num.Value; else data[j] = 0; } else data[j] = 0; } } var datamd = new DT_OrderCountData(); datamd.name = listshop[i].Name; datamd.data = data; list.Add(datamd); } } md.categories = categories; JavaScriptSerializer JsonConvert = new JavaScriptSerializer(); string postmessage = JsonConvert.Serialize(list); md.Data = postmessage; return md; } #endregion #region 首页订单统计 [WebMethod(EnableSession = true)] public DT_OrderNum GetDefaultOrderCount1(List listshop,int Type,int Days) { PagesNew.Login(this.Session); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var obj = new DD_OrderData(); string Ids = ""; string[] categories = null; DT_OrderNum md = new DT_OrderNum(); var list = new List(); DateTime SDate = DateTime.Today.AddDays(-1 * Days); DateTime EDate = DateTime.Today; TimeSpan ts = EDate - SDate; int days = ts.Days + 1; List countlist = new List(); countlist = obj.GetDefaultCountListFromDay2(Type, Ids.Trim(','), SDate, EDate.AddDays(1), CompanyId); List countlist2 = new List(); if(Type==3) countlist2 = obj.GetDefaultCountListFromDay2(4, Ids.Trim(','), SDate, EDate.AddDays(1), CompanyId); categories = new string[days]; if (days > 0) { for (int i = 0; i < days; i++) { categories[i] = (SDate.AddDays(i)).ToString("MM月dd日"); } } if (Type == 3) { var smd = new DT_OrderCountContent(); smd.Id = 0; smd.Name = "总销售额"; listshop.Insert(0,smd); } if (listshop != null && listshop.Count > 0) { for (int i = 0; i < listshop.Count; i++) { decimal[] data = new decimal[days]; if (days > 0) { for (int j = 0; j < days; j++) { if (listshop[i].Id == 0 && Type == 3) { if (countlist2 != null) { var countmd2 = countlist2.Find(n => n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd")); if (countmd2 != null) data[j] = countmd2.Price.Value; else data[j] = 0; } else data[j] = 0; } else { if (countlist != null) { var countmd = countlist.Find(n => n.PlatId == listshop[i].Id && n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd")); if (countmd != null && Type == 3) data[j] = countmd.Price.Value; else if (countmd != null) data[j] = countmd.Num.Value; else data[j] = 0; } else data[j] = 0; } } } var datamd = new DT_OrderCountData(); datamd.name = listshop[i].Name; datamd.data = data; list.Add(datamd); } } md.categories = categories; JavaScriptSerializer JsonConvert = new JavaScriptSerializer(); string postmessage = JsonConvert.Serialize(list); md.Data = postmessage; return md; } #endregion #region 首页订单统计 [WebMethod(EnableSession = true)] public DT_OrderNum GetDefaultOrderCountHWC(int Type, int Days) { PagesNew.Login(this.Session); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var obj = new DD_OrderData(); string Ids = ""; string[] categories = null; DT_OrderNum md = new DT_OrderNum(); var list = new List(); DateTime SDate = DateTime.Today.AddDays(-1 * Days); DateTime EDate = DateTime.Today; TimeSpan ts = EDate - SDate; int days = ts.Days + 1; List countlist = new List(); countlist = obj.GetDefaultCountListHWC(Type, Ids.Trim(','), SDate, EDate.AddDays(1), CompanyId); categories = new string[days]; if (days > 0) { for (int i = 0; i < days; i++) { categories[i] = (SDate.AddDays(i)).ToString("MM月dd日"); } } decimal[] data = new decimal[days]; if (days > 0) { for (int j = 0; j < days; j++) { if (countlist != null) { var countmd = countlist.Find(n => n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd")); if (countmd != null) data[j] = countmd.Num.Value; else data[j] = 0; } else data[j] = 0; } } var datamd = new DT_OrderCountData(); datamd.name ="发货单量"; datamd.data = data; list.Add(datamd); md.categories = categories; JavaScriptSerializer JsonConvert = new JavaScriptSerializer(); string postmessage = JsonConvert.Serialize(list); md.Data = postmessage; return md; } #endregion #region 首页订单统计 [WebMethod(EnableSession = true)] public DT_OrderNum GetDefaultOrderCount2(List listshop) { PagesNew.Login(this.Session); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var obj = new DD_OrderData(); string Ids = ""; if (listshop != null) { foreach (var shopmd in listshop) { Ids += shopmd.Id + ","; } } string[] categories = null; DT_OrderNum md = new DT_OrderNum(); var list = new List(); DateTime SDate = DateTime.Today.AddDays(-10); DateTime EDate = DateTime.Today; TimeSpan ts = EDate - SDate; int days = ts.Days + 1; List countlist = new List(); countlist = obj.GetDefaultCountListFromDay2(2, Ids.Trim(','), SDate, EDate.AddDays(1), CompanyId); categories = new string[days]; if (days > 0) { for (int i = 0; i < days; i++) { categories[i] = (SDate.AddDays(i)).ToString("MM月dd日"); } } if (listshop != null && listshop.Count > 0) { for (int i = 0; i < listshop.Count; i++) { decimal[] data = new decimal[days]; if (days > 0) { for (int j = 0; j < days; j++) { if (countlist != null) { var countmd = countlist.Find(n => n.PlatId == listshop[i].Id && n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd")); if (countmd != null) data[j] = countmd.Num.Value; else data[j] = 0; } else data[j] = 0; } } var datamd = new DT_OrderCountData(); datamd.name = listshop[i].Name; datamd.data = data; list.Add(datamd); } } md.categories = categories; JavaScriptSerializer JsonConvert = new JavaScriptSerializer(); string postmessage = JsonConvert.Serialize(list); md.Data = postmessage; return md; } #endregion #region 货物销量统计 [WebMethod(EnableSession = true)] public DT_OrderNum GetGoodsCount(int GoodsId,string GoodsCode,int Type,int Days) { PagesNew.Login(this.Session); PagesNew.Login(this.Session); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var obj = new DD_OrderData(); string Ids = ""; string[] categories = null; DT_OrderNum md = new DT_OrderNum(); var list = new List(); DateTime SDate = DateTime.Today.AddDays(-1 * Days); DateTime EDate = DateTime.Today; TimeSpan ts = EDate - SDate; int days = ts.Days + 1; List countlist = new List(); countlist = obj.GetGoodsCount(Type, GoodsId,SDate, EDate.AddDays(1), CompanyId); categories = new string[days]; if (days > 0) { for (int i = 0; i < days; i++) { categories[i] = (SDate.AddDays(i)).ToString("MM月dd日"); } } decimal[] data = new decimal[days]; if (days > 0) { for (int j = 0; j < days; j++) { if (countlist != null) { var countmd = countlist.Find(n => n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd")); if (countmd != null) data[j] = countmd.Num.Value; else data[j] = 0; } else data[j] = 0; } } var datamd = new DT_OrderCountData(); datamd.name = GoodsCode; datamd.data = data; list.Add(datamd); md.categories = categories; JavaScriptSerializer JsonConvert = new JavaScriptSerializer(); string postmessage = JsonConvert.Serialize(list); md.Data = postmessage; return md; } #endregion #region 统计订单金额 [WebMethod(EnableSession = true)] public DT_OrderNum GetOrderNumCount(int PlatType, int CountType, List listshop, int DateType, List DateList, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var obj = new DD_OrderData(); string Ids = ""; if (listshop!=null) { foreach (var shopmd in listshop) { Ids += shopmd.Id + ","; } } string[] categories = null; DT_OrderNum md=new DT_OrderNum(); List itemlist = new List(); List listData = new List(); var list = new List(); if (DateType == 1) //按日期统计 { TimeSpan ts = EDate.Value - SDate.Value; int days = ts.Days + 1; if (days > 31) { md.Error = "日期范围不能超过31天"; return md; } List countlist=new List(); if(CountType==1) countlist = obj.GetCountListFromDay(PlatType, Ids.Trim(','), SDate, EDate.Value.AddDays(1),CompanyId); else if (CountType == 2) countlist = obj.GetCountPriceFromDay(PlatType, Ids.Trim(','), SDate, EDate.Value.AddDays(1),CompanyId); categories=new string[days]; if (days > 0) { for (int i = 0; i < days; i++) { categories[i] = (SDate.Value.AddDays(i)).ToString("MM月dd日"); DT_OrderCountItem itemmd = new DT_OrderCountItem(); itemmd.name = (SDate.Value.AddDays(i)).ToString("MM月dd日"); itemmd.dataname = "Data" + (i + 1).ToString(); itemlist.Add(itemmd); } } if (listshop!=null&&listshop.Count>0) { for (int i = 0; i < listshop.Count; i++) { decimal[] data = new decimal[days]; if (days > 0) { for (int j = 0; j < days; j++) { if (countlist != null) { var countmd = countlist.Find(n => n.PlatId == listshop[i].Id && n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd")); if (countmd != null) { if (CountType == 1) data[j] = countmd.Num.Value; else data[j] = countmd.Price.Value; } else data[j] = 0; } else data[j] = 0; DT_OrderCount1 mdData = new DT_OrderCount1(); mdData.ShopId = listshop[i].Id; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data[j]; listData.Add(mdData); } } var datamd = new DT_OrderCountData(); datamd.name = listshop[i].Name; datamd.data = data; list.Add(datamd); } } } else if(DateType == 2) //按月统计 { int Count = DateList.Count; List countlist = new List(); categories = new string[Count]; string months = ""; if (DateList != null) { for (int i = 0; i < DateList.Count; i++) { categories[i] = DateList[i].DateName; months += DateList[i].DateValue + ","; DT_OrderCountItem itemmd = new DT_OrderCountItem(); itemmd.name = DateList[i].DateName; itemmd.dataname = "Data" + (i + 1).ToString(); itemlist.Add(itemmd); } } if(CountType==1) countlist = obj.GetCountListFromMonth(PlatType, Ids.Trim(','), months.Trim(','), CompanyId); else if (CountType == 2) countlist = obj.GetCountPriceFromMonth(PlatType, Ids.Trim(','), months.Trim(','), CompanyId); if (listshop!=null&&listshop.Count>0) { for (int i = 0; i < listshop.Count; i++) { decimal[] data = new decimal[Count]; if (Count > 0) { for (int j = 0; j < DateList.Count; j++) { if (countlist != null) { var countmd = countlist.Find(n => n.PlatId == listshop[i].Id && n.MonthId.Value==DateList[j].DateValue); if (countmd != null) { if (CountType == 1) data[j] = countmd.Num.Value; else data[j] = countmd.Price.Value; } else data[j] = 0; } else data[j] = 0; DT_OrderCount1 mdData = new DT_OrderCount1(); mdData.ShopId = listshop[i].Id; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data[j]; listData.Add(mdData); } } var datamd = new DT_OrderCountData(); datamd.name = listshop[i].Name; datamd.data = data; list.Add(datamd); } } } else if (DateType == 3) //按季度统计 { int Count = DateList.Count; List countlist1 = new List(); List countlist2 = new List(); List countlist3 = new List(); List countlist4 = new List(); categories = new string[Count]; if (DateList != null) { for (int i = 0; i < DateList.Count; i++) { categories[i] = DateList[i].DateName; DT_OrderCountItem itemmd = new DT_OrderCountItem(); itemmd.name = DateList[i].DateName; itemmd.dataname = "Data" + (i + 1).ToString(); itemlist.Add(itemmd); int SMonth = DateList[i].DateValue * 3 - 2; int EMonth = DateList[i].DateValue * 3; var countmd = new DT_CountListFromMonth(); if (DateList[i].DateValue == 1) { if (CountType == 1) countlist1 = obj.GetCountListFromQuarter(PlatType, Ids.Trim(','), SMonth, EMonth,CompanyId); else if (CountType == 2) countlist1 = obj.GetCountPriceFromQuarter(PlatType, Ids.Trim(','), SMonth, EMonth, CompanyId); } else if (DateList[i].DateValue == 2) { if (CountType == 1) countlist2 = obj.GetCountListFromQuarter(PlatType, Ids.Trim(','), SMonth, EMonth, CompanyId); else if (CountType == 2) countlist2 = obj.GetCountPriceFromQuarter(PlatType, Ids.Trim(','), SMonth, EMonth, CompanyId); } else if (DateList[i].DateValue == 3) { if (CountType == 1) countlist3 = obj.GetCountListFromQuarter(PlatType, Ids.Trim(','), SMonth, EMonth, CompanyId); else if (CountType == 2) countlist3 = obj.GetCountPriceFromQuarter(PlatType, Ids.Trim(','), SMonth, EMonth, CompanyId); } else if (DateList[i].DateValue == 4) { if (CountType == 1) countlist4 = obj.GetCountListFromQuarter(PlatType, Ids.Trim(','), SMonth, EMonth, CompanyId); else if (CountType == 2) countlist4 = obj.GetCountPriceFromQuarter(PlatType, Ids.Trim(','), SMonth, EMonth, CompanyId); } } } if (listshop != null && listshop.Count > 0) { for (int i = 0; i < listshop.Count; i++) { decimal[] data = new decimal[Count]; if (Count > 0) { for (int j = 0; j < DateList.Count; j++) { var countmd = new DT_CountListFromMonth(); if (DateList[j].DateValue == 1 && countlist1!=null) countmd = countlist1.Find(n => n.PlatId == listshop[i].Id); else if (DateList[j].DateValue == 2 && countlist2 != null) countmd = countlist2.Find(n => n.PlatId == listshop[i].Id); else if (DateList[j].DateValue == 3 && countlist3 != null) countmd = countlist3.Find(n => n.PlatId == listshop[i].Id); else if (DateList[j].DateValue == 4 && countlist4 != null) countmd = countlist4.Find(n => n.PlatId == listshop[i].Id); if (countmd != null) { if (CountType == 1&&countmd.Num!=null) data[j] = countmd.Num.Value; else if (CountType == 2 && countmd.Price != null) data[j] = countmd.Price.Value; } else data[j] = 0; DT_OrderCount1 mdData = new DT_OrderCount1(); mdData.ShopId = listshop[i].Id; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data[j]; listData.Add(mdData); } } var datamd = new DT_OrderCountData(); datamd.name = listshop[i].Name; datamd.data = data; list.Add(datamd); } } } md.categories = categories; JavaScriptSerializer JsonConvert = new JavaScriptSerializer(); string postmessage = JsonConvert.Serialize(list); md.Data = postmessage; md.listItem = itemlist; md.listData = listData; //md.list1 = list1; //var Model = obj.GetSortModelModel(SortId); return md; } #endregion #region 统计订单利润 [WebMethod(EnableSession = true)] public DT_OrderNum GetOrderPriceCount(int PlatId,int ShopId, int DateType, List DateList, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); string[] categories = null; DT_OrderNum md = new DT_OrderNum(); List itemlist = new List(); List listData = new List(); var list = new List(); if (DateType == 1) //按日期统计 { TimeSpan ts = EDate.Value - SDate.Value; int days = ts.Days + 1; if (days > 31) { md.Error = "日期范围不能超过31天"; return md; } List countlist = new List(); countlist = obj.GetDTPriceFromDay(PlatId, ShopId, SDate, EDate.Value.AddDays(1)); categories = new string[days]; if (days > 0) { for (int i = 0; i < days; i++) { categories[i] = (SDate.Value.AddDays(i)).ToString("MM月dd日"); DT_OrderCountItem itemmd = new DT_OrderCountItem(); itemmd.name = (SDate.Value.AddDays(i)).ToString("MM月dd日"); itemmd.dataname = "Data" + (i + 1).ToString(); itemlist.Add(itemmd); } } decimal[] data = new decimal[days]; decimal[] data2 = new decimal[days]; decimal[] data3 = new decimal[days]; if (days > 0) { for (int j = 0; j < days; j++) { if (countlist != null) { var countmd = countlist.Find(n =>n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd")); if (countmd != null) { data[j] = countmd.TotalPrice.Value; data2[j] = countmd.GoodsFee.Value + countmd.PostFee.Value; data3[j] = countmd.TotalPrice.Value - countmd.GoodsFee.Value - countmd.PostFee.Value; } else { data[j] = 0; data2[j]=0; data3[j] = 0; } } else { data[j] = 0; data2[j] = 0; data3[j] = 0; } DT_OrderCount1 mdData = new DT_OrderCount1(); mdData.ShopId = 1; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data[j]; listData.Add(mdData); mdData = new DT_OrderCount1(); mdData.ShopId = 2; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data2[j]; listData.Add(mdData); mdData = new DT_OrderCount1(); mdData.ShopId = 3; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data3[j]; listData.Add(mdData); } } var datamd = new DT_OrderCountData(); datamd.name = "销售额"; datamd.data = data; list.Add(datamd); datamd = new DT_OrderCountData(); datamd.name = "成本"; datamd.data = data2; list.Add(datamd); datamd = new DT_OrderCountData(); datamd.name = "利润"; datamd.data = data3; list.Add(datamd); } else if (DateType == 2) //按月统计 { int Count = DateList.Count; List countlist = new List(); categories = new string[Count]; string months = ""; if (DateList != null) { for (int i = 0; i < DateList.Count; i++) { categories[i] = DateList[i].DateName; months += DateList[i].DateValue + ","; DT_OrderCountItem itemmd = new DT_OrderCountItem(); itemmd.name = DateList[i].DateName; itemmd.dataname = "Data" + (i + 1).ToString(); itemlist.Add(itemmd); } } countlist = obj.GetDTPriceFromMonth(PlatId,ShopId, months.Trim(',')); decimal[] data = new decimal[Count]; decimal[] data2 = new decimal[Count]; decimal[] data3 = new decimal[Count]; if (Count > 0) { for (int j = 0; j < DateList.Count; j++) { if (countlist != null) { var countmd = countlist.Find(n => n.DayId.Value == DateList[j].DateValue); if (countmd != null) { data[j] = countmd.TotalPrice.Value; data2[j] = countmd.GoodsFee.Value + countmd.PostFee.Value; data3[j] = countmd.TotalPrice.Value - countmd.GoodsFee.Value - countmd.PostFee.Value; } else { data[j] = 0; data2[j] = 0; data3[j] = 0; } } else { data[j] = 0; data2[j] = 0; data3[j] = 0; } DT_OrderCount1 mdData = new DT_OrderCount1(); mdData.ShopId = 1; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data[j]; listData.Add(mdData); mdData = new DT_OrderCount1(); mdData.ShopId = 2; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data2[j]; listData.Add(mdData); mdData = new DT_OrderCount1(); mdData.ShopId = 3; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data3[j]; listData.Add(mdData); } } var datamd = new DT_OrderCountData(); datamd.name = "销售额"; datamd.data = data; list.Add(datamd); datamd = new DT_OrderCountData(); datamd.name = "成本"; datamd.data = data2; list.Add(datamd); datamd = new DT_OrderCountData(); datamd.name = "利润"; datamd.data = data3; list.Add(datamd); } else if (DateType == 3) //按季度统计 { int Count = DateList.Count; List countlist1 = new List(); List countlist2 = new List(); List countlist3 = new List(); List countlist4 = new List(); categories = new string[Count]; if (DateList != null) { for (int i = 0; i < DateList.Count; i++) { categories[i] = DateList[i].DateName; DT_OrderCountItem itemmd = new DT_OrderCountItem(); itemmd.name = DateList[i].DateName; itemmd.dataname = "Data" + (i + 1).ToString(); itemlist.Add(itemmd); int SMonth = DateList[i].DateValue * 3 - 2; int EMonth = DateList[i].DateValue * 3; var countmd = new DT_CountListFromMonth(); if (DateList[i].DateValue == 1) { countlist1 = obj.GetDTPriceFromQuarter(PlatId, ShopId, SMonth, EMonth); } else if (DateList[i].DateValue == 2) { countlist2 = obj.GetDTPriceFromQuarter(PlatId, ShopId, SMonth, EMonth); } else if (DateList[i].DateValue == 3) { countlist3 = obj.GetDTPriceFromQuarter(PlatId, ShopId, SMonth, EMonth); } else if (DateList[i].DateValue == 4) { countlist4 = obj.GetDTPriceFromQuarter(PlatId, ShopId, SMonth, EMonth); } } } decimal[] data = new decimal[Count]; decimal[] data2 = new decimal[Count]; decimal[] data3 = new decimal[Count]; if (Count > 0) { for (int j = 0; j < DateList.Count; j++) { var countmd = new DT_CountPrice(); if (DateList[j].DateValue == 1 && countlist1 != null && countlist1.Count > 0) countmd = countlist1[0]; else if (DateList[j].DateValue == 2 && countlist2 != null && countlist2.Count > 0) countmd = countlist2[0]; else if (DateList[j].DateValue == 3 && countlist3 != null && countlist3.Count > 0) countmd = countlist3[0]; else if (DateList[j].DateValue == 4 && countlist4 != null && countlist4.Count > 0) countmd = countlist4[0]; if (countmd != null) { data[j] = countmd.TotalPrice.Value; data2[j] = countmd.GoodsFee.Value + countmd.PostFee.Value; data3[j] = countmd.TotalPrice.Value - countmd.GoodsFee.Value - countmd.PostFee.Value; } else { data[j] = 0; data2[j] = 0; data3[j] = 0; } DT_OrderCount1 mdData = new DT_OrderCount1(); mdData.ShopId = 1; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data[j]; listData.Add(mdData); mdData = new DT_OrderCount1(); mdData.ShopId = 2; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data2[j]; listData.Add(mdData); mdData = new DT_OrderCount1(); mdData.ShopId = 3; mdData.DayId = "Data" + (j + 1).ToString(); mdData.Data = data3[j]; listData.Add(mdData); } } var datamd = new DT_OrderCountData(); datamd.name = "销售额"; datamd.data = data; list.Add(datamd); datamd = new DT_OrderCountData(); datamd.name = "成本"; datamd.data = data2; list.Add(datamd); datamd = new DT_OrderCountData(); datamd.name = "利润"; datamd.data = data3; list.Add(datamd); } md.categories = categories; JavaScriptSerializer JsonConvert = new JavaScriptSerializer(); string postmessage = JsonConvert.Serialize(list); md.Data = postmessage; md.listItem = itemlist; md.listData = listData; //md.list1 = list1; //var Model = obj.GetSortModelModel(SortId); return md; } #endregion #region 查询利润报表 [WebMethod(EnableSession = true)] public List GetOrderSaleMoney(string ShopIds,Decimal? PersonFee, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); if (PersonFee == null) PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); var list = obj.GetOrderSaleMoney(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var cblist = obj.GetBuyMoney(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); DataTable tb = new DataTable(); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; if (list != null) { string PlatOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row = tb.NewRow(); if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.00"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); if (md.MoneyRate != null) row["MoneyRate"] = md.MoneyRate.Value.ToString("0.00"); if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); row["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) row["PostFee"] = md.PostFee.Value.ToString("0.00"); row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.00"); if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.00"); if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee - 2).ToString("0.00"); row["PersonMoney"] = PersonFee.Value.ToString("f1"); var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); row1["PlatOrderCode"] = md.PlatOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] = ""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.00"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.00"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.00"); row1["GNPostFee"] = ""; row1["PersonMoney"] = md.PostFee.Value.ToString("f1"); if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - md.PostFee.Value).ToString("0.00"); row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += PersonFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - md.PostFee.Value; tb.Rows.Add(row1); row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["MoneyRate"] = ""; row["OffNum"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.00"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.00"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += PersonFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; } } DataRow row2 = tb.NewRow(); row2["TrackCode"] = "合计:"; row2["TotalPrice"] = TotalPrice.ToString("0.00"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["PostFee"] = PostFee.ToString("0.00"); row2["GoodsFee"] = GoodsFee.ToString("0.00"); row2["GNPostFee"] = GNPostFee.ToString("0.00"); row2["FactMoney"] = FactMoney.ToString("0.00"); tb.Rows.Add(row2); if (tb == null) return null; return tb.ToList(); } #endregion #region 导出利润报表 [WebMethod(EnableSession = true)] public string ExcelOrderSaleMoney(string ShopIds,Decimal? PersonFee, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); if (PersonFee == null) PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); var list = obj.GetOrderSaleMoney(SDate,EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var cblist = obj.GetBuyMoney(SDate,EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); DataTable tb = new DataTable(); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; if (list != null) { string PlatOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row=tb.NewRow(); if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.00"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); if (md.MoneyRate != null) row["MoneyRate"] = md.MoneyRate.Value.ToString("0.00"); if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); row["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) row["PostFee"] = md.PostFee.Value.ToString("0.00"); row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.00"); if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.00"); if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee-2).ToString("0.00"); row["PersonMoney"] = PersonFee.Value.ToString("f1"); var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); row1["PlatOrderCode"] = md.PlatOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] =""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.00"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.00"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.00"); row1["GNPostFee"] = ""; row1["PersonMoney"] = md.PostFee.Value.ToString("f1"); if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - md.PostFee.Value).ToString("0.00"); row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += PersonFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - md.PostFee.Value; tb.Rows.Add(row1); row["PostDate"] =""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["MoneyRate"] = ""; row["OffNum"] =""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0- dGoodsFee - dGNPostFee).ToString("0.00"); row["PostFee"] = ""; row["ErrorInfo"] =""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.00"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += PersonFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; } } DataRow row2 = tb.NewRow(); row2["TrackCode"] = "合计:"; row2["TotalPrice"] = TotalPrice.ToString("0.00"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["PostFee"] = PostFee.ToString("0.00"); row2["GoodsFee"] = GoodsFee.ToString("0.00"); row2["GNPostFee"] = GNPostFee.ToString("0.00"); row2["FactMoney"] = FactMoney.ToString("0.00"); tb.Rows.Add(row2); TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("PostDate", "发货时间", DbType.String, ""); listColumns.Add("PlatOrderCode", "订单号", DbType.String, ""); listColumns.Add("GoodsCode", "货物编号", DbType.String, ""); listColumns.Add("GoodsName", "货物名称", DbType.String, ""); listColumns.Add("CountryName", "国家", DbType.String, ""); listColumns.Add("TypeDesc", "描述", DbType.String, ""); //listColumns.Add("OffNum", "汇率", DbType.String, ""); listColumns.Add("OffNum", "运费折扣", DbType.String, ""); listColumns.Add("TrackCode", "挂号", DbType.String, ""); listColumns.Add("GoodsNum", "数量", DbType.String, ""); listColumns.Add("TotalWeight", "重量", DbType.String, ""); listColumns.Add("TotalPrice", "总价格", DbType.String, ""); listColumns.Add("MoneyRate", "汇率", DbType.String, ""); listColumns.Add("PostFee", "实际运费", DbType.String, ""); listColumns.Add("GoodsFee", "进货价", DbType.String, ""); listColumns.Add("GNPostFee", "国内运费", DbType.String, ""); listColumns.Add("PersonMoney", "人工费", DbType.String, ""); listColumns.Add("FactMoney", "最终利润", DbType.String, ""); listColumns.Add("ErrorInfo", "异常", DbType.String, ""); listColumns.Add("PostName", "发货方式", DbType.String, ""); MicrosoftExcel obj2 = new MicrosoftExcel(); return obj2.Export(tb, listColumns); } #endregion #region 查询利润报表 [WebMethod(EnableSession = true)] public List GetOrderSaleMoneyNew(string ShopIds, Decimal? PersonFee, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); if (PersonFee == null) PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); var list = obj.GetOrderSaleMoney(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var cblist = obj.GetBuyMoneyNew(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); DataTable tb = new DataTable(); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; if (list != null && cblist!=null) { string PlatOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row = tb.NewRow(); if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.00"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); if (md.MoneyRate != null) row["MoneyRate"] = md.MoneyRate.Value.ToString("0.00"); if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); row["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) row["PostFee"] = md.PostFee.Value.ToString("0.00"); row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.00"); if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.00"); if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee - 2).ToString("0.00"); row["PersonMoney"] = PersonFee.Value.ToString("f1"); var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); row1["PlatOrderCode"] = md.PlatOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] = ""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.00"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.00"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.00"); row1["GNPostFee"] = ""; row1["PersonMoney"] = PersonFee.Value.ToString("f1"); if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - PersonFee.Value).ToString("0.00"); row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += PersonFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - PersonFee.Value; tb.Rows.Add(row1); row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["MoneyRate"] = ""; row["OffNum"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.00"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.00"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += PersonFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; } } DataRow row2 = tb.NewRow(); row2["TrackCode"] = "合计:"; row2["TotalPrice"] = TotalPrice.ToString("0.00"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["PostFee"] = PostFee.ToString("0.00"); row2["GoodsFee"] = GoodsFee.ToString("0.00"); row2["GNPostFee"] = GNPostFee.ToString("0.00"); row2["FactMoney"] = FactMoney.ToString("0.00"); tb.Rows.Add(row2); if (tb == null) return null; return tb.ToList(); } #endregion #region 查询利润报表 [WebMethod(EnableSession = true)] public List GetOrderSaleMoneyForTM(string ShopIds, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; // int ShopId=0; // if(ShopIds!="") // ShopId=Convert.ToInt32(ShopIds.Split(',')[0]); int CompanyId = Convert.ToInt32(Session["CompanyId"]); // var moneylist = obj.GetMoneyList(ShopId); var list = obj.GetOrderSaleMoneyForTM(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var cblist = obj.GetBuyMoneyNew(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); //var tracklist = obj.GetMoneyList(ShopId); DataTable tb = new DataTable(); tb.Columns.Add("Id", typeof(Int32)); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("escrowFee", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; decimal escrowFee = 0; if (list != null && cblist != null) { string PlatOrderCode = ""; string JoinOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row = tb.NewRow(); row["Id"] = md.Id; row["ShopName"] = md.ShopName; if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode!="") row["PlatOrderCode"] = md.JoinOrderCode; else row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); //row["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); if (md.MoneyRate != null) row["MoneyRate"] = md.MoneyRate.Value.ToString("0.00000"); if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); row["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) row["PostFee"] = md.PostFee.Value.ToString("0.0000"); md.FactMoney = md.RMBPrice - md.escrowFee.Value - md.PostFee.Value * md.OffNum/10; row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.0000"); if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.0000"); row["PersonMoney"] = md.PersonFee.Value.ToString("f1"); if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee - md.PersonFee.Value).ToString("0.00"); var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (JoinOrderCode != "" && md.JoinOrderCode == JoinOrderCode) { row["TrackCode"] = ""; row["TotalWeight"] = "0"; row["PostFee"] = 0; md.PostFee = 0; md.TotalWeight = 0; row["PersonMoney"] = 0; md.PersonFee=0; row["FactMoney"] = (md.RMBPrice.Value - md.escrowFee.Value - dGoodsFee - dGNPostFee).ToString("0.00"); } if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); row1["Id"] = md.Id; row1["ShopName"] = md.ShopName; if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row1["PlatOrderCode"] = md.JoinOrderCode; else row1["PlatOrderCode"] = md.PlatOrderCode; //if (md.JoinOrderCode!=null) //row1["JoinOrderCode"] = md.JoinOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] = ""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); // row1["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.00000"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.0000"); row1["GNPostFee"] = ""; row1["PersonMoney"] = md.PersonFee.Value.ToString("f1"); if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - md.PersonFee.Value).ToString("0.00"); row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += md.PersonFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - md.PersonFee.Value; escrowFee += md.escrowFee.Value; tb.Rows.Add(row1); row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["MoneyRate"] = ""; row["OffNum"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.0000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.0000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } if ((JoinOrderCode == "" || md.JoinOrderCode != JoinOrderCode) && md.JoinOrderCode != null) { var checklist = list.FindAll(n => n.JoinOrderCode == md.JoinOrderCode&&n.TotalWeight!=null); if(checklist.Count()>0) { md.TotalWeight = checklist.First().TotalWeight; md.PostFee = checklist.First().PostFee; row["TotalWeight"] = checklist.First().TotalWeight; row["PostFee"] = checklist.First().PostFee; } } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += md.PersonFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; if (md.JoinOrderCode == null) JoinOrderCode = ""; else JoinOrderCode = md.JoinOrderCode; } } DataRow row2 = tb.NewRow(); row2["TrackCode"] = "合计:"; // row2["escrowFee"] = escrowFee.ToString("0.0000"); row2["TotalPrice"] = TotalPrice.ToString("0.0000"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["PostFee"] = PostFee.ToString("0.0000"); row2["GoodsFee"] = GoodsFee.ToString("0.0000"); row2["GNPostFee"] = GNPostFee.ToString("0.0000"); row2["FactMoney"] = FactMoney.ToString("0.0000"); tb.Rows.Add(row2); if (tb == null) return null; return tb.ToList(); } #endregion #region 查询利润报表 [WebMethod(EnableSession = true)] public List GetOrderSaleMoneyForTM2(string ShopIds, DateTime? SDate, DateTime? EDate,string GoodsCode) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int ShopId = 0; if (ShopIds != "") ShopId = Convert.ToInt32(ShopIds.Split(',')[0]); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var moneylist = obj.GetMoneyList(ShopId); var list = obj.GetOrderSaleMoneyForTM2(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','),GoodsCode.Trim(), CompanyId); var cblist = obj.GetBuyMoneyNew(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var tracklist = obj.GetTrackCodeList(ShopIds.TrimEnd(','), SDate, EDate.Value.AddDays(1)); //var cateList=obj DataTable tb = new DataTable(); tb.Columns.Add("Id", typeof(Int32)); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("escrowFee", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; decimal escrowFee = 0; int OrderNum = 0; if (list != null && cblist != null) { string PlatOrderCode = ""; string JoinOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row = tb.NewRow(); row["Id"] = md.Id; row["ShopName"] = md.ShopName; if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row["PlatOrderCode"] = md.JoinOrderCode; else row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); //row["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); var moneymd = moneylist.Find(n => n.PlatId == md.PlatId && n.MCode == md.MoneyCode); if (moneymd != null) { md.RMBPrice = md.TotalPrice * moneymd.MRate.Value; md.MoneyRate = moneymd.MRate; row["MoneyRate"] = moneymd.MRate.Value.ToString("0.00000"); } else { row["MoneyRate"] = "1"; md.RMBPrice = md.TotalPrice; } if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); string tcode = ""; if (md.JoinOrderCode != null && md.JoinOrderCode != "") { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.JoinOrderCode == md.JoinOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + "
"; } } } } else { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.OrderCode == md.PlatOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + "
"; } } } } md.TrackCode = tcode; row["TrackCode"] = tcode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) { md.PostFee = md.PostFee.Value * md.OffNum / 10; row["PostFee"] = md.PostFee.Value.ToString("0.0000"); } else md.PostFee = 0; md.FactMoney = md.RMBPrice - md.PostFee.Value; row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.0000"); if (md.GoodsName.Contains("0-10") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "5"; dGoodsFee = 5; } else if (md.GoodsName.Contains("10-20") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "15"; dGoodsFee = 15; } else if (md.GoodsName.Contains("20-30") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "25"; dGoodsFee = 25; } if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.0000"); row["PersonMoney"] = md.PersonFee.Value.ToString("f1"); if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee - md.PersonFee.Value).ToString("0.00"); var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (JoinOrderCode != "" && md.JoinOrderCode == JoinOrderCode) { row["TrackCode"] = ""; row["TotalWeight"] = "0"; row["PostFee"] = 0; md.PostFee = 0; md.TotalWeight = 0; row["PersonMoney"] = 0; md.PersonFee = 0; row["FactMoney"] = (md.RMBPrice.Value - dGoodsFee - dGNPostFee).ToString("0.00"); } if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); row1["Id"] = md.Id; row1["ShopName"] = md.ShopName; if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row1["PlatOrderCode"] = md.JoinOrderCode; else row1["PlatOrderCode"] = md.PlatOrderCode; //if (md.JoinOrderCode!=null) //row1["JoinOrderCode"] = md.JoinOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] = ""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); // row1["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.00000"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.0000"); row1["GNPostFee"] = ""; row1["PersonMoney"] = md.PersonFee.Value.ToString("f1"); if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - md.PersonFee.Value).ToString("0.00"); row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += md.PersonFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - md.PersonFee.Value; // escrowFee += md.escrowFee.Value; tb.Rows.Add(row1); OrderNum++; row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["MoneyRate"] = ""; row["OffNum"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.0000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.0000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else OrderNum++; if ((JoinOrderCode == "" || md.JoinOrderCode != JoinOrderCode) && md.JoinOrderCode != null) { var checklist = list.FindAll(n => n.JoinOrderCode == md.JoinOrderCode && n.TotalWeight != null); if (checklist.Count() > 0) { md.TotalWeight = checklist.First().TotalWeight; md.PostFee = checklist.First().PostFee; row["TotalWeight"] = checklist.First().TotalWeight; row["PostFee"] = checklist.First().PostFee; } } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += md.PersonFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; if (md.JoinOrderCode == null) JoinOrderCode = ""; else JoinOrderCode = md.JoinOrderCode; } } DataRow row2 = tb.NewRow(); row2["PostDate"] = OrderNum.ToString(); row2["TrackCode"] = "合计:"; // row2["escrowFee"] = escrowFee.ToString("0.0000"); row2["TotalPrice"] = TotalPrice.ToString("0.0000"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["PostFee"] = PostFee.ToString("0.0000"); row2["GoodsFee"] = GoodsFee.ToString("0.0000"); row2["GNPostFee"] = GNPostFee.ToString("0.0000"); row2["FactMoney"] = FactMoney.ToString("0.0000"); tb.Rows.Add(row2); if (tb == null) return null; return tb.ToList(); } #endregion #region 查询利润报表 [WebMethod(EnableSession = true)] public List GetOrderSaleMoneyForTM3(string ShopIds, DateTime? SDate, DateTime? EDate, string GoodsCode) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int ShopId = 0; if (ShopIds != "") ShopId = Convert.ToInt32(ShopIds.Split(',')[0]); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var moneylist = obj.GetMoneyList(ShopId); var list = obj.GetOrderSaleMoneyForTM3(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), GoodsCode.Trim(), CompanyId); var cblist = obj.GetBuyMoneyNew(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var tracklist = obj.GetTrackCodeList(ShopIds.TrimEnd(','), SDate, EDate.Value.AddDays(1)); //var cateList=obj DataTable tb = new DataTable(); tb.Columns.Add("Id", typeof(Int32)); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("BuyDate", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("escrowFee", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("ZJMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; decimal escrowFee = 0; decimal ZJMoney = 0; int OrderNum = 0; if (list != null && cblist != null) { string PlatOrderCode = ""; string JoinOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row = tb.NewRow(); row["Id"] = md.Id; row["ShopName"] = md.ShopName; if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.BuyDate != null) row["BuyDate"] = md.BuyDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row["PlatOrderCode"] = md.JoinOrderCode; else row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); //row["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); var moneymd = moneylist.Find(n => n.PlatId == md.PlatId && n.MCode == md.MoneyCode); if (moneymd != null) { md.RMBPrice = md.TotalPrice * moneymd.MRate.Value; md.MoneyRate = moneymd.MRate; row["MoneyRate"] = moneymd.MRate.Value.ToString("0.00000"); } else { row["MoneyRate"] = "1"; md.RMBPrice = md.TotalPrice; } if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); string tcode = ""; if (md.JoinOrderCode != null && md.JoinOrderCode != "") { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.JoinOrderCode == md.JoinOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + "
"; } } } } else { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.OrderCode == md.PlatOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + "
"; } } } } md.TrackCode = tcode; row["TrackCode"] = tcode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) { md.PostFee = md.PostFee.Value * md.OffNum / 10; row["PostFee"] = md.PostFee.Value.ToString("0.0000"); } else md.PostFee = 0; md.FactMoney = md.RMBPrice - md.PostFee.Value; row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.0000"); if (md.GoodsName.Contains("0-10") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "5"; dGoodsFee = 5; } else if (md.GoodsName.Contains("10-20") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "15"; dGoodsFee = 15; } else if (md.GoodsName.Contains("20-30") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "25"; dGoodsFee = 25; } if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.0000"); row["PersonMoney"] = md.PersonFee.Value.ToString("f1"); row["ZJMoney"] = md.ZJFee.Value.ToString("f1"); if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee - md.PersonFee.Value-md.ZJFee.Value).ToString("0.00"); var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (JoinOrderCode != "" && md.JoinOrderCode == JoinOrderCode) { row["TrackCode"] = ""; row["TotalWeight"] = "0"; row["PostFee"] = 0; md.PostFee = 0; md.TotalWeight = 0; row["PersonMoney"] = 0; row["ZJMoney"] = 0; md.PersonFee = 0; row["FactMoney"] = (md.RMBPrice.Value - dGoodsFee - dGNPostFee).ToString("0.00"); } if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); row1["Id"] = md.Id; row1["ShopName"] = md.ShopName; if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.BuyDate != null) row1["BuyDate"] = md.BuyDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row1["PlatOrderCode"] = md.JoinOrderCode; else row1["PlatOrderCode"] = md.PlatOrderCode; //if (md.JoinOrderCode!=null) //row1["JoinOrderCode"] = md.JoinOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] = ""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); // row1["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.00000"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.0000"); row1["GNPostFee"] = ""; row1["PersonMoney"] = md.PersonFee.Value.ToString("f1"); row1["ZJMoney"] = ""; if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - md.PersonFee.Value).ToString("0.00"); row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += md.PersonFee.Value; ZJMoney += md.ZJFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - md.PersonFee.Value; // escrowFee += md.escrowFee.Value; tb.Rows.Add(row1); OrderNum++; row["BuyDate"] = ""; row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["MoneyRate"] = ""; row["OffNum"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; //row["ZJMoney"] =""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee-md.ZJFee.Value).ToString("0.0000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["BuyDate"] = ""; row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; // row["ZJMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee-md.ZJFee.Value).ToString("0.0000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else OrderNum++; if ((JoinOrderCode == "" || md.JoinOrderCode != JoinOrderCode) && md.JoinOrderCode != null) { var checklist = list.FindAll(n => n.JoinOrderCode == md.JoinOrderCode && n.TotalWeight != null); if (checklist.Count() > 0) { md.TotalWeight = checklist.First().TotalWeight; md.PostFee = checklist.First().PostFee; row["TotalWeight"] = checklist.First().TotalWeight; row["PostFee"] = checklist.First().PostFee; } } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += md.PersonFee.Value; if (row["ZJMoney"] != null && row["ZJMoney"].ToString() != "") ZJMoney += md.ZJFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; if (md.JoinOrderCode == null) JoinOrderCode = ""; else JoinOrderCode = md.JoinOrderCode; } } DataRow row2 = tb.NewRow(); row2["PostDate"] = OrderNum.ToString(); row2["TrackCode"] = "合计:"; // row2["escrowFee"] = escrowFee.ToString("0.0000"); row2["TotalPrice"] = TotalPrice.ToString("0.0000"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["ZJMoney"] = ZJMoney.ToString("0"); row2["PostFee"] = PostFee.ToString("0.0000"); row2["GoodsFee"] = GoodsFee.ToString("0.0000"); row2["GNPostFee"] = GNPostFee.ToString("0.0000"); row2["FactMoney"] = FactMoney.ToString("0.0000"); tb.Rows.Add(row2); if (tb == null) return null; return tb.ToList(); } #endregion #region 查询利润报表 [WebMethod(EnableSession = true)] public List GetOrderSaleMoneyForTM4(string ShopIds, DateTime? SDate, DateTime? EDate, string GoodsCode) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int ShopId = 0; if (ShopIds != "") ShopId = Convert.ToInt32(ShopIds.Split(',')[0]); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var moneylist = obj.GetMoneyList(ShopId); var list = obj.GetOrderSaleMoneyForTM3(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), GoodsCode.Trim(), CompanyId); var cblist = obj.GetBuyMoneyNew(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var tracklist = obj.GetTrackCodeList(ShopIds.TrimEnd(','), SDate, EDate.Value.AddDays(1)); //var cateList=obj DataTable tb = new DataTable(); tb.Columns.Add("Id", typeof(Int32)); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("BuyDate", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("escrowFee", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("RateMoney", typeof(string)); tb.Columns.Add("ZJMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; decimal escrowFee = 0; decimal ZJMoney = 0; decimal RateMoney = 0; int OrderNum = 0; if (list != null && cblist != null) { string PlatOrderCode = ""; string JoinOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row = tb.NewRow(); row["Id"] = md.Id; row["ShopName"] = md.ShopName; if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.BuyDate != null) row["BuyDate"] = md.BuyDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row["PlatOrderCode"] = md.JoinOrderCode; else row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); //row["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); var moneymd = moneylist.Find(n => n.PlatId == md.PlatId && n.MCode == md.MoneyCode); if (moneymd != null) { md.RMBPrice = md.TotalPrice * moneymd.MRate.Value; md.MoneyRate = moneymd.MRate; row["MoneyRate"] = moneymd.MRate.Value.ToString("0.00000"); } else { row["MoneyRate"] = "1"; md.RMBPrice = md.TotalPrice; } if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); string tcode = ""; if (md.JoinOrderCode != null && md.JoinOrderCode != "") { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.JoinOrderCode == md.JoinOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + "
"; } } } } else { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.OrderCode == md.PlatOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + "
"; } } } } md.TrackCode = tcode; row["TrackCode"] = tcode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) { md.PostFee = md.PostFee.Value * md.OffNum / 10; row["PostFee"] = md.PostFee.Value.ToString("0.0000"); } else md.PostFee = 0; md.FactMoney = md.RMBPrice - md.PostFee.Value; row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.0000"); //if (md.GoodsName.Contains("0-10") && md.GoodsName.Contains("礼物")) //{ // row["GoodsFee"] = "5"; // dGoodsFee = 5; //} //else if (md.GoodsName.Contains("10-20") && md.GoodsName.Contains("礼物")) //{ // row["GoodsFee"] = "15"; // dGoodsFee = 15; //} //else if (md.GoodsName.Contains("20-30") && md.GoodsName.Contains("礼物")) //{ // row["GoodsFee"] = "25"; // dGoodsFee = 25; //} if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.0000"); row["PersonMoney"] = md.PersonFee.Value.ToString("f1"); row["ZJMoney"] =0; if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee - md.PersonFee.Value).ToString("0.00"); decimal rate=0; if (md.RMBPrice != null && md.RMBPrice.Value > 0) rate = (md.FactMoney.Value - dGoodsFee - dGNPostFee - md.PersonFee.Value) * 100 / md.RMBPrice.Value; row["RateMoney"] = rate.ToString("0.000") + "%"; var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (JoinOrderCode != "" && md.JoinOrderCode == JoinOrderCode) { row["TrackCode"] = ""; row["TotalWeight"] = "0"; row["PostFee"] = 0; md.PostFee = 0; md.TotalWeight = 0; row["PersonMoney"] = 0; row["ZJMoney"] = 0; md.PersonFee = 0; row["FactMoney"] = (md.RMBPrice.Value - dGoodsFee - dGNPostFee).ToString("0.00"); rate = 0; if (md.RMBPrice != null && md.RMBPrice.Value > 0) rate = (md.RMBPrice.Value - dGoodsFee - dGNPostFee) * 100 / md.RMBPrice.Value; row["RateMoney"] = rate.ToString("0.000") + "%"; } if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); row1["Id"] = md.Id; row1["ShopName"] = md.ShopName; if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.BuyDate != null) row1["BuyDate"] = md.BuyDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row1["PlatOrderCode"] = md.JoinOrderCode; else row1["PlatOrderCode"] = md.PlatOrderCode; //if (md.JoinOrderCode!=null) //row1["JoinOrderCode"] = md.JoinOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] = ""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); // row1["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.00000"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.0000"); row1["GNPostFee"] = ""; row1["PersonMoney"] = md.PersonFee.Value.ToString("f1"); row1["ZJMoney"] = ""; if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - md.PersonFee.Value).ToString("0.00"); decimal rate1 = 0; if (md.RMBPrice != null && md.RMBPrice.Value > 0) rate1 = (md.FactMoney.Value - md.PersonFee.Value) * 100 / md.RMBPrice.Value; row1["RateMoney"] = rate1.ToString("0.000") + "%"; row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += md.PersonFee.Value; // ZJMoney += md.ZJFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - md.PersonFee.Value; // escrowFee += md.escrowFee.Value; tb.Rows.Add(row1); OrderNum++; row["BuyDate"] = ""; row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["MoneyRate"] = ""; row["OffNum"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; //row["ZJMoney"] =""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.0000"); rate = 0; if (md.FactMoney != null && md.FactMoney.Value > 0) rate = (0 - dGoodsFee - dGNPostFee) * 100 / md.FactMoney.Value; row["RateMoney"] = rate.ToString("0.000") + "%"; row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["BuyDate"] = ""; row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; // row["ZJMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.0000"); rate = 0; if (md.FactMoney != null && md.FactMoney.Value > 0) rate = (0 - dGoodsFee - dGNPostFee) * 100 / md.FactMoney.Value; row["RateMoney"] = rate.ToString("0.000") + "%"; row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else OrderNum++; if ((JoinOrderCode == "" || md.JoinOrderCode != JoinOrderCode) && md.JoinOrderCode != null) { var checklist = list.FindAll(n => n.JoinOrderCode == md.JoinOrderCode && n.TotalWeight != null); if (checklist.Count() > 0) { md.TotalWeight = checklist.First().TotalWeight; md.PostFee = checklist.First().PostFee; row["TotalWeight"] = checklist.First().TotalWeight; row["PostFee"] = checklist.First().PostFee; } } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += md.PersonFee.Value; if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "" && md.TotalPrice!=null) RateMoney += md.TotalPrice.Value * md.MoneyRate.Value; // if (row["ZJMoney"] != null && row["ZJMoney"].ToString() != "") // ZJMoney += md.ZJFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; if (md.JoinOrderCode == null) JoinOrderCode = ""; else JoinOrderCode = md.JoinOrderCode; } } DataRow row2 = tb.NewRow(); row2["PostDate"] = OrderNum.ToString(); row2["TrackCode"] = "合计:"; // row2["escrowFee"] = escrowFee.ToString("0.0000"); row2["TotalPrice"] = TotalPrice.ToString("0.0000"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["ZJMoney"] ="0"; row2["PostFee"] = PostFee.ToString("0.0000"); row2["GoodsFee"] = GoodsFee.ToString("0.0000"); row2["GNPostFee"] = GNPostFee.ToString("0.0000"); row2["FactMoney"] = FactMoney.ToString("0.0000"); if(RateMoney>0) row2["RateMoney"] =(FactMoney*100/RateMoney).ToString("0.000")+"%"; else row2["RateMoney"]=""; tb.Rows.Add(row2); if (tb == null) return null; return tb.ToList(); } #endregion #region 导出利润报表 [WebMethod(EnableSession = true)] public string ExcelOrderSaleMoneyNew(string ShopIds, Decimal? PersonFee, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); if (PersonFee == null) PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); var list = obj.GetOrderSaleMoney(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var cblist = obj.GetBuyMoneyNew(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); DataTable tb = new DataTable(); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("BuyDate", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; if (list != null) { string PlatOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row = tb.NewRow(); if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.BuyDate != null) row["BuyDate"] = md.BuyDate.Value.ToString("yyyy/MM/dd"); row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.00"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); if (md.MoneyRate != null) row["MoneyRate"] = md.MoneyRate.Value.ToString("0.00"); if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); row["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) row["PostFee"] = md.PostFee.Value.ToString("0.00"); row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.00"); if (md.GoodsName.Contains("0-10") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "5"; dGoodsFee = 5; } else if (md.GoodsName.Contains("10-20") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "15"; dGoodsFee = 15; } else if (md.GoodsName.Contains("20-30") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "25"; dGoodsFee = 25; } if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.00"); if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee - 2).ToString("0.00"); row["PersonMoney"] = PersonFee.Value.ToString("f1"); var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); row1["PlatOrderCode"] = md.PlatOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] = ""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.00"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.00"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.00"); row1["GNPostFee"] = ""; row1["PersonMoney"] = PersonFee.Value.ToString("f1"); if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - PersonFee.Value).ToString("0.00"); row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += PersonFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - PersonFee.Value; tb.Rows.Add(row1); row["BuyDate"] = ""; row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["MoneyRate"] = ""; row["OffNum"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.00"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["BuyDate"] = ""; row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.00"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += PersonFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; } } DataRow row2 = tb.NewRow(); row2["TrackCode"] = "合计:"; row2["TotalPrice"] = TotalPrice.ToString("0.00"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["PostFee"] = PostFee.ToString("0.00"); row2["GoodsFee"] = GoodsFee.ToString("0.00"); row2["GNPostFee"] = GNPostFee.ToString("0.00"); row2["FactMoney"] = FactMoney.ToString("0.00"); tb.Rows.Add(row2); TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("PostDate", "发货时间", DbType.String, ""); listColumns.Add("PlatOrderCode", "订单号", DbType.String, ""); listColumns.Add("GoodsCode", "货物编号", DbType.String, ""); listColumns.Add("GoodsName", "货物名称", DbType.String, ""); listColumns.Add("BuyDate", "采购日期", DbType.String, ""); listColumns.Add("CountryName", "国家", DbType.String, ""); listColumns.Add("TypeDesc", "描述", DbType.String, ""); //listColumns.Add("OffNum", "汇率", DbType.String, ""); listColumns.Add("OffNum", "运费折扣", DbType.String, ""); listColumns.Add("TrackCode", "挂号", DbType.String, ""); listColumns.Add("GoodsNum", "数量", DbType.String, ""); listColumns.Add("TotalWeight", "重量", DbType.String, ""); listColumns.Add("TotalPrice", "总价格", DbType.String, ""); listColumns.Add("MoneyRate", "汇率", DbType.String, ""); listColumns.Add("PostFee", "实际运费", DbType.String, ""); listColumns.Add("GoodsFee", "进货价", DbType.String, ""); listColumns.Add("GNPostFee", "国内运费", DbType.String, ""); listColumns.Add("PersonMoney", "人工费", DbType.String, ""); listColumns.Add("FactMoney", "最终利润", DbType.String, ""); listColumns.Add("ErrorInfo", "异常", DbType.String, ""); listColumns.Add("PostName", "发货方式", DbType.String, ""); MicrosoftExcel obj2 = new MicrosoftExcel(); return obj2.Export(tb, listColumns); } #endregion #region 查询店铺利润合计报表 [WebMethod(EnableSession = true)] public List GetShopDayCount(List list, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); string ShopIds = ""; if (list == null ||list.Count == 0) return null; foreach (var md in list) { ShopIds += md.ShopId.ToString() + ","; } DataSet ds = obj.GetDayCountPriceCount(ShopIds.Trim(','), SDate,EDate.Value.AddDays(1)); if(ds==null) return null; DataTable tb = new DataTable(); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("OrderNum", typeof(string)); tb.Columns.Add("ShopId", typeof(string)); tb.Columns.Add("OrderDate", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GnPostFee", typeof(string)); tb.Columns.Add("BackPrice", typeof(string)); tb.Columns.Add("SalePrice", typeof(string)); TimeSpan ts = EDate.Value - SDate.Value; int days = ts.Days + 1; foreach(var md in list) { int HjTotalNum = 0; decimal HjTotalPrice = 0; decimal HjGoodsFee = 0; decimal HjPostFee = 0; decimal HjGnPostFee = 0; decimal HjBackPrice = 0; decimal HjSalePrice = 0; DataRow row1 = tb.NewRow(); row1["ShopName"] = md.ShopName; tb.Rows.Add(row1); for (int i = 0; i < days; i++) { int TotalNum = 0; decimal TotalPrice = 0; decimal GoodsFee = 0; decimal PostFee = 0; decimal BackPrice = 0; decimal SalePrice = 0; decimal GnPostFee = 0; DataRow row = tb.NewRow(); row["ShopName"] = ""; DataRow[] dr = ds.Tables[0].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr.Length > 0) { row["OrderNum"] = dr[0]["OrderNum"].ToString(); TotalNum = Convert.ToInt32(dr[0]["OrderNum"]); HjTotalNum += TotalNum; } row["OrderDate"] = SDate.Value.AddDays(i).ToString("yyyy/MM/dd"); DataRow[] dr1 = ds.Tables[1].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr1.Length > 0) { row["TotalPrice"] = Convert.ToDecimal(dr1[0]["TotalPrice"].ToString()).ToString("0.00"); TotalPrice = Convert.ToDecimal(dr1[0]["TotalPrice"]); HjTotalPrice += TotalPrice; } DataRow[] dr2 = ds.Tables[2].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr2.Length > 0) { row["GoodsFee"] = Convert.ToDecimal(dr2[0]["Price"].ToString()).ToString("0.00"); GoodsFee = Convert.ToDecimal(dr2[0]["Price"]); HjGoodsFee += GoodsFee; } DataRow[] dr3 = ds.Tables[3].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr3.Length > 0) { row["PostFee"] = Convert.ToDecimal(dr3[0]["PostPrice"].ToString()).ToString("0.00"); PostFee = Convert.ToDecimal(dr3[0]["PostPrice"]); HjPostFee += PostFee; } DataRow[] dr4 = ds.Tables[4].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr4.Length > 0) { string BackMoney = dr4[0]["BackMoney"].ToString(); row["BackPrice"] =Convert.ToDecimal( BackMoney).ToString("0.00"); BackPrice = Convert.ToDecimal(dr4[0]["BackMoney"]); HjBackPrice += BackPrice; } DataRow[] dr5 = ds.Tables[5].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr5.Length > 0) { row["GnPostFee"] = Convert.ToDecimal(dr5[0]["PostFee"].ToString()).ToString("0.00"); GnPostFee = Convert.ToDecimal(dr5[0]["PostFee"]); HjGnPostFee += GnPostFee; } SalePrice = TotalPrice - GoodsFee - PostFee - GnPostFee - BackPrice; row["SalePrice"] = SalePrice.ToString("0.00"); HjSalePrice += SalePrice; tb.Rows.Add(row); } DataRow row2 = tb.NewRow(); row2["OrderDate"] = "合计:"; row2["OrderNum"] = HjTotalNum.ToString("0.00"); row2["TotalPrice"] = HjTotalPrice.ToString("0.00"); row2["GoodsFee"] = HjGoodsFee.ToString("0.00"); row2["PostFee"] = HjPostFee.ToString("0.00"); row2["BackPrice"] = HjBackPrice.ToString("0.00"); row2["GnPostFee"] = HjGnPostFee.ToString("0.00"); row2["SalePrice"] = HjSalePrice.ToString("0.00"); tb.Rows.Add(row2); } if (tb == null) return null; return tb.ToList(); } #endregion #region 导出店铺利润合计报表 [WebMethod(EnableSession = true)] public string ExcelShopDayCount(List list, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); string ShopIds = ""; if (list == null || list.Count == 0) return ""; foreach (var md in list) { ShopIds += md.ShopId.ToString() + ","; } DataSet ds = obj.GetDayCountPriceCount(ShopIds.Trim(','), SDate, EDate.Value.AddDays(1)); if (ds == null) return null; DataTable tb = new DataTable(); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("OrderNum", typeof(string)); tb.Columns.Add("ShopId", typeof(string)); tb.Columns.Add("OrderDate", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GnPostFee", typeof(string)); tb.Columns.Add("BackPrice", typeof(string)); tb.Columns.Add("SalePrice", typeof(string)); TimeSpan ts = EDate.Value - SDate.Value; int days = ts.Days + 1; foreach (var md in list) { int HjTotalNum = 0; decimal HjTotalPrice = 0; decimal HjGoodsFee = 0; decimal HjPostFee = 0; decimal HjGnPostFee = 0; decimal HjBackPrice = 0; decimal HjSalePrice = 0; DataRow row1 = tb.NewRow(); row1["OrderDate"] = md.ShopName; tb.Rows.Add(row1); DataRow row11 = tb.NewRow(); row11["OrderDate"] = "日期"; row11["OrderNum"] = "单量"; row11["TotalPrice"] = "销售额"; row11["GoodsFee"] = "采购成本"; row11["PostFee"] = "国际运费"; row11["BackPrice"] = "赔款"; row11["GnPostFee"] = "国内运费"; row11["SalePrice"] = "利润"; tb.Rows.Add(row11); for (int i = 0; i < days; i++) { int TotalNum = 0; decimal TotalPrice = 0; decimal GoodsFee = 0; decimal PostFee = 0; decimal BackPrice = 0; decimal SalePrice = 0; decimal GnPostFee = 0; DataRow row = tb.NewRow(); row["ShopName"] = ""; DataRow[] dr = ds.Tables[0].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr.Length > 0) { row["OrderNum"] = dr[0]["OrderNum"].ToString(); TotalNum = Convert.ToInt32(dr[0]["OrderNum"]); HjTotalNum += TotalNum; } row["OrderDate"] = SDate.Value.AddDays(i).ToString("yyyy/MM/dd"); DataRow[] dr1 = ds.Tables[1].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr1.Length > 0) { row["TotalPrice"] = dr1[0]["TotalPrice"].ToString(); TotalPrice = Convert.ToDecimal(dr1[0]["TotalPrice"]); HjTotalPrice += TotalPrice; } DataRow[] dr2 = ds.Tables[2].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr2.Length > 0) { row["GoodsFee"] = dr2[0]["Price"].ToString(); GoodsFee = Convert.ToDecimal(dr2[0]["Price"]); HjGoodsFee += GoodsFee; } DataRow[] dr3 = ds.Tables[3].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr3.Length > 0) { row["PostFee"] = dr3[0]["PostPrice"].ToString(); PostFee = Convert.ToDecimal(dr3[0]["PostPrice"]); HjPostFee += PostFee; } DataRow[] dr4 = ds.Tables[4].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr4.Length > 0) { row["BackPrice"] = dr4[0]["BackMoney"].ToString(); BackPrice = Convert.ToDecimal(dr4[0]["BackMoney"]); HjBackPrice += BackPrice; } DataRow[] dr5 = ds.Tables[5].Select("shopid='" + md.ShopId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr5.Length > 0) { row["GnPostFee"] = dr5[0]["PostFee"].ToString(); GnPostFee = Convert.ToDecimal(dr5[0]["PostFee"]); HjGnPostFee += GnPostFee; } SalePrice = TotalPrice - GoodsFee - PostFee - GnPostFee - BackPrice; row["SalePrice"] = SalePrice.ToString(); HjSalePrice += SalePrice; tb.Rows.Add(row); } DataRow row2 = tb.NewRow(); row2["OrderDate"] = "合计:"; row2["OrderNum"] = HjTotalNum.ToString("0.000"); row2["TotalPrice"] = HjTotalPrice.ToString("0.000"); row2["GoodsFee"] = HjGoodsFee.ToString("0.000"); row2["PostFee"] = HjPostFee.ToString("0.000"); row2["BackPrice"] = HjBackPrice.ToString("0.000"); row2["GnPostFee"] = HjGnPostFee.ToString("0.000"); row2["SalePrice"] = HjSalePrice.ToString("0.000"); tb.Rows.Add(row2); DataRow row3 = tb.NewRow(); row3["OrderDate"] = "调整金额:"; tb.Rows.Add(row3); DataRow row4 = tb.NewRow(); row4["OrderDate"] = "最终数据:"; tb.Rows.Add(row4); DataRow row5 = tb.NewRow(); row5["OrderDate"] = ""; tb.Rows.Add(row5); row5 = tb.NewRow(); tb.Rows.Add(row5); } if (tb == null) return ""; TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("OrderDate", "", DbType.String, ""); listColumns.Add("OrderNum", "", DbType.String, ""); listColumns.Add("TotalPrice", "", DbType.String, ""); listColumns.Add("PostFee", "", DbType.String, ""); listColumns.Add("GoodsFee", "", DbType.String, ""); listColumns.Add("GnPostFee", "", DbType.String, ""); listColumns.Add("BackPrice", "", DbType.String, ""); listColumns.Add("SalePrice", "", DbType.String, ""); MicrosoftExcel obj2 = new MicrosoftExcel(); return obj2.Export(tb, listColumns); } #endregion #region 查询部门利润合计报表 [WebMethod(EnableSession = true)] public List GetDeptDayCount(List list, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); string DeptIds = ""; if (list == null || list.Count == 0) return null; foreach (var md in list) { DeptIds += md.DeptId.ToString() + ","; } DataSet ds = obj.GetDayDeptCountPriceCount(DeptIds.Trim(','), SDate, EDate.Value.AddDays(1)); if (ds == null) return null; DataTable tb = new DataTable(); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("OrderNum", typeof(string)); tb.Columns.Add("ShopId", typeof(string)); tb.Columns.Add("OrderDate", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GnPostFee", typeof(string)); tb.Columns.Add("BackPrice", typeof(string)); tb.Columns.Add("SalePrice", typeof(string)); TimeSpan ts = EDate.Value - SDate.Value; int days = ts.Days + 1; foreach (var md in list) { int HjTotalNum = 0; decimal HjTotalPrice = 0; decimal HjGoodsFee = 0; decimal HjPostFee = 0; decimal HjGnPostFee = 0; decimal HjBackPrice = 0; decimal HjSalePrice = 0; DataRow row1 = tb.NewRow(); row1["ShopName"] = md.DeptName; tb.Rows.Add(row1); for (int i = 0; i < days; i++) { int TotalNum = 0; decimal TotalPrice = 0; decimal GoodsFee = 0; decimal PostFee = 0; decimal BackPrice = 0; decimal SalePrice = 0; decimal GnPostFee = 0; DataRow row = tb.NewRow(); row["ShopName"] = ""; DataRow[] dr = ds.Tables[0].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr.Length > 0) { row["OrderNum"] = dr[0]["OrderNum"].ToString(); TotalNum = Convert.ToInt32(dr[0]["OrderNum"]); HjTotalNum += TotalNum; } row["OrderDate"] = SDate.Value.AddDays(i).ToString("yyyy/MM/dd"); DataRow[] dr1 = ds.Tables[1].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr1.Length > 0) { row["TotalPrice"] = dr1[0]["TotalPrice"].ToString(); TotalPrice = Convert.ToDecimal(dr1[0]["TotalPrice"]); HjTotalPrice += TotalPrice; } DataRow[] dr2 = ds.Tables[2].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr2.Length > 0) { row["GoodsFee"] = dr2[0]["Price"].ToString(); GoodsFee = Convert.ToDecimal(dr2[0]["Price"]); HjGoodsFee += GoodsFee; } DataRow[] dr3 = ds.Tables[3].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr3.Length > 0) { row["PostFee"] = dr3[0]["PostPrice"].ToString(); PostFee = Convert.ToDecimal(dr3[0]["PostPrice"]); HjPostFee += PostFee; } DataRow[] dr4 = ds.Tables[4].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr4.Length > 0) { row["BackPrice"] = dr4[0]["BackMoney"].ToString(); BackPrice = Convert.ToDecimal(dr4[0]["BackMoney"]); HjBackPrice += BackPrice; } DataRow[] dr5 = ds.Tables[5].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr5.Length > 0) { row["GnPostFee"] = dr5[0]["PostFee"].ToString(); GnPostFee = Convert.ToDecimal(dr5[0]["PostFee"]); HjGnPostFee += GnPostFee; } SalePrice = TotalPrice - GoodsFee - PostFee - GnPostFee - BackPrice; row["SalePrice"] = SalePrice.ToString(); HjSalePrice += SalePrice; tb.Rows.Add(row); } DataRow row2 = tb.NewRow(); row2["OrderDate"] = "合计:"; row2["OrderNum"] = HjTotalNum.ToString("0.000"); row2["TotalPrice"] = HjTotalPrice.ToString("0.000"); row2["GoodsFee"] = HjGoodsFee.ToString("0.000"); row2["PostFee"] = HjPostFee.ToString("0.000"); row2["BackPrice"] = HjBackPrice.ToString("0.000"); row2["GnPostFee"] = HjGnPostFee.ToString("0.000"); row2["SalePrice"] = HjSalePrice.ToString("0.000"); tb.Rows.Add(row2); } if (tb == null) return null; return tb.ToList(); } #endregion #region 导出部门利润合计报表 [WebMethod(EnableSession = true)] public string ExcelDeptDayCount(List list, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); string DeptIds = ""; if (list == null || list.Count == 0) return null; foreach (var md in list) { DeptIds += md.DeptId.ToString() + ","; } DataSet ds = obj.GetDayDeptCountPriceCount(DeptIds.Trim(','), SDate, EDate.Value.AddDays(1)); if (ds == null) return null; DataTable tb = new DataTable(); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("OrderNum", typeof(string)); tb.Columns.Add("ShopId", typeof(string)); tb.Columns.Add("OrderDate", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GnPostFee", typeof(string)); tb.Columns.Add("BackPrice", typeof(string)); tb.Columns.Add("SalePrice", typeof(string)); TimeSpan ts = EDate.Value - SDate.Value; int days = ts.Days + 1; foreach (var md in list) { int HjTotalNum = 0; decimal HjTotalPrice = 0; decimal HjGoodsFee = 0; decimal HjPostFee = 0; decimal HjGnPostFee = 0; decimal HjBackPrice = 0; decimal HjSalePrice = 0; DataRow row1 = tb.NewRow(); row1["OrderDate"] = md.DeptName; tb.Rows.Add(row1); DataRow row11 = tb.NewRow(); row11["OrderDate"] = "日期"; row11["OrderNum"] = "单量"; row11["TotalPrice"] = "销售额"; row11["GoodsFee"] = "采购成本"; row11["PostFee"] = "国际运费"; row11["BackPrice"] = "赔款"; row11["GnPostFee"] = "国内运费"; row11["SalePrice"] = "利润"; tb.Rows.Add(row11); for (int i = 0; i < days; i++) { int TotalNum = 0; decimal TotalPrice = 0; decimal GoodsFee = 0; decimal PostFee = 0; decimal BackPrice = 0; decimal SalePrice = 0; decimal GnPostFee = 0; DataRow row = tb.NewRow(); row["ShopName"] = ""; DataRow[] dr = ds.Tables[0].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr.Length > 0) { row["OrderNum"] = dr[0]["OrderNum"].ToString(); TotalNum = Convert.ToInt32(dr[0]["OrderNum"]); HjTotalNum += TotalNum; } row["OrderDate"] = SDate.Value.AddDays(i).ToString("yyyy/MM/dd"); DataRow[] dr1 = ds.Tables[1].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr1.Length > 0) { row["TotalPrice"] = dr1[0]["TotalPrice"].ToString(); TotalPrice = Convert.ToDecimal(dr1[0]["TotalPrice"]); HjTotalPrice += TotalPrice; } DataRow[] dr2 = ds.Tables[2].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr2.Length > 0) { row["GoodsFee"] = dr2[0]["Price"].ToString(); GoodsFee = Convert.ToDecimal(dr2[0]["Price"]); HjGoodsFee += GoodsFee; } DataRow[] dr3 = ds.Tables[3].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr3.Length > 0) { row["PostFee"] = dr3[0]["PostPrice"].ToString(); PostFee = Convert.ToDecimal(dr3[0]["PostPrice"]); HjPostFee += PostFee; } DataRow[] dr4 = ds.Tables[4].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr4.Length > 0) { row["BackPrice"] = dr4[0]["BackMoney"].ToString(); BackPrice = Convert.ToDecimal(dr4[0]["BackMoney"]); HjBackPrice += BackPrice; } DataRow[] dr5 = ds.Tables[5].Select("DeptId='" + md.DeptId + "' and PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr5.Length > 0) { row["GnPostFee"] = dr5[0]["PostFee"].ToString(); GnPostFee = Convert.ToDecimal(dr5[0]["PostFee"]); HjGnPostFee += GnPostFee; } SalePrice = TotalPrice - GoodsFee - PostFee - GnPostFee - BackPrice; row["SalePrice"] = SalePrice.ToString(); HjSalePrice += SalePrice; tb.Rows.Add(row); } DataRow row2 = tb.NewRow(); row2["OrderDate"] = "合计:"; row2["OrderNum"] = HjTotalNum.ToString("0.000"); row2["TotalPrice"] = HjTotalPrice.ToString("0.000"); row2["GoodsFee"] = HjGoodsFee.ToString("0.000"); row2["PostFee"] = HjPostFee.ToString("0.000"); row2["BackPrice"] = HjBackPrice.ToString("0.000"); row2["GnPostFee"] = HjGnPostFee.ToString("0.000"); row2["SalePrice"] = HjSalePrice.ToString("0.000"); tb.Rows.Add(row2); DataRow row3 = tb.NewRow(); row3["OrderDate"] = "调整金额:"; tb.Rows.Add(row3); DataRow row4 = tb.NewRow(); row4["OrderDate"] = "最终数据:"; tb.Rows.Add(row4); DataRow row5 = tb.NewRow(); row5["OrderDate"] = ""; tb.Rows.Add(row5); row5 = tb.NewRow(); tb.Rows.Add(row5); } if (tb == null) return ""; TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("OrderDate", "", DbType.String, ""); listColumns.Add("OrderNum", "", DbType.String, ""); listColumns.Add("TotalPrice", "", DbType.String, ""); listColumns.Add("PostFee", "", DbType.String, ""); listColumns.Add("GoodsFee", "", DbType.String, ""); listColumns.Add("GnPostFee", "", DbType.String, ""); listColumns.Add("BackPrice", "", DbType.String, ""); listColumns.Add("SalePrice", "", DbType.String, ""); MicrosoftExcel obj2 = new MicrosoftExcel(); return obj2.Export(tb, listColumns); } #endregion #region 查询公司利润合计报表 [WebMethod(EnableSession = true)] public List GetCompanyDayCount(DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); DataSet ds = obj.GetDayCompanyCountPriceCount(CompanyId, SDate, EDate.Value.AddDays(1)); if (ds == null) return null; DataTable tb = new DataTable(); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("OrderNum", typeof(string)); tb.Columns.Add("ShopId", typeof(string)); tb.Columns.Add("OrderDate", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GnPostFee", typeof(string)); tb.Columns.Add("BackPrice", typeof(string)); tb.Columns.Add("SalePrice", typeof(string)); TimeSpan ts = EDate.Value - SDate.Value; int days = ts.Days + 1; int HjTotalNum = 0; decimal HjTotalPrice = 0; decimal HjGoodsFee = 0; decimal HjPostFee = 0; decimal HjGnPostFee = 0; decimal HjBackPrice = 0; decimal HjSalePrice = 0; DataRow row1 = tb.NewRow(); row1["ShopName"] = SDate.Value.ToString("MM/dd") + "-" + EDate.Value.ToString("MM/dd") + "公司利润"; tb.Rows.Add(row1); for (int i = 0; i < days; i++) { int TotalNum = 0; decimal TotalPrice = 0; decimal GoodsFee = 0; decimal PostFee = 0; decimal BackPrice = 0; decimal SalePrice = 0; decimal GnPostFee = 0; DataRow row = tb.NewRow(); row["ShopName"] = ""; DataRow[] dr = ds.Tables[0].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr.Length > 0) { row["OrderNum"] = dr[0]["OrderNum"].ToString(); TotalNum = Convert.ToInt32(dr[0]["OrderNum"]); HjTotalNum += TotalNum; } row["OrderDate"] = SDate.Value.AddDays(i).ToString("yyyy/MM/dd"); DataRow[] dr1 = ds.Tables[1].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr1.Length > 0) { row["TotalPrice"] = dr1[0]["TotalPrice"].ToString(); TotalPrice = Convert.ToDecimal(dr1[0]["TotalPrice"]); HjTotalPrice += TotalPrice; } DataRow[] dr2 = ds.Tables[2].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr2.Length > 0) { row["GoodsFee"] = dr2[0]["Price"].ToString(); GoodsFee = Convert.ToDecimal(dr2[0]["Price"]); HjGoodsFee += GoodsFee; } DataRow[] dr3 = ds.Tables[3].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr3.Length > 0) { row["PostFee"] = dr3[0]["PostPrice"].ToString(); PostFee = Convert.ToDecimal(dr3[0]["PostPrice"]); HjPostFee += PostFee; } DataRow[] dr4 = ds.Tables[4].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr4.Length > 0) { row["BackPrice"] = dr4[0]["BackMoney"].ToString(); BackPrice = Convert.ToDecimal(dr4[0]["BackMoney"]); HjBackPrice += BackPrice; } DataRow[] dr5 = ds.Tables[5].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr5.Length > 0) { row["GnPostFee"] = dr5[0]["PostFee"].ToString(); GnPostFee = Convert.ToDecimal(dr5[0]["PostFee"]); HjGnPostFee += GnPostFee; } SalePrice = TotalPrice - GoodsFee - PostFee - GnPostFee - BackPrice; row["SalePrice"] = SalePrice.ToString(); HjSalePrice += SalePrice; tb.Rows.Add(row); } DataRow row2 = tb.NewRow(); row2["OrderDate"] = "合计:"; row2["OrderNum"] = HjTotalNum.ToString("0.000"); row2["TotalPrice"] = HjTotalPrice.ToString("0.000"); row2["GoodsFee"] = HjGoodsFee.ToString("0.000"); row2["PostFee"] = HjPostFee.ToString("0.000"); row2["BackPrice"] = HjBackPrice.ToString("0.000"); row2["GnPostFee"] = HjGnPostFee.ToString("0.000"); row2["SalePrice"] = HjSalePrice.ToString("0.000"); tb.Rows.Add(row2); if (tb == null) return null; return tb.ToList(); } #endregion #region 导出公司利润合计报表 [WebMethod(EnableSession = true)] public string ExcelCompanyDayCount(DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); DataSet ds = obj.GetDayCompanyCountPriceCount(CompanyId, SDate, EDate.Value.AddDays(1)); if (ds == null) return null; DataTable tb = new DataTable(); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("OrderNum", typeof(string)); tb.Columns.Add("ShopId", typeof(string)); tb.Columns.Add("OrderDate", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GnPostFee", typeof(string)); tb.Columns.Add("BackPrice", typeof(string)); tb.Columns.Add("SalePrice", typeof(string)); TimeSpan ts = EDate.Value - SDate.Value; int days = ts.Days + 1; int HjTotalNum = 0; decimal HjTotalPrice = 0; decimal HjGoodsFee = 0; decimal HjPostFee = 0; decimal HjGnPostFee = 0; decimal HjBackPrice = 0; decimal HjSalePrice = 0; DataRow row1 = tb.NewRow(); row1["OrderDate"] = SDate.Value.ToString("MM/dd") + "-" + EDate.Value.ToString("MM/dd") + "公司利润"; tb.Rows.Add(row1); DataRow row11 = tb.NewRow(); row11["OrderDate"] = "日期"; row11["OrderNum"] = "单量"; row11["TotalPrice"] = "销售额"; row11["GoodsFee"] = "采购成本"; row11["PostFee"] = "国际运费"; row11["BackPrice"] = "赔款"; row11["GnPostFee"] = "国内运费"; row11["SalePrice"] = "利润"; tb.Rows.Add(row11); for (int i = 0; i < days; i++) { int TotalNum = 0; decimal TotalPrice = 0; decimal GoodsFee = 0; decimal PostFee = 0; decimal BackPrice = 0; decimal SalePrice = 0; decimal GnPostFee = 0; DataRow row = tb.NewRow(); row["ShopName"] = ""; DataRow[] dr = ds.Tables[0].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr.Length > 0) { row["OrderNum"] = dr[0]["OrderNum"].ToString(); TotalNum = Convert.ToInt32(dr[0]["OrderNum"]); HjTotalNum += TotalNum; } row["OrderDate"] = SDate.Value.AddDays(i).ToString("yyyy/MM/dd"); DataRow[] dr1 = ds.Tables[1].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr1.Length > 0) { row["TotalPrice"] = dr1[0]["TotalPrice"].ToString(); TotalPrice = Convert.ToDecimal(dr1[0]["TotalPrice"]); HjTotalPrice += TotalPrice; } DataRow[] dr2 = ds.Tables[2].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr2.Length > 0) { row["GoodsFee"] = dr2[0]["Price"].ToString(); GoodsFee = Convert.ToDecimal(dr2[0]["Price"]); HjGoodsFee += GoodsFee; } DataRow[] dr3 = ds.Tables[3].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr3.Length > 0) { row["PostFee"] = dr3[0]["PostPrice"].ToString(); PostFee = Convert.ToDecimal(dr3[0]["PostPrice"]); HjPostFee += PostFee; } DataRow[] dr4 = ds.Tables[4].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr4.Length > 0) { row["BackPrice"] = dr4[0]["BackMoney"].ToString(); BackPrice = Convert.ToDecimal(dr4[0]["BackMoney"]); HjBackPrice += BackPrice; } DataRow[] dr5 = ds.Tables[5].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); if (dr5.Length > 0) { row["GnPostFee"] = dr5[0]["PostFee"].ToString(); GnPostFee = Convert.ToDecimal(dr5[0]["PostFee"]); HjGnPostFee += GnPostFee; } SalePrice = TotalPrice - GoodsFee - PostFee - GnPostFee - BackPrice; row["SalePrice"] = SalePrice.ToString(); HjSalePrice += SalePrice; tb.Rows.Add(row); } DataRow row2 = tb.NewRow(); row2["OrderDate"] = "合计:"; row2["OrderNum"] = HjTotalNum.ToString("0.000"); row2["TotalPrice"] = HjTotalPrice.ToString("0.000"); row2["GoodsFee"] = HjGoodsFee.ToString("0.000"); row2["PostFee"] = HjPostFee.ToString("0.000"); row2["BackPrice"] = HjBackPrice.ToString("0.000"); row2["GnPostFee"] = HjGnPostFee.ToString("0.000"); row2["SalePrice"] = HjSalePrice.ToString("0.000"); tb.Rows.Add(row2); DataRow row3 = tb.NewRow(); row3["OrderDate"] = "调整金额:"; tb.Rows.Add(row3); DataRow row4 = tb.NewRow(); row4["OrderDate"] = "最终数据:"; tb.Rows.Add(row4); if (tb == null) return ""; TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("OrderDate", "", DbType.String, ""); listColumns.Add("OrderNum", "", DbType.String, ""); listColumns.Add("TotalPrice", "", DbType.String, ""); listColumns.Add("PostFee", "", DbType.String, ""); listColumns.Add("GoodsFee", "", DbType.String, ""); listColumns.Add("GnPostFee", "", DbType.String, ""); listColumns.Add("BackPrice", "", DbType.String, ""); listColumns.Add("SalePrice", "", DbType.String, ""); MicrosoftExcel obj2 = new MicrosoftExcel(); return obj2.Export(tb, listColumns); } #endregion #region 修改利润 [WebMethod(EnableSession = true)] public void UpdateOrderSale(int Id, decimal? PostFee, decimal? escrowFee, decimal? GNPostFee, decimal? Price) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); obj.UpdateOrderSale(Id, PostFee, escrowFee, GNPostFee, Price); } #endregion #region 导出利润报表 [WebMethod(EnableSession = true)] public string ExcelOrderSaleMoneyForTM(string ShopIds, Decimal? PersonFee, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var obj = new DD_OrderData(); var list = obj.GetOrderSaleMoneyForTM(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var cblist = obj.GetBuyMoneyNew(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); DataTable tb = new DataTable(); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("escrowFee", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; decimal escrowFee = 0; if (list != null && cblist != null) { string PlatOrderCode = ""; string JoinOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row = tb.NewRow(); row["ShopName"] = md.ShopName; if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row["PlatOrderCode"] = md.JoinOrderCode; else row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.000"); row["escrowFee"] = md.escrowFee.Value.ToString("0.000"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); if (md.MoneyRate != null) row["MoneyRate"] = md.MoneyRate.Value.ToString("0.000"); if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); row["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) row["PostFee"] = md.PostFee.Value.ToString("0.000"); md.FactMoney = md.RMBPrice - md.escrowFee.Value - md.PostFee.Value * md.OffNum / 10; row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.000"); if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.000"); row["PersonMoney"] = md.PersonFee.Value.ToString("f1"); if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee - md.PersonFee.Value).ToString("0.00"); var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (JoinOrderCode != "" && md.JoinOrderCode == JoinOrderCode) { row["TrackCode"] = ""; row["TotalWeight"] = "0"; row["PostFee"] = 0; md.PostFee = 0; md.TotalWeight = 0; row["PersonMoney"] = 0; md.PersonFee = 0; row["FactMoney"] = (md.RMBPrice.Value - md.escrowFee.Value - dGoodsFee - dGNPostFee).ToString("0.00"); } if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); row1["ShopName"] = md.ShopName; if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row1["PlatOrderCode"] = md.JoinOrderCode; else row1["PlatOrderCode"] = md.PlatOrderCode; //if (md.JoinOrderCode!=null) //row1["JoinOrderCode"] = md.JoinOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] = ""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.000"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); row1["escrowFee"] = md.escrowFee.Value.ToString("0.000"); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.000"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.000"); row1["GNPostFee"] = ""; row1["PersonMoney"] = md.PersonFee.Value.ToString("f1"); if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - md.PersonFee.Value).ToString("0.00"); row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += md.PersonFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - md.PersonFee.Value; escrowFee += md.escrowFee.Value; tb.Rows.Add(row1); row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["MoneyRate"] = ""; row["OffNum"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += md.PersonFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; if (md.JoinOrderCode == null) JoinOrderCode = ""; else JoinOrderCode = md.JoinOrderCode; } } DataRow row2 = tb.NewRow(); row2["TrackCode"] = "合计:"; row2["escrowFee"] = escrowFee.ToString("0.000"); row2["TotalPrice"] = TotalPrice.ToString("0.000"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["PostFee"] = PostFee.ToString("0.000"); row2["GoodsFee"] = GoodsFee.ToString("0.000"); row2["GNPostFee"] = GNPostFee.ToString("0.000"); row2["FactMoney"] = FactMoney.ToString("0.000"); tb.Rows.Add(row2); TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("ShopName", "店铺", DbType.String, ""); listColumns.Add("PostDate", "发货时间", DbType.String, ""); listColumns.Add("PlatOrderCode", "订单号", DbType.String, ""); listColumns.Add("GoodsCode", "货物编号", DbType.String, ""); listColumns.Add("GoodsName", "货物名称", DbType.String, ""); listColumns.Add("CountryName", "国家", DbType.String, ""); listColumns.Add("TypeDesc", "描述", DbType.String, ""); //listColumns.Add("OffNum", "汇率", DbType.String, ""); listColumns.Add("OffNum", "运费折扣", DbType.String, ""); listColumns.Add("TrackCode", "挂号", DbType.String, ""); listColumns.Add("GoodsNum", "数量", DbType.String, ""); listColumns.Add("TotalWeight", "重量", DbType.String, ""); listColumns.Add("TotalPrice", "总价格", DbType.String, ""); listColumns.Add("escrowFee", "平台佣金", DbType.String, ""); listColumns.Add("MoneyRate", "汇率", DbType.String, ""); listColumns.Add("PostFee", "实际运费", DbType.String, ""); listColumns.Add("GoodsFee", "进货价", DbType.String, ""); listColumns.Add("GNPostFee", "国内运费", DbType.String, ""); listColumns.Add("PersonMoney", "人工费", DbType.String, ""); listColumns.Add("FactMoney", "最终利润", DbType.String, ""); listColumns.Add("ErrorInfo", "异常", DbType.String, ""); listColumns.Add("PostName", "发货方式", DbType.String, ""); MicrosoftExcel obj2 = new MicrosoftExcel(); return obj2.Export(tb, listColumns); } #endregion #region 导出利润报表 [WebMethod(EnableSession = true)] public string ExcelOrderSaleMoneyForTM2(string ShopIds, Decimal? PersonFee, DateTime? SDate, DateTime? EDate,string GoodsCode) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int ShopId = 0; if (ShopIds != "") ShopId = Convert.ToInt32(ShopIds.Split(',')[0]); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var moneylist = obj.GetMoneyList(ShopId); var list = obj.GetOrderSaleMoneyForTM2(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','),GoodsCode.Trim(),CompanyId); var cblist = obj.GetBuyMoneyNew(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var tracklist = obj.GetTrackCodeList(ShopIds.TrimEnd(','), SDate, EDate.Value.AddDays(1)); DataTable tb = new DataTable(); tb.Columns.Add("Id", typeof(Int32)); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("escrowFee", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; decimal escrowFee = 0; int OrderNum = 0; if (list != null && cblist != null) { string PlatOrderCode = ""; string JoinOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row = tb.NewRow(); row["Id"] = md.Id; row["ShopName"] = md.ShopName; if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row["PlatOrderCode"] = md.JoinOrderCode; else row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); //row["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); var moneymd = moneylist.Find(n => n.PlatId == md.PlatId && n.MCode == md.MoneyCode); if (moneymd != null) { md.RMBPrice = md.TotalPrice * moneymd.MRate.Value; md.MoneyRate = moneymd.MRate; row["MoneyRate"] = moneymd.MRate.Value.ToString("0.00000"); } else { row["MoneyRate"] = "1"; md.RMBPrice = md.TotalPrice; } if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); string tcode = ""; if (md.JoinOrderCode != null && md.JoinOrderCode != "") { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.JoinOrderCode == md.JoinOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + ","; } } } } else { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.OrderCode == md.PlatOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + ","; } } } } tcode = tcode.Trim(','); md.TrackCode = tcode; row["TrackCode"] = tcode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) { md.PostFee = md.PostFee.Value * md.OffNum / 10; row["PostFee"] = md.PostFee.Value.ToString("0.0000"); } else md.PostFee = 0; md.FactMoney = md.RMBPrice - md.PostFee.Value; row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.0000"); if (md.GoodsName.Contains("0-10") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "5"; dGoodsFee = 5; } else if (md.GoodsName.Contains("10-20") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "15"; dGoodsFee = 15; } else if (md.GoodsName.Contains("20-30") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "25"; dGoodsFee = 25; } if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.0000"); row["PersonMoney"] = md.PersonFee.Value.ToString("f1"); if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee - md.PersonFee.Value).ToString("0.00"); var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (JoinOrderCode != "" && md.JoinOrderCode == JoinOrderCode) { row["TrackCode"] = ""; row["TotalWeight"] = "0"; row["PostFee"] = 0; md.PostFee = 0; md.TotalWeight = 0; row["PersonMoney"] = 0; md.PersonFee = 0; row["FactMoney"] = (md.RMBPrice.Value - dGoodsFee - dGNPostFee).ToString("0.00"); } if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); row1["Id"] = md.Id; row1["ShopName"] = md.ShopName; if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row1["PlatOrderCode"] = md.JoinOrderCode; else row1["PlatOrderCode"] = md.PlatOrderCode; //if (md.JoinOrderCode!=null) //row1["JoinOrderCode"] = md.JoinOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] = ""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); // row1["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.00000"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.0000"); row1["GNPostFee"] = ""; row1["PersonMoney"] = md.PersonFee.Value.ToString("f1"); if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - md.PersonFee.Value).ToString("0.00"); row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += md.PersonFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - md.PersonFee.Value; // escrowFee += md.escrowFee.Value; tb.Rows.Add(row1); OrderNum++; row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["MoneyRate"] = ""; row["OffNum"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.0000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.0000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else OrderNum++; if ((JoinOrderCode == "" || md.JoinOrderCode != JoinOrderCode) && md.JoinOrderCode != null) { var checklist = list.FindAll(n => n.JoinOrderCode == md.JoinOrderCode && n.TotalWeight != null); if (checklist.Count() > 0) { md.TotalWeight = checklist.First().TotalWeight; md.PostFee = checklist.First().PostFee; row["TotalWeight"] = checklist.First().TotalWeight; row["PostFee"] = checklist.First().PostFee; } } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += md.PersonFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; if (md.JoinOrderCode == null) JoinOrderCode = ""; else JoinOrderCode = md.JoinOrderCode; } } DataRow row2 = tb.NewRow(); row2["PostDate"] = OrderNum.ToString(); row2["TrackCode"] = "合计:"; // row2["escrowFee"] = escrowFee.ToString("0.0000"); row2["TotalPrice"] = TotalPrice.ToString("0.0000"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["PostFee"] = PostFee.ToString("0.0000"); row2["GoodsFee"] = GoodsFee.ToString("0.0000"); row2["GNPostFee"] = GNPostFee.ToString("0.0000"); row2["FactMoney"] = FactMoney.ToString("0.0000"); tb.Rows.Add(row2); TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("ShopName", "店铺", DbType.String, ""); listColumns.Add("PostDate", "发货时间", DbType.String, ""); listColumns.Add("PlatOrderCode", "订单号", DbType.String, ""); listColumns.Add("GoodsCode", "货物编号", DbType.String, ""); listColumns.Add("GoodsName", "货物名称", DbType.String, ""); listColumns.Add("CountryName", "国家", DbType.String, ""); listColumns.Add("TypeDesc", "描述", DbType.String, ""); //listColumns.Add("OffNum", "汇率", DbType.String, ""); listColumns.Add("OffNum", "运费折扣", DbType.String, ""); listColumns.Add("TrackCode", "挂号", DbType.String, ""); listColumns.Add("GoodsNum", "数量", DbType.String, ""); listColumns.Add("TotalWeight", "重量", DbType.String, ""); listColumns.Add("TotalPrice", "总价格", DbType.Decimal, ""); //listColumns.Add("escrowFee", "平台佣金", DbType.String, ""); listColumns.Add("MoneyRate", "汇率", DbType.String, ""); listColumns.Add("PostFee", "实际运费", DbType.Decimal, ""); listColumns.Add("GoodsFee", "进货价", DbType.Decimal, ""); listColumns.Add("GNPostFee", "国内运费", DbType.Decimal, ""); listColumns.Add("PersonMoney", "人工费", DbType.Decimal, ""); listColumns.Add("FactMoney", "最终利润", DbType.Decimal, ""); listColumns.Add("ErrorInfo", "异常", DbType.String, ""); listColumns.Add("PostName", "发货方式", DbType.String, ""); MicrosoftExcel obj2 = new MicrosoftExcel(); return obj2.Export(tb, listColumns); } #endregion #region 导出利润报表 [WebMethod(EnableSession = true)] public string ExcelOrderSaleMoneyForTM3(string ShopIds, Decimal? PersonFee, DateTime? SDate, DateTime? EDate, string GoodsCode) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int ShopId = 0; if (ShopIds != "") ShopId = Convert.ToInt32(ShopIds.Split(',')[0]); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var moneylist = obj.GetMoneyList(ShopId); var list = obj.GetOrderSaleMoneyForTM3(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), GoodsCode.Trim(), CompanyId); var cblist = obj.GetBuyMoneyNew(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var tracklist = obj.GetTrackCodeList(ShopIds.TrimEnd(','), SDate, EDate.Value.AddDays(1)); DataTable tb = new DataTable(); tb.Columns.Add("Id", typeof(Int32)); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("BuyDate", typeof(string)); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("escrowFee", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("ZJMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; decimal ZJMoney = 0; decimal escrowFee = 0; int OrderNum = 0; if (list != null && cblist != null) { string PlatOrderCode = ""; string JoinOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row = tb.NewRow(); row["Id"] = md.Id; row["ShopName"] = md.ShopName; if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.BuyDate != null) row["BuyDate"] = md.BuyDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row["PlatOrderCode"] = md.JoinOrderCode; else row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); //row["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); var moneymd = moneylist.Find(n => n.PlatId == md.PlatId && n.MCode == md.MoneyCode); if (moneymd != null) { md.RMBPrice = md.TotalPrice * moneymd.MRate.Value; md.MoneyRate = moneymd.MRate; row["MoneyRate"] = moneymd.MRate.Value.ToString("0.00000"); } else { row["MoneyRate"] = "1"; md.RMBPrice = md.TotalPrice; } if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); string tcode = ""; if (md.JoinOrderCode != null && md.JoinOrderCode != "") { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.JoinOrderCode == md.JoinOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + "
"; } } } } else { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.OrderCode == md.PlatOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + "
"; } } } } md.TrackCode = tcode; row["TrackCode"] = tcode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) { md.PostFee = md.PostFee.Value * md.OffNum / 10; row["PostFee"] = md.PostFee.Value.ToString("0.0000"); } else md.PostFee = 0; md.FactMoney = md.RMBPrice - md.PostFee.Value; row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.0000"); if (md.GoodsName.Contains("0-10") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "5"; dGoodsFee = 5; } else if (md.GoodsName.Contains("10-20") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "15"; dGoodsFee = 15; } else if (md.GoodsName.Contains("20-30") && md.GoodsName.Contains("礼物")) { row["GoodsFee"] = "25"; dGoodsFee = 25; } if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.0000"); row["PersonMoney"] = md.PersonFee.Value.ToString("f1"); row["ZJMoney"] = md.ZJFee.Value.ToString("f1"); if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee - md.PersonFee.Value - md.ZJFee.Value).ToString("0.00"); var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (JoinOrderCode != "" && md.JoinOrderCode == JoinOrderCode) { row["TrackCode"] = ""; row["TotalWeight"] = "0"; row["PostFee"] = 0; md.PostFee = 0; md.TotalWeight = 0; row["PersonMoney"] = 0; row["ZJMoney"] = 0; md.PersonFee = 0; row["FactMoney"] = (md.RMBPrice.Value - dGoodsFee - dGNPostFee).ToString("0.00"); } if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); row1["Id"] = md.Id; row1["ShopName"] = md.ShopName; if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.BuyDate != null) row1["BuyDate"] = md.BuyDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row1["PlatOrderCode"] = md.JoinOrderCode; else row1["PlatOrderCode"] = md.PlatOrderCode; //if (md.JoinOrderCode!=null) //row1["JoinOrderCode"] = md.JoinOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] = ""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); // row1["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.00000"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.0000"); row1["GNPostFee"] = ""; row1["PersonMoney"] = md.PersonFee.Value.ToString("f1"); row1["ZJMoney"] = ""; if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - md.PersonFee.Value).ToString("0.00"); row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += md.PersonFee.Value; ZJMoney += md.ZJFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - md.PersonFee.Value; // escrowFee += md.escrowFee.Value; tb.Rows.Add(row1); OrderNum++; row["BuyDate"] = ""; row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["MoneyRate"] = ""; row["OffNum"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; //row["ZJMoney"] =""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee - md.ZJFee.Value).ToString("0.0000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; // row["ZJMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee - md.ZJFee.Value).ToString("0.0000"); row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else OrderNum++; if ((JoinOrderCode == "" || md.JoinOrderCode != JoinOrderCode) && md.JoinOrderCode != null) { var checklist = list.FindAll(n => n.JoinOrderCode == md.JoinOrderCode && n.TotalWeight != null); if (checklist.Count() > 0) { md.TotalWeight = checklist.First().TotalWeight; md.PostFee = checklist.First().PostFee; row["TotalWeight"] = checklist.First().TotalWeight; row["PostFee"] = checklist.First().PostFee; } } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += md.PersonFee.Value; if (row["ZJMoney"] != null && row["ZJMoney"].ToString() != "") ZJMoney += md.ZJFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; if (md.JoinOrderCode == null) JoinOrderCode = ""; else JoinOrderCode = md.JoinOrderCode; } } DataRow row2 = tb.NewRow(); row2["PostDate"] = OrderNum.ToString(); row2["TrackCode"] = "合计:"; // row2["escrowFee"] = escrowFee.ToString("0.0000"); row2["TotalPrice"] = TotalPrice.ToString("0.0000"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["ZJMoney"] = ZJMoney.ToString("0"); row2["PostFee"] = PostFee.ToString("0.0000"); row2["GoodsFee"] = GoodsFee.ToString("0.0000"); row2["GNPostFee"] = GNPostFee.ToString("0.0000"); row2["FactMoney"] = FactMoney.ToString("0.0000"); tb.Rows.Add(row2); TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("ShopName", "店铺", DbType.String, ""); listColumns.Add("PostDate", "发货时间", DbType.String, ""); listColumns.Add("PlatOrderCode", "订单号", DbType.String, ""); listColumns.Add("GoodsCode", "货物编号", DbType.String, ""); listColumns.Add("GoodsName", "货物名称", DbType.String, ""); listColumns.Add("BuyDate", "采购日期", DbType.String, ""); listColumns.Add("CountryName", "国家", DbType.String, ""); listColumns.Add("TypeDesc", "描述", DbType.String, ""); //listColumns.Add("OffNum", "汇率", DbType.String, ""); listColumns.Add("OffNum", "运费折扣", DbType.String, ""); listColumns.Add("TrackCode", "挂号", DbType.String, ""); listColumns.Add("GoodsNum", "数量", DbType.String, ""); listColumns.Add("TotalWeight", "重量", DbType.String, ""); listColumns.Add("TotalPrice", "总价格", DbType.Decimal, ""); //listColumns.Add("escrowFee", "平台佣金", DbType.String, ""); listColumns.Add("MoneyRate", "汇率", DbType.String, ""); listColumns.Add("PostFee", "实际运费", DbType.Decimal, ""); listColumns.Add("GoodsFee", "进货价", DbType.Decimal, ""); listColumns.Add("GNPostFee", "国内运费", DbType.Decimal, ""); listColumns.Add("PersonMoney", "人工费", DbType.Decimal, ""); listColumns.Add("ZJMoney", "质检费", DbType.Decimal, ""); listColumns.Add("FactMoney", "最终利润", DbType.Decimal, ""); listColumns.Add("ErrorInfo", "异常", DbType.String, ""); listColumns.Add("PostName", "发货方式", DbType.String, ""); MicrosoftExcel obj2 = new MicrosoftExcel(); return obj2.Export(tb, listColumns); } #endregion #region 导出利润报表 [WebMethod(EnableSession = true)] public string ExcelOrderSaleMoneyForTM4(string ShopIds, Decimal? PersonFee, DateTime? SDate, DateTime? EDate, string GoodsCode) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); // if (PersonFee == null) // PersonFee = 2; int ShopId = 0; if (ShopIds != "") ShopId = Convert.ToInt32(ShopIds.Split(',')[0]); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var moneylist = obj.GetMoneyList(ShopId); var list = obj.GetOrderSaleMoneyForTM3(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), GoodsCode.Trim(), CompanyId); var cblist = obj.GetBuyMoneyNew(SDate, EDate.Value.AddDays(1), ShopIds.TrimEnd(','), CompanyId); var tracklist = obj.GetTrackCodeList(ShopIds.TrimEnd(','), SDate, EDate.Value.AddDays(1)); //var cateList=obj DataTable tb = new DataTable(); tb.Columns.Add("Id", typeof(Int32)); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("PostDate", typeof(string)); tb.Columns.Add("PlatOrderCode", typeof(string)); tb.Columns.Add("GoodsCode", typeof(string)); tb.Columns.Add("GoodsName", typeof(string)); tb.Columns.Add("CountryName", typeof(string)); tb.Columns.Add("BuyDate", typeof(string)); tb.Columns.Add("TypeDesc", typeof(string)); tb.Columns.Add("TotalPrice", typeof(string)); tb.Columns.Add("escrowFee", typeof(string)); tb.Columns.Add("MoneyRate", typeof(string)); tb.Columns.Add("OffNum", typeof(string)); tb.Columns.Add("GoodsNum", typeof(string)); tb.Columns.Add("TrackCode", typeof(string)); tb.Columns.Add("TotalWeight", typeof(string)); tb.Columns.Add("PostFee", typeof(string)); tb.Columns.Add("GoodsFee", typeof(string)); tb.Columns.Add("PersonMoney", typeof(string)); tb.Columns.Add("RateMoney", typeof(string)); tb.Columns.Add("ZJMoney", typeof(string)); tb.Columns.Add("GNPostFee", typeof(string)); tb.Columns.Add("FactMoney", typeof(string)); tb.Columns.Add("ErrorInfo", typeof(string)); tb.Columns.Add("PostName", typeof(string)); decimal TotalPrice = 0; int TotalNum = 0; decimal TotalWeight = 0; decimal PostFee = 0; decimal GoodsFee = 0; decimal GNPostFee = 0; decimal FactMoney = 0; decimal PersonMoney = 0; decimal escrowFee = 0; decimal ZJMoney = 0; decimal RateMoney = 0; int OrderNum = 0; if (list != null && cblist != null) { string PlatOrderCode = ""; string JoinOrderCode = ""; foreach (var md in list) { decimal dGoodsFee = 0; decimal dGNPostFee = 0; DataRow row = tb.NewRow(); row["Id"] = md.Id; row["ShopName"] = md.ShopName; if (md.PostDate != null) row["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.BuyDate != null) row["BuyDate"] = md.BuyDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row["PlatOrderCode"] = md.JoinOrderCode; else row["PlatOrderCode"] = md.PlatOrderCode; row["GoodsCode"] = md.GoodsCode; row["GoodsName"] = md.GoodsName; row["CountryName"] = md.CountryName; row["TypeDesc"] = md.TypeDesc; if (md.TotalPrice != null) row["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); //row["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); if (md.OffNum != null) row["OffNum"] = md.OffNum.ToString(); var moneymd = moneylist.Find(n => n.PlatId == md.PlatId && n.MCode == md.MoneyCode); if (moneymd != null) { md.RMBPrice = md.TotalPrice * moneymd.MRate.Value; md.MoneyRate = moneymd.MRate; row["MoneyRate"] = moneymd.MRate.Value.ToString("0.00000"); } else { row["MoneyRate"] = "1"; md.RMBPrice = md.TotalPrice; } if (md.GoodsNum != null) row["GoodsNum"] = md.GoodsNum.ToString(); string tcode = ""; if (md.JoinOrderCode != null && md.JoinOrderCode != "") { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.JoinOrderCode == md.JoinOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + "
"; } } } } else { if (tracklist != null && tracklist.Count > 0) { var tlist = tracklist.FindAll(n => n.OrderCode == md.PlatOrderCode); if (tlist != null) { foreach (var tmd in tlist) { tcode += tmd.TrackCode + "
"; } } } } md.TrackCode = tcode; row["TrackCode"] = tcode; if (md.TotalWeight != null) row["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.PostFee != null) { md.PostFee = md.PostFee.Value * md.OffNum / 10; row["PostFee"] = md.PostFee.Value.ToString("0.0000"); } else md.PostFee = 0; md.FactMoney = md.RMBPrice - md.PostFee.Value; row["ErrorInfo"] = md.ErrorInfo; row["PostName"] = md.PostName; var cbmd = cblist.Find(n => n.Id == md.Id); if (cbmd != null && cbmd.Price != null) dGoodsFee = cbmd.Price.Value * md.GoodsNum.Value; row["GoodsFee"] = dGoodsFee.ToString("0.0000"); //if (md.GoodsName.Contains("0-10") && md.GoodsName.Contains("礼物")) //{ // row["GoodsFee"] = "5"; // dGoodsFee = 5; //} //else if (md.GoodsName.Contains("10-20") && md.GoodsName.Contains("礼物")) //{ // row["GoodsFee"] = "15"; // dGoodsFee = 15; //} //else if (md.GoodsName.Contains("20-30") && md.GoodsName.Contains("礼物")) //{ // row["GoodsFee"] = "25"; // dGoodsFee = 25; //} if (cbmd != null && cbmd.PostPrice != null) dGNPostFee = cbmd.PostPrice.Value * md.GoodsNum.Value; row["GNPostFee"] = dGNPostFee.ToString("0.0000"); row["PersonMoney"] = md.PersonFee.Value.ToString("f1"); row["ZJMoney"] = 0; if (md.FactMoney != null) row["FactMoney"] = (md.FactMoney.Value - dGoodsFee - dGNPostFee - md.PersonFee.Value).ToString("0.00"); decimal rate = 0; if (md.RMBPrice != null && md.RMBPrice.Value > 0) rate = (md.FactMoney.Value - dGoodsFee - dGNPostFee - md.PersonFee.Value) * 100 / md.RMBPrice.Value; row["RateMoney"] = rate.ToString("0.000") + "%"; var mlist = list.FindAll(n => n.PlatOrderCode == md.PlatOrderCode); if (JoinOrderCode != "" && md.JoinOrderCode == JoinOrderCode) { row["TrackCode"] = ""; row["TotalWeight"] = "0"; row["PostFee"] = 0; md.PostFee = 0; md.TotalWeight = 0; row["PersonMoney"] = 0; row["ZJMoney"] = 0; md.PersonFee = 0; row["FactMoney"] = (md.RMBPrice.Value - dGoodsFee - dGNPostFee).ToString("0.00"); rate = 0; if (md.RMBPrice != null && md.RMBPrice.Value > 0) rate = (md.RMBPrice.Value - dGoodsFee - dGNPostFee) * 100 / md.RMBPrice.Value; row["RateMoney"] = rate.ToString("0.000") + "%"; } if (PlatOrderCode != md.PlatOrderCode && mlist != null && mlist.Count > 1) { DataRow row1 = tb.NewRow(); row1["Id"] = md.Id; row1["ShopName"] = md.ShopName; if (md.PostDate != null) row1["PostDate"] = md.PostDate.Value.ToString("yyyy/MM/dd"); if (md.BuyDate != null) row1["BuyDate"] = md.BuyDate.Value.ToString("yyyy/MM/dd"); if (md.JoinOrderCode != null && md.JoinOrderCode != "") row1["PlatOrderCode"] = md.JoinOrderCode; else row1["PlatOrderCode"] = md.PlatOrderCode; //if (md.JoinOrderCode!=null) //row1["JoinOrderCode"] = md.JoinOrderCode; row1["GoodsCode"] = ""; row1["GoodsName"] = ""; row1["CountryName"] = md.CountryName; row1["TypeDesc"] = ""; if (md.TotalPrice != null) row1["TotalPrice"] = md.TotalPrice.Value.ToString("0.0000"); if (md.OffNum != null) row1["OffNum"] = md.OffNum.ToString(); // row1["escrowFee"] = md.escrowFee.Value.ToString("0.0000"); row1["GoodsNum"] = ""; row1["TrackCode"] = md.TrackCode; if (md.TotalWeight != null) row1["TotalWeight"] = md.TotalWeight.Value.ToString("0"); if (md.MoneyRate != null) row1["MoneyRate"] = md.MoneyRate.Value.ToString("0.00000"); row1["GoodsFee"] = ""; if (md.PostFee != null) row1["PostFee"] = md.PostFee.Value.ToString("0.0000"); row1["GNPostFee"] = ""; row1["PersonMoney"] = md.PersonFee.Value.ToString("f1"); row1["ZJMoney"] = ""; if (md.FactMoney != null) row1["FactMoney"] = (md.FactMoney.Value - md.PersonFee.Value).ToString("0.00"); decimal rate1 = 0; if (md.RMBPrice != null && md.RMBPrice.Value > 0) rate1 = (md.FactMoney.Value - md.PersonFee.Value) * 100 / md.RMBPrice.Value; row1["RateMoney"] = rate1.ToString("0.000") + "%"; row1["ErrorInfo"] = md.ErrorInfo; row1["PostName"] = md.PostName; PersonMoney += md.PersonFee.Value; // ZJMoney += md.ZJFee.Value; if (md.TotalPrice != null) TotalPrice += md.TotalPrice.Value; if (md.TotalWeight != null) TotalWeight += md.TotalWeight.Value; if (md.PostFee != null) PostFee += md.PostFee.Value; if (md.FactMoney != null) FactMoney += md.FactMoney.Value - md.PersonFee.Value; // escrowFee += md.escrowFee.Value; tb.Rows.Add(row1); OrderNum++; row["BuyDate"] = ""; row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["MoneyRate"] = ""; row["OffNum"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; //row["ZJMoney"] =""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.0000"); rate = 0; if (md.FactMoney != null && md.FactMoney.Value > 0) rate = (0 - dGoodsFee - dGNPostFee) * 100 / md.FactMoney.Value; row["RateMoney"] = rate.ToString("0.000") + "%"; row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else if (PlatOrderCode == md.PlatOrderCode) { row["BuyDate"] = ""; row["PostDate"] = ""; row["CountryName"] = ""; row["TotalPrice"] = ""; row["escrowFee"] = ""; row["OffNum"] = ""; row["MoneyRate"] = ""; row["TrackCode"] = ""; row["TotalWeight"] = ""; row["PersonMoney"] = ""; // row["ZJMoney"] = ""; if (md.FactMoney != null) row["FactMoney"] = (0 - dGoodsFee - dGNPostFee).ToString("0.0000"); rate = 0; if (md.FactMoney != null && md.FactMoney.Value > 0) rate = (0 - dGoodsFee - dGNPostFee) * 100 / md.FactMoney.Value; row["RateMoney"] = rate.ToString("0.000") + "%"; row["PostFee"] = ""; row["ErrorInfo"] = ""; row["PostName"] = ""; } else OrderNum++; if ((JoinOrderCode == "" || md.JoinOrderCode != JoinOrderCode) && md.JoinOrderCode != null) { var checklist = list.FindAll(n => n.JoinOrderCode == md.JoinOrderCode && n.TotalWeight != null); if (checklist.Count() > 0) { md.TotalWeight = checklist.First().TotalWeight; md.PostFee = checklist.First().PostFee; row["TotalWeight"] = checklist.First().TotalWeight; row["PostFee"] = checklist.First().PostFee; } } if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "") TotalPrice += md.TotalPrice.Value; if (row["GoodsNum"] != null && row["GoodsNum"].ToString() != "") TotalNum += md.GoodsNum.Value; if (row["TotalWeight"] != null && row["TotalWeight"].ToString() != "") TotalWeight += md.TotalWeight.Value; if (row["PostFee"] != null && row["PostFee"].ToString() != "") PostFee += md.PostFee.Value; if (row["GoodsFee"] != null && row["GoodsFee"].ToString() != "") GoodsFee += dGoodsFee; if (row["FactMoney"] != null && row["FactMoney"].ToString() != "") FactMoney += Convert.ToDecimal(row["FactMoney"]); if (row["GNPostFee"] != null && row["GNPostFee"].ToString() != "") GNPostFee += dGNPostFee; if (row["PersonMoney"] != null && row["PersonMoney"].ToString() != "") PersonMoney += md.PersonFee.Value; if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "" && md.TotalPrice != null) RateMoney += md.TotalPrice.Value * md.MoneyRate.Value; // if (row["ZJMoney"] != null && row["ZJMoney"].ToString() != "") // ZJMoney += md.ZJFee.Value; tb.Rows.Add(row); PlatOrderCode = md.PlatOrderCode; if (md.JoinOrderCode == null) JoinOrderCode = ""; else JoinOrderCode = md.JoinOrderCode; } } DataRow row2 = tb.NewRow(); row2["PostDate"] = OrderNum.ToString(); row2["TrackCode"] = "合计:"; // row2["escrowFee"] = escrowFee.ToString("0.0000"); row2["TotalPrice"] = TotalPrice.ToString("0.0000"); row2["GoodsNum"] = TotalNum.ToString(); row2["TotalWeight"] = TotalWeight.ToString("0"); row2["PersonMoney"] = PersonMoney.ToString("0"); row2["ZJMoney"] = "0"; row2["PostFee"] = PostFee.ToString("0.0000"); row2["GoodsFee"] = GoodsFee.ToString("0.0000"); row2["GNPostFee"] = GNPostFee.ToString("0.0000"); row2["FactMoney"] = FactMoney.ToString("0.0000"); if (RateMoney > 0) row2["RateMoney"] = (FactMoney * 100 / RateMoney).ToString("0.000") + "%"; else row2["RateMoney"] = ""; tb.Rows.Add(row2); TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("ShopName", "店铺", DbType.String, ""); listColumns.Add("PostDate", "发货时间", DbType.String, ""); listColumns.Add("PlatOrderCode", "订单号", DbType.String, ""); listColumns.Add("GoodsCode", "货物编号", DbType.String, ""); listColumns.Add("GoodsName", "货物名称", DbType.String, ""); listColumns.Add("BuyDate", "采购日期", DbType.String, ""); listColumns.Add("CountryName", "国家", DbType.String, ""); listColumns.Add("TypeDesc", "描述", DbType.String, ""); //listColumns.Add("OffNum", "汇率", DbType.String, ""); listColumns.Add("OffNum", "运费折扣", DbType.String, ""); listColumns.Add("TrackCode", "挂号", DbType.String, ""); listColumns.Add("GoodsNum", "数量", DbType.String, ""); listColumns.Add("TotalWeight", "重量", DbType.String, ""); listColumns.Add("TotalPrice", "总价格", DbType.Decimal, ""); //listColumns.Add("escrowFee", "平台佣金", DbType.String, ""); listColumns.Add("MoneyRate", "汇率", DbType.String, ""); listColumns.Add("PostFee", "实际运费", DbType.Decimal, ""); listColumns.Add("GoodsFee", "进货价", DbType.Decimal, ""); listColumns.Add("GNPostFee", "国内运费", DbType.Decimal, ""); listColumns.Add("PersonMoney", "人工费", DbType.Decimal, ""); // listColumns.Add("ZJMoney", "质检费", DbType.Decimal, ""); listColumns.Add("FactMoney", "最终利润", DbType.Decimal, ""); listColumns.Add("RateMoney", "利润率", DbType.String, ""); listColumns.Add("ErrorInfo", "异常", DbType.String, ""); listColumns.Add("PostName", "发货方式", DbType.String, ""); MicrosoftExcel obj2 = new MicrosoftExcel(); return obj2.Export(tb, listColumns); } #endregion #region 查询速卖通绩效 [WebMethod(EnableSession = true)] public List GetUserMoneyCount(List list, int Year, int Month) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); var obj1 = new BaseService(); // if (PersonFee == null) // PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); if (list == null || list.Count == 0) return null; //foreach (var md in list) //{ // ShopIds += md.ShopId.ToString() + ","; //} //DataSet ds = obj.GetDayCompanyCountPriceCount(CompanyId, SDate, EDate.Value.AddDays(1)); // if (ds == null) // return null; DataTable tb = new DataTable(); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("ShopData", typeof(string)); tb.Columns.Add("ShopMoney", typeof(string)); // TimeSpan ts = EDate.Value - SDate.Value; //int days = ts.Days + 1; int i = 0; foreach (var md in list) { var list1 = obj1.GetShopUser(md.ShopId.Value); string Users = ""; if (list1 != null) { foreach (var md1 in list1) { Users += md1.Name + ","; } } DataRow row = tb.NewRow(); row["ShopName"] = md.ShopName; row["ShopData"] = ""; row["ShopMoney"] = ""; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] ="(" + Users.Trim(',') + ")"; row["ShopData"] = ""; row["ShopMoney"] = "2.5"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "好评"; row["ShopData"] = "95.9"; row["ShopMoney"] = "-400"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "dsr"; row["ShopData"] = "4.6,4.4,4.5"; row["ShopMoney"] = "300"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "odr"; row["ShopData"] = "4.85"; row["ShopMoney"] = "0"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "赔款"; row["ShopData"] = "0.92"; row["ShopMoney"] = "500"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "爆款"; row["ShopData"] = "8"; row["ShopMoney"] = "1600"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "销售额"; row["ShopData"] = "29653.25"; row["ShopMoney"] = "-400"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "毛利率"; row["ShopData"] = "13.9"; row["ShopMoney"] = "0.7"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "总奖金"; row["ShopData"] = ""; row["ShopMoney"] = "3430"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "单份奖金"; row["ShopData"] = ""; row["ShopMoney"] = "1372"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "奖金分配"; if(i==0) row["ShopData"] = "唐锡萍:1029;陈圣文(请假6天):686;吴晓庆:1715"; else row["ShopData"] = "周玲玲:686;宋可珂:1372;艾晨:1372"; row["ShopMoney"] = "1372"; tb.Rows.Add(row); i++; } //int HjTotalNum = 0; //decimal HjTotalPrice = 0; //decimal HjGoodsFee = 0; //decimal HjPostFee = 0; //decimal HjGnPostFee = 0; //decimal HjBackPrice = 0; //decimal HjSalePrice = 0; //DataRow row1 = tb.NewRow(); //row1["ShopName"] = SDate.Value.ToString("MM/dd") + "-" + EDate.Value.ToString("MM/dd") + "公司利润"; //tb.Rows.Add(row1); //for (int i = 0; i < days; i++) //{ // int TotalNum = 0; // decimal TotalPrice = 0; // decimal GoodsFee = 0; // decimal PostFee = 0; // decimal BackPrice = 0; // decimal SalePrice = 0; // decimal GnPostFee = 0; // DataRow row = tb.NewRow(); // row["ShopName"] = ""; // DataRow[] dr = ds.Tables[0].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); // if (dr.Length > 0) // { // row["OrderNum"] = dr[0]["OrderNum"].ToString(); // TotalNum = Convert.ToInt32(dr[0]["OrderNum"]); // HjTotalNum += TotalNum; // } // row["OrderDate"] = SDate.Value.AddDays(i).ToString("yyyy/MM/dd"); // DataRow[] dr1 = ds.Tables[1].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); // if (dr1.Length > 0) // { // row["TotalPrice"] = dr1[0]["TotalPrice"].ToString(); // TotalPrice = Convert.ToDecimal(dr1[0]["TotalPrice"]); // HjTotalPrice += TotalPrice; // } // DataRow[] dr2 = ds.Tables[2].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); // if (dr2.Length > 0) // { // row["GoodsFee"] = dr2[0]["Price"].ToString(); // GoodsFee = Convert.ToDecimal(dr2[0]["Price"]); // HjGoodsFee += GoodsFee; // } // DataRow[] dr3 = ds.Tables[3].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); // if (dr3.Length > 0) // { // row["PostFee"] = dr3[0]["PostPrice"].ToString(); // PostFee = Convert.ToDecimal(dr3[0]["PostPrice"]); // HjPostFee += PostFee; // } // DataRow[] dr4 = ds.Tables[4].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); // if (dr4.Length > 0) // { // row["BackPrice"] = dr4[0]["BackMoney"].ToString(); // BackPrice = Convert.ToDecimal(dr4[0]["BackMoney"]); // HjBackPrice += BackPrice; // } // DataRow[] dr5 = ds.Tables[5].Select("PostDate='" + SDate.Value.AddDays(i).ToString("yyyy-MM-dd") + "'"); // if (dr5.Length > 0) // { // row["GnPostFee"] = dr5[0]["PostFee"].ToString(); // GnPostFee = Convert.ToDecimal(dr5[0]["PostFee"]); // HjGnPostFee += GnPostFee; // } // SalePrice = TotalPrice - GoodsFee - PostFee - GnPostFee - BackPrice; // row["SalePrice"] = SalePrice.ToString(); // HjSalePrice += SalePrice; // tb.Rows.Add(row); //} //DataRow row2 = tb.NewRow(); //row2["OrderDate"] = "合计:"; //row2["OrderNum"] = HjTotalNum.ToString("0.000"); //row2["TotalPrice"] = HjTotalPrice.ToString("0.000"); //row2["GoodsFee"] = HjGoodsFee.ToString("0.000"); //row2["PostFee"] = HjPostFee.ToString("0.000"); //row2["BackPrice"] = HjBackPrice.ToString("0.000"); //row2["GnPostFee"] = HjGnPostFee.ToString("0.000"); //row2["SalePrice"] = HjSalePrice.ToString("0.000"); //tb.Rows.Add(row2); //if (tb == null) // return null; return tb.ToList(); } #endregion #region 查询速卖通绩效 [WebMethod(EnableSession = true)] public string ExcelUserShopMoney(List list, int Year, int Month) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); var obj1 = new BaseService(); // if (PersonFee == null) // PersonFee = 2; int CompanyId = Convert.ToInt32(Session["CompanyId"]); if (list == null || list.Count == 0) return null; //foreach (var md in list) //{ // ShopIds += md.ShopId.ToString() + ","; //} //DataSet ds = obj.GetDayCompanyCountPriceCount(CompanyId, SDate, EDate.Value.AddDays(1)); // if (ds == null) // return null; DataTable tb = new DataTable(); tb.Columns.Add("ShopName", typeof(string)); tb.Columns.Add("ShopData", typeof(string)); tb.Columns.Add("ShopMoney", typeof(string)); // TimeSpan ts = EDate.Value - SDate.Value; //int days = ts.Days + 1; int i = 0; foreach (var md in list) { var list1 = obj1.GetShopUser(md.ShopId.Value); string Users = ""; if (list1 != null) { foreach (var md1 in list1) { Users += md1.Name + ","; } } DataRow row = tb.NewRow(); row["ShopName"] = md.ShopName; row["ShopData"] = ""; row["ShopMoney"] = ""; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "(" + Users.Trim(',') + ")"; row["ShopData"] = ""; row["ShopMoney"] = "2.5"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "好评"; row["ShopData"] = "95.9"; row["ShopMoney"] = "-400"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "dsr"; row["ShopData"] = "4.6,4.4,4.5"; row["ShopMoney"] = "300"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "odr"; row["ShopData"] = "4.85"; row["ShopMoney"] = "0"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "赔款"; row["ShopData"] = "0.92"; row["ShopMoney"] = "500"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "爆款"; row["ShopData"] = "8"; row["ShopMoney"] = "1600"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "销售额"; row["ShopData"] = "29653.25"; row["ShopMoney"] = "-400"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "毛利率"; row["ShopData"] = "13.9"; row["ShopMoney"] = "0.7"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "总奖金"; row["ShopData"] = ""; row["ShopMoney"] = "3430"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "单份奖金"; row["ShopData"] = ""; row["ShopMoney"] = "1372"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = "奖金分配"; if (i == 0) row["ShopData"] = "唐锡萍:1029;陈圣文(请假6天):686;吴晓庆:1715"; else row["ShopData"] = "周玲玲:686;宋可珂:1372;艾晨:1372"; row["ShopMoney"] = "1372"; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = ""; row["ShopData"] = ""; row["ShopMoney"] = ""; tb.Rows.Add(row); row = tb.NewRow(); row["ShopName"] = ""; row["ShopData"] = ""; row["ShopMoney"] = ""; tb.Rows.Add(row); i++; } TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("ShopName", "店铺", DbType.String, ""); listColumns.Add("ShopData", "数据", DbType.String, ""); listColumns.Add("ShopMoney", "奖金", DbType.String, ""); MicrosoftExcel obj2 = new MicrosoftExcel(); return obj2.Export(tb, listColumns); } #endregion #region 查询物流折扣 [WebMethod(EnableSession = true)] public List GetExpressOff() { PagesNew.Login(this.Session); var obj = new JC_ExpressCodeService(); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var list = obj.GetExpressOff(CompanyId); return list; } #endregion #region 查询人工费 [WebMethod(EnableSession = true)] public decimal GetPersonFee() { PagesNew.Login(this.Session); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var md = JC_CompanyService.GetModel(CompanyId); if (md != null && md.PersonFee != null) return md.PersonFee.Value; return 2; } #endregion #region 保存物流折扣 [WebMethod(EnableSession = true)] public void SaveExpressOff(List list,Decimal? PersonFee) { PagesNew.Login(this.Session); var obj = new JC_ExpressCodeService(); int CompanyId = Convert.ToInt32(Session["CompanyId"]); if (list != null) { foreach (var md in list) { obj.UpdateExpressOff(md.ExpressPostID.Value, md.OffNum.Value); } } if (PersonFee > -1) { JC_CompanyService.UpdatePersonFee(CompanyId, PersonFee.Value); } } #endregion #region 报表 public string GetReport(DataTable dt,int ReportId) { PagesNew.Login(this.Session); var obj = new BaseService(); var rmd = BaseService.GetReportModel(ReportId); var rlist = obj.GetRepoartColsList(ReportId); if (rmd == null || rlist == null) return ""; StringBuilder html = new StringBuilder(); html.Append("序号"); foreach (var md in rlist) { html.Append(""+md.ColName+""); } html.Append(""); if (dt != null) { DataRow row = null; for (int i = 0; i < dt.Rows.Count; i++) { html.Append(""+(i+1).ToString()+""); int rowindex = 1; foreach (var md in rlist) { if (dt.Columns.Contains(md.ColValue)==false) { html.Append(""); rowindex++; continue; } if (md.IsSum == 1&&i==0) { if (row == null) row = dt.NewRow(); if (md.ColType == "int") { try { row[md.ColValue] = Convert.ToInt32(dt.Compute("sum(" + md.ColValue + ")", "" + md.ColValue + " is not null")); } catch { row[md.ColValue] = 0; } } else if (md.ColType == "dec") { try { row[md.ColValue] = Convert.ToDecimal(dt.Compute("sum(" + md.ColValue + ")", "" + md.ColValue + ">0")); } catch { row[md.ColValue] = 0; } } } if (dt.Rows[i][md.ColValue] != null && dt.Rows[i][md.ColValue].ToString() != "") { string csscolor = ""; if (md.ContionType == "=" && dt.Rows[i][md.ColValue].ToString()==md.SValue) { csscolor = md.ColColor; } else if (md.ContionType == ">" && Convert.ToDecimal(dt.Rows[i][md.ColValue]) > Convert.ToDecimal(md.SValue) && Convert.ToDecimal(dt.Rows[i][md.ColValue])< Convert.ToDecimal(md.EValue)) { csscolor = md.ColColor; } else if (md.ContionType == ">=" && Convert.ToDecimal(dt.Rows[i][md.ColValue]) >= Convert.ToDecimal(md.SValue) && Convert.ToDecimal(dt.Rows[i][md.ColValue]) <= Convert.ToDecimal(md.EValue)) { csscolor = md.ColColor; } if (csscolor != "") csscolor = "style='color:" + csscolor + "'"; string datav = ""; if (md.ColType == "date1") datav = Convert.ToDateTime(dt.Rows[i][md.ColValue]).ToString("yyyy-MM-dd"); else if (md.ColType == "date2") datav = Convert.ToDateTime(dt.Rows[i][md.ColValue]).ToString("yyyy-MM-dd HH:mm"); else datav = dt.Rows[i][md.ColValue].ToString(); html.Append("" + datav + ""); } else html.Append(""); rowindex++; } html.Append(""); } int hj = 0; if (row != null) { html.Append("合计:"); foreach (var md in rlist) { if (dt.Columns.Contains(md.ColValue) == false) { html.Append(""); continue; } if (md.IsSum == 1 && row[md.ColValue] != null) { if (hj == 0) { hj = 1; html.Append("" + row[md.ColValue] + ""); } else html.Append("" + row[md.ColValue] + ""); } else html.Append(""); } html.Append(""); } } return html.ToString(); } #endregion #region 报表 public string GetReport2(DataTable dt, int ReportId) { PagesNew.Login(this.Session); var obj = new BaseService(); var rmd = BaseService.GetReportModel(ReportId); var rlist = obj.GetRepoartColsList(ReportId); if (rmd == null || rlist == null) return ""; StringBuilder html = new StringBuilder(); html.Append("序号"); foreach (var md in rlist) { html.Append("" + md.ColName + ""); } html.Append(""); if (dt != null) { DataRow row = null; for (int i = 0; i < dt.Rows.Count; i++) { html.Append("" + (i + 1).ToString() + ""); int rowindex = 1; foreach (var md in rlist) { if (dt.Columns.Contains(md.ColValue) == false) { html.Append(""); rowindex++; continue; } if (md.IsSum == 1 && i == 0) { if (row == null) row = dt.NewRow(); if (md.ColType == "int") { try { row[md.ColValue] = Convert.ToInt32(dt.Compute("sum(" + md.ColValue + ")", "" + md.ColValue + " is not null")); } catch { row[md.ColValue] = 0; } } else if (md.ColType == "dec") { try { row[md.ColValue] = Convert.ToDecimal(dt.Compute("sum(" + md.ColValue + ")", "" + md.ColValue + ">0")); } catch { row[md.ColValue] = 0; } } } if (dt.Rows[i][md.ColValue] != null && dt.Rows[i][md.ColValue].ToString() != "") { string csscolor = ""; if (md.ContionType == "=" && dt.Rows[i][md.ColValue].ToString() == md.SValue) { csscolor = md.ColColor; } else if (md.ContionType == ">" && Convert.ToDecimal(dt.Rows[i][md.ColValue]) > Convert.ToDecimal(md.SValue) && Convert.ToDecimal(dt.Rows[i][md.ColValue]) < Convert.ToDecimal(md.EValue)) { csscolor = md.ColColor; } else if (md.ContionType == ">=" && Convert.ToDecimal(dt.Rows[i][md.ColValue]) >= Convert.ToDecimal(md.SValue) && Convert.ToDecimal(dt.Rows[i][md.ColValue]) <= Convert.ToDecimal(md.EValue)) { csscolor = md.ColColor; } if (csscolor != "") csscolor = "style='color:" + csscolor + "'"; string datav = ""; if (md.ColType == "date1") datav = Convert.ToDateTime(dt.Rows[i][md.ColValue]).ToString("yyyy-MM-dd"); else if (md.ColType == "date2") datav = Convert.ToDateTime(dt.Rows[i][md.ColValue]).ToString("yyyy-MM-dd HH:mm"); else datav = dt.Rows[i][md.ColValue].ToString(); html.Append("" + datav + ""); } else html.Append(""); rowindex++; } html.Append(""); } int hj = 0; if (row != null) { html.Append("合计:"); foreach (var md in rlist) { if (dt.Columns.Contains(md.ColValue) == false) { html.Append(""); continue; } if (md.IsSum == 1 && row[md.ColValue] != null) { if (hj == 0) { hj = 1; html.Append("" + row[md.ColValue] + ""); } else html.Append("" + row[md.ColValue] + ""); } else html.Append(""); } html.Append(""); } } return html.ToString(); } #endregion #region 报表1 [WebMethod(EnableSession = true)] public string GetReportTable1(DateTime? InDate,int DeptId,int ShopId,int PlatId,string MoneyCode,string Sort) { var obj = new BaseService(); string tj = ""; string tj1 = ""; if (DeptId > 0) { tj += " and b.DeptId=" + DeptId + " "; tj1 += " and a.DeptId=" + DeptId + " "; } if (PlatId > 0) { tj += " and b.PlatType=" + PlatId + " "; tj1 += " and a.PlatType=" + PlatId + " "; } if (ShopId > 0) { tj += " and b.ShopId=" + ShopId + " "; tj1 += " and a.ShopId=" + ShopId + " "; } if (MoneyCode!="0") tj += " and a.MoneyCode='" + MoneyCode + "' "; string sql = @" select a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end,b.GoodRate,b.ODR,b.DSRGoods,b.DSRService,b.DSRPost,b.InforViolate,b.PropertyViolate,b.OtherViolate from JC_Shop a inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a inner join JC_Shop b on a.ShopId=b.ShopId where a.State>0 " + tj + " and a.State<3 and DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by b.ShopId)c on a.ShopId=c.ShopId left join JC_ShopData b on a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 where a.CompanyId=1 " + tj1 + " order by " + Sort; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 1); } #endregion #region 报表1 [WebMethod(EnableSession = true)] public string GetReportExcel(DateTime? InDate, int DeptId, int ShopId, int PlatId, string MoneyCode, string Sort) { var obj = new BaseService(); string tj = ""; string tj1 = ""; if (DeptId > 0) { tj += " and b.DeptId=" + DeptId + " "; tj1 += " and a.DeptId=" + DeptId + " "; } if (PlatId > 0) { tj += " and b.PlatType=" + PlatId + " "; tj1 += " and a.PlatType=" + PlatId + " "; } if (ShopId > 0) { tj += " and b.ShopId=" + ShopId + " "; tj1 += " and a.ShopId=" + ShopId + " "; } if (MoneyCode != "0") tj += " and a.MoneyCode='" + MoneyCode + "' "; string sql = @" select a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end,b.GoodRate,b.ODR,b.DSRGoods,b.DSRService,b.DSRPost,b.InforViolate,b.PropertyViolate,b.OtherViolate from JC_Shop a inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a inner join JC_Shop b on a.ShopId=b.ShopId where a.State>0 " + tj + " and a.State<3 and DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by b.ShopId)c on a.ShopId=c.ShopId left join JC_ShopData b on a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 where a.CompanyId=1 " + tj1 + " order by " + Sort; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 1); } #endregion #region 报表18 [WebMethod(EnableSession = true)] public string GetReportTable18(DateTime? InDate, int DeptId, int ShopId, int PlatId, string MoneyCode, string Sort) { var obj = new BaseService(); string tj = ""; string tj1 = ""; if (DeptId > 0) { tj += " and b.DeptId=" + DeptId + " "; tj1 += " and a.DeptId=" + DeptId + " "; } if (PlatId > 0) { tj += " and b.PlatType=" + PlatId + " "; tj1 += " and a.PlatType=" + PlatId + " "; } if (ShopId > 0) { tj += " and b.ShopId=" + ShopId + " "; tj1 += " and a.ShopId=" + ShopId + " "; } if (MoneyCode != "0") tj += " and a.MoneyCode='" + MoneyCode + "' "; string sql = @" select a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end,b.GoodRate,b.ODR,b.DSRGoods,b.DSRService,b.DSRPost,b.USDUseMoney,b.USDUseMoney,b.USDNoMoney,b.RMBUseMoney,b.RMBNoMoney,b.InforViolate,b.PropertyViolate,b.OtherViolate,b.Rate1,b.Rate2,b.Rate3,b.Rate4,a.FeeDate,InPrice=d.InPrice from JC_Shop a inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a inner join JC_Shop b on a.ShopId=b.ShopId where a.State>0 " + tj + " and a.State<3 and DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by b.ShopId)c on a.ShopId=c.ShopId left join JC_ShopData b on a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 inner join (select a.ShopId,InPrice=sum(isnull(d.InPrice,0)) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by a.ShopId)d on a.ShopId=d.ShopId where a.CompanyId=1 " + tj1 + " order by "+Sort; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 18); } #endregion #region 报表18 [WebMethod(EnableSession = true)] public string GetReportExcel18(DateTime? InDate, int DeptId, int ShopId, int PlatId, string MoneyCode,string Sort) { var obj = new BaseService(); string tj = ""; string tj1 = ""; if (DeptId > 0) { tj += " and b.DeptId=" + DeptId + " "; tj1 += " and a.DeptId=" + DeptId + " "; } if (PlatId > 0) { tj += " and b.PlatType=" + PlatId + " "; tj1 += " and a.PlatType=" + PlatId + " "; } if (ShopId > 0) { tj += " and b.ShopId=" + ShopId + " "; tj1 += " and a.ShopId=" + ShopId + " "; } if (MoneyCode != "0") tj += " and a.MoneyCode='" + MoneyCode + "' "; string sql = @" select a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end,b.GoodRate,b.ODR,b.DSRGoods,b.DSRService,b.DSRPost,b.USDUseMoney,b.USDUseMoney,b.USDNoMoney,b.RMBUseMoney,b.RMBNoMoney,b.InforViolate,b.PropertyViolate,b.OtherViolate,b.Rate1,b.Rate2,b.Rate3,b.Rate4,b.Rate5,b.Rate6 from JC_Shop a inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a inner join JC_Shop b on a.ShopId=b.ShopId where a.State>0 " + tj + " and a.State<3 and DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by b.ShopId)c on a.ShopId=c.ShopId left join JC_ShopData b on a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 where a.CompanyId=1 " + tj1 + " order by" + Sort; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 18); } #endregion #region 报表40 [WebMethod(EnableSession = true)] public string GetReportTable402(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode) { var obj = new BaseService(); int CompanyId = Convert.ToInt32(Session["CompanyId"]); string tj = ""; if (SDate!=null) { tj += " and d.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; } if (EDate != null) { tj += " and d.OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (UserId > 0) { tj += " and a.UserId=" + UserId + " "; } if (GoodsCode != "") tj += " and e.GoodsCode='" + GoodsCode + "' "; string sql = @"select c.UserId,c.Name,Num=sum(b.Num),OrderNum=COUNT(0),Price=SUM(dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a inner join ( select a.UserId,d.OrderId,Num=SUM(c.GoodsNum) from HW_GoodsUser a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join HW_GoodsDetail e on b.GoodsId=e.GoodsId inner join DT_OrderGoods c on e.DetailId=c.DetailId inner join DT_OrderInfo d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where d.CompanyId=" + CompanyId + " and d.State>0 and d.State<3 " + tj + @" group by a.UserId,d.OrderId)b on a.OrderId=b.OrderId inner join JC_UserInfo c on b.UserId=c.UserId group by c.UserId,c.Name "; DataTable dt = obj.GetReportData(sql); return GetReport2(dt, 40); } #endregion #region 报表40 [WebMethod(EnableSession = true)] public string GetReportTable40(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode) { var obj = new BaseService(); int CompanyId = Convert.ToInt32(Session["CompanyId"]); string tj = ""; string tj2 = ""; if (SDate != null) { tj += " and d.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; tj2 += " b.LastOrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; } if (EDate != null) { tj += " and d.OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; tj2 += " and b.LastOrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (UserId > 0) { tj += " and a.UserId=" + UserId + " "; } if (GoodsCode != "") tj += " and e.GoodsCode='" + GoodsCode + "' "; string sql = @"select c.Name,c.UserName,a.*,GoodsNum=d.Num,OutGoods=isnull(e.Num,0),NoGoods=d.Num-isnull(e.Num,0) from ( select b.UserId,Num=sum(b.Num),OrderNum=COUNT(0),Price=SUM(dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a inner join ( select a.UserId,d.OrderId,Num=SUM(c.GoodsNum) from HW_GoodsUser a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join HW_GoodsDetail e on b.GoodsId=e.GoodsId inner join DT_OrderGoods c on e.DetailId=c.DetailId inner join DT_OrderInfo d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where d.CompanyId=1 and d.State>0 and d.State<3 "+tj+@" group by a.UserId,d.OrderId)b on a.OrderId=b.OrderId group by b.UserId)a inner join JC_UserInfo c on a.UserId=c.UserId inner join (select UserId,Num=COUNT(0) from HW_GoodsUser group by UserId)d on c.UserId=d.UserId left join (select a.UserId,Num=COUNT(0) from HW_GoodsUser a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where "+tj2+@" group by a.UserId)e on c.UserId=e.UserId "; DataTable dt = obj.GetReportData(sql); return GetReport2(dt, 40); } #endregion #region 报表16 [WebMethod(EnableSession = true)] public string GetReportTable16(DateTime? SDate, DateTime? EDate, int DeptId, int ShopId, int PlatId, string MoneyCode,string Sort) { var obj = new BaseService(); if (EDate == null) EDate = DateTime.Now; string tj = ""; string tj1 = ""; if (DeptId > 0) { tj += " and b.DeptId=" + DeptId + " "; tj1 += " and a.DeptId=" + DeptId + " "; } if (PlatId > 0) { tj += " and b.PlatType=" + PlatId + " "; tj1 += " and a.PlatType=" + PlatId + " "; } if (ShopId > 0) { tj += " and b.ShopId=" + ShopId + " "; tj1 += " and a.ShopId=" + ShopId + " "; } string endtime = Convert.ToDateTime( EDate.ToString()).AddDays(1).ToString(); if (MoneyCode != "0") tj += " and a.MoneyCode='" + MoneyCode + "' "; string sql = @" select a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end from JC_Shop a inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a inner join JC_Shop b on a.ShopId=b.ShopId where a.State>0 " + tj + " and a.State<3 and a.InDate>='" + SDate + "' and a.InDate<'" + endtime + @"' group by b.ShopId)c on a.ShopId=c.ShopId where a.CompanyId=1 " + tj1 + " order by " + Sort; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 16); } #endregion #region 报表16 [WebMethod(EnableSession = true)] public string GetReportExcel16(DateTime? SDate, DateTime? EDate, int DeptId, int ShopId, int PlatId, string MoneyCode, string Sort) { var obj = new BaseService(); string tj = ""; string tj1 = ""; if (DeptId > 0) { tj += " and b.DeptId=" + DeptId + " "; tj1 += " and a.DeptId=" + DeptId + " "; } if (PlatId > 0) { tj += " and b.PlatType=" + PlatId + " "; tj1 += " and a.PlatType=" + PlatId + " "; } if (ShopId > 0) { tj += " and b.ShopId=" + ShopId + " "; tj1 += " and a.ShopId=" + ShopId + " "; } string endtime = Convert.ToDateTime(EDate.ToString()).AddDays(1).ToString(); if (MoneyCode != "0") tj += " and a.MoneyCode='" + MoneyCode + "' "; string sql = @" select a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end from JC_Shop a inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a inner join JC_Shop b on a.ShopId=b.ShopId where a.State>0 " + tj + " and a.State<3 and a.InDate>='" + SDate + "' and a.InDate<='" + endtime + @"' group by b.ShopId)c on a.ShopId=c.ShopId where a.CompanyId=1 " + tj1 + " order by " + Sort; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 16); } #endregion #region 报表20 [WebMethod(EnableSession = true)] public string GetReportTable20(int ChaseId) { var obj = new CG_ChaseData(); var md = obj.GetPurchaseModel(ChaseId); var list=obj.GetPurchaseTableGoods(ChaseId); if(md==null||list==null) return ""; StringBuilder shtml = new StringBuilder(); string supper = ""; if (md.Supplier!=null) { if(md.Supplier!="") { supper = md.Supplier; } } if (supper=="") { supper = list.First().SupplierName; } shtml.Append(""); shtml.Append(""); shtml.Append(""); shtml.Append(""); shtml.Append(""); shtml.Append(""); shtml.Append("
采 购 清 单
批次编号"+md.ChaseCode+"发货编号"+md.BuyCode+"导出时间"+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"
    分包数 
供应商名称:" + md.Supplier + "联系人姓名:" + md.Supplier + "供应商电话"+md.SupplierPhone+"
"); int Num=0; foreach(var gmd in list) { decimal tprice = gmd.BuyNum.Value * gmd.GoodsPrice.Value; Num+=gmd.BuyNum.Value; shtml.Append(""); } shtml.Append(""); shtml.Append("
编码新编号名称供应商编码规格描述购买数量单价合计发货数量
" + gmd.GoodsOldCode + "" + gmd.GoodsCode + "" + gmd.GoodsName + "" + gmd.GoodsSupplyCode + "" + gmd.TypeDesc + "" + gmd.BuyNum + "" + gmd.GoodsPrice + "" + tprice + "
总计:" + Num + "" + md.GoodsMoney + "
运费:" + md.PostFee + "运单号:
"); return shtml.ToString(); } #endregion #region 报表列 [WebMethod(EnableSession = true)] public List GetReportCols(int ReportId) { PagesNew.Login(this.Session); var obj = new BaseService(); var rlist = obj.GetRepoartColsList(ReportId); return rlist; } #endregion #region 报表2 [WebMethod(EnableSession = true)] public string GetReportTable2(DateTime? SDate,DateTime? EDate,int PlatId, string GoodsCode, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (PlatId > 0) tj += " and d.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and d.ShopId=" + ShopId + " "; if (GoodsCode != "") { tj += " and ( c.GoodsOldCode='" + GoodsCode + "' or c.GoodsCode='" + GoodsCode + "' ) "; } if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @" select c.GoodsName,c.GoodsOldCode,b.TypeCode,b.TypeDesc,a.GoodsNum,a.OrderNum,a.TotalPrice from ( select c.GoodsId,a.DetailId, GoodsNum=sum(a.GoodsNum),OrderNum=COUNT(0),TotalPrice=Sum(d.TotalPrice) from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where d.CompanyId="+CompanyId+tj+@" and d.State>0 and d.State<3 group by c.GoodsId,a.DetailId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId order by c.GoodsId,b.TypeCode "; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 2); } #endregion #region 报表2 [WebMethod(EnableSession = true)] public string GetExcelTable2(DateTime? SDate, DateTime? EDate, int PlatId, string GoodsCode, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (PlatId > 0) tj += " and d.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and d.ShopId=" + ShopId + " "; if (GoodsCode != "") { tj += " and ( c.GoodsOldCode='" + GoodsCode + "' or c.GoodsCode='" + GoodsCode + "' ) "; } if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @" select c.GoodsName,c.GoodsOldCode,b.TypeCode,b.TypeDesc,a.GoodsNum,a.OrderNum,a.TotalPrice from ( select c.GoodsId,a.DetailId, GoodsNum=sum(a.GoodsNum),OrderNum=COUNT(0),TotalPrice=Sum(d.TotalPrice) from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where d.CompanyId=" + CompanyId + tj + @" and d.State>0 and d.State<3 group by c.GoodsId,a.DetailId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId order by c.GoodsId,b.TypeCode "; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 2); } #endregion #region 报表3 [WebMethod(EnableSession = true)] public string GetReportTable3(DateTime? SDate, DateTime? EDate, Int32? SNum, Int32? ENum,int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); if (SNum == null) SNum = 0; string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; if (PlatId > 0) tj += " and a.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and a.ShopId=" + ShopId + " "; if (SDate != null) tj += " and a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (SNum != null) tj1 += " where OrderNum>=" + SNum + " "; if (ENum != null) tj1 += " and OrderNum<=" + ENum + " "; string sql = @"select * from ( select b.RevMail,b.CustomID,b.RevName,OrderNum=COUNT(0),TotalPrice=SUM(a.TotalPrice) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.State>0 and a.State<3 and a.CompanyId="+CompanyId+tj+@" and b.RevMail is not null and b.RevMail<>'' group by b.RevMail,b.CustomID,b.RevName)a "+tj1+@" order by OrderNum desc "; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 3); } #endregion #region 报表3 [WebMethod(EnableSession = true)] public string GetExcelTable3(DateTime? SDate, DateTime? EDate, Int32? SNum, Int32? ENum, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); if (SNum == null) SNum = 0; string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; if (PlatId > 0) tj += " and a.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and a.ShopId=" + ShopId + " "; if (SDate != null) tj += " and a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (SNum != null) tj1 += " where OrderNum>=" + SNum + " "; if (ENum != null) tj1 += " and OrderNum<=" + ENum + " "; string sql = @"select * from ( select b.RevMail,b.CustomID,b.RevName,OrderNum=COUNT(0),TotalPrice=SUM(a.TotalPrice) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.State>0 and a.State<3 and a.CompanyId=" + CompanyId + tj + @" and b.RevMail is not null and b.RevMail<>'' group by b.RevMail,b.CustomID,b.RevName)a " + tj1 + @" order by OrderNum desc "; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 3); } #endregion #region 报表4 [WebMethod(EnableSession = true)] public string GetReportTable4(DateTime? SDate, DateTime? EDate, string Supplier, string GoodsCode, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (SDate != null) tj += " and b.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (GoodsCode != "") tj1 += " where d.GoodsCode='" + GoodsCode + "' "; if (tj1!=""&&Supplier != "") tj1 += " and d.SupplierId like '%" + Supplier + "%' "; else if (tj1 == "" && Supplier != "") tj1 += " where d.SupplierId like '%" + Supplier + "%' "; string sql = @"select top 400 GoodsOldCode=d.GoodsCode,d.GoodsName,c.TypeDesc,a.*,LeftNum=c.GoodsNum+c.GoodsInNum-c.GoodsPlanNum,Supplier=d.SupplierId,d.GoodsSupplyCode,Price=case when c.Price>0 then c.Price else d.NowPrice end from ( select a.DetailId,GoodsNum=SUM(a.GoodsNum),OrderNum=COUNT(0) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.State>0 and b.State<3 and b.CompanyId=" + CompanyId + tj + @" and a.DetailId>0 group by a.DetailId)a inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId " + tj1 + @" order by d.GoodsId,a.GoodsNum desc "; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 4); } #endregion #region 报表4 [WebMethod(EnableSession = true)] public string GetExcelTable4(DateTime? SDate, DateTime? EDate, string Supplier, string GoodsCode, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (SDate != null) tj += " and b.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (GoodsCode != "") tj1 += " where d.GoodsCode='" + GoodsCode + "' "; if (tj1 != "" && Supplier != "") tj1 += " and d.SupplierId like '%" + Supplier + "%' "; else if (tj1 == "" && Supplier != "") tj1 += " where d.SupplierId like '%" + Supplier + "%' "; string sql = @"select top 400 GoodsOldCode=d.GoodsCode,d.GoodsName,c.TypeDesc,a.*,LeftNum=c.GoodsNum+c.GoodsInNum-c.GoodsPlanNum,Supplier=d.SupplierId,d.GoodsSupplyCode,Price=case when c.Price>0 then c.Price else d.NowPrice end from ( select a.DetailId,GoodsNum=SUM(a.GoodsNum),OrderNum=COUNT(0) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.State>0 and b.State<3 and b.CompanyId=" + CompanyId + tj + @" and a.DetailId>0 group by a.DetailId)a inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId " + tj1 + @" order by d.GoodsId,a.GoodsNum desc "; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 4); } #endregion #region 报表6 [WebMethod(EnableSession = true)] public string GetReportTable6(DateTime? SDate, DateTime? EDate, string Reason1, string Reason2, string Reason3, int DeptId, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); if (EDate == null) EDate = DateTime.Now; string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (DeptId > 0) tj += " and c.DeptId=" + DeptId + " "; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (SDate != null) tj += " and a.BackDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.BackDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (Reason1 != "0") tj += " and a.BackReason1='" + Reason1 + "' "; if (Reason2 != "0") tj += " and a.BackReason2='" + Reason2 + "' "; if (Reason3 != "0") tj += " and a.BackReason3='" + Reason3 + "' "; string sql = @"select d.DeptName,c.ShopName,b.PlatOrderCode,a.BackDate,a.InDate,a.BackMoney,a.BackType,a.BackMoneyCode,a.BackReason1,a.BackReason2,a.BackReason3,a.BackRemark,e.TrackCode,b.PostDate,ImageIds='http://server.store1945.com:9988/tmsk/'+(SELECT TOP 1 FileUrl FROM dbo.JC_Resource e WHERE e.id=substring(a.ImageIds,0,charindex(',',a.ImageIds+','))) from DT_OrderSaleBack a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join JC_Shop c on b.ShopId=c.ShopId inner join JC_DepartMent d on c.DeptId=d.DeptId left JOIN (select OrderId,TrackCode from DT_TrackCodeApply where id in ( select id=MAX(id) from DT_TrackCodeApply where state=1 and trackType=1 group by OrderId)) e ON a.OrderId=e.OrderId where a.SaleType=2 and b.CompanyId=" + CompanyId + tj + @" and a.BackMoney is not null "; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 6); } #endregion #region 报表6 [WebMethod(EnableSession = true)] public string GetExcelTable6(DateTime? SDate, DateTime? EDate, string Reason1, string Reason2, string Reason3, int DeptId, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); if (EDate == null) EDate = DateTime.Now; string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (DeptId > 0) tj += " and c.DeptId=" + DeptId + " "; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (SDate != null) tj += " and a.BackDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.BackDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (Reason1 != "0") tj += " and a.BackReason1='" + Reason1 + "' "; if (Reason2 != "0") tj += " and a.BackReason2='" + Reason2 + "' "; if (Reason3 != "0") tj += " and a.BackReason3='" + Reason3 + "' "; string sql = @"select d.DeptName,c.ShopName,b.PlatOrderCode,a.BackDate,a.InDate,a.BackMoney,a.BackType,a.BackMoneyCode,a.BackReason1,a.BackReason2,a.BackReason3,a.BackRemark,e.TrackCode,b.PostDate,ImageIds='http://server.store1945.com:9988/tmsk/'+(SELECT TOP 1 FileUrl FROM dbo.JC_Resource e WHERE e.id=substring(a.ImageIds,0,charindex(',',a.ImageIds+','))) from DT_OrderSaleBack a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join JC_Shop c on b.ShopId=c.ShopId inner join JC_DepartMent d on c.DeptId=d.DeptId left JOIN (select OrderId,TrackCode from DT_TrackCodeApply where id in ( select id=MAX(id) from DT_TrackCodeApply where state=1 and trackType=1 group by OrderId)) e ON a.OrderId=e.OrderId where a.SaleType=2 and b.CompanyId=" + CompanyId + tj + @" and a.BackMoney is not null "; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 6); } #endregion #region 报表7 [WebMethod(EnableSession = true)] public string GetReportTable7(DateTime? SDate, DateTime? EDate, string Reason1, string Reason2, string Reason3, int DeptId, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); if (EDate == null) EDate = DateTime.Now; string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (DeptId > 0) tj += " and c.DeptId=" + DeptId + " "; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (SDate != null) tj += " and a.BadDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.BadDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (Reason1 != "0") tj += " and a.BadType='" + Reason1 + "' "; if (Reason2 != "0") tj += " and a.ChangeBad='" + Reason2 + "' "; if (Reason3 != "0") tj += " and a.BadReason='" + Reason3 + "' "; string sql = @"select d.DeptName,c.ShopName,b.PlatOrderCode,a.BadDate,a.InDate,a.BadType,a.ChangeBad,a.BadReason,a.BadRemark,a.GoodsUrl,t.CountryName,t.RevMoblie,t.RevName,a.GoodsCode from DT_OrderSaleBack a inner join DT_OrderInfo b on a.OrderId=b.OrderId INNER JOIN dbo.DT_OrderXXInfo t ON t.OrderId=b.OrderId inner join JC_Shop c on b.ShopId=c.ShopId inner join JC_DepartMent d on c.DeptId=d.DeptId where a.SaleType=1" + tj + @""; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 7); } #endregion #region 报表7 [WebMethod(EnableSession = true)] public string GetExcelTable7(DateTime? SDate, DateTime? EDate, string Reason1, string Reason2, string Reason3, int DeptId, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); if (EDate == null) EDate = DateTime.Now; string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (DeptId > 0) tj += " and c.DeptId=" + DeptId + " "; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (SDate != null) tj += " and a.BadDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.BadDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (Reason1 != "0") tj += " and a.BadType='" + Reason1 + "' "; if (Reason2 != "0") tj += " and a.ChangeBad='" + Reason2 + "' "; if (Reason3 != "0") tj += " and a.BadReason='" + Reason3 + "' "; string sql = @"select d.DeptName,c.ShopName,b.PlatOrderCode,a.BadDate,a.InDate,a.BadType,a.ChangeBad,a.BadReason,a.BadRemark,a.GoodsUrl,t.CountryName,t.RevMoblie,t.RevName,a.GoodsCode from DT_OrderSaleBack a inner join DT_OrderInfo b on a.OrderId=b.OrderId INNER JOIN dbo.DT_OrderXXInfo t ON t.OrderId=b.OrderId inner join JC_Shop c on b.ShopId=c.ShopId inner join JC_DepartMent d on c.DeptId=d.DeptId where a.SaleType=1" + tj + @""; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 7); } #endregion #region 报表8 [WebMethod(EnableSession = true)] public string GetReportTable8(DateTime? SDate, DateTime? EDate, string Supplier, string GoodsCode, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (SDate != null) tj += " and b.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (GoodsCode != "") tj1 += " where b.GoodsOldCode='" + GoodsCode + "' "; if (tj1 != "" && Supplier != "") tj1 += " and b.SupplierId like '%" + Supplier + "%' "; else if (tj1 == "" && Supplier != "") tj1 += " where b.SupplierId like '%" + Supplier + "%' "; string sql = @"select d.ShopName,b.GoodsOldCode,b.GoodsName,a.GoodsNum,Supplier=b.SupplierId,c.TypeDesc from ( select b.ShopId,a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.DetailId=c.DetailId where b.CompanyId=" +CompanyId+tj+@" and b.State=1 and c.GoodsNum+c.GoodsInNum-c.GoodsPlanNum<0 group by b.ShopId,a.DetailId)a inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo b on c.GoodsId=b.GoodsId inner join JC_Shop d on a.ShopId=d.ShopId "+tj1+@" "; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 8); } #endregion #region 报表8 [WebMethod(EnableSession = true)] public string GetExcelTable8(DateTime? SDate, DateTime? EDate, string Supplier, string GoodsCode, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (SDate != null) tj += " and b.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (GoodsCode != "") tj1 += " where b.GoodsOldCode='" + GoodsCode + "' "; if (tj1 != "" && Supplier != "") tj1 += " and b.SupplierId like '%" + Supplier + "%' "; else if (tj1 == "" && Supplier != "") tj1 += " where b.SupplierId like '%" + Supplier + "%' "; string sql = @"select d.ShopName,b.GoodsOldCode,b.GoodsName,a.GoodsNum,Supplier=b.SupplierId,c.TypeDesc from ( select b.ShopId,a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.DetailId=c.DetailId where b.CompanyId=" + CompanyId + tj + @" and b.State=1 and c.GoodsNum+c.GoodsInNum-c.GoodsPlanNum<0 group by b.ShopId,a.DetailId)a inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo b on c.GoodsId=b.GoodsId inner join JC_Shop d on a.ShopId=d.ShopId " + tj1 + @" "; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 8); } #endregion #region 跟踪码导出 [WebMethod(EnableSession = true)] public string GetReportTrack(DateTime? SDate, DateTime? EDate, int PlatId, int ShopId, int LogisticId, int postid, int DateType) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (DateType == 2) { if (SDate != null) tj += " and b.PostDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.PostDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (DateType == 1) { if (SDate != null) tj += " and b.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (LogisticId > 0) { tj += " and e.LogisticsId=" + LogisticId + " "; } if (postid > 0) { tj += " and a.PostId=" + postid + " "; } string sql = @"SELECT a.TrackCode,d.ShopName,e.Name,b.OrderCode,b.PostDate,t.LogisticsName,o.RevMoblie,o.RevPhone FROM DT_TrackCodeScan a WITH (NOLOCK) INNER JOIN DT_OrderInfo b WITH (NOLOCK) on a.OrderId=b.OrderId inner join JC_Shop d WITH (NOLOCK) on b.ShopId=d.ShopId INNER JOIN dbo.JC_Express e WITH (NOLOCK) ON e.ExpressID=a.PostId INNER JOIN dbo.JC_ExpressType t WITH (NOLOCK) ON t.LogisticsId=e.LogisticsId INNER JOIN dbo.DT_OrderXXInfo o WITH (NOLOCK) ON o.OrderId=b.OrderId where 1=1 " + tj + @""; if (DateType == 1) { sql = @"SELECT a.TrackCode,d.ShopName,e.Name,b.OrderCode,b.PostDate,t.LogisticsName,o.RevMoblie,o.RevPhone FROM DT_TrackCodeApply a WITH (NOLOCK) INNER JOIN DT_OrderInfo b WITH (NOLOCK) on a.OrderId=b.OrderId inner join JC_Shop d WITH (NOLOCK) on b.ShopId=d.ShopId INNER JOIN dbo.JC_Express e WITH (NOLOCK) ON e.ExpressID=a.PostId INNER JOIN dbo.JC_ExpressType t WITH (NOLOCK) ON t.LogisticsId=e.LogisticsId INNER JOIN dbo.DT_OrderXXInfo o WITH (NOLOCK) ON o.OrderId=b.OrderId where a.State=1 " + tj + @""; } DataTable dt = obj.GetReportData(sql); return GetReport(dt, 19); } #endregion #region 报表10 [WebMethod(EnableSession = true)] public string GetReportTable10(DateTime? Date1, DateTime? SDate, DateTime? EDate, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; if (PlatId > 0) { tj += " and b.PlatId=" + PlatId + " "; tj1 = " and b.PlatId=" + PlatId + " "; } if (ShopId > 0) { tj += " and b.ShopId=" + ShopId + " "; tj1 = " and b.PlatId=" + PlatId + " "; } if (Date1 != null) tj += " and datediff(day,b.OrderDate,'" + Date1.Value.ToString("yyyy-MM-dd") + "')=0 "; if (SDate != null) tj1 += " and b.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj1 += " and b.OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; TimeSpan sp = EDate.Value.Subtract(SDate.Value); int days = sp.Days; if (days < 1) days = 1; string sql = @"select a.*,AvgOrderNum=isnull(b.AvgOrderNum,0),OrderNum1=isnull(b.OrderNum,0),TotalPrice1=isnull(b.TotalPrice,0) from ( select d.GoodsId,d.GoodsOldCode,OrderNum=COUNT(0),TotalPrice=SUM(b.TotalPrice) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where b.CompanyId="+CompanyId+tj+@" and b.State>0 and b.State<3 and a.DetailId>0 group by d.GoodsId,d.GoodsOldCode )a left join ( select d.GoodsId,d.GoodsOldCode,OrderNum=COUNT(0),TotalPrice=SUM(b.TotalPrice),AvgOrderNum=COUNT(0)/"+days+@" from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where b.CompanyId=" + CompanyId +tj1+ @" and b.State>0 and b.State<3 and a.DetailId>0 group by d.GoodsId,d.GoodsOldCode)b on a.GoodsId=b.GoodsId"; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 10); } #endregion #region 报表11 [WebMethod(EnableSession = true)] public string GetReportTable11(DateTime? SDate, DateTime? EDate, int IsLeft) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (IsLeft==1) { tj += " and isnull(b.GoodsNum,0)+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0)>0 "; } if (SDate != null) tj += " and a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select c.GoodsCode,c.GoodsOldCode,c.GoodsName,c.SupplierId,b.TypeCode,b.TypeDesc,d.PlatOrderCode,shopname=dbo.GetShopName(d.ShopId),a.InDate,b.GoodsNum,b.GoodsPlanNum,b.GoodsInNum,LeftNum=isnull(b.GoodsNum,0)+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0),OffNum=case when a.NowDetailId<>a.OldDetailId then a.OldNum when a.NowDetailId=a.OldDetailId then a.OldNum-a.NowNum end, StateName=case when a.NowDetailId=0 then '取消' else '修改' end from [DT_OrderGoodsChange] a inner join HW_GoodsDetail b on a.OldDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId where a.CompanyId=" +CompanyId+tj+" and (NowDetailId<>OldDetailId or OldNum>NowNum)"; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 11); } #endregion #region 报表11 [WebMethod(EnableSession = true)] public string GetExcelTable11(DateTime? SDate, DateTime? EDate, int IsLeft) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (IsLeft == 1) { tj += " and isnull(b.GoodsNum,0)+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0)>0 "; } if (SDate != null) tj += " and a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select c.GoodsCode,c.GoodsOldCode,c.GoodsName,c.SupplierId,b.TypeCode,b.TypeDesc,d.PlatOrderCode,shopname=dbo.GetShopName(d.ShopId),a.InDate,b.GoodsNum,b.GoodsPlanNum,b.GoodsInNum,LeftNum=isnull(b.GoodsNum,0)+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0),OffNum=case when a.NowDetailId<>a.OldDetailId then a.OldNum when a.NowDetailId=a.OldDetailId then a.OldNum-a.NowNum end, StateName=case when a.NowDetailId=0 then '取消' else '修改' end from [DT_OrderGoodsChange] a inner join HW_GoodsDetail b on a.OldDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId where a.CompanyId=" + CompanyId + tj + " and (NowDetailId<>OldDetailId or OldNum>NowNum)"; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 11); } #endregion #region 报表13 [WebMethod(EnableSession = true)] public string GetReportTable13(DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (SDate != null) tj += " and a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select a.ChaseCode,a.BuyCode,Price=a.GoodsMoney,a.PostFee,TotalPrice=a.GoodsMoney+ISNULL(a.PostFee,0),Suplier=(select top 1 c.SupplierId from CG_PurchaseGoods aa inner join HW_GoodsDetail b on aa.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where aa.ChaseId=a.ChaseId and c.SupplierId is not null and c.SupplierId<>''),FeeType=(select top 1 MoneyType=case when d.MoneyType is not null and d.MoneyType<>'' then d.MoneyType else '现结' end from CG_PurchaseGoods aa inner join HW_GoodsDetail b on aa.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId left join JC_Supplier d on c.Supplier=d.SupplierId where aa.ChaseId=a.ChaseId),FeeState='' from CG_Purchase a where a.State>0 and a.IsDelete=0 and a.CompanyId=" + CompanyId + tj; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 13); } #endregion #region 报表13 [WebMethod(EnableSession = true)] public string GetReportExcel13(DateTime? SDate, DateTime? EDate) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (SDate != null) tj += " and a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select a.ChaseCode,a.BuyCode,Price=a.GoodsMoney,a.PostFee,TotalPrice=a.GoodsMoney+ISNULL(a.PostFee,0),Suplier=(select top 1 c.SupplierId from CG_PurchaseGoods aa inner join HW_GoodsDetail b on aa.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where aa.ChaseId=a.ChaseId and c.SupplierId is not null and c.SupplierId<>''),FeeType=(select top 1 MoneyType=case when d.MoneyType is not null and d.MoneyType<>'' then d.MoneyType else '现结' end from CG_PurchaseGoods aa inner join HW_GoodsDetail b on aa.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId left join JC_Supplier d on c.Supplier=d.SupplierId where aa.ChaseId=a.ChaseId),FeeState='' from CG_Purchase a where a.State>0 and a.IsDelete=0 and a.CompanyId=" + CompanyId + tj; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 13); } #endregion #region 报表14 [WebMethod(EnableSession = true)] public string GetReportTable14(DateTime? SDate, DateTime? EDate,int GoodsNum,decimal? Price,int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; if (ShopId>0) tj1=" and a.ShopId="+ShopId+" "; if (SDate != null) tj += " and b.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select a.GoodsNum,a.Price,d.GoodsName,d.GoodsCode,d.GoodsOldCode,e.ShopName,Suplier=d.SupplierId,MoneyCode='USD' from ( select b.ShopId,d.GoodsId,GoodsNum=SUM(a.GoodsNum),Price=SUM([dbo].[MoneyUSDChange](b.TotalPrice,b.MoneyCode,b.CompanyId)/a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where b.State>0 and b.State<3 and b.CompanyId=" + CompanyId + tj+ @" group by b.ShopId,d.GoodsId)a inner join HW_GoodsInfo d on a.GoodsId=d.GoodsId inner join JC_Shop e on a.ShopId=e.ShopId where a.GoodsNum>" + GoodsNum + " and a.Price>=" + Price + tj1; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 14); } #endregion #region 报表14 [WebMethod(EnableSession = true)] public string GetReportExcel14(DateTime? SDate, DateTime? EDate, int GoodsNum, decimal? Price, int ShopId) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; if (ShopId > 0) tj1 = " and a.ShopId=" + ShopId + " "; if (SDate != null) tj += " and b.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select a.GoodsNum,a.Price,d.GoodsName,d.GoodsCode,d.GoodsOldCode,e.ShopName,Suplier=d.SupplierId,MoneyCode='USD' from ( select b.ShopId,d.GoodsId,GoodsNum=SUM(a.GoodsNum),Price=SUM([dbo].[MoneyUSDChange](b.TotalPrice,b.MoneyCode,b.CompanyId)/a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where b.State>0 and b.State<3 and b.CompanyId=" + CompanyId + tj + @" group by b.ShopId,d.GoodsId)a inner join HW_GoodsInfo d on a.GoodsId=d.GoodsId inner join JC_Shop e on a.ShopId=e.ShopId where a.GoodsNum>" + GoodsNum + " and a.Price<=" + Price + tj1; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 14); } #endregion #region 报表23 [WebMethod(EnableSession = true)] public string GetReportTable23(string Supplier, string GoodsCode) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj1 = ""; if (GoodsCode != "") tj1 += " where (c.GoodsOldCode='" + GoodsCode + "' or c.GoodsCode='" + GoodsCode + "') "; if (tj1 != "" && Supplier != "") tj1 += " and c.SupplierId like '%" + Supplier + "%' "; else if (tj1 == "" && Supplier != "") tj1 += " where c.SupplierId like '%" + Supplier + "%' "; string sql = @"select c.GoodsCode,c.GoodsOldCode,c.GoodsName,b.TypeCode,b.TypeDesc,a.GoodsNum,b.GoodsInNum,b.GoodsPlanNum,LeftNum=a.GoodsNum+b.GoodsInNum-b.GoodsPlanNum,c.SupplierId,c.GoodsSupplyCode,Price=case when b.Price>0 then b.Price else c.NowPrice end,d.PostionCode from ( select DetailId,PostionId,GoodsNum=SUM(kcnum) from HW_GoodsInDetail where OrderGoodsId=0 group by DetailId,PostionId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join CK_StorePostion d on a.PostionId=d.PostionId "+tj1+@" order by c.GoodsId,b.TypeCode "; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 23); } #endregion #region 报表23 [WebMethod(EnableSession = true)] public string GetExcelTable23(string Supplier, string GoodsCode) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj1 = ""; if (GoodsCode != "") tj1 += " where (c.GoodsOldCode='" + GoodsCode + "' or c.GoodsCode='" + GoodsCode + "') "; if (tj1 != "" && Supplier != "") tj1 += " and c.SupplierId like '%" + Supplier + "%' "; else if (tj1 == "" && Supplier != "") tj1 += " where c.SupplierId like '%" + Supplier + "%' "; string sql = @"select c.GoodsCode,c.GoodsOldCode,c.GoodsName,b.TypeCode,b.TypeDesc,a.GoodsNum,b.GoodsInNum,b.GoodsPlanNum,LeftNum=a.GoodsNum+b.GoodsInNum-b.GoodsPlanNum,c.SupplierId,c.GoodsSupplyCode,Price=case when b.Price>0 then b.Price else c.NowPrice end,d.PostionCode from ( select DetailId,PostionId,GoodsNum=SUM(kcnum) from HW_GoodsInDetail where OrderGoodsId=0 group by DetailId,PostionId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join CK_StorePostion d on a.PostionId=d.PostionId " + tj1 + @" order by c.GoodsId,b.TypeCode "; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 23); } #endregion #region 跟踪码导出表格 [WebMethod(EnableSession = true)] public string GetReportTrackToExcel(DateTime? SDate, DateTime? EDate, int PlatId, int ShopId, int LogisticId, int postid, int DateType) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (DateType == 2) { if (SDate != null) tj += " and b.PostDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.PostDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (DateType == 1) { if (SDate != null) tj += " and b.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (LogisticId > 0) { tj += " and e.LogisticsId=" + LogisticId + " "; } if (postid > 0) { tj += " and a.PostId=" + postid + " "; } string sql = @"SELECT a.TrackCode,d.ShopName,e.Name,a.OrderCode,b.PostDate,t.LogisticsName,o.RevMoblie,o.RevPhone FROM DT_TrackCodeScan a WITH (NOLOCK) INNER JOIN DT_OrderInfo b WITH (NOLOCK) on a.OrderCode=b.OrderCode OR a.OrderCode=b.JoinOrderCode inner join JC_Shop d WITH (NOLOCK) on b.ShopId=d.ShopId INNER JOIN dbo.JC_Express e WITH (NOLOCK) ON e.ExpressID=a.PostId INNER JOIN dbo.JC_ExpressType t WITH (NOLOCK) ON t.LogisticsId=e.LogisticsId INNER JOIN dbo.DT_OrderXXInfo o WITH (NOLOCK) ON o.OrderId=b.OrderId where 1=1 " + tj + @" "; if (DateType == 1) { sql = @"SELECT a.TrackCode,d.ShopName,e.Name,a.OrderCode,b.PostDate,t.LogisticsName,o.RevMoblie,o.RevPhone FROM DT_TrackCodeApply a WITH (NOLOCK) INNER JOIN DT_OrderInfo b WITH (NOLOCK) on a.OrderCode=b.OrderCode OR a.OrderCode=b.JoinOrderCode inner join JC_Shop d WITH (NOLOCK) on b.ShopId=d.ShopId INNER JOIN dbo.JC_Express e WITH (NOLOCK) ON e.ExpressID=a.PostId INNER JOIN dbo.JC_ExpressType t WITH (NOLOCK) ON t.LogisticsId=e.LogisticsId INNER JOIN dbo.DT_OrderXXInfo o WITH (NOLOCK) ON o.OrderId=b.OrderId where a.state=1 " + tj + @""; } DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 19); } #endregion #region 导出报表 public string GetExcelReport(DataTable dt, int ReportId) { PagesNew.Login(this.Session); var obj = new BaseService(); TableColumnCollection listColumns = new TableColumnCollection(); var rmd = BaseService.GetReportModel(ReportId); var rlist = obj.GetRepoartColsList(ReportId); if (rmd == null || rlist == null || dt==null) return ""; DataRow row = null; int hj = 0; foreach (var md in rlist) { if(md.IsExcel==1) listColumns.Add(md.ColValue, md.ColName, DbType.String, ""); if (md.IsSum == 1) { if (row == null) row = dt.NewRow(); if (md.ColType == "int" && dt != null && dt.Rows.Count > 0) row[md.ColValue] = Convert.ToInt32(dt.Compute("sum(" + md.ColValue + ")", "")); else if (md.ColType == "dec" && dt != null && dt.Rows.Count>0) row[md.ColValue] = Convert.ToDecimal(dt.Compute("sum(" + md.ColValue + ")", "")); } else if (hj == 0&&md.ColType=="str") { if (row == null) row = dt.NewRow(); row[md.ColValue] = "合计:"; } } if (row != null) dt.Rows.Add(row); MicrosoftExcel obj2 = new MicrosoftExcel(); return obj2.Export(dt, listColumns); } #endregion #region 报表15 [WebMethod(EnableSession = true)] public string GetReportTable15(DateTime? SDate, DateTime? EDate) { var obj1 = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); DataTable dt = obj1.GetLowGoodsPriceList(SDate, EDate.Value.AddDays(1)); var olist = obj1.GetSumGoodsNumList(SDate, EDate.Value.AddDays(1), SDate, EDate.Value.AddDays(8)); if (dt != null) { for (int i = 0; i < dt.Rows.Count; i++) { DateTime? SDate1 = null; DateTime? EDate1 = null; if (dt.Rows[i]["InDate"] != null) EDate1 = Convert.ToDateTime(dt.Rows[i]["InDate"]); SDate1 = EDate1.Value.AddMonths(-3); int DetailId = Convert.ToInt32(dt.Rows[i]["DetailId"]); int GoodsId = Convert.ToInt32(dt.Rows[i]["GoodsId"]); decimal Price = 0; if (dt.Rows[i]["Price"] != null) Price = Convert.ToDecimal(dt.Rows[i]["Price"]); decimal offprice = 0; int Num = 0; if(olist!=null&&olist.Count>0) { var omd = olist.Find(n => n.DetailId == DetailId && n.Price == Price); if(omd!=null) { Num = omd.GoodsNum.Value; dt.Rows[i]["GoodsNum"]=omd.GoodsNum; if(dt.Rows[i]["LowPrice"]==null||Convert.ToDecimal(dt.Rows[i]["LowPrice"])<=0) { decimal a = obj1.GetLowGoodsPrice(EDate1, SDate1, DetailId, GoodsId); if (a > 0 && a > Price) offprice = a - Price; } else if(Convert.ToDecimal(dt.Rows[i]["LowPrice"])>Price) offprice = Convert.ToDecimal(dt.Rows[i]["LowPrice"]) - Price; } } dt.Rows[i]["OffPrice"] = offprice; dt.Rows[i]["TotalPrice"] = Num * offprice; } for (int i = dt.Rows.Count-1; i>=0; i--) { if (Convert.ToDecimal(dt.Rows[i]["TotalPrice"]) <= 0) dt.Rows.RemoveAt(i); } } return GetReport(dt, 15); } #endregion #region 报表15 [WebMethod(EnableSession = true)] public string GetReportExcel15(DateTime? SDate, DateTime? EDate) { var obj1 = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); DataTable dt = obj1.GetLowGoodsPriceList(SDate, EDate.Value.AddDays(1)); var olist = obj1.GetSumGoodsNumList(SDate, EDate.Value.AddDays(1), SDate, EDate.Value.AddDays(8)); if (dt != null) { for (int i = 0; i < dt.Rows.Count; i++) { DateTime? SDate1 = null; DateTime? EDate1 = null; if (dt.Rows[i]["InDate"] != null) EDate1 = Convert.ToDateTime(dt.Rows[i]["InDate"]); SDate1 = EDate1.Value.AddMonths(-3); int DetailId = Convert.ToInt32(dt.Rows[i]["DetailId"]); int GoodsId = Convert.ToInt32(dt.Rows[i]["GoodsId"]); decimal Price = 0; if (dt.Rows[i]["Price"] != null) Price = Convert.ToDecimal(dt.Rows[i]["Price"]); decimal offprice = 0; int Num = 0; if (olist != null && olist.Count > 0) { var omd = olist.Find(n => n.DetailId == DetailId && n.Price == Price); if (omd != null) { Num = omd.GoodsNum.Value; dt.Rows[i]["GoodsNum"] = omd.GoodsNum; if (dt.Rows[i]["LowPrice"] == null || Convert.ToDecimal(dt.Rows[i]["LowPrice"]) <= 0) { decimal a = obj1.GetLowGoodsPrice(EDate1, SDate1, DetailId, GoodsId); if (a > 0 && a > Price) offprice = a - Price; } else if (Convert.ToDecimal(dt.Rows[i]["LowPrice"]) > Price) offprice = Convert.ToDecimal(dt.Rows[i]["LowPrice"]) - Price; } } dt.Rows[i]["OffPrice"] = offprice; dt.Rows[i]["TotalPrice"] = Num * offprice; } for (int i = dt.Rows.Count - 1; i >= 0; i--) { if (Convert.ToDecimal(dt.Rows[i]["TotalPrice"]) <= 0) dt.Rows.RemoveAt(i); } } return GetExcelReport(dt, 15); } #endregion #region 报表22 [WebMethod(EnableSession = true)] public string GetReportTable22(int TopNum, string ShopIds, DateTime? SDate, string GoodsCode, string Supplier) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; if (GoodsCode.Trim() != "") { GoodsCode = GoodsCode.Trim(); tj = " and (d.GoodsCode='" + GoodsCode + "' or d.GoodsOldCode='" + GoodsCode + "')"; } if (Supplier != "") { Supplier = Supplier.Trim(); tj += " and d.SupplierId like '%" + Supplier + "%'"; } if (ShopIds != "0" && ShopIds!="") tj1 += " and b.ShopId in (" + ShopIds.Trim(',') + @")"; ShopIds = ShopIds.Trim(','); DateTime PreMSDate = SDate.Value.AddDays(-30); DateTime PreWSDate = GetWeekStart(SDate.Value).AddDays(-7); DateTime PreWEDate = GetWeekStart(SDate.Value); DateTime PreWSDate2 = PreWSDate.AddDays(-7); DateTime PreWEDate2 = PreWEDate.AddDays(-7); DateTime PreNSDate = GetWeekStart(SDate.Value); DateTime PreNEDate = GetWeekStart(SDate.Value).AddDays(7); //if (IsLeft == 1) //{ // tj += " and isnull(b.GoodsNum,0)+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0)>0 "; //} //if (SDate != null) // tj += " and a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; //if (EDate != null) // tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select d.GoodsId,c.DetailId,GoodsOldCode=case when d.GoodsCode is not null and d.GoodsCode<>'' then d.GoodsCode else d.GoodsOldCode end,d.GoodsName,SupplierName=d.SupplierId,SupplierCode=d.GoodsSupplyCode,c.TypeCode,TypeDesc=c.TypeDesc,leftNum=c.GoodsNum+c.GoodsInNum-c.GoodsPlanNum ,Nowprice=case when c.Price>0 then c.Price else d.NowPrice end,PreMWeekNum=0,PreWeekNum=0,PreWeekNum2=0,NWeekNum=0,PreBHNum=null,SJBHNum=null,TotalPrice=null,BuyName=e.BuyerName,BuyDept='',BHName='',BHDate='' from ( select top " +TopNum+@" DetailId,GoodsNum from ( select c.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.DetailId=c.DetailId where a.DetailId>0 and b.State<3 and b.InDate>='" + PreMSDate.ToString("yyyy-MM-01") + @"'and b.InDate<'" + SDate.Value.AddDays(1).ToString("yyyy-MM-dd") + @"' "+ tj1 + @" group by c.DetailId)a order by a.GoodsNum desc)a inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId left join JC_Supplier e on d.Supplier=e.SupplierId where d.CompanyId=1 " + tj+@" order by a.GoodsNum,d.GoodsId,c.TypeCode select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.State<3 and b.InDate>='" + PreMSDate.ToString("yyyy-MM-01") + @"' and b.InDate<'" + SDate.Value.ToString("yyyy-MM-01") + @"' " + tj1 + @" group by a.DetailId select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.State<3 and b.InDate>='" + PreWSDate.ToString("yyyy-MM-dd") + @"' and b.InDate<'" + PreWEDate.ToString("yyyy-MM-dd") + @"'" + tj1 + @" group by a.DetailId select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.State<3 and b.InDate>='" + PreNSDate.ToString("yyyy-MM-dd") + @"'and b.InDate<'" + PreNEDate.ToString("yyyy-MM-dd") + @"' " + tj1 + @" group by a.DetailId select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.State<3 and b.InDate>='" + PreWSDate2.ToString("yyyy-MM-dd") + @"' and b.InDate<'" + PreWEDate2.ToString("yyyy-MM-dd") + @"'" + tj1 + @" group by a.DetailId "; DataSet ds = obj.GetReportData2(sql); DataTable dt1 = ds.Tables[0]; DataTable dt = ds.Tables[0].Clone(); for (int i = dt1.Rows.Count-1; i>=0; i--) { int GoodsId = Convert.ToInt32(dt1.Rows[i]["GoodsId"]); DataRow[] row = dt1.Select("GoodsId=" + GoodsId); int DetailId = Convert.ToInt32(dt1.Rows[i]["DetailId"]); DataRow[] row2 = dt.Select("DetailId=" + DetailId); if (row2 != null && row2.Length > 0) { continue; } if (row != null && row.Length > 0) { for (int j = 0; j < row.Length; j++) { DataRow row1 = dt.NewRow(); row1.ItemArray = row[j].ItemArray;//这是加入的是第一行 dt.Rows.Add(row1); //dt1.Rows.Remove(row[j]); } } } for (int i = 0; i < dt.Rows.Count; i++) { int DetailId=Convert.ToInt32(dt.Rows[i]["DetailId"]); DataRow[] row1 = ds.Tables[1].Select("DetailId=" + DetailId); if (row1 != null && row1.Length > 0) dt.Rows[i]["PreMWeekNum"] = row1[0]["GoodsNum"]; DataRow[] row2 = ds.Tables[2].Select("DetailId=" + DetailId); if (row2 != null && row2.Length > 0) dt.Rows[i]["PreWeekNum"] = row2[0]["GoodsNum"]; DataRow[] row3 = ds.Tables[3].Select("DetailId=" + DetailId); if (row3 != null && row3.Length > 0) dt.Rows[i]["NWeekNum"] = row3[0]["GoodsNum"]; DataRow[] row4 = ds.Tables[4].Select("DetailId=" + DetailId); if (row4 != null && row4.Length > 0) dt.Rows[i]["PreWeekNum2"] = row4[0]["GoodsNum"]; } return GetReport(dt, 20); } #endregion #region 报表22 [WebMethod(EnableSession = true)] public string GetExcelTable22(int TopNum,string ShopIds, DateTime? SDate, string GoodsCode, string Supplier) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; if (GoodsCode.Trim() != "") { GoodsCode = GoodsCode.Trim(); tj = " and (d.GoodsCode='" + GoodsCode + "' or d.GoodsOldCode='" + GoodsCode + "')"; } if (Supplier != "") { Supplier = Supplier.Trim(); tj += " and d.SupplierId like '%" + Supplier + "%'"; } if (ShopIds != "0" && ShopIds != "") tj1 += " and b.ShopId in (" + ShopIds.Trim(',') + @")"; ShopIds = ShopIds.Trim(','); DateTime PreMSDate = SDate.Value.AddDays(-30); DateTime PreWSDate = GetWeekStart(SDate.Value).AddDays(-7); DateTime PreWEDate = GetWeekStart(SDate.Value); DateTime PreWSDate2 = PreWSDate.AddDays(-7); DateTime PreWEDate2 = PreWEDate.AddDays(-7); DateTime PreNSDate = GetWeekStart(SDate.Value); DateTime PreNEDate = GetWeekStart(SDate.Value).AddDays(7); //if (IsLeft == 1) //{ // tj += " and isnull(b.GoodsNum,0)+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0)>0 "; //} //if (SDate != null) // tj += " and a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; //if (EDate != null) // tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select d.GoodsId,c.DetailId,GoodsOldCode=case when d.GoodsCode is not null and d.GoodsCode<>'' then d.GoodsCode else d.GoodsOldCode end,d.GoodsName,SupplierName=d.SupplierId,SupplierCode=d.GoodsSupplyCode,c.TypeCode,TypeDesc=c.TypeDesc,leftNum=c.GoodsNum+c.GoodsInNum-c.GoodsPlanNum ,Nowprice=case when c.Price>0 then c.Price else d.NowPrice end,PreMWeekNum=0,PreWeekNum=0,PreWeekNum2=0,NWeekNum=0,PreBHNum=null,SJBHNum=null,TotalPrice=null,BuyName=e.BuyerName,BuyDept='',BHName='',BHDate='' from ( select top " + TopNum + @" DetailId,GoodsNum from ( select c.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.DetailId=c.DetailId where a.DetailId>0 and b.State<3 and b.InDate>='" + PreMSDate.ToString("yyyy-MM-01") + @"'and b.InDate<'" + SDate.Value.AddDays(1).ToString("yyyy-MM-dd") + @"' " + tj1 + @" group by c.DetailId)a order by a.GoodsNum desc)a inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId left join JC_Supplier e on d.Supplier=e.SupplierId where d.CompanyId=1 " + tj + @" order by a.GoodsNum,d.GoodsId,c.TypeCode select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.State<3 and b.InDate>='" + PreMSDate.ToString("yyyy-MM-01") + @"' and b.InDate<'" + SDate.Value.ToString("yyyy-MM-01") + @"' " + tj1 + @" group by a.DetailId select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.State<3 and b.InDate>='" + PreWSDate.ToString("yyyy-MM-dd") + @"' and b.InDate<'" + PreWEDate.ToString("yyyy-MM-dd") + @"'" + tj1 + @" group by a.DetailId select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.State<3 and b.InDate>='" + PreNSDate.ToString("yyyy-MM-dd") + @"'and b.InDate<'" + PreNEDate.ToString("yyyy-MM-dd") + @"' " + tj1 + @" group by a.DetailId select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.State<3 and b.InDate>='" + PreWSDate2.ToString("yyyy-MM-dd") + @"' and b.InDate<'" + PreWEDate2.ToString("yyyy-MM-dd") + @"'" + tj1 + @" group by a.DetailId "; DataSet ds = obj.GetReportData2(sql); DataTable dt1 = ds.Tables[0]; DataTable dt = ds.Tables[0].Clone(); for (int i = dt1.Rows.Count - 1; i >= 0; i--) { int GoodsId = Convert.ToInt32(dt1.Rows[i]["GoodsId"]); DataRow[] row = dt1.Select("GoodsId=" + GoodsId); int DetailId = Convert.ToInt32(dt1.Rows[i]["DetailId"]); DataRow[] row2 = dt.Select("DetailId=" + DetailId); if (row2 != null && row2.Length > 0) { continue; } if (row != null && row.Length > 0) { for (int j = 0; j < row.Length; j++) { DataRow row1 = dt.NewRow(); row1.ItemArray = row[j].ItemArray;//这是加入的是第一行 dt.Rows.Add(row1); //dt1.Rows.Remove(row[j]); } } } for (int i = 0; i < dt.Rows.Count; i++) { int DetailId = Convert.ToInt32(dt.Rows[i]["DetailId"]); DataRow[] row1 = ds.Tables[1].Select("DetailId=" + DetailId); if (row1 != null && row1.Length > 0) dt.Rows[i]["PreMWeekNum"] = row1[0]["GoodsNum"]; DataRow[] row2 = ds.Tables[2].Select("DetailId=" + DetailId); if (row2 != null && row2.Length > 0) dt.Rows[i]["PreWeekNum"] = row2[0]["GoodsNum"]; DataRow[] row3 = ds.Tables[3].Select("DetailId=" + DetailId); if (row3 != null && row3.Length > 0) dt.Rows[i]["NWeekNum"] = row3[0]["GoodsNum"]; DataRow[] row4 = ds.Tables[4].Select("DetailId=" + DetailId); if (row4 != null && row4.Length > 0) dt.Rows[i]["PreWeekNum2"] = row4[0]["GoodsNum"]; } return GetExcelReport(dt, 20); } #endregion private DateTime GetWeekStart(DateTime datePoint)//函数作用是接受某一天,然后返回该日期所处星期的第一天 { //新建要返回的变量 DateTime result = new DateTime(); //其实到此为止。。就已经判断完所处本周中哪一天了。 C#自带了这个方法,只不过DayOfWeek不是一个基本类型,需要用string取出来。 //转换为我们可以判断操作的string类型 DayOfWeek day = datePoint.DayOfWeek; string dayString = day.ToString(); //switch判断 switch (dayString) { case "Monday": //若就是星期一,那本周开头一天就是这个传进来的变量 result = datePoint.Date; break; case "Tuesday": //以此类推 result = datePoint.Date.AddDays(-1); break; case "Wednesday": result = datePoint.Date.AddDays(-2); break; case "Thursday": result = datePoint.Date.AddDays(-3); break; case "Friday": result = datePoint.Date.AddDays(-4); break; case "Saturday": result = datePoint.Date.AddDays(-5); break; case "Sunday": result = datePoint.Date.AddDays(-6); break; } //switch return result; } #region 报表12 [WebMethod(EnableSession = true)] public string GetReportTable12(DateTime? SDate, DateTime? EDate) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (SDate != null) tj += " aa.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and aa.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select b.Name,Num=COUNT(0),Prcie=sum(a.Prcie) from ( select a.*,Prcie=case when a.Weight<500 and GoodsNum>1 then BagFee*1.1 when a.Weight>=500 and a.Weight<1000 and GoodsNum>1 then BagFee*1.2 when a.Weight>=1000 and a.Weight<2000 and GoodsNum>1 then BagFee*1.4 when a.Weight>2000 and GoodsNum>1 then 5 else BagFee end from ( select aa.BagUserId,aa.Weight,GoodsNum=isnull(b.GoodsNum,1), BagFee=(select BagFee=isnull(MAX(d.BagFee),1) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join HW_GoodsSort d on c.SortId=d.SortId where a.OrderId=aa.OrderId) from DT_TrackCodeScan aa inner join DT_OrderInfo b on aa.OrderId=b.OrderId where "+tj+@" )a)a inner join JC_UserInfo b on a.BagUserId=b.UserId group by b.Name"; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 12); } #endregion #region 报表12 [WebMethod(EnableSession = true)] public string GetReportExcel12(DateTime? SDate, DateTime? EDate) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (SDate != null) tj += " aa.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and aa.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select b.Name,Num=COUNT(0),Prcie=sum(a.Prcie) from ( select a.*,Prcie=case when a.Weight<500 and GoodsNum>1 then BagFee*1.1 when a.Weight>=500 and a.Weight<1000 and GoodsNum>1 then BagFee*1.2 when a.Weight>=1000 and a.Weight<2000 and GoodsNum>1 then BagFee*1.4 when a.Weight>2000 and GoodsNum>1 then 5 else BagFee end from ( select aa.BagUserId,aa.Weight,GoodsNum=isnull(b.GoodsNum,1), BagFee=(select BagFee=isnull(MAX(d.BagFee),1) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join HW_GoodsSort d on c.SortId=d.SortId where a.OrderId=aa.OrderId) from DT_TrackCodeScan aa inner join DT_OrderInfo b on aa.OrderId=b.OrderId where " + tj + @" )a)a inner join JC_UserInfo b on a.BagUserId=b.UserId group by b.Name"; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 12); } #endregion #region 货物总销量 [WebMethod(EnableSession = true)] public string GetGoodTotal(string Supplier, DateTime? SDate, DateTime? EDate,string ShopIds, string GoodsCode) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1= ""; //if (PlatId > 0) // tj += " and d.PlatId=" + PlatId + " "; //if (ShopId > 0) // tj += " and d.ShopId=" + ShopId + " "; if (GoodsCode != "") { tj += " and (c.GoodsOldCode='" + GoodsCode + "' or c.GoodsCode='" + GoodsCode + "' ) "; } if (Supplier != "") { Supplier = Supplier.Trim(); tj += " and c.SupplierId like '%" + Supplier + "%'"; } if (ShopIds != "0" && ShopIds != "") tj1 += " and d.ShopId in (" + ShopIds.Trim(',') + @")"; if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @" select top 500 c.GoodsName,ISNULL(c.GoodsOldCode,'无') AS GoodsOldCode,ISNULL(c.GoodsCode,'无') AS GoodsCode,a.GoodsNum as totalgood,a.OrderNum as totalorder,a.TotalPrice as orderprice,Supplier=c.SupplierId from ( select c.GoodsId, GoodsNum=sum(a.GoodsNum),OrderNum=COUNT(0),TotalPrice=Sum(d.TotalPrice) from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where d.CompanyId=" + CompanyId + tj +tj1+ @" and d.State>0 and d.State<3 group by c.GoodsId)a inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId order by a.GoodsNum desc "; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 21); } #endregion #region 货物总销量 [WebMethod(EnableSession = true)] public string GetExcelGoodTotal(string Supplier, DateTime? SDate, DateTime? EDate, string ShopIds, string GoodsCode) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; //if (PlatId > 0) // tj += " and d.PlatId=" + PlatId + " "; //if (ShopId > 0) // tj += " and d.ShopId=" + ShopId + " "; if (GoodsCode != "") { tj += " and (c.GoodsOldCode='" + GoodsCode + "' or c.GoodsCode='" + GoodsCode + "' ) "; } if (Supplier != "") { Supplier = Supplier.Trim(); tj += " and c.SupplierId like '%" + Supplier + "%'"; } if (ShopIds != "0" && ShopIds != "") tj1 += " and d.ShopId in (" + ShopIds.Trim(',') + @")"; if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @" select top 500 c.GoodsName,ISNULL(c.GoodsOldCode,'无') AS GoodsOldCode,ISNULL(c.GoodsCode,'无') AS GoodsCode,a.GoodsNum as totalgood,a.OrderNum as totalorder,a.TotalPrice as orderprice,Supplier=c.SupplierId from ( select c.GoodsId, GoodsNum=sum(a.GoodsNum),OrderNum=COUNT(0),TotalPrice=Sum(d.TotalPrice) from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where d.CompanyId=" + CompanyId + tj + tj1 + @" and d.State>0 and d.State<3 group by c.GoodsId)a inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId order by a.GoodsNum desc "; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 21); } #endregion #region 货物SKU [WebMethod(EnableSession = true)] public string GetGoodSKU(string GoodsCode) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (GoodsCode != "") { tj += " and ( c.GoodsOldCode='" + GoodsCode + "' or c.GoodsCode='" + GoodsCode + "' ) "; } string sql = @" SELECT TOP 1000 ISNULL(GoodsCode,'无'),ISNULL(GoodsOldCode,'无'),GoodsName,TypeCode,TypeDesc,SKU1,SKU2,SKU3,SKU4,SKU5,SKU6,SKU7 FROM dbo.HW_GoodsInfo a INNER JOIN dbo.HW_GoodsDetail b ON a.GoodsId=b.GoodsId where d.CompanyId=" + CompanyId + tj + @""; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 22); } #endregion #region 货物SKU [WebMethod(EnableSession = true)] public string GetExcelGoodSKU(string GoodsCode) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (GoodsCode != "") { tj += " and ( c.GoodsOldCode='" + GoodsCode + "' or c.GoodsCode='" + GoodsCode + "' ) "; } string sql = @" SELECT TOP 1000 ISNULL(GoodsCode,'无'),ISNULL(GoodsOldCode,'无'),GoodsName,TypeCode,TypeDesc,SKU1,SKU2,SKU3,SKU4,SKU5,SKU6,SKU7 FROM dbo.HW_GoodsInfo a INNER JOIN dbo.HW_GoodsDetail b ON a.GoodsId=b.GoodsId where d.CompanyId=" + CompanyId + tj + @""; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 22); } #endregion #region 查询报表列表 [WebMethod(EnableSession = true)] public List GetReportList() { PagesNew.Login(this.Session); var obj = new BaseService(); return obj.GetReportList(); } #endregion #region 查询发票 [WebMethod(EnableSession = true)] public List GetOrderBillList(string OrderIds) { PagesNew.Login(this.Session); if (OrderIds.Trim(',') == "") return null; var obj = new DD_OrderData(); List list = new List(); string[] Ids = OrderIds.Trim(',').Split(','); for (int i = 0; i < Ids.Length; i++) { DT_OrderBill md=obj.Get_OrderBillList(Convert.ToInt32(Ids[i])); if(md!=null) list.Add(md); } return list; } #endregion #region 选品报表 [WebMethod(EnableSession = true)] public string XPStatistical(DateTime? SDate, DateTime? EDate, DateTime? SDate1, DateTime? EDate1, string InName, int Sort) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; string tj2 = ""; if (SDate != null) { tj += " and e.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; } if (EDate != null) { tj += " and e.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (SDate1 != null) { tj1 += " a.InDate>='" + SDate1.Value.ToString("yyyy-MM-dd") + "' "; } if (EDate1 != null) { tj1 += " and a.InDate<'" + EDate1.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (InName.Trim() != "") { tj2 += " and (a.InName='" + InName.Trim() + "') "; } // string sql = @"SELECT b.GoodsCode,b.GoodsName,a.InName,SUM(d.GoodsNum) AS sellnum,(SELECT COUNT(*) FROM dbo.XP_GoodsSelect WHERE InName=a.InName " + tj1 + @" ) AS num FROM dbo.XP_GoodsSelect a //INNER JOIN dbo.HW_GoodsInfo b ON b.GoodsCode=a.GoodsCode //INNER JOIN dbo.HW_GoodsDetail c ON c.GoodsId=b.GoodsId //INNER JOIN dbo.DT_OrderGoods d ON d.DetailId=c.DetailId //WHERE a.CompanyId=1 " + tj + @" GROUP BY b.GoodsCode,b.GoodsName,a.InName //"; DataTable dt = new DataTable(); if (Sort == 1) { string sql = @"select InName,Price=SUM(Price),SaleNum=0,XPNum=0 from ( select a.InName,Price=case when e.MoneyCode='USD' then e.TotalPrice else dbo.MoneyUSDChange(e.TotalPrice,e.MoneyCode,1) end from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj1 + tj2 + @")a group by InName order by Price desc select a.InName,SaleNum=sum(d.GoodsNum) from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj2 + @" group by a.InName select a.InName,XPNum=COUNT(0) from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode where 1=1 " + tj1 + tj2 + @" group by a.InName "; DataSet ds = obj.GetReportData2(sql); dt = ds.Tables[0]; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { string Iname = dt.Rows[i]["InName"].ToString(); DataRow[] row = ds.Tables[1].Select("InName='" + Iname + "'"); if (row != null && row.Length > 0) dt.Rows[i]["SaleNum"] = row[0]["SaleNum"]; DataRow[] row1 = ds.Tables[2].Select("InName='" + Iname + "'"); if (row1 != null && row1.Length > 0) dt.Rows[i]["XPNum"] = row1[0]["XPNum"]; } } } else { string sql = @" select InName,Price=0.00,SaleNum,XPNum=0 from ( select a.InName,SaleNum=sum(d.GoodsNum) from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj +tj1+ tj2 + @" group by a.InName)a order by SaleNum desc select InName,Price=SUM(Price) from ( select a.InName,Price=case when e.MoneyCode='USD' then e.TotalPrice else dbo.MoneyUSDChange(e.TotalPrice,e.MoneyCode,1) end from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj2 + @")a group by InName select a.InName,XPNum=COUNT(0) from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode where 1=1 " + tj1 + tj2 + @" group by a.InName "; DataSet ds = obj.GetReportData2(sql); dt = ds.Tables[0]; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { string Iname = dt.Rows[i]["InName"].ToString(); DataRow[] row = ds.Tables[1].Select("InName='" + Iname + "'"); if (row != null && row.Length > 0) dt.Rows[i]["Price"] = row[0]["Price"]; DataRow[] row1 = ds.Tables[2].Select("InName='" + Iname + "'"); if (row1 != null && row1.Length > 0) dt.Rows[i]["XPNum"] = row1[0]["XPNum"]; } } } return GetReport(dt, 24); } #endregion #region 选品报表 [WebMethod(EnableSession = true)] public string GetExcelXPStatistical(DateTime? SDate, DateTime? EDate, DateTime? SDate1, DateTime? EDate1, string InName, int Sort) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; string tj1 = ""; string tj2 = ""; if (SDate != null) { tj += " and e.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; } if (EDate != null) { tj += " and e.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (SDate1 != null) { tj1 += " a.InDate>='" + SDate1.Value.ToString("yyyy-MM-dd") + "' "; } if (EDate1 != null) { tj1 += " and a.InDate<'" + EDate1.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (InName.Trim() != "") { tj2 += " and (a.InName='" + InName.Trim() + "') "; } // string sql = @"SELECT b.GoodsCode,b.GoodsName,a.InName,SUM(d.GoodsNum) AS sellnum,(SELECT COUNT(*) FROM dbo.XP_GoodsSelect WHERE InName=a.InName " + tj1 + @" ) AS num FROM dbo.XP_GoodsSelect a //INNER JOIN dbo.HW_GoodsInfo b ON b.GoodsCode=a.GoodsCode //INNER JOIN dbo.HW_GoodsDetail c ON c.GoodsId=b.GoodsId //INNER JOIN dbo.DT_OrderGoods d ON d.DetailId=c.DetailId //WHERE a.CompanyId=1 " + tj + @" GROUP BY b.GoodsCode,b.GoodsName,a.InName //"; DataTable dt = new DataTable(); if (Sort == 1) { string sql = @"select InName,Price=SUM(Price),SaleNum=0,XPNum=0 from ( select a.InName,Price=case when e.MoneyCode='USD' then e.TotalPrice else dbo.MoneyUSDChange(e.TotalPrice,e.MoneyCode,1) end from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj2 + @")a group by InName order by Price desc select a.InName,SaleNum=sum(d.GoodsNum) from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj2 + @" group by a.InName select a.InName,XPNum=COUNT(0) from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode where 1=1 " + tj1 + tj2 + @" group by a.InName "; DataSet ds = obj.GetReportData2(sql); dt = ds.Tables[0]; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { string Iname = dt.Rows[i]["InName"].ToString(); DataRow[] row = ds.Tables[1].Select("InName='" + Iname + "'"); if (row != null && row.Length > 0) dt.Rows[i]["SaleNum"] = row[0]["SaleNum"]; DataRow[] row1 = ds.Tables[2].Select("InName='" + Iname + "'"); if (row1 != null && row1.Length > 0) dt.Rows[i]["XPNum"] = row1[0]["XPNum"]; } } } else { string sql = @" select InName,Price=0.00,SaleNum,XPNum=0 from ( select a.InName,SaleNum=sum(d.GoodsNum) from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj2 + @" group by a.InName)a order by SaleNum desc select InName,Price=SUM(Price) from ( select a.InName,Price=case when e.MoneyCode='USD' then e.TotalPrice else dbo.MoneyUSDChange(e.TotalPrice,e.MoneyCode,1) end from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj2 + @")a group by InName select a.InName,XPNum=COUNT(0) from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode where 1=1 " + tj1 + tj2 + @" group by a.InName "; DataSet ds = obj.GetReportData2(sql); dt = ds.Tables[0]; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { string Iname = dt.Rows[i]["InName"].ToString(); DataRow[] row = ds.Tables[1].Select("InName='" + Iname + "'"); if (row != null && row.Length > 0) dt.Rows[i]["Price"] = row[0]["Price"]; DataRow[] row1 = ds.Tables[2].Select("InName='" + Iname + "'"); if (row1 != null && row1.Length > 0) dt.Rows[i]["XPNum"] = row1[0]["XPNum"]; } } } return GetExcelReport(dt, 24); } #endregion #region 选品报表2 [WebMethod(EnableSession = true)] public string XPStatistical2(DateTime? SDate, DateTime? EDate, DateTime? SDate1, DateTime? EDate1, string InName, string GoodsCode,int Sort) { PagesNew.Login(this.Session); var obj = new BaseService(); string tj = ""; string tj1 = ""; string tj2 = ""; if (SDate != null) { tj += " and e.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; } if (EDate != null) { tj += " and e.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (SDate1 != null) { tj1 += " a.InDate>='" + SDate1.Value.ToString("yyyy-MM-dd") + "' "; } if (EDate1 != null) { tj1 += " and a.InDate<'" + EDate1.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (InName.Trim() != "") { tj2 += " and a.InName='" + InName.Trim() + "' "; } if (GoodsCode.Trim() != "") { tj2 += " and b.GoodsCode='" + GoodsCode.Trim() + "' "; } // string sql = @"SELECT b.GoodsCode,b.GoodsName,a.InName,SUM(d.GoodsNum) AS sellnum,(SELECT COUNT(*) FROM dbo.XP_GoodsSelect WHERE InName=a.InName " + tj1 + @" ) AS num FROM dbo.XP_GoodsSelect a //INNER JOIN dbo.HW_GoodsInfo b ON b.GoodsCode=a.GoodsCode //INNER JOIN dbo.HW_GoodsDetail c ON c.GoodsId=b.GoodsId //INNER JOIN dbo.DT_OrderGoods d ON d.DetailId=c.DetailId //WHERE a.CompanyId=1 " + tj + @" GROUP BY b.GoodsCode,b.GoodsName,a.InName //"; DataTable dt = new DataTable(); if (Sort == 1) { string sql = @" select a.InName,b.GoodsCode,Price=case when e.MoneyCode='USD' then e.TotalPrice else dbo.MoneyUSDChange(e.TotalPrice,e.MoneyCode,1) end into #xpcount from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj1 + tj2 + @" select top 100 InName,GoodsCode,Price=SUM(Price),SaleNum=0 from #xpcount group by InName,GoodsCode order by Price desc select a.InName,b.GoodsCode,SaleNum=sum(d.GoodsNum) from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj1 + tj2 + @" group by a.InName,b.GoodsCode drop table #xpcount "; DataSet ds = obj.GetReportData2(sql); dt = ds.Tables[0]; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { string Iname = dt.Rows[i]["InName"].ToString(); string Code = dt.Rows[i]["GoodsCode"].ToString(); DataRow[] row = ds.Tables[1].Select("InName='" + Iname + "' and GoodsCode='" + Code + "'"); if (row != null && row.Length > 0) dt.Rows[i]["SaleNum"] = row[0]["SaleNum"]; } } } else { string sql = @" select a.InName,b.GoodsCode,SaleNum=sum(d.GoodsNum) into #xpcount from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj1 + tj2 + @" group by a.InName,b.GoodsCode select top 100 InName,GoodsCode,SaleNum,Price=0.0 from #xpcount order by SaleNum desc select a.InName,b.GoodsCode,Price=case when e.MoneyCode='USD' then e.TotalPrice else dbo.MoneyUSDChange(e.TotalPrice,e.MoneyCode,1) end into #xpcount1 from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj1 + tj2 + @" select InName,GoodsCode,Price=SUM(Price) from #xpcount1 group by InName,GoodsCode drop table #xpcount drop table #xpcount1 "; DataSet ds = obj.GetReportData2(sql); dt = ds.Tables[0]; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { string Iname = dt.Rows[i]["InName"].ToString(); string Code = dt.Rows[i]["GoodsCode"].ToString(); DataRow[] row = ds.Tables[1].Select("InName='" + Iname + "' and GoodsCode='" + Code + "'"); if (row != null && row.Length > 0) dt.Rows[i]["Price"] = row[0]["Price"]; } } } return GetReport(dt, 26); } #endregion #region 选品报表2 [WebMethod(EnableSession = true)] public string XPExcelStatistical2(DateTime? SDate, DateTime? EDate, DateTime? SDate1, DateTime? EDate1, string InName, string GoodsCode, int Sort) { PagesNew.Login(this.Session); var obj = new BaseService(); string tj = ""; string tj1 = ""; string tj2 = ""; if (SDate != null) { tj += " and e.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; } if (EDate != null) { tj += " and e.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (SDate1 != null) { tj1 += " a.InDate>='" + SDate1.Value.ToString("yyyy-MM-dd") + "' "; } if (EDate1 != null) { tj1 += " and a.InDate<'" + EDate1.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; } if (InName.Trim() != "") { tj2 += " and a.InName='" + InName.Trim() + "' "; } if (GoodsCode.Trim() != "") { tj2 += " and b.GoodsCode='" + GoodsCode.Trim() + "' "; } // string sql = @"SELECT b.GoodsCode,b.GoodsName,a.InName,SUM(d.GoodsNum) AS sellnum,(SELECT COUNT(*) FROM dbo.XP_GoodsSelect WHERE InName=a.InName " + tj1 + @" ) AS num FROM dbo.XP_GoodsSelect a //INNER JOIN dbo.HW_GoodsInfo b ON b.GoodsCode=a.GoodsCode //INNER JOIN dbo.HW_GoodsDetail c ON c.GoodsId=b.GoodsId //INNER JOIN dbo.DT_OrderGoods d ON d.DetailId=c.DetailId //WHERE a.CompanyId=1 " + tj + @" GROUP BY b.GoodsCode,b.GoodsName,a.InName //"; DataTable dt = new DataTable(); if (Sort == 1) { string sql = @" select a.InName,b.GoodsCode,Price=case when e.MoneyCode='USD' then e.TotalPrice else dbo.MoneyUSDChange(e.TotalPrice,e.MoneyCode,1) end into #xpcount from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj1 + tj2 + @" select top 100 InName,GoodsCode,Price=SUM(Price),SaleNum=0 from #xpcount group by InName,GoodsCode order by Price desc select a.InName,b.GoodsCode,SaleNum=sum(d.GoodsNum) from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj1 + tj2 + @" group by a.InName,b.GoodsCode drop table #xpcount "; DataSet ds = obj.GetReportData2(sql); dt = ds.Tables[0]; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { string Iname = dt.Rows[i]["InName"].ToString(); string Code = dt.Rows[i]["GoodsCode"].ToString(); DataRow[] row = ds.Tables[1].Select("InName='" + Iname + "' and GoodsCode='" + Code + "'"); if (row != null && row.Length > 0) dt.Rows[i]["SaleNum"] = row[0]["SaleNum"]; } } } else { string sql = @" select a.InName,b.GoodsCode,SaleNum=sum(d.GoodsNum) into #xpcount from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj1 + tj2 + @" group by a.InName,b.GoodsCode select top 100 InName,GoodsCode,SaleNum,Price=0.0 from #xpcount order by SaleNum desc select a.InName,b.GoodsCode,Price=case when e.MoneyCode='USD' then e.TotalPrice else dbo.MoneyUSDChange(e.TotalPrice,e.MoneyCode,1) end into #xpcount1 from XP_GoodsSelect a inner join HW_GoodsInfo b on a.GoodsCode=b.GoodsCode inner join HW_GoodsDetail c on b.GoodsId=c.GoodsId inner join DT_OrderGoods d on c.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.State<3 " + tj + tj1 + tj2 + @" select InName,GoodsCode,Price=SUM(Price) from #xpcount1 group by InName,GoodsCode drop table #xpcount drop table #xpcount1 "; DataSet ds = obj.GetReportData2(sql); dt = ds.Tables[0]; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { string Iname = dt.Rows[i]["InName"].ToString(); string Code = dt.Rows[i]["GoodsCode"].ToString(); DataRow[] row = ds.Tables[1].Select("InName='" + Iname + "' and GoodsCode='" + Code + "'"); if (row != null && row.Length > 0) dt.Rows[i]["Price"] = row[0]["Price"]; } } } return GetExcelReport(dt, 26); } #endregion #region 报表24 [WebMethod(EnableSession = true)] public string GetReportTable24(int PlatId,int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (GoodsCode.Trim() != "") { GoodsCode = GoodsCode.Trim(); tj = " and (c.GoodsCode='" + GoodsCode + "' or c.GoodsOldCode='" + GoodsCode + "')"; } if (PlatId !=0) tj += " and d.PlatId ="+PlatId; if (ShopId != 0) tj += " and d.ShopId =" + ShopId; if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select * from ( select e.CountryName,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join DT_OrderXXInfo e on d.OrderId=e.OrderId where d.State<3 "+tj+@" group by e.CountryName)a order by GoodsNum desc"; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 27); } #endregion #region 报表24 [WebMethod(EnableSession = true)] public List GetReportChart24(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (GoodsCode.Trim() != "") { GoodsCode = GoodsCode.Trim(); tj = " and (c.GoodsCode='" + GoodsCode + "' or c.GoodsOldCode='" + GoodsCode + "')"; } if (PlatId != 0) tj += " and d.PlatId =" + PlatId; if (ShopId != 0) tj += " and d.ShopId =" + ShopId; if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select * from ( select e.CountryName,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join DT_OrderXXInfo e on d.OrderId=e.OrderId where d.State<3 " + tj + @" group by e.CountryName)a order by GoodsNum desc"; DataTable dt = obj.GetReportData(sql); return dt.ToList(); } #endregion #region 报表24 [WebMethod(EnableSession = true)] public string GetExcelTable24(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (GoodsCode.Trim() != "") { GoodsCode = GoodsCode.Trim(); tj = " and (c.GoodsCode='" + GoodsCode + "' or c.GoodsOldCode='" + GoodsCode + "')"; } if (PlatId != 0) tj += " and d.PlatId =" + PlatId; if (ShopId != 0) tj += " and d.ShopId =" + ShopId; if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select * from ( select e.CountryName,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join DT_OrderXXInfo e on d.OrderId=e.OrderId where d.State<3 " + tj + @" group by e.CountryName)a order by GoodsNum desc"; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 27); } #endregion #region 报表25 [WebMethod(EnableSession = true)] public string GetReportTable25(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string CountryName,int TopNum) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (CountryName.Trim() != "") { CountryName = CountryName.Trim(','); tj = " and e.CountryName in (" + CountryName + ")"; } if (PlatId != 0) tj += " and d.PlatId =" + PlatId; if (ShopId != 0) tj += " and d.ShopId =" + ShopId; if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select top "+TopNum+@" GoodsCode,GoodsNum from ( select GoodsCode,GoodsNum=SUM(GoodsNum) from ( select a.GoodsNum,GoodsCode=case when c.GoodsCode is null then c.GoodsOldCode else c.GoodsCode end from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join DT_OrderXXInfo e on d.OrderId=e.OrderId where d.State<3 "+tj+")a group by GoodsCode)a order by GoodsNum desc"; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 28); } #endregion #region 报表25 [WebMethod(EnableSession = true)] public string GetExcelTable25(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string CountryName, int TopNum) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (CountryName.Trim() != "") { CountryName = CountryName.Trim(','); tj = " and e.CountryName in (" + CountryName + ")"; } if (PlatId != 0) tj += " and d.PlatId =" + PlatId; if (ShopId != 0) tj += " and d.ShopId =" + ShopId; if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select top " + TopNum + @" GoodsCode,GoodsNum from ( select GoodsCode,GoodsNum=SUM(GoodsNum) from ( select a.GoodsNum,GoodsCode=case when c.GoodsCode is null then c.GoodsOldCode else c.GoodsCode end from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join DT_OrderXXInfo e on d.OrderId=e.OrderId where d.State<3 " + tj + ")a group by GoodsCode)a order by GoodsNum desc"; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 28); } #endregion #region 报表26 [WebMethod(EnableSession = true)] public string GetReportTable26(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int SortId) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (SortId>0) { tj = " and g.ParentId=" + SortId; } if (PlatId != 0) tj += " and d.PlatId =" + PlatId; if (ShopId != 0) tj += " and d.ShopId =" + ShopId; if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select * from ( select e.CountryName,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join DT_OrderXXInfo e on d.OrderId=e.OrderId inner join HW_GoodsSort f on c.SortId=f.SortId inner join HW_GoodsSort g on f.ParentId=g.SortId where d.State<3 " + tj + @" group by e.CountryName)a order by GoodsNum desc"; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 29); } #endregion #region 报表26 [WebMethod(EnableSession = true)] public List GetReportChart26(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int SortId) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (SortId > 0) { tj = " and g.ParentId=" + SortId; } if (PlatId != 0) tj += " and d.PlatId =" + PlatId; if (ShopId != 0) tj += " and d.ShopId =" + ShopId; if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select * from ( select e.CountryName,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join DT_OrderXXInfo e on d.OrderId=e.OrderId inner join HW_GoodsSort f on c.SortId=f.SortId inner join HW_GoodsSort g on f.ParentId=g.SortId where d.State<3 " + tj + @" group by e.CountryName)a order by GoodsNum desc"; DataTable dt = obj.GetReportData(sql); return dt.ToList(); } #endregion #region 报表26 [WebMethod(EnableSession = true)] public string GetExcelTable26(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int SortId) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (SortId > 0) { tj = " and g.ParentId=" + SortId; } if (PlatId != 0) tj += " and d.PlatId =" + PlatId; if (ShopId != 0) tj += " and d.ShopId =" + ShopId; if (SDate != null) tj += " and d.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and d.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select * from ( select e.CountryName,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join DT_OrderXXInfo e on d.OrderId=e.OrderId inner join HW_GoodsSort f on c.SortId=f.SortId inner join HW_GoodsSort g on f.ParentId=g.SortId where d.State<3 " + tj + @" group by e.CountryName)a order by GoodsNum desc"; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 29); } #endregion #region 报表27 [WebMethod(EnableSession = true)] public string GetReportTable27(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int StoreId) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (StoreId > 0) { tj = " and b.StoreId=" + StoreId; } if (PlatId != 0) tj += " and a.PlatId =" + PlatId; if (ShopId != 0) tj += " and a.ShopId =" + ShopId; if (SDate != null) tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select a.PlatOrderCode,a.TotalPrice,shopName=dbo.GetShopName(a.shopId),b.CountryName,SKU=dbo.getGoodsSKU(a.OrderId),a.MoneyCode,a.OrderDate,a.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.State<3 " + tj; DataTable dt = obj.GetReportData(sql); return GetReport(dt,38); } #endregion #region 报表27 [WebMethod(EnableSession = true)] public string GetExcelTable27(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int StoreId) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (StoreId > 0) { tj = " and b.StoreId=" + StoreId; } if (PlatId != 0) tj += " and a.PlatId =" + PlatId; if (ShopId != 0) tj += " and a.ShopId =" + ShopId; if (SDate != null) tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select a.PlatOrderCode,a.TotalPrice,shopName=dbo.GetShopName(a.shopId),b.CountryName,SKU=dbo.getGoodsSKU(a.OrderId),a.MoneyCode,a.OrderDate,a.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.State<3 " + tj; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 38); } #endregion #region 报表28 [WebMethod(EnableSession = true)] public string GetReportTable28(DateTime? SDate, DateTime? EDate, string GoodsCode) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if(GoodsCode!="") tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (SDate != null) tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select shopName=dbo.GetShopName(a.ShopId),TotalPrice=SUM(a.TotalPrice),GoodsNum=SUM(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State<3 "+tj+" group by a.ShopId"; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 39); } #endregion #region 报表28 [WebMethod(EnableSession = true)] public string GetExcelTable28(DateTime? SDate, DateTime? EDate, string GoodsCode) { var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (GoodsCode != "") tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (SDate != null) tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"select shopName=dbo.GetShopName(a.ShopId),TotalPrice=SUM(a.TotalPrice),GoodsNum=SUM(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State<3 " + tj + " group by a.ShopId"; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 39); } #endregion #region 导出供应商相关信息 [WebMethod(EnableSession = true)] public string GetSupplierData(string Supplier) { PagesNew.Login(this.Session); var obj = new BaseService(); string sql = @" SELECT GoodsCode,GoodsName,GoodsSupplyCode,NowPrice FROM dbo.HW_GoodsInfo WHERE SupplierId like '%" + Supplier + "%'"; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 30); } #endregion #region 导出供应商相关信息 [WebMethod(EnableSession = true)] public string GetSupplierExcel(string Supplier) { PagesNew.Login(this.Session); var obj = new BaseService(); string sql = @" SELECT GoodsCode,GoodsName,GoodsSupplyCode,NowPrice FROM dbo.HW_GoodsInfo WHERE SupplierId like '%" + Supplier + "%'"; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 30); } #endregion #region 上架情况导出 [WebMethod(EnableSession = true)] public string GetReportShelves(DateTime? SDate, DateTime? EDate, string name, string dept, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (SDate != null) tj += " and b.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (name != "") tj += " and InName ='" + name + "' "; if (dept != "0" ) tj += " and DeptId = '" + dept + "' "; string sql = @"SELECT GoodsCode,GoodsName,ShopName,InName,num=1 FROM dbo.HW_Shop a INNER JOIN dbo.JC_Shop b ON a.ShopId=b.ShopId INNER JOIN dbo.HW_GoodsInfo c ON c.GoodsId=a.GoodsId where b.CompanyId=" + CompanyId + tj + @" "; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 31); } #endregion #region 上架情况导出 [WebMethod(EnableSession = true)] public string GetExcelShelves(DateTime? SDate, DateTime? EDate, string name, string dept, int PlatId, int ShopId) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (PlatId > 0) tj += " and b.PlatId=" + PlatId + " "; if (ShopId > 0) tj += " and b.ShopId=" + ShopId + " "; if (SDate != null) tj += " and b.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and b.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; if (name != "") tj += " and InName ='" + name + "' "; if (dept != "0") tj += " and DeptId = '" + dept + "' "; string sql = @"SELECT GoodsCode,GoodsName,ShopName,InName,num=1 FROM dbo.HW_Shop a INNER JOIN dbo.JC_Shop b ON a.ShopId=b.ShopId INNER JOIN dbo.HW_GoodsInfo c ON c.GoodsId=a.GoodsId where b.CompanyId=" + CompanyId + tj + @" "; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 31); } #endregion #region 滞销导出 [WebMethod(EnableSession = true)] public string GetUnSold(DateTime? SDate, DateTime? EDate, int BDate) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (SDate != null) tj += " and a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"SELECT GoodsName,GoodsCode,GoodsOldCode,TypeCode,TypeDesc,KCNum,a.InDate,DATEDIFF(dd,a.InDate,GETDATE()) AS Xdate,PostionCode,a.Price,SupplierId ,ODate=(SELECT MAX(InDate) FROM dbo.DT_OrderInfo o1 INNER JOIN dbo.DT_OrderGoods o2 ON o1.OrderId=o2.OrderId WHERE DetailId=a.DetailId ) FROM HW_GoodsInDetail a INNER JOIN dbo.HW_GoodsDetail b ON a.DetailId=b.DetailId INNER JOIN dbo.HW_GoodsInfo c ON c.GoodsId=b.GoodsId INNER JOIN dbo.CK_StorePostion d ON a.PostionId=d.PostionId WHERE OrderGoodsId=0 AND KCNum>0 " + tj + @" AND DATEDIFF(dd,ISNULL((SELECT MAX(InDate) FROM dbo.DT_OrderInfo o1 INNER JOIN dbo.DT_OrderGoods o2 ON o1.OrderId=o2.OrderId WHERE DetailId=a.DetailId ), dateadd(month,-6,getdate()) ),GETDATE())>" + BDate + @" ORDER BY c.GoodsCode,TypeCode "; DataTable dt = obj.GetReportData(sql); return GetReport(dt, 32); } #endregion #region 上架情况导出 [WebMethod(EnableSession = true)] public string GetExcelUnSold(DateTime? SDate, DateTime? EDate,int BDate) { PagesNew.Login(this.Session); var obj = new BaseService(); string CompanyId = Session["CompanyId"].ToString(); string tj = ""; if (SDate != null) tj += " and a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; if (EDate != null) tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' "; string sql = @"SELECT GoodsName,GoodsCode,GoodsOldCode,TypeCode,TypeDesc,KCNum,a.InDate,DATEDIFF(dd,a.InDate,GETDATE()) AS Xdate,PostionCode,a.Price,SupplierId ,ODate=(SELECT MAX(InDate) FROM dbo.DT_OrderInfo o1 INNER JOIN dbo.DT_OrderGoods o2 ON o1.OrderId=o2.OrderId WHERE DetailId=a.DetailId ) FROM HW_GoodsInDetail a INNER JOIN dbo.HW_GoodsDetail b ON a.DetailId=b.DetailId INNER JOIN dbo.HW_GoodsInfo c ON c.GoodsId=b.GoodsId INNER JOIN dbo.CK_StorePostion d ON a.PostionId=d.PostionId WHERE OrderGoodsId=0 AND KCNum>0 " + tj + @" AND DATEDIFF(dd,ISNULL((SELECT MAX(InDate) FROM dbo.DT_OrderInfo o1 INNER JOIN dbo.DT_OrderGoods o2 ON o1.OrderId=o2.OrderId WHERE DetailId=a.DetailId ), dateadd(month,-6,getdate()) ),GETDATE())>" + BDate + @" ORDER BY c.GoodsCode,TypeCode "; DataTable dt = obj.GetReportData(sql); return GetExcelReport(dt, 32); } #endregion //#region 个人订单列表 // [WebMethod(EnableSession = true)] //public string GetUserOrderList(int UserId, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode, decimal? GDFee, decimal YJRate) //{ // PagesNew.Login(this.Session); // int CompanyId = Convert.ToInt32(Session["CompanyId"]); // var obj = new DD_OrderData(); // List dlist = null; // var slist = obj.Get_ShopList(CompanyId); // if(UserId>0) // dlist = obj.Get_OrderUser(CompanyId,PlatId,ShopId, UserId, SDate, EDate, GoodsCode); // else // dlist = obj.Get_OrderUser2(CompanyId, PlatId, ShopId, SDate, EDate, GoodsCode); // List glist = null; // if(UserId>0) // glist = obj.Get_OrderGoods(CompanyId, PlatId, ShopId, UserId, SDate, EDate, GoodsCode); // else // glist = obj.Get_OrderGoods2(CompanyId, PlatId, ShopId, SDate, EDate, GoodsCode); // if (dlist == null || glist == null) // return ""; // decimal USDRate =Convert.ToDecimal(6.5); // var obj2=new BaseService(); // var mlist = obj2.GetMoneyList2(); // StringBuilder html = new StringBuilder(); // html.Append("序号"); // html.Append("平台|店铺"); // html.Append("订单号"); // html.Append("合并订单号"); // html.Append("国家"); // html.Append("订单日期"); // html.Append("发货日期"); // html.Append("物流方式"); // html.Append("货物编号"); // html.Append("订单金额$"); // html.Append("货物成本"); // // html.Append("关税税率"); // html.Append("关税"); // html.Append("头程费用"); // html.Append("预估运费"); // html.Append("运费"); // html.Append("尾程佣金"); // html.Append("固定成本"); // html.Append("毛利润"); // html.Append("利润率"); // html.Append(""); // if (dlist != null) // { // int rowindex = 1; // decimal hj1 = 0; // decimal hj2 = 0; // decimal hj3 = 0; // decimal hj4 = 0; // decimal hj5 = 0; // decimal hj51 = 0; // decimal hj6 = 0; // decimal hj7 = 0; // decimal hj8 = 0; // foreach(var md in dlist) // { // var mmd = mlist.Find(n => n.PlatId == md.PlatId&&n.MCode=="USD"); // if (mmd != null) // USDRate = mmd.MRate.Value; // decimal? Lr = 0; // html.Append("" + rowindex.ToString() + ""); // rowindex++; // var shopmd = slist.Find(n => n.ShopId == md.ShopId); // if (shopmd != null) // { // html.Append("" + shopmd.PlatName +"|"+ shopmd.ShopName + ""); // } // else // html.Append(""); // html.Append(""+md.PlatOrderCode+""); // html.Append(""+md.JoinOrderCode+""); // html.Append("" + md.CountryName + ""); // html.Append(""+md.OrderDate.Value.ToString("yyyy-MM-dd")+""); // if(md.PostDate!=null) // html.Append(""+md.PostDate.Value.ToString("yyyy-MM-dd")+""); // else // html.Append(""); // html.Append(""+md.PostInfo+""); // var gglist = glist.FindAll(n => n.OrderId == md.OrderId); // decimal hwcb = 0; // decimal tc = 0; // decimal sf = 0; // string ghtml = ""; // if (gglist != null) // { // foreach (var ggmd in gglist) // { // if (ggmd.GoodsFee != null) // { // hwcb += ggmd.GoodsFee.Value; // if (ggmd.FeeRate != null) // sf += ggmd.GoodsFee.Value * ggmd.FeeRate.Value / 100; // } // if (ggmd.TCFee != null) // { // tc += ggmd.TCFee.Value; // } // ghtml+=ggmd.GoodsCode + " " + ggmd.TypeDesc + "数量:"+ggmd.GoodsNum+";"; // if (ggmd.GoodsFee != null) // { // ghtml+="成本:" + (ggmd.GoodsFee.Value / USDRate).ToString("0.00") + ";"; // } // else // ghtml+="成本:0"; // if (ggmd.FeeRate != null) // { // ghtml += "税率:" + ggmd.FeeRate.Value + "%;
"; // // if (ggmd.GoodsFee != null) // // ghtml += "税费:" + (ggmd.GoodsFee.Value * ggmd.FeeRate.Value / 100 / USDRate).ToString("0.00") +";"; // // else // // ghtml += "税费:0;"; // } // else // { // ghtml += "税率:0;
"; // // ghtml += "税费:0;"; // } // //if (ggmd.TCFee != null) // //{ // // ghtml += "头程:" + ggmd.TCFee.Value.ToString("0.00") + ";
"; // //} // //else // // ghtml += "头程:0;
"; // } // } // html.Append("
" + ghtml + "
"); // if (md.TotalPrice != null) // { // html.Append("" + md.TotalPrice + ""); // Lr += md.TotalPrice.Value; // hj1 += md.TotalPrice.Value; // } // else // html.Append("0"); // if (hwcb > 0) // { // if(md.Fee2!=null) // html.Append("" + md.Fee2.Value.ToString("0.00") + ""); // else // html.Append("" + (hwcb / USDRate).ToString("0.00") + ""); // hj2 += hwcb / USDRate; // } // else // html.Append("0"); // // html.Append(""); // if (sf > 0) // { // html.Append("" + (sf / USDRate).ToString("0.00") + ""); // hj3 += sf / USDRate; // } // else // html.Append("0"); // if (md.Fee3 != null) // { // tc = md.Fee3.Value; // } // if (tc > 0) // { // html.Append("" + tc.ToString("0.00") + ""); // Lr -= tc; // hj4 += tc; // } // else // html.Append("0"); // if (md.Fee2 != null) // { // html.Append("" + (md.Fee2.Value).ToString("0.00") + ""); // hj51 += md.Fee2.Value; // } // else // html.Append("0"); // if (md.PostFee != null) // { // html.Append("" + (md.PostFee.Value).ToString("0.00") + ""); // Lr -= md.PostFee.Value; // hj5 += md.PostFee.Value; // } // else // html.Append("0"); // if (md.PostFee != null) // { // html.Append("" + (md.PostFee.Value * YJRate/100).ToString("0.00") + ""); // Lr -= md.PostFee.Value * YJRate/100; // hj6+= md.PostFee.Value * YJRate/100; // } // else // html.Append("0"); // if (md.GDFee != null) // { // html.Append("" + md.GDFee.Value + ""); // Lr -= md.GDFee.Value; // hj7 += md.GDFee.Value; // } // else // html.Append("0"); // Lr -= hwcb / USDRate; // Lr -= sf / USDRate; // html.Append("" + Lr.Value.ToString("0.00") + ""); // hj8+= Lr.Value; // if (Lr.Value > 0 && md.TotalPrice != null && md.TotalPrice>0) // html.Append("" + ((Lr.Value / md.TotalPrice.Value)*100).ToString("0.00") + "%"); // else if (Lr.Value==0) // html.Append("0%"); // if (Lr.Value < 0 && md.TotalPrice != null && md.TotalPrice > 0) // html.Append("-" + ((Lr.Value*-1 / md.TotalPrice.Value) * 100).ToString("0.00") + "%"); // html.Append(""); // } // html.Append(""); // html.Append(""); // html.Append(""); // html.Append(""); // html.Append(""); // html.Append(""); // html.Append(""); // html.Append(""); // html.Append("合计:"); // html.Append(""+hj1.ToString("0.00")+""); // html.Append("" + hj2.ToString("0.00") + ""); // // html.Append(""); // html.Append("" + hj3.ToString("0.00") + ""); // html.Append("" + hj4.ToString("0.00") + ""); // html.Append("" + hj51.ToString("0.00") + ""); // html.Append("" + hj5.ToString("0.00") + ""); // html.Append("" + hj6.ToString("0.00") + ""); // html.Append("" + hj7.ToString("0.00") + ""); // html.Append("" + hj8.ToString("0.00") + ""); // if(hj8>0) // html.Append("" + (hj8 / hj1 * 100).ToString("0.00") + "%"); // else if (hj8 == 0) // html.Append("0%"); // else // html.Append("-" + (hj8 * -1 / hj1 * 100).ToString("0.00") + "%"); // html.Append(""); // } // return html.ToString(); //} //#endregion #region 个人订单列表 [WebMethod(EnableSession = true)] public JsonModel> GetUserOrderList2(int BJState, int UserId, int OrderState, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode, decimal? GDFee, decimal YJRate, string OrderCode, string Name, string TrackCode, int PageSize, int PageIndex) { PagesNew.Login(this.Session); try { int CompanyId = Convert.ToInt32(Session["CompanyId"]); var obj = new DD_OrderData(); List dlist = null; var slist = obj.Get_ShopList(CompanyId); if (UserId > 0) dlist = obj.Get_OrderUser(BJState,CompanyId, OrderState, PlatId, ShopId, UserId, SDate, EDate.Value.AddDays(1), GoodsCode, OrderCode, TrackCode, Name); else dlist = obj.Get_OrderUser2(BJState,CompanyId, OrderState, PlatId, ShopId, SDate, EDate.Value.AddDays(1), GoodsCode, OrderCode, TrackCode, Name); List glist = null; if (UserId > 0) glist = obj.Get_OrderGoods(CompanyId, PlatId, ShopId, UserId, SDate, EDate.Value.AddDays(1), GoodsCode); else glist = obj.Get_OrderGoods2(CompanyId, PlatId, ShopId, SDate, EDate.Value.AddDays(1), GoodsCode); // ErrorFollow.TraceWrite("GetUserOrderList2", "", dlist.Count().ToString() + " " + glist.Count().ToString()); if (dlist == null || glist == null) return null; decimal USDRate = Convert.ToDecimal(6.5); var obj2 = new BaseService(); var mlist = obj2.GetMoneyList2(); List olist = new List(); int rowindex = 1; string Ids = ""; string Ids2 = ""; if (dlist != null) { foreach (var md in dlist) { Ids2 += md.OrderId.Value + ","; if (md.OrderState2 == 1) Ids += md.OrderId.Value + ","; } } var backorderlist = new List(); if (Ids != "") { backorderlist = DD_OrderData.GetListOrderBackMoneyApply(Ids.Trim(',')); } var trackorderlist = new List(); if (Ids2 != "") { trackorderlist = DD_OrderData.GetListOrderTrackCodeApply(Ids2.Trim(',')); } if (dlist != null) { decimal hj1 = 0; decimal hj11 = 0; decimal hj21 = 0; decimal hj2 = 0; decimal hj3 = 0; decimal hj4 = 0; decimal hj5 = 0; decimal hj51 = 0; decimal hj6 = 0; decimal hj7 = 0; decimal hj8 = 0; decimal hj9 = 0;//赔款 decimal hj10 = 0;//我们承担运费 int hjsl = 0; foreach (var md in dlist) { var mmd = mlist.Find(n => n.PlatId == md.PlatId && n.MCode == "USD"); if (mmd != null) USDRate = mmd.MRate.Value; decimal? Lr = 0; DT_OrderUserList model = new DT_OrderUserList(); model.BJState = md.BJState; model.OrderId = md.OrderId; model.StateName = "正常订单"; int BackType = 0;//退款类型 int BackOrderState = 0;//订单类型 int? GoodsBackType = 0;//退款类型 int IsBackOrder = 0;//是否退货订单 int GoodsState = 0;//是否退货订单 decimal PKPrice = 0;//赔款金额 decimal OurPostFee = 0;//退货运费 string TrackCode2 = ""; if (trackorderlist != null && trackorderlist.Count > 0) { var tlist = trackorderlist.FindAll(n => n.OrderId == md.OrderId); if (tlist != null) { foreach (var tmd in tlist) { TrackCode2 += tmd.TrackCode + "
"; } } } if (md.OrderState2 == 1 && backorderlist != null) { var bmd = backorderlist.Find(n => n.OrderId == md.OrderId); if (bmd != null) { IsBackOrder = 1; model.StateName = "退货赔款订单"; // // // // // // if (bmd.FactPrice != null) PKPrice = bmd.FactPrice.Value; if (bmd.GoodState != null) GoodsState = bmd.GoodState.Value; if (bmd.PostFee != null && bmd.PostFee > 0) OurPostFee = bmd.PostFee.Value; GoodsBackType = bmd.BackState; if (bmd.BackType != null) { BackType = bmd.BackType.Value; if (bmd.BackType == 0) { model.Remark = "退款/退货"; } else if (bmd.BackType == 1) { model.Remark = "退款/不退货"; } else if (bmd.BackType == 2) { model.Remark = "部分赔款/不退货"; } else if (bmd.BackType == 3) { model.Remark = "赔款退货"; } else if (bmd.BackType == 6) { model.Remark = "补发配件"; } } if (bmd.OrderState != null) { BackOrderState = bmd.OrderState.Value; if (bmd.OrderState == 0) { model.Remark += "取消订单收取佣金20%"; } else if (bmd.OrderState == 1) { model.Remark += "订单和佣金正常"; } } } } var shopmd = slist.Find(n => n.ShopId == md.ShopId); if (shopmd != null) { model.PlatName = shopmd.PlatName + "|" + shopmd.ShopName; } else model.PlatName = ""; model.RevName = md.RevName; model.TrackCode = TrackCode2;// md.TrackCode2; model.PlatOrderCode = md.PlatOrderCode; model.JoinOrderCode = md.JoinOrderCode; model.CountryName = md.CountryName; model.OrderDate = md.OrderDate.Value.ToString("yyyy-MM-dd"); if (md.PostDate != null) model.PostDate = md.PostDate.Value.ToString("yyyy-MM-dd"); else model.PostDate = ""; model.PostInfo = md.PostInfo; model.GoodsNum = md.GoodsNum; hjsl += md.GoodsNum.Value; var gglist = glist.FindAll(n => n.OrderId == md.OrderId); decimal hwcb = 0; decimal tc = 0; decimal sf = 0; string ghtml = ""; if (gglist != null) { foreach (var ggmd in gglist) { if (ggmd.GoodsFee != null) { hwcb += ggmd.GoodsFee.Value; if (ggmd.FeeRate != null) sf += ggmd.GoodsFee.Value * ggmd.FeeRate.Value / 100; } if (ggmd.TCFee != null) { tc += ggmd.TCFee.Value; } decimal hwcb2 = 0; if (ggmd.GoodsFee != null && ggmd.GoodsNum != null && ggmd.GoodsNum.Value>0) hwcb2 = ggmd.GoodsFee.Value/ggmd.GoodsNum.Value; ghtml += "
" + ggmd.GoodsCode + "" + ggmd.TypeDesc + "数量:" + ggmd.GoodsNum + ";"; if (ggmd.GoodsFee != null) { ghtml += "成本:" + (ggmd.GoodsFee.Value / USDRate).ToString("0.00") + ";"; } else ghtml += "成本:0"; if (ggmd.FeeRate != null) { ghtml += "税率:" + ggmd.FeeRate.Value + "%;"; // if (ggmd.GoodsFee != null) // ghtml += "税费:" + (ggmd.GoodsFee.Value * ggmd.FeeRate.Value / 100 / USDRate).ToString("0.00") +";"; // else // ghtml += "税费:0;"; } else { ghtml += "税率:0;"; // ghtml += "税费:0;"; } //if (ggmd.TCFee != null) //{ // ghtml += "头程:" + ggmd.TCFee.Value.ToString("0.00") + ";
"; //} //else // ghtml += "头程:0;
"; } } model.GoodsCode = ghtml; //if @PlatId=1 set @escrowFee=0.95else if @PlatId=2 or @PlatId=3set @escrowFee=0.85else if @PlatId=5 set @escrowFee=0.9 decimal ptyjrate = 0; if (md.PlatId == 1) ptyjrate = Convert.ToDecimal(0.05); else if (md.PlatId == 2 || md.PlatId == 3 || md.PlatId == 6) ptyjrate = Convert.ToDecimal(0.15); else if (md.PlatId == 5) ptyjrate = Convert.ToDecimal(0.1); if (md.TotalPrice != null) { if (md.MoneyCode != "USD") { var opmd = mlist.Find(n => n.MCode == md.MoneyCode); var opmd2 = mlist.Find(n => n.MCode == "USD"); if (opmd != null) md.TotalPrice = opmd.MRate * md.TotalPrice / opmd2.MRate; } if (IsBackOrder == 1 && BackOrderState == 0)//取消订单 { model.TotalPrice = "0"; model.YJPrice = (md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2)).ToString("0.00"); model.escrowFee = md.escrowFee.Value.ToString("0.00"); Lr -= md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2); Lr -= md.escrowFee.Value; hj11 += md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2); hj21 += md.escrowFee.Value; } else { model.TotalPrice = md.TotalPrice.Value.ToString("0.00"); model.YJPrice = (md.TotalPrice.Value * ptyjrate).ToString("0.00"); model.escrowFee = md.escrowFee.Value.ToString("0.00"); Lr += md.TotalPrice.Value; Lr -= md.TotalPrice.Value * ptyjrate; Lr -= md.escrowFee.Value; hj1 += md.TotalPrice.Value; hj11 += md.TotalPrice.Value * ptyjrate; hj21 += md.escrowFee.Value; } } else { model.TotalPrice = ""; model.YJPrice = ""; model.escrowFee = ""; } if (IsBackOrder == 1 && (GoodsBackType == 1 || GoodsBackType == 2))//退货已经入库 不计成本 { model.GoodsFee = "0"; model.Fee1 = "0"; model.Fee3 = "0"; } else { if (md.Fee4 != null) //货物成本 { model.GoodsFee = md.Fee4.Value.ToString("0.00"); hj2 += md.Fee4.Value; Lr -= md.Fee4.Value; } else if (hwcb > 0) { model.GoodsFee = (hwcb / USDRate).ToString("0.00"); hj2 += hwcb / USDRate; Lr -= hwcb / USDRate; } else model.GoodsFee = "0"; // html.Append(""); if (sf > 0) { model.Fee1 = (sf / USDRate).ToString("0.00"); hj3 += sf / USDRate; Lr -= sf / USDRate; } else model.Fee1 = ""; if (md.Fee3 != null) //头程 { tc = md.Fee3.Value; } if (tc > 0) { model.Fee3 = tc.ToString("0.00"); Lr -= tc; hj4 += tc; } else model.Fee3 = "0"; } decimal yjyf = 0; if (md.Fee6 != null && md.Fee6 > 0) yjyf = md.Fee6.Value; else if (md.Fee7 != null && md.Fee7 > 0) yjyf = md.Fee7.Value; else if (md.Fee8 != null && md.Fee8 > 0) yjyf = md.Fee8.Value; if (md.Fee6 != null && md.Fee6 > 0 && md.Fee6 < yjyf) yjyf = md.Fee6.Value; if (md.Fee7 != null && md.Fee7 > 0 && md.Fee7 < yjyf) yjyf = md.Fee7.Value; if (md.Fee8 != null && md.Fee8 > 0 && md.Fee8 < yjyf) yjyf = md.Fee8.Value; md.Fee2 = yjyf; if (md.Fee2 != null) { model.Fee2 = (md.Fee2.Value).ToString("0.00"); hj51 += md.Fee2.Value; } else model.Fee2 = "0"; if (md.PostFee != null) { model.PostFee = (md.PostFee.Value).ToString("0.00"); Lr -= md.PostFee.Value; hj5 += md.PostFee.Value; } else model.PostFee = "0"; if (md.PostInfo != null && md.PostInfo.Contains("Fedex") && md.PostFee != null) { model.Fee4 = (md.PostFee.Value * YJRate / 100).ToString("0.00"); Lr -= md.PostFee.Value * YJRate / 100; hj6 += md.PostFee.Value * YJRate / 100; } else model.Fee4 = "0"; if (md.GDFee != null) { model.GDFee = md.GDFee.Value.ToString("0.00"); Lr -= md.GDFee.Value; hj7 += md.GDFee.Value; } else model.GDFee = ""; model.BackPostFee = OurPostFee.ToString("0.00"); Lr -= OurPostFee; hj10 += OurPostFee; if (IsBackOrder == 1 && PKPrice > 0) { model.BackMoney = PKPrice.ToString("0.00"); Lr -= PKPrice; hj9 += PKPrice; } model.LRFee = Lr.Value.ToString("0.00"); hj8 += Lr.Value; if (Lr.Value > 0 && md.TotalPrice != null && md.TotalPrice > 0) model.LRRate = ((Lr.Value / md.TotalPrice.Value) * 100).ToString("0.00") + "%"; else if (Lr.Value == 0) model.LRRate = "0%"; if (Lr.Value < 0 && md.TotalPrice != null && md.TotalPrice > 0) model.LRRate = "-" + ((Lr.Value * -1 / md.TotalPrice.Value) * 100).ToString("0.00") + "%"; if (rowindex > PageSize * (PageIndex - 1) && rowindex <= PageSize * PageIndex) olist.Add(model); rowindex++; } DT_OrderUserList model2 = new DT_OrderUserList(); model2.GoodsCode = "合计:"; model2.GoodsNum = hjsl; model2.TotalPrice = hj1.ToString("0.00"); model2.YJPrice = hj11.ToString("0.00"); model2.GoodsFee = hj2.ToString("0.00"); model2.escrowFee = hj21.ToString("0.00"); model2.Fee1 = hj3.ToString("0.00"); model2.Fee3 = hj4.ToString("0.00"); model2.PostFee = hj5.ToString("0.00"); model2.Fee4 = hj6.ToString("0.00"); model2.BackPostFee = hj10.ToString("0.00"); model2.BackMoney = hj9.ToString("0.00"); model2.LRFee = hj8.ToString("0.00"); if (hj8 > 0 && hj1 > 0) model2.LRRate = (hj8 / hj1 * 100).ToString("0.00") + "%"; else if (hj8 == 0) model2.LRRate = "0%"; else if (hj1 > 0) model2.LRRate = "-" + (hj8 * -1 / hj1 * 100).ToString("0.00") + "%"; olist.Add(model2); // html.Append(""); // html.Append(""); // html.Append(""); // html.Append(""); // html.Append(""); // html.Append(""); // html.Append(""); // html.Append(""); //model2. 合计:"); // html.Append("" + hj1.ToString("0.00") + ""); // html.Append("" + hj2.ToString("0.00") + ""); // // html.Append(""); // html.Append("" + hj3.ToString("0.00") + ""); // html.Append("" + hj4.ToString("0.00") + ""); // html.Append("" + hj51.ToString("0.00") + ""); // html.Append("" + hj5.ToString("0.00") + ""); // html.Append("" + hj6.ToString("0.00") + ""); // html.Append("" + hj7.ToString("0.00") + ""); // html.Append("" + hj8.ToString("0.00") + ""); // if (hj8 > 0) // html.Append("" + (hj8 / hj1 * 100).ToString("0.00") + "%"); // else if (hj8 == 0) // html.Append("0%"); // else // html.Append("-" + (hj8 * -1 / hj1 * 100).ToString("0.00") + "%"); // html.Append(""); } JsonModel> resultModel = new JsonModel>(); int RowCount = 0; resultModel.DataSource = olist; resultModel.RowCount = rowindex; return resultModel; } catch(Exception ex) { ErrorFollow.TraceWrite("GetUserOrderList2", "", ex.Message); } return null; } #endregion #region 个人订单列表 [WebMethod(EnableSession = true)] public string GetUserOrderExcel(int BJState,int UserId, int OrderState, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode, decimal? GDFee, decimal YJRate, string OrderCode, string Name, string TrackCode) { PagesNew.Login(this.Session); try { int CompanyId = Convert.ToInt32(Session["CompanyId"]); var obj = new DD_OrderData(); List dlist = null; var slist = obj.Get_ShopList(CompanyId); if (UserId > 0) dlist = obj.Get_OrderUser(BJState,CompanyId, OrderState, PlatId, ShopId, UserId, SDate, EDate.Value.AddDays(1), GoodsCode, OrderCode, TrackCode, Name); else dlist = obj.Get_OrderUser2(BJState,CompanyId, OrderState, PlatId, ShopId, SDate, EDate.Value.AddDays(1), GoodsCode, OrderCode, TrackCode, Name); List glist = null; if (UserId > 0) glist = obj.Get_OrderGoods(CompanyId, PlatId, ShopId, UserId, SDate, EDate.Value.AddDays(1), GoodsCode); else glist = obj.Get_OrderGoods2(CompanyId, PlatId, ShopId, SDate, EDate.Value.AddDays(1), GoodsCode); // ErrorFollow.TraceWrite("GetUserOrderList2", "", dlist.Count().ToString() + " " + glist.Count().ToString()); if (dlist == null || glist == null) return null; decimal USDRate = Convert.ToDecimal(6.5); var obj2 = new BaseService(); var mlist = obj2.GetMoneyList2(); List olist = new List(); int rowindex = 1; string Ids = ""; string Ids2 = ""; if (dlist != null) { foreach (var md in dlist) { Ids2 += md.OrderId.Value + ","; if (md.OrderState2 == 1) Ids += md.OrderId.Value + ","; } } var backorderlist = new List(); if (Ids != "") { backorderlist = DD_OrderData.GetListOrderBackMoneyApply(Ids.Trim(',')); } var trackorderlist = new List(); if (Ids2 != "") { trackorderlist = DD_OrderData.GetListOrderTrackCodeApply(Ids2.Trim(',')); } if (dlist != null) { decimal hj1 = 0; decimal hj11 = 0; decimal hj21 = 0; decimal hj2 = 0; decimal hj3 = 0; decimal hj4 = 0; decimal hj5 = 0; decimal hj51 = 0; decimal hj6 = 0; decimal hj7 = 0; decimal hj8 = 0; decimal hj9 = 0;//赔款 decimal hj10 = 0;//我们承担运费 int hjsl = 0; foreach (var md in dlist) { var mmd = mlist.Find(n => n.PlatId == md.PlatId && n.MCode == "USD"); if (mmd != null) USDRate = mmd.MRate.Value; decimal? Lr = 0; DT_OrderUserList model = new DT_OrderUserList(); model.OrderId = md.OrderId; model.StateName = "正常订单"; int BackType = 0;//退款类型 int BackOrderState = 0;//订单类型 int? GoodsBackType = 0;//退款类型 int IsBackOrder = 0;//是否退货订单 int GoodsState = 0;//是否退货订单 decimal PKPrice = 0;//赔款金额 decimal OurPostFee = 0;//退货运费 string TrackCode2 = ""; if (trackorderlist != null && trackorderlist.Count>0) { var tlist = trackorderlist.FindAll(n => n.OrderId == md.OrderId); if (tlist != null) { foreach (var tmd in tlist) { TrackCode2 += tmd.TrackCode + ","; } } } if (md.OrderState2 == 1 && backorderlist != null) { var bmd = backorderlist.Find(n => n.OrderId == md.OrderId); if (bmd != null) { IsBackOrder = 1; model.StateName = "退货赔款订单"; // // // // // // if (bmd.FactPrice != null) PKPrice = bmd.FactPrice.Value; if (bmd.GoodState != null) GoodsState = bmd.GoodState.Value; if (bmd.PostFee != null && bmd.PostFee > 0) OurPostFee = bmd.PostFee.Value; GoodsBackType = bmd.BackState; if (bmd.BackType != null) { BackType = bmd.BackType.Value; if (bmd.BackType == 0) { model.Remark = "退款/退货"; } else if (bmd.BackType == 1) { model.Remark = "退款/不退货"; } else if (bmd.BackType == 2) { model.Remark = "部分赔款/不退货"; } else if (bmd.BackType == 3) { model.Remark = "赔款退货"; } else if (bmd.BackType == 6) { model.Remark = "补发配件"; } } if (bmd.OrderState != null) { BackOrderState = bmd.OrderState.Value; if (bmd.OrderState == 0) { model.Remark += "取消订单收取佣金20%"; } else if (bmd.OrderState == 1) { model.Remark += "订单和佣金正常"; } } } } var shopmd = slist.Find(n => n.ShopId == md.ShopId); if (shopmd != null) { model.PlatName = shopmd.PlatName + "|" + shopmd.ShopName; } else model.PlatName = ""; model.RevName = md.RevName; model.TrackCode = TrackCode2.TrimEnd(',');//md.TrackCode2; model.PlatOrderCode = md.PlatOrderCode; model.JoinOrderCode = md.JoinOrderCode; model.CountryName = md.CountryName; model.OrderDate = md.OrderDate.Value.ToString("yyyy-MM-dd"); if (md.PostDate != null) model.PostDate = md.PostDate.Value.ToString("yyyy-MM-dd"); else model.PostDate = ""; model.PostInfo = md.PostInfo; model.GoodsNum = md.GoodsNum; hjsl += md.GoodsNum.Value; var gglist = glist.FindAll(n => n.OrderId == md.OrderId); decimal hwcb = 0; decimal tc = 0; decimal sf = 0; string ghtml = ""; if (gglist != null) { foreach (var ggmd in gglist) { if (ggmd.GoodsFee != null) { hwcb += ggmd.GoodsFee.Value; if (ggmd.FeeRate != null) sf += ggmd.GoodsFee.Value * ggmd.FeeRate.Value / 100; } if (ggmd.TCFee != null) { tc += ggmd.TCFee.Value; } ghtml += ggmd.GoodsCode + " " + ggmd.TypeDesc + "数量:" + ggmd.GoodsNum + ";"; //if (ggmd.GoodsFee != null) //{ // ghtml += "成本:" + (ggmd.GoodsFee.Value / USDRate).ToString("0.00") + ";"; //} //else // ghtml += "成本:0"; //if (ggmd.FeeRate != null) //{ // ghtml += "税率:" + ggmd.FeeRate.Value + "%;"; // // if (ggmd.GoodsFee != null) // // ghtml += "税费:" + (ggmd.GoodsFee.Value * ggmd.FeeRate.Value / 100 / USDRate).ToString("0.00") +";"; // // else // // ghtml += "税费:0;"; //} //else //{ // ghtml += "税率:0;"; // // ghtml += "税费:0;"; //} //if (ggmd.TCFee != null) //{ // ghtml += "头程:" + ggmd.TCFee.Value.ToString("0.00") + ";
"; //} //else // ghtml += "头程:0;
"; } } model.GoodsCode = ghtml; //if @PlatId=1 set @escrowFee=0.95else if @PlatId=2 or @PlatId=3set @escrowFee=0.85else if @PlatId=5 set @escrowFee=0.9 decimal ptyjrate = 0; if (md.PlatId == 1) ptyjrate = Convert.ToDecimal(0.05); else if (md.PlatId == 2 || md.PlatId == 3 || md.PlatId == 6) ptyjrate = Convert.ToDecimal(0.15); else if (md.PlatId == 5) ptyjrate = Convert.ToDecimal(0.1); if (md.TotalPrice != null) { if (md.MoneyCode != "USD") { var opmd = mlist.Find(n => n.MCode == md.MoneyCode); var opmd2 = mlist.Find(n => n.MCode == "USD"); if (opmd != null) md.TotalPrice = opmd.MRate * md.TotalPrice / opmd2.MRate; } if (IsBackOrder == 1 && BackOrderState == 0)//取消订单 { model.TotalPrice = "0"; model.YJPrice = (md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2)).ToString("0.00"); model.escrowFee = md.escrowFee.Value.ToString("0.00"); Lr -= md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2); Lr -= md.escrowFee.Value; hj11 += md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2); hj21 += md.escrowFee.Value; } else { model.TotalPrice = md.TotalPrice.Value.ToString("0.00"); model.YJPrice = (md.TotalPrice.Value * ptyjrate).ToString("0.00"); model.escrowFee = md.escrowFee.Value.ToString("0.00"); Lr += md.TotalPrice.Value; Lr -= md.TotalPrice.Value * ptyjrate; Lr -= md.escrowFee.Value; hj1 += md.TotalPrice.Value; hj11 += md.TotalPrice.Value * ptyjrate; hj21 += md.escrowFee.Value; } } else { model.TotalPrice = ""; model.YJPrice = ""; model.escrowFee = ""; } if (IsBackOrder == 1 && (GoodsBackType == 1 || GoodsBackType == 2))//退货已经入库 不计成本 { model.GoodsFee = "0"; model.Fee1 = "0"; model.Fee3 = "0"; } else { if (md.Fee4 != null) //货物成本 { model.GoodsFee = md.Fee4.Value.ToString("0.00"); hj2 += md.Fee4.Value; Lr -= md.Fee4.Value; } else if (hwcb > 0) { model.GoodsFee = (hwcb / USDRate).ToString("0.00"); hj2 += hwcb / USDRate; Lr -= hwcb / USDRate; } else model.GoodsFee = "0"; // html.Append(""); if (sf > 0) { model.Fee1 = (sf / USDRate).ToString("0.00"); hj3 += sf / USDRate; Lr -= sf / USDRate; } else model.Fee1 = ""; if (md.Fee3 != null) //头程 { tc = md.Fee3.Value; } if (tc > 0) { model.Fee3 = tc.ToString("0.00"); Lr -= tc; hj4 += tc; } else model.Fee3 = "0"; } decimal yjyf = 0; if (md.Fee6 != null && md.Fee6 > 0) yjyf = md.Fee6.Value; else if (md.Fee7 != null && md.Fee7 > 0) yjyf = md.Fee7.Value; else if (md.Fee8 != null && md.Fee8 > 0) yjyf = md.Fee8.Value; if (md.Fee6 != null && md.Fee6 > 0 && md.Fee6 < yjyf) yjyf = md.Fee6.Value; if (md.Fee7 != null && md.Fee7 > 0 && md.Fee7 < yjyf) yjyf = md.Fee7.Value; if (md.Fee8 != null && md.Fee8 > 0 && md.Fee8 < yjyf) yjyf = md.Fee8.Value; md.Fee2 = yjyf; if (md.Fee2 != null) { model.Fee2 = (md.Fee2.Value).ToString("0.00"); hj51 += md.Fee2.Value; } else model.Fee2 = "0"; if (md.PostFee != null) { model.PostFee = (md.PostFee.Value).ToString("0.00"); Lr -= md.PostFee.Value; hj5 += md.PostFee.Value; } else model.PostFee = "0"; if (md.PostInfo != null && md.PostInfo.Contains("Fedex") && md.PostFee != null) { model.Fee4 = (md.PostFee.Value * YJRate / 100).ToString("0.00"); Lr -= md.PostFee.Value * YJRate / 100; hj6 += md.PostFee.Value * YJRate / 100; } else model.Fee4 = "0"; if (md.GDFee != null) { model.GDFee = md.GDFee.Value.ToString("0.00"); Lr -= md.GDFee.Value; hj7 += md.GDFee.Value; } else model.GDFee = ""; model.BackPostFee = OurPostFee.ToString("0.00"); Lr -= OurPostFee; hj10 += OurPostFee; if (IsBackOrder == 1 && PKPrice > 0) { model.BackMoney = PKPrice.ToString("0.00"); Lr -= PKPrice; hj9 += PKPrice; } model.LRFee = Lr.Value.ToString("0.00"); hj8 += Lr.Value; if (Lr.Value > 0 && md.TotalPrice != null && md.TotalPrice > 0) model.LRRate = ((Lr.Value / md.TotalPrice.Value) * 100).ToString("0.00") + "%"; else if (Lr.Value == 0) model.LRRate = "0%"; if (Lr.Value < 0 && md.TotalPrice != null && md.TotalPrice > 0) model.LRRate = "-" + ((Lr.Value * -1 / md.TotalPrice.Value) * 100).ToString("0.00") + "%"; olist.Add(model); rowindex++; } DT_OrderUserList model2 = new DT_OrderUserList(); model2.GoodsCode = "合计:"; model2.GoodsNum = hjsl; model2.TotalPrice = hj1.ToString("0.00"); model2.YJPrice = hj11.ToString("0.00"); model2.GoodsFee = hj2.ToString("0.00"); model2.escrowFee = hj21.ToString("0.00"); model2.Fee1 = hj3.ToString("0.00"); model2.Fee3 = hj4.ToString("0.00"); model2.PostFee = hj5.ToString("0.00"); model2.Fee4 = hj6.ToString("0.00"); model2.BackPostFee = hj10.ToString("0.00"); model2.BackMoney = hj9.ToString("0.00"); model2.LRFee = hj8.ToString("0.00"); if (hj8 > 0 && hj1 > 0) model2.LRRate = (hj8 / hj1 * 100).ToString("0.00") + "%"; else if (hj8 == 0) model2.LRRate = "0%"; else if (hj1 > 0) model2.LRRate = "-" + (hj8 * -1 / hj1 * 100).ToString("0.00") + "%"; olist.Add(model2); } if (olist == null) return ""; DataTable tb = olist.ToDataTable(); TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("PlatName", "平台|店铺", DbType.String, ""); listColumns.Add("PlatOrderCode", "订单号", DbType.String, ""); listColumns.Add("CountryName", "国家", DbType.String, ""); listColumns.Add("OrderDate", "订单日期", DbType.String, ""); listColumns.Add("PostDate", "发货日期", DbType.String, ""); listColumns.Add("RevName", "收件人", DbType.String, ""); listColumns.Add("PostInfo", "物流方式", DbType.String, ""); listColumns.Add("TrackCode", "跟踪码", DbType.String, ""); listColumns.Add("GoodsCode", "货物编号", DbType.String, ""); listColumns.Add("GoodsNum", "货物数量", DbType.String, ""); listColumns.Add("TotalPrice", "订单金额$", DbType.String, ""); listColumns.Add("YJPrice", "佣金$", DbType.String, ""); listColumns.Add("escrowFee", "税费$", DbType.String, ""); listColumns.Add("GoodsFee", "货物成本", DbType.String, ""); listColumns.Add("Fee1", "关税", DbType.String, ""); listColumns.Add("Fee3", "头程费用", DbType.String, ""); listColumns.Add("Fee2", "预估运费", DbType.String, ""); listColumns.Add("PostFee", "运费", DbType.String, ""); listColumns.Add("Fee4", "运费佣金", DbType.String, ""); listColumns.Add("GDFee", "固定成本", DbType.String, ""); listColumns.Add("LRFee", "毛利润", DbType.String, ""); listColumns.Add("LRRate", "利润率", DbType.String, ""); MicrosoftExcel obj3 = new MicrosoftExcel(); return obj3.Export(tb, listColumns); } catch (Exception ex) { ErrorFollow.TraceWrite("GetUserOrderList2", "", ex.Message); } return null; } #endregion #region 个人订单列表 [WebMethod(EnableSession = true)] public string GetUserOrderExcel2(int BJState, int UserId, int OrderState, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode, decimal? GDFee, decimal YJRate, string OrderCode, string Name, string TrackCode) { PagesNew.Login(this.Session); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var obj = new DD_OrderData(); List dlist = null; var slist = obj.Get_ShopList(CompanyId); if (UserId > 0) dlist = obj.Get_OrderUser(BJState,CompanyId, OrderState, PlatId, ShopId, UserId, SDate, EDate, GoodsCode, OrderCode, TrackCode, Name); else dlist = obj.Get_OrderUser2(BJState,CompanyId, OrderState, PlatId, ShopId, SDate, EDate, GoodsCode, OrderCode, TrackCode, Name); List glist = null; if (UserId > 0) glist = obj.Get_OrderGoods(CompanyId, PlatId, ShopId, UserId, SDate, EDate, GoodsCode); else glist = obj.Get_OrderGoods2(CompanyId, PlatId, ShopId, SDate, EDate, GoodsCode); if (dlist == null || glist == null) return null; decimal USDRate = Convert.ToDecimal(6.5); var obj2 = new BaseService(); var mlist = obj2.GetMoneyList2(); List olist = new List(); int rowindex = 1; string Ids = ""; if (dlist != null) { foreach (var md in dlist) { if (md.OrderState2 == 1) Ids += md.OrderId.Value + ","; } } var backorderlist = new List(); if (Ids != "") { backorderlist = DD_OrderData.GetListOrderBackMoneyApply(Ids.Trim(',')); } if (dlist != null) { decimal hj1 = 0; decimal hj11 = 0; decimal hj2 = 0; decimal hj21 = 0; decimal hj3 = 0; decimal hj4 = 0; decimal hj5 = 0; decimal hj51 = 0; decimal hj6 = 0; decimal hj7 = 0; decimal hj8 = 0; decimal hj9 = 0;//赔款 decimal hj10 = 0;//我们承担运费 int hjsl = 0; foreach (var md in dlist) { var mmd = mlist.Find(n => n.PlatId == md.PlatId && n.MCode == "USD"); if (mmd != null) USDRate = mmd.MRate.Value; decimal? Lr = 0; DT_OrderUserList model = new DT_OrderUserList(); model.StateName = "正常订单"; int BackType = 0;//退款类型 int? GoodsBackType = 0;//退款类型 int BackOrderState = 0;//订单类型 int IsBackOrder = 0;//是否退货订单 int GoodsState = 0;//是否退货订单 decimal PKPrice = 0;//赔款金额 decimal OurPostFee = 0;//退货运费 ; if (md.OrderState2 == 1 && backorderlist != null) { var bmd = backorderlist.Find(n => n.OrderId == md.OrderId); if (bmd != null) { IsBackOrder = 1; model.StateName = "退货赔款订单"; // // // // // // if (bmd.FactPrice != null) PKPrice = bmd.FactPrice.Value; if (bmd.GoodState != null) GoodsState = bmd.GoodState.Value; if (bmd.PostFee != null && bmd.PostFee>0) OurPostFee = bmd.PostFee.Value; GoodsBackType = bmd.BackState.Value; if (bmd.BackType != null) { BackType = bmd.BackType.Value; if (bmd.BackType == 0) { model.Remark = "退款/退货"; } else if (bmd.BackType == 1) { model.Remark = "退款/不退货"; } else if (bmd.BackType == 2) { model.Remark = "部分赔款/不退货"; } else if (bmd.BackType == 3) { model.Remark = "赔款退货"; } else if (bmd.BackType == 6) { model.Remark = "补发配件"; } } if (bmd.OrderState != null) { BackOrderState = bmd.OrderState.Value; if (bmd.OrderState == 0) { model.Remark += "取消订单收取佣金20%"; } else if (bmd.OrderState == 1) { model.Remark += "订单和佣金正常"; } } } } var shopmd = slist.Find(n => n.ShopId == md.ShopId); if (shopmd != null) { model.PlatName = shopmd.PlatName + "|" + shopmd.ShopName; } else model.PlatName = ""; model.RevName = md.RevName; model.TrackCode = md.TrackCode2; model.PlatOrderCode = md.PlatOrderCode; model.JoinOrderCode = md.JoinOrderCode; model.CountryName = md.CountryName; model.OrderDate = md.OrderDate.Value.ToString("yyyy-MM-dd"); if (md.PostDate != null) model.PostDate = md.PostDate.Value.ToString("yyyy-MM-dd"); else model.PostDate = ""; model.PostInfo = md.PostInfo; model.GoodsNum = md.GoodsNum; hjsl += md.GoodsNum.Value; var gglist = glist.FindAll(n => n.OrderId == md.OrderId); decimal hwcb = 0; decimal tc = 0; decimal sf = 0; string ghtml = ""; if (gglist != null) { foreach (var ggmd in gglist) { if (ggmd.GoodsFee != null) { hwcb += ggmd.GoodsFee.Value; if (ggmd.FeeRate != null) sf += ggmd.GoodsFee.Value * ggmd.FeeRate.Value / 100; } if (ggmd.TCFee != null) { tc += ggmd.TCFee.Value; } ghtml += ggmd.GoodsCode + " " + ggmd.TypeDesc + "数量:" + ggmd.GoodsNum + ";"; if (ggmd.GoodsFee != null) { ghtml += "成本:" + (ggmd.GoodsFee.Value / USDRate).ToString("0.00") + ";"; } else ghtml += "成本:0"; if (ggmd.FeeRate != null) { ghtml += "税率:" + ggmd.FeeRate.Value + "%;"; // if (ggmd.GoodsFee != null) // ghtml += "税费:" + (ggmd.GoodsFee.Value * ggmd.FeeRate.Value / 100 / USDRate).ToString("0.00") +";"; // else // ghtml += "税费:0;"; } else { ghtml += "税率:0;"; // ghtml += "税费:0;"; } //if (ggmd.TCFee != null) //{ // ghtml += "头程:" + ggmd.TCFee.Value.ToString("0.00") + ";
"; //} //else // ghtml += "头程:0;
"; } } model.GoodsCode = ghtml; //if @PlatId=1 set @escrowFee=0.95else if @PlatId=2 or @PlatId=3set @escrowFee=0.85else if @PlatId=5 set @escrowFee=0.9 decimal ptyjrate = 0; if (md.PlatId == 1) ptyjrate = Convert.ToDecimal(0.05); else if (md.PlatId == 2 || md.PlatId == 3 || md.PlatId == 6) ptyjrate = Convert.ToDecimal(0.15); else if (md.PlatId == 5) ptyjrate = Convert.ToDecimal(0.1); if (md.TotalPrice != null) { if (md.MoneyCode != "USD") { var opmd = mlist.Find(n => n.MCode == md.MoneyCode); var opmd2 = mlist.Find(n => n.MCode == "USD"); if (opmd != null) md.TotalPrice = opmd.MRate * md.TotalPrice / opmd2.MRate; } if (IsBackOrder == 1 && BackOrderState == 0)//取消订单 { model.TotalPrice = "0"; model.YJPrice = (md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2)).ToString("0.00"); model.escrowFee = md.escrowFee.Value.ToString("0.00"); Lr -= md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2); Lr -= md.escrowFee.Value; hj11 += md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2); hj21 += md.escrowFee.Value; } else { model.TotalPrice = md.TotalPrice.Value.ToString("0.00"); model.YJPrice = (md.TotalPrice.Value * ptyjrate).ToString("0.00"); model.escrowFee = md.escrowFee.Value.ToString("0.00"); Lr += md.TotalPrice.Value; Lr -= md.TotalPrice.Value * ptyjrate; Lr -= md.escrowFee.Value; hj1 += md.TotalPrice.Value; hj11 += md.TotalPrice.Value * ptyjrate; hj21 += md.escrowFee.Value; } } else { model.TotalPrice = ""; model.YJPrice = ""; model.escrowFee = ""; } if (IsBackOrder == 1 && (GoodsBackType == 1 || GoodsBackType == 2))//退货已经入库 不计成本 { model.GoodsFee = "0"; model.Fee1 = "0"; model.Fee3 = "0"; } else { if (md.Fee4 != null) //货物成本 { model.GoodsFee = md.Fee4.Value.ToString("0.00"); hj2 += md.Fee4.Value; Lr -= md.Fee4.Value; } else if (hwcb > 0) { model.GoodsFee = (hwcb / USDRate).ToString("0.00"); hj2 += hwcb / USDRate; Lr -= hwcb / USDRate; } else model.GoodsFee = "0"; // html.Append(""); if (sf > 0) { model.Fee1 = (sf / USDRate).ToString("0.00"); hj3 += sf / USDRate; Lr -= sf / USDRate; } else model.Fee1 = ""; if (md.Fee3 != null) //头程 { tc = md.Fee3.Value; } if (tc > 0) { model.Fee3 = tc.ToString("0.00"); Lr -= tc; hj4 += tc; } else model.Fee3 = "0"; } if (md.Fee2 != null) { model.Fee2 = (md.Fee2.Value).ToString("0.00"); hj51 += md.Fee2.Value; } else model.Fee2 = "0"; if (md.PostFee != null) { model.PostFee = (md.PostFee.Value).ToString("0.00"); Lr -= md.PostFee.Value; hj5 += md.PostFee.Value; } else model.PostFee = "0"; if (md.PostInfo != null && md.PostInfo.Contains("Fedex") && md.PostFee != null) { model.Fee4 = (md.PostFee.Value * YJRate / 100).ToString("0.00"); Lr -= md.PostFee.Value * YJRate / 100; hj6 += md.PostFee.Value * YJRate / 100; } else model.Fee4 = "0"; if (md.GDFee != null) { model.GDFee = md.GDFee.Value.ToString("0.00"); Lr -= md.GDFee.Value; hj7 += md.GDFee.Value; } else model.GDFee = ""; model.BackPostFee = OurPostFee.ToString("0.00"); Lr -= OurPostFee; hj10 += OurPostFee; if (IsBackOrder == 1 && PKPrice > 0) { model.BackMoney = PKPrice.ToString("0.00"); Lr -= PKPrice; hj9 += PKPrice; } model.LRFee = Lr.Value.ToString("0.00"); hj8 += Lr.Value; if (Lr.Value > 0 && md.TotalPrice != null && md.TotalPrice > 0) model.LRRate = ((Lr.Value / md.TotalPrice.Value) * 100).ToString("0.00") + "%"; else if (Lr.Value == 0) model.LRRate = "0%"; olist.Add(model); rowindex++; } DT_OrderUserList model2 = new DT_OrderUserList(); model2.GoodsCode = "合计:"; model2.GoodsNum = hjsl; model2.TotalPrice = hj1.ToString("0.00"); model2.YJPrice = hj11.ToString("0.00"); model2.escrowFee = hj21.ToString("0.00"); model2.GoodsFee = hj2.ToString("0.00"); model2.Fee1 = hj3.ToString("0.00"); model2.Fee3 = hj4.ToString("0.00"); model2.PostFee = hj5.ToString("0.00"); model2.Fee4 = hj6.ToString("0.00"); model2.BackPostFee = hj10.ToString("0.00"); model2.BackMoney = hj9.ToString("0.00"); model2.LRFee = hj8.ToString("0.00"); if (hj8 > 0) model2.LRRate = (hj8 / hj1 * 100).ToString("0.00") + "%"; else if (hj8 == 0) model2.LRRate = "0%"; else if (hj1 > 0) model2.LRRate = "-" + (hj8 * -1 / hj1 * 100).ToString("0.00") + "%"; olist.Add(model2); } if (olist == null) return ""; DataTable tb = olist.ToDataTable(); TableColumnCollection listColumns = new TableColumnCollection(); listColumns.Add("PlatName", "平台|店铺", DbType.String, ""); listColumns.Add("PlatOrderCode", "订单号", DbType.String, ""); listColumns.Add("CountryName", "国家", DbType.String, ""); listColumns.Add("OrderDate", "订单日期", DbType.String, ""); listColumns.Add("PostDate", "发货日期", DbType.String, ""); listColumns.Add("RevName", "收件人", DbType.String, ""); listColumns.Add("PostInfo", "物流方式", DbType.String, ""); listColumns.Add("TrackCode", "跟踪码", DbType.String, ""); listColumns.Add("GoodsCode", "货物编号", DbType.String, ""); listColumns.Add("GoodsNum", "货物数量", DbType.String, ""); listColumns.Add("TotalPrice", "订单金额$", DbType.String, ""); listColumns.Add("YJPrice", "佣金$", DbType.String, ""); listColumns.Add("escrowFee", "税费$", DbType.String, ""); listColumns.Add("GoodsFee", "货物成本", DbType.String, ""); listColumns.Add("Fee1", "关税", DbType.String, ""); listColumns.Add("Fee3", "头程费用", DbType.String, ""); listColumns.Add("Fee2", "预估运费", DbType.String, ""); listColumns.Add("PostFee", "运费", DbType.String, ""); listColumns.Add("Fee4", "运费佣金", DbType.String, ""); listColumns.Add("GDFee", "固定成本", DbType.String, ""); listColumns.Add("LRFee", "毛利润", DbType.String, ""); listColumns.Add("LRRate", "利润率", DbType.String, ""); MicrosoftExcel obj3 = new MicrosoftExcel(); return obj3.Export(tb, listColumns); } #endregion #region 修改成本 [WebMethod(EnableSession = true)] public void UpdateOrderCB(int Id, decimal GoodsFee) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); obj.UpdateOrderGoodsFee(Id, GoodsFee); } #endregion #region 标记回看 [WebMethod(EnableSession = true)] public void UpdateOrderBJ(int OrderId, string OrderName) { PagesNew.Login(this.Session); var obj = new DD_OrderData(); obj.UpdateOrderBJ(OrderName, OrderId); } #endregion #region 首页我的订单统计 [WebMethod(EnableSession = true)] public DT_OrderNum GetMyOrderCount(int UserId, DateTime SDate, DateTime EDate, string GoodsCode) { PagesNew.Login(this.Session); int CompanyId = Convert.ToInt32(Session["CompanyId"]); var obj = new DD_OrderData(); string[] categories = null; DT_OrderNum md = new DT_OrderNum(); var list = new List(); TimeSpan ts = EDate - SDate; int days = ts.Days + 1; if (days < 0) return null; List countlist = new List(); countlist = obj.GetCountListMyOrder(CompanyId, UserId, SDate, EDate, GoodsCode); categories = new string[days]; if (days > 0) { for (int i = 0; i < days; i++) { categories[i] = (SDate.AddDays(i)).ToString("MM月dd日"); } } decimal[] data = new decimal[days]; if (days > 0) { for (int j = 0; j < days; j++) { if (countlist != null) { var countmd = countlist.Find(n => n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd")); if (countmd != null) data[j] = countmd.Num.Value; else data[j] = 0; } else data[j] = 0; } } var datamd = new DT_OrderCountData(); datamd.name = "货物销量"; datamd.data = data; list.Add(datamd); md.categories = categories; JavaScriptSerializer JsonConvert = new JavaScriptSerializer(); string postmessage = JsonConvert.Serialize(list); md.Data = postmessage; return md; } #endregion #region 保存物流折扣 [WebMethod(EnableSession = true)] public void SaveGDFee(int Rate, Decimal? GDFee) { PagesNew.Login(this.Session); var obj = new BaseService(); int CompanyId = Convert.ToInt32(Session["CompanyId"]); obj.SaveGDFee(CompanyId, Rate, GDFee); } #endregion #region 获取物流折扣 [WebMethod(EnableSession = true)] public JC_Company GetGDFee() { PagesNew.Login(this.Session); var obj = new BaseService(); int CompanyId = Convert.ToInt32(Session["CompanyId"]); return obj.GetCompanyModel(CompanyId); } #endregion #region 修改跟踪码 [WebMethod(EnableSession = true)] public void UpdateDDTrackCode() { PagesNew.Login(this.Session); var obj = new DD_OrderData(); obj.UpdateDDTrackCode(); } #endregion #region 保存费用 [WebMethod(EnableSession = true)] public void SaveFee(int Type,string OrderCode, Decimal? Fee) { PagesNew.Login(this.Session); var obj = new BaseService(); int CompanyId = Convert.ToInt32(Session["CompanyId"]); obj.SaveFee(Type, OrderCode, Fee); } #endregion #region 查询费用报表 [WebMethod(EnableSession = true)] public string GetListFeeReport(int CompanyId, int FeeType, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); EDate = EDate.Value.AddDays(1); string html = ""; var list=BaseService.GetListFeeReport(CompanyId,FeeType,SDate,EDate); if (list == null) list = new List(); int days=DateDiff(SDate.Value,EDate.Value); decimal totalfee=0; for (int i = days-1; i>=0; i--) { html += ""; if (FeeType > 0) { var dlist = list.Find(n => n.InDate == SDate.Value.AddDays(i) && n.FeeType == FeeType); if (dlist != null) { html += ""; html += ""; html += ""; totalfee+=dlist.Dec.Value; html += ""; html += ""; html += ""; html += ""; html += "
" + SDate.Value.AddDays(i).ToString("yyyy年MM月dd日") + " 费用 合计:" + dlist.Dec + "$
"; html += "
" + dlist.FeeName + ":
" + dlist.Dec + "$
"; html += "
"; html += "
"; } else { html += ""; html += "
" + SDate.Value.AddDays(i).ToString("yyyy年MM月dd日") + " 费用 合计:0$
"; html += ""; html += ""; html += "
0$
"; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; } } else { var dlist = list.FindAll(n => n.InDate == SDate.Value.AddDays(i)); if (dlist != null && dlist.Count>0) { decimal hj = 0; foreach (var md in dlist) { hj += md.Dec.Value; } html += ""; totalfee+=hj; html += "
" + SDate.Value.AddDays(i).ToString("yyyy年MM月dd日") + " 费用 合计:" + hj + "$
"; html += ""; html += ""; int r = 1; foreach (var md in dlist) { if (r == 1) { html += "" + md.FeeName + ":"; html += "
" + md.Dec + "$
"; r = 2; } else if (r == 2) { html += "" + md.FeeName + ":"; html += "
" + md.Dec + "$
"; html += ""; r = 1; } } if (r == 2) { html += ""; html += ""; } html += ""; } else { html += ""; html += "
" + SDate.Value.AddDays(i).ToString("yyyy年MM月dd日") + " 费用 合计:0$
"; html += ""; html += ""; html += "
0$
"; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; } } } html += "
合计费用:" + totalfee + "$
"; return html; } private static int DateDiff(DateTime dateStart, DateTime dateEnd) { DateTime start = Convert.ToDateTime(dateStart.ToShortDateString()); DateTime end = Convert.ToDateTime(dateEnd.ToShortDateString()); TimeSpan sp = end.Subtract(start); return sp.Days; } #endregion #region 查询费用报表 [WebMethod(EnableSession = true)] public List GetListFeeReport2(int CompanyId, int FeeType, DateTime? SDate, DateTime? EDate) { PagesNew.Login(this.Session); EDate = EDate.Value.AddDays(1); string html = ""; List list = new List(); int CompanyID = Convert.ToInt32(Session["CompanyId"]); var clist=BaseService.GetListCompany3(CompanyID); var rlist = BaseService.GetListFeeReport2(CompanyId, FeeType, SDate, EDate); if (clist == null) return null; foreach (var cmd in clist) { CK_FeeReport2 rmd = new CK_FeeReport2(); rmd.CompanyName = cmd.Name; rmd.CompanyId = cmd.ID; decimal hj = 0; rmd.Fee1 = 0; rmd.Fee2 = 0; rmd.Fee3 = 0; rmd.Fee4 = 0; rmd.Fee5 = 0; rmd.Fee9= 0; rmd.HJFee = 0; if (rlist != null) { var relist = rlist.FindAll(n => n.CompanyId == cmd.ID); if (relist != null) { foreach (var remmd in relist) { if (remmd.FeeType == 1) { rmd.Fee1 = remmd.TotalFee.Value; hj += remmd.TotalFee.Value; } if (remmd.FeeType == 2) { rmd.Fee2 = remmd.TotalFee.Value; hj += remmd.TotalFee.Value; } if (remmd.FeeType == 3) { rmd.Fee3 = remmd.TotalFee.Value; hj += remmd.TotalFee.Value; } if (remmd.FeeType == 4) { rmd.Fee4 = remmd.TotalFee.Value; hj += remmd.TotalFee.Value; } if (remmd.FeeType == 5) { rmd.Fee5 = remmd.TotalFee.Value; hj += remmd.TotalFee.Value; } if (remmd.FeeType == 9) { rmd.Fee9 = remmd.TotalFee.Value; hj += remmd.TotalFee.Value; } } } } rmd.HJFee = hj; list.Add(rmd); } return list; } #endregion } }