Commit b0e36c8c by 泽锋 李

补货建议先读后写

parent 310a7735
...@@ -159,7 +159,7 @@ order by t1.start_time desc ...@@ -159,7 +159,7 @@ order by t1.start_time desc
/// 张莹霞1的要减去缺货数才下单 /// 张莹霞1的要减去缺货数才下单
/// </summary> /// </summary>
/// <param name="mainID"></param> /// <param name="mainID"></param>
public static void ImportDetailed(int mainID, DateTime date) public static void ImportDetailed_bak(int mainID, DateTime date)
{ {
//RedundancyDeduction("QYBLZZ", "GZBLWH"); //RedundancyDeduction("QYBLZZ", "GZBLWH");
...@@ -317,6 +317,159 @@ and t1.quantity_init_advise>=0 and ( t3.buyer_name in ('张莹霞1') and t1.ware ...@@ -317,6 +317,159 @@ and t1.quantity_init_advise>=0 and ( t3.buyer_name in ('张莹霞1') and t1.ware
} }
public static void ImportDetailed(int mainID, DateTime date)
{
//RedundancyDeduction("QYBLZZ", "GZBLWH");
//RedundancyDeduction("GZBLWH", "QYBLZZ");
// 生成采购建议 (只补缺货的不管)
var datas1 = _connection.Query<dc_auto_purchase_advise_detailed>(@"select * from (
select
t1.bailun_sku,
t1.warehouse_code as 'source_warehouse_code',
(case when t8.group_id=2 then 'GZBLWH' else t1.warehouse_code end ) as 'warehouse_code',
t1.quantity_init_advise as 'quantity_init_advise', -- 原始采购建议数量 new
(
case
when t6.buyer_name in ('张莹霞') then ( case when t1.quantity_init_advise>0 then greatest(t1.quantity_init_advise,t6.moq) else 0 end) -- (张莹霞的sku取moq下单)
when t7.sum_quantity_init_advise>=t7.max_moq then t1.quantity_init_advise-- 如果商品的下单总量达到moq了,就直接下单
when t7.sku_count=1 then t7.max_moq -- 如果该商品只有一个sku需要下单,则直接下一个moq
else
FLOOR(
GREATEST(t1.quantity_init_advise,0) +
(
(t7.max_moq-GREATEST(t7.sum_quantity_init_advise,0))
*
(t1.history_fourteenday_sales / t7.sum_history_fourteenday_sales )
)
)-- 如果以上条件都不满足,则计算该sku需要摊分多少moq余下的任务
end
) as 'quantity_final_advise', -- 计算moq之后的数量 new
t7.product_inner_code as 'product_inner_code', -- 内部商品编码 new
t7.sum_quantity_init_advise as 'goods_quantity_init_advise', -- 商品本次的建议下单数量 new
t7.max_moq as 'goods_moq', -- 商品的moq new
t7.sku_codes as 'good_sku_codes', -- 商品涉及的下单所有sku new
t7.sum_history_fourteenday_sales as 'goods_history_fourteenday_sales', -- 商品的最近14日总日均销量
t1.history_fourteenday_sales as 'history_fourteenday_sales', -- sku的最近14日日均
0 as 'quantity_actual', -- 真实下单数量
@main_id as 'main_id',
t2.forecast_formula as 'forecast_formula',
t2.fit_forecast_formula as 'fit_forecast_formula',
t1.turnover_days,
t1.supplier_delivery,
t1.inspection_delivery,
t1.transfer_delivery,
t1.sales_upper_limit,
0 as 'ispush',
(case when t1.quantity_out_stock>0 then 2 when t1.`status` then 1 else 3 end) as 'type',
t6.suppliers_id,
t1.quantity_out_stock,
(
case when t6.buyer_name in ('张莹霞','张莹霞1') and t1.warehouse_code='GZBLWH' then 1
else 0
end
) as 'purchase_type_jit',
t1.auto_replace_logistics_task_id,
tr_task.logistics_code,
tr_task.transport_type as 'task_transport_type'
from dc_auto_turnover as t1
left join dc_auto_sales as t2 on t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code
left join dc_auto_config_sku_warehouse as t5 on t1.bailun_sku = t5.bailun_sku and t1.warehouse_code = t5.warehouse_code
left join dc_base_sku as t6 on t1.bailun_sku = t6.bailun_sku
left join view_goods_moq as t7 on t6.product_inner_code = t7.product_inner_code and t1.warehouse_code = t7.warehouse_code and t6.suppliers_id = t7.suppliers_id
left join dc_auto_jit_tag as t8 on t1.tag_id = t8.id
left join dc_auto_replace_logistics_task as tr_task on t1.auto_replace_logistics_task_id = tr_task.id
where t1.gmt_modified>=@btime
and t6.`status`=2 and (t1.history_fourteenday_sales>0 or t1.quantity_out_stock>0 ) and ( t5.`status`=0 or t5.`status` is null ) and t7.sum_quantity_init_advise>0
and (
( ( t6.buyer_name not in ('赵美聪','甄杰靖','张莹霞','张莹霞1','冯兆欣') or t1.warehouse_code not in ('GZBLWH','GZBLYS') ) and t1.warehouse_code!='BLGZ03' )
or
( t1.tag_id > 0 and t8.is_eliminate = 0 )
) -- 非jit 或者 jit 备货
) as t1 where t1.quantity_final_advise>0
", new { main_id = mainID, btime = date }, commandTimeout: 0).ToList();
foreach (var item in datas1)
{
_connection.Insert(item);
}
// 凑单sku(初始建议数没有) 如果下单数只有一个,改为2 ( 只补缺货的不管 )
_connection.Execute(@" update dc_auto_purchase_advise_detailed as t1,
dc_base_sku as t2
set t1.quantity_final_advise=2
where t2.`status`=2 and t1.bailun_sku = t2.bailun_sku and t1.quantity_final_advise=1 and t1.quantity_init_advise<=0 and ( t2.buyer_name not in ('赵美聪','甄杰靖','张莹霞','张莹霞1') or t1.warehouse_code!='GZBLWH' ) and t1.main_id=@main_id ", new { main_id = mainID }, commandTimeout: 0);
// 初始建议数为1,,系统建议数为1时 改为3 ( 只补缺货的不管 )
_connection.Execute(@" update dc_auto_purchase_advise_detailed as t1,
dc_base_sku as t2
set quantity_final_advise=3
where t2.`status`=2 and t1.bailun_sku = t2.bailun_sku and quantity_final_advise=1 and quantity_init_advise=1 and ( t2.buyer_name not in ('赵美聪','甄杰靖','张莹霞','张莹霞1') or t1.warehouse_code!='GZBLWH' ) and main_id=@main_id ", new { main_id = mainID }, commandTimeout: 0);
//张莹霞1 and 广州01 去掉缺货数
_connection.Execute(@" update dc_auto_purchase_advise_detailed as t1,
dc_mid_transit as t2 ,
dc_base_sku as t3
set t1.quantity_final_advise=GREATEST(0,t1.quantity_final_advise-t2.quantity_out_stock)
where t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code and t1.bailun_sku=t3.bailun_sku
and t1.quantity_init_advise>=0 and ( t3.buyer_name in ('张莹霞1') and t1.warehouse_code='GZBLWH' ) and t1.main_id=@main_id ", new { main_id = mainID }, commandTimeout: 0);
// 调整因为舍弃小数导致的moq不足
var datas = _connection.Query<dc_auto_purchase_advise_detailed>(" select * from dc_auto_purchase_advise_detailed where main_id=@main_id ", new { main_id = mainID }, commandTimeout: 0).AsList();
if (datas != null && datas.Count > 0)
{
foreach (var itemGoods in datas.GroupBy(s => new { s.suppliers_id, s.product_inner_code, s.warehouse_code }))
{
// 判断总建议采购数是否达到了moq
var difference = itemGoods.Max(s => s.goods_moq) - itemGoods.Sum(s => s.quantity_final_advise);
if (difference > 0)
{
// 把最大的那条记录找出来,加给他
var max_data = itemGoods.OrderByDescending(s => s.history_fourteenday_sales).FirstOrDefault();
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=@quantity_final_advise where id=@id ", new
{
quantity_final_advise = max_data.quantity_final_advise + difference,
id = max_data.id
});
}
else if (difference < 0)
{
// 由于上面的补单规则,会导致超出moq . 有超出的部分,把补单的(初始建议数为负数)按销量排序,逐个消减
var abatement = 0 - difference;
foreach (var item in itemGoods.Where(s => s.quantity_init_advise < 0).OrderBy(s => s.goods_history_fourteenday_sales))
{
if (abatement >= item.quantity_final_advise)
{
_connection.Execute(" delete from dc_auto_purchase_advise_detailed where id=@id ", new { id = item.id });
abatement -= item.quantity_final_advise;
}
else
{
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=@quantity_final_advise where id=@id ", new { id = item.id, quantity_final_advise = item.quantity_final_advise - abatement });
abatement = 0;
}
if (abatement <= 0)
{
break;
}
}
}
}
}
//ImportShoujiShortageDetailed(mainID);
}
/// <summary> /// <summary>
/// 把流水号装换成4位数字符串形式 /// 把流水号装换成4位数字符串形式
/// </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