// // korrigiere_DVREC.jpl // // 2012.02.24 alch // // V0.1 initiale Version // // Dieses Skript soll Kostenstellen nach Innenaufträge zuordnen. // Normalerweise wird dies von einem Hook während des Imports erledigt; dieser war aber offenbar nicht in "the condition to make". :-( // // // Kunde: BuW, Fr. Luther // call korrigiere_DVREC() proc korrigiere_DVREC() { call xlog( 4, "*******************************************************" ) call xlog( 4, "* korrigiere_DVREC.jpl " ) call xlog( 4, "* von Christian Albers " ) call xlog( 4, "* (c) 2012 d.velop process Solutions GmbH " ) call xlog( 4, "*******************************************************" ) //call xlog( 4, "" ) //call xlog( 4, "*******************************************************" ) vars DVREC[4000] vars ergebnis vars doku_id, P_doc_id vars zaehler = 0 vars v_kostenstelle, tmp_innenauftrag, v_retVal, v_changed, v_pos_counter, i, db_pos_innenauftrag dbms declare cursor work for \ select f.doku_id from firmen_spezifisch f, phys_datei p where f.doku_id = p.doku_id and f.kue_dokuart = 'DVREC' and p.datum_einbring > '10.01.2011' and p.datum_einbring < '02.24.2012' order by doku_id dbms with cursor work alias doku_id dbms WITH CURSOR work EXECUTE while ( @dmrowcount > 0 ) { zaehler = zaehler + 1 DVREC[ zaehler ] = doku_id dbms with cursor work continue } dbms alias // Jetzt stehen alle möglicherweise zu bearbeitenden Doku-IDs in DVREC[] // for i = 1 while i <= zaehler step 1 { P_doc_id = DVREC[ i ] db_pos_innenauftrag = "65" call xlog( 4, "bearbeite Zeile :i - Doku-ID : :P_doc_id " ) call api_clear_document_context() // Merken, ob Attribute geaendert wurden v_changed = 0 // Aktuelle Attribute ermitteln v_retVal = api_function( "attribute_get_all", P_doc_id, "" ) if ( v_retVal == 0 ) { if ( @length(db_pos_innenauftrag) == 2) { for v_pos_counter = 1 while ( v_pos_counter <= 100 ) step 1 { if ( api_doc_field_:(db_pos_innenauftrag)[v_pos_counter] != "" && api_doc_field_64[v_pos_counter] == "") { tmp_innenauftrag = AddiereFuehrendeNullen( api_doc_field_:(db_pos_innenauftrag)[v_pos_counter] , 12 ) //call xlog( 4, " 5 hook_upd_attrib_exit_20_dps P_doc_id: :P_doc_id tmp_innenauftrag :tmp_innenauftrag " ) DBMS ALIAS v_kostenstelle DBMS SQL \ SELECT kst \ FROM dos_ia_kst (NOLOCK) \ WHERE ia = :+tmp_innenauftrag //call xlog( 4, " 6 hook_upd_attrib_exit_20_dps P_doc_id: :P_doc_id v_kostenstelle :v_kostenstelle " ) if ( @dmrowcount > 0 ) { api_doc_field_64[v_pos_counter] = EntferneFuehrendeNullen( v_kostenstelle ) call xlog( 4, "P_doc_id: :P_doc_id api_doc_field_64[ :v_pos_counter ] :api_doc_field_64[v_pos_counter] " ) v_changed = 1 } else { //call api_log_error("Keine Kostenstelle zum Innenauftrag :tmp_innenauftrag gefunden" ) call xlog( 2, "P_doc_id: :P_doc_id Keine Kostenstelle zum Innenauftrag :tmp_innenauftrag gefunden" ) } DBMS ALIAS } else { //call xlog( 4, "Kostenstelle bereits gefüllt." ) } } } // Nur wenn Attribute geaendert wurden, dann alle speichern if ( v_changed == 1 ) { //v_retVal = api_function( "attribute_update_all", P_doc_id, "" ) v_retVal = 0 if ( v_retVal != 0 ) { api_doc_field[70] = FormatiereGeld( api_doc_field[70] ) call xlog( 3, "Noch mal (:P_doc_id) mit Betrag :api_doc_field[70]") //v_retVal = api_function( "attribute_update_all", P_doc_id, "" ) v_retVal = 0 if ( v_retVal != 0 ) { call xlog( 2, "Dokumentattribute zu :P_doc_id konnten nicht gespeichert werden") } else { call xlog( 4, "Attribute zu :P_doc_id wurden gespeichert." ) } } else { call xlog( 4, "Attribute zu :P_doc_id wurden gespeichert." ) } } else { call xlog( 4, "keine Änderungen, keine Speicherungen." ) } } else { call xlog( 2, "Dokumentattribute zu :P_doc_id konnten nicht ermittelt werden") } call xlog( 4, "*******************************************************" ) } call xlog( 4, "korrigiere_DVREC.jpl beendet sich ..." ) } global vars g_loglevel = 5 global vars g_logdatei = "D\:\\d3\\apps\\korrigiere_DVREC\\korrigiere_DVREC.log" // Legt fest, wohin geloggt werden soll: DATEI => nur Datei, D3LOG => d.3 Log, BEIDE => sowohl FILE als auch D3LOG global vars g_logdirect = "DATEI" // call xlog( 4, "Hello World!" ) proc xlog( loglevel, message ) { vars zeitstempel, loglevel_lang, d3loglevel, logmessage if ( loglevel == 5 ) { loglevel_lang = "DEBUG" // Da die d.3 Server i.d.R. nicht im Debug-Modus laufen, erscheinen DEBUG-Meldungen nicht im Log. d3loglevel = 9 } if ( loglevel == 4 ) { loglevel_lang = "INFO." d3loglevel = 6 } if ( loglevel == 3 ) { loglevel_lang = "WARN." d3loglevel = 6 } if ( loglevel == 2 ) { loglevel_lang = "ERROR" d3loglevel = 0 } if ( loglevel == 1 ) { loglevel_lang = "FATAL" d3loglevel = 0 } if ( loglevel <= g_loglevel ) { if ( ( g_logdirect == "DATEI" ) || ( g_logdirect == "BEIDE" ) ) { // Ausgabe in Datei zeitstempel = sm_sdtime( "n%4y.%0m.%0d %0h\:%0M\:%0s" ) logmessage = zeitstempel ## " " ## loglevel_lang ## " " ## message call api_function( "file_add_line", g_logdatei, logmessage, "APPEND" ) } if ( ( g_logdirect == "D3LOG" ) || ( g_logdirect == "BEIDE" ) ) { // Ausgabe im d.3 Log logmessage = loglevel_lang ## " " ## message call api_log( d3loglevel, logmessage ) } } }