<?php

namespace App\Reports\Sources\DocsList;

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

	public function populate() :void
	{

		global $DBTRd_docTemplates, $DBTRd_docSeries, $DBTRd_autoProcessRules, $DBTRd_offices, $DBTRd_departments;

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

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

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

		// FILL EXTRA COLUMNS /////////////////////////////////////////////////////////////////////

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

		// update the document type name
		$docNames = [];
		foreach (\App\Config\IssueDocuments::getInstance()->getAll() as $docType=>$docDetails) {
			$docNames[$docType] = $docDetails['name'];
		}
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addCaseStructureColumn("doc_typeName",   "doc_typeCode",   $docNames);
		$reportCopyInfo->populate();

		// update the document template name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_docTemplates, 'doc_templateName', 'doc_idTemplate', 'name');

		// update the document series code
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_docSeries, 'doc_seriesCode', 'doc_idSeries', 'code');

		// update the document auto process rule name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_autoProcessRules, 'doc_autoProcessRuleName', 'doc_idAutoProcessRule', 'name');

		// update the pivot name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addCaseStructureColumn("pivot_name",   "pivot_code",   (Array)$_LANG['documentPivotName']);
		$reportCopyInfo->populate();

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

		// update the document department name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_departments, 'doc_addUserDeptName', 'doc_addUserDeptId', "name");

	}

}
