| 4500 |
mandeep.dh |
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
2 |
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
3 |
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
4 |
|
|
|
5 |
<mapper namespace="in.shop2020.warehouse.persistence.ScanMapper">
|
|
|
6 |
<resultMap type="scan" id="scanResult">
|
|
|
7 |
<id property="id" column="id"/>
|
|
|
8 |
</resultMap>
|
|
|
9 |
|
|
|
10 |
<insert id="insert" parameterType="scan" useGeneratedKeys="true" keyProperty="id">
|
|
|
11 |
INSERT INTO scanNew
|
|
|
12 |
(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId)
|
|
|
13 |
VALUES
|
|
|
14 |
(#{inventoryItemId}, #{warehouseId}, #{type}, NOW(), #{quantity}, #{orderId})
|
|
|
15 |
</insert>
|
|
|
16 |
|
|
|
17 |
<select id="get" parameterType="map" resultType="scan">
|
|
|
18 |
SELECT *
|
|
|
19 |
FROM scanNew
|
|
|
20 |
WHERE inventoryItemId = #{inventoryItemId}
|
|
|
21 |
<if test="scanType != null">
|
|
|
22 |
AND type = #{scanType}
|
|
|
23 |
</if>
|
|
|
24 |
ORDER BY scannedAt
|
|
|
25 |
</select>
|
| 5361 |
mandeep.dh |
26 |
|
|
|
27 |
<select id="getScansFromOrderId" parameterType="java.lang.Long" resultType="scan">
|
|
|
28 |
SELECT *
|
|
|
29 |
FROM scanNew
|
|
|
30 |
WHERE orderId = #{orderId}
|
|
|
31 |
ORDER BY scannedAt
|
|
|
32 |
</select>
|
| 5372 |
mandeep.dh |
33 |
|
|
|
34 |
<select id="getPurchaseScans" parameterType="map" resultType="detailedPurchaseScan">
|
| 5395 |
mandeep.dh |
35 |
SELECT p.purchaseOrder_id AS purchaseOrderId, 1000 * UNIX_TIMESTAMP(po.createdAt) AS poCreatedAt, s.name AS supplierName,
|
| 5372 |
mandeep.dh |
36 |
GROUP_CONCAT(DISTINCT(invoiceNumber)) AS invoiceNumbers, i.itemId,
|
| 6361 |
rajveer |
37 |
brand, modelName, modelNumber, color, unitPrice, SUM(initialQuantity) AS quantity, 1000 * UNIX_TIMESTAMP(receivedOn) as purchasedAt, p.id as purchaseId
|
| 5372 |
mandeep.dh |
38 |
FROM purchase p
|
|
|
39 |
JOIN purchaseorder po
|
|
|
40 |
ON (po.id = p.purchaseOrder_id)
|
|
|
41 |
JOIN inventoryItem i
|
|
|
42 |
ON (p.id = i.purchaseId)
|
|
|
43 |
JOIN lineitem l
|
|
|
44 |
ON (l.itemId = i.itemId AND l.purchaseOrder_id = po.id)
|
|
|
45 |
JOIN supplier s
|
|
|
46 |
ON (s.id = po.supplierId)
|
|
|
47 |
WHERE po.createdAt BETWEEN #{startDate} AND #{endDate}
|
| 6364 |
rajveer |
48 |
AND lastScanType != 'DOA_REPLACED'
|
| 6362 |
rajveer |
49 |
GROUP BY p.purchaseOrder_id, p.id, i.itemId
|
|
|
50 |
ORDER BY p.purchaseOrder_id, p.id, i.itemId
|
| 5372 |
mandeep.dh |
51 |
</select>
|
| 5496 |
mandeep.dh |
52 |
|
|
|
53 |
<select id="fetchMismatchScansPerInvoiceNumber" parameterType="java.util.Date" resultType="invoiceScan" >
|
|
|
54 |
SELECT i.invoiceNumber, i.numItems, sum(initialQuantity) as scannedQuantity, i.date, s.name as supplierName
|
|
|
55 |
FROM invoice i
|
|
|
56 |
JOIN supplier s
|
|
|
57 |
ON (s.id = i.supplierId)
|
|
|
58 |
LEFT JOIN purchase p
|
|
|
59 |
ON (p.invoiceNumber = i.invoiceNumber)
|
|
|
60 |
LEFT JOIN inventoryItem ii ON (ii.purchaseId = p.id)
|
|
|
61 |
WHERE i.date = #{date}
|
|
|
62 |
GROUP BY i.invoiceNumber, i.numItems
|
|
|
63 |
HAVING SUM(initialQuantity) != i.numItems
|
|
|
64 |
</select>
|
| 5372 |
mandeep.dh |
65 |
|
| 5711 |
mandeep.dh |
66 |
<select id="getInventoryAge" resultType="inventoryAge">
|
|
|
67 |
SELECT t.itemId, brand, modelName, modelNumber, color,
|
|
|
68 |
SUM((age < 1) * currentQuantity) AS freshCount,
|
| 5768 |
mandeep.dh |
69 |
SUM((age >= 1 and age < 2) * currentQuantity) AS oneToTwoCount,
|
|
|
70 |
SUM((age >= 2 and age < 3) * currentQuantity) AS twoToThreeCount,
|
|
|
71 |
SUM((age >= 3 and age < 4) * currentQuantity) AS threeToFourCount,
|
|
|
72 |
SUM((age >= 4) * currentQuantity) as fourPlusCount,
|
|
|
73 |
SUM((age >= 1) * currentQuantity) as onePlusCount,
|
|
|
74 |
SUM((age >= 1) * unitPrice) as onePlusCost,
|
|
|
75 |
SUM(currentQuantity) as zeroPlusCount,
|
|
|
76 |
SUM(l.unitPrice) as zeroPlusCost,
|
|
|
77 |
l.productGroup as category
|
| 5711 |
mandeep.dh |
78 |
FROM (SELECT ii.id, ii.itemId, ii.currentQuantity, ii.purchaseId,
|
|
|
79 |
DATEDIFF(now(), MAX(s.scannedAt)) / 7 as age
|
|
|
80 |
FROM inventoryItem ii
|
|
|
81 |
JOIN scanNew s
|
|
|
82 |
ON (s.inventoryItemId = ii.id)
|
|
|
83 |
WHERE ii.lastScanType IN ('PURCHASE', 'SALE_RET')
|
|
|
84 |
GROUP BY ii.id, ii.itemId, ii.currentQuantity) t
|
|
|
85 |
JOIN purchase p
|
|
|
86 |
ON (p.id = t.purchaseId)
|
|
|
87 |
JOIN lineitem l
|
|
|
88 |
ON (l.purchaseOrder_id = p.purchaseOrder_id AND l.itemId = t.itemId)
|
|
|
89 |
GROUP BY t.itemId
|
|
|
90 |
HAVING SUM(currentQuantity) != 0
|
|
|
91 |
</select>
|
| 6322 |
amar.kumar |
92 |
|
|
|
93 |
<select id = "getScansForItem" parameterType = "map" resultType = "scan">
|
|
|
94 |
SELECT s.id, s.inventoryItemId, s.warehouseId, s.type, s.scannedAt,
|
|
|
95 |
s.quantity, s.orderId from scanNew s JOIN inventoryItem i
|
|
|
96 |
ON
|
|
|
97 |
s.inventoryItemId = i.id
|
|
|
98 |
AND
|
| 6414 |
amar.kumar |
99 |
i.itemId = #{itemId}
|
| 6322 |
amar.kumar |
100 |
AND
|
|
|
101 |
s.scannedAt BETWEEN #{fromDate} AND #{toDate};
|
|
|
102 |
</select>
|
|
|
103 |
|
| 6467 |
amar.kumar |
104 |
<insert id="scanForPurchaseReturn" parameterType="scan" useGeneratedKeys="true" keyProperty="id">
|
|
|
105 |
INSERT INTO scanNew
|
|
|
106 |
(inventoryItemId, warehouseId, type, scannedAt, quantity)
|
|
|
107 |
VALUES
|
|
|
108 |
(#{inventoryItemId}, #{warehouseId}, #{type}, NOW(), #{quantity})
|
|
|
109 |
</insert>
|
|
|
110 |
|
| 4500 |
mandeep.dh |
111 |
</mapper>
|