@ -130,31 +130,42 @@ from (((((`wms_storage_log` `lg`
where ( ( ` st ` . ` deleted ` = 0 ) and ( ` mat ` . ` deleted ` = 0 ) and ( ` wh ` . ` deleted ` = 0 ) and ( ` rg ` . ` deleted ` = 0 ) and ( ` pn ` . ` deleted ` = 0 ) ) ;
CREATE OR REPLACE VIEW v_storage_material_now AS
select ` t ` . ` deleted ` AS ` deleted ` , ` t ` . ` id ` AS ` id ` , ` t ` . ` creator ` AS ` creator ` , ` t ` . ` create_time` AS ` create_time ` , ` t ` . ` updater ` AS ` updater ` , ` t ` . ` update_time ` AS ` update_time ` , ` t ` . ` tenant_id ` AS ` tenant_id ` ,
` t ` . ` mat_code` AS ` mat_code ` , ` t ` . ` mat_name ` AS ` mat_name ` , ` t ` . ` mat_type ` AS ` mat_type ` , ` t ` . ` mat_spec ` AS ` mat_spec ` , ` t ` . ` mat_unit ` AS ` mat_unit ` , ` t ` . ` mat_brand ` AS ` mat_brand ` ,
` t ` . ` wh_id` AS ` wh_id ` , ` t ` . ` wh_name ` AS ` wh_name ` , ` t ` . ` rg_id ` AS ` rg_id ` , ` t ` . ` rg_name ` AS ` rg_name ` , ` t ` . ` pn_id ` AS ` pn_id ` , ` t ` . ` pn_name ` AS ` pn_name ` , ` t ` . ` lot_no ` AS ` lot_no ` , ` t ` . ` short_name ` AS ` short_name ` ,
sum ( ` t ` . ` storage_ok_qty ` ) AS ` storage_ok_qty `
select ` t ` . ` deleted ` AS ` deleted ` , ` t ` . ` id ` AS ` id ` , ` t ` . ` creator ` AS ` creator ` , ` t ` . ` updater` AS ` updater ` , cast ( ' 2000-01-01 00:00 ' as date ) AS ` create_time ` , cast ( ' 2000-01-01 00:00 ' as date ) AS ` update_time ` ,
` t ` . ` tenant_id` AS ` tenant_id ` , ` t ` . ` mat_code` AS ` mat_code ` , ` t ` . ` mat_name ` AS ` mat_name ` ,
` t ` . ` mat_type` AS ` mat_type ` , ` t ` . ` mat_spec ` AS ` mat_spec ` , ` t ` . ` mat_unit ` AS ` mat_unit ` , ` t ` . ` mat_brand ` AS ` mat_brand ` , ` t ` . ` wh_id` AS ` wh_id ` , ` t ` . ` wh_name ` AS ` wh_name ` , ` t ` . ` rg_id ` AS ` rg_id ` ,
` t ` . ` rg_name ` AS ` rg_name ` , ` t ` . ` pn_id ` AS ` pn_id ` , ` t ` . ` pn_name ` AS ` pn_name ` , ' ' AS ` lot_no ` , ` t ` . ` short_name ` AS ` short_name ` , sum ( ` t ` . ` storage_ok_qty ` ) AS ` storage_ok_qty `
from (
select 0 AS ` deleted ` , ` mat ` . ` id ` AS ` id ` , ` mat ` . ` creator ` AS ` creator ` , ` mat ` . ` create_time` AS ` create_time ` , ` mat ` . ` updater ` AS ` updater ` , ` mat ` . ` update_time ` AS ` update_time ` , ` mat ` . ` tenant_id ` AS ` tenant_id ` ,
` mat ` . ` code ` AS ` mat_code ` , ` mat ` . ` name ` AS ` mat_name ` , ( select ` mes - heli ` . ` system_dict_data ` . ` label `
from ` mes - heli ` . ` system_dict_data `
where ( ( ` mes - heli ` . ` system_dict_data ` . ` dict_type ` = ' heli_material_type ' ) and ( ` mes - heli ` . ` system_dict_data ` . ` value ` = ` mat ` . ` material_type ` ) ) ) AS ` mat_type ` ,
( case when ( isnull ( ` mat ` . ` short_name ` ) = TRUE ) then ' ' else ` mat ` . ` short_name` end ) AS ` short_name ` , ( case when ( isnull ( ` mat ` . ` spec ` ) = TRUE ) then ' ' else ` mat ` . ` spec ` end ) AS ` mat_spec ` ,
( case when ( isnull ( ` mat ` . ` brand ` ) = TRUE ) then ' ' else ` mat ` . ` brand ` end ) AS ` mat_brand ` , ( select ` mes - heli ` . ` system_dict_data ` . ` label ` from ` mes - heli ` . ` system_dict_data ` where ( ( ` mes - heli ` . ` system_dict_data ` . ` dict_type ` = ' heli_material_unit ' ) and ( ` mes - heli ` . ` system_dict_data ` . ` value ` = ` mat ` . ` unit ` ) ) ) AS ` mat_unit ` ,
select 0 AS ` deleted ` , ` mat ` . ` id ` AS ` id ` , ` mat ` . ` creator ` AS ` creator ` , ` mat ` . ` updater` AS ` updater ` , ` mat ` . ` tenant_id ` AS ` tenant_id ` , ` mat ` . ` code ` AS ` mat_code ` , ` mat ` . ` name ` AS ` mat_name ` ,
( select ` mes - heli ` . ` system_dict_data ` . ` label ` from ` mes - heli ` . ` system_dict_data ` where ( ( ` mes - heli ` . ` system_dict_data ` . ` dict_type ` = ' heli_material_type ' ) and ( ` mes - heli ` . ` system_dict_data ` . ` value ` = ` mat ` . ` material_type ` ) ) ) AS ` mat_type ` ,
( case when ( isnull ( ` mat ` . ` short_name ` ) = TRUE ) then ' ' else ` mat ` . ` short_name ` end ) AS ` short_name ` ,
( case when ( isnull ( ` mat ` . ` spec ` ) = TRUE ) then ' ' else ` mat ` . ` spec ` end ) AS ` mat_spec ` ,
( case when ( isnull ( ` mat ` . ` brand ` ) = TRUE ) then ' ' else ` mat ` . ` brand` end ) AS ` mat_brand ` ,
( select ` mes - heli ` . ` system_dict_data ` . ` label ` from ` mes - heli ` . ` system_dict_data ` where ( ( ` mes - heli ` . ` system_dict_data ` . ` dict_type ` = ' heli_material_unit ' ) and ( ` mes - heli ` . ` system_dict_data ` . ` value ` = ` mat ` . ` unit ` ) ) ) AS ` mat_unit ` ,
` wh ` . ` id ` AS ` wh_id ` , ` wh ` . ` wh_name ` AS ` wh_name ` , ` rg ` . ` id ` AS ` rg_id ` , ` rg ` . ` rg_name ` AS ` rg_name ` , ` pn ` . ` id ` AS ` pn_id ` , ` pn ` . ` pn_name ` AS ` pn_name ` ,
( case when ( isnull ( ` lg ` . ` lot_no ` ) = 1 ) then ' ' else ` lg ` . ` lot_no ` end ) AS ` lot_no ` , ( case when ( ( ` st ` . ` stock_type ` = 1 ) and ( ` lg ` . ` status ` = 2 ) ) then ` lg ` . ` storage_ok_qty ` when ( ( ` st ` . ` stock_type ` = 1 ) and ( ` lg ` . ` status ` = 3 ) ) then ( - ( 1 ) * ` lg ` . ` storage_ok_qty ` ) when ( ( ` st ` . ` stock_type ` = 2 ) and ( ` lg ` . ` status ` = 2 ) ) then ( - ( 1 ) * ` lg ` . ` storage_ok_qty ` ) when ( ( ` st ` . ` stock_type ` = 2 ) and ( ` lg ` . ` status ` = 3 ) ) then ` lg ` . ` storage_ok_qty ` else ` lg ` . ` storage_ok_qty ` end ) AS ` storage_ok_qty `
from ( ( ( ( ( ` mes - heli ` . ` wms_storage_log ` ` lg ` left join ` mes - heli ` . ` wms_storage ` ` st ` on ( ( ` lg ` . ` stock_id ` = ` st ` . ` id ` ) ) ) left join ` mes - heli ` . ` base_material ` ` mat ` on ( ( ` lg ` . ` mat_id ` = ` mat ` . ` id ` ) ) ) left join ` mes - heli ` . ` wms_wh ` ` wh ` on ( ( ` lg ` . ` wh_id ` = ` wh ` . ` id ` ) ) ) left join ` mes - heli ` . ` wms_rg ` ` rg ` on ( ( ` lg ` . ` rg_id ` = ` rg ` . ` id ` ) ) ) left join ` mes - heli ` . ` wms_pn ` ` pn ` on ( ( ` lg ` . ` pn_id ` = ` pn ` . ` id ` ) ) ) where ( ( ` st ` . ` deleted ` = 0 ) and ( ` mat ` . ` deleted ` = 0 ) and ( ` wh ` . ` deleted ` = 0 ) and ( ` rg ` . ` deleted ` = 0 ) and ( ` pn ` . ` deleted ` = 0 ) ) ) ` t `
group by ` t ` . ` deleted ` , ` t ` . ` id ` , ` t ` . ` creator ` , ` t ` . ` create_time ` , ` t ` . ` updater ` , ` t ` . ` update_time ` , ` t ` . ` tenant_id ` , ` t ` . ` mat_code ` , ` t ` . ` mat_name ` , ` t ` . ` mat_type ` , ` t ` . ` mat_spec ` , ` t ` . ` mat_unit ` , ` t ` . ` mat_brand ` , ` t ` . ` wh_id ` , ` t ` . ` wh_name ` , ` t ` . ` rg_id ` , ` t ` . ` rg_name ` , ` t ` . ` pn_id ` , ` t ` . ` pn_name ` , ` t ` . ` lot_no ` , ` t ` . ` short_name ` ;
( case when ( isnull ( ` lg ` . ` lot_no ` ) = 1 ) then ' ' else ` lg ` . ` lot_no ` end ) AS ` lot_no ` ,
( case when ( ( ` st ` . ` stock_type ` = 1 ) and ( ` lg ` . ` status ` = 2 ) ) then ` lg ` . ` storage_ok_qty ` when ( ( ` st ` . ` stock_type ` = 1 ) and ( ` lg ` . ` status ` = 3 ) ) then ( - ( 1 ) * ` lg ` . ` storage_ok_qty ` ) when ( ( ` st ` . ` stock_type ` = 2 ) and ( ` lg ` . ` status ` = 2 ) ) then ( - ( 1 ) * ` lg ` . ` storage_ok_qty ` ) when ( ( ` st ` . ` stock_type ` = 2 ) and ( ` lg ` . ` status ` = 3 ) ) then ` lg ` . ` storage_ok_qty ` else ` lg ` . ` storage_ok_qty ` end ) AS ` storage_ok_qty `
from ( ( ( ( ( ` mes - heli ` . ` wms_storage_log ` ` lg `
left join ` mes - heli ` . ` wms_storage ` ` st ` on ( ( ` lg ` . ` stock_id ` = ` st ` . ` id ` ) ) )
left join ` mes - heli ` . ` base_material ` ` mat ` on ( ( ` lg ` . ` mat_id ` = ` mat ` . ` id ` ) ) )
left join ` mes - heli ` . ` wms_wh ` ` wh ` on ( ( ` lg ` . ` wh_id ` = ` wh ` . ` id ` ) ) )
left join ` mes - heli ` . ` wms_rg ` ` rg ` on ( ( ` lg ` . ` rg_id ` = ` rg ` . ` id ` ) ) )
left join ` mes - heli ` . ` wms_pn ` ` pn ` on ( ( ` lg ` . ` pn_id ` = ` pn ` . ` id ` ) ) )
where ( ( ` st ` . ` deleted ` = 0 ) and ( ` mat ` . ` deleted ` = 0 ) and ( ` wh ` . ` deleted ` = 0 ) and ( ` rg ` . ` deleted ` = 0 ) and ( ` pn ` . ` deleted ` = 0 ) ) ) ` t `
group by ` t ` . ` deleted ` , ` t ` . ` id ` , ` t ` . ` creator ` , ` t ` . ` updater ` , ` t ` . ` tenant_id ` , ` t ` . ` mat_code ` , ` t ` . ` mat_name ` , ` t ` . ` mat_type ` , ` t ` . ` mat_spec ` , ` t ` . ` mat_unit ` , ` t ` . ` mat_brand ` , ` t ` . ` wh_id ` , ` t ` . ` wh_name ` , ` t ` . ` rg_id ` , ` t ` . ` rg_name ` , ` t ` . ` pn_id ` , ` t ` . ` pn_name ` , ` t ` . ` short_name `
CREATE OR REPLACE VIEW v_storage_material_amount AS
select ` t ` . ` tenant_id ` AS ` tenant_id ` , ` t ` . ` mat_id ` AS ` mat_id ` , ` t ` . ` mat_name ` AS ` mat_name ` , ` t ` . ` mat_code ` AS ` mat_code ` , ` t ` . ` wh_id ` AS ` wh_id ` , ` t ` . ` rg_id ` AS ` rg_id ` , ` t ` . ` pn_id ` AS ` pn_id ` ,
` t ` . ` spec ` AS ` spec ` , ` t ` . ` unit ` AS ` unit ` , ` t ` . ` material_type ` AS ` material_type ` , ` t ` . ` lot_no ` AS ` lot_no ` , ' ' AS ` storage_ok_qty ` , sum ( ` t ` . ` storage_ok_qty ` ) AS ` mat_rest `
select ` t ` . ` deleted ` AS ` deleted ` , ` t ` . ` id ` AS ` mat_id ` , ` t ` . ` creator ` AS ` creator ` , ` t ` . ` updater ` AS ` updater ` , ` t ` . ` tenant_id ` AS ` tenant_id ` , ` t ` . ` mat_code ` AS ` mat_code ` , ` t ` . ` mat_name ` AS ` mat_name ` ,
` t ` . ` material_type ` AS ` material_type ` , ` t ` . ` spec ` AS ` spec ` , ` t ` . ` unit ` AS ` unit ` , ` t ` . ` wh_id ` AS ` wh_id ` , ` t ` . ` rg_id ` AS ` rg_id ` , ` t ` . ` pn_id ` AS ` pn_id ` , ` t ` . ` short_name ` AS ` short_name ` ,
0 AS ` storage_ok_qty ` , sum ( ` t ` . ` storage_ok_qty ` ) AS ` mat_rest `
from (
select ` st ` . ` stock_type ` AS ` stock_type ` , ` mat ` . ` tenant_id ` AS ` tenant_id ` , ` mat ` . ` mat_id ` AS ` mat_id ` , ` bm ` . ` code ` AS ` mat_code ` , ` bm ` . ` name ` AS ` mat_name ` , ` mat ` . ` wh_id ` AS ` wh_id ` , ` mat ` . ` rg_id ` AS ` rg_id ` , ` mat ` . ` pn_id ` AS ` pn_id ` , ` mat ` . ` lot_no ` AS ` lot_no ` , ` bm ` . ` spec ` AS ` spec ` , ` bm ` . ` unit ` AS ` unit ` , ` bm ` . ` material_type ` AS ` material_type ` ,
( case when ( ( ` st ` . ` status ` = 2 ) and ( ` st ` . ` stock_type ` = 1 ) ) then ` mat ` . ` storage_ok_qty ` when ( ( ` st ` . ` status ` = 3 ) and ( ` st ` . ` stock_type ` = 1 ) ) then ( - ( 1 ) * ` mat ` . ` storage_ok_qty ` ) when ( ( ` st ` . ` status ` = 2 ) and ( ` st ` . ` stock_type ` = 2 ) ) then ( - ( 1 ) * ` mat ` . ` storage_ok_qty ` ) when ( ( ` st ` . ` status ` = 3 ) and ( ` st ` . ` stock_type ` = 2 ) ) then ` mat ` . ` storage_ok_qty ` else 0 end ) AS ` storage_ok_qty `
from ( ( ` mes - heli ` . ` wms_storage_mat ` ` mat `
left join ` mes - heli ` . ` wms_storage ` ` st ` on ( ( ` mat ` . ` stock_id ` = ` st ` . ` id ` ) ) )
left join ` mes - heli ` . ` base_material ` ` bm ` on ( ( ` mat ` . ` mat_id ` = ` bm ` . ` id ` ) ) )
where ( ( ` mat ` . ` deleted ` = 0 ) and ( ` st ` . ` status ` < > 1 ) and ( ` st ` . ` deleted ` = 0 ) and ( ` bm ` . ` deleted ` = 0 ) and ( ` bm ` . ` status ` = 1 ) )
) ` t ` group by ` t ` . ` mat_id ` ;
select 0 AS ` deleted ` , ` mat ` . ` id ` AS ` id ` , ` mat ` . ` creator ` AS ` creator ` , ` mat ` . ` updater ` AS ` updater ` , ` mat ` . ` tenant_id ` AS ` tenant_id ` , ` mat ` . ` code ` AS ` mat_code ` , ` mat ` . ` name ` AS ` mat_name ` ,
` mat ` . ` material_type ` AS ` material_type ` , ( case when ( isnull ( ` mat ` . ` short_name ` ) = TRUE ) then ' ' else ` mat ` . ` short_name ` end ) AS ` short_name ` ,
` mat ` . ` spec ` AS ` spec ` , ` mat ` . ` unit ` AS ` unit ` , ` lg ` . ` wh_id ` AS ` wh_id ` , ` lg ` . ` rg_id ` AS ` rg_id ` , ` lg ` . ` pn_id ` AS ` pn_id ` ,
( case when ( isnull ( ` lg ` . ` lot_no ` ) = 1 ) then ' ' else ` lg ` . ` lot_no ` end ) AS ` lot_no ` ,
( case when ( ( ` st ` . ` stock_type ` = 1 ) and ( ` lg ` . ` status ` = 2 ) ) then ` lg ` . ` storage_ok_qty ` when ( ( ` st ` . ` stock_type ` = 1 ) and ( ` lg ` . ` status ` = 3 ) ) then ( - ( 1 ) * ` lg ` . ` storage_ok_qty ` ) when ( ( ` st ` . ` stock_type ` = 2 ) and ( ` lg ` . ` status ` = 2 ) ) then ( - ( 1 ) * ` lg ` . ` storage_ok_qty ` ) when ( ( ` st ` . ` stock_type ` = 2 ) and ( ` lg ` . ` status ` = 3 ) ) then ` lg ` . ` storage_ok_qty ` else ` lg ` . ` storage_ok_qty ` end ) AS ` storage_ok_qty `
from ( ( ` mes - heli ` . ` wms_storage_log ` ` lg `
left join ` mes - heli ` . ` wms_storage ` ` st ` on ( ( ` lg ` . ` stock_id ` = ` st ` . ` id ` ) ) )
left join ` mes - heli ` . ` base_material ` ` mat ` on ( ( ` lg ` . ` mat_id ` = ` mat ` . ` id ` ) ) )
where ( ( ` st ` . ` deleted ` = 0 ) and ( ` mat ` . ` deleted ` = 0 ) and ( ` lg ` . ` deleted ` = 0 ) )
) ` t `
group by ` t ` . ` deleted ` , ` t ` . ` id ` , ` t ` . ` creator ` , ` t ` . ` updater ` , ` t ` . ` tenant_id ` , ` t ` . ` mat_code ` , ` t ` . ` mat_name ` , ` t ` . ` material_type ` , ` t ` . ` spec ` , ` t ` . ` unit ` , ` t ` . ` wh_id ` , ` t ` . ` rg_id ` , ` t ` . ` pn_id ` , ` t ` . ` short_name ` ;