<?php
///////////////////////////////////////////////////////////////////////////////////////////////////
// UPDATE CONTRACT DETAILS/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
refreshReportStatus('processingRecords', 'updateContractDetails', 0);

// update type name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addCaseStructureColumn("cont_typeName", "cont_typeCode", (array)$_LANG['generalData']['contractTypes'] );
$reportCopyInfo->populate();

// update service name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addCaseStructureColumn("cont_serviceName", "cont_serviceCode", \App\Config\Services_Basic::getInstance()->getListLinearSimple());
$reportCopyInfo->populate();

// update responsible user office name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_offices, 'user_respOfficeName', 'user_respIdOffice', 'name');

// update responsible user department name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_departments, 'user_respDepartmentName', 'user_respIdDepartment', 'name');

// add user details
$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addJoinTable($DBTRd_users,		'addUser',		'rep.user_idAddUser=addUser.id',	'LEFT');
$reportCopyInfo->addStructureColumn("user_addUserName", 		"CONCAT(addUser.firstName, ' ', addUser.lastName)", 	"addUser");
$reportCopyInfo->populate();

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


///////////////////////////////////////////////////////////////////////////////////////////////////
// UPDATE CORPORATE DETAILS////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
refreshReportStatus('processingRecords', 'updateCorporateDetails', 0);

$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addJoinTable($DBTRd_corporates,       'corp',        'rep.corp_id=corp.id', 	'LEFT');

$cols = [
	'corp_alias'			=> 'corp.alias',
	'corp_companyName'		=> 'corp.companyNameStd',
	'corp_idSegment'		=> 'corp.idSegment',
	'corp_idAccountManager'	=> 'corp.idAccountManager',
];
$reportCopyInfo->setStructureColumns($cols);
$reportCopyInfo->populate();

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

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


