| 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 |
|