<?php
 $loopRecColumns = [ 'supplierBankAccountNumber', 'supplierBankAccountBankId', 'supplierBankAccountBankName', 'supplierBankAccountBankOfficeId', 'supplierBankAccountBankOfficeName', ]; if (!array_intersect($availableTableColumns, $loopRecColumns)) { return ; } $recordsCountSQL = "SELECT COUNT(*) FROM `$reportTable`"; $recordsCount = $db->GetOne($recordsCountSQL); $groupSize = 500; for ($startGroup = 0; $startGroup < $recordsCount; $startGroup += $groupSize) { refreshReportStatus('processingRecords', 'loopResults', $startGroup/$recordsCount*100); $getRecordsListSQL = "SELECT * FROM `$reportTable` LIMIT ".$startGroup.", ".$groupSize; $recordsList = $db->GetAll($getRecordsListSQL); if ($db->ErrorNo()) killReport("Could not run SQL in report. SQL: ".$getServicesListSQL); foreach ($recordsList as $thisRow) { $updateColumns = []; if ( ($tableColumns['supplierBankAccountNumber'] or $tableColumns['supplierBankAccountBankId'] or $tableColumns['supplierBankAccountBankName'] or $tableColumns['supplierBankAccountBankOfficeId'] or $tableColumns['supplierBankAccountBankOfficeName']) and $thisRow['supplierBankAccountId'] ) { $suppObj = new \App\ReportsData\EntityFields\Supplier($thisRow['supplierOriginalId']); $suppBas = $suppObj->getValue('bankAccounts'); $baDet = $suppBas[$thisRow['supplierBankAccountId']]; if ($suppBas and $baDet) { if ($tableColumns['supplierBankAccountNumber']) { $updateColumns['supplierBankAccountNumber'] = $baDet['account']; } if ($tableColumns['supplierBankAccountBankId']) { $updateColumns['supplierBankAccountBankId'] = $baDet['idBank']; } if ($tableColumns['supplierBankAccountBankName'] and $baDet['idBank']) { $bankObj = new \App\ReportsData\EntityFields\Bank($baDet['idBank']); $updateColumns['supplierBankAccountBankName'] = $bankObj->getValue('nameStd'); } if ($tableColumns['supplierBankAccountBankOfficeId']) { $updateColumns['supplierBankAccountBankOfficeId'] = $baDet['idBankOffice']; } if ($tableColumns['supplierBankAccountBankOfficeName'] and $baDet['idBankOffice']) { $bankOffObj = new \App\ReportsData\EntityFields\BankOffice($baDet['idBankOffice']); $updateColumns['supplierBankAccountBankOfficeName'] = $bankOffObj->getValue('nameStd'); } } } if ($updateColumns) { $colsList = implode(', ', array_map(function($col){ return "`{$col}` = ?"; }, array_keys($updateColumns))); $updateRecordSQL = "UPDATE `$reportTable` SET {$colsList} WHERE invoiceId='".$thisRow['invoiceId']."'"; $updateRecordEx = $db->Execute($updateRecordSQL, array_values($updateColumns)); if ($db->ErrorNo()) { killReport("Could not run SQL in report. SQL: ".$updateRecordSQL); } } } } unset($recordsList); 