<?php

namespace App\Reports\Sources\SupplierContracts;

class PopulateQuickColumns extends \App\Reports\Sources\PopulateAbstract
{

	public function populate() :void
	{

		global $DBTRd_users, $DBTRd_offices, $DBTRd_departments, $DBTRd_suppliers, $DBTRd_trusts;

		$_LANG = \App\Loader_Lang::getInstance()->getGlobal();

		$reportTable = $this->tableManager->getTableName();

		$activeColumns = array_keys( $this->columnsManager->getStdColumns() );


		// UPDATE CONTRACT DETAILS/////////////////////////////////////////////////////////////////

		$this->reportGenerationStatusUpdate('processingRecords', 'updateContractDetails', 0);

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

		// update service name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$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, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_offices, 'user_respOfficeName', 'user_respIdOffice', 'name');

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

		// add user details
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$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, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_users, 'user_updateUserName', 'user_idUpdateUser', "CONCAT(joinTable.firstName, ' ', joinTable.lastName)");


		// UPDATE SUPPLIER DETAILS/////////////////////////////////////////////////////////////////
		$this->reportGenerationStatusUpdate('processingRecords', 'updateSupplierDetails', 0);


		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addJoinTable($DBTRd_suppliers,       'supp',        'rep.supp_id=supp.id', 	'LEFT');

		$cols = [
			'supp_alias'			=> 'supp.alias',
			'supp_companyName'		=> 'supp.companyName',
			'supp_idTrust'			=> 'supp.idTrust',
		];
		$reportCopyInfo->setStructureColumns($cols);
		$reportCopyInfo->populate();

		// update supplier trust name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_trusts, 'supp_trustName', 'supp_idTrust', 'name');

	}

}

