174 lines
6.7 KiB
Groovy
174 lines
6.7 KiB
Groovy
import com.dvelop.d3.server.Condition
|
|
import com.dvelop.d3.server.Document
|
|
import com.dvelop.d3.server.DocumentType
|
|
import com.dvelop.d3.server.DocumentVersion
|
|
import com.dvelop.d3.server.PhysicalVersion
|
|
import com.dvelop.d3.server.Entrypoint
|
|
import com.dvelop.d3.server.RepositoryField
|
|
import com.dvelop.d3.server.User
|
|
import com.dvelop.d3.server.UserGroup
|
|
import com.dvelop.d3.server.UserOrUserGroup
|
|
import com.dvelop.d3.server.Document.DocStatus
|
|
import com.dvelop.d3.server.core.D3Interface
|
|
import com.dvelop.d3.server.exceptions.D3Exception
|
|
|
|
import groovy.sql.GroovyRowResult
|
|
import groovy.sql.Sql
|
|
|
|
|
|
|
|
|
|
|
|
public class Hooks
|
|
{
|
|
|
|
|
|
@Entrypoint( entrypoint = "hook_insert_entry_10" )
|
|
public int hookInsertEntry10(D3Interface d3, User user, DocumentType docType, Document doc)
|
|
{
|
|
d3.log.info("START | hookInsertEntry10 ");
|
|
|
|
//////////////////////////////////////////////////
|
|
// Prüfung, ob Ablage erlaubt ist / Geräte-/Produktakte | calb d.velop 2025.12.17 START
|
|
|
|
|
|
// Zu einer Position darf es nur eine Geräte oder Produktakte geben - nicht beide gleichzeitig.
|
|
// Da die Dokumentarten nach Akte aufgeteilt sind, kann man also prüfen, ob bei einer Ablage eines Dokuments in die Produktakte bereits eine entsprechende Geräteakte existiert, und - falls ja - die Ablage ablehnen. (Umgekehrt natürlich genauso.)
|
|
// Diese Logik wird benötigt, weil die Kollegen die Dokumentart während der Ablage ändern könnten.
|
|
|
|
String dokumentarten_produktakte = "DBESC;DCSTR;DEAUS;DDBLT;DERST;DGSPZ;DHAND;DKAEL;DKONF;DSOND;DSTRO;DWINP;DWINS;DZPRO";
|
|
String dokumentarten_geraeteakte = "DCHEA;DCHEP;DCHLP;DCHEC;DDFAD;DLAUF;DPDK1;DPDK2;DPDK3;DPDW1;DPDW2;DPDW3;DPRSP;DPR01;DTYPD;DTYPS;DVSAK";
|
|
String dokumentarten_auftrag_sap = "DCONO;SCONO;SINVO;SCORD;SDENO;SMSDP;SDSW;SSVRP;";
|
|
|
|
|
|
String such_aktenart = "";
|
|
String aktenname = "";
|
|
def do_it = false;
|
|
String sqlStatement = "";
|
|
|
|
if ( dokumentarten_produktakte.contains( docType.id() ) )
|
|
{
|
|
// Es handelt sich um eine Produktakten-Dokumentart, daher darf keine Geraeteakte existieren
|
|
do_it = true;
|
|
such_aktenart = "AGAKE";
|
|
aktenname = "Geraeteakte Kundeneinzel";
|
|
doc.status = Document.DocStatus.DOC_STAT_RELEASE;
|
|
}
|
|
|
|
if ( dokumentarten_geraeteakte.contains( docType.id() ) )
|
|
{
|
|
// Es handelt sich um eine Geraeteakten-Dokumentart, daher darf keine Produktakte existieren
|
|
do_it = true;
|
|
such_aktenart = "APRKE";
|
|
aktenname = "Produktakte Kundeneinzel";
|
|
doc.status = Document.DocStatus.DOC_STAT_RELEASE;
|
|
}
|
|
|
|
if ( dokumentarten_auftrag_sap.contains( docType.id() ) )
|
|
{
|
|
doc.status = Document.DocStatus.DOC_STAT_RELEASE;
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( do_it )
|
|
{
|
|
// DDF22: Vertriebsbelegposition DDF60: Auftrags-Nr.
|
|
sqlStatement = "select doku_id from firmen_spezifisch where kue_dokuart = '" + such_aktenart + "' and dok_dat_feld_22 = '" + doc.field[ 22 ] + "' and doku_id in ( select doku_id from firm_spez_mult_val where value_char = '" + doc.field[ 60 ][ 1 ] + "' and field_no = 60 )";
|
|
|
|
def rows = d3.sql.executeAndGet( sqlStatement );
|
|
|
|
if ( rows.size() > 0 )
|
|
{
|
|
// Es wurde ein Treffer gefunden => Fehler
|
|
d3.hook.setProperty( "additional_info_text", "Da eine Akte vom Typ " + aktenname + " mit den Eigenschaften Auftrags-Nr. " + doc.field[ 60 ][ 1 ] + " / Vertriebsbelegposition " + doc.field[ 22 ] + " bereits existiert, ist eine Ablage dieses Dokuments in dieser Dokumentart nicht erlaubt." );
|
|
return -142;
|
|
}
|
|
}
|
|
|
|
|
|
// Prüfung, ob Ablage erlaubt ist / Geräte-/Produktakte | calb d.velop 2025.12.17 ENDE
|
|
//////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
// Prüfung ob Doppelablage bei Dokumentarten, bei denen das nicht vorgesehen ist / Geräte-/Produktakte | calb d.velop 2025.12.17 START
|
|
|
|
// Bei den hier angegebenen Dokumentarten der Produkt-/Geräteakte sind nur eindeutige Dokumente erlaubt, d.h. pro Auftrags-Nr., Vertriebsbelegposition darf es nur ein Dokument pro Dokumentart geben
|
|
|
|
|
|
String dokumentarten_produktakte_pruef = "DBESC;DCSTR;DEAUS;DDBLT;DERST;DGSPZ;DHAND;DKAEL;DKONF;DSTRO;DWINP;DWINS";
|
|
|
|
if ( dokumentarten_produktakte_pruef.contains( docType.id() ) )
|
|
{
|
|
// DDF22: Vertriebsbelegposition DDF60: Auftrags-Nr.
|
|
sqlStatement = "select doku_id from firmen_spezifisch where kue_dokuart = '" + docType.id() + "' and dok_dat_feld_22 = '" + doc.field[ 22 ] + "' and doku_id in ( select doku_id from firm_spez_mult_val where value_char = '" + doc.field[ 60 ][ 1 ] + "' and field_no = 60 )";
|
|
|
|
def rows = d3.sql.executeAndGet( sqlStatement );
|
|
|
|
if ( rows.size() > 0 )
|
|
{
|
|
// Es wurde ein Treffer gefunden => Fehler
|
|
d3.hook.setProperty( "additional_info_text", "Fuer die Auftrags-Nr. " + doc.field[ 60 ][ 1 ] + " / Vertriebsbelegposition " + doc.field[ 22 ] + " existiert bereits ein Dokument in dieser Dokumentart (Doku-ID " + rows[ 0 ].doku_id + " )." );
|
|
return -142;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String dokumentarten_geraeteakte_pruef = "DCHEA;DCHEP;DCHLP;DCHEC;DDFAD;DLAUF;DPDK1;DPDK2;DPDK3;DPDW1;DPDW2;DPDW3;DPRSP;DPR01;DTYPD;DTYPS;DVSAK";
|
|
|
|
// Eindeutig: Dokumentart, Auftrags-Nr., Vertriebsbelegposition, Materialnummer, Fertigungsauftragsnummer und, wenn angegeben, Serialnummer
|
|
if ( dokumentarten_geraeteakte_pruef.contains( docType.id() ) )
|
|
{
|
|
def where = "";
|
|
def meld = "";
|
|
|
|
if ( doc.field[ 24 ] )
|
|
{
|
|
where = " and dok_dat_feld_24 = '" + doc.field[ 24 ] + "'";
|
|
meld = " / Serialnummer " + doc.field[ 24 ] + " ";
|
|
}
|
|
|
|
|
|
// DDF22: Vertriebsbelegposition DDF60: Auftrags-Nr. DDF21: Materialnummer DDF26: Fertigungsauftragsnummer DDF24 Serialnummer
|
|
sqlStatement = "select doku_id from firmen_spezifisch where kue_dokuart = '" + docType.id() + "' and dok_dat_feld_22 = '" + doc.field[ 22 ] + "' and dok_dat_feld_21 = '" + doc.field[ 21 ] + "' and dok_dat_feld_26 = '" + doc.field[ 26 ] + "' and doku_id in ( select doku_id from firm_spez_mult_val where value_char = '" + doc.field[ 60 ][ 1 ] + "' and field_no = 60 ) " + where;
|
|
|
|
def rows = d3.sql.executeAndGet( sqlStatement );
|
|
|
|
if ( rows.size() > 0 )
|
|
{
|
|
// Es wurde ein Treffer gefunden => Fehler
|
|
d3.hook.setProperty( "additional_info_text", "Fuer die Auftrags-Nr. " + doc.field[ 60 ][ 1 ] + " / Vertriebsbelegposition " + doc.field[ 22 ] + " / Materialnummer " + doc.field[ 21 ] + " / Materialnummer " + doc.field[ 26 ] + meld + " existiert bereits ein Dokument in dieser Dokumentart (Doku-ID " + rows[ 0 ].doku_id + " )." );
|
|
return -142;
|
|
}
|
|
}
|
|
|
|
// Prüfung ob Doppelablage bei Dokumentarten, bei denen das nicht vorgesehen ist / Geräte-/Produktakte | calb d.velop 2025.12.17 ENDE
|
|
//////////////////////////////////////////////////
|
|
|
|
d3.log.info("ENDE | hookInsertEntry10 ");
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|