@ -26,6 +26,8 @@
WHEN 'CYCLE' THEN '循环盘点'
WHEN 'MANUAL' THEN '手工盘点'
WHEN 'DAILY' THEN '日常盘点'
WHEN 'MID_YEAR' THEN '年中盘点'
WHEN 'YEAR_END' THEN '年末盘点'
ELSE h.count_type
END AS countTypeDesc,
CASE h.status
@ -118,7 +120,7 @@
h.remark,
h.created_by AS createdBy,
h.created_date AS createdDate,
CASE h.count_type WHEN 'CYCLE' THEN '循环盘点' WHEN 'MANUAL' THEN '手工盘点' WHEN 'DAILY' THEN '日常盘点' ELSE h.count_type END AS countTypeDesc,
CASE h.count_type WHEN 'CYCLE' THEN '循环盘点' WHEN 'MANUAL' THEN '手工盘点' WHEN 'DAILY' THEN '日常盘点' WHEN 'MID_YEAR' THEN '年中盘点' WHEN 'YEAR_END' THEN '年末盘点' ELSE h.count_type END AS countTypeDesc,
CASE h.status WHEN 'DRAFT' THEN '草稿' WHEN 'RELEASED' THEN '已下达' WHEN 'CHECKING' THEN '盘点中' WHEN 'APPROVED' THEN '已审批' WHEN 'COMPLETED' THEN '已完成' WHEN 'CANCELLED' THEN '已取消' ELSE h.status END AS statusDesc,
(SELECT COUNT(1) FROM count_label WHERE site = h.site AND count_no = h.count_no) AS totalLabelCount,
(SELECT COUNT(1) FROM count_label WHERE site = h.site AND count_no = h.count_no AND count_flag = 'Y') AS checkedLabelCount,
@ -878,11 +880,119 @@
WHERE site = #{header.site} AND count_no = #{header.countNo}
</update>
<!-- rqrq - 插入盘点主表 -->
<!-- rqrq - 插入盘点主表(可选写入下达/完成人时间,供日常盘点与年度盘点报告等) -->
<insert id= "insertCountHeader" >
INSERT INTO count_header (site, count_no, count_type, status, count_percent, apply_user, apply_date, remark, created_by, created_date)
INSERT INTO count_header (site, count_no, count_type, status, count_percent, apply_user, apply_date, remark, created_by, created_date
<if test= "header.releaseUser != null and header.releaseUser != ''" >
, release_user, release_date
</if>
<if test= "header.completeUser != null and header.completeUser != ''" >
, complete_user, complete_date
</if>
)
VALUES (#{header.site}, #{header.countNo}, #{header.countType}, #{header.status}, #{header.countPercent},
#{header.applyUser}, GETDATE(), #{header.remark}, #{header.createdBy}, GETDATE())
#{header.applyUser}, GETDATE(), #{header.remark}, #{header.createdBy}, GETDATE()
<if test= "header.releaseUser != null and header.releaseUser != ''" >
, #{header.releaseUser}, GETDATE()
</if>
<if test= "header.completeUser != null and header.completeUser != ''" >
, #{header.completeUser}, GETDATE()
</if>
)
</insert>
<!-- rqrq - 在库且未盘点标签数量(in_stock_flag=Y 且 count_flag 非 Y) -->
<select id= "countInStockUncountedLabels" resultType= "int" >
SELECT COUNT(1)
FROM handling_unit h WITH (NOLOCK)
WHERE h.site = #{site}
AND h.in_stock_flag = 'Y'
AND ISNULL(h.count_flag, 'N') < > 'Y'
</select>
<!-- rqrq - 在库且未盘点标签号前 20 条(年度盘点报告提示) -->
<select id= "listInStockUncountedUnitIdsTop" resultType= "java.lang.String" >
SELECT TOP 20 h.unit_id
FROM handling_unit h WITH (NOLOCK)
WHERE h.site = #{site}
AND h.in_stock_flag = 'Y'
AND ISNULL(h.count_flag, 'N') < > 'Y'
ORDER BY h.unit_id
</select>
<!-- rqrq - 在库且已盘点标签总数(年度报告准入条数,须 in_stock_flag 与 count_flag 均为 Y) -->
<select id= "countHandlingUnitInStock" resultType= "int" >
SELECT COUNT(1)
FROM handling_unit h WITH (NOLOCK)
WHERE h.site = #{site}
AND h.in_stock_flag = 'Y'
AND h.count_flag = 'Y'
</select>
<!-- rqrq - 年度盘点报告:仅 in_stock_flag=Y 且 count_flag=Y;从 handling_unit 写入 count_label,pallet_id 固定 * -->
<insert id= "insertYearReportCountLabelFromHandlingUnit" >
INSERT INTO count_label (
site, count_no, unit_id, part_no, qty,
batch_no, location_id, warehouse_id, wdr, pallet_id,
label_type, count_flag, count_date, count_user,
created_by, created_date
)
SELECT
h.site,
#{countNo},
h.unit_id,
h.part_no,
h.qty,
h.batch_no,
h.location_id,
h.warehouse_id,
h.wdr,
'*',
'ASSIGNED',
'Y',
COALESCE(h.last_count_date, h.modified_date, h.created_date, GETDATE()),
'SYSTEM',
#{username},
GETDATE()
FROM handling_unit h WITH (NOLOCK)
WHERE h.site = #{site}
AND h.in_stock_flag = 'Y'
AND h.count_flag = 'Y'
</insert>
<!-- rqrq - 年度盘点报告:仅 in_stock_flag=Y 且 count_flag=Y;写入 count_result,结果均为 OK、无差异(count_date NOT NULL,须兜底) -->
<insert id= "insertYearReportCountResultFromHandlingUnit" >
INSERT INTO count_result (
site, count_no, unit_id, part_no, qty,
batch_no, location_id, warehouse_id, wdr, pallet_id,
count_date, count_user, count_result, diff_qty,
handle_flag, handle_type, remark,
created_by, created_date
)
SELECT
h.site,
#{countNo},
h.unit_id,
h.part_no,
h.qty,
h.batch_no,
h.location_id,
h.warehouse_id,
h.wdr,
'*',
COALESCE(h.last_count_date, h.modified_date, h.created_date, GETDATE()),
'SYSTEM',
'OK',
0,
'Y',
'',
N'年度盘点报告(无差异)',
#{username},
GETDATE()
FROM handling_unit h WITH (NOLOCK)
WHERE h.site = #{site}
AND h.in_stock_flag = 'Y'
AND h.count_flag = 'Y'
</insert>
<!-- rqrq - 删除盘点主表 -->