Rev 10407 | Rev 10689 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="in.shop2020.warehouse.persistence.ScanMapper"><resultMap type="scan" id="scanResult"><id property="id" column="id"/></resultMap><insert id="insert" parameterType="scan" useGeneratedKeys="true" keyProperty="id">INSERT INTO scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId, transferLotId, remarks)VALUES(#{inventoryItemId}, #{warehouseId}, #{type}, NOW(), #{quantity}, #{orderId}, #{transferLotId}, #{remarks})</insert><select id="get" parameterType="map" resultType="scan">SELECT *FROM scanNewWHERE inventoryItemId = #{inventoryItemId}<if test="scanType != null">AND type = #{scanType}</if>ORDER BY scannedAt</select><select id="getScansFromOrderId" parameterType="java.lang.Long" resultType="scan">SELECT *FROM scanNewWHERE orderId = #{orderId}ORDER BY scannedAt</select><select id="getScansForOrderAndItem" parameterType="map" resultType="scan">SELECT s.id as id, s.inventoryItemId as inventoryItemId, s.warehouseId as warehouseId, s.type as type,s.scannedAt as scannedAt, s.quantity as quantity, s.orderId as orderIdFROM scanNew sJOIN inventoryItem iON (s.inventoryItemId = i.id)WHERE i.itemId = #{itemId}AND s.orderId = #{orderId}ORDER BY scannedAt</select><select id="getPurchaseScans" parameterType="map" resultType="detailedPurchaseScan">SELECT p.purchaseOrder_id AS purchaseOrderId, 1000 * UNIX_TIMESTAMP(po.createdAt) AS poCreatedAt, s.name AS supplierName,GROUP_CONCAT(DISTINCT(p.invoiceNumber)) AS invoiceNumbers, GROUP_CONCAT(DISTINCT(inv.receivedFrom)) AS receivedBy, i.itemId,brand, modelName, modelNumber, color, unitPrice, SUM(initialQuantity) AS quantity, 1000 * UNIX_TIMESTAMP(receivedOn) as purchasedAt,p.id as purchaseId, nlc, po.warehouseIdFROM purchase pJOIN purchaseorder poON (po.id = p.purchaseOrder_id)JOIN inventoryItem iON (p.id = i.purchaseId)JOIN lineitem lON (l.itemId = i.itemId AND l.purchaseOrder_id = po.id)JOIN supplier sON (s.id = po.supplierId)JOIN invoice invON (inv.invoiceNumber = p.invoiceNumber AND inv.supplierId = po.supplierId)WHERE po.createdAt BETWEEN #{startDate} AND #{endDate}AND lastScanType != 'DOA_REPLACED'GROUP BY p.purchaseOrder_id, p.id, i.itemIdORDER BY p.purchaseOrder_id, p.id, i.itemId</select><select id="getPurchaseScansByGrnDate" parameterType="map" resultType="detailedPurchaseScan">SELECT p.purchaseOrder_id AS purchaseOrderId, 1000 * UNIX_TIMESTAMP(po.createdAt) AS poCreatedAt, s.name AS supplierName,p.invoiceNumber AS invoiceNumbers, inv.receivedFrom AS receivedBy, i.itemId,brand, modelName, modelNumber, color,unitPrice, SUM(initialQuantity) AS quantity, 1000 * UNIX_TIMESTAMP(receivedOn) as purchasedAt, p.id as purchaseId,nlc, po.warehouseId, po.taxTypeFROM purchase pJOIN purchaseorder poON (po.id = p.purchaseOrder_id)JOIN inventoryItem iON (p.id = i.purchaseId)JOIN lineitem lON (l.itemId = i.itemId AND l.purchaseOrder_id = po.id)JOIN supplier sON (s.id = po.supplierId)JOIN invoice invON (inv.invoiceNumber = p.invoiceNumber AND inv.supplierId = po.supplierId)WHERE p.receivedOn BETWEEN #{startDate} AND #{endDate}AND inv.date < #{endDate}AND inv.date > ADDDATE(#{startDate},-1)AND lastScanType != 'DOA_REPLACED'GROUP BY p.purchaseOrder_id, p.id, i.itemIdORDER BY p.purchaseOrder_id, p.id, i.itemId</select><select id="fetchMismatchScansPerInvoiceNumber" parameterType="java.util.Date" resultType="invoiceScan" >SELECT i.invoiceNumber, i.numItems, sum(initialQuantity) as scannedQuantity, i.date, s.name as supplierNameFROM invoice iJOIN supplier sON (i.supplierId = s.id)LEFT JOIN purchase pON (p.invoiceNumber = i.invoiceNumber)LEFT JOIN inventoryItem iiON (ii.purchaseId = p.id)JOIN scanNew snON (sn.inventoryItemId = ii.id)WHERE i.date = #{date}AND sn.scannedAt between #{date} and ADDDATE(#{date},1)AND sn.type = 'PURCHASE'AND s.id !=1GROUP BY i.invoiceNumber, i.numItemsHAVING SUM(initialQuantity) != i.numItems</select><select id="getInventoryAge" resultType="inventoryAge">SELECT t.itemId, brand, modelName, modelNumber, color,SUM((age < 1) * currentQuantity) AS freshCount,SUM((age >= 1 and age < 2) * currentQuantity) AS oneToTwoCount,SUM((age >= 2 and age < 3) * currentQuantity) AS twoToThreeCount,SUM((age >= 3 and age < 4) * currentQuantity) AS threeToFourCount,SUM((age >= 4) * currentQuantity) as fourPlusCount,SUM((age >= 1) * currentQuantity) as onePlusCount,SUM((age >= 13) * currentQuantity) as threeMonthPlusCount,SUM((age >= 26) * currentQuantity) as sixMonthPlusCount,SUM((age >= 1) * unitPrice*currentQuantity) as onePlusCost,SUM(currentQuantity) as zeroPlusCount,SUM(l.unitPrice*currentQuantity) as zeroPlusCost,l.productGroup as categoryFROM (SELECT ii.id, ii.itemId, ii.currentQuantity, ii.purchaseId,DATEDIFF(now(), MIN(s.scannedAt)) / 7 as ageFROM inventoryItem iiJOIN scanNew sON (s.inventoryItemId = ii.id)WHERE (ii.lastScanType IN ('PURCHASE', 'SALE_RET', 'MARKED_GOOD')OR ii.currentQuantity>1)AND (transferStatus is NULL or transferStatus != 'IN_TRANSIT')AND ii.physicalWarehouseId !=16GROUP BY ii.id, ii.itemId, ii.currentQuantity) tJOIN purchase pON (p.id = t.purchaseId)JOIN lineitem lON (l.purchaseOrder_id = p.purchaseOrder_id AND l.itemId = t.itemId)GROUP BY t.itemIdHAVING SUM(currentQuantity) != 0</select><!--select id="inventoryAgeOnePlus" resultType="detailedInventoryAge">SELECT t.itemId, brand, modelName, modelNumber, color, scannedAt, i.warehouseIdSUM((age >= 1) * currentQuantity) AS onePlusCount,SUM((age >= 1) * unitPrice) as onePlusCost,l.productGroup as categoryFROM (SELECT ii.id, ii.itemId, ii.currentQuantity, ii.purchaseId, MIN(s.scannedAt)DATEDIFF(now(), MAX(s.scannedAt)) / 7 as ageFROM inventoryItem iiJOIN scanNew sON (s.inventoryItemId = ii.id)WHERE ii.lastScanType IN ('PURCHASE', 'SALE_RET')GROUP BY ii.id, ii.itemId, ii.currentQuantity) tJOIN purchase pON (p.id = t.purchaseId)JOIN lineitem lON (l.purchaseOrder_id = p.purchaseOrder_id AND l.itemId = t.itemId)GROUP BY t.itemId, i.warehouseIdHAVING SUM(currentQuantity) != 0</select--><select id = "getScansForItem" parameterType = "map" resultType = "scan">SELECT s.id, s.inventoryItemId, s.warehouseId, s.type, s.scannedAt,s.quantity, s.orderId from scanNew s JOIN inventoryItem iONs.inventoryItemId = i.idANDi.itemId = #{itemId}ANDs.scannedAt BETWEEN #{fromDate} AND #{toDate};</select><insert id="genericScan" parameterType="scan" useGeneratedKeys="true" keyProperty="id">INSERT INTO scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId, transferLotId, remarks)VALUES(#{inventoryItemId}, #{warehouseId}, #{type}, NOW(), #{quantity}, #{orderId}, #{transferLotId}, #{remarks})</insert><select id = "getCurrentSerializedInventoryByScans" resultType = "inventoryAvailability">SELECT x.itemId, ci.brand, ci.model_name as modelName,ci.model_number as modelNumber, ci.color as color, (x.inx-if(y.outx is null,0,y.outx)) as quantityfrom(select i.itemId, count(*) as inx from scanNew sJOIN inventoryItem i ON (i.id = s.inventoryItemId)JOIN catalog.item c ON i.itemId = c.idJOIN inventory.warehouse w ON w.id = s.warehouseIdwhere s.type in ('PURCHASE','SALE_RET', 'MARKED_GOOD','WAREHOUSE_TRANSFER_IN') and c.type = 'SERIALIZED'and w.billingWarehouseId = #{physicalWarehouseId}group by i.itemId ) as xLEFT JOIN(select i.itemId, count(*) as outx from scanNew sJOIN inventoryItem i on i.id = s.inventoryItemIdJOIN catalog.item c ON i.itemId = c.idJOIN inventory.warehouse w ON w.id = s.warehouseIdwhere s.type in ('SALE','LOST_IN_WAREHOUSE','PURCHASE_RETURN','MARKED_USED','MARKED_BAD','WAREHOUSE_TRANSFER_OUT') and c.type = 'SERIALIZED'and w.billingWarehouseId = #{physicalWarehouseId}group by i.itemId) as yON x.itemId = y.itemIdJOIN catalog.item ci ON ci.id = x.itemIdwhere ci.type = 'SERIALIZED' having quantity>0</select><select id = "getHistoricSerializedInventoryByScans" resultType = "inventoryAvailability" parameterType = "date">SELECT x.itemId, ci.brand, ci.model_name as modelName,ci.model_number as modelNumber, ci.color as color, (x.inx-if(y.outx is null,0,y.outx)) as quantityfrom(select i.itemId, count(*) as inx from scanNew sJOIN inventoryItem i ON (i.id = s.inventoryItemId)JOIN catalog.item c ON i.itemId = c.idwhere s.type in ('PURCHASE','SALE_RET', 'MARKED_GOOD','WAREHOUSE_TRANSFER_IN') and c.type = 'SERIALIZED'and s.scannedAt < #{date}group by i.itemId ) as xLEFT JOIN(select i.itemId, count(*) as outx from scanNew sJOIN inventoryItem i on i.id = s.inventoryItemIdJOIN catalog.item c ON i.itemId = c.idwhere s.type in ('SALE','LOST_IN_WAREHOUSE','PURCHASE_RETURN','MARKED_USED','MARKED_BAD','WAREHOUSE_TRANSFER_OUT') and c.type = 'SERIALIZED'and s.scannedAt < #{date}group by i.itemId) as yON x.itemId = y.itemIdJOIN catalog.item ci ON ci.id = x.itemIdwhere ci.type = 'SERIALIZED' having quantity>0</select><select id = "getOurHistoricSerializedInventoryByScans" resultType = "inventoryAvailability" parameterType = "date">SELECT x.itemId, ci.brand, ci.model_name as modelName,ci.model_number as modelNumber, ci.color as color, (x.inx-if(y.outx is null,0,y.outx)) as quantityfrom(select i.itemId, count(*) as inx from scanNew sJOIN inventoryItem i ON (i.id = s.inventoryItemId)JOIN catalog.item c ON i.itemId = c.idwhere s.type in ('PURCHASE','SALE_RET', 'MARKED_GOOD','WAREHOUSE_TRANSFER_IN') and c.type = 'SERIALIZED'and s.scannedAt < #{date}and s.warehouseId != 16group by i.itemId ) as xLEFT JOIN(select i.itemId, count(*) as outx from scanNew sJOIN inventoryItem i on i.id = s.inventoryItemIdJOIN catalog.item c ON i.itemId = c.idwhere s.type in ('SALE','LOST_IN_WAREHOUSE','PURCHASE_RETURN','MARKED_USED','MARKED_BAD','WAREHOUSE_TRANSFER_OUT') and c.type = 'SERIALIZED'and s.scannedAt < #{date}and s.warehouseId != 16group by i.itemId) as yON x.itemId = y.itemIdJOIN catalog.item ci ON ci.id = x.itemIdwhere ci.type = 'SERIALIZED' having quantity>0</select><select id = "getCurrentNonSerializedInventoryByScans" resultType = "inventoryAvailability">SELECT x.itemId, ci.brand, ci.model_name as modelName,ci.model_number as modelNumber, ci.color as color, (x.inx-if(y.outx is null,0,y.outx)) as quantityfrom(select i.itemId, sum(quantity) as inx from scanNew sJOIN inventoryItem i ON (i.id = s.inventoryItemId)JOIN catalog.item c ON i.itemId = c.idJOIN inventory.warehouse w ON w.id = s.warehouseIdwhere s.type in ('PURCHASE','SALE_RET', 'MARKED_GOOD','WAREHOUSE_TRANSFER_IN') and c.type = 'NON_SERIALIZED'and w.billingWarehouseId = #{physicalWarehouseId}group by i.itemId ) as xLEFT JOIN(select i.itemId, sum(quantity) as outx from scanNew sJOIN inventoryItem i on i.id = s.inventoryItemIdJOIN catalog.item c ON i.itemId = c.idJOIN inventory.warehouse w ON w.id = s.warehouseIdwhere s.type in ('SALE','LOST_IN_WAREHOUSE','PURCHASE_RETURN','MARKED_USED','MARKED_BAD','WAREHOUSE_TRANSFER_OUT') and c.type = 'NON_SERIALIZED'and w.billingWarehouseId = #{physicalWarehouseId}group by i.itemId) as yON x.itemId = y.itemIdJOIN catalog.item ci ON ci.id = x.itemIdwhere ci.type = 'NON_SERIALIZED' having quantity>0</select><select id = "getHistoricNonSerializedInventoryByScans" resultType = "inventoryAvailability" parameterType = "date">SELECT x.itemId, ci.brand, ci.model_name as modelName,ci.model_number as modelNumber, ci.color as color, (x.inx-if(y.outx is null,0,y.outx)) as quantityfrom(SELECT i.itemId, sum(quantity) as inx from scanNew sJOIN inventoryItem i ON (i.id = s.inventoryItemId)JOIN catalog.item c ON i.itemId = c.idwhere s.type in ('PURCHASE','SALE_RET', 'MARKED_GOOD','WAREHOUSE_TRANSFER_IN') and c.type = 'NON_SERIALIZED'and s.scannedAt < #{date}group by i.itemId ) as xLEFT JOIN(SELECT i.itemId, sum(quantity) as outx from scanNew sJOIN inventoryItem i on i.id = s.inventoryItemIdJOIN catalog.item c ON i.itemId = c.idwhere s.type in ('SALE','LOST_IN_WAREHOUSE','PURCHASE_RETURN','MARKED_USED','MARKED_BAD','WAREHOUSE_TRANSFER_OUT') and c.type = 'NON_SERIALIZED'and s.scannedAt < #{date}group by i.itemId) as yON x.itemId = y.itemIdJOIN catalog.item ci ON ci.id = x.itemIdwhere ci.type = 'NON_SERIALIZED' having quantity>0</select><select id = "getOurHistoricNonSerializedInventoryByScans" resultType = "inventoryAvailability" parameterType = "date">SELECT x.itemId, ci.brand, ci.model_name as modelName,ci.model_number as modelNumber, ci.color as color, (x.inx-if(y.outx is null,0,y.outx)) as quantityfrom(SELECT i.itemId, sum(quantity) as inx from scanNew sJOIN inventoryItem i ON (i.id = s.inventoryItemId)JOIN catalog.item c ON i.itemId = c.idwhere s.type in ('PURCHASE','SALE_RET', 'MARKED_GOOD','WAREHOUSE_TRANSFER_IN') and c.type = 'NON_SERIALIZED'and s.scannedAt < #{date}and s.warehouseId != 16group by i.itemId ) as xLEFT JOIN(SELECT i.itemId, sum(quantity) as outx from scanNew sJOIN inventoryItem i on i.id = s.inventoryItemIdJOIN catalog.item c ON i.itemId = c.idwhere s.type in ('SALE','LOST_IN_WAREHOUSE','PURCHASE_RETURN','MARKED_USED','MARKED_BAD','WAREHOUSE_TRANSFER_OUT') and c.type = 'NON_SERIALIZED'and s.scannedAt < #{date}and s.warehouseId != 16group by i.itemId) as yON x.itemId = y.itemIdJOIN catalog.item ci ON ci.id = x.itemIdwhere ci.type = 'NON_SERIALIZED' having quantity>0</select><select id = "getMovementSerializedInventoryByScans" resultType = "inventoryMovement" parameterType = "map">SELECT itemId, brand, model_name as modelName, model_number as modelNumber, color, s.type, count(*) as quantityFROM inventoryItem i JOIN scanNew s ON i.id = s.inventoryItemIdLEFT JOIN catalog.item c ON i.itemId = c.idwhere s.scannedAt between #{startDate} and #{endDate} and c.type = 'SERIALIZED'and i.currentWarehouseId not in (1,2,6,9)and s.warehouseId != 16group by itemId, s.type</select><select id = "getMovementNonSerializedInventoryByScans" resultType = "inventoryMovement" parameterType = "map">SELECT itemId, brand, model_name as modelName, model_number as modelNumber, color, s.type, sum(quantity) as quantityFROM inventoryItem i JOIN scanNew s ON i.id = s.inventoryItemIdLEFT JOIN catalog.item c ON i.itemId = c.idwhere s.scannedAt between #{startDate} and #{endDate} and c.type = 'NON_SERIALIZED'and i.currentWarehouseId not in (1,2,6,9)and s.warehouseId != 16group by itemId, s.type</select><select id = "getCompleteMovementSerializedInventoryByScans" resultType = "inventoryMovement" parameterType = "map">SELECT itemId, brand, model_name as modelName, model_number as modelNumber, color, s.type, count(*) as quantityFROM inventoryItem i JOIN scanNew s ON i.id = s.inventoryItemIdLEFT JOIN catalog.item c ON i.itemId = c.idwhere s.scannedAt between #{startDate} and #{endDate} and c.type = 'SERIALIZED'and s.warehouseId != 16group by itemId, s.type</select><select id = "getCompleteMovementNonSerializedInventoryByScans" resultType = "inventoryMovement" parameterType = "map">SELECT itemId, brand, model_name as modelName, model_number as modelNumber, color, s.type, sum(quantity) as quantityFROM inventoryItem i JOIN scanNew s ON i.id = s.inventoryItemIdLEFT JOIN catalog.item c ON i.itemId = c.idwhere s.scannedAt between #{startDate} and #{endDate} and c.type = 'NON_SERIALIZED'and s.warehouseId != 16group by itemId, s.type</select><select id = "getTransferrableWarehousesFromWarehouse" resultType = "java.lang.Long" parameterType = "java.lang.Long">SELECT toWarehouseIdFROM possibleWarehouseMovementWHERE fromWarehouseId = #{warehouseId}</select><select id = "getHistoricBadInventoryByScans" resultType = "inventoryAvailability" parameterType = "date">SELECT x.itemId, ci.brand, ci.model_name as modelName, ci.model_number as modelNumber,ci.color as color, (x.inx-if(y.outx is null,0,y.outx)) as quantityFROM(SELECT i.itemId, count(*) as inx FROM scanNew s JOIN inventoryItem i ON(i.id = s.inventoryItemId) JOIN catalog.item c ON i.itemId = c.idwhere s.type in ('DOA_IN', 'SALE_RET_UNUSABLE') ands.scannedAt < #{date} and s.scannedAt > '2013-01-01' group by i.itemId ) as xLEFT JOIN(SELECT i.itemId, count(*) as outx FROM scanNew s JOIN inventoryItem i ONi.id = s.inventoryItemId JOIN catalog.item c ON i.itemId = c.id WHEREs.type in ('DOA_OUT') and s.scannedAt < #{date} and s.scannedAt > '2013-01-01'group by i.itemId) as yON x.itemId = y.itemIdJOIN catalog.item ci ON ci.id = x.itemIdhaving quantity>0;</select><select id = "getScansForTransferLot" resultType = "scan" parameterType = "java.lang.Long">SELECT *FROM scanNewWHERE transferLotId = #{id}AND type = 'WAREHOUSE_TRANSFER_OUT'</select><select id= "getScansForTransferLotAndInventoryItem" resultType = "scan" parameterType="map" >SELECT *FROM scanNewWHERE transferLotId = #{transferLotId}AND inventoryItemId = #{inventoryItemId}AND type = 'WAREHOUSE_TRANSFER_OUT'LIMIT 1</select></mapper>