<?php

namespace App\Reports\Sources\BalancesList;

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

	public function populate() :void
	{

		// INITS //////////////////////////////////////////////////////////////////////////////////
		global $DBTRd_offices, $DBTRd_departments, $DBTRd_users;

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

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

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

		// EXTRA COLUMNS //////////////////////////////////////////////////////////////////////////
		$this->reportGenerationStatusUpdate('extractMainDataFromDb', 'updateBalanceDetails', 0);

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

		// update the balance reponsible department name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTRd_departments, 'bal_deptName', 'bal_deptId', 'name');

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

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

		// update balance type name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addCaseStructureColumn("bal_typeName",   "bal_typeCode",   (Array)$_LANG['invoiceBalance']['type']);
		$reportCopyInfo->populate();

		// update balance status name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addCaseStructureColumn("bal_statusName", "bal_statusCode", (Array)$_LANG['invoiceBalance']['status']);
		$reportCopyInfo->populate();

	}

}
