Commit 7be344a7 by GhostUI

管理成本

parent 475ddaa9
...@@ -24,5 +24,10 @@ namespace Bailun.DC.Models.Dtos.Finance ...@@ -24,5 +24,10 @@ namespace Bailun.DC.Models.Dtos.Finance
public string FeeType { get; set; } public string FeeType { get; set; }
public bool IsPage { get; set; } = false; public bool IsPage { get; set; } = false;
#endregion #endregion
public int? IsStatistics { get; set; }
/// <summary>
/// 0付现 1成本
/// </summary>
public int Flag { get; set; }
} }
} }
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models.WebApiModels
{
public class ManagementCost : dc_base_finance_fee
{
///// <summary>
///// 费用标题
///// </summary>
//public string TypeName { get; set; }
//public string AccountingSubjectName { get; set; }
///// <summary>
///// 费用类型编码
///// </summary>
//public int? CostForm { get; set; }
///// <summary>
///// 费用类型中文名称
///// </summary>
//public string CostName { get; set; }
//public string CompanyName { get; set; }
//public decimal? Amount { get; set; }
//public decimal? AmountRmb { get; set; }
///// <summary>
///// 是否管理成本 0否 1是
///// </summary>
//public int? Statistics { get; set; }
//public int? IsLend { get; set; }
//public int? LendBalance { get; set; }
//public int? CompanyType { get; set; }
public string management_cost_name { get; set; }
}
}
...@@ -4,6 +4,7 @@ using Bailun.DC.Models; ...@@ -4,6 +4,7 @@ using Bailun.DC.Models;
using Bailun.DC.Models.Common; using Bailun.DC.Models.Common;
using Bailun.DC.Models.Common.Page; using Bailun.DC.Models.Common.Page;
using Bailun.DC.Models.Dtos.Finance; using Bailun.DC.Models.Dtos.Finance;
using Bailun.DC.Models.WebApiModels;
using Dapper; using Dapper;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using Newtonsoft.Json; using Newtonsoft.Json;
...@@ -57,34 +58,35 @@ namespace Bailun.DC.Services.WebApiService ...@@ -57,34 +58,35 @@ namespace Bailun.DC.Services.WebApiService
} }
} }
} }
dtos.Col.Add(new columnsObj var jsonStr = GenerateStr(Col, listValue);
{ //dtos.Col.Add(new columnsObj
key = "key", //{
title = "费用类型" // key = "key",
}); // title = "费用类型"
for (int j = 0; j < Col.Count; j++) //});
{ //for (int j = 0; j < Col.Count; j++)
var keyInfo = new columnsObj //{
{ // var keyInfo = new columnsObj
key = "key" + j, // {
title = Col[j] // key = "key" + j,
}; // title = Col[j]
dtos.Col.Add(keyInfo); // };
} // dtos.Col.Add(keyInfo);
var jsonStr = "["; //}
for (int i = 0; i < listValue.Count; i++) //var jsonStr = "[";
{ //for (int i = 0; i < listValue.Count; i++)
jsonStr += "{"; //{
jsonStr += "\"key\":\"" + listValue[i].Item1 + "\",";//第一条费用类型 // jsonStr += "{";
for (int j = 0; j < listValue[i].Item2.Count; j++)//第一条类型里所有数据 // jsonStr += "\"key\":\"" + listValue[i].Item1 + "\",";//第一条费用类型
{ // for (int j = 0; j < listValue[i].Item2.Count; j++)//第一条类型里所有数据
jsonStr += "\"" + dtos.Col[j + 1].key + "\":\"" + listValue[i].Item2[j] + "\","; // {
} // jsonStr += "\"" + dtos.Col[j + 1].key + "\":\"" + listValue[i].Item2[j] + "\",";
jsonStr = jsonStr.Trim(','); // }
jsonStr += "},"; // jsonStr = jsonStr.Trim(',');
} // jsonStr += "},";
jsonStr = jsonStr.Trim(','); //}
jsonStr += "]"; //jsonStr = jsonStr.Trim(',');
//jsonStr += "]";
//if (listInterest.Count > 0) //if (listInterest.Count > 0)
//{ //{
...@@ -93,7 +95,8 @@ namespace Bailun.DC.Services.WebApiService ...@@ -93,7 +95,8 @@ namespace Bailun.DC.Services.WebApiService
//{ //{
//} //}
dtos.Data = jsonStr; dtos.Col = jsonStr.Item1;
dtos.Data = jsonStr.Item2;
} }
return new CommonApiResponseDto<FinanceDto> return new CommonApiResponseDto<FinanceDto>
{ {
...@@ -115,6 +118,7 @@ namespace Bailun.DC.Services.WebApiService ...@@ -115,6 +118,7 @@ namespace Bailun.DC.Services.WebApiService
}; };
} }
#region 付现流水明细 #region 付现流水明细
/// <summary> /// <summary>
/// 分页查询付现流水明细 /// 分页查询付现流水明细
...@@ -189,7 +193,7 @@ namespace Bailun.DC.Services.WebApiService ...@@ -189,7 +193,7 @@ namespace Bailun.DC.Services.WebApiService
return sqlText.ToString(); return sqlText.ToString();
} }
#endregion #endregion
private List<dc_base_finance_fee> GetFinanceFeeList(GetCashFlowStatementInput input) private List<ManagementCost> GetFinanceFeeList(GetCashFlowStatementInput input)
{ {
var sql = $@"select * from dc_base_finance_fee s1 var sql = $@"select * from dc_base_finance_fee s1
left JOIN dc_base_finance_company s2 left JOIN dc_base_finance_company s2
...@@ -216,7 +220,7 @@ and s2.company_type = @CorporateEntity "; ...@@ -216,7 +220,7 @@ and s2.company_type = @CorporateEntity ";
para.Add("offset", input.PageNumber); para.Add("offset", input.PageNumber);
} }
} }
var data = SimpleCRUD.Query<dc_base_finance_fee>(sql, para, GlobalConfig.ConnectionString).ToList(); var data = SimpleCRUD.Query<ManagementCost>(sql, para, GlobalConfig.ConnectionString).ToList();
foreach (var item in data) foreach (var item in data)
{ {
if (item.cost_form == 2) if (item.cost_form == 2)
...@@ -242,7 +246,15 @@ and s2.company_type = @CorporateEntity "; ...@@ -242,7 +246,15 @@ and s2.company_type = @CorporateEntity ";
try try
{ {
//input.IsPage = true; //input.IsPage = true;
var data = GetFinanceFeeList(input); var data = new List<ManagementCost>();
if (input.Flag == 1)
{
data = GetManagementCostList(input);
}
else
{
data = GetFinanceFeeList(input);
}
var dto = data.Select(x => new FinanceDetailsDto var dto = data.Select(x => new FinanceDetailsDto
{ {
Amount = Convert.ToDecimal(x.amount), Amount = Convert.ToDecimal(x.amount),
...@@ -271,5 +283,132 @@ and s2.company_type = @CorporateEntity "; ...@@ -271,5 +283,132 @@ and s2.company_type = @CorporateEntity ";
return new CommonApiResponseDto<List<FinanceDetailsDto>> { IsSuccess = false, Message = e.Message }; return new CommonApiResponseDto<List<FinanceDetailsDto>> { IsSuccess = false, Message = e.Message };
} }
} }
public CommonApiResponseDto<FinanceDto> GetManagementCost(GetCashFlowStatementInput input)
{
var data = GetManagementCostList(input);
var dtos = new FinanceDto();
//var typeNameList = data.Select(x => x.TypeName).Distinct().ToList();//费用标题
var costNameList = data.Select(x => x.management_cost_name).Distinct().ToList();//费用类型(借支/借还、付款、收款)
var listValue = new List<Tuple<string, List<decimal>>>();
for (var i = 0; i < costNameList.Count; i++)//根据费用类型取数
{
//从源数据里拿到所有数据
var feedata = data.Where(x => x.management_cost_name == costNameList[i]).ToList();
//赋值所有费用标题 没有的默认赋值0
foreach (var item in feedata)
{
//var fee = feedata.Where(x => x.TypeName == item).ToList();
var obj = listValue.Where(a => a.Item1 == item.type_name).FirstOrDefault();
if (obj == null)
{
var listItems = new List<decimal>();
while (listItems.Count < costNameList.Count)//所有主体都添加上
{
listItems.Add(0.00M);
}
listItems[i] = item.amount_rmb ?? 0;//当前主体赋值
listValue.Add(new Tuple<string, List<decimal>>(item.type_name, listItems));
}
else
{
obj.Item2[i] += item.amount_rmb ?? 0;
}
}
}
var jsonStr = GenerateStr(costNameList, listValue);
dtos.Col = jsonStr.Item1;
dtos.Data = jsonStr.Item2;
return new CommonApiResponseDto<FinanceDto>
{
Data = dtos,
};
}
private List<ManagementCost> GetManagementCostList(GetCashFlowStatementInput input)
{
var sql = $@"select *
from dc_base_finance_management_cost s1
LEFT JOIN dc_base_finance_fee s2
ON s1.management_cost_type = s2.cost_form
and s1.management_cost_category = s2.accounting_subject_name
and s1.management_cost_title = s2.type_name
LEFT JOIN dc_base_finance_company s3
ON s3.company_name = s2.company_name
where s2.cost_status = 4
and (s2.is_lend is null or s2.is_lend = 1
or (s2.is_lend = 2 and s2.lend_balance > 0) or (s2.is_lend = 2 and s2.cost_form = 1))
and s2.pay_time >= '{input.PaymentTimeStart.Date}'
and s2.pay_time < '{input.PaymentTimeEnd.AddDays(1).Date}'
and s3.company_type = {input.CorporateEntity} ";
var para = new DynamicParameters();
if (!string.IsNullOrEmpty(input.CompanyName) &&
!string.IsNullOrEmpty(input.FeeType))
{
sql += @" and s2.type_name = @typename
and s1.management_cost_name = @managementcostname";
para.Add("typename", input.FeeType);
para.Add("managementcostname", input.CompanyName);
}
var data = SimpleCRUD.Query<ManagementCost>(sql, para, GlobalConfig.ConnectionString).ToList();
data.ForEach((item) =>
{
if (item.cost_form == 2)
{
item.amount = -(item.amount);
item.amount_rmb = -(item.amount_rmb);
}
//借支单待还余额
if (item.cost_form == 3)
{
if (item.is_lend.HasValue && item.is_lend.Value == 2 && ((item.lend_balance ?? 0) > 0)) //归还金额
{
item.amount = -(item.amount);
item.amount_rmb = -(item.amount_rmb);
}
}
});
return data;
}
/// <summary>
/// 生成前端需要的表头和内容
/// </summary>
/// <param name="Col"></param>
/// <param name="listValue"></param>
/// <returns></returns>
private (List<columnsObj>,string) GenerateStr(List<string> Col, List<Tuple<string, List<decimal>>> listValue)
{
var colList = new List<columnsObj>();
colList.Add(new columnsObj
{
key = "key",
title = "费用类型"
});
for (int j = 0; j < Col.Count; j++)
{
var keyInfo = new columnsObj
{
key = "key" + j,
title = Col[j]
};
colList.Add(keyInfo);
}
var jsonStr = "[";
for (int i = 0; i < listValue.Count; i++)
{
jsonStr += "{";
jsonStr += "\"key\":\"" + listValue[i].Item1 + "\",";//第一条费用类型
for (int j = 0; j < listValue[i].Item2.Count; j++)//第一条类型里所有数据
{
jsonStr += "\"" + colList[j + 1].key + "\":\"" + listValue[i].Item2[j] + "\",";
}
jsonStr = jsonStr.Trim(',');
jsonStr += "},";
}
jsonStr = jsonStr.Trim(',');
jsonStr += "]";
return (colList, jsonStr);
}
} }
} }
...@@ -106,5 +106,13 @@ namespace Bailun.DC.WebApi.Controllers ...@@ -106,5 +106,13 @@ namespace Bailun.DC.WebApi.Controllers
[HttpPost("getFinanceDetails")] [HttpPost("getFinanceDetails")]
public CommonApiResponseDto<List<FinanceDetailsDto>> GetFinanceDetails(GetCashFlowStatementInput input) public CommonApiResponseDto<List<FinanceDetailsDto>> GetFinanceDetails(GetCashFlowStatementInput input)
=> new FinanceService().GetFinanceDetails(input); => new FinanceService().GetFinanceDetails(input);
/// <summary>
/// 获取管理成本
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("getManagementCost")]
public CommonApiResponseDto<FinanceDto> GetManagementCost(GetCashFlowStatementInput input)
=> new FinanceService().GetManagementCost(input);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment