Passed
Push — master ( f22ecf...a98eef )
by Andrey
03:27
created

InternetDocument::getDocumentPrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 20
rs 9.9332
1
<?php
2
3
namespace Daaner\NovaPoshta\Models;
4
5
use Carbon\Carbon;
6
use Daaner\NovaPoshta\NovaPoshta;
7
use Daaner\NovaPoshta\Traits\DateTimes;
8
use Daaner\NovaPoshta\Traits\DocumentList;
9
use Daaner\NovaPoshta\Traits\InternetDocumentProperty;
10
use Daaner\NovaPoshta\Traits\Limit;
11
use Daaner\NovaPoshta\Traits\OptionsSeatProperty;
12
use Daaner\NovaPoshta\Traits\PDFDocumentProperty;
13
use Daaner\NovaPoshta\Traits\RecipientProperty;
14
use Daaner\NovaPoshta\Traits\SenderProperty;
15
use Illuminate\Contracts\Container\BindingResolutionException;
16
use Illuminate\Support\Facades\Date;
17
18
class InternetDocument extends NovaPoshta
19
{
20
    /**
21
     * getDocumentList
22
     * getMoneyTransferDocuments.
23
     */
24
    use Limit, DateTimes;
25
26
    /**
27
     * getDocumentList.
28
     */
29
    use DocumentList;
30
31
    /**
32
     * save.
33
     */
34
    use InternetDocumentProperty, SenderProperty, OptionsSeatProperty, RecipientProperty;
35
36
    /**
37
     * getPDF.
38
     */
39
    use PDFDocumentProperty;
40
41
    protected $model = 'InternetDocument';
42
    protected $calledMethod;
43
    protected $methodProperties = [];
44
45
    /**
46
     * Получить список ЭН.
47
     *
48
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a9d22b34-8512-11ec-8ced-005056b2dbe1 Получить список ЭН
49
     * @since 2022-11-07
50
     *
51
     * @return array
52
     */
53
    public function getDocumentList(): array
54
    {
55
        $this->calledMethod = 'getDocumentList';
56
57
        $this->getPage();
58
        $this->getLimit();
59
60
        //DateTime
61
        $this->getDateTime();
62
        $this->getDateTimeFromTo();
63
64
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
65
    }
66
67
    /**
68
     * Создать экспресс-накладную.
69
     *
70
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a965630e-8512-11ec-8ced-005056b2dbe1 Создать экспресс-накладную
71
     * @since 2022-11-07
72
     *
73
     * @param  string|null  $description  Описание посылки
74
     * @return array
75
     */
76
    public function save(string $description = null): array
77
    {
78
        $this->calledMethod = 'save';
79
80
        $this->getPayerType();
81
        $this->getServiceType();
82
        $this->getPaymentMethod();
83
        $this->getCargoType();
84
85
        $this->getDateTime();
86
        $this->setDescription($description);
87
        $this->getSeatsAmount();
88
        $this->getCost();
89
        $this->getOptionsSeat();
90
91
        //Отправитель и другое
92
        $this->getSender();
93
        $this->getRecipientType();
94
        $this->getBackwardDeliveryData();
95
        $this->getNote();
96
        $this->getAdditionalInformation();
97
98
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
99
    }
100
101
    /**
102
     * Удаление экспресс-накладной.
103
     *
104
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a9f43ff1-8512-11ec-8ced-005056b2dbe1 Удаление экспресс-накладной
105
     * @since 2022-11-07
106
     *
107
     * @param  string|array  $DocumentRefs  Ref или массив Ref ТТН
108
     * @return array
109
     */
110
    public function delete($DocumentRefs): array
111
    {
112
        $this->calledMethod = 'delete';
113
114
        if (is_array($DocumentRefs) === false) {
115
            $DocumentRefs = explode(', ', /** @scrutinizer ignore-type */ $DocumentRefs);
116
        }
117
118
        $this->methodProperties['DocumentRefs'] = array_values(/** @scrutinizer ignore-type */ $DocumentRefs);
119
120
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
121
    }
122
123
    /**
124
     * Получить данные о платежах за определенный период.
125
     *
126
     * @since 2022-11-07 НЕ ДОКУМЕНТИРОВАНО
127
     *
128
     * @param  null|string|Carbon|date  $dateFrom  Начиная с текущей даты
129
     * @param  null|string|Carbon|date  $dateTo  До текущей даты
130
     * @return array
131
     */
132
    public function getMoneyTransferDocuments($dateFrom = null, $dateTo = null): array
133
    {
134
        $this->calledMethod = 'getMoneyTransferDocuments';
135
136
        $this->getLimit();
137
        $this->getPage();
138
        $this->getDateFromTo($dateFrom, $dateTo);
139
140
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
141
    }
142
143
    /**
144
     * Редактирование экспресс-накладной.
145
     *
146
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a98a4354-8512-11ec-8ced-005056b2dbe1 Редактирование экспресс-накладной
147
     *
148
     * @author https://github.com/seriklav/NovaPoshta
149
     *
150
     * TODO need tested
151
     *
152
     * @since НЕ ПРОВЕРЕНО
153
     *
154
     * @param  string|null  $description  Описание
155
     * @return array
156
     */
157
    public function edit(?string $description = null): array
158
    {
159
        $this->calledMethod = 'update';
160
161
        $this->getRef();
162
163
        $this->getPayerType();
164
        $this->getServiceType();
165
        $this->getPaymentMethod();
166
        $this->getCargoType();
167
168
        $this->getDateTime();
169
        $this->setDescription($description);
170
        $this->getSeatsAmount();
171
        $this->getCost();
172
        $this->getWeight();
173
//        $this->getOptionsSeat();
174
175
        //Отправитель и другое
176
        $this->getSender();
177
        $this->getRecipientType();
178
        $this->getBackwardDeliveryData();
179
        $this->getNote();
180
        $this->getAdditionalInformation();
181
182
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
183
    }
184
185
    /**
186
     * Прогноз даты доставки груза.
187
     *
188
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a941c714-8512-11ec-8ced-005056b2dbe1 Прогноз даты доставки груза
189
     * @since 2022-11-07
190
     *
191
     * @author https://github.com/seriklav/NovaPoshta
192
     *
193
     * @param  string  $CitySender  Ref города отправителя
194
     * @param  string  $CityRecipient  Ref города получателя
195
     * @return array
196
     */
197
    public function getDocumentDeliveryDate(string $CitySender, string $CityRecipient): array {
198
        $this->calledMethod = 'getDocumentDeliveryDate';
199
200
        $this->methodProperties['CitySender'] = $CitySender;
201
        $this->methodProperties['CityRecipient'] = $CityRecipient;
202
203
        $this->getDateTime();
204
        $this->getServiceType();
205
206
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false);
207
    }
