Function tfgGetReportFiles

Generates TFG/UFG "wykaz umรณw" JSON payloads (channel PORTAL) for manual upload in the TFG portal. It selects reservations in scope (contracts concluded from 1 July 2026, not older than 28 months), determines the correct operation (NOWEDANE / KOREKTA / ROZWIAZANIE / USUNIECIE) for each one, builds the TFG contract objects from the latest R2_LOG_ZMIAN snapshot, and groups them by operationType in chunked JSON payloads (max 1000 contracts per file). File content is returned in the API response (files[].fileContent) and logged in TFG_REPORTS_HISTORY (TYP=GET_FILES). On success, state is persisted in R2_TFG_REPORTS.

โ„น๏ธ
Prerequisite

Run reservationLog for the reservations first โ€” the report is built from the latest snapshot in R2_LOG_ZMIAN.

โš ๏ธ
Atomic batch

If any reservation fails validation, the call returns status=FAIL, files=[], and no changes are written to R2_TFG_REPORTS. Fix all reported errors and call the function again.

โ„น๏ธ
USUNIECIE (deleted reservation)

When the thick CRM client physically deletes an R2 row, the integration detects it via R2_LOG_ZMIAN (snapshot remains) + missing R2 + prior entry in R2_TFG_REPORTS (scope: DATA_REZERWACJI from 1 July 2026, max 28 months). The payload contains only nrUmowyRezerwacji (from R2_TFG_REPORTS.NR_UMOWY). Deleted before first report โ†’ POMIN.

โš ๏ธ
Reservation status scope & downgrade

Only reservations with R2.STATUS IN ('Sprzedaลผ','Sprzedana','Anulowana') are reported. Reservations in Oferta/Nowa that were never reported are silently skipped (POMIN). However, if a reservation was already sent as active (LAST_OPERATION = NOWEDANE/KOREKTA) and its status is later downgraded to Oferta/Nowa, it raises a blocking validation error (the whole batch fails, status=FAIL) until the operator restores Sprzedana or cancels the reservation (Anulowana โ†’ ROZWIAZANIE).

Arguments

  • params :
        array (
              [ 'idCompany' ]      = ''          // REQUIRED, branch id (= R2.ID_FIRMY)
              [ 'idReservations' ] = array(...)  // OPTIONAL, narrow scope to given ID_R2
            )
        

Returns

  • status - OK | FAIL
  • idCompany - the branch id used
  • summary - counters: NOWEDANE / KOREKTA / ROZWIAZANIE / USUNIECIE / POMIN / ERROR
  • files - list of generated file payloads (name, operationType, correctionReason, liczbaUmow, umowy, fileContent)
  • warnings - soft warnings (e.g. missing IATAโ†’ICAO mapping)
  • errors - array of error records (code, message, idReservation, reservationNumber)

TFG_REPORTS_HISTORY.ODPOWIEDZ: status=OK stores {"files":[...]} (unchanged format); status=FAIL stores the full API response JSON.

Example


  require_once ( 'classUddsOx.php' ) ;

  $udds = new classUddsOx ;
  $udds->customerCode = [your_customerCode] ;
  $udds->login = [your_login] ;
  $udds->password = [your_password] ;
  $udds->serverUrl = 'http://api.dlaoperatora.pl/udds/' ;

  $yourParams = array();
  $yourParams [ 'idCompany' ] = '21624' ;
  $ret = $udds->tfgGetReportFiles ( $yourParams ) ;


Returns $ret =
array ( 'status' => 'OK', 'idCompany' => '21624', 'summary' => array ( 'NOWEDANE'=>2, 'KOREKTA'=>1, 'ROZWIAZANIE'=>0, 'USUNIECIE'=>0, 'POMIN'=>3, 'ERROR'=>0 ), 'files' => array ( array ( 'name'=>'TFG_2026-07-16_13-30-45_NOWEDANE_1.json', 'operationType'=>'NOWEDANE', 'liczbaUmow'=>2, ... ) ), 'errors' => array (), )