<?php

namespace App\Reports\Sources\SupplierContactPersons;

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

	public function populate() :void
	{

		global $DBTRd_suppliers, $DBTRd_users, $DBTRd_offices;

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

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

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

		// EXTRA COLUMNS //////////////////////////////////////////////////////////////////////////

		$this->reportGenerationStatusUpdate('extractMainDataFromDb', 'updateContactDetails', 0);

		// update the title name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addCaseStructureColumn("contact_titleName", "contact_titleCode", (Array)$_LANG['generalData']['personTitles']);
		$reportCopyInfo->populate();

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

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

		$this->reportGenerationStatusUpdate('extractMainDataFromDb', 'updateSupplierDetails', 0);

		// update the supplier info
		$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_companyPrefix'	=> 'supp.companyPrefix',
			'supp_companySuffix'	=> 'supp.companySuffix',
		];
		$reportCopyInfo->setStructureColumns($cols);
		$reportCopyInfo->addStructureColumn("supp_companyFull", 		"TRIM(CONCAT(supp.companyName, ' ', supp.companySuffix))", "supp");
		$reportCopyInfo->populate();

	}

}

