-
Notifications
You must be signed in to change notification settings - Fork 16
/
XBRL-Report-Compare.php
116 lines (98 loc) · 3.71 KB
/
XBRL-Report-Compare.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* Comparison report implementation
*
* @author Bill Seddon
* @version 0.9
* @Copyright (C) 2018 Lyquidity Solutions Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Load the XBRL implementation
*/
require_once( 'XBRL-Report-Base.php' );
/**
* Class to support the creation of comparative reports
* @author Bill Seddon
*/
class XBRL_Report_Compare extends XBRL_Report_Base
{
/**
* Default constructor
* @param array $years An array of the years to explicitly include in the report
*/
public function __construct( $years = array() ) {}
/**
* This function is overridden to check the validity of the instance documents included
*
* @param bool $prune True if the presentation hierarchies should be pruned to keep only items with elements assigned
* @return void
*/
public function preparePresentation( $prune = true )
{
$docs = $this->getInstanceDocuments();
$existingYears = null;
foreach ( $docs as $instanceKey => $instance )
{
$instanceYears = array();
foreach ( $instance->usedContexts as $key => $context )
{
$instanceYears[ $context['year'] ] = $context['year'];
}
// Eliminate any years that are not in the valid years list
if ( $this->validYears )
{
$diffYears = array_diff( $instanceYears, $this->validYears );
if ( $diffYears )
{
sort( $diffYears );
$omittedYears = implode( ",", $diffYears );
$this->log()->info( "Data in the instance document {$instance->getDocumentName()} for $omittedYears will not be included in the generated report." );
}
$instanceYears = array_intersect( $instanceYears, $this->validYears );
}
if ( $existingYears === null )
{
$existingYears = $instanceYears;
continue;
}
// Check the instances have overlaps. Order the arrays this way so the $instanceYears are checked
$diffYears = array_diff( $instanceYears, $existingYears ) + array_diff( $existingYears, $instanceYears );
if ( ! $diffYears ) continue;
if ( ! array_intersect( $diffYears, $instanceYears ) )
{
$this->log()->info( "None of the years in instance {$instance->getDefaultCurrency()} overlap with other documents included in this report" );
}
if ( count( array_intersect( $diffYears, $instanceYears ) ) !== count( $instanceYears ) )
{
$omittedYears = implode( ",", $diffYears );
$this->log()->info( "Some of the years ($omittedYears) in instance {$instance->getDefaultCurrency()} do not overlap with other documents included in this report" );
}
$existingYears = array_intersect_key( $existingYears, $instanceYears );
}
if ( ! $existingYears )
{
$message = $this->validYears
? "There are no years in the instance documents selected that match the valid years you have chosen"
: "The instance documents you have selected contain no data.";
throw new Exception( $message );
}
// Make sure only $existingYears exist in $this->years
$this->years = array_intersect_key( $this->years, $existingYears );
parent::preparePresentation( $prune );
}
}
?>