Commit 719d8eac by lizefeng

修复非先货后款的的单,计算平均到货天数时的异常

parent 751a4804
...@@ -182,7 +182,7 @@ select ...@@ -182,7 +182,7 @@ select
/// <param name="limit"></param> /// <param name="limit"></param>
/// <param name="total"></param> /// <param name="total"></param>
/// <returns></returns> /// <returns></returns>
public static List<dc_auto_purchase_advise_detailed_dto> DetailList(dc_auto_purchase_advise_detailed_search_dto m, int offset, int limit, ref int total) public static List<dc_auto_purchase_advise_detailed_dto> DetailList(dc_auto_purchase_advise_detailed_search_dto m, int offset, int limit, ref int total, string order = "", string sort = "")
{ {
var list = new List<dc_auto_purchase_advise_detailed_dto>(); var list = new List<dc_auto_purchase_advise_detailed_dto>();
...@@ -194,19 +194,44 @@ select ...@@ -194,19 +194,44 @@ select
{ {
sql = @" sql = @"
select select
sum(t5.forecast_turnoverday_sales) as 'forecast_turnoverday_sales', -- 供应链长度日均
sum(t5.quantity_out_stock) as 'quantity_out_stock', -- 缺货
sum(t5.quantity_transfer) as 'quantity_transfer', -- 调拨在途
sum(t5.quantity_purchase) as 'quantity_purchase', -- 采购在途
sum(t5.quantity_inventory) as 'quantity_inventory', -- 库存数
sum(t3.unit_price * t1.quantity_final_advise) as 'quantity_final_advise_price', -- 采购金额
sum(t5.turnover_days) as 'turnover_days', -- 周转天数
sum(t1.quantity_init_advise) as 'quantity_init_advise',
sum(t1.quantity_final_advise) as 'quantity_final_advise',
sum(t1.quantity_actual) as 'quantity_actual',
sum(t1.history_fourteenday_sales) as 'history_fourteenday_sales',
sum(t1.goods_quantity_init_advise) as 'goods_quantity_init_advise',
sum(t1.goods_history_fourteenday_sales) as 'goods_history_fourteenday_sales'
from dc_auto_purchase_advise_detailed as t1 from dc_auto_purchase_advise_detailed as t1
left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code
left join dc_base_sku as t3 on t1.bailun_sku = t3.bailun_sku left join dc_base_sku as t3 on t1.bailun_sku = t3.bailun_sku
left join dc_auto_purchase_advise as t4 on t1.main_id = t4.id left join dc_auto_purchase_advise as t4 on t1.main_id = t4.id
left join dc_auto_turnover as t5 on t1.warehouse_code = t5.warehouse_code and t1.bailun_sku = t5.bailun_sku
where 1=1 "; where 1=1 ";
} }
else { else {
sql = @" sql = @"
select t1.*,t2.warehouse_name,t3.sku_title_cn as 'sku_name',t4.create_time from dc_auto_purchase_advise_detailed as t1 select
t1.*,t2.warehouse_name,t3.sku_title_cn as 'sku_name',t4.create_time,
(t5.forecast_turnoverday_sales) as 'forecast_turnoverday_sales', -- 供应链长度日均
(t5.quantity_out_stock) as 'quantity_out_stock', -- 缺货
(t5.quantity_transfer) as 'quantity_transfer', -- 调拨在途
(t5.quantity_purchase) as 'quantity_purchase', -- 采购在途
(t5.quantity_inventory) as 'quantity_inventory', -- 库存数
(t3.unit_price * t1.quantity_final_advise) as 'quantity_final_advise_price', -- 采购金额
t3.suppliers_name
from dc_auto_purchase_advise_detailed as t1
left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code
left join dc_base_sku as t3 on t1.bailun_sku = t3.bailun_sku left join dc_base_sku as t3 on t1.bailun_sku = t3.bailun_sku
left join dc_auto_purchase_advise as t4 on t1.main_id = t4.id left join dc_auto_purchase_advise as t4 on t1.main_id = t4.id
left join dc_auto_turnover as t5 on t1.warehouse_code = t5.warehouse_code and t1.bailun_sku = t5.bailun_sku
where 1=1 "; where 1=1 ";
} }
...@@ -268,16 +293,40 @@ where 1=1 "; ...@@ -268,16 +293,40 @@ where 1=1 ";
sql += " and t3.buyer_name =@buyer_name "; sql += " and t3.buyer_name =@buyer_name ";
parameters.Add("buyer_name", m.purchase_user); parameters.Add("buyer_name", m.purchase_user);
} }
sql += " order by t1.quantity_final_advise desc ";
if (m.isSum)
{
total = 0;
}
else
{
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters); total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters);
var obj = _connection.Query<dc_auto_purchase_advise_detailed_dto>(sql + " limit " + offset + "," + limit, parameters); //设置默认排序字段
if (string.IsNullOrWhiteSpace(sort)) sort = "t1.quantity_final_advise";
if (!string.IsNullOrEmpty(sort))
{
sql += " order by " + sort;
if (!string.IsNullOrEmpty(order))
{
sql += " " + order;
}
else
{
sql += " asc";
}
}
sql += " limit " + offset + "," + limit;
}
var obj = _connection.Query<dc_auto_purchase_advise_detailed_dto>(sql, parameters, buffered: false, commandTimeout: 0);
return obj.AsList(); return obj.AsList();
} }
catch (Exception) catch (Exception ex)
{ {
return list; return list;
} }
......
...@@ -156,6 +156,20 @@ namespace AutoTurnOver.Models ...@@ -156,6 +156,20 @@ namespace AutoTurnOver.Models
public string create_time_str { get { return create_time.ToString("yyyy-MM-dd"); } } public string create_time_str { get { return create_time.ToString("yyyy-MM-dd"); } }
public decimal forecast_turnoverday_sales { get; set; }
public decimal quantity_out_stock { get; set; }
public decimal quantity_transfer { get; set; }
public decimal quantity_purchase { get; set; }
public decimal quantity_inventory { get; set; }
public decimal quantity_final_advise_price { get; set; }
public string suppliers_name { get; set; }
} }
......
...@@ -86,9 +86,9 @@ namespace AutoTurnOver.Services ...@@ -86,9 +86,9 @@ namespace AutoTurnOver.Services
/// <param name="limit"></param> /// <param name="limit"></param>
/// <param name="total"></param> /// <param name="total"></param>
/// <returns></returns> /// <returns></returns>
public static List<dc_auto_purchase_advise_detailed_dto> DetailList(dc_auto_purchase_advise_detailed_search_dto m, int offset, int limit, ref int total) public static List<dc_auto_purchase_advise_detailed_dto> DetailList(dc_auto_purchase_advise_detailed_search_dto m, int offset, int limit, ref int total, string order = "", string sort = "")
{ {
return purchase_advise.DetailList(m, offset, limit, ref total); return purchase_advise.DetailList(m, offset, limit, ref total, order,sort);
} }
/// <summary> /// <summary>
......
...@@ -75,7 +75,7 @@ namespace AutoTurnOver.Services ...@@ -75,7 +75,7 @@ namespace AutoTurnOver.Services
} }
else else
{ {
delivery_days += (int)Math.Ceiling((itemArrivalList.Min(s => s.update_time) - tempPurchase.confirm_time).Value.TotalDays / 24); delivery_days += (int)Math.Ceiling((itemArrivalList.Min(s => s.update_time) - tempPurchase.confirm_time).Value.TotalHours / 24);
} }
} }
......
...@@ -60,7 +60,7 @@ namespace AutoTurnOver.Controllers ...@@ -60,7 +60,7 @@ namespace AutoTurnOver.Controllers
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public string DetailList(int limit, int offset, int main_id, string sort, string sku, string warehousecode, public string DetailList(int limit, int offset, int main_id, string sort, string sku, string warehousecode,
DateTime? end_date, DateTime? start_date, string warehousetype, int? warehousearea, DateTime? end_date, DateTime? start_date, string warehousetype, int? warehousearea, string order,
bool? ispush = null, int? type = null, string supplier_name = null, string purchase_user = null, string product_inner_code = null) bool? ispush = null, int? type = null, string supplier_name = null, string purchase_user = null, string product_inner_code = null)
{ {
var m = new dc_auto_purchase_advise_detailed_search_dto var m = new dc_auto_purchase_advise_detailed_search_dto
...@@ -80,7 +80,7 @@ namespace AutoTurnOver.Controllers ...@@ -80,7 +80,7 @@ namespace AutoTurnOver.Controllers
}; };
var total = 0; var total = 0;
var list = PurchaseAdviseServices.DetailList(m, offset, limit, ref total); var list = PurchaseAdviseServices.DetailList(m, offset, limit, ref total, order,sort);
return new return new
{ {
...@@ -100,9 +100,10 @@ namespace AutoTurnOver.Controllers ...@@ -100,9 +100,10 @@ namespace AutoTurnOver.Controllers
/// <param name="start_date"></param> /// <param name="start_date"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public string DetailListSumFooter(int limit, int offset, int main_id, string sort, string sku, string warehousecode, public JsonResult DetailListSumFooter(int limit, int offset, int main_id, string sort, string sku, string warehousecode,
DateTime? end_date, DateTime? start_date, string warehousetype, int? warehousearea, DateTime? end_date, DateTime? start_date, string warehousetype, int? warehousearea,
bool? ispush = null, int? type = null, string supplier_name = null, string purchase_user = null, string product_inner_code = null) bool? ispush = null, int? type = null, string supplier_name = null, string purchase_user = null, string product_inner_code = null
)
{ {
var m = new dc_auto_purchase_advise_detailed_search_dto var m = new dc_auto_purchase_advise_detailed_search_dto
{ {
...@@ -124,7 +125,7 @@ namespace AutoTurnOver.Controllers ...@@ -124,7 +125,7 @@ namespace AutoTurnOver.Controllers
var total = 0; var total = 0;
var list = PurchaseAdviseServices.DetailList(m, offset, limit, ref total); var list = PurchaseAdviseServices.DetailList(m, offset, limit, ref total);
return (list == null || list.Count <= 0 ? new dc_auto_purchase_advise_detailed_dto() : list[0]).ToJson(true); return new JsonResult(list == null || list.Count <= 0 ? new dc_auto_purchase_advise_detailed_dto() : list[0]);
} }
/// <summary> /// <summary>
......
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