Regola per controllare se l'articolo che si sta salvando nel listino di vendita ha un codice a barre o un plu
Some checks failed
IntegryManagementSystem_Multi/pipeline/head There was a failure building this commit
Some checks failed
IntegryManagementSystem_Multi/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomer;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250117125427 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
createSetupQuery("SI_NO", "SI_NO", "SELECT 'S' UNION ALL SELECT 'N'");
|
||||
createSetup("VTB_LIST", "SETUP", "CHECK_BARCODE_ART", "N",
|
||||
"Regola per verificare se l'articolo che si sta salvando ha un codice a barre o un plu.", false, "SI_NO", false, false,
|
||||
false, false, false, null, false, "SELECT 'S' UNION ALL SELECT 'N'");
|
||||
|
||||
if (isCustomer(IntegryCustomer.Carelli)){
|
||||
updateSetupValue("VTB_LIST", "SETUP", "CHECK_BARCODE_ART", "S");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PurchasesRules extends QueryRules {
|
||||
|
||||
@@ -50,12 +51,12 @@ public class PurchasesRules extends QueryRules {
|
||||
|
||||
String sql =
|
||||
Query.format("SELECT tipo_variazione"
|
||||
+ " FROM dbo.getGrigliaAcquisto(%s, %s,%s, %s, %s)",
|
||||
atbGriglieArt.getDataValidita(),
|
||||
atbGriglieArt.getCodAlis(),
|
||||
atbGriglieArt.getCodMdep(),
|
||||
atbGriglieArt.getCodArtFor(),
|
||||
atbGriglieArt.getCodMart());
|
||||
+ " FROM dbo.getGrigliaAcquisto(%s, %s,%s, %s, %s)",
|
||||
atbGriglieArt.getDataValidita(),
|
||||
atbGriglieArt.getCodAlis(),
|
||||
atbGriglieArt.getCodMdep(),
|
||||
atbGriglieArt.getCodArtFor(),
|
||||
atbGriglieArt.getCodMart());
|
||||
|
||||
String tipoVariazione = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(connection, sql);
|
||||
|
||||
@@ -303,11 +304,11 @@ public class PurchasesRules extends QueryRules {
|
||||
String codArtFor = entity.getCodArtFor();
|
||||
|
||||
String query =
|
||||
Query.format(
|
||||
"SELECT TOP 1 lisa.cod_mart\n " +
|
||||
" FROM dbo.getListinoAcquisto(%s, %s, %s, null, 'N', null) lisa\n " +
|
||||
"ORDER BY (case when tipo_variazione <> 'D' THEN 0 ELSE 1 END)\n ",
|
||||
dataValidita, listino, codArtFor );
|
||||
Query.format(
|
||||
"SELECT TOP 1 lisa.cod_mart\n " +
|
||||
" FROM dbo.getListinoAcquisto(%s, %s, %s, null, 'N', null) lisa\n " +
|
||||
"ORDER BY (case when tipo_variazione <> 'D' THEN 0 ELSE 1 END)\n ",
|
||||
dataValidita, listino, codArtFor);
|
||||
|
||||
String codMart = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, query);
|
||||
if (UtilityString.isNullOrEmpty(codMart)) {
|
||||
@@ -762,4 +763,51 @@ public class PurchasesRules extends QueryRules {
|
||||
return idRiga;
|
||||
|
||||
}
|
||||
|
||||
public static void checkBarcodeArt(Connection conn, VtbListData entity) throws Exception {
|
||||
boolean active = setupGest.getSetupBoolean(conn, "VTB_LIST", "SETUP", "CHECK_BARCODE_ART");
|
||||
if (!active) return;
|
||||
|
||||
List<String> codMartList = entity.getMtbLisvData()
|
||||
.stream()
|
||||
.filter(x -> x.getOperation() != OperationType.DELETE)
|
||||
.map(MtbLisvData::getCodMart)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (codMartList.isEmpty()) return;
|
||||
|
||||
String sql = String.format(
|
||||
"SELECT cod_mart,\n" +
|
||||
" descrizione,\n" +
|
||||
" CAST(IIF(bar_code IS NULL OR LTRIM(RTRIM(bar_code)) = '' AND\n" +
|
||||
" plu IS NULL OR LTRIM(RTRIM(plu)) = '', 1, 0) AS BIT) AS has_empty_barcode\n" +
|
||||
"FROM mtb_aart\n" +
|
||||
"WHERE cod_mart in (%s)",
|
||||
UtilityDB.listValueToString(codMartList)
|
||||
);
|
||||
|
||||
List<HashMap<String, Object>> resultQuery = UtilityDB.executeSimpleQuery(conn, sql);
|
||||
|
||||
List<String> artWithoutBarcode = new ArrayList<>();
|
||||
|
||||
if (!resultQuery.isEmpty()) {
|
||||
for (HashMap<String, Object> map : resultQuery) {
|
||||
boolean emptyBarcode = (boolean) map.get("has_empty_barcode");
|
||||
String codMart = (String) map.get("cod_mart");
|
||||
String descrizione = (String) map.get("descrizione");
|
||||
|
||||
if (emptyBarcode) {
|
||||
artWithoutBarcode.add(String.format("%s - %s", codMart, descrizione));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!artWithoutBarcode.isEmpty()) {
|
||||
String message = String.format(
|
||||
"Impossibile salvare gli articoli senza barcode o plu. \n %s",
|
||||
StringUtils.join(artWithoutBarcode, "\n")
|
||||
);
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,4 +408,13 @@ when
|
||||
$entity: DtbOrdt(operation == OperationType.UPDATE && gestione == "L" && !dtbOrdSteps.isEmpty() && flagEvasoProd == "E" && flagEvasoForzato == "S")
|
||||
then
|
||||
ProductionsRules.checkCanCloseOrder(conn, $entity);
|
||||
end
|
||||
|
||||
rule "checkBarcodeArt"
|
||||
no-loop
|
||||
when
|
||||
eval(checkRulesEnabled)
|
||||
$entity : VtbListData(operation != OperationType.DELETE)
|
||||
then
|
||||
PurchasesRules.checkBarcodeArt(conn, $entity);
|
||||
end
|
||||
Reference in New Issue
Block a user