<?php
 $loopRecColumns = [ 'supp_bankAccountNumber', 'supp_bankAccountBankId', 'supp_bankAccountBankName', 'supp_bankAccountBankOfficeId', 'supp_bankAccountBankOfficeName', ]; 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['supp_bankAccountNumber'] or $tableColumns['supp_bankAccountBankId'] or $tableColumns['supp_bankAccountBankName'] or $tableColumns['supp_bankAccountBankOfficeId'] or $tableColumns['supp_bankAccountBankOfficeName']) and $thisRow['supp_bankAccountId'] ) { $suppObj = new \App\ReportsData\EntityFields\Supplier($thisRow['supp_originalId']); $suppBas = $suppObj->getValue('bankAccounts'); $baDet = $suppBas[$thisRow['supp_bankAccountId']]; if ($suppBas and $baDet) { if ($tableColumns['supp_bankAccountNumber']) { $updateColumns['supp_bankAccountNumber'] = $baDet['account']; } if ($tableColumns['supp_bankAccountBankId']) { $updateColumns['supp_bankAccountBankId'] = $baDet['idBank']; } if ($tableColumns['supp_bankAccountBankName'] and $baDet['idBank']) { $bankObj = new \App\ReportsData\EntityFields\Bank($baDet['idBank']); $updateColumns['supp_bankAccountBankName'] = $bankObj->getValue('nameStd'); } if ($tableColumns['supp_bankAccountBankOfficeId']) { $updateColumns['supp_bankAccountBankOfficeId'] = $baDet['idBankOffice']; } if ($tableColumns['supp_bankAccountBankOfficeName'] and $baDet['idBankOffice']) { $bankOffObj = new \App\ReportsData\EntityFields\BankOffice($baDet['idBankOffice']); $updateColumns['supp_bankAccountBankOfficeName'] = $bankOffObj->getValue('nameStd'); } } } if ($updateColumns) { $colsList = implode(', ', array_map(function($col){ return "`{$col}` = ?"; }, array_keys($updateColumns))); $updateRecordSQL = "UPDATE `$reportTable` SET {$colsList} WHERE inv_id='".$thisRow['inv_id']."'"; $updateRecordEx = $db->Execute($updateRecordSQL, array_values($updateColumns)); if ($db->ErrorNo()) { killReport("Could not run SQL in report. SQL: ".$updateRecordSQL); } } } } unset($recordsList); 