<?php

namespace App\Reports\Sources\SupplierInvoiceRows;

class PopulateLoopRecords extends \App\Reports\Sources\PopulateLoopRecordsAbstract
{

	/**
	 * These are the standard columns that we expect are filled in during the loop records. The list
	 * may not contain anyting
	 * @var array
	 */
	protected array $processStandardColumns = [
		'supp_bankAccountNumber', 'supp_bankAccountBankId', 'supp_bankAccountBankName',
		'supp_bankAccountBankOfficeId', 'supp_bankAccountBankOfficeName',
	];

	/**
	 * {@inheritDoc}
	 * @see \App\Reports\Sources\PopulateLoopRecordsAbstract::updateReportStdColumns()
	 */
	protected function updateReportStdColumns(array $currentRow) :array
	{

		// loads all the standard columns from
		$tableColumns = $this->columnsManager->getStdColumns();

		$updateColumns = [];

		// collect supplier bank account details
		if ($currentRow['supp_bankAccountId']) {

			$suppObj = new \App\ReportsData\EntityFields\Supplier($currentRow['supp_originalId']);
			$suppBas = $suppObj->getValue('bankAccounts');
			$baDet = $suppBas[$currentRow['supp_bankAccountId']];
			if ($suppBas and $baDet) {
				if ($tableColumns['supp_bankAccountNumber']) {
					$updateColumns['supp_bankAccountNumber'] = $baDet['account'];
				}
				if ($tableColumns['supp_bankAccountBankId']) {
					$updateColumns['supp_bankAccountBankId'] = $baDet['idBank'];
				}
				if ($tableColumns['supp_bankAccountBankName'] and $baDet['idBank']) {
					$bankObj = new \App\ReportsData\EntityFields\Bank($baDet['idBank']);
					$updateColumns['supp_bankAccountBankName'] = $bankObj->getValue('nameStd');
				}
				if ($tableColumns['supp_bankAccountBankOfficeId']) {
					$updateColumns['supp_bankAccountBankOfficeId'] = $baDet['idBankOffice'];
				}
				if ($tableColumns['supp_bankAccountBankOfficeName'] and $baDet['idBankOffice']) {
					$bankOffObj = new \App\ReportsData\EntityFields\BankOffice($baDet['idBankOffice']);
					$updateColumns['supp_bankAccountBankOfficeName'] = $bankOffObj->getValue('nameStd');
				}
			}
		}

		return $updateColumns;

	}

}
