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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
*/
namespace Temando\Shipping\Block\Adminhtml;
use Magento\Backend\Block\Template as BackendTemplate;
use Magento\Backend\Block\Template\Context;
use Temando\Shipping\Model\DispatchProviderInterface;
use Temando\Shipping\Model\DocumentationInterface;
use Temando\Shipping\Model\ResourceModel\Rma\RmaAccess;
use Temando\Shipping\Model\Shipment\ShipmentProviderInterface;
/**
* Temando Documentation Listing Layout Block
*
* @package Temando\Shipping\Block
* @author Christoph Aßmann <christoph.assmann@netresearch.de>
* @author Rhodri Davies <rhodri.davies@temando.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link http://www.temando.com/
*
* @api
* @deprecated since 1.1.3 | Block data is provided by view model
* @see \Temando\Shipping\ViewModel\Shipment\ShipmentDetails
*/
class Documentation extends BackendTemplate
{
/**
* @var ShipmentProviderInterface
*/
private $shipmentProvider;
/**
* @var DispatchProviderInterface
*/
private $dispatchProvider;
/**
* @var RmaAccess
*/
private $rmaAccess;
/**
* @param Context $context
* @param ShipmentProviderInterface $shipmentProvider
* @param DispatchProviderInterface $dispatchProvider
* @param RmaAccess $rmaAccess
* @param mixed[] $data
*/
public function __construct(
Context $context,
ShipmentProviderInterface $shipmentProvider,
DispatchProviderInterface $dispatchProvider,
RmaAccess $rmaAccess,
array $data = []
) {
$this->shipmentProvider = $shipmentProvider;
$this->dispatchProvider = $dispatchProvider;
$this->rmaAccess = $rmaAccess;
parent::__construct($context, $data);
}
/**
* Set documentation from
* - dispatch
* - shipment or
* - rma shipment
*
* @return BackendTemplate
*/
protected function _beforeToHtml()
{
if (!$this->hasData('documentation')) {
if ($this->dispatchProvider->getDispatch()) {
$dispatch = $this->dispatchProvider->getDispatch();
$this->setData('documentation', $dispatch->getDocumentation());
} elseif ($this->shipmentProvider->getShipment()) {
$shipment = $this->shipmentProvider->getShipment();
$this->setData('documentation', $shipment->getDocumentation());
} elseif ($this->rmaAccess->getCurrentRmaShipment()) {
$shipment = $this->rmaAccess->getCurrentRmaShipment();
$this->setData('documentation', $shipment->getDocumentation());
}
}
return parent::_beforeToHtml();
}
/**
* @return DocumentationInterface[]
*/
public function getDocumentation()
{
return $this->hasData('documentation') ? $this->getData('documentation') : [];
}
/**
* @param DocumentationInterface $documentation
* @return \Magento\Framework\Phrase
*/
public function getDisplayName(DocumentationInterface $documentation)
{
$fileTypeNames = [
'nafta' => 'NAFTA',
'certificateOfOrigin' => 'Certificate Of Origin',
'cn22' => 'CN 22',
'cn23' => 'CN 23',
'codTurnInPage' => 'Cash On Delivery Turn In Page',
'commercialInvoice' => 'Commercial Invoice',
'customerInvoice' => 'Customer Invoice',
'highValueReport' => 'High Value Report',
'manifestSummary' => 'Manifest Summary',
'packageLabel' => 'Package Label',
'packageReturnLabel' => 'Package Return Label',
'packagingList' => 'Packaging List',
'proofOfDelivery' => 'Proof Of Delivery'
];
$displayName = isset($fileTypeNames[$documentation->getType()])
? $fileTypeNames[$documentation->getType()]
: $documentation->getType();
return __($displayName);
}
/**
* @return bool
*/
public function isPaperless()
{
/** @var \Temando\Shipping\Model\ShipmentInterface $shipment */
$shipment = $this->shipmentProvider->getShipment();
if ($shipment) {
$originCountryCode = $shipment->getOriginLocation()->getCountryCode();
$destinationCountryCode = $shipment->getDestinationLocation()->getCountryCode();
if (($originCountryCode != $destinationCountryCode) && $shipment->isPaperless()) {
return true;
}
}
return false;
}
}