Fix su query di calcolo fabbisogno linee prod per WMS
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -8,32 +8,46 @@ import java.util.Date;
|
|||||||
public class WMSApprovvigionamentoLineeDTO {
|
public class WMSApprovvigionamentoLineeDTO {
|
||||||
@SqlField(value = "cod_mart")
|
@SqlField(value = "cod_mart")
|
||||||
private String codMart;
|
private String codMart;
|
||||||
|
|
||||||
@SqlField(value = "cod_jfas")
|
@SqlField(value = "cod_jfas")
|
||||||
private String codJfas;
|
private String codJfas;
|
||||||
|
|
||||||
@SqlField(value = "qta_ord")
|
@SqlField(value = "qta_ord")
|
||||||
private BigDecimal qtaOrd;
|
private BigDecimal qtaOrd;
|
||||||
|
|
||||||
@SqlField(value = "num_cnf_ord")
|
@SqlField(value = "num_cnf_ord")
|
||||||
private BigDecimal numCnfOrd;
|
private BigDecimal numCnfOrd;
|
||||||
|
|
||||||
@SqlField(value = "unt_mis")
|
@SqlField(value = "unt_mis")
|
||||||
private String untMis;
|
private String untMis;
|
||||||
|
|
||||||
@SqlField(value = "qta_col_versata")
|
@SqlField(value = "qta_col_versata")
|
||||||
private BigDecimal qtaColVersata;
|
private BigDecimal qtaColVersata;
|
||||||
|
|
||||||
@SqlField(value = "num_cnf_versata")
|
@SqlField(value = "num_cnf_versata")
|
||||||
private BigDecimal numCnfVersata;
|
private BigDecimal numCnfVersata;
|
||||||
|
|
||||||
@SqlField(value = "qta_fabbisogno")
|
@SqlField(value = "qta_fabbisogno")
|
||||||
private BigDecimal qtaFabbisogno;
|
private BigDecimal qtaFabbisogno;
|
||||||
|
|
||||||
@SqlField(value = "num_cnf_fabbisogno")
|
@SqlField(value = "num_cnf_fabbisogno")
|
||||||
private BigDecimal numCnfFabbisogno;
|
private BigDecimal numCnfFabbisogno;
|
||||||
|
|
||||||
@SqlField(value = "data_inizio")
|
@SqlField(value = "data_inizio")
|
||||||
private Date dataInizio;
|
private Date dataInizio;
|
||||||
|
|
||||||
@SqlField(value = "data_fine")
|
@SqlField(value = "data_fine")
|
||||||
private Date dataFine;
|
private Date dataFine;
|
||||||
|
|
||||||
@SqlField(value = "cod_mgrp")
|
@SqlField(value = "cod_mgrp")
|
||||||
private String codMgrp;
|
private String codMgrp;
|
||||||
|
|
||||||
@SqlField(value = "descrizione_mgrp")
|
@SqlField(value = "descrizione_mgrp")
|
||||||
private String descrizioneMgrp;
|
private String descrizioneMgrp;
|
||||||
|
|
||||||
@SqlField(value = "cod_msgr")
|
@SqlField(value = "cod_msgr")
|
||||||
private String codMsgr;
|
private String codMsgr;
|
||||||
|
|
||||||
@SqlField(value = "descrizione_msgr")
|
@SqlField(value = "descrizione_msgr")
|
||||||
private String descrizioneMsgr;
|
private String descrizioneMsgr;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package it.integry.ems.retail.wms.lavorazione.service;
|
|||||||
|
|
||||||
import it.integry.ems.retail.wms.lavorazione.dto.WMSApprovvigionamentoLineeDTO;
|
import it.integry.ems.retail.wms.lavorazione.dto.WMSApprovvigionamentoLineeDTO;
|
||||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
|
import it.integry.ems_model.utility.Query;
|
||||||
import it.integry.ems_model.utility.UtilityDB;
|
import it.integry.ems_model.utility.UtilityDB;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
@@ -17,10 +18,7 @@ public class WMSApprovvigionamentoLineeService {
|
|||||||
private MultiDBTransactionManager multiDBTransactionManager;
|
private MultiDBTransactionManager multiDBTransactionManager;
|
||||||
|
|
||||||
public List<WMSApprovvigionamentoLineeDTO> retrieveFabbisogno(String numOrd, String codMdep) throws Exception {
|
public List<WMSApprovvigionamentoLineeDTO> retrieveFabbisogno(String numOrd, String codMdep) throws Exception {
|
||||||
String sql = "declare @codMdep varchar(5)\n" +
|
String sql = Query.format(
|
||||||
"set @codMdep = " + UtilityDB.valueToString(codMdep) + ";\n" +
|
|
||||||
" \n" +
|
|
||||||
" \n" +
|
|
||||||
"WITH withdraw_mtb_colr AS (SELECT cod_mart,\n" +
|
"WITH withdraw_mtb_colr AS (SELECT cod_mart,\n" +
|
||||||
" SUM(ISNULL(qta_col, 0)) AS qta_col,\n" +
|
" SUM(ISNULL(qta_col, 0)) AS qta_col,\n" +
|
||||||
" SUM(ISNULL(num_cnf, 0)) AS num_cnf,\n" +
|
" SUM(ISNULL(num_cnf, 0)) AS num_cnf,\n" +
|
||||||
@@ -36,7 +34,7 @@ public class WMSApprovvigionamentoLineeService {
|
|||||||
" AND cod_dtip IS NULL\n" +
|
" AND cod_dtip IS NULL\n" +
|
||||||
" GROUP BY cod_mart, mtb_colr.data_ord, mtb_colr.num_ord, mtb_colr.gestione),\n" +
|
" GROUP BY cod_mart, mtb_colr.data_ord, mtb_colr.num_ord, mtb_colr.gestione),\n" +
|
||||||
" custom_mtb_colr AS (SELECT cod_mart, SUM(qta_col) AS qta_col, SUM(num_cnf) AS num_cnf, posizione\n" +
|
" custom_mtb_colr AS (SELECT cod_mart, SUM(qta_col) AS qta_col, SUM(num_cnf) AS num_cnf, posizione\n" +
|
||||||
" FROM mvw_sitart_udc_det_inventario\t\t\t\t\t\t \n" +
|
" FROM mvw_sitart_udc_det_inventario\n" +
|
||||||
" GROUP BY cod_mart, posizione),\n" +
|
" GROUP BY cod_mart, posizione),\n" +
|
||||||
" grouped_ord AS (SELECT dtb_ordr.cod_mart,\n" +
|
" grouped_ord AS (SELECT dtb_ordr.cod_mart,\n" +
|
||||||
" dtb_ordt.cod_jfas,\n" +
|
" dtb_ordt.cod_jfas,\n" +
|
||||||
@@ -60,8 +58,8 @@ public class WMSApprovvigionamentoLineeService {
|
|||||||
" AND flag_evaso_prod = 'I'\n" +
|
" AND flag_evaso_prod = 'I'\n" +
|
||||||
" AND dtb_ordr.flag_evaso_forzato = 'N'\n" +
|
" AND dtb_ordr.flag_evaso_forzato = 'N'\n" +
|
||||||
" AND flag_annulla = 'N'\n" +
|
" AND flag_annulla = 'N'\n" +
|
||||||
" AND dtb_ordt.cod_mdep = @codMdep\n" +
|
" AND dtb_ordt.cod_mdep = {}\n" +
|
||||||
"\t\t\t\t\t AND dtb_ordt.num_ord in (" + numOrd + ")\n" +
|
" AND dtb_ordt.num_ord IN (" + numOrd + ")\n" +
|
||||||
" GROUP BY dtb_ordr.cod_mart, dtb_ordt.cod_jfas, dtb_ordt.cod_mdep, dtb_ordt.gestione),\n" +
|
" GROUP BY dtb_ordr.cod_mart, dtb_ordt.cod_jfas, dtb_ordt.cod_mdep, dtb_ordt.gestione),\n" +
|
||||||
" tmp_ord AS (SELECT grouped_ord.cod_mart,\n" +
|
" tmp_ord AS (SELECT grouped_ord.cod_mart,\n" +
|
||||||
" mtb_aart.unt_mis,\n" +
|
" mtb_aart.unt_mis,\n" +
|
||||||
@@ -70,26 +68,25 @@ public class WMSApprovvigionamentoLineeService {
|
|||||||
" SUM(num_cnf_ord) - SUM(num_cnf_scaricata) AS num_cnf_ord\n" +
|
" SUM(num_cnf_ord) - SUM(num_cnf_scaricata) AS num_cnf_ord\n" +
|
||||||
" FROM grouped_ord\n" +
|
" FROM grouped_ord\n" +
|
||||||
" INNER JOIN mtb_aart ON grouped_ord.cod_mart = mtb_aart.cod_mart\n" +
|
" INNER JOIN mtb_aart ON grouped_ord.cod_mart = mtb_aart.cod_mart\n" +
|
||||||
" GROUP BY grouped_ord.cod_mart, mtb_aart.unt_mis, grouped_ord.cod_jfas)\t\t\t\t\n" +
|
" GROUP BY grouped_ord.cod_mart, mtb_aart.unt_mis, grouped_ord.cod_jfas),\n" +
|
||||||
"\t\t\t\t ,\n" +
|
|
||||||
" ord_without_positioned_mtb_colt AS (SELECT DISTINCT tmp_ord.cod_mart,\n" +
|
" ord_without_positioned_mtb_colt AS (SELECT DISTINCT tmp_ord.cod_mart,\n" +
|
||||||
" tmp_ord.cod_jfas,\n" +
|
" tmp_ord.cod_jfas,\n" +
|
||||||
" ISNULL(custom_mtb_colr_on_linea.posizione, tmp_ord.cod_jfas) AS posizione,\n" +
|
" unt_mis,\n" +
|
||||||
" unt_mis,\n" +
|
" qta_ord AS qta_ord_calc,\n" +
|
||||||
" qta_ord AS qta_ord_calc,\n" +
|
" num_cnf_ord AS num_cnf_ord_calc,\n" +
|
||||||
" num_cnf_ord AS num_cnf_ord_calc,\n" +
|
" SUM(ISNULL(custom_mtb_colr_on_linea.qta_col, 0)) AS qta_gia_posizionata,\n" +
|
||||||
" ISNULL(custom_mtb_colr_on_linea.qta_col, 0) AS qta_gia_posizionata,\n" +
|
" SUM(ISNULL(custom_mtb_colr_on_linea.num_cnf, 0)) AS num_cnf_gia_posizionata,\n" +
|
||||||
" ISNULL(custom_mtb_colr_on_linea.num_cnf, 0) AS num_cnf_gia_posizionata,\n" +
|
" qta_ord - SUM(ISNULL(custom_mtb_colr_on_linea.qta_col, 0)) AS qta_fabbisogno,\n" +
|
||||||
" qta_ord - ISNULL(custom_mtb_colr_on_linea.qta_col, 0) AS qta_fabbisogno,\n" +
|
" num_cnf_ord - SUM(ISNULL(custom_mtb_colr_on_linea.num_cnf, 0)) AS num_cnf_fabbisogno\n" +
|
||||||
" num_cnf_ord - ISNULL(custom_mtb_colr_on_linea.num_cnf, 0) AS num_cnf_fabbisogno\n" +
|
|
||||||
" FROM tmp_ord\n" +
|
" FROM tmp_ord\n" +
|
||||||
" INNER JOIN jrl_fase_posizioni\n" +
|
" INNER JOIN jrl_fase_posizioni\n" +
|
||||||
" ON tmp_ord.cod_jfas = jrl_fase_posizioni.cod_jfas \n" +
|
" ON tmp_ord.cod_jfas = jrl_fase_posizioni.cod_jfas\n" +
|
||||||
" LEFT OUTER JOIN custom_mtb_colr custom_mtb_colr_on_linea\n" +
|
" LEFT OUTER JOIN custom_mtb_colr custom_mtb_colr_on_linea\n" +
|
||||||
" ON tmp_ord.cod_mart =\n" +
|
" ON tmp_ord.cod_mart =\n" +
|
||||||
" custom_mtb_colr_on_linea.cod_mart AND\n" +
|
" custom_mtb_colr_on_linea.cod_mart AND\n" +
|
||||||
" jrl_fase_posizioni.posizione =\n" +
|
" jrl_fase_posizioni.posizione =\n" +
|
||||||
" custom_mtb_colr_on_linea.posizione)\n" +
|
" custom_mtb_colr_on_linea.posizione\n" +
|
||||||
|
" GROUP BY tmp_ord.cod_mart, tmp_ord.cod_jfas, unt_mis, qta_ord, num_cnf_ord)\n" +
|
||||||
"SELECT t.cod_mart,\n" +
|
"SELECT t.cod_mart,\n" +
|
||||||
" t.unt_mis,\n" +
|
" t.unt_mis,\n" +
|
||||||
" SUM(qta_ord_calc) AS qta_ord,\n" +
|
" SUM(qta_ord_calc) AS qta_ord,\n" +
|
||||||
@@ -109,7 +106,7 @@ public class WMSApprovvigionamentoLineeService {
|
|||||||
"GROUP BY t.cod_mart, t.unt_mis, mtb_aart.cod_mgrp, mtb_grup.descrizione, mtb_aart.cod_msgr, mtb_sgrp.descrizione\n" +
|
"GROUP BY t.cod_mart, t.unt_mis, mtb_aart.cod_mgrp, mtb_grup.descrizione, mtb_aart.cod_msgr, mtb_sgrp.descrizione\n" +
|
||||||
"HAVING SUM(qta_ord_calc - qta_gia_posizionata) > 0\n" +
|
"HAVING SUM(qta_ord_calc - qta_gia_posizionata) > 0\n" +
|
||||||
" AND SUM(num_cnf_ord_calc - num_cnf_gia_posizionata) > 0\n" +
|
" AND SUM(num_cnf_ord_calc - num_cnf_gia_posizionata) > 0\n" +
|
||||||
"ORDER BY t.cod_mart";
|
"ORDER BY t.cod_mart", codMdep);
|
||||||
|
|
||||||
return UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, WMSApprovvigionamentoLineeDTO.class);
|
return UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, WMSApprovvigionamentoLineeDTO.class);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user