|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Giansalex |
|
5
|
|
|
* Date: 09/08/2017 |
|
6
|
|
|
* Time: 20:00 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Greenter\Factory; |
|
10
|
|
|
|
|
11
|
|
|
use Greenter\Model\Company\Company; |
|
12
|
|
|
use Greenter\Model\Despatch\Despatch; |
|
13
|
|
|
use Greenter\Model\Perception\Perception; |
|
14
|
|
|
use Greenter\Model\Response\BillResult; |
|
15
|
|
|
use Greenter\Model\Response\StatusResult; |
|
16
|
|
|
use Greenter\Model\Response\SummaryResult; |
|
17
|
|
|
use Greenter\Model\Retention\Retention; |
|
18
|
|
|
use Greenter\Model\Voided\Reversion; |
|
19
|
|
|
use Greenter\Ws\Services\CeSunat; |
|
20
|
|
|
use Greenter\Xml\Builder\CeBuilder; |
|
21
|
|
|
use Greenter\Xml\Builder\CeBuilderInterface; |
|
22
|
|
|
|
|
23
|
|
|
class CeFactory extends BaseFactory implements CeFactoryInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var CeBuilderInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $builder; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var bool |
|
32
|
|
|
*/ |
|
33
|
|
|
private $isProd; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* CeFactory constructor. |
|
37
|
|
|
*/ |
|
38
|
20 |
|
public function __construct() |
|
39
|
|
|
{ |
|
40
|
20 |
|
parent::__construct(); |
|
41
|
20 |
|
$this->builder = new CeBuilder(); |
|
42
|
20 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Envia una Guia de Remision. |
|
46
|
|
|
* |
|
47
|
|
|
* @param Despatch $despatch |
|
48
|
|
|
* @return BillResult |
|
49
|
|
|
*/ |
|
50
|
4 |
View Code Duplication |
public function sendDispatch(Despatch $despatch) |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
4 |
|
$xml = $this->builder->buildDespatch($despatch); |
|
53
|
2 |
|
$filename = $despatch->getFilename($this->company->getRuc()); |
|
54
|
|
|
|
|
55
|
2 |
|
$this->setService(true); |
|
56
|
2 |
|
return $this->getBillResult($xml, $filename); |
|
57
|
2 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Envia una Retencion. |
|
61
|
|
|
* |
|
62
|
|
|
* @param Retention $retention |
|
63
|
|
|
* @return BillResult |
|
64
|
|
|
*/ |
|
65
|
4 |
View Code Duplication |
public function sendRetention(Retention $retention) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
4 |
|
$xml = $this->builder->buildRetention($retention); |
|
68
|
2 |
|
$filename = $retention->getFilename($this->company->getRuc()); |
|
69
|
|
|
|
|
70
|
2 |
|
$this->setService(); |
|
71
|
2 |
|
return $this->getBillResult($xml, $filename); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Envia una Percepcion. |
|
76
|
|
|
* |
|
77
|
|
|
* @param Perception $perception |
|
78
|
|
|
* @return BillResult |
|
79
|
|
|
*/ |
|
80
|
6 |
View Code Duplication |
public function sendPerception(Perception $perception) |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
6 |
|
$xml = $this->builder->buildPerception($perception); |
|
83
|
4 |
|
$filename = $perception->getFilename($this->company->getRuc()); |
|
84
|
|
|
|
|
85
|
4 |
|
$this->setService(); |
|
86
|
4 |
|
return $this->getBillResult($xml, $filename); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Envia una Resumen de Reversiones. |
|
91
|
|
|
* |
|
92
|
|
|
* @param Reversion $reversion |
|
93
|
|
|
* @return SummaryResult |
|
94
|
|
|
*/ |
|
95
|
4 |
View Code Duplication |
public function sendReversion(Reversion $reversion) |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
4 |
|
$xml = $this->builder->buildReversion($reversion); |
|
98
|
2 |
|
$filename = $reversion->getFileName($this->company->getRuc()); |
|
99
|
|
|
|
|
100
|
4 |
|
$this->setService(); |
|
101
|
2 |
|
return $this->getSummaryResult($xml, $filename); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Get Status by Ticket. |
|
106
|
|
|
* |
|
107
|
|
|
* @param string $ticket |
|
108
|
|
|
* @return StatusResult |
|
109
|
|
|
*/ |
|
110
|
2 |
|
public function getStatus($ticket) |
|
111
|
|
|
{ |
|
112
|
2 |
|
$this->setService(); |
|
113
|
2 |
|
return $this->sender->getStatus($ticket); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Get Last XML Signed. |
|
118
|
|
|
* |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getLastXml() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->lastXml; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Set Company |
|
128
|
|
|
* |
|
129
|
|
|
* @param $company |
|
130
|
|
|
* @return $this |
|
131
|
|
|
*/ |
|
132
|
20 |
|
public function setCompany(Company $company) |
|
133
|
|
|
{ |
|
134
|
20 |
|
$this->company = $company; |
|
135
|
20 |
|
$this->builder->setCompany($company); |
|
136
|
|
|
|
|
137
|
20 |
|
return $this; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param array $params |
|
142
|
|
|
*/ |
|
143
|
20 |
View Code Duplication |
public function setParameters($params) |
|
|
|
|
|
|
144
|
|
|
{ |
|
145
|
20 |
|
$this->setWsParams($params['ws']); |
|
146
|
|
|
|
|
147
|
20 |
|
if (isset($params['xml'])) { |
|
148
|
20 |
|
$this->builder->setParameters($params['xml']); |
|
149
|
20 |
|
} |
|
150
|
|
|
|
|
151
|
20 |
|
if (isset($params['cert'])) { |
|
152
|
20 |
|
$this->signer->setCertificate($params['cert']); |
|
153
|
20 |
|
} |
|
154
|
20 |
|
} |
|
155
|
|
|
|
|
156
|
12 |
|
private function setService($isGuia = false) |
|
157
|
|
|
{ |
|
158
|
12 |
|
if ($isGuia === true) { |
|
159
|
2 |
|
$this->sender->setService($this->isProd ? CeSunat::GUIA_PRODUCCION : CeSunat::GUIA_BETA); |
|
160
|
2 |
|
return; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
10 |
|
$this->sender->setService($this->isProd ? CeSunat::RETENCION_PRODUCCION : CeSunat::RETENCION_BETA); |
|
164
|
|
|
} |
|
165
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.