Rev 5711 | Rev 6322 | 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)VALUES(#{inventoryItemId}, #{warehouseId}, #{type}, NOW(), #{quantity}, #{orderId})</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="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(invoiceNumber)) AS invoiceNumbers, i.itemId,brand, modelName, modelNumber, color, unitPrice, SUM(initialQuantity) AS quantityFROM 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)WHERE po.createdAt BETWEEN #{startDate} AND #{endDate}GROUP BY p.purchaseOrder_id, i.itemIdORDER BY p.purchaseOrder_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 (s.id = i.supplierId)LEFT JOIN purchase pON (p.invoiceNumber = i.invoiceNumber)LEFT JOIN inventoryItem ii ON (ii.purchaseId = p.id)WHERE i.date = #{date}GROUP 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 >= 1) * unitPrice) as onePlusCost,SUM(currentQuantity) as zeroPlusCount,SUM(l.unitPrice) as zeroPlusCost,l.productGroup as categoryFROM (SELECT ii.id, ii.itemId, ii.currentQuantity, ii.purchaseId,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.itemIdHAVING SUM(currentQuantity) != 0</select></mapper>