<?php

namespace App\EntityList;

class SupplierInvoiceRows extends SupplierInvoices
{

	/**
	 * The class constructor.
	 */
	public function __construct()
	{

		// store the table name (without the YYYYMM terminator)
		global $DBTSupplierInvoices, $DBTSupplierInvoiceRows;
		$this->tableName = $DBTSupplierInvoiceRows;
		$this->tableAlias = 'invRow';
		$this->allowedTables['invRow']=['table'=>$DBTSupplierInvoiceRows, 'type'=>'month'];
		$this->allowedTables['inv']=['table'=>$DBTSupplierInvoices, 'type'=>'month', 'foreignKeyRef'=>'inv.id=invRow.idInvoice', 'joinType'=>'INNER'];

		// run the parent
		GeneralMtAbstract::__construct();

		// set some default column
		$this->setColumn('invRow.id', 'id');
	}

	/**
	 * (non-PHPdoc)
	 * @see \App\EntityList\GeneralMtAbstract::setDefaultFilters()
	 */
	public function setDefaultFilters(): void
	{
		$this->setFilter('inv.deleted', '=', '0');
	}

	/**
	 * Returns an array of yearMonth depending on current filters
	 * @return Array
	 */
	public function getMonthTablesList(): array
	{

		// get the table months if the services were filtered by reservation id
		$tableMonths_idInv1=$this->getMonthTablesList_id(['inv.id']);
		$tableMonths_idInv2=$this->getMonthTablesList_id(['invRow.idInvoice']);
		$tableMonths_idInv3=$this->getMonthTablesList_id(['idInvoice']);

		// get the table months if the services were filtered by reservation date
		$tableMonths_invDate=$this->getMonthTablesList_invoiceDate();

		// intersect the two lists of months
		$tableMonths=array_intersect($tableMonths_idInv1, $tableMonths_idInv2, $tableMonths_idInv3, $tableMonths_invDate);

		return $tableMonths;

	}

	/**
	 * Applys the user access restrictions.
	 * @see \App\EntityList\GeneralMtAbstract::addUserRestrictionFilter()
	 */
	protected function addUserRestrictionFilter()
	{

	}


}

