<?php
refreshReportStatus('extractMainDataFromDb', 'updateOfficeDetails', 0);
// update office country
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_countries, 'office_countryName', 'office_countryCode', 'nameStd', 'code');

// update office city
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_cities, 'office_cityName', 'office_cityId', "nameStd");

// update the office name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_offices, 'office_addOfficeName', 'office_addOfficeId', "name");

// update the update user name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'office_updateUserName', 'office_idUpdateUser', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");

refreshReportStatus('extractMainDataFromDb', 'updateCorporateDetails', 0);

// update the segment name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_corporateSegments, 'corp_segmentName', 'corp_idSegment', 'name');

// update the kam name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'corp_accountManagerName', 'corp_idAccountManager', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");

// update the collection responsible name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'corp_collectionRespName', 'corp_idCollectionResp', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");

// update the trust name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_trusts, 'trust_name', 'trust_id', 'name');

// update the domain name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_activityDomains, 'domain_name', 'domain_id', 'name');

// update the domain category name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_activityDomainCategories, 'domainCategory_name', 'domainCategory_id', 'name');

// update the real corporate info
$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addJoinTable($DBTRd_corporates,	'realCorp',		'rep.realCorp_id=realCorp.id',	'LEFT');
$cols = [
	'realCorp_alias'			=> 'realCorp.alias',
	'realCorp_companyNameStd'	=> 'realCorp.companyNameStd',
	'realCorp_companyNameLoc'	=> 'realCorp.companyNameLoc',
];
$reportCopyInfo->setStructureColumns($cols);
$reportCopyInfo->populate();

// update hasContract info
$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addStructureColumn('corp_hasContract', '(SELECT 1 FROM `'.$DBTRd_corporateContracts.'` WHERE rep.corp_id = idCorporate AND deleted=0 LIMIT 1)', 'rep');
$reportCopyInfo->populate();

// update the add user name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'corp_addUserName', 'corp_idAddUser', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");

// update the update user name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'corp_updateUserName', 'corp_idUpdateUser', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");