@@ -78,67 +78,72 @@ delete from base_inventory_summary
<insertid="SetCabinetInventory">
INSERT INTO base_inventory_summary (id,org_id_int,org_name,type_id, type_name,size_id,size_name,location_id,location_name,number,price, stock_number, outbound_number,destruction_number,location_type,create_time,update_time)
INSERT INTO base_inventory_summary (id,org_id_int,org_name,type_id, type_name,size_id,size_name,location_id,location_name,number,unit_price,price,stock_number, outbound_number,destruction_number,expire_number,location_type,create_time,update_time)
select
MAX(t.id) as id,t.orgId,t.orgName,t.type_id,t.typeName,t.size_id,t.sizeName,t.locationId,t.locationName,sum(t.number) as number,sum(t.price)as price,sum(t.stockNumber)as stockNumber,sum(t.outboundNumber)as outboundNumber,sum(t.destructionNumber)as destructionNumber,t.location_type,NOW(),NOW()
MAX(t.id) as id,t.orgId,t.orgName,t.type_id,t.typeName,t.size_id,t.sizeName,t.locationId,t.locationName,sum(t.number) as number,t.unitPrice,sum(t.price)as price,sum(t.stockNumber)as stockNumber,sum(t.outboundNumber)as outboundNumber,sum(t.destructionNumber)as destructionNumber,sum(t.expireNumber)as expireNumber,t.location_type,NOW(),NOW()
FROM
(SELECT
UUID() as id,
bi.org_id_int as orgId,
po.org_name as orgName,
bcb.cabinet_id as locationId,
bi.location_id as locationBoxId,
bc.name as locationName,
bi.type_id,
t.name as typeName,
bi.size_id,
s.name as sizeName,
count(*) as number,
sum(bi.price) as price,
SUM(CASE WHEN location_state = 'in' THEN 1 ELSE 0 END) AS stockNumber,
count(*) - SUM(CASE WHEN location_state = 'in' THEN 1 ELSE 0 END) - sum(case when bi.state = 'destory' then 1 else 0 end) AS outboundNumber,
sum(case when bi.state = 'destory' then 1 else 0 end) as destructionNumber,
bi.location_type
FROM base_inventory bi
join base_cabinet_box bcb on bi.location_id = bcb.id
join base_cabinet bc on bcb.cabinet_id = bc.id
join base_equipment_type t on t.id = bi.type_id
join base_equipment_size s on s.id = bi.size_id
join pub_org po on bi.org_id_int = po.org_id
WHERE location_type = 1
GROUP BY location_id, type_id,size_id,bi.org_id_int ) as t
GROUP BY t.locationId,t.type_id,t.size_id,t.orgId
(SELECT
UUID() as id,
bi.org_id_int as orgId,
po.org_name as orgName,
bcb.cabinet_id as locationId,
bi.location_id as locationBoxId,
bc.name as locationName,
bi.type_id,
t.name as typeName,
bi.size_id,
s.name as sizeName,
count(*) as number,
Max(bi.price) as unitPrice,
sum(bi.price) as price,
SUM(CASE WHEN location_state = 'in' THEN 1 ELSE 0 END) AS stockNumber,
count(*) - SUM(CASE WHEN location_state = 'in' THEN 1 ELSE 0 END) AS outboundNumber,
sum(case when bi.state = 'destory' then 1 else 0 end) as destructionNumber,
sum(case when bi.warranty_period=0 then 0 when DATE_ADD(bi.production_date,INTERVAL bi.warranty_period MONTH) < NOW() then 1 else 0 end )as expireNumber,
bi.location_type
FROM base_inventory bi
join base_cabinet_box bcb on bi.location_id = bcb.id
join base_cabinet bc on bcb.cabinet_id = bc.id
join base_equipment_type t on t.id = bi.type_id
join base_equipment_size s on s.id = bi.size_id
join pub_org po on bi.org_id_int = po.org_id
WHERE location_type = 1
GROUP BY location_id, type_id,size_id,bi.org_id_int,bi.price ) as t
GROUP BY t.locationId,t.type_id,t.size_id,t.orgId,t.unitPrice
</insert>
<insertid="SetWarehouseInventory">
INSERT INTO base_inventory_summary (id,org_id_int,org_name,type_id, type_name,size_id,size_name,location_id,location_name,number,price, stock_number, outbound_number,destruction_number,location_type,create_time,update_time)
INSERT INTO base_inventory_summary (id,org_id_int,org_name,location_id,location_name,type_id, type_name,size_id,size_name,number,unit_price,price, stock_number, outbound_number,destruction_number,expire_number,location_type,create_time,update_time)
select
MAX(t.id) as id,t.orgId,t.orgName,t.type_id,t.typeName,t.size_id,t.sizeName,t.locationId,MAX(t.locationName),sum(t.number) as number,sum(t.price)as price,sum(t.stockNumber)as stockNumber,sum(t.outboundNumber)as outboundNumber,sum(t.destructionNumber)as destructionNumber,t.location_type,NOW(),NOW()
MAX(t.id) as id,t.orgId,t.orgName,t.locationId,MAX(t.locationName),t.type_id,t.typeName,t.size_id,t.sizeName,sum(t.number) as number,t.unitPrice,sum(t.price)as price,sum(t.stockNumber)as stockNumber,sum(t.outboundNumber)as outboundNumber,sum(t.destructionNumber)as destructionNumber,sum(t.destructionNumber) as expireNumber,t.location_type,NOW(),NOW()
FROM
(SELECT
UUID() as id,
bi.org_id_int as orgId,
po.org_name as orgName,
MAX(bi.location_id) as locationId,
MAX(bw.name) as locationName,
bi.type_id,
t.name as typeName,
bi.size_id,
s.name as sizeName,
count(*) as number,
sum(bi.price) as price,
SUM(CASE WHEN location_state = 'in' THEN 1 ELSE 0 END) AS stockNumber,
count(*) - SUM(CASE WHEN location_state = 'in' THEN 1 ELSE 0 END)- sum(case when bi.state = 'destory' then 1 else 0 end) AS outboundNumber,
sum(case when bi.state = 'destory' then 1 else 0 end) as destructionNumber,
bi.location_type
FROM base_inventory bi
join base_warehouse bw on bi.location_id = bw.id
join base_equipment_type t on t.id = bi.type_id
join base_equipment_size s on s.id = bi.size_id
join pub_org po on bi.org_id_int = po.org_id
WHERE location_type = 0
GROUP BY type_id,size_id,bi.org_id_int,location_id) as t
GROUP BY t.locationId,t.type_id,t.size_id,t.orgId
(SELECT
UUID() as id,
bi.org_id_int as orgId,
po.org_name as orgName,
MAX(bi.location_id) as locationId,
MAX(bw.name) as locationName,
bi.type_id,
t.name as typeName,
bi.size_id,
s.name as sizeName,
count(*) as number,
Max(bi.price) as unitPrice,
sum(bi.price) as price,
SUM(CASE WHEN location_state = 'in' THEN 1 ELSE 0 END) AS stockNumber,
count(*) - SUM(CASE WHEN location_state = 'in' THEN 1 ELSE 0 END) AS outboundNumber,
sum(case when bi.state = 'destory' then 1 else 0 end) as destructionNumber,
sum(case when bi.warranty_period=0 then 0 when DATE_ADD(bi.production_date,INTERVAL bi.warranty_period MONTH) < NOW() then 1
else 0 end )as expireNumber,
bi.location_type
FROM base_inventory bi
join base_warehouse bw on bi.location_id = bw.id
join base_equipment_type t on t.id = bi.type_id
join base_equipment_size s on s.id = bi.size_id
join pub_org po on bi.org_id_int = po.org_id
WHERE location_type = 0
GROUP BY type_id,size_id,bi.org_id_int,location_id,bi.price) as t
GROUP BY t.locationId,t.type_id,t.size_id,t.orgId,t.unitPrice