<?php

namespace App\QuickReports\PivotTables\Data;

class SupplierInvoiceRows extends GeneralAbstract
{

	/**
	 * A list of all the available columns for the current pivot source.
	 * @var array
	 */
	protected $allAvailableColumns = [
		'invoiceDate', 'invoiceDateY', 'invoiceDateM', 'invoiceDateYM',
		'dueDate', 'dueDays', 'dueDateY', 'dueDateM', 'dueDateYM', 'statusOp',
		'rowType', 'rowValOrg', 'rowVatOrg', 'rowTtlOrg', 'currency',
		'rowValDef', 'rowVatDef', 'rowTtlDef', 'rowValWrk', 'rowVatWrk', 'rowTtlWrk', 'rowVatPercent', 'rowVatText',
		'idSupplier', 'supplierCountryCode', 'serviceCode', 'invoiceIdUser', 'invoiceIdOffice',
		'payedStatus', 'payedOrg', 'payedDef', 'payedWrk',
		'duePayOrg', 'duePayDef', 'duePayWrk', 'payDate', 'payDays',
	]; // OTHER COLS (not used): id


	/**
	 * {@inheritDoc}
	 * @see \App\QuickReports\PivotTables\Data\GeneralAbstract::getDbTable()
	 */
	protected function getDbTable()
	{
		global $DBTPivotTablesData_supplierInvoiceRows;
		return $DBTPivotTablesData_supplierInvoiceRows;
	}

	public function getColumnDisplayValue($column, $value)
	{
		switch ($column) {

			// date fields
			case 'invoiceDate': case 'dueDate': case 'payDate': {
				return \Engine\DateTime::isoToStd($value);
			}

			case 'invoiceDateM': case 'dueDateM': {
				$_LANG = \App\Loader_Lang::getInstance()->getGlobal();
				return $_LANG['date']['month']['short'][$value];
			}
			case 'invoiceDateYM': case 'dueDateYM': {
				$_LANG = \App\Loader_Lang::getInstance()->getGlobal();
				$y = floor($value/100);
				$m = $value % 100;
				return $_LANG['date']['month']['short'][$m].' '.$y;
			}

			case 'statusOp': {
				$_LANG = \App\Loader_Lang::getInstance()->getGlobal();
				return $_LANG['supplierInvoices']['statusOp'][$value];
			}

			// entity fields
			case 'idSupplier': {
				return \Entity\Supplier::select($value)->alias;
			}
			case 'supplierCountryCode': {
				return \Entity\Country::select($value)->name;
			}
			case 'invoiceIdUser': {
				return \Entity\User::select($value)->name;
			}
			case 'invoiceIdOffice': {
				return \Entity\Office::select($value)->name;
			}

			// others
			case 'rowType': {
				$_LANG = \App\Loader_Lang::getInstance()->getGlobal();
				return $_LANG['rowType'][$value];
			}
			case 'payedStatus': {
				$_LANG = \App\Loader_Lang::getInstance()->getGlobal();
				return $_LANG['supplierInvoices']['statusFin'][$value];
			}
			case 'serviceCode': {
				return \App\Config\Services_Basic::getInstance()->getServiceName($value);
			}
			case 'rowVatPercent': {
				return $value.'%';
			}

			default: {
				return parent::getColumnDisplayValue($column, $value);
			}
		}

	}

}
