<?php

namespace App\Reports\Sources\ClientInvoices;

class ColumnsManager extends \App\Reports\Sources\ColumnsManagerAbstract
{

	/**
	 * The definition of report source columns.
	 * @var array
	 */
	protected array $columnsCfg = [

		'currentRowIndex' =>			[ 'type' => 'numeric',   'dbDef' => "INT UNSIGNED NOT NULL DEFAULT '0'",            'cat' => "general"],
		'invoiceId' =>					[ 'type' => 'numeric',   'dbDef' => "BIGINT UNSIGNED NOT NULL",                     'cat' => "general"],
		'invoiceNumber' =>				[ 'type' => 'numeric',   'dbDef' => "BIGINT UNSIGNED NOT NULL DEFAULT '0'",      	'cat' => "general"],
		'invoiceDate' =>				[ 'type' => 'date',      'dbDef' => "DATE NULL DEFAULT NULL",                       'cat' => "general"],
		'invoiceDateYM' =>				[ 'type' => 'yearMonth', 'dbDef' => "DATE NULL DEFAULT NULL",                       'cat' => "general"],
		'invoiceDateY' =>				[ 'type' => 'year',      'dbDef' => "YEAR NULL DEFAULT NULL",                       'cat' => "general"],
		'invoiceSeriesId' =>			[ 'type' => 'numeric',   'dbDef' => "MEDIUMINT UNSIGNED NOT NULL DEFAULT '0'",      'cat' => "general"],
		'invoiceSeriesCode' =>			[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "general"],
		'invoiceDueDate' =>				[ 'type' => 'date',      'dbDef' => "DATE NULL DEFAULT NULL",                       'cat' => "general"],
		'invoiceDueDateYM' =>			[ 'type' => 'yearMonth', 'dbDef' => "DATE NULL DEFAULT NULL",      			   		'cat' => "general"],
		'invoiceDueDateY' =>			[ 'type' => 'year',      'dbDef' => "YEAR NULL DEFAULT NULL",      			   		'cat' => "general"],
		'invoiceDueDays' =>				[ 'type' => 'numeric',   'dbDef' => "SMALLINT NULL DEFAULT '0'",               	    'cat' => "general"],
		'invoiceDuePassedDays' =>		[ 'type' => 'numeric',   'dbDef' => "MEDIUMINT NOT NULL DEFAULT '0'",               'cat' => "general"],
		'invoiceFulfillmentDate' =>		[ 'type' => 'date',      'dbDef' => "DATE NULL DEFAULT NULL",      			   		'cat' => "general"],
		'invoiceComments' =>			[ 'type' => 'string',    'dbDef' => "TEXT NOT NULL",                              	'cat' => "general"],
		'invoiceRemarks' =>				[ 'type' => 'string',    'dbDef' => "TEXT NOT NULL",                              	'cat' => "general"],
		'invoiceProcessedRemarks' =>	[ 'type' => 'string',    'dbDef' => "TEXT NOT NULL",                              	'cat' => "general", 'disabled' => true, 'content' => 'remarks'],
		'invoiceFormOfPayment' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(20) NOT NULL DEFAULT ''",            	'cat' => "general"],
		'invoiceFormOfPaymentName' =>	[ 'type' => 'string',    'dbDef' => "VARCHAR(20) NOT NULL DEFAULT ''",            	'cat' => "general"],
		'invoiceTemporary' =>			[ 'type' => 'boolean',   'dbDef' => "TINYINT UNSIGNED NOT NULL DEFAULT '0'",        'cat' => "general"],
		'invoiceIssued' =>				[ 'type' => 'boolean',   'dbDef' => "TINYINT UNSIGNED NOT NULL DEFAULT '0'",        'cat' => "general"],
		'invoiceVoided' =>				[ 'type' => 'boolean',   'dbDef' => "TINYINT UNSIGNED NOT NULL DEFAULT '0'",        'cat' => "general"],
		'invoiceVoidReasonCode' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(20) NOT NULL",                         'cat' => "general"],
		'invoiceVoidReasonName' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(40) NOT NULL",                         'cat' => "general"],
		'invoiceCumulativeInvoice' =>	[ 'type' => 'boolean',   'dbDef' => "TINYINT UNSIGNED NOT NULL DEFAULT '0'",        'cat' => "general"],
		'invoiceRoundTotal' =>			[ 'type' => 'boolean',   'dbDef' => "TINYINT UNSIGNED NOT NULL DEFAULT '0'",        'cat' => "general"],
		'autoProcessRuleId' =>			[ 'type' => 'numeric',   'dbDef' => "MEDIUMINT UNSIGNED NOT NULL DEFAULT '0'",   	'cat' => "general"],
		'autoProcessRuleName' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(50) NOT NULL DEFAULT ''",            	'cat' => "general"],
		'genDocsAssoc' =>				[ 'type' => 'string',    'dbDef' => "VARCHAR(200) NOT NULL DEFAULT ''",           	'cat' => "general", 'disabled' => true, 'content'=>'assocArray'],
		'definedPsgListStd' =>			[ 'type' => 'string', 	 'dbDef' => "TEXT NOT NULL",     							'cat' => "general",  'formula'=>['type'=>'entity', 'entity'=>'ClientInvoice', 'id'=>'invoiceId', 'attribute'=>'definedPassengersNameListStd'] ],

		'clientId' =>					[ 'type' => 'numeric',   'dbDef' => "INT UNSIGNED NOT NULL DEFAULT '0'",            'cat' => "clientUnifDetails"],
		'clientName' =>					[ 'type' => 'string',    'dbDef' => "VARCHAR(201) NOT NULL DEFAULT ''",             'cat' => "clientUnifDetails"],
		'clientTypeCode' =>				[ 'type' => 'string',    'dbDef' => "VARCHAR(2) NOT NULL DEFAULT ''",               'cat' => "clientUnifDetails"],
		'clientTypeName' =>				[ 'type' => 'string',    'dbDef' => "VARCHAR(30) NOT NULL DEFAULT ''",              'cat' => "clientUnifDetails"],
		'clientCountryCode' =>			[ 'type' => 'string',    'dbDef' => "VARCHAR(2) NOT NULL DEFAULT ''",               'cat' => "clientUnifDetails"],
		'clientCountryName' =>			[ 'type' => 'string',    'dbDef' => "VARCHAR(50) NOT NULL DEFAULT ''",              'cat' => "clientUnifDetails"],
		'clientCityId' =>				[ 'type' => 'numeric',   'dbDef' => "INT UNSIGNED NOT NULL DEFAULT '0'",            'cat' => "clientUnifDetails"],
		'clientCityName' =>				[ 'type' => 'string',    'dbDef' => "VARCHAR(150) NOT NULL DEFAULT ''",             'cat' => "clientUnifDetails"],

		'corporateId' =>				[ 'type' => 'numeric',   'dbDef' => "INT UNSIGNED NOT NULL DEFAULT '0'",            'cat' => "legalEntityDetails"],
		'corporateAlias' =>				[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "legalEntityDetails"],
		'corporateCompanyName' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(170) NOT NULL DEFAULT ''",             'cat' => "legalEntityDetails"],
		'corporateTrustId' =>			[ 'type' => 'numeric',   'dbDef' => "MEDIUMINT UNSIGNED NOT NULL DEFAULT '0'",      'cat' => "legalEntityDetails"],
		'corporateTrustName' =>			[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "legalEntityDetails"],
		'corporateSegmentId' =>			[ 'type' => 'numeric',   'dbDef' => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",       'cat' => "legalEntityDetails"],
		'corporateSegmentName' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "legalEntityDetails"],
		'corporateKamId' =>				[ 'type' => 'numeric',   'dbDef' => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",       'cat' => "legalEntityDetails"],
		'corporateKamName' =>			[ 'type' => 'string',    'dbDef' => "VARCHAR(101) NOT NULL DEFAULT ''",             'cat' => "legalEntityDetails"],
		'corporateRemarks' =>			[ 'type' => 'string',    'dbDef' => "TEXT NOT NULL",                                'cat' => "legalEntityDetails"],
		'corporateProcessedRemarks' =>	[ 'type' => 'string',    'dbDef' => "TEXT NOT NULL",                                'cat' => "legalEntityDetails", 'disabled' => true, 'content' => 'remarks'],
		'corporateDuplicated' =>		[ 'type' => 'boolean',   'dbDef' => "TINYINT UNSIGNED NOT NULL DEFAULT '0'",        'cat' => "legalEntityDetails"],
		'corporateOriginalId' =>		[ 'type' => 'numeric',   'dbDef' => "INT UNSIGNED NOT NULL DEFAULT '0'",            'cat' => "legalEntityDetails"],
		'corporateSelectedOfficeId' =>	[ 'type' => 'numeric',   'dbDef' => "INT UNSIGNED NOT NULL DEFAULT '0'",            'cat' => "legalEntityDetails"],
		'corporateSelectedOfficeName' =>[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "legalEntityDetails"],
		'corporateCountryCode' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(3) NOT NULL DEFAULT ''",               'cat' => "legalEntityDetails"],
		'corporateCountryName' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "legalEntityDetails"],
		'corporateCityId' =>			[ 'type' => 'numeric',   'dbDef' => "INT UNSIGNED NOT NULL DEFAULT '0'",            'cat' => "legalEntityDetails"],
		'corporateCityName' =>			[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "legalEntityDetails"],
		'corporateDomainId' =>        	[ 'type' => 'numeric',   'dbDef' => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",       'cat' => "legalEntityDetails"],
		'corporateDomainName' =>      	[ 'type' => 'string',    'dbDef' => "VARCHAR(150) NOT NULL DEFAULT ''",             'cat' => "legalEntityDetails"],
		'corporateDomainCategoryId' =>	[ 'type' => 'numeric',   'dbDef' => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",       'cat' => "legalEntityDetails"],
		'corporateDomainCategoryName'=>	[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "legalEntityDetails"],
		'corporateGroupsList' => 		[ 'type' => 'string',    'dbDef' => "TEXT NOT NULL",                                'cat' => "legalEntityDetails", 'formula' => ['type' => 'entity', 'entity' => 'Corporate', 'id' => 'corporateId', 'attribute' => 'groupElementsNames']],

		'customerId' =>					[ 'type' => 'numeric',   'dbDef' => "INT UNSIGNED NOT NULL DEFAULT '0'",            'cat' => "individualDetails"],
		'customerName' =>				[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "individualDetails"],
		'customerSegmentId' =>			[ 'type' => 'numeric',   'dbDef' => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",       'cat' => "individualDetails"],
		'customerSegmentName' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "individualDetails"],
		'customerRemarks' =>			[ 'type' => 'string',    'dbDef' => "TEXT NOT NULL",                                'cat' => "individualDetails"],
		'customerProcessedRemarks' =>	[ 'type' => 'string',    'dbDef' => "TEXT NOT NULL",                                'cat' => "individualDetails", 'disabled' => true, 'content' => 'remarks'],
		'customerCountryCode' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(3) NOT NULL DEFAULT ''",               'cat' => "individualDetails"],
		'customerCountryName' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "individualDetails"],
		'customerCityId' =>				[ 'type' => 'numeric',   'dbDef' => "INT UNSIGNED NOT NULL DEFAULT '0'",            'cat' => "individualDetails"],
		'customerCityName' =>			[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "individualDetails"],
		'customerDuplicated' =>			[ 'type' => 'boolean',   'dbDef' => "TINYINT UNSIGNED NOT NULL DEFAULT '0'",        'cat' => "individualDetails"],
		'customerOriginalId' =>			[ 'type' => 'numeric',   'dbDef' => "INT UNSIGNED NOT NULL DEFAULT '0'",            'cat' => "individualDetails"],

		'invoiceBase' =>				[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",    	    'cat' => "values", 'subtotals' => "invoiceCurrency"],
		'invoiceVat' =>					[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",    	    'cat' => "values", 'subtotals' => "invoiceCurrency"],
		'invoiceTotal' =>				[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",           'cat' => "values", 'subtotals' => "invoiceCurrency"],
		'invoiceCurrency' =>			[ 'type' => 'string',    'dbDef' => "VARCHAR(3) NOT NULL DEFAULT ''", 	            'cat' => "values"],
		'invoiceDefCurrencyExchRate' =>	[ 'type' => 'price',     'dbDef' => "DECIMAL(15,8) NOT NULL DEFAULT '0'",           'cat' => "values"],
		'invoiceWorkCurrencyExchRate' =>[ 'type' => 'price',     'dbDef' => "DECIMAL(15,8) NOT NULL DEFAULT '0'",    	    'cat' => "values"],
		'invoiceBaseDefCurr' =>			[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",           'cat' => "values", 'subtotals' => true],
		'invoiceVatDefCurr' =>			[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",    	    'cat' => "values", 'subtotals' => true],
		'invoiceTotalDefCurr' =>		[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",           'cat' => "values", 'subtotals' => true],
		'invoiceBaseWorkCurr' =>		[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",    	    'cat' => "values", 'subtotals' => true],
		'invoiceVatWorkCurr' =>			[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",   	    'cat' => "values", 'subtotals' => true],
		'invoiceTotalWorkCurr' =>		[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",    	    'cat' => "values", 'subtotals' => true],

		'cashedPercent' =>				[ 'type' => 'percent',   'dbDef' => "DECIMAL(7, 6) NOT NULL DEFAULT '0'",           'cat' => "cashingDetails"],
		'cashedStatus' =>				[ 'type' => 'string',    'dbDef' => "CHAR(1) NOT NULL DEFAULT ''",                  'cat' => "cashingDetails"],
		'cashedStatusName' =>			[ 'type' => 'string',    'dbDef' => "VARCHAR(50) NOT NULL DEFAULT ''",              'cat' => "cashingDetails"],
		'cashedValue' =>				[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",           'cat' => "cashingDetails", 'subtotals' => "invoiceCurrency"],
		'notCashedValue' =>				[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",           'cat' => "cashingDetails", 'subtotals' => "invoiceCurrency"],
		'cashedValueDefCurr' =>			[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",           'cat' => "cashingDetails", 'subtotals' => true],
		'notCashedValueDefCurr' =>		[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",           'cat' => "cashingDetails", 'subtotals' => true],
		'cashedValueWorkCurr' =>		[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",           'cat' => "cashingDetails", 'subtotals' => true],
		'notCashedValueWorkCurr' =>		[ 'type' => 'price',     'dbDef' => "DECIMAL(16,3) NOT NULL DEFAULT '0'",           'cat' => "cashingDetails", 'subtotals' => true],
		'lastCashingDocDate' =>			[ 'type' => 'date',      'dbDef' => "DATE NULL DEFAULT NULL", 			            'cat' => "cashingDetails"],
		'lastCashingDocType' =>			[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => 'cashingDetails'],
		'lastCashingDocTypeName' =>		[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => 'cashingDetails'],
		'lastCashingDocId' =>			[ 'type' => 'numeric',   'dbDef' => "BIGINT NOT NULL DEFAULT '0'",                  'cat' => "cashingDetails"],

		'userId' =>						[ 'type' => 'numeric',   'dbDef' => "INT UNSIGNED NOT NULL DEFAULT '0'",            'cat' => "userDetails"],
		'userName' => 					[ 'type' => 'string',    'dbDef' => "VARCHAR(101) NOT NULL DEFAULT ''",             'cat' => "userDetails"],
		'userOfficeId' =>				[ 'type' => 'numeric',   'dbDef' => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",       'cat' => "userDetails"],
		'userOfficeName' =>				[ 'type' => 'string',    'dbDef' => "VARCHAR(150) NOT NULL DEFAULT ''",             'cat' => "userDetails"],
		'userDepartmentId' =>			[ 'type' => 'numeric',   'dbDef' => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",       'cat' => "userDetails"],
		'userDepartmentName' =>			[ 'type' => 'string',    'dbDef' => "VARCHAR(100) NOT NULL DEFAULT ''",             'cat' => "userDetails"],
		'addUserId' =>					[ 'type' => 'numeric',   'dbDef' => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",       'cat' => "userDetails"],
		'addUserName' =>				[ 'type' => 'string',    'dbDef' => "VARCHAR(101) NOT NULL DEFAULT ''",             'cat' => "userDetails"],
		'issueUserId' =>				[ 'type' => 'numeric',   'dbDef' => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",       'cat' => "userDetails"],
		'issueUserName' =>				[ 'type' => 'string',    'dbDef' => "VARCHAR(101) NOT NULL DEFAULT ''",             'cat' => "userDetails"],
		'voidUserId' =>					[ 'type' => 'numeric',   'dbDef' => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",       'cat' => "userDetails"],
		'voidUserName' =>				[ 'type' => 'string',    'dbDef' => "VARCHAR(101) NOT NULL DEFAULT ''",             'cat' => "userDetails"],

		'addTime' =>					[ 'type' => 'datetime',  'dbDef' => "DATETIME NULL DEFAULT NULL",                   'cat' => "operationTimes"],
		'issueTime' =>					[ 'type' => 'datetime',  'dbDef' => "DATETIME NULL DEFAULT NULL",                   'cat' => "operationTimes"],
		'voidTime' =>					[ 'type' => 'datetime',  'dbDef' => "DATETIME NULL DEFAULT NULL",                   'cat' => "operationTimes"],
		'lastUpdateTime' =>				[ 'type' => 'datetime',  'dbDef' => "DATETIME NULL DEFAULT NULL",                   'cat' => "operationTimes"],
		'updatesCount' =>				[ 'type' => 'numeric',   'dbDef' => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",       'cat' => "operationTimes"],

	];

	/**
	 * The primary key column.
	 * @var string
	 */
	protected string $primaryKeyColumn = 'invoiceId';

	/**
	 * The columns that are forced into the report.
	 * @var array
	 */
	protected array $forcedColumns = [
		'clientTypeCode', // for filtering by client type
		'corporateId', 'customerId', // added by the 'clientTypeCode' column itself
	];

	/**
	 * The columns dependencies list.
	 * @var array
	 */
	protected array $columnsDependencies = [
		'autoProcessRuleName'			=> ['autoProcessRuleId'],
		'userOfficeName'				=> ['userOfficeId'],
		'userDepartmentId' 				=> ['userId'],
		'userDepartmentName' 			=> ['userDepartmentId'],

		'corporateAlias'				=> ['corporateId'],
		'corporateCompanyName'			=> ['corporateId'],
		'corporateKamId'				=> ['corporateId'],
		'corporateKamName' 				=> ['corporateKamId'],
		'corporateTrustId'				=> ['corporateId'],
		'corporateTrustName' 			=> ['corporateTrustId'],
		'corporateSegmentId'			=> ['corporateId'],
		'corporateSegmentName' 			=> ['corporateSegmentId'],
		'corporateRemarks'				=> ['corporateId'],
		'corporateSelectedOfficeId'		=> ['corporateId'],
		'corporateSelectedOfficeName'	=> ['corporateSelectedOfficeId'],
		'corporateCountryCode'			=> ['corporateSelectedOfficeId'],
		'corporateCountryName'  		=> ['corporateCountryCode'],
		'corporateCityId'				=> ['corporateSelectedOfficeId'],
		'corporateCityName' 			=> ['corporateCityId'],
		'corporateDomainName'        	=> ['corporateDomainId'],
		'corporateDomainCategoryName'	=> ['corporateDomainCategoryId'],
		'corporateGroupsList'			=> ['corporateId'],

		'customerName' 					=> ['customerId'],
		'customerSegmentId'				=> ['customerId'],
		'customerSegmentName' 			=> ['customerSegmentId'],
		'customerRemarks'				=> ['customerId'],
		'customerCountryCode'			=> ['customerId'],
		'customerCountryName' 			=> ['customerCountryCode'],
		'customerCityId'				=> ['customerId'],
		'customerCityName' 				=> ['customerCityId'],

		'clientId' 						=> ['corporateId', 'customerId'],
		'clientName' 					=> ['corporateAlias', 'customerName'],
//		'clientTypeCode'				=> ['corporateId', 'customerId'],
		'clientTypeName'				=> ['clientTypeCode'],
		'clientCountryCode' 			=> ['corporateCountryCode', 'customerId'],
		'clientCityId'					=> ['corporateCityId', 'customerId'],
		'clientCountryName' 			=> ['clientCountryCode'],
		'clientCityName' 				=> ['clientCityId'],

		'lastCashingDocTypeName'		=> ['lastCashingDocType'],
		'cashedStatusName'				=> ['cashedStatus'],

		'invoiceFormOfPaymentName'		=> ['invoiceFormOfPayment'],
		'invoiceVoidReasonName'			=> ['invoiceVoidReasonCode'],

	];

}