208
209
    /**
210
     * Прогноз стоимости доставки груза.
211
     *
212
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a91f115b-8512-11ec-8ced-005056b2dbe1 Прогноз стоимости доставки груза
213
     * @since 2022-11-07
214
     *
215
     * @param  string  $CitySender  Ref города отправителя
216
     * @param  string  $CityRecipient  Ref города получателя
217
     * @return array
218
     */
219
    public function getDocumentPrice(string $CitySender, string $CityRecipient):array
220
    {
221
        $this->calledMethod = 'getDocumentPrice';
222
223
        $this->methodProperties['CitySender'] = $CitySender;
224
        $this->methodProperties['CityRecipient'] = $CityRecipient;
225
226
        $this->methodProperties['ServiceType'] = $ServiceType ?? config('novaposhta.service_type');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ServiceType seems to never exist and therefore isset should always be false.
Loading history...
227
228
        $this->getWeight();
229
        $this->getDateTime();
230
        $this->getCargoType();
231
        $this->getServiceType();
232
        $this->getCost();
233
234
        /**
235
         * TODO Есть еще куча всяких штук, я не добавил
236
         */
237
238
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false);
239
    }
240
241
    /**
242
     * Печать накладной.
243
     *
244
     * @since 2022-11-07
245
     *
246
     * @param  string|array  $DocumentRefs  Ref либо ТТН (можно и массивом Ref или ТТН)
247
     * @param  bool  $getStreamFile  Получать файл сразу (false - в массиве в ключе result)
248
     *
249
     * @throws BindingResolutionException
250
     */
251
    public function getPDF($DocumentRefs, bool $getStreamFile)
252
    {
253
        $this->calledMethod = 'printFull';
254
255
        if (is_array($DocumentRefs) === false) {
256
            $DocumentRefs = explode(', ', /** @scrutinizer ignore-type */ $DocumentRefs);
257
        }
258
259
        $this->getPrintForm();
260
261
        /**
262
         * Форсирование параметров, при определенных условиях.
263
         */
264
        if ($this->printForm == 'ScanSheet') {
265
            $this->setThisIsScansheet();
266
267
            $this->methodProperties['PrintOrientation'] = $this->PrintOrientation;
268
            $this->Type = 'pdf';
269
270
            $this->PageFormat = null;
271
            $this->Position = 1;
272
            $this->Copies = 1;
273
        }
274
275
        if ($this->printForm == 'Document_new') {
276
            $this->Type = 'pdf';
277
278
            $this->Copies = $this->Copies ?: 1;
279
            $this->PageFormat = $this->PageFormat ?: 'A4';
280
        }
281
282
        if ($this->printForm == 'Marking_85x85') {
283
            $this->PageFormat = 'A4';
284
            $this->Type = 'pdf8';
285
        }
286
287
        if ($this->printForm == 'Marking_100x100') {
288
            $this->PageFormat = null;
289
            $this->Type = 'pdf';
290
            $this->Position = '';
291
        }
292
293
        if ($this->isScansheet) {
294
            $this->methodProperties['ScanSheetRefs'] = array_values(/** @scrutinizer ignore-type */ $DocumentRefs);
295
        } else {
296
            $this->methodProperties['DocumentRefs'] = array_values(/** @scrutinizer ignore-type */ $DocumentRefs);
297
        }
298
299
        $this->getPageFormat();
300
        $this->getCopies();
301
        $this->getPosition();
302
        $this->getType();
303
304
        if ($getStreamFile) {
305
            $data = $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
306
307
            $file = null;
308
            $status = 500;
309
            $filename = microtime(false).'.pdf';
310
311
            if (isset($data['info']['file']) && $data['info']['file'] && $data['success']) {
312
                $file = $data['result'];
313
                $status = 200;
314
            }
315
316
            return response()->make($file, $status, [
317
                'Content-Type' => 'application/pdf',
318
                'Content-Disposition' => 'inline; filename="'.$filename.'"',
319
            ]);
320
        }
321
322
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
323
    }
324
}
325