SELECT
a.citem_code,
min(A.id) id,
A.site,
min(A.warehouse_id) AS warehouse_id,
A.part_no,min(A.batch_no) as batch_no,
min(A.location_id) AS location_id,
sum(isnull( A.in_qty , 0 )) AS inQty,
sum(isnull( A.out_qty , 0 )) AS outQty,
sum(isnull( A.qty_on_hand , 0 )) AS qtyOnHand,
B.part_description,
min(B.spec) AS spec,
B.min_stock,
B.max_stock,
min(A.partner_id) AS partner_id,
min(A.first_in_date) AS first_in_date,
B.average_price,
B.umid,
(sum(isnull( A.qty_on_hand , 0 )) * B.average_price) as totalCost,
dbo.get_bu_desc( A.site,A.citem_code) buDesc
from inventory_stock A
left join part_spare B on A.site = B.site and A.part_no = B.part_no and a.citem_code=b.bu_no
left join accessBu D on A.site=D.site and A.citem_code=d.bu_no and D.username=#{query.username}
A.site = #{query.site} and D.username is not null
and A.batch_no is not null and b.part_no is not null
and B.active = #{query.active}
and a.citem_code = #{query.buNo}
and A.batch_no like '%'+#{query.batchNo}+'%'
and A.warehouse_id like '%'+#{query.warehouseId}+'%'
and A.location_id like '%'+#{query.locationId}+'%'
and A.part_no like '%'+#{query.partNo}+'%'
and B.part_description like '%'+#{query.partDescription}+'%'
and B.spec like '%'+#{query.spec}+'%'
and A.first_in_date >= #{query.startFirstInDate}
and A.first_in_date #{query.endFirstInDate}
and A.qty_on_hand >= #{query.startQtyOnHand}
and A.qty_on_hand #{query.endQtyOnHand}
and A.qty_on_hand ]]> B.min_stock
and A.qty_on_hand B.min_stock
GROUP BY
A.site, A.part_no, B.part_description, A.batch_no, b.min_stock, b.max_stock, B.average_price, B.umid,a.citem_code
A.site, A.part_no, B.part_description, b.min_stock, b.max_stock, B.average_price, B.umid,a.citem_code
update inventory_stock set qty_of_po = isnull(qty_of_po,0) + #{qtyOfPo} where id = #{id}
update inventory_stock set qty_on_hand = isnull(qty_on_hand,0) + #{qtyOfPo}, qty_of_po = isnull(qty_of_po,0) - #{qtyOfPo} where id = #{id}
update inventory_stock set qty_of_po = isnull(qty_of_po,0) - #{qtyOfPo} where id = #{id}
SELECT
A.citem_code,
min(A.id) as id,
A.site,
min(A.warehouse_id) AS warehouse_id,
A.part_no,min(A.batch_no) as batch_no,
min(A.location_id) AS location_id,
sum(isnull( A.in_qty , 0 )) AS inQty,
sum(isnull( A.out_qty , 0 )) AS outQty,
sum(isnull( A.qty_on_hand , 0 )) AS qtyOnHand,
B.part_description,
min(B.spec) AS spec,
B.min_stock,
B.max_stock,
min(A.partner_id) AS partner_id,
min(A.first_in_date) AS first_in_date,
B.average_price,
B.umid,
sum(isnull(A.qty_of_po,0)) as qty_of_po,
(sum(isnull( A.qty_on_hand , 0 )) * B.average_price) as totalCost,
dbo.get_bu_desc( A.site,A.citem_code) buDesc
from inventory_stock A
left join part_spare B on A.site = B.site and A.part_no = B.part_no and a.citem_code=b.bu_no
left join accessBu D on A.site=D.site and A.citem_code=d.bu_no and D.username=#{query.username}
A.site = #{query.site} and D.username is not null
and A.batch_no is not null and b.part_no is not null
and B.active = #{query.active}
and a.citem_code = #{query.buNo}
and A.batch_no like '%'+#{query.batchNo}+'%'
and A.warehouse_id like '%'+#{query.warehouseId}+'%'
and A.location_id like '%'+#{query.locationId}+'%'
and A.part_no like '%'+#{query.partNo}+'%'
and B.part_description like '%'+#{query.partDescription}+'%'
and B.spec like '%'+#{query.spec}+'%'
and A.first_in_date >= #{query.startFirstInDate}
and A.first_in_date #{query.endFirstInDate}
and A.qty_on_hand >= #{query.startQtyOnHand}
and A.qty_on_hand #{query.endQtyOnHand}
and A.qty_on_hand ]]> B.min_stock
GROUP BY
A.site, A.part_no, B.part_description, A.batch_no, b.min_stock, b.max_stock, B.average_price, B.umid,a.citem_code
A.site, A.part_no, B.part_description, b.min_stock, b.max_stock, B.average_price, B.umid,a.citem_code
having sum(A.qty_on_hand) B.min_stock
having sum(A.qty_on_hand) + sum(isnull(A.qty_of_po,0.0)) B.min_stock