1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* amadeus-ws-client |
4
|
|
|
* |
5
|
|
|
* Copyright 2015 Amadeus Benelux NV |
6
|
|
|
* |
7
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
8
|
|
|
* you may not use this file except in compliance with the License. |
9
|
|
|
* You may obtain a copy of the License at |
10
|
|
|
* |
11
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
12
|
|
|
* |
13
|
|
|
* Unless required by applicable law or agreed to in writing, software |
14
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
15
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16
|
|
|
* See the License for the specific language governing permissions and |
17
|
|
|
* limitations under the License. |
18
|
|
|
* |
19
|
|
|
* @package Amadeus |
20
|
|
|
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0 |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace Amadeus\Client\Struct\Fare\PricePnr13; |
24
|
|
|
|
25
|
|
|
use Amadeus\Client\RequestOptions\Fare\PricePnr\ObFee; |
26
|
|
|
use Amadeus\Client\RequestOptions\Fare\PricePnr\ZapOff; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* PenDisInformation |
30
|
|
|
* |
31
|
|
|
* @package Amadeus\Client\Struct\Fare\PricePnr13 |
32
|
|
|
* @author Dieter Devlieghere <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class PenDisInformation |
35
|
|
|
{ |
36
|
|
|
const QUAL_PENALTY = 700; |
37
|
|
|
const QUAL_DISCOUNT = 701; |
38
|
|
|
const QUAL_OB_FEES = "OBF"; |
39
|
|
|
const QUAL_ZAPOFF_DISCOUNT = "ZAP"; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* self::QUAL_* |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
public $discountPenaltyQualifier; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var DiscountPenaltyDetails[] |
50
|
|
|
*/ |
51
|
|
|
public $discountPenaltyDetails = []; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* PenDisInformation constructor. |
55
|
|
|
* |
56
|
|
|
* @param string|null $discountPenaltyQualifier |
57
|
|
|
* @param mixed $data |
58
|
30 |
|
*/ |
59
|
|
|
public function __construct($discountPenaltyQualifier, $data) |
60
|
30 |
|
{ |
61
|
|
|
$this->discountPenaltyQualifier = $discountPenaltyQualifier; |
62
|
12 |
|
|
63
|
18 |
|
switch ($discountPenaltyQualifier) { |
64
|
5 |
|
case PenDisInformation::QUAL_OB_FEES: |
65
|
5 |
|
$this->loadObFees($data); |
66
|
15 |
|
break; |
67
|
25 |
|
case PenDisInformation::QUAL_DISCOUNT: |
68
|
25 |
|
$this->loadPaxDiscounts($data); |
69
|
|
|
break; |
70
|
30 |
|
case PenDisInformation::QUAL_ZAPOFF_DISCOUNT: |
71
|
|
|
$this->loadZapOffDiscounts($data); |
72
|
|
|
break; |
73
|
|
|
} |
74
|
|
|
} |
75
|
5 |
|
|
76
|
|
|
/** |
77
|
5 |
|
* @param ObFee[] $obFees |
78
|
5 |
|
*/ |
79
|
5 |
|
protected function loadObFees($obFees) |
80
|
|
|
{ |
81
|
5 |
|
foreach ($obFees as $obFee) { |
82
|
|
|
$amountType = (!empty($obFee->amount)) ? |
83
|
5 |
|
DiscountPenaltyDetails::AMOUNTTYPE_FIXED_WHOLE_AMOUNT : DiscountPenaltyDetails::AMOUNTTYPE_PERCENTAGE; |
84
|
5 |
|
|
85
|
5 |
|
$rate = (!empty($obFee->amount)) ? $obFee->amount : $obFee->percentage; |
86
|
4 |
|
|
87
|
4 |
|
$this->discountPenaltyDetails[] = new DiscountPenaltyDetails( |
88
|
5 |
|
$obFee->rate, |
89
|
2 |
|
self::makeObFeeFunction($obFee->include), |
90
|
2 |
|
$amountType, |
91
|
5 |
|
$rate, |
92
|
|
|
$obFee->currency |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
} |
96
|
25 |
|
|
97
|
|
|
/** |
98
|
25 |
|
* @param string[] $discounts |
99
|
25 |
|
*/ |
100
|
10 |
|
protected function loadPaxDiscounts($discounts) |
101
|
25 |
|
{ |
102
|
|
|
foreach ($discounts as $discount) { |
103
|
|
|
$this->discountPenaltyDetails[] = new DiscountPenaltyDetails($discount); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param $zapOffs ZapOff[] |
109
|
5 |
|
*/ |
110
|
|
|
protected function loadZapOffDiscounts($zapOffs) |
111
|
5 |
|
{ |
112
|
|
|
foreach ($zapOffs as $zapOff) { |
113
|
|
|
$amountType = (isset($zapOff->amount)) ? |
114
|
|
|
DiscountPenaltyDetails::AMOUNTTYPE_FIXED_WHOLE_AMOUNT : DiscountPenaltyDetails::AMOUNTTYPE_PERCENTAGE; |
115
|
|
|
|
116
|
|
|
$rate = (isset($zapOff->amount)) ? $zapOff->amount : $zapOff->percentage; |
117
|
|
|
|
118
|
|
|
$this->discountPenaltyDetails[] = new DiscountPenaltyDetails( |
119
|
|
|
$zapOff->rate, |
120
|
|
|
$zapOff->applyTo, |
121
|
|
|
$amountType, |
122
|
|
|
$rate |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Make the correct function code |
129
|
|
|
* |
130
|
|
|
* @param bool $include |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
protected static function makeObFeeFunction($include) |
134
|
|
|
{ |
135
|
|
|
return ($include === true) ? ObFee::FUNCTION_INCLUDE : ObFee::FUNCTION_EXCLUDE; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|