Commit e1491841 authored by liudong1993's avatar liudong1993

采购

parent 1c5838e7
...@@ -129,5 +129,14 @@ namespace Mall.Model.Entity.Property ...@@ -129,5 +129,14 @@ namespace Mall.Model.Entity.Property
/// 财务单据id /// 财务单据id
/// </summary> /// </summary>
public int? FinanceId { get; set; } public int? FinanceId { get; set; }
/// <summary>
/// 供应商id
/// </summary>
public int? SupplierId { get; set; }
/// <summary>
/// 供应商名称
/// </summary>
public string SupplierName { get; set; }
} }
} }
\ No newline at end of file
...@@ -29,5 +29,9 @@ namespace Mall.Model.Extend.Property ...@@ -29,5 +29,9 @@ namespace Mall.Model.Extend.Property
/// /틔id /// /틔id
/// </summary> /// </summary>
public int GoodsId { get; set; } public int GoodsId { get; set; }
/// <summary>
/// 구鬧
/// </summary>
public string GoodsRemark { get; set; }
} }
} }
\ No newline at end of file
...@@ -40,5 +40,9 @@ namespace Mall.Model.Extend.Property ...@@ -40,5 +40,9 @@ namespace Mall.Model.Extend.Property
/// 明细列表 /// 明细列表
/// </summary> /// </summary>
public List<RB_Procurement_Detail_Extend> DetailList { get; set; } public List<RB_Procurement_Detail_Extend> DetailList { get; set; }
/// <summary>
/// 账户类型
/// </summary>
public int IsPublic { get; set; }
} }
} }
\ No newline at end of file
...@@ -17,6 +17,8 @@ using Mall.Repository.BaseSetUp; ...@@ -17,6 +17,8 @@ using Mall.Repository.BaseSetUp;
using Mall.Repository.Product; using Mall.Repository.Product;
using Mall.Repository.Property; using Mall.Repository.Property;
using Mall.Repository.User; using Mall.Repository.User;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Mall.Module.Property namespace Mall.Module.Property
...@@ -102,11 +104,11 @@ namespace Mall.Module.Property ...@@ -102,11 +104,11 @@ namespace Mall.Module.Property
if (list.Any()) { if (list.Any()) {
string procurementIds = string.Join(",", list.Select(x => x.Id)); string procurementIds = string.Join(",", list.Select(x => x.Id));
//查询明细 //查询明细
var pdList = procurement_DetailRepository.GetList(new RB_Procurement_Detail_Extend() { ProcurementIds = procurementIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }); var pdList = procurement_DetailRepository.GetList(new RB_Procurement_Detail_Extend() { RB_Group_Id = demodel.RB_Group_Id, ProcurementIds = procurementIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
//查询物料 //查询物料
if (pdList.Any()) { if (pdList.Any()) {
string MaterialIds = string.Join(",", pdList.Select(x => x.MaterialId).Distinct()); string MaterialIds = string.Join(",", pdList.Select(x => x.MaterialId).Distinct());
var mList = supplies_MaterialRepository.GetList(new RB_Supplies_Material_Extend() { SuppliesIdStr = MaterialIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }); var mList = supplies_MaterialRepository.GetList(new RB_Supplies_Material_Extend() { RB_Group_Id = demodel.RB_Group_Id, SuppliesIdStr = MaterialIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
foreach (var item in pdList) { foreach (var item in pdList) {
item.MaterialModel = mList.Where(x => x.Id == item.MaterialId).FirstOrDefault(); item.MaterialModel = mList.Where(x => x.Id == item.MaterialId).FirstOrDefault();
if (item.MaterialModel != null) if (item.MaterialModel != null)
...@@ -125,19 +127,18 @@ namespace Mall.Module.Property ...@@ -125,19 +127,18 @@ namespace Mall.Module.Property
{ {
item.MaterialModel.Images = "[]"; item.MaterialModel.Images = "[]";
} }
var imglist = JsonConvert.DeserializeObject<List<string>>(item.MaterialModel.Images); item.MaterialModel.ImageList = JsonConvert.DeserializeObject<List<string>>(item.MaterialModel.Images);
item.MaterialModel.ImageList = new List<string>();
} }
else { else {
item.MaterialModel = new RB_Supplies_Material_Extend(); item.MaterialModel = new RB_Supplies_Material_Extend();
} }
} }
} }
var elist = employeeRepository.GetEmployeeListRepository(new Model.Entity.User.RB_Employee_Extend() { EmployeeIds = string.Join(",", list.Select(x => x.CreateBy ?? 0).Distinct()) }); //var elist = employeeRepository.GetEmployeeListRepository(new Model.Entity.User.RB_Employee_Extend() { EmployeeIds = string.Join(",", list.Select(x => x.CreateBy ?? 0).Distinct()) });
var wlist = supplies_WareHouseRepository.GetList(new RB_Supplies_WareHouse_Extend() { WareHouseIdStr = string.Join(",", list.Select(x => x.WareHouseId ?? 0).Distinct()) }); var wlist = supplies_WareHouseRepository.GetList(new RB_Supplies_WareHouse_Extend() { RB_Group_Id = demodel.RB_Group_Id, WareHouseIdStr = string.Join(",", list.Select(x => x.WareHouseId ?? 0).Distinct()) });
foreach (var item in list) { foreach (var item in list) {
item.DetailList = pdList.Where(x => x.ProcurementId == item.Id).ToList(); item.DetailList = pdList.Where(x => x.ProcurementId == item.Id).ToList();
item.CreateByName = elist.Where(x => x.EmpId == item.CreateBy).FirstOrDefault()?.EmpName ?? ""; //item.CreateByName = elist.Where(x => x.EmpId == item.CreateBy).FirstOrDefault()?.EmpName ?? "";
item.WareHouseName = wlist.Where(x => x.Id == item.WareHouseId).FirstOrDefault()?.Name ?? ""; item.WareHouseName = wlist.Where(x => x.Id == item.WareHouseId).FirstOrDefault()?.Name ?? "";
} }
} }
...@@ -241,16 +242,16 @@ namespace Mall.Module.Property ...@@ -241,16 +242,16 @@ namespace Mall.Module.Property
/// <param name="TenantId"></param> /// <param name="TenantId"></param>
/// <param name="MallBaseId"></param> /// <param name="MallBaseId"></param>
/// <returns></returns> /// <returns></returns>
public RB_Procurement_Extend GetProcurementInfo(int procurementId,int TenantId,int MallBaseId) public RB_Procurement_Extend GetProcurementInfo(int procurementId,int TenantId,int MallBaseId,int ERPGroupId)
{ {
var pmodel = procurementRepository.GetEntity<RB_Procurement_Extend>(procurementId); var pmodel = procurementRepository.GetEntity<RB_Procurement_Extend>(procurementId);
//查询明细 //查询明细
var pdList = procurement_DetailRepository.GetList(new RB_Procurement_Detail_Extend() { ProcurementId = procurementId, TenantId = TenantId, MallBaseId = MallBaseId }); var pdList = procurement_DetailRepository.GetList(new RB_Procurement_Detail_Extend() { RB_Group_Id = ERPGroupId, ProcurementId = procurementId, TenantId = TenantId, MallBaseId = MallBaseId });
//查询物料 //查询物料
if (pdList.Any()) if (pdList.Any())
{ {
string MaterialIds = string.Join(",", pdList.Select(x => x.MaterialId).Distinct()); string MaterialIds = string.Join(",", pdList.Select(x => x.MaterialId).Distinct());
var mList = supplies_MaterialRepository.GetList(new RB_Supplies_Material_Extend() { SuppliesIdStr = MaterialIds, TenantId = TenantId, MallBaseId = MallBaseId }); var mList = supplies_MaterialRepository.GetList(new RB_Supplies_Material_Extend() { RB_Group_Id = ERPGroupId, SuppliesIdStr = MaterialIds, TenantId = TenantId, MallBaseId = MallBaseId });
foreach (var item in pdList) foreach (var item in pdList)
{ {
item.MaterialModel = mList.Where(x => x.Id == item.MaterialId).FirstOrDefault(); item.MaterialModel = mList.Where(x => x.Id == item.MaterialId).FirstOrDefault();
...@@ -270,8 +271,7 @@ namespace Mall.Module.Property ...@@ -270,8 +271,7 @@ namespace Mall.Module.Property
{ {
item.MaterialModel.Images = "[]"; item.MaterialModel.Images = "[]";
} }
var imglist = JsonConvert.DeserializeObject<List<string>>(item.MaterialModel.Images); item.MaterialModel.ImageList = JsonConvert.DeserializeObject<List<string>>(item.MaterialModel.Images);
item.MaterialModel.ImageList = new List<string>();
} }
else else
{ {
...@@ -279,7 +279,7 @@ namespace Mall.Module.Property ...@@ -279,7 +279,7 @@ namespace Mall.Module.Property
} }
} }
} }
var wlist = supplies_WareHouseRepository.GetList(new RB_Supplies_WareHouse_Extend() { WareHouseIdStr = (pmodel.WareHouseId ?? 0).ToString() }); var wlist = supplies_WareHouseRepository.GetList(new RB_Supplies_WareHouse_Extend() { RB_Group_Id = ERPGroupId, WareHouseIdStr = (pmodel.WareHouseId ?? 0).ToString() });
pmodel.DetailList = pdList; pmodel.DetailList = pdList;
pmodel.WareHouseName = wlist.FirstOrDefault()?.Name ?? ""; pmodel.WareHouseName = wlist.FirstOrDefault()?.Name ?? "";
...@@ -298,15 +298,23 @@ namespace Mall.Module.Property ...@@ -298,15 +298,23 @@ namespace Mall.Module.Property
/// <returns></returns> /// <returns></returns>
public string SetProcurementInfo(RB_Procurement_Extend demodel, int eRPEmpId, int eRPBranchId, int eRPGroupId, int tenantId, int mallBaseId, int empId) public string SetProcurementInfo(RB_Procurement_Extend demodel, int eRPEmpId, int eRPBranchId, int eRPGroupId, int tenantId, int mallBaseId, int empId)
{ {
var sModel = supplierRepository.GetEntity(demodel.SupplierId ?? 0);
if (sModel == null) { return "供应商不存在"; }
if (sModel.BankAccountId <= 0) { return "供应商未绑定账户信息"; }
//核实提交的商品物料里是否存在 //核实提交的商品物料里是否存在
string GoodsIds = string.Join(",", demodel.DetailList.Select(x => x.GoodsId).Distinct()); string GoodsIds = string.Join(",", demodel.DetailList.Select(x => x.GoodsId).Distinct());
var mList = supplies_MaterialRepository.GetList(new RB_Supplies_Material_Extend() { GoodsIds = GoodsIds, TenantId = tenantId, MallBaseId = mallBaseId }); var mList = supplies_MaterialRepository.GetList(new RB_Supplies_Material_Extend() { RB_Group_Id = eRPGroupId, GoodsIds = GoodsIds, TenantId = tenantId, MallBaseId = mallBaseId });
foreach (var item in demodel.DetailList) { foreach (var item in demodel.DetailList) {
var mModel = mList.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationKey).FirstOrDefault(); var mModel = mList.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationKey).FirstOrDefault();
if (mModel == null) { if (mModel == null) {
return "商品未找到对应的资产物料档案,商品ID:" + item.GoodsId; return "商品未找到对应的资产物料档案,商品ID:" + item.GoodsId;
} }
item.MaterialId = mModel.Id; item.MaterialId = mModel.Id;
item.GoodsRemark = mModel.Name +"("+ item.GoodsId + ")"+ " ";
if (!string.IsNullOrEmpty(mModel.SpecificationName)) {
var sList = JsonConvert.DeserializeObject<List<string>>(mModel.SpecificationName);
item.GoodsRemark += string.Join(",", sList);
}
} }
demodel.TotalCostMoney = demodel.DetailList.Sum(x => x.CostMoney ?? 0); demodel.TotalCostMoney = demodel.DetailList.Sum(x => x.CostMoney ?? 0);
demodel.TotalNumber = demodel.DetailList.Sum(x => x.Number ?? 0); demodel.TotalNumber = demodel.DetailList.Sum(x => x.Number ?? 0);
...@@ -320,6 +328,7 @@ namespace Mall.Module.Property ...@@ -320,6 +328,7 @@ namespace Mall.Module.Property
demodel.TenantId = tenantId; demodel.TenantId = tenantId;
demodel.MallBaseId = mallBaseId; demodel.MallBaseId = mallBaseId;
demodel.FinanceId = 0; demodel.FinanceId = 0;
demodel.SupplierName = sModel.Name ?? "";
var trans = procurementRepository.DbTransaction; var trans = procurementRepository.DbTransaction;
try try
...@@ -346,18 +355,133 @@ namespace Mall.Module.Property ...@@ -346,18 +355,133 @@ namespace Mall.Module.Property
TenantId = tenantId TenantId = tenantId
}, trans); }, trans);
} }
property_LogRepository.Insert(new Model.Entity.Property.RB_Property_Log()
{
Type = 3,
Content = "新增采购单",
CreateBy = empId,
CreateDate = DateTime.Now,
Id = 0,
MallBaseId = mallBaseId,
SourceId = pid,
TenantId = tenantId
});
}
procurementRepository.DBSession.Commit();
if (pid > 0)
{
//生成采购财务单 //生成采购财务单
OrderProcurementFinanceModule(demodel, sModel.BankAccountId, pid, demodel.Remark);
}
}
catch (Exception ex)
{
LogHelper.Write(ex, "SetProcurementInfo");
procurementRepository.DBSession.Rollback();
return "出错啦,请联系管理员";
}
return "";
}
/// <summary>
/// 生成采购单据
/// </summary>
/// <param name="omodel"></param>
/// <returns></returns>
public bool OrderProcurementFinanceModule(RB_Procurement_Extend demodel, int BankAccountId,int pid,string pRemark)
{
var flag = false;
try
{
int CostTypeId = Convert.ToInt32(new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("FinanceSetting")["ProcurementCTId"]);
int CurrencyId = Convert.ToInt32(new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("FinanceSetting")["ProcurementCurrencyId"]);
int ProcurementFWId = Convert.ToInt32(new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("FinanceSetting")["ProcurementFWId"]);
int ProcurementDirector = Convert.ToInt32(new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("FinanceSetting")["ProcurementDirector"]);
int ProcurementBranchId = Convert.ToInt32(new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("FinanceSetting")["ProcurementBranchId"]);
int ProcurementDepartment = Convert.ToInt32(new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("FinanceSetting")["ProcurementDepartment"]);
decimal TotalMoney = 0;
var detailList = new List<object>();
foreach (var item in demodel.DetailList)
{
decimal Money = (item.CostMoney ?? 0) * (item.Number ?? 0);
TotalMoney += Money;
detailList.Add(
new
{
CostTypeId,
Number = (item.Number ?? 0),
OriginalMoney = Money,
UnitPrice = (item.CostMoney ?? 0),
Remark = item.GoodsRemark
}
);
}
string Remark = System.DateTime.Now.ToString("yyyy年MM月dd日") + " 自动生成采购单据";
var financeObj = new
{
CreateBy = ProcurementDirector,
demodel.IsPublic,
ClientType = 10,
ClientID = BankAccountId,
CurrencyId,
WBMoney = TotalMoney,
PayDate = DateTime.Now.ToString("yyyy-MM-dd"),
RB_Branch_Id = ProcurementBranchId,
TemplateId = ProcurementFWId,
OrderSource = 16,
OtherType = 15,
ReFinanceId = pid,
Remark,
detailList,
RB_Depart_Id = ProcurementDepartment
};
string sign = EncryptionHelper.AesEncrypt(JsonHelper.Serialize(financeObj), Config.FinanceKey);
var resultInfo = new
{
msg = sign
};
string apiResult = Mall.Common.Plugin.HttpHelper.HttpPost(Config.PaymentFinanceApi, JsonHelper.Serialize(resultInfo), "");
LogHelper.Write(apiResult);
var apir = JsonConvert.DeserializeObject<ApiResult>(apiResult);
if (apir.resultCode == 1)
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Procurement_Extend.Remark), pRemark +" 自动生成采购单据:"+ apir.data.ToString()}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Procurement_Extend.Id),
FiledValue=pid,
OperatorEnum=OperatorEnum.Equal
} }
};
procurementRepository.Update(keyValues, wheres);
} }
catch (Exception) else
{ {
//记录自动生成失败,需手动新增财务单据
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Procurement_Extend.Remark), pRemark +" 财务单据新增失败,请手动增加"}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Procurement_Extend.Id),
FiledValue=pid,
OperatorEnum=OperatorEnum.Equal
}
};
procurementRepository.Update(keyValues, wheres);
}
throw;
} }
catch (Exception ex)
{
LogHelper.Write(ex);
}
return ""; return flag;
} }
#endregion #endregion
...@@ -593,7 +717,7 @@ namespace Mall.Module.Property ...@@ -593,7 +717,7 @@ namespace Mall.Module.Property
} }
} }
else { else {
string SpecificationName = "规格:" + item.DefaultSpecificationName; string SpecificationName = "[规格:" + item.DefaultSpecificationName + "]";
var mModel = mList.Where(x => x.GoodsId == item.Id && x.SpecificationKey == "").FirstOrDefault(); var mModel = mList.Where(x => x.GoodsId == item.Id && x.SpecificationKey == "").FirstOrDefault();
if (mModel == null) if (mModel == null)
{ {
......
...@@ -63,6 +63,9 @@ namespace Mall.Repository.Product ...@@ -63,6 +63,9 @@ namespace Mall.Repository.Product
if (dmodel.IsProxy > 0) { if (dmodel.IsProxy > 0) {
where += $@" and g.{nameof(RB_Goods_Extend.IsProxy)}={dmodel.IsProxy}"; where += $@" and g.{nameof(RB_Goods_Extend.IsProxy)}={dmodel.IsProxy}";
} }
if (dmodel.SupplierId > 0) {
where += $@" and g.{nameof(RB_Goods_Extend.SupplierId)}={dmodel.SupplierId}";
}
string orderBy = " g.CreateDate desc"; string orderBy = " g.CreateDate desc";
if (dmodel.OrderBy == 1) if (dmodel.OrderBy == 1)
......
...@@ -43,6 +43,8 @@ namespace Mall.WebApi.Controllers.MallBase ...@@ -43,6 +43,8 @@ namespace Mall.WebApi.Controllers.MallBase
} }
demodel.RB_Group_Id = requestParm.ERPGroupId; demodel.RB_Group_Id = requestParm.ERPGroupId;
demodel.TenantId = requestParm.TenantId;
demodel.MallBaseId = requestParm.MallBaseId;
var list = propertyModule.GetProcurementPageList(pagelist.pageIndex, pagelist.pageSize, demodel, out long count); var list = propertyModule.GetProcurementPageList(pagelist.pageIndex, pagelist.pageSize, demodel, out long count);
pagelist.count = Convert.ToInt32(count); pagelist.count = Convert.ToInt32(count);
pagelist.pageData = list.Select(x => new pagelist.pageData = list.Select(x => new
...@@ -92,7 +94,7 @@ namespace Mall.WebApi.Controllers.MallBase ...@@ -92,7 +94,7 @@ namespace Mall.WebApi.Controllers.MallBase
return ApiResult.ParamIsNull("请传递参数"); return ApiResult.ParamIsNull("请传递参数");
} }
var model = propertyModule.GetProcurementInfo(ProcurementId, requestParm.TenantId, requestParm.MallBaseId); var model = propertyModule.GetProcurementInfo(ProcurementId, requestParm.TenantId, requestParm.MallBaseId, requestParm.ERPGroupId);
return ApiResult.Success("",new { return ApiResult.Success("",new {
model.Id, model.Id,
model.WareHouseId, model.WareHouseId,
...@@ -171,10 +173,19 @@ namespace Mall.WebApi.Controllers.MallBase ...@@ -171,10 +173,19 @@ namespace Mall.WebApi.Controllers.MallBase
{ {
return ApiResult.ParamIsNull("请传递参数"); return ApiResult.ParamIsNull("请传递参数");
} }
if (requestParm.ERPGroupId <= 0)
{
return ApiResult.ParamIsNull("请传递参数");
}
if (requestParm.EmpId <= 0) { if (requestParm.EmpId <= 0) {
return ApiResult.ParamIsNull("请传递参数"); return ApiResult.ParamIsNull("请传递参数");
} }
if (demodel.IsPublic < 0) {
return ApiResult.ParamIsNull("请选择账户类型");
}
if ((demodel.SupplierId ?? 0) <= 0) {
return ApiResult.ParamIsNull("请传递供应商");
}
if ((demodel.WareHouseId ?? 0) <= 0) { if ((demodel.WareHouseId ?? 0) <= 0) {
return ApiResult.ParamIsNull("请传递仓库id"); return ApiResult.ParamIsNull("请传递仓库id");
} }
......
...@@ -44,8 +44,8 @@ ...@@ -44,8 +44,8 @@
"ExpendBranchId": 49, //财务支出创建人公司 "ExpendBranchId": 49, //财务支出创建人公司
"ExpendDepartment": 331, "ExpendDepartment": 331,
"RebornDMC": "reborn_dmc", "RebornDMC": "reborn_dmc",
"IncomeFinanceApi": "http://192.168.2.16:8083/api/Mall/InsertFinanceBatchForMallIn", "IncomeFinanceApi": "http://testapi.oytour.com/api/Mall/InsertFinanceBatchForMallIn",
"PaymentFinanceApi": "http://192.168.2.16:8083/api/Mall/InsertFinanceBatchForMallOut", "PaymentFinanceApi": "http://testapi.oytour.com/api/Mall/InsertFinanceBatchForMallOut",
"FinanceKey": "FinanceMallInsertToERPViitto2020", "FinanceKey": "FinanceMallInsertToERPViitto2020",
"SettlementRate": "0.60", "SettlementRate": "0.60",
//"RedisSetting": { //"RedisSetting": {
...@@ -65,7 +65,13 @@ ...@@ -65,7 +65,13 @@
"TenantId": 1, "TenantId": 1,
"MallBaseId": 1, "MallBaseId": 1,
"RemitTypeId": 10, "RemitTypeId": 10,
"RemitAccountId": 3012 "RemitAccountId": 3012,
"ProcurementCTId": 224, //以下采购
"ProcurementFWId": 127,
"ProcurementDirector": 1756,
"ProcurementBranchId": 49,
"ProcurementDepartment": 331,
"ProcurementCurrencyId": 1
}, },
"InitializeImages": { "InitializeImages": {
"GradeEntranceImage": "1234566778" "GradeEntranceImage": "1234566778"
......
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