////////////////////////////////////////////////////////////////////////////////
// General hooks for dbs | invoice
// File-Encoding: UTF-8 without BOM( Test: ü,ä,ö )
//------------------------------------------------------------------------------
// Created/Edited       | Description
//------------------------------------------------------------------------------
// 08.2017              | dbs | invoice workflow 1.1.0
////////////////////////////////////////////////////////////////////////////////

//------------------------------------------------------------------------------
// InsertEntry10
//------------------------------------------------------------------------------
// dbs.invoice specific hooks
//------------------------------------------------------------------------------
proc InsertEntry10( pUser, pDocTypeShort )
{
   vars lReturnValue = 0
   lReturnValue = InsertEntry10_dbsInvoice( pUser, pDocTypeShort )
   
   if( lReturnValue != 0 )
   {
      return lReturnValue
   } 
   
     
   
} //end of InsertEntry10

//------------------------------------------------------------------------------
// InsertExit30
//------------------------------------------------------------------------------
// dbs.invoice specific hooks
//------------------------------------------------------------------------------
proc InsertExit30( pDocId, pFileDestination, pImportOk, pUser, pDocTypeShort )
{
	call InsertExit30_dbsInvoice( pDocId, pFileDestination, pImportOk, pUser, pDocTypeShort )
	
} //end of InsertExit30


//------------------------------------------------------------------------------
// UpdateAttribEntry20
//------------------------------------------------------------------------------
//  Vorbereitung Start Rückfrage-WFL für Rechnungen, die aus dem NAV per upd-Datei
//  in den Bemerkungsfeldern 1 & 2 eine Rückfrage übergeben wurde.
//  Nicht dbs Invoice!!!
//------------------------------------------------------------------------------
proc UpdateAttribEntry20( pDocId, pUser, pDocTypeShort, pDocTypeShortNew )
{
	/*
    //if (pDocTypeShort == gDTS_INVOICE && text[1] != "" && text[2] != "" )
    if (pDocTypeShort == gDTS_INVOICE && dok_dat_feld[gDDF_DEPARTMENT] != "" && dok_dat_feld[gDDF_DESCRIPTION] != "" )
	{
        vars lEmpfaenger = dok_dat_feld[gDDF_DEPARTMENT]  //text[1]
        vars lNotiztext = dok_dat_feld[gDDF_DESCRIPTION] // text[2]
		
        //Schreiben der Empfaengergruppe in ddf 20
        dok_dat_feld[gDDF_DEPARTMENT] = lEmpfaenger
        //Rückfragetext in die Notiz eintragen
		SERVER_API_NO_HOOKS = 1
        vars lRueckgabe = api_function("note_add_string",lNotiztext, pDocId, "Master")
		SERVER_API_NO_HOOKS = 0
        //msg emsg "lRuckgabe Notiz schreiben :lRueckgabe"
        //msg emsg "lEmpfaenger :lEmpfaenger ddf20 :dok_dat_feld[20]"
    }
	*/
}


//------------------------------------------------------------------------------
// UpdateAttribExit20
//------------------------------------------------------------------------------
//  dbs.invoice specific hooks
//------------------------------------------------------------------------------
proc UpdateAttribExit20( pDocId, pErrorNumber, pUser, pDocTypeShort )
{
	call UpdAttribExit20_dbsInvoice( pDocId, pErrorNumber, pUser, pDocTypeShort )
	
	if (pDocTypeShort == gDTS_INVOICE && dok_dat_feld[gDDF_DEPARTMENT] != "" && dok_dat_feld[gDDF_DESCRIPTION] != "")
	{	
		//ID des Rückfrage-Workflows
		vars lWflId = "14q28erod7ov9u3o155ahkn3kh"
		//Rechnung bereits im WFL?
		//vars lLeitwegAktiv = api_function("workpath_get_document_info", pDocId, "Master")
		vars lLeitwegAktiv = api_function("attribute_get_all", pDocId, "Master")
		//msg emsg "LeitwegAktiv = :lLeitwegAktiv"
		//if (pDocTypeShort == gDTS_INVOICE && text[1] != "" && text[2] != "" && lLeitwegAktiv == -523 )
			
		if ( api_doc_workflow == 0 )
		{
			vars lEmpfaenger = dok_dat_feld[gDDF_DEPARTMENT]  //text[1]
			vars lNotiztext = dok_dat_feld[gDDF_DESCRIPTION] // text[2]
			
			//Schreiben der Empfaengergruppe in ddf 20
			//dok_dat_feld[gDDF_DEPARTMENT] = lEmpfaenger
			//Rückfragetext in die Notiz eintragen
			SERVER_API_NO_HOOKS = 1
			vars lRueckgabe = api_function("note_add_string",lNotiztext, pDocId, "Master")
			SERVER_API_NO_HOOKS = 0
			//msg emsg "lRuckgabe Notiz schreiben :lRueckgabe"
			//msg emsg "lEmpfaenger :lEmpfaenger ddf20 :dok_dat_feld[20]"
			
			vars lRueckgabe = api_function("workpath_start_document", lWflId, pDocId, "" )
			if (lRueckgabe == 0)
			{
				call api_log_info("Rueckfrage-WFL fuer Dokument :pDocId erfolgreich gestartet")
				//call api_log_info("Rueckfrage-WFL :pDocId gDDF_DEPARTMENT :dok_dat_feld[gDDF_DEPARTMENT] gDDF_DESCRIPTION :dok_dat_feld[gDDF_DESCRIPTION]")
			}
			else
			{
				call api_log_error("FEHLER :lRueckgabe Rueckfrage-WFL konnte für Dokument :pDocId nicht gestartet werden!!!")
			}
		}
		SERVER_API_NO_HOOKS = 1
		call api_function("attribute_update_single", gDDF_DEPARTMENT, "",0, pDocId, "Master")
		call api_function("attribute_update_single", gDDF_DESCRIPTION, "",0, pDocId, "Master")
		SERVER_API_NO_HOOKS = 0
	}
	
}// end  of UpdateAttribExit20

//------------------------------------------------------------------------------
// LinkExit10
//------------------------------------------------------------------------------
//  dbs.invoice specific hooks
//------------------------------------------------------------------------------
proc LinkExit10( pDocIdFather, pDocIdChild, pErrorCode, pErrorNumber )
{
	call LinkExit10_dbsInvoice( pDocIdFather, pDocIdChild, pErrorCode, pErrorNumber )
}// end  of LinkExit10