<?php

namespace App\QuickReports\PivotTables\Data;

class OrderServices extends GeneralAbstract
{

	/**
	 * A list of all the available columns for the current pivot source.
	 * @var array
	 */
	protected $allAvailableColumns = [
		'id', 'idOrder', 'orderDate', 'orderDateY', 'orderDateM', 'orderDateYM', 'orderType', 'orderServicesType', 'idMiceProject',
		'orderStartDate', 'orderStartDateY', 'orderStartDateM', 'orderStartDateYM',
		'orderEndDate', 'orderEndDateYM', 'orderEndDateY', 'orderEndDateM',
		'orderIdUser', 'orderIdOffice', 'orderIdDepartment',
		'idExternalSystem', 'pax', 'serviceCode', 'serviceName', 'serviceCategory', 'statusOp', 'statusFin',
		'balanced', 'agencyCostCenter', 'idUser', 'idOffice',
		'ticketsDate', 'ticketsDateY', 'ticketsDateM', 'ticketsDateYM',
		'addDate', 'cancelDate', 'refundDate',
		'offerStartDate', 'offerStartDateYM', 'offerStartDateY', 'offerStartDateM', 'offerDuration',
		'offerEndDate', 'offerEndDateYM', 'offerEndDateY', 'offerEndDateM', 'offerIdSupplier', 'offerIdSupplierProduct',
		'offerDeptCountryCode', 'offerDeptCityId', 'offerDestCountryCode', 'offerDestCityId',
		'offerTotalValueOrg', 'offerProfitValueOrg', 'offerCostValueOrg', 'offerCurrency', 'offerCurrencyType', 'offerCurrencyDate',
		'offerTotalValueDef', 'offerProfitValueDef', 'offerCostValueDef', 'offerTotalValueWrk', 'offerProfitValueWrk', 'offerCostValueWrk',
		'invoiceDate', 'invoiceDateY', 'invoiceDateM', 'invoiceDateYM',
		'invoiceIdCorporate', 'invoiceIdCustomer', 'invoiceClientType', 'invoiceIdUser', 'invoiceIdOffice',
		'invoiceValOrg', 'invoiceVatOrg', 'invoiceTtlOrg', 'invoiceCurrency',
		'invoiceValWrk', 'invoiceVatWrk', 'invoiceTtlWrk',
		'invoiceValDef', 'invoiceVatDef', 'invoiceTtlDef',
		'invoicesCashedStatus', 'invoiceDueDate', 'invoiceCashDate',
		'balanceDate', 'balanceDateY', 'balanceDateM', 'balanceDateYM',
		'balanceVirtualDate', 'balanceVirtualDateY', 'balanceVirtualDateM', 'balanceVirtualDateYM',
		'balanceProfitDef',
	]; // OTHER COLS (not used): idInvoice, idOrder. idBalance, serviceCode


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


	/**
	 * {@inheritDoc}
	 * @see \App\QuickReports\PivotTables\Data\GeneralAbstract::getColumnDisplayValue()
	 */
	public function getColumnDisplayValue($column, $value)
	{

		switch ($column) {

			// date fields
			case 'orderDate': case 'orderStartDate': case 'orderEndDate': case 'offerStartDate': case 'offerEndDate':
			case 'offerCurrencyDate': case 'invoiceDate': case 'invoiceDueDate': case 'invoiceCashDate':
			case 'balanceDate': case 'balanceVirtualDate': case 'ticketsDate':
			case 'addDate': case 'cancelDate': case 'refundDate': {
				return \Engine\DateTime::isoToStd($value);
			}

			case 'orderDateM': case 'orderStartDateM': case 'orderEndDateM': case 'offerStartDateM': case 'offerEndDateM':
			case 'invoiceDateM': case 'balanceDateM': case 'balanceVirtualDateM': case 'ticketsDateM': {
				$_LANG = \App\Loader_Lang::getInstance()->getGlobal();
				return $_LANG['date']['month']['short'][$value];
			}

			case 'orderDateYM': case 'orderStartDateYM': case 'orderEndDateYM': case 'offerStartDateYM':
			case 'offerEndDateYM': case 'invoiceDateYM': case 'balanceDateYM': case 'balanceVirtualDateYM': case 'ticketsDateYM': {
				$_LANG = \App\Loader_Lang::getInstance()->getGlobal();
				$y = floor($value/100);
				$m = $value % 100;
				return $_LANG['date']['month']['short'][$m].' '.$y;
			}

			case 'idMiceProject': {
				return \Entity\MiceProject::select($value)->name;
			}

			case 'orderIdUser': case 'idUser': case 'invoiceIdUser': {
				return \Entity\User::select($value)->name;
			}

			case 'orderIdOffice': case 'idOffice': case 'invoiceIdOffice': {
				return \Entity\Office::select($value)->name;
			}

			case 'orderIdDepartment': {
				return \Entity\Department::select($value)->name;
			}

			case 'idExternalSystem': {
				return \Entity\ExtResSystem::select($value)->name;
			}

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

			case 'invoiceIdCorporate': {
				return \Entity\Corporate::select($value)->alias;
			}

			case 'invoiceIdCustomer': {
				if (\Entity\Customer::select($value)->nameStandard) {
					return \Entity\Customer::select($value)->nameStandard;
				} else {
					return \Entity\Customer::select($value)->nameLocal;
				}
			}

			case 'offerIdSupplier': {
				return \Entity\Supplier::select($value)->alias;
			}

			case 'offerIdSupplierProduct': {
				return \Entity\SupplierProduct::select($value)->productName;
			}

			case 'offerDeptCountryCode': case 'offerDestCountryCode': {
				return \Entity\Country::select($value)->name;
			}

			case 'offerDeptCityId': case 'offerDestCityId': {
				return \Entity\City::select($value)->name;
			}

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

			case 'balanced': {
				$_LANG = \App\Loader_Lang::getInstance()->getGlobal();
				if ($value) return $_LANG['yes'];
				else return $_LANG['no'];
			}

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

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

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

			case 'orderType': {
				return \App\Config\OrderTypes::getInstance()->get($value);
			}

			case 'orderServicesType': {
				return \App\Config\OrderServicesTypes::getInstance()->get($value);
			}

			case 'offerCurrencyType': {
				return \App\Config\CurrencyTypes::getInstance()->getName($value);
			}

			case 'agencyCostCenter': {
				return \App\Config\AgencyCostCenters::getInstance()->getName($value);
			}

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

		}

	}

}
