<?php

namespace App\Reports\Sources\ImportedServices;

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

	public function populate() :void
	{

		global $DBTRd_corporates, $DBTRd_suppliers, $DBTRd_customers, $DBTRd_users, $DBTRd_offices;
		global $DBTRd_importedOrderSystems, $DBTRd_countries, $DBTRd_cities;

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

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

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


		//  UPDATE EXTRA COLUMNS //////////////////////////////////////////////////////////////////

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

		// update the company alias
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_corporates, 'impOrd_corporateOwnerAlias', 'impOrd_idCorporateOwner', "alias");

		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_customers, 'impOrd_customerOwnerName', 'impOrd_idCustomerOwner', "CONCAT(joinTable.lastNameStd, ' ', joinTable.firstNameStd)");

		// update the system name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_importedOrderSystems, 'impOrd_systemName', 'impOrd_idSystem', "name");

		// update the proces status name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addCaseStructureColumn("impServ_processStatusName", "impServ_processStatusCode", (Array)$_LANG['importedService']['statusName']);
		$reportCopyInfo->populate();

		// update the system status name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addCaseStructureColumn("impServ_systemStatusName", "impServ_systemStatusCode", (Array)$_LANG['importedService']['systemStatusName']);
		$reportCopyInfo->populate();

		// update the imp service name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addCaseStructureColumn("impServ_serviceName", "impServ_serviceCode", \App\Config\Services_Basic::getInstance()->getListLinearSimple());
		$reportCopyInfo->populate();

		$this->reportGenerationStatusUpdate('extractMainDataFromDb', 'updateImpServiceDetails', 30);

		// update destination country
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_countries, 'impServ_destinationCountryName', 'impServ_destinationCountryCode', 'nameStd', 'code');

		// update destination city
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_cities, 'impServ_destinationCityName', 'impServ_destinationCityId', "nameStd");

		// update the imp offer supplier name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_suppliers, 'impOff_supplierAlias', 'impOff_idSupplier', "alias");

		// update the imp service form of payment
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addCaseStructureColumn('impOff_offerFormOfPaymentName',  "impOff_offerFormOfPaymentCode", \App\Config\FormsOfPayment::getInstance()->getAll());
		$reportCopyInfo->populate();

		$this->reportGenerationStatusUpdate('extractMainDataFromDb', 'updateImpServiceDetails', 60);

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

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

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

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

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

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

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

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


	}

}

