223 lines
11 KiB
C#
223 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Util;
|
|
using WX.CRM.IBLL.Wx;
|
|
using WX.CRM.Model.DTO;
|
|
using WX.CRM.WebHelper;
|
|
|
|
namespace WX.CRM.WEB.Controllers.WeiXin
|
|
{
|
|
public class MonthSettlementController : BaseController
|
|
{
|
|
private readonly IWX_BALANCE _balance;
|
|
private readonly ICACHE_Q _cache;
|
|
|
|
public MonthSettlementController(IWX_BALANCE balance, ICACHE_Q cache)
|
|
{
|
|
_balance = balance;
|
|
this._cache = cache;
|
|
}
|
|
|
|
[HttpGet]
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_员工工资查询)]
|
|
[AuthorizeSession(HasRight = true)]
|
|
public ActionResult Index()
|
|
{
|
|
try
|
|
{
|
|
ToolBar tool = new ToolBar();
|
|
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.订单分成导出, userRightId);
|
|
tool.AllowButton(toolbtn);
|
|
tool.AddOtherButton("Other2", "导出", "icon-export", "ExportAllPage_Click", true);
|
|
ViewBag.ToolBar = tool;
|
|
|
|
string tableId = "tablist";
|
|
Table tab = new Table(tableId);
|
|
tab.AddHeadCol("eid", "", "工号");
|
|
tab.AddHeadCol("uname", "", "姓名");
|
|
tab.AddHeadCol("gname", "", "组别");
|
|
tab.AddHeadCol("isdismiss", "", "在/离职");
|
|
var x = 5;
|
|
//tab.AddHeadCol("subproductname", "", "产品", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
//x++;
|
|
tab.AddHeadCol("PerformanceAmount", "", "业绩额", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
x++;
|
|
//tab.AddHeadCol("commissionratio", "", "业绩额提成比例", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
//x++;
|
|
tab.AddHeadCol("OrderCount", "", "单量", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
x++;
|
|
//tab.AddHeadCol("ordercountratio", "", "单量提成比例", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
//x++;
|
|
//tab.AddHeadCol("allratio", "", "总比例", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
//x++;
|
|
tab.AddHeadCol("COMMISSION", "", "本月提成", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
x++;
|
|
tab.AddHeadCol("yingshou", "", "本月应付", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
x++;
|
|
tab.AddHeadCol("yuliu", "", "本月预留", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
x++;
|
|
tab.AddHeadCol("fanhuan", "", "预留返还", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
x++;
|
|
tab.AddHeadCol("tuikuan", "", "退款", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
x++;
|
|
tab.AddHeadCol("shishou", "", "本月实付", "sortTable('tablist'," + x + ",'float');", "cursor:pointer");
|
|
|
|
tab.AddHeadRow();
|
|
|
|
ViewBag.gridTable = tab.GetHead();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex);
|
|
}
|
|
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_员工工资查询)]
|
|
[AuthorizeSession(HasRight = true)]
|
|
public JsonResult Index(string year, string month, string columns)
|
|
{
|
|
try
|
|
{
|
|
var yearmonth = new DateTime(int.Parse(year), int.Parse(month), 01);
|
|
var table = new Table(columns, true);
|
|
//var list = _balance.GetSaleUserWageQuery(yearmonth).Tables[0].ToList<WX_BALANCESALEUSER>();
|
|
var yejiList = _balance.GetUserYeJi(yearmonth, null).Tables[0].ToList<UserYeJiView>();
|
|
var tuikuanList = _balance.GetUserTuiKuan(yearmonth, null).Tables[0].ToList<UserTuiKuanView>();
|
|
var yuliuList = _balance.GetUserYuLiu(yearmonth, null).Tables[0].ToList<UserYuLiuView>();
|
|
|
|
var users = _cache.GetUserList();
|
|
|
|
var yejiData = yejiList.GroupBy(m => new { m.eid, m.gname })
|
|
.Select(g => new
|
|
{
|
|
g.Key.eid,
|
|
g.Key.gname,
|
|
performanceamount = g.Sum(m => m.performanceamount),
|
|
ordercount = g.Sum(m => m.ordercount),
|
|
commission = g.Sum(m => m.commission)
|
|
});
|
|
var tuikuanData = tuikuanList.GroupBy(m => new { m.eid }).Select(g => new { g.Key.eid, tuikuan = g.Sum(m => m.refundprice) });
|
|
|
|
foreach (var item in users)
|
|
{
|
|
var yejiItem = yejiData.FirstOrDefault(p => p.eid == item.EID);
|
|
var tuikuanItem = tuikuanData.FirstOrDefault(p => p.eid == item.EID);
|
|
var yuliuItem = yuliuList.FirstOrDefault(p => p.eid == item.EID);
|
|
|
|
var performanceamount = yejiItem != null ? yejiItem.performanceamount : 0;
|
|
var ordercount = yejiItem != null ? yejiItem.ordercount : 0;
|
|
var commission = yejiItem != null ? yejiItem.commission : 0;
|
|
var yingshou = yejiItem != null ? yejiItem.commission * (decimal)0.7 : 0;
|
|
var yuliu = yejiItem != null ? yejiItem.commission * (decimal)0.3 : 0;
|
|
var fanhuan = yuliuItem != null ? yuliuItem.returnmoney : 0;
|
|
var tuikuan = tuikuanItem != null ? tuikuanItem.tuikuan : 0;
|
|
var shishou = yingshou + fanhuan - tuikuan;
|
|
|
|
table.AddCol(item.EID);
|
|
table.AddCol(item.UNAME);
|
|
table.AddCol(yejiItem != null ? yejiItem.gname : "未知");
|
|
table.AddCol(string.Format("{0}", item.ISDISMISS == 1 ? "<span style='color:red'>离职</span>" : "在职"));
|
|
table.AddCol(performanceamount);
|
|
table.AddCol(ordercount);
|
|
table.AddCol(commission);
|
|
table.AddCol(yingshou);
|
|
table.AddCol(yuliu);
|
|
table.AddCol(fanhuan);
|
|
table.AddCol(tuikuan);
|
|
table.AddCol(shishou);
|
|
|
|
table.AddRow();
|
|
}
|
|
table.AddCol("合计:");
|
|
table.AddCol("");
|
|
table.AddCol("");
|
|
table.AddCol("");
|
|
table.AddCol(yejiList.Sum(p => p.performanceamount));
|
|
table.AddCol(yejiList.Sum(p => p.ordercount));
|
|
table.AddCol(yejiList.Sum(p => p.commission));
|
|
table.AddCol(yejiList.Sum(p => p.commission) * (decimal)0.7);
|
|
table.AddCol(yejiList.Sum(p => p.commission) * (decimal)0.3);
|
|
table.AddCol(yuliuList.Sum(p => p.returnmoney));
|
|
table.AddCol(tuikuanList.Sum(p => p.refundprice));
|
|
table.AddCol((yejiList.Sum(p => p.commission) * (decimal)0.7) + yuliuList.Sum(p => p.returnmoney) - tuikuanList.Sum(p => p.refundprice));
|
|
table.AddFootRow();
|
|
|
|
var json = new
|
|
{
|
|
rowsList = table.GetRows(),
|
|
foot = table.GetFoot()
|
|
};
|
|
return Json(json, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error("MonthSettlementController/Index:" + ex.Message + ex.StackTrace);
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_员工工资查询)]
|
|
[AuthorizeSession(HasRight = true)]
|
|
public FileResult Export(string year, string month)
|
|
{
|
|
var yearmonth = new DateTime(int.Parse(year), int.Parse(month), 01);
|
|
string checkedFilds = Server.UrlDecode(Request.Cookies["checkedFilds"].Value).Replace("groupid", "组别");
|
|
string checkedTitle = Server.UrlDecode(Request.Cookies["checkedTitles"].Value);
|
|
Request.Cookies.Remove("checkedFilds");//用完后删除cookies
|
|
Request.Cookies.Remove("checkedTitles");//用完后删除cookies
|
|
//var list = _balance.GetSaleUserWageQuery(yearmonth).Tables[0].ToList<WX_BALANCESALEUSER>();
|
|
var export = new List<SaleUserWageExport>();
|
|
//foreach (var item in list)
|
|
//{
|
|
// var info = new SaleUserWageExport
|
|
// {
|
|
// eid = item.EID,
|
|
// uname = item.UNAME,
|
|
// gname = item.GNAME,
|
|
// isdismiss = item.ISDISMISS.Value == 1 ? "离职" : "在职",
|
|
// SUBPRODUCTNAME = item.SUBPRODUCTNAME,
|
|
// PerformanceAmount = item.PERFORMANCEAMOUNT,
|
|
// OrderCount = item.ORDERCOUNT,
|
|
// COMMISSION = item.COMMISSION,
|
|
// yingshou = item.YINGSHOU,
|
|
// yuliu = item.YULIU,
|
|
// fanhuan = item.FANHUAN,
|
|
// tuikuan = item.TUIKUAN,
|
|
// shishou = item.SHISHOU
|
|
// };
|
|
// export.Add(info);
|
|
//}
|
|
return File(ExcelHelper.ExportListModelToExcel<SaleUserWageExport>(export, "员工工资实时报表", 60000, checkedFilds, checkedTitle, null), "application/ms-excel", PageRequest.GetDlownLoadName("员工工资实时报表.xls"));
|
|
}
|
|
|
|
private class SaleUserWageExport
|
|
{
|
|
public decimal eid { get; set; }
|
|
public string uname { get; set; }
|
|
public string gname { get; set; }
|
|
public string isdismiss { get; set; }
|
|
public string SUBPRODUCTNAME { get; set; }
|
|
public decimal PerformanceAmount { get; set; }
|
|
//public string commissionratio { get; set; }
|
|
public decimal OrderCount { get; set; }
|
|
//public string ordercountratio { get; set; }
|
|
//public string allratio { get; set; }
|
|
//public decimal AllPerformanceAmount { get; set; }
|
|
public decimal COMMISSION { get; set; }
|
|
public decimal yingshou { get; set; }
|
|
public decimal yuliu { get; set; }
|
|
public decimal fanhuan { get; set; }
|
|
public decimal tuikuan { get; set; }
|
|
public decimal shishou { get; set; }
|
|
}
|
|
|
|
}
|
|
}
|