PluginProbe
Packeta / trunk
Packeta vtrunk
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / EntityFactory / CustomsDeclaration.php

CustomsDeclaration.php in Packeta trunk, at src/Packetery/Module/EntityFactory/CustomsDeclaration.php

70 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class CustomsDeclaration.
4 *
5 * @package Packetery
6 */
7
8 declare(strict_types=1);
9
10 namespace Packetery\Module\EntityFactory;
11
12 use Packetery\Core\CoreHelper;
13 use Packetery\Core\Entity;
14
15 /**
16 * Class CustomsDeclaration.
17 */
18 class CustomsDeclaration {
19 /**
20 * Creates customs declaration entity from standard structure.
21 *
22 * @param array $data Data.
23 * @param string $orderId Order ID.
24 *
25 * @return Entity\CustomsDeclaration
26 */
27 public function fromStandardizedStructure( array $data, string $orderId ): Entity\CustomsDeclaration {
28 $entity = new Entity\CustomsDeclaration(
29 $orderId,
30 $data['ead'],
31 (float) $data['delivery_cost'],
32 $data['invoice_number'],
33 \DateTimeImmutable::createFromFormat(
34 CoreHelper::MYSQL_DATE_FORMAT,
35 $data['invoice_issue_date']
36 )
37 );
38 $entity->setId( $data['id'] ?? null );
39 $entity->setInvoiceFileId( $data['invoice_file_id'] );
40 $entity->setMrn( $data['mrn'] );
41 $entity->setEadFileId( $data['ead_file_id'] );
42
43 return $entity;
44 }
45
46 /**
47 * Creates item from standardized structure.
48 *
49 * @param array<string, string> $data Data.
50 * @return Entity\CustomsDeclarationItem
51 */
52 public function createItemFromStandardizedStructure( array $data ): Entity\CustomsDeclarationItem {
53 $entity = new Entity\CustomsDeclarationItem(
54 $data['customs_declaration_id'],
55 $data['customs_code'],
56 (float) $data['value'],
57 $data['product_name_en'],
58 (int) $data['units_count'],
59 $data['country_of_origin'],
60 (float) $data['weight']
61 );
62 $entity->setId( $data['id'] ?? null );
63 $entity->setProductName( $data['product_name'] );
64 $entity->setIsFoodOrBook( (bool) ( $data['is_food_or_book'] ?? false ) );
65 $entity->setIsVoc( (bool) ( $data['is_voc'] ?? false ) );
66
67 return $entity;
68 }
69 }
70