<?php

namespace App\Reports\Sources\SupplierInvoices;

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 = [
		'supplierBankAccountNumber', 'supplierBankAccountBankId', 'supplierBankAccountBankName',
		'supplierBankAccountBankOfficeId', 'supplierBankAccountBankOfficeName',
	];

	/**
	 * {@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['supplierBankAccountId']) {

			$suppObj = new \App\ReportsData\EntityFields\Supplier($currentRow['supplierOriginalId']);
			$suppBas = $suppObj->getValue('bankAccounts');
			$baDet = $suppBas[$currentRow['supplierBankAccountId']];

			if ($suppBas and $baDet) {
				if ($tableColumns['supplierBankAccountNumber']) {
					$updateColumns['supplierBankAccountNumber'] = $baDet['account'];
				}
				if ($tableColumns['supplierBankAccountBankId']) {
					$updateColumns['supplierBankAccountBankId'] = $baDet['idBank'];
				}
				if ($tableColumns['supplierBankAccountBankName'] and $baDet['idBank']) {
					$bankObj = new \App\ReportsData\EntityFields\Bank($baDet['idBank']);
					$updateColumns['supplierBankAccountBankName'] = $bankObj->getValue('nameStd');
				}
				if ($tableColumns['supplierBankAccountBankOfficeId']) {
					$updateColumns['supplierBankAccountBankOfficeId'] = $baDet['idBankOffice'];
				}
				if ($tableColumns['supplierBankAccountBankOfficeName'] and $baDet['idBankOffice']) {
					$bankOffObj = new \App\ReportsData\EntityFields\BankOffice($baDet['idBankOffice']);
					$updateColumns['supplierBankAccountBankOfficeName'] = $bankOffObj->getValue('nameStd');
				}
			}
		}

		return $updateColumns;

	}

}
