src/AtechNet/CoreBundle/Entity/Order.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use App\AtechNet\CoreBundle\DTO\PriorityContext;
  4. use App\AtechNet\CoreBundle\Entity\Statistics\OrderChangelog;
  5. use App\AtechNet\CoreBundle\Enum\PaymentType;
  6. use App\AtechNet\CoreBundle\Helper\Unas;
  7. use App\AtechNet\CoreBundle\Helper\VAT;
  8. use App\AtechNet\CoreBundle\Interface\Prioritizable;
  9. use App\AtechNet\CoreBundle\Service\Order\OrderChangeLogService;
  10. use App\AtechNet\CoreBundle\Translation\TranslatorInterface;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\ORM\Mapping\Column;
  13. use Doctrine\ORM\Mapping\Entity;
  14. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  15. use Doctrine\ORM\Mapping\Index;
  16. use Doctrine\ORM\Mapping\JoinColumn;
  17. use Doctrine\ORM\Mapping\ManyToOne;
  18. use Doctrine\ORM\Mapping\OneToMany;
  19. use Doctrine\ORM\Mapping\OrderBy;
  20. use Doctrine\ORM\Mapping\Table as Table;
  21. use Doctrine\Persistence\ManagerRegistry;
  22. use Symfony\Component\Validator\Constraints as Assert;
  23. /**
  24.  * Order
  25.  *
  26.  * @Table(name="orders", 
  27.  *     indexes={
  28.  *         @Index(name="idx_order_status", columns={"status"})
  29.  *     })
  30.  * @Entity(repositoryClass="App\AtechNet\CoreBundle\Repository\OrderRepository")
  31.  * @HasLifecycleCallbacks
  32.  */
  33. class Order extends AbstractSignedEntity implements Prioritizable
  34. {
  35.     public const int STATUS_OPEN = 10;
  36.     public const int STATUS_TRIAGE = 11;
  37.     public const int STATUS_RESERVED = 12;
  38.     public const int STATUS_WAITING_FOR_PAYMENT = 13;
  39.     public const int STATUS_WAITING = 20;
  40.     public const int STATUS_PRE_PROCESSING_ISSUE = 21;
  41.     public const int STATUS_WAITING_FOR_PARTNER = 22;
  42.     public const int STATUS_WAITING_FOR_PRODUCTION = 25;
  43.     public const int STATUS_WAITING_FOR_PRODUCTION_SALES = 26;
  44.     public const int STATUS_WAITING_FOR_PRODUCTION_QUARANTINE = 27;
  45.     public const int STATUS_WAITING_FOR_PRODUCTION_AIKEN = 28;
  46.     public const int STATUS_WAITING_FOR_PRODUCTION_DATA = 29;
  47.     public const int STATUS_PROCESSABLE = 30;
  48.     public const int STATUS_WAITING_FOR_ANSWER_SALES = 31;
  49.     public const int STATUS_WAITING_FOR_ANSWER_STOCK = 32;
  50.     public const int STATUS_WAITING_FOR_ANSWER_SERVICE = 33;
  51.     public const int STATUS_WAITING_FOR_ANSWER_ADMIN = 34;
  52.     public const int STATUS_WAITING_FOR_ANSWER_PARTS = 35;
  53.     public const int STATUS_WAITING_FOR_ANSWER = 37;
  54.     public const int STATUS_WAITING_FOR_ANSWER_AIKEN = 38;
  55.     public const int STATUS_WAITING_FOR_ANSWER_PARTNER = 39;
  56.     public const int STATUS_PROCESSING = 40;
  57.     public const int STATUS_WAITING_FOR_ANSWER_DATA = 41;
  58.     public const int STATUS_PROCESSING_ISSUES = 44;
  59.     public const int STATUS_READY_TO_PACK = 45;
  60.     public const int STATUS_READY_TO_SHIP = 50;
  61.     public const int STATUS_FINISHED = 60;
  62.     public const int STATUS_CANCELED = 70;
  63.     public const int STATUS_PICKUP_POINT = 80;
  64.     public const int PARCEL_STATUS_UNAVAILABLE = 0;
  65.     public const int PARCEL_STATUS_DATA_COLLECTED = 1;
  66.     public const int PARCEL_STATUS_ARRIVAL_IN_DEPOT = 3;
  67.     public const int PARCEL_STATUS_IN_DELIVERY = 4;
  68.     public const int PARCEL_STATUS_DELIVERED = 5;
  69.     public const int PARCEL_STATUS_DATA_RECEIVED = 51;
  70.     public const int PARCEL_STATUS_COD_DATA_RECEIVED = 52;
  71.     public const int PARCEL_STATUS_PACKAGE_PICKED_UP = 86;
  72.     public const string CreatedByType_Customer = 'Customer';
  73.     public const string CreatedByType_User = 'User';
  74.     public const string CreatedByType_Import = 'Import';
  75.     public const int WARRANTY_NO = 10;
  76.     public const int WARRANTY_30_DAYS = 20;
  77.     public const int WARRANTY_6_MONTHS = 25;
  78.     public const int WARRANTY_1_YEAR = 30;
  79.     public const int WARRANTY_2_YEAR = 40;
  80.     public const int WARRANTY_3_YEAR = 50;
  81.     public const int WARRANTY_4_YEAR = 60;
  82.     public const int WARRANTY_5_YEAR = 70;
  83.     public const int EXTERNAL_ORDER_SOURCE_BACKMARKET = 1;
  84.     public const int EXTERNAL_ORDER_SOURCE_REFURBED = 2;
  85.     public const int EXTERNAL_ORDER_SOURCE_AMAZON = 3;
  86.     public const int EXTERNAL_ORDER_SOURCE_EMAG = 4;
  87.     public const int EXTERNAL_ORDER_SOURCE_FNAC = 5;
  88.     public const int EXTERNAL_ORDER_SOURCE_CDISCOUNT = 6;
  89.     public const int EXTERNAL_ORDER_SOURCE_RAKUTEN = 7;
  90.     public const int EXTERNAL_ORDER_SOURCE_KAUFLAND = 8;
  91.     public const int EXTERNAL_ORDER_SOURCE_EBAY = 9;
  92.     public const int EXTERNAL_ORDER_SOURCE_ALLEGRO = 10;
  93.     public const int EXTERNAL_ORDER_SOURCE_RICONDIZIONATO = 11;
  94.     public const int EXTERNAL_ORDER_SOURCE_BACKMARKET_PRO = 12;
  95.     public const int EXTERNAL_ORDER_SOURCE_AUKRO = 13;
  96.     public const int EXTERNAL_ORDER_SOURCE_UNAS = 14;
  97.     public const int EXTERNAL_ORDER_SOURCE_MEDIAMARKT    = 15;
  98.     public const int EXTERNAL_ORDER_SOURCE_PCCOMPONENTES = 16;
  99.     public const int PAYMENT_STATUS_PENDING = 0;
  100.     public const int PAYMENT_STATUS_PAID = 1;
  101.     public const int PAYMENT_STATUS_FAILED = 2;
  102.     public const int PAYMENT_STATUS_OVERPAID = 3;
  103.     public const int PAYMENT_STATUS_PARTIAL = 4;
  104.     public const int PAYMENT_STATUS_COMMISSION = 5;
  105.     public const string PUBLIC_LINK_SECRET = '4t6w9z$C&F)J@NcRfUjXn2r5u8x!A%D*';
  106.     public const array LANGUAGES_BY_COUNTRIES = [
  107.         'FR' => 'FR',
  108.         'IT' => 'IT',
  109.         'ES' => 'ES',
  110.         'US' => 'US',
  111.         'UK' => 'UK',
  112.         'DE' => 'DE',
  113.         'PT' => 'PT',
  114.         'BE' => 'FR',
  115.         'SE' => 'SWE',
  116.         'SK' => 'SK',
  117.         'NL' => 'NL',
  118.         'DK' => 'DN',
  119.         'FI' => 'FI',
  120.         'SI' => 'SI',
  121.         'RO' => 'RO',
  122.         'RE' => 'FR',
  123.         'PL' => 'PL',
  124.         'MT' => 'UK',
  125.         'MC' => 'UK',
  126.         'LV' => 'LT',
  127.         'LU' => 'DE',
  128.         'LT' => 'UK',
  129.         'IE' => 'UK',
  130.         'HR' => 'HR',
  131.         'HK' => 'UK',
  132.         'GR' => 'GR',
  133.         'GP' => 'FR',
  134.         'EE' => 'UK',
  135.         'CY' => 'GR',
  136.         'CH' => 'DE',
  137.         'BG' => 'BG',
  138.         'AT' => 'DE',
  139.         'HU' => 'HU',
  140.         'CZ' => 'CZ'
  141.     ];
  142.     private ArrayCollection $orderChangelog;
  143.     /**
  144.      * @return string[]
  145.      */
  146.     public static function getStatusChoices(): array
  147.     {
  148.         return [
  149.             self::STATUS_TRIAGE                            => 'Triage',
  150.             self::STATUS_RESERVED                          => 'Reserved',
  151.             self::STATUS_WAITING_FOR_PAYMENT               => 'Waiting for payment',
  152.             self::STATUS_PRE_PROCESSING_ISSUE              => 'Pre-Processing Issue',
  153.             self::STATUS_WAITING_FOR_PARTNER               => 'Waiting for partner',
  154.             self::STATUS_WAITING_FOR_PRODUCTION_SALES      => 'Waiting for production - Sales',
  155.             self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE => 'Waiting for production - Quarantine',
  156.             self::STATUS_WAITING_FOR_PRODUCTION_AIKEN      => 'Waiting for production - Aiken',
  157.             self::STATUS_WAITING_FOR_PRODUCTION_DATA       => 'Waiting for Data',
  158.             self::STATUS_PROCESSABLE                       => 'Processable',
  159.             self::STATUS_PROCESSING                        => 'Processing',
  160.             self::STATUS_PROCESSING_ISSUES                 => 'Processing Issues',
  161.             self::STATUS_WAITING_FOR_ANSWER_SALES          => 'Waiting for answer sales',
  162.             self::STATUS_WAITING_FOR_ANSWER_STOCK          => 'Waiting for answer stock',
  163.             self::STATUS_WAITING_FOR_ANSWER_SERVICE        => 'Waiting for answer service',
  164.             self::STATUS_WAITING_FOR_ANSWER_ADMIN          => 'Waiting for answer admin',
  165.             self::STATUS_WAITING_FOR_ANSWER_PARTS          => 'Waiting for answer parts',
  166.             self::STATUS_WAITING_FOR_ANSWER_AIKEN          => 'Waiting for answer aiken',
  167.             self::STATUS_WAITING_FOR_ANSWER_PARTNER        => 'Waiting for answer partner',
  168.             self::STATUS_WAITING_FOR_ANSWER_DATA           => 'Waiting for answer data',
  169.             self::STATUS_READY_TO_PACK                     => 'Ready to pack',
  170.             self::STATUS_READY_TO_SHIP                     => 'Ready to ship',
  171.             self::STATUS_FINISHED                          => 'Finished',
  172.             self::STATUS_CANCELED                          => 'Canceled',
  173.         ];
  174.     }
  175.     public static function getStatusChoicesOldAndNew(): array
  176.     {
  177.         return [
  178.             self::STATUS_OPEN                               => 'Open',
  179.             self::STATUS_WAITING                            => 'Waiting',
  180.             self::STATUS_WAITING_FOR_PARTNER                => 'Waiting for partner',
  181.             self::STATUS_WAITING_FOR_PRODUCTION             => 'Waiting for production',
  182.             self::STATUS_WAITING_FOR_PRODUCTION_SALES       => 'Waiting for production - Sales',
  183.             self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE  => 'Waiting for production - Quarantine',
  184.             self::STATUS_WAITING_FOR_PRODUCTION_AIKEN       => 'Waiting for production - Aiken',
  185.             self::STATUS_WAITING_FOR_PRODUCTION_DATA        => 'Waiting for Data',
  186.             self::STATUS_WAITING_FOR_ANSWER_SALES           => 'Waiting for answer sales',
  187.             self::STATUS_WAITING_FOR_ANSWER_STOCK           => 'Waiting for answer stock',
  188.             self::STATUS_WAITING_FOR_ANSWER_SERVICE         => 'Waiting for answer service',
  189.             self::STATUS_WAITING_FOR_ANSWER_ADMIN           => 'Waiting for answer admin',
  190.             self::STATUS_WAITING_FOR_ANSWER_AIKEN           => 'Waiting for answer aiken',
  191.             self::STATUS_WAITING_FOR_ANSWER_PARTS           => 'Waiting for answer parts',
  192.             self::STATUS_WAITING_FOR_ANSWER_PARTNER         => 'Waiting for answer partner',
  193.             self::STATUS_WAITING_FOR_ANSWER_DATA            => 'Waiting for answer data',
  194.             self::STATUS_WAITING_FOR_ANSWER                 => 'Waiting for answer',
  195.             self::STATUS_READY_TO_PACK                      => 'Ready to pack',
  196.             self::STATUS_READY_TO_SHIP                      => 'Ready to ship',
  197.             self::STATUS_PICKUP_POINT                       => 'Pickup point',
  198.             self::STATUS_TRIAGE                             => 'Triage',
  199.             self::STATUS_RESERVED                           => 'Reserved',
  200.             self::STATUS_WAITING_FOR_PAYMENT                => 'Waiting for payment',
  201.             self::STATUS_PRE_PROCESSING_ISSUE               => 'Pre-Processing Issue',
  202.             self::STATUS_PROCESSABLE                        => 'Processable',
  203.             self::STATUS_PROCESSING_ISSUES                  => 'Processing Issues',
  204.             self::STATUS_PROCESSING                         => 'Processing',
  205.             self::STATUS_FINISHED                           => 'Finished',
  206.             self::STATUS_CANCELED                           => 'Canceled',
  207.         ];
  208.     }
  209.     /**
  210.      * @param int $from
  211.      * @param string $userRight
  212.      * @return array|int[]
  213.      */
  214.     public static function getAvailableNextStep(int $from, string $userRight): array
  215.     {
  216.         if ($userRight === User::PERMISSION_ORDER_STATUS_ALL) {
  217.             return [
  218.                 self::STATUS_TRIAGE,
  219.                 self::STATUS_RESERVED,
  220.                 self::STATUS_WAITING_FOR_PAYMENT,
  221.                 self::STATUS_WAITING_FOR_PARTNER,
  222.                 self::STATUS_WAITING_FOR_PRODUCTION_SALES,
  223.                 self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE,
  224.                 self::STATUS_WAITING_FOR_PRODUCTION_AIKEN,
  225.                 self::STATUS_WAITING_FOR_PRODUCTION_DATA,
  226.                 self::STATUS_PROCESSABLE,
  227.                 self::STATUS_PROCESSING,
  228.                 self::STATUS_WAITING_FOR_ANSWER_SALES,
  229.                 self::STATUS_WAITING_FOR_ANSWER_STOCK,
  230.                 self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  231.                 self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  232.                 self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  233.                 self::STATUS_WAITING_FOR_ANSWER_PARTS,
  234.                 self::STATUS_WAITING_FOR_ANSWER_PARTNER,
  235.                 self::STATUS_WAITING_FOR_ANSWER_DATA,
  236.                 self::STATUS_READY_TO_SHIP,
  237.                 self::STATUS_READY_TO_PACK,
  238.                 self::STATUS_CANCELED,
  239.                 self::STATUS_FINISHED
  240.             ];
  241.         }
  242.         if ($userRight === User::PERMISSION_ORDER_STATUS_SALES) {
  243.             return [
  244.                 self::STATUS_TRIAGE,
  245.                 self::STATUS_RESERVED,
  246.                 self::STATUS_WAITING_FOR_PAYMENT,
  247.                 self::STATUS_WAITING_FOR_PARTNER,
  248.                 self::STATUS_WAITING_FOR_PRODUCTION_SALES,
  249.                 self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE,
  250.                 self::STATUS_WAITING_FOR_PRODUCTION_AIKEN,
  251.                 self::STATUS_WAITING_FOR_PRODUCTION_DATA,
  252.                 self::STATUS_READY_TO_PACK,
  253.                 self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  254.                 self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  255.                 self::STATUS_WAITING_FOR_ANSWER_SALES,
  256.                 self::STATUS_WAITING_FOR_ANSWER_PARTNER,
  257.                 self::STATUS_WAITING_FOR_ANSWER_DATA,
  258.                 self::STATUS_PROCESSABLE,
  259.                 self::STATUS_CANCELED,
  260.             ];
  261.         }
  262.         if ($userRight === User::PERMISSION_ORDER_STATUS_PRODUCTION) {
  263.             return [
  264.                 self::STATUS_PROCESSABLE,
  265.                 self::STATUS_PROCESSING,
  266.                 self::STATUS_WAITING_FOR_ANSWER_SALES,
  267.                 self::STATUS_WAITING_FOR_ANSWER_STOCK,
  268.                 self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  269.                 self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  270.                 self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  271.                 self::STATUS_WAITING_FOR_ANSWER_PARTS,
  272.                 self::STATUS_WAITING_FOR_ANSWER_PARTNER,
  273.                 self::STATUS_WAITING_FOR_ANSWER_DATA,
  274.                 self::STATUS_READY_TO_SHIP,
  275.                 self::STATUS_READY_TO_PACK,
  276.                 self::STATUS_CANCELED,
  277.                 self::STATUS_FINISHED
  278.             ];
  279.         }
  280.         return [];
  281. //        if ($userRight === User::PERMISSION_ORDER_STATUS_SALES &&
  282. //            !in_array($from, [
  283. //                self::STATUS_TRIAGE,
  284. //                self::STATUS_RESERVED,
  285. //                self::STATUS_WAITING_FOR_PAYMENT,
  286. //                self::STATUS_WAITING_FOR_PARTNER,
  287. //                self::STATUS_WAITING_FOR_PRODUCTION_SALES,
  288. //                self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE,
  289. //                self::STATUS_WAITING_FOR_PRODUCTION_AIKEN,
  290. //                self::STATUS_WAITING_FOR_PRODUCTION_DATA,
  291. //                self::STATUS_READY_TO_PACK,
  292. //                self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  293. //                self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  294. //                self::STATUS_PROCESSABLE,
  295. //                self::STATUS_CANCELED,
  296. //            ])
  297. //        ) {
  298. //            return [];
  299. //        }
  300. //
  301. //        if ($userRight === User::PERMISSION_ORDER_STATUS_PRODUCTION &&
  302. //            !in_array($from, [
  303. //                self::STATUS_PROCESSABLE,
  304. //                self::STATUS_PROCESSING,
  305. //                self::STATUS_WAITING_FOR_ANSWER_SALES,
  306. //                self::STATUS_WAITING_FOR_ANSWER_STOCK,
  307. //                self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  308. //                self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  309. //                self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  310. //                self::STATUS_WAITING_FOR_ANSWER_PARTS,
  311. //                self::STATUS_READY_TO_SHIP,
  312. //                self::STATUS_READY_TO_PACK,
  313. //                self::STATUS_CANCELED,
  314. //                self::STATUS_FINISHED
  315. //            ])
  316. //        ) {
  317. //            return [];
  318. //        }
  319. //
  320. //        return match ($from) {
  321. //            self::STATUS_TRIAGE => [
  322. //                self::STATUS_TRIAGE,
  323. //                self::STATUS_RESERVED,
  324. //                self::STATUS_WAITING_FOR_PAYMENT,
  325. //                self::STATUS_PROCESSABLE,
  326. //                self::STATUS_CANCELED,
  327. //            ],
  328. //            self::STATUS_RESERVED => [
  329. //                self::STATUS_RESERVED,
  330. //                self::STATUS_WAITING_FOR_PAYMENT,
  331. //                self::STATUS_PROCESSABLE,
  332. //                self::STATUS_CANCELED,
  333. //            ],
  334. //
  335. //            self::STATUS_WAITING_FOR_PARTNER => [
  336. //                self::STATUS_WAITING_FOR_PARTNER,
  337. //                self::STATUS_RESERVED,
  338. //                self::STATUS_WAITING_FOR_PAYMENT,
  339. //                self::STATUS_WAITING_FOR_PRODUCTION_SALES,
  340. //                self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE,
  341. //                self::STATUS_WAITING_FOR_PRODUCTION_AIKEN,
  342. //        self::STATUS_WAITING_FOR_PRODUCTION_DATA,
  343. //                self::STATUS_PROCESSABLE,
  344. //                self::STATUS_CANCELED,
  345. //            ],
  346. //            self::STATUS_WAITING_FOR_PRODUCTION_SALES => [
  347. //                self::STATUS_WAITING_FOR_PRODUCTION_SALES,
  348. //                self::STATUS_RESERVED,
  349. //                self::STATUS_WAITING_FOR_PAYMENT,
  350. //                self::STATUS_WAITING_FOR_PARTNER,
  351. //                self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE,
  352. //                self::STATUS_WAITING_FOR_PRODUCTION_AIKEN,
  353. //                self::STATUS_WAITING_FOR_PRODUCTION_DATA,
  354. //                self::STATUS_PROCESSABLE,
  355. //                self::STATUS_CANCELED,
  356. //            ],
  357. //
  358. //            self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE => [
  359. //                self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE,
  360. //                self::STATUS_RESERVED,
  361. //                self::STATUS_WAITING_FOR_PAYMENT,
  362. //                self::STATUS_WAITING_FOR_PARTNER,
  363. //                self::STATUS_WAITING_FOR_PRODUCTION_SALES,
  364. //                self::STATUS_WAITING_FOR_PRODUCTION_AIKEN,
  365. //        self::STATUS_WAITING_FOR_PRODUCTION_DATA,
  366. //                self::STATUS_PROCESSABLE,
  367. //                self::STATUS_CANCELED,
  368. //            ],
  369. //            self::STATUS_WAITING_FOR_PRODUCTION_AIKEN => [
  370. //                self::STATUS_WAITING_FOR_PRODUCTION_AIKEN,
  371. //                self::STATUS_WAITING_FOR_PRODUCTION_DATA,
  372. //                self::STATUS_RESERVED,
  373. //                self::STATUS_WAITING_FOR_PAYMENT,
  374. //                self::STATUS_WAITING_FOR_PARTNER,
  375. //                self::STATUS_WAITING_FOR_PRODUCTION_SALES,
  376. //                self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE,
  377. //                self::STATUS_PROCESSABLE,
  378. //                self::STATUS_CANCELED,
  379. //            ],
  380. //           self::STATUS_WAITING_FOR_PRODUCTION_DATA => [
  381. //                self::STATUS_WAITING_FOR_PRODUCTION_AIKEN,
  382. //                self::STATUS_WAITING_FOR_PRODUCTION_DATA,
  383. //                self::STATUS_RESERVED,
  384. //                self::STATUS_WAITING_FOR_PAYMENT,
  385. //                self::STATUS_WAITING_FOR_PARTNER,
  386. //                self::STATUS_WAITING_FOR_PRODUCTION_SALES,
  387. //                self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE,
  388. //                self::STATUS_PROCESSABLE,
  389. //                self::STATUS_CANCELED,
  390. //            ],
  391. //            self::STATUS_WAITING_FOR_PAYMENT => [
  392. //                self::STATUS_WAITING_FOR_PAYMENT,
  393. //                self::STATUS_PROCESSABLE,
  394. //                self::STATUS_WAITING_FOR_PRODUCTION_SALES,
  395. //                self::STATUS_WAITING_FOR_PARTNER,
  396. //                self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE,
  397. //                self::STATUS_WAITING_FOR_PRODUCTION_AIKEN,
  398. //                self::STATUS_WAITING_FOR_PRODUCTION_DATA,
  399. //                self::STATUS_RESERVED,
  400. //                self::STATUS_CANCELED,
  401. //            ],
  402. //
  403. //            self::STATUS_WAITING_FOR_ANSWER_SALES => [
  404. //                self::STATUS_WAITING_FOR_ANSWER_SALES,
  405. //                self::STATUS_PROCESSABLE,
  406. //                self::STATUS_PROCESSING,
  407. //                self::STATUS_WAITING_FOR_ANSWER_STOCK,
  408. //                self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  409. //                self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  410. //                self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  411. //                self::STATUS_WAITING_FOR_ANSWER_PARTS,
  412. //                self::STATUS_READY_TO_PACK,
  413. //                self::STATUS_CANCELED,
  414. //            ],
  415. //            self::STATUS_WAITING_FOR_ANSWER_STOCK => [
  416. //                self::STATUS_WAITING_FOR_ANSWER_STOCK,
  417. //                self::STATUS_PROCESSABLE,
  418. //                self::STATUS_PROCESSING,
  419. //                self::STATUS_WAITING_FOR_ANSWER_SALES,
  420. //                self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  421. //                self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  422. //                self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  423. //                self::STATUS_WAITING_FOR_ANSWER_PARTS,
  424. //                self::STATUS_READY_TO_PACK,
  425. //                self::STATUS_CANCELED,
  426. //            ],
  427. //            self::STATUS_WAITING_FOR_ANSWER_SERVICE => [
  428. //                self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  429. //                self::STATUS_PROCESSABLE,
  430. //                self::STATUS_PROCESSING,
  431. //                self::STATUS_WAITING_FOR_ANSWER_SALES,
  432. //                self::STATUS_WAITING_FOR_ANSWER_STOCK,
  433. //                self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  434. //                self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  435. //                self::STATUS_WAITING_FOR_ANSWER_PARTS,
  436. //                self::STATUS_READY_TO_PACK,
  437. //                self::STATUS_CANCELED,
  438. //            ],
  439. //            self::STATUS_WAITING_FOR_ANSWER_ADMIN => [
  440. //                self::STATUS_PROCESSABLE,
  441. //                self::STATUS_PROCESSING,
  442. //                self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  443. //                self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  444. //                self::STATUS_WAITING_FOR_ANSWER_SALES,
  445. //                self::STATUS_WAITING_FOR_ANSWER_STOCK,
  446. //                self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  447. //                self::STATUS_WAITING_FOR_ANSWER_PARTS,
  448. //                self::STATUS_READY_TO_PACK,
  449. //                self::STATUS_CANCELED,
  450. //            ],
  451. //            self::STATUS_WAITING_FOR_ANSWER_AIKEN => [
  452. //                self::STATUS_PROCESSABLE,
  453. //                self::STATUS_PROCESSING,
  454. //                self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  455. //                self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  456. //                self::STATUS_WAITING_FOR_ANSWER_SALES,
  457. //                self::STATUS_WAITING_FOR_ANSWER_STOCK,
  458. //                self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  459. //                self::STATUS_WAITING_FOR_ANSWER_PARTS,
  460. //                self::STATUS_READY_TO_PACK,
  461. //                self::STATUS_CANCELED,
  462. //            ],
  463. //            self::STATUS_WAITING_FOR_ANSWER_PARTS => [
  464. //                self::STATUS_WAITING_FOR_ANSWER_PARTS,
  465. //                self::STATUS_PROCESSABLE,
  466. //                self::STATUS_PROCESSING,
  467. //                self::STATUS_WAITING_FOR_ANSWER_SALES,
  468. //                self::STATUS_WAITING_FOR_ANSWER_STOCK,
  469. //                self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  470. //                self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  471.         //        self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  472. //                self::STATUS_READY_TO_PACK,
  473. //                self::STATUS_CANCELED,
  474. //            ],
  475. //            self::STATUS_PROCESSABLE => [
  476. //                self::STATUS_PROCESSABLE,
  477. //                self::STATUS_PROCESSING,
  478. //                self::STATUS_WAITING_FOR_ANSWER_SALES,
  479. //                self::STATUS_WAITING_FOR_ANSWER_STOCK,
  480. //                self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  481. //                self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  482.         //        self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  483. //                self::STATUS_CANCELED,
  484. //            ],
  485. //            self::STATUS_PROCESSING => [
  486. //                self::STATUS_PROCESSING,
  487. //                self::STATUS_WAITING_FOR_ANSWER_SALES,
  488. //                self::STATUS_WAITING_FOR_ANSWER_STOCK,
  489. //                self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  490. //                self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  491. //                self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  492. //                self::STATUS_WAITING_FOR_ANSWER_PARTS,
  493. //                self::STATUS_READY_TO_PACK,
  494. //                self::STATUS_CANCELED,
  495. //            ],
  496. //            self::STATUS_READY_TO_PACK => [
  497. //                self::STATUS_READY_TO_PACK,
  498. //                self::STATUS_READY_TO_SHIP,
  499. //                self::STATUS_PROCESSING,
  500. //                self::STATUS_CANCELED,
  501. //            ],
  502. //
  503. //            self::STATUS_READY_TO_SHIP => [
  504. //                self::STATUS_READY_TO_SHIP,
  505. //                self::STATUS_READY_TO_PACK,
  506. //                self::STATUS_FINISHED,
  507. //                self::STATUS_CANCELED,
  508. //            ],
  509. //            default => [self::STATUS_CANCELED],
  510. //        };
  511.     }
  512.     public static function getWaitingForStatusIndexes(): array
  513.     {
  514.         return [
  515.             self::STATUS_WAITING_FOR_ANSWER_SALES,
  516.             self::STATUS_WAITING_FOR_ANSWER_STOCK,
  517.             self::STATUS_WAITING_FOR_ANSWER_SERVICE,
  518.             self::STATUS_WAITING_FOR_ANSWER_ADMIN,
  519.             self::STATUS_WAITING_FOR_ANSWER_AIKEN,
  520.             self::STATUS_WAITING_FOR_ANSWER_PARTS,
  521.             self::STATUS_WAITING_FOR_ANSWER_PARTNER,
  522.             self::STATUS_WAITING_FOR_ANSWER_DATA,
  523.         ];
  524.     }
  525.     public static function getWaitingForStatusForFilter(): array
  526.     {
  527.         return [
  528.             self::STATUS_WAITING_FOR_ANSWER_SALES   => 'Sales',
  529.             self::STATUS_WAITING_FOR_ANSWER_STOCK   => 'Stock',
  530.             self::STATUS_WAITING_FOR_ANSWER_SERVICE => 'Service',
  531.             self::STATUS_WAITING_FOR_ANSWER_ADMIN   => 'Admin',
  532.             self::STATUS_WAITING_FOR_ANSWER_PARTS   => 'Parts',
  533.             self::STATUS_WAITING_FOR_ANSWER_AIKEN   => 'Aiken',
  534.             self::STATUS_WAITING_FOR_ANSWER_PARTNER => 'Partner', 
  535.             self::STATUS_WAITING_FOR_ANSWER_DATA    => 'Data', 
  536.         ];
  537.     }
  538.     public static function getWaitingForProductionStatusIndexes(): array
  539.     {
  540.         return [
  541.             self::STATUS_WAITING_FOR_PARTNER,
  542.             self::STATUS_WAITING_FOR_PRODUCTION_SALES,
  543.             self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE,
  544.             self::STATUS_WAITING_FOR_PRODUCTION_AIKEN,
  545.             self::STATUS_WAITING_FOR_PRODUCTION_DATA
  546.         ];
  547.     }
  548.     public static function getWaitingForProductionStatusForFilter(): array
  549.     {
  550.         return [
  551.             self::STATUS_WAITING_FOR_PRODUCTION_SALES      => 'Sales',
  552.             self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE => 'Quarantine',
  553.             self::STATUS_WAITING_FOR_PRODUCTION_AIKEN      => 'Aiken'
  554.         ];
  555.     }
  556.     public static function getPreProcessingIssueStatusForFilter(): array
  557.     {
  558.         return [
  559.             self::STATUS_WAITING_FOR_PARTNER               => 'Partner',
  560.             self::STATUS_WAITING_FOR_PRODUCTION_SALES      => 'Sales',
  561.             self::STATUS_WAITING_FOR_PRODUCTION_QUARANTINE => 'Quarantine',
  562.             self::STATUS_WAITING_FOR_PRODUCTION_AIKEN      => 'Aiken',
  563.             self::STATUS_WAITING_FOR_PRODUCTION_DATA       => 'Data',
  564.         ];
  565.     }
  566.     /**
  567.      * @param null $currentStatus
  568.      * @param bool $isAtechPartnerChildOrder
  569.      * @param int|null $customerId
  570.      * @return array
  571.      */
  572.     public static function getAvailableStatusChoices(
  573.         $currentStatus = null,
  574.         $isAtechPartnerChildOrder = false,
  575.         ?int $customerId = null
  576.     ): array
  577.     {
  578.         $statusChoices = self::getStatusChoices();
  579.         if (is_null($currentStatus)) { // new order
  580.             $availableStatuses = [
  581.                 self::STATUS_TRIAGE => $statusChoices[self::STATUS_TRIAGE],
  582.             ];
  583.         } else { // edit order
  584.             if ($isAtechPartnerChildOrder) {
  585.                 if ($currentStatus == Order::STATUS_PICKUP_POINT) {
  586.                     $availableStatuses = [
  587.                         // edit from finished
  588.                         self::STATUS_WAITING => $statusChoices[self::STATUS_PICKUP_POINT],
  589.                     ];
  590.                 } else {
  591.                     $availableStatuses = [
  592.                         // edit from finished
  593.                         $currentStatus => $statusChoices[$currentStatus],
  594.                     ];
  595.                 }
  596.             } else {
  597.                 if ($currentStatus < self::STATUS_FINISHED) { // edit below finished
  598.                     $availableStatuses = $statusChoices;
  599.                 } else {
  600.                     $availableStatuses = [
  601.                         // edit from finished
  602.                         self::STATUS_FINISHED => $statusChoices[self::STATUS_FINISHED],
  603.                     ];
  604.                     if (!is_null($customerId) && $customerId == Customer::AMAZON_ID) {
  605.                         $availableStatuses[self::STATUS_CANCELED] = $statusChoices[self::STATUS_CANCELED];
  606.                     }
  607.                 }
  608.             }
  609.         }
  610.         return $availableStatuses;
  611.     }
  612.     /**
  613.      * @return array
  614.      */
  615.     public static function getParcelStatusChoices(): array
  616.     {
  617.         return [
  618.             self::PARCEL_STATUS_UNAVAILABLE => 'Unavailable',
  619.             self::PARCEL_STATUS_DATA_COLLECTED => 'Data collected',
  620.             self::PARCEL_STATUS_ARRIVAL_IN_DEPOT => 'Arrival in depot',
  621.             self::PARCEL_STATUS_IN_DELIVERY => 'In delivery',
  622.             self::PARCEL_STATUS_DELIVERED => 'Delivered',
  623.             self::PARCEL_STATUS_DATA_RECEIVED => 'Data received',
  624.             self::PARCEL_STATUS_COD_DATA_RECEIVED => 'COD data received',
  625.             self::PARCEL_STATUS_PACKAGE_PICKED_UP => 'Package picked up',
  626.         ];
  627.     }
  628.     /**
  629.      * @return array
  630.      */
  631.     public static function getCreatedByTypeChoices(): array
  632.     {
  633.         return [
  634.             self::CreatedByType_Customer,
  635.             self::CreatedByType_User,
  636.             self::CreatedByType_Import,
  637.         ];
  638.     }
  639.     /**
  640.      * @return array
  641.      */
  642.     public static function getWarrantyChoices(): array
  643.     {
  644.         return [
  645.             self::WARRANTY_NO => 'No warranty',
  646.             self::WARRANTY_30_DAYS => '30 days',
  647.             self::WARRANTY_6_MONTHS => '6 months',
  648.             self::WARRANTY_1_YEAR => '1 year',
  649.             self::WARRANTY_2_YEAR => '2 year',
  650.             self::WARRANTY_3_YEAR => '3 year',
  651.             self::WARRANTY_4_YEAR => '4 year',
  652.             self::WARRANTY_5_YEAR => '5 year',
  653.         ];
  654.     }
  655.     /**
  656.      * @return array
  657.      */
  658.     public static function getExternalOrderSourceChoices(): array
  659.     {
  660.         return [
  661.             self::EXTERNAL_ORDER_SOURCE_BACKMARKET => 'BackMarket',
  662.             self::EXTERNAL_ORDER_SOURCE_BACKMARKET_PRO => 'BackMarket PRO',
  663.             self::EXTERNAL_ORDER_SOURCE_REFURBED => 'refurbed',
  664.             self::EXTERNAL_ORDER_SOURCE_AMAZON => 'Amazon',
  665.             self::EXTERNAL_ORDER_SOURCE_EMAG => 'eMag',
  666.             self::EXTERNAL_ORDER_SOURCE_FNAC => 'Fnac',
  667.             self::EXTERNAL_ORDER_SOURCE_CDISCOUNT => 'Cdiscount',
  668.             self::EXTERNAL_ORDER_SOURCE_RAKUTEN => 'Rakuten',
  669.             self::EXTERNAL_ORDER_SOURCE_KAUFLAND => 'Kaufland',
  670.             self::EXTERNAL_ORDER_SOURCE_EBAY => 'eBay',
  671.             self::EXTERNAL_ORDER_SOURCE_ALLEGRO => 'Allegro',
  672.             self::EXTERNAL_ORDER_SOURCE_RICONDIZIONATO => 'Ricondizionato',
  673.             self::EXTERNAL_ORDER_SOURCE_AUKRO => 'Aukro',
  674.             self::EXTERNAL_ORDER_SOURCE_UNAS => 'Unas',
  675.             self::EXTERNAL_ORDER_SOURCE_MEDIAMARKT    => 'MediaMarkt',
  676.             self::EXTERNAL_ORDER_SOURCE_PCCOMPONENTES => 'PcComponentes',
  677.         ];
  678.     }
  679.     /**
  680.      * @return string[]
  681.      */
  682.     public static function getMarketplaces(): array
  683.     {
  684.         return [
  685.             self::EXTERNAL_ORDER_SOURCE_BACKMARKET => 'Backmarket',
  686.             self::EXTERNAL_ORDER_SOURCE_REFURBED => 'Refurbed',
  687.             self::EXTERNAL_ORDER_SOURCE_AMAZON => 'Amazon',
  688.             self::EXTERNAL_ORDER_SOURCE_EMAG => 'Emag',
  689.             self::EXTERNAL_ORDER_SOURCE_FNAC => 'FNAC',
  690.             self::EXTERNAL_ORDER_SOURCE_CDISCOUNT => 'Cdiscount',
  691.             self::EXTERNAL_ORDER_SOURCE_RAKUTEN => 'Rakuten',
  692.             self::EXTERNAL_ORDER_SOURCE_KAUFLAND => 'Kaufland',
  693.             self::EXTERNAL_ORDER_SOURCE_EBAY => 'Ebay',
  694.             self::EXTERNAL_ORDER_SOURCE_ALLEGRO => 'Allegro',
  695.             self::EXTERNAL_ORDER_SOURCE_RICONDIZIONATO => 'Ricondizionato',
  696.             self::EXTERNAL_ORDER_SOURCE_BACKMARKET_PRO => 'Backmarket Pro',
  697.             self::EXTERNAL_ORDER_SOURCE_AUKRO => 'Aukro',
  698.             self::EXTERNAL_ORDER_SOURCE_UNAS => 'Unas',
  699.             self::EXTERNAL_ORDER_SOURCE_MEDIAMARKT    => 'MediaMarkt',
  700.             self::EXTERNAL_ORDER_SOURCE_PCCOMPONENTES => 'PcComponentes',
  701.         ];
  702.     }
  703.     /**
  704.      * @param string $code
  705.      * @param int $source
  706.      * @return bool
  707.      */
  708.     public static function isExternalOrderCodeValidForSource(string $code, int $source): bool
  709.     {
  710.         $valid = true;
  711.         if ($code) {
  712.             switch ($source) {
  713.                 case self::EXTERNAL_ORDER_SOURCE_BACKMARKET:
  714.                     $valid = preg_match('/^\d{8}$/', $code);
  715.                     break;
  716.                 case self::EXTERNAL_ORDER_SOURCE_REFURBED:
  717.                     $valid = preg_match('/^\d{7}$/', $code) || preg_match('/^\d{8}$/', $code);
  718.                     break;
  719.                 case self::EXTERNAL_ORDER_SOURCE_AMAZON:
  720.                     $valid = preg_match('/^\d{3}-\d{7}-\d{7}$/', $code);
  721.                     break;
  722.                 case self::EXTERNAL_ORDER_SOURCE_EMAG:
  723.                 case self::EXTERNAL_ORDER_SOURCE_FNAC:
  724.                 case self::EXTERNAL_ORDER_SOURCE_CDISCOUNT:
  725.                 case self::EXTERNAL_ORDER_SOURCE_RAKUTEN:
  726.                 default:
  727.                     break;
  728.             }
  729.         }
  730.         return $valid;
  731.     }
  732.     /**
  733.      * @var Domain
  734.      *
  735.      * @ManyToOne(targetEntity="Domain", inversedBy="orders")
  736.      * @JoinColumn(name="domain_id", referencedColumnName="id")
  737.      */
  738.     private $domain;
  739.     /**
  740.      * @var Customer
  741.      *
  742.      * @ManyToOne(targetEntity="Customer", inversedBy="orders")
  743.      * @JoinColumn(name="customer_id", referencedColumnName="id")
  744.      */
  745.     private $customer;
  746.     /**
  747.      * @var string
  748.      *
  749.      * @Assert\NotNull
  750.      *
  751.      * @Column(name="status", type="string", length=16)
  752.      */
  753.     private $status;
  754.     public const string PaymentStatus_Pending = 'Pending';
  755.     public const string PaymentStatus_Paid = 'Paid';
  756.     public const string PaymentStatus_Failed = 'Failed';
  757.     public const string PaymentStatus_OverPaid = 'Over paid';
  758.     public const string PaymentStatus_Partial = 'Partial';
  759.     public const string PaymentStatus_Commission = 'Commission';
  760.     public const int PAYMENT_STATUS_ID_PENDING = 0;
  761.     public const int PAYMENT_STATUS_ID_PAID = 1;
  762.     public const int PAYMENT_STATUS_ID_FAILED = 2;
  763.     public const int PAYMENT_STATUS_ID_OVERLOAD = 3;
  764.     public const int PAYMENT_STATUS_ID_PARTIAL = 4;
  765.     public const int PAYMENT_STATUS_ID_COMMISSION = 5;
  766.     /**
  767.      * @return string[]
  768.      */
  769.     public static function getPaymentStatusChoices(): array
  770.     {
  771.         return [
  772.             self::PAYMENT_STATUS_ID_PENDING => self::PaymentStatus_Pending,
  773.             self::PAYMENT_STATUS_ID_PAID => self::PaymentStatus_Paid,
  774.             self::PAYMENT_STATUS_ID_FAILED => self::PaymentStatus_Failed,
  775.             self::PAYMENT_STATUS_ID_OVERLOAD => self::PaymentStatus_OverPaid,
  776.             self::PAYMENT_STATUS_ID_PARTIAL => self::PaymentStatus_Partial,
  777.             self::PAYMENT_STATUS_ID_COMMISSION => self::PaymentStatus_Commission,
  778.         ];
  779.     }
  780.     /**
  781.      * @var int
  782.      *
  783.      * @Column(name="payment_status", type="integer")
  784.      */
  785.     private $paymentStatus;
  786.     /**
  787.      * @var string
  788.      *
  789.      * @Column(name="invoice_code", type="string", length=16, nullable=true)
  790.      */
  791.     private $invoiceCode;
  792.     /**
  793.      * @var string
  794.      *
  795.      * @Assert\NotNull
  796.      *
  797.      * @Column(name="payment_type", type="string", length=16)
  798.      */
  799.     private $paymentType;
  800.     /**
  801.      * @var int
  802.      *
  803.      * @Column(name="payment_price", type="decimal", precision=10, scale=2, nullable=true)
  804.      */
  805.     private $paymentPrice;
  806.     /**
  807.      * @var string
  808.      *
  809.      * @Assert\NotNull
  810.      *
  811.      * @Column(name="shipping_type", type="string", length=16)
  812.      */
  813.     private $shippingType;
  814.     /**
  815.      * @var int
  816.      *
  817.      * @Column(name="shipping_price", type="decimal", precision=10, scale=2, nullable=true)
  818.      */
  819.     private $shippingPrice;
  820.     /**
  821.      * @var string
  822.      *
  823.      * @Assert\NotNull
  824.      *
  825.      * @Column(name="billing_first_name", type="string", length=64)
  826.      */
  827.     private $billingFirstName;
  828.     /**
  829.      * @var string
  830.      *
  831.      * @Assert\NotNull
  832.      *
  833.      * @Column(name="billing_last_name", type="string", length=64)
  834.      */
  835.     private $billingLastName;
  836.     /**
  837.      * @var string
  838.      *
  839.      * @Column(name="billing_business_name", type="string", length=128, nullable=true)
  840.      */
  841.     private $billingBusinessName = null;
  842.     /**
  843.      * @var string
  844.      *
  845.      * @Assert\NotNull
  846.      *
  847.      * @Column(name="billing_street", type="string", length=128)
  848.      */
  849.     private $billingStreet;
  850.     /**
  851.      * @var string
  852.      *
  853.      * @Assert\NotNull
  854.      *
  855.      * @Column(name="billing_city", type="string", length=64)
  856.      */
  857.     private $billingCity;
  858.     /**
  859.      * @var string
  860.      *
  861.      * @Assert\NotNull
  862.      *
  863.      * @Column(name="billing_zip", type="string", length=12)
  864.      */
  865.     private $billingZip;
  866.     /**
  867.      * @var string
  868.      *
  869.      * @Assert\NotNull
  870.      *
  871.      * @Column(name="billing_country", type="string", length=32)
  872.      */
  873.     private $billingCountry;
  874.     /**
  875.      * @var string
  876.      *
  877.      * @Column(name="billing_business_id", type="string", length=16, nullable=true)
  878.      */
  879.     private $billingBusinessId = null;
  880.     /**
  881.      * @var string
  882.      *
  883.      * @Column(name="billing_tax_id", type="string", length=16, nullable=true)
  884.      */
  885.     private $billingTaxId = null;
  886.     /**
  887.      * @var string
  888.      *
  889.      * @Column(name="billing_vat_id", type="string", length=16, nullable=true)
  890.      */
  891.     private $billingVatId = null;
  892.     /**
  893.      * @var string
  894.      *
  895.      * @Assert\NotNull
  896.      *
  897.      * @Column(name="billing_email", type="string", length=64)
  898.      */
  899.     private $billingEmail;
  900.     /**
  901.      * @var string
  902.      *
  903.      * @Assert\NotNull
  904.      *
  905.      * @Column(name="billing_phone_number", type="string", length=32)
  906.      */
  907.     private $billingPhone;
  908.     /**
  909.      * @var string
  910.      *
  911.      * @Column(name="shipping_first_name", type="string", length=64, nullable=true)
  912.      */
  913.     private $shippingFirstName;
  914.     /**
  915.      * @var string
  916.      *
  917.      * @Column(name="shipping_last_name", type="string", length=64, nullable=true)
  918.      */
  919.     private $shippingLastName;
  920.     /**
  921.      * @var string
  922.      *
  923.      * @Column(name="shipping_business_name", type="string", length=128, nullable=true)
  924.      */
  925.     private $shippingBusinessName = null;
  926.     /**
  927.      * @var string
  928.      *
  929.      * @Column(name="shipping_street", type="string", length=128, nullable=true)
  930.      */
  931.     private $shippingStreet;
  932.     /**
  933.      * @var string
  934.      *
  935.      * @Column(name="shipping_city", type="string", length=64, nullable=true)
  936.      */
  937.     private $shippingCity;
  938.     /**
  939.      * @var string
  940.      *
  941.      * @Column(name="shipping_zip", type="string", length=12, nullable=true)
  942.      */
  943.     private $shippingZip;
  944.     /**
  945.      * @var string
  946.      *
  947.      * @Column(name="shipping_country", type="string", length=32, nullable=true)
  948.      */
  949.     private $shippingCountry;
  950.     /**
  951.      * @var string
  952.      *
  953.      * @Column(name="shipping_email", type="string", length=64, nullable=true)
  954.      */
  955.     private $shippingEmail;
  956.     /**
  957.      * @var string
  958.      *
  959.      * @Column(name="shipping_phone_number", type="string", length=32, nullable=true)
  960.      */
  961.     private $shippingPhone;
  962.     /**
  963.      * @var string
  964.      *
  965.      * @Column(name="message", type="text", nullable=true)
  966.      */
  967.     private $message;
  968.     /**
  969.      * @var string
  970.      *
  971.      * @Column(name="coupon_code", type="string", length=255, nullable=true)
  972.      */
  973.     private $couponCode;
  974.     /**
  975.      * @var \DateTime
  976.      *
  977.      * @Column(name="ship_date", type="datetime", nullable=true)
  978.      */
  979.     private $shipDate;
  980.     /**
  981.      * @var \DateTime|null
  982.      *
  983.      * @Column(name="planned_ship_date", type="datetime", nullable=true)
  984.      */
  985.     private $plannedShipDate;
  986.     /**
  987.      * @var \DateTime
  988.      *
  989.      * @Column(name="delivery_date", type="datetime", nullable=true)
  990.      */
  991.     private $deliveryDate;
  992.     /**
  993.      * @return array
  994.      */
  995.     public static function getBoxCountChoices(): array
  996.     {
  997.         $choices = [];
  998.         for ($x = 0; $x <= 60; $x++) {
  999.             $choices[$x] = $x;
  1000.         }
  1001.         return $choices;
  1002.     }
  1003.     /**
  1004.      * @var int
  1005.      *
  1006.      * @Column(name="box_count", type="integer")
  1007.      */
  1008.     private $boxCount = 1;
  1009.     /**
  1010.      * @var bool
  1011.      *
  1012.      * @Column(name="useBillingAddressAsShippingAddress", type="boolean")
  1013.      */
  1014.     private $useBillingAddressAsShippingAddress = true;
  1015.     /**
  1016.      * @var float
  1017.      *
  1018.      * @Column(name="full_price", type="decimal", precision=10, scale=2)
  1019.      */
  1020.     private $fullPrice = 0;
  1021.     /**
  1022.      * @var string
  1023.      *
  1024.      * @Column(name="presta_order_code", type="string", length=24, nullable=true)
  1025.      */
  1026.     private $prestaOrderCode;
  1027.     /**
  1028.      * @var int|null
  1029.      *
  1030.      * @Column(name="external_order_source", type="integer", nullable=true)
  1031.      */
  1032.     private $externalOrderSource;
  1033.     /**
  1034.      * @var string|null
  1035.      *
  1036.      * @Column(name="external_order_code", type="string", length=32, nullable=true)
  1037.      */
  1038.     private $externalOrderCode;
  1039.     /**
  1040.      * @var bool
  1041.      *
  1042.      * @Column(name="message_done", type="boolean")
  1043.      */
  1044.     private $messageDone = false;
  1045.     /**
  1046.      * @var User
  1047.      *
  1048.      * @ManyToOne(targetEntity="User")
  1049.      * @JoinColumn(name="message_done_by", referencedColumnName="id", nullable=true)
  1050.      */
  1051.     private $messageDoneBy;
  1052.     /**
  1053.      * @var \DateTime
  1054.      *
  1055.      * @Column(name="message_done_time", type="datetime", nullable=true)
  1056.      */
  1057.     private $messageDoneTime;
  1058.     /**
  1059.      * @var ArrayCollection
  1060.      *
  1061.      * @OneToMany(targetEntity="CustomerBillingoData", mappedBy="order", orphanRemoval=true)
  1062.      * @OrderBy({"created" = "DESC"})
  1063.      **/
  1064.     private $billingoDocuments;
  1065.     /**
  1066.      * @var bool
  1067.      *
  1068.      * @Column(name="force_free_shipping", type="boolean")
  1069.      */
  1070.     private $forceFreeShipping = false;
  1071.     /**
  1072.      * @var int
  1073.      *
  1074.      * @Column(name="warranty", type="integer", nullable=true)
  1075.      */
  1076.     private $warranty;
  1077.     /**
  1078.      * @var int
  1079.      *
  1080.      * @Column(name="created_by_type", type="integer")
  1081.      */
  1082.     private $createdByType = 0;
  1083.     /**
  1084.      * @var bool
  1085.      *
  1086.      * @Column(name="archived", type="boolean")
  1087.      */
  1088.     private $archived = false;
  1089.     /**
  1090.      * @var ArrayCollection
  1091.      *
  1092.      * @OneToMany(targetEntity="OrderItem", mappedBy="order", orphanRemoval=true)
  1093.      * @OrderBy({"created" = "ASC", "id" = "ASC"})
  1094.      **/
  1095.     private $orderItems;
  1096.     /**
  1097.      * @var ArrayCollection
  1098.      *
  1099.      * @OneToMany(targetEntity="Document", mappedBy="order", orphanRemoval=true)
  1100.      * @OrderBy({"created" = "DESC"})
  1101.      **/
  1102.     private $documents;
  1103.     /**
  1104.      * @var ArrayCollection
  1105.      *
  1106.      * @OneToMany(targetEntity="StockMovement", mappedBy="order", orphanRemoval=true)
  1107.      * @OrderBy({"created" = "DESC"})
  1108.      **/
  1109.     private $stockMovements;
  1110.     /**
  1111.      * @var ArrayCollection
  1112.      *
  1113.      * @OneToMany(targetEntity="StockMovement", mappedBy="orderConfigChange", orphanRemoval=true)
  1114.      * @OrderBy({"created" = "DESC"})
  1115.      **/
  1116.     private $configChangeStockMovements;
  1117.     /**
  1118.      * @var int
  1119.      *
  1120.      * @Column(name="discount", type="integer")
  1121.      **/
  1122.     private $discount = 0;
  1123.     /**
  1124.      * @var ArrayCollection
  1125.      *
  1126.      * @OneToMany(targetEntity="OrderComment", mappedBy="order", orphanRemoval=true)
  1127.      * @OrderBy({"type"="ASC","created" = "DESC"})
  1128.      **/
  1129.     private $comments;
  1130.     /**
  1131.      * @var ArrayCollection
  1132.      *
  1133.      * @OneToMany(targetEntity="OrderSetting", mappedBy="order", orphanRemoval=true)
  1134.      * @OrderBy({"created" = "DESC"})
  1135.      **/
  1136.     private $settings;
  1137.     /**
  1138.      * @var ArrayCollection
  1139.      *
  1140.      * @OneToMany(targetEntity="OrderPackage", mappedBy="order", orphanRemoval=true)
  1141.      * @OrderBy({"created" = "ASC"})
  1142.      **/
  1143.     private $packages;
  1144.     /**
  1145.      * @var ArrayCollection
  1146.      *
  1147.      * @OneToMany(targetEntity="Claim", mappedBy="order", orphanRemoval=true)
  1148.      * @OrderBy({"created" = "ASC"})
  1149.      **/
  1150.     private $claims;
  1151.     /**
  1152.      * @var string
  1153.      *
  1154.      * @Column(name="tracking_url", type="string", nullable=true)
  1155.      */
  1156.     private $trackingUrl;
  1157.     /**
  1158.      * @var string
  1159.      *
  1160.      * @Column(name="parcelNumber", type="string", length=256, nullable=true)
  1161.      */
  1162.     private $parcelNumber;
  1163.     /**
  1164.      * @var string
  1165.      *
  1166.      * @Column(name="dhlShipmentNumber", type="string", length=256, nullable=true)
  1167.      */
  1168.     private $dhlShipmentNumber;
  1169.     /**
  1170.      * @var int
  1171.      *
  1172.      * @Column(name="parcelStatus", type="integer", nullable=true)
  1173.      */
  1174.     private $parcelStatus;
  1175.     /**
  1176.      * @var bool
  1177.      *
  1178.      * @Column(name="priority", type="boolean")
  1179.      */
  1180.     private $priority = false;
  1181.     /**
  1182.      * @var int|null
  1183.      *
  1184.      * @Column(name="base_order_id", type="integer", nullable=true)
  1185.      */
  1186.     private $baseOrderId = null;
  1187.     /**
  1188.      * @var float|null
  1189.      *
  1190.      * @Column(name="vat", type="decimal", precision=10, scale=2, nullable=true)
  1191.      */
  1192.     private $vat = null;
  1193.     public function __construct()
  1194.     {
  1195.         parent::__construct();
  1196.         $this->orderItems = new ArrayCollection();
  1197.         $this->orderChangelog = new ArrayCollection();
  1198.         $this->documents = new ArrayCollection();
  1199.         $this->stockMovements = new ArrayCollection();
  1200.         $this->configChangeStockMovements = new ArrayCollection();
  1201.         $this->comments = new ArrayCollection();
  1202.         $this->settings = new ArrayCollection();
  1203.         $this->packages = new ArrayCollection();
  1204.         $this->claims = new ArrayCollection();
  1205.     }
  1206.     /**
  1207.      * @return Domain
  1208.      */
  1209.     public function getDomain()
  1210.     {
  1211.         return $this->domain;
  1212.     }
  1213.     /**
  1214.      * @param Domain $domain
  1215.      */
  1216.     public function setDomain($domain)
  1217.     {
  1218.         $this->domain = $domain;
  1219.     }
  1220.     /**
  1221.      * @return Customer
  1222.      */
  1223.     public function getCustomer()
  1224.     {
  1225.         return $this->customer;
  1226.     }
  1227.     /**
  1228.      * @param Customer $customer
  1229.      */
  1230.     public function setCustomer($customer)
  1231.     {
  1232.         $this->customer = $customer;
  1233.     }
  1234.     /**
  1235.      * @return string
  1236.      */
  1237.     public function getStatus()
  1238.     {
  1239.         return $this->status;
  1240.     }
  1241.     /**
  1242.      * @param string $status
  1243.      */
  1244.     public function setStatus($status)
  1245.     {
  1246.         $this->status = $status;
  1247.     }
  1248.     /**
  1249.      * @return int
  1250.      */
  1251.     public function getPaymentStatus()
  1252.     {
  1253.         return $this->paymentStatus;
  1254.     }
  1255.     /**
  1256.      * @param int $paymentStatus
  1257.      */
  1258.     public function setPaymentStatus($paymentStatus)
  1259.     {
  1260.         $this->paymentStatus = $paymentStatus;
  1261.     }
  1262.     /**
  1263.      * @return string
  1264.      */
  1265.     public function getPaymentType()
  1266.     {
  1267.         return $this->paymentType;
  1268.     }
  1269.     /**
  1270.      * @param string $paymentType
  1271.      */
  1272.     public function setPaymentType($paymentType)
  1273.     {
  1274.         $this->paymentType = $paymentType;
  1275.     }
  1276.     /**
  1277.      * Returns the title of current payment type, or null if not set
  1278.      *
  1279.      * @param TranslatorInterface|null $translator
  1280.      * @return mixed
  1281.      */
  1282.     public function getPaymentTypeTitle(?TranslatorInterface $translator = null)
  1283.     {
  1284.         if ($this->paymentType != null) {
  1285.             $paymentTypes = PaymentType::getChoices();
  1286.             return is_null($translator) ? $paymentTypes[$this->paymentType] : $translator->trans(
  1287.                 $paymentTypes[$this->paymentType]
  1288.             );
  1289.         } else {
  1290.             return null;
  1291.         }
  1292.     }
  1293.     /**
  1294.      * @return string
  1295.      */
  1296.     public function getShippingType()
  1297.     {
  1298.         return $this->shippingType;
  1299.     }
  1300.     /**
  1301.      * @param string $shippingType
  1302.      */
  1303.     public function setShippingType($shippingType)
  1304.     {
  1305.         $this->shippingType = $shippingType;
  1306.     }
  1307.     /**
  1308.      * Returns the title of current shipping type, or null if not set
  1309.      *
  1310.      * @param TranslatorInterface|null $translator
  1311.      * @return mixed
  1312.      */
  1313.     public function getShippingTypeTitle(?TranslatorInterface $translator = null)
  1314.     {
  1315.         if ($this->shippingType != null) {
  1316.             $shippingTypes = DomainShippingType::getShippingTypeChoices();
  1317.             return is_null($translator) ? $shippingTypes[$this->shippingType] : $translator->trans(
  1318.                 $shippingTypes[$this->shippingType]
  1319.             );
  1320.         } else {
  1321.             return null;
  1322.         }
  1323.     }
  1324.     /**
  1325.      * @return string
  1326.      */
  1327.     public function getBillingPhone()
  1328.     {
  1329.         return $this->billingPhone;
  1330.     }
  1331.     /**
  1332.      * @param string $billingPhone
  1333.      */
  1334.     public function setBillingPhone($billingPhone)
  1335.     {
  1336.         $this->billingPhone = $billingPhone;
  1337.     }
  1338.     /**
  1339.      * @return string
  1340.      */
  1341.     public function getBillingCountry()
  1342.     {
  1343.         return $this->billingCountry;
  1344.     }
  1345.     /**
  1346.      * @param string $billingCountry
  1347.      */
  1348.     public function setBillingCountry($billingCountry)
  1349.     {
  1350.         $this->billingCountry = $billingCountry;
  1351.     }
  1352.     /**
  1353.      * @return string
  1354.      */
  1355.     public function getBillingCity()
  1356.     {
  1357.         return $this->billingCity;
  1358.     }
  1359.     /**
  1360.      * @param string $billingCity
  1361.      */
  1362.     public function setBillingCity($billingCity)
  1363.     {
  1364.         $this->billingCity = $billingCity;
  1365.     }
  1366.     /**
  1367.      * @return string
  1368.      */
  1369.     public function getShippingPhone()
  1370.     {
  1371.         return $this->shippingPhone;
  1372.     }
  1373.     /**
  1374.      * @param string $shippingPhone
  1375.      */
  1376.     public function setShippingPhone($shippingPhone)
  1377.     {
  1378.         $this->shippingPhone = $shippingPhone;
  1379.     }
  1380.     /**
  1381.      * @return string
  1382.      */
  1383.     public function getShippingEmail()
  1384.     {
  1385.         return $this->shippingEmail;
  1386.     }
  1387.     /**
  1388.      * @param string $shippingEmail
  1389.      */
  1390.     public function setShippingEmail($shippingEmail)
  1391.     {
  1392.         $this->shippingEmail = $shippingEmail;
  1393.     }
  1394.     /**
  1395.      * @return string
  1396.      */
  1397.     public function getShippingCountry()
  1398.     {
  1399.         return $this->shippingCountry;
  1400.     }
  1401.     /**
  1402.      * @param string $shippingCountry
  1403.      */
  1404.     public function setShippingCountry($shippingCountry)
  1405.     {
  1406.         $this->shippingCountry = $shippingCountry;
  1407.     }
  1408.     /**
  1409.      * @return string
  1410.      */
  1411.     public function getShippingCity()
  1412.     {
  1413.         return $this->shippingCity;
  1414.     }
  1415.     /**
  1416.      * @param string $shippingCity
  1417.      */
  1418.     public function setShippingCity($shippingCity)
  1419.     {
  1420.         $this->shippingCity = $shippingCity;
  1421.     }
  1422.     /**
  1423.      * @return string
  1424.      */
  1425.     public function getInvoiceCode()
  1426.     {
  1427.         return $this->invoiceCode;
  1428.     }
  1429.     /**
  1430.      * @param string $invoiceCode
  1431.      */
  1432.     public function setInvoiceCode($invoiceCode)
  1433.     {
  1434.         $this->invoiceCode = $invoiceCode;
  1435.     }
  1436.     /**
  1437.      * @return string
  1438.      */
  1439.     public function getBillingFirstName()
  1440.     {
  1441.         return $this->billingFirstName;
  1442.     }
  1443.     /**
  1444.      * @param string $billingFirstName
  1445.      */
  1446.     public function setBillingFirstName($billingFirstName)
  1447.     {
  1448.         $this->billingFirstName = ucfirst($billingFirstName);
  1449.     }
  1450.     /**
  1451.      * @return string
  1452.      */
  1453.     public function getBillingLastName()
  1454.     {
  1455.         return $this->billingLastName;
  1456.     }
  1457.     /**
  1458.      * @param string $billingLastName
  1459.      */
  1460.     public function setBillingLastName($billingLastName)
  1461.     {
  1462.         $this->billingLastName = ucfirst($billingLastName);
  1463.     }
  1464.     /**
  1465.      * @return string
  1466.      */
  1467.     public function getBillingBusinessName()
  1468.     {
  1469.         return $this->billingBusinessName;
  1470.     }
  1471.     /**
  1472.      * @param string $billingBusinessName
  1473.      */
  1474.     public function setBillingBusinessName($billingBusinessName)
  1475.     {
  1476.         $this->billingBusinessName = $billingBusinessName;
  1477.     }
  1478.     /**
  1479.      * @return string
  1480.      */
  1481.     public function getBillingStreet()
  1482.     {
  1483.         return $this->billingStreet;
  1484.     }
  1485.     /**
  1486.      * @param string $billingStreet
  1487.      */
  1488.     public function setBillingStreet($billingStreet)
  1489.     {
  1490.         $this->billingStreet = $billingStreet;
  1491.     }
  1492.     /**
  1493.      * @return string
  1494.      */
  1495.     public function getBillingZip()
  1496.     {
  1497.         return $this->billingZip;
  1498.     }
  1499.     /**
  1500.      * @param string $billingZip
  1501.      */
  1502.     public function setBillingZip($billingZip)
  1503.     {
  1504.         $this->billingZip = preg_replace('/^[A-Z]{2}[-,\s]+/', '', (string) $billingZip);
  1505.     }
  1506.     /**
  1507.      * @return string
  1508.      */
  1509.     public function getBillingBusinessId()
  1510.     {
  1511.         return $this->billingBusinessId;
  1512.     }
  1513.     /**
  1514.      * @param string $billingBusinessId
  1515.      */
  1516.     public function setBillingBusinessId($billingBusinessId)
  1517.     {
  1518.         $this->billingBusinessId = $billingBusinessId;
  1519.     }
  1520.     /**
  1521.      * @return string
  1522.      */
  1523.     public function getBillingTaxId()
  1524.     {
  1525.         return $this->billingTaxId;
  1526.     }
  1527.     /**
  1528.      * @param string $billingTaxId
  1529.      */
  1530.     public function setBillingTaxId($billingTaxId)
  1531.     {
  1532.         $this->billingTaxId = $billingTaxId;
  1533.     }
  1534.     /**
  1535.      * @return string
  1536.      */
  1537.     public function getBillingVatId()
  1538.     {
  1539.         return $this->billingVatId;
  1540.     }
  1541.     /**
  1542.      * @param string $billingVatId
  1543.      */
  1544.     public function setBillingVatId($billingVatId)
  1545.     {
  1546.         $this->billingVatId = $billingVatId;
  1547.     }
  1548.     /**
  1549.      * @return string
  1550.      */
  1551.     public function getBillingEmail()
  1552.     {
  1553.         return $this->billingEmail;
  1554.     }
  1555.     /**
  1556.      * @param string $billingEmail
  1557.      */
  1558.     public function setBillingEmail($billingEmail)
  1559.     {
  1560.         $this->billingEmail = $billingEmail;
  1561.     }
  1562.     /**
  1563.      * @return string
  1564.      */
  1565.     public function getShippingFirstName()
  1566.     {
  1567.         return $this->shippingFirstName;
  1568.     }
  1569.     /**
  1570.      * @param string $shippingFirstName
  1571.      */
  1572.     public function setShippingFirstName($shippingFirstName)
  1573.     {
  1574.         $this->shippingFirstName = ucfirst($shippingFirstName);
  1575.     }
  1576.     /**
  1577.      * @return string
  1578.      */
  1579.     public function getShippingLastName()
  1580.     {
  1581.         return $this->shippingLastName;
  1582.     }
  1583.     /**
  1584.      * @param string $shippingLastName
  1585.      */
  1586.     public function setShippingLastName($shippingLastName)
  1587.     {
  1588.         $this->shippingLastName = ucfirst($shippingLastName);
  1589.     }
  1590.     /**
  1591.      * @return string
  1592.      */
  1593.     public function getShippingBusinessName()
  1594.     {
  1595.         return $this->shippingBusinessName;
  1596.     }
  1597.     /**
  1598.      * @param string $shippingBusinessName
  1599.      */
  1600.     public function setShippingBusinessName($shippingBusinessName)
  1601.     {
  1602.         $this->shippingBusinessName = $shippingBusinessName;
  1603.     }
  1604.     /**
  1605.      * @return string
  1606.      */
  1607.     public function getShippingStreet()
  1608.     {
  1609.         return $this->shippingStreet;
  1610.     }
  1611.     /**
  1612.      * @param string $shippingStreet
  1613.      */
  1614.     public function setShippingStreet($shippingStreet)
  1615.     {
  1616.         $this->shippingStreet = $shippingStreet;
  1617.     }
  1618.     /**
  1619.      * @return string
  1620.      */
  1621.     public function getShippingZip()
  1622.     {
  1623.         return $this->shippingZip;
  1624.     }
  1625.     /**
  1626.      * @param string $shippingZip
  1627.      */
  1628.     public function setShippingZip($shippingZip)
  1629.     {
  1630.         $this->shippingZip = preg_replace('/^[A-Z]{2}[-,\s]+/', '', (string) $shippingZip);
  1631.     }
  1632.     public function hasProblematicShippingAddress(): bool
  1633.     {
  1634.         $fields = array_filter([
  1635.             $this->shippingFirstName,
  1636.             $this->shippingLastName,
  1637.             $this->shippingBusinessName,
  1638.             $this->shippingStreet,
  1639.             $this->shippingCity,
  1640.         ]);
  1641.         $combined = implode(' ', $fields);
  1642.         if (preg_match('/[°@&#€%\(\)\[\]{}<>ר]/u', $combined)) {
  1643.             return true;
  1644.         }
  1645.         $wordPatterns = [
  1646.             '/\bajtó\b/iu',
  1647.             '/\bszoba\b/iu',
  1648.             '/\bGmbH\b/i',
  1649.             '/\bC\.o\.?\b/i',
  1650.             '/\bKft\.?/i',
  1651.             '/\bs\.r\.o\.?/i',
  1652.         ];
  1653.         foreach ($wordPatterns as $pattern) {
  1654.             if (preg_match($pattern, $combined)) {
  1655.                 return true;
  1656.             }
  1657.         }
  1658.         return false;
  1659.     }
  1660.     /**
  1661.      * @return int
  1662.      */
  1663.     public function getBoxCount()
  1664.     {
  1665.         return $this->boxCount;
  1666.     }
  1667.     /**
  1668.      * @param int $boxCount
  1669.      */
  1670.     public function setBoxCount($boxCount)
  1671.     {
  1672.         $this->boxCount = $boxCount;
  1673.     }
  1674.     /**
  1675.      * @return string
  1676.      */
  1677.     public function getMessage()
  1678.     {
  1679.         return $this->message;
  1680.     }
  1681.     /**
  1682.      * @param string $message
  1683.      */
  1684.     public function setMessage($message)
  1685.     {
  1686.         $this->message = $message;
  1687.     }
  1688.     /**
  1689.      * @return string
  1690.      */
  1691.     public function getCouponCode()
  1692.     {
  1693.         return $this->couponCode;
  1694.     }
  1695.     /**
  1696.      * @param string $couponCode
  1697.      */
  1698.     public function setCouponCode($couponCode)
  1699.     {
  1700.         $this->couponCode = $couponCode;
  1701.     }
  1702.     /**
  1703.      * @return boolean
  1704.      */
  1705.     public function useBillingAddressAsShippingAddress()
  1706.     {
  1707.         return $this->useBillingAddressAsShippingAddress;
  1708.     }
  1709.     /**
  1710.      * @param boolean $useBillingAddressAsShippingAddress
  1711.      */
  1712.     public function setUseBillingAddressAsShippingAddress($useBillingAddressAsShippingAddress)
  1713.     {
  1714.         $this->useBillingAddressAsShippingAddress = $useBillingAddressAsShippingAddress;
  1715.     }
  1716.     /**
  1717.      * @return ArrayCollection
  1718.      */
  1719.     public function getOrderItems()
  1720.     {
  1721.         return $this->orderItems;
  1722.     }
  1723.     /**
  1724.      * @param ArrayCollection $orderItems
  1725.      */
  1726.     public function setOrderItems($orderItems)
  1727.     {
  1728.         if ($this->orderItems === $orderItems) {
  1729.             return;
  1730.         }
  1731.         // orderItems is a OneToMany with orphanRemoval=true: reassigning the property outright
  1732.         // de-references Doctrine's tracked collection, which schedules a bulk DELETE of everything
  1733.         // it held (even already-persisted, still-valid items). Mutate the existing collection instead.
  1734.         $this->orderItems->clear();
  1735.         foreach ($orderItems as $orderItem) {
  1736.             $this->orderItems->add($orderItem);
  1737.         }
  1738.     }
  1739.     /**
  1740.      * @return ArrayCollection
  1741.      */
  1742.     public function getDocuments()
  1743.     {
  1744.         return $this->documents;
  1745.     }
  1746.     /**
  1747.      * @return ArrayCollection
  1748.      */
  1749.     public function getStockMovements()
  1750.     {
  1751.         return $this->stockMovements;
  1752.     }
  1753.     /**
  1754.      * @return void
  1755.      */
  1756.     public function reMakeArrayCollectionsForOrder()
  1757.     {
  1758.         $this->orderItems = new ArrayCollection();
  1759.         $this->orderChangelog = new ArrayCollection();
  1760.         $this->documents = new ArrayCollection();
  1761.         $this->stockMovements = new ArrayCollection();
  1762.         $this->configChangeStockMovements = new ArrayCollection();
  1763.         $this->comments = new ArrayCollection();
  1764.         $this->settings = new ArrayCollection();
  1765.         $this->packages = new ArrayCollection();
  1766.         $this->claims = new ArrayCollection();
  1767.     }
  1768.     public function getClaims()
  1769.     {
  1770.         return $this->claims;
  1771.     }
  1772.     /**
  1773.      * @return void
  1774.      */
  1775.     public function emptyStockMovements()
  1776.     {
  1777.         $this->stockMovements = new ArrayCollection();
  1778.     }
  1779.     /**
  1780.      * @return StockMovement|null
  1781.      */
  1782.     public function getLastStockMovement()
  1783.     {
  1784.         return $this->getStockMovements()->count() > 0 ? $this->getStockMovements()->first() : null;
  1785.     }
  1786.     /**
  1787.      * Get order weight in kg
  1788.      *
  1789.      * @return int
  1790.      */
  1791.     public function getFullWeight()
  1792.     {
  1793.         $itemsWeight = 0;
  1794.         /**
  1795.          * @var OrderItem $orderItem
  1796.          */
  1797.         foreach ($this->orderItems as $orderItem) {
  1798.             $itemsWeight = $itemsWeight + (($orderItem->getProduct()->getWeight() * $orderItem->getQuantity()) / 1000);
  1799.         }
  1800.         return $itemsWeight;
  1801.     }
  1802.     /**
  1803.      * @return mixed
  1804.      */
  1805.     public function getPaymentPrice()
  1806.     {
  1807.         return $this->paymentPrice;
  1808.     }
  1809.     /**
  1810.      * @param mixed $paymentPrice
  1811.      */
  1812.     public function setPaymentPrice($paymentPrice)
  1813.     {
  1814.         $this->paymentPrice = $paymentPrice;
  1815.     }
  1816.     /**
  1817.      * @return int
  1818.      */
  1819.     public function getShippingPrice()
  1820.     {
  1821.         return $this->shippingPrice;
  1822.     }
  1823.     /**
  1824.      * @param int $shippingPrice
  1825.      */
  1826.     public function setShippingPrice($shippingPrice)
  1827.     {
  1828.         $this->shippingPrice = $shippingPrice;
  1829.     }
  1830.     public function getSubTotal()
  1831.     {
  1832.         $fullPrice = 0;
  1833.         /** @var OrderItem $orderItem */
  1834.         foreach ($this->getOrderItems() as $orderItem) {
  1835.             if ($orderItem->getParent() == null) { // Skip container children
  1836.                 $fullPrice += $orderItem->getItemFullPrice();
  1837.             }
  1838.         }
  1839.         return $fullPrice;
  1840.     }
  1841.     /**
  1842.      * Returns the quantity of products in the whole order
  1843.      *
  1844.      * TODO tz update
  1845.      * @return int
  1846.      */
  1847.     public function getAllItemQuantity()
  1848.     {
  1849.         $fullQuantity = 0;
  1850.         foreach ($this->orderItems as $orderItem) {
  1851.             $fullQuantity += $orderItem->getQuantity();
  1852.         }
  1853.         return $fullQuantity;
  1854.     }
  1855.     /**
  1856.      * Set fullPrice from subtotal, payment price and shipping price
  1857.      * Triggered on every persist and update of any Order entity
  1858.      *
  1859.      * @internal param float $fullPrice
  1860.      */
  1861.     public function setFullPrice()
  1862.     {
  1863.         $fullPrice = $this->getSubTotal();
  1864.         $fullPrice = $fullPrice + $this->getPaymentPrice() + $this->getShippingPrice();
  1865.         $this->fullPrice = round($fullPrice, 2);
  1866.     }
  1867.     /**
  1868.      * Return the full price of order with shipping and payment price in domains currency
  1869.      *
  1870.      * @return float
  1871.      */
  1872.     public function getFullPrice()
  1873.     {
  1874.         if (in_array($this->domain->getId(), [Domain::DOMAIN_ID_RT_HU, Domain::DOMAIN_ID_WS_HU])
  1875.             && $this->getVat() == 0
  1876.             && $this->fullPrice % 10 != 0) {
  1877.             return ceil($this->fullPrice / 10) * 10;
  1878.         }
  1879.         return $this->fullPrice;
  1880.     }
  1881.     /**
  1882.      * @return float
  1883.      */
  1884.     public function getVat(): float
  1885.     {
  1886.         if($this->vat !== null) {
  1887.             return (float) $this->vat;
  1888.         }
  1889.         $dateStr = $this->getCreated()->format('YmdHi');
  1890.         $vatId = 'not set';
  1891.         if (!is_null($this->customer) && $this->customer->getId() == Customer::MAXMEDIA_KFT_ID) {
  1892.             return 27;
  1893.         }
  1894.         //NOTE UNASOS ORDEREKNAL ROSSZUL VOLT ERTELMEZVE, NEM TUDTUK HOGY HA A X DOMAINEN RENDEL Y ORSZAGBA AKKOR NEM X DOMAIN VATJAT SZOLJA HANEM Y ORSZAGET
  1895.         if ($this->getUnasOrderDomainSetting() && $dateStr < (new \DateTime('2026-03-17 16:30'))->format('YmdHi')) {
  1896.             return Unas::getVatPercentageByLanguage($this->getUnasOrderDomainSetting()->getValue()) * 100;
  1897.         }
  1898.         if ($this->isRefurbedCH()) {
  1899.             return 8.1;
  1900.         }
  1901.         if ($this->getCreated()->format('Ymd') < VAT::OSS_VAT_SWITCH_DATE) {
  1902.             if ($this->getBillingVatId() != null) {
  1903.                 $vatId = $this->getBillingVatId();
  1904.             } elseif ($this->customer->getVatId() != null) {
  1905.                 $vatId = $this->customer->getVatId();
  1906.             }
  1907.             if (!is_null($this->getDomain())) {
  1908.                 return $this->customer->useZeroVat($vatId, $dateStr) ? 0 : $this->getDomain()->getVat($dateStr);
  1909.             } else {
  1910.                 return $this->customer->useZeroVat($vatId, $dateStr) ? 0 : $this->getCustomer()->getDomain()->getVat(
  1911.                     $dateStr
  1912.                 );
  1913.             }
  1914.         } else {
  1915.             $euPersonalTaxId = null;
  1916.             if (!is_null($this->getEuPersonalTaxIdSetting())) {
  1917.                 $euPersonalTaxId = $this->getEuPersonalTaxIdSetting()->getValue();
  1918.             }
  1919.             if (is_null($euPersonalTaxId)) {
  1920.                 if (!is_null($this->getBillingTaxId())) {
  1921.                     $euPersonalTaxId = $this->getBillingTaxId();
  1922.                 }
  1923.             }
  1924.             return VAT::getVatByCustomerData(
  1925.                 $this->getCustomer()->useZeroVat($this->getBillingVatId(), $dateStr),
  1926.                 $this->getBillingCountry(),
  1927.                 $this->getBillingBusinessId(),
  1928.                 $this->getShippingCountry(),
  1929.                 $this->getCreated(),
  1930.                 $euPersonalTaxId
  1931.             );
  1932.         }
  1933.     }
  1934.     /**
  1935.      * Returns the amount of money tax, from the full price of order
  1936.      *
  1937.      * @return float
  1938.      */
  1939.     public function getTaxOutOfFullPrice()
  1940.     {
  1941.         $fullPrice = $this->getFullPrice();
  1942.         $taxPercentage = $this->getVat();
  1943.         return ($fullPrice / (100 + $taxPercentage)) * $taxPercentage;
  1944.     }
  1945.     /**
  1946.      * Returns title of current payment type
  1947.      *
  1948.      * @return mixed
  1949.      */
  1950.     public function getPaymentTitle()
  1951.     {
  1952.         return PaymentType::from($this->paymentType)->getDisplayName();
  1953.     }
  1954.     /**
  1955.      * Returns title of current payment status type
  1956.      *
  1957.      * @return mixed
  1958.      */
  1959.     public function getPaymentStatusTitle()
  1960.     {
  1961.         $choices = $this->getPaymentStatusChoices();
  1962.         return $choices[$this->paymentStatus];
  1963.     }
  1964.     /**
  1965.      * Returns title of current shipping type
  1966.      *
  1967.      * @return mixed
  1968.      */
  1969.     public function getShippingTitle()
  1970.     {
  1971.         $choices = DomainShippingType::getShippingTypeChoices();
  1972.         return $choices[$this->shippingType] ?? '';
  1973.     }
  1974.     /**
  1975.      * @param $parcel
  1976.      * @return void
  1977.      */
  1978.     public function setShippingTypeByCarrier($parcel): void
  1979.     {
  1980.         switch ($parcel) {
  1981.             case OrderPackage::CARRIER_FEDEX_AIR:
  1982.             case OrderPackage::CARRIER_DHL_AIR:
  1983.                 $this->shippingType = DomainShippingType::SHIPPING_TYPE_CARRIER_EXPRESS_ID;
  1984.                 break;
  1985.             case OrderPackage::CARRIER_GLS:
  1986.             case OrderPackage::CARRIER_PBH:
  1987.             case OrderPackage::CARRIER_DHL_AT:
  1988.             case OrderPackage::CARRIER_FEDEX_ROAD:
  1989.             case OrderPackage::CARRIER_DHL_ROAD:
  1990.                 $this->shippingType = DomainShippingType::ShippingType_Carrier_Id;
  1991.                 break;
  1992.             case OrderPackage::CARRIER_PACKETA:
  1993.                 $this->shippingType = DomainShippingType::SHIPPING_TYPE_PACKETA_PICKUP_POINT_ID;
  1994.                 break;
  1995.         }
  1996.     }
  1997.     /**
  1998.      * Returns title of current status
  1999.      *
  2000.      * @param TranslatorInterface|null $translator
  2001.      * @return mixed
  2002.      */
  2003.     public function getStatusTitle(?TranslatorInterface $translator = null)
  2004.     {
  2005.         return Order::statusToTitle($this->status, $translator);
  2006.     }
  2007.     public static function statusToTitle($status, ?TranslatorInterface $translator = null)
  2008.     {
  2009.         $choices = Order::getStatusChoicesOldAndNew();
  2010.         if ($translator != null) {
  2011.             return $translator->trans($choices[$status]);
  2012.         }
  2013.         return $choices[$status];
  2014.     }
  2015.     /**
  2016.      * @return boolean
  2017.      */
  2018.     public function isMessageDone()
  2019.     {
  2020.         return $this->messageDone;
  2021.     }
  2022.     /**
  2023.      * @param boolean $messageDone
  2024.      */
  2025.     public function setMessageDone($messageDone)
  2026.     {
  2027.         $this->messageDone = $messageDone;
  2028.     }
  2029.     /**
  2030.      * @return int
  2031.      */
  2032.     public function getCreatedByType()
  2033.     {
  2034.         return $this->createdByType;
  2035.     }
  2036.     /**
  2037.      * @param int $createdByType
  2038.      */
  2039.     public function setCreatedByType($createdByType)
  2040.     {
  2041.         $this->createdByType = $createdByType;
  2042.     }
  2043.     /**
  2044.      * @return boolean
  2045.      */
  2046.     public function isArchived()
  2047.     {
  2048.         return $this->archived;
  2049.     }
  2050.     /**
  2051.      * @param boolean $archived
  2052.      */
  2053.     public function setArchived($archived)
  2054.     {
  2055.         $this->archived = $archived;
  2056.     }
  2057.     /**
  2058.      * @return \DateTime
  2059.      */
  2060.     public function getShipDate()
  2061.     {
  2062.         return $this->shipDate;
  2063.     }
  2064.     /**
  2065.      * @param \DateTime $shipDate
  2066.      */
  2067.     public function setShipDate($shipDate)
  2068.     {
  2069.         if (is_null($this->shipDate)) {
  2070.             $this->shipDate = $shipDate;
  2071.         }
  2072.     }
  2073.     /**
  2074.      * Returns all stock items of this order
  2075.      * @return ArrayCollection
  2076.      */
  2077.     public function getStockItems()
  2078.     {
  2079.         $stockItems = new ArrayCollection();
  2080.         if (!is_null($this->getLastStockMovement())) {
  2081.             $stockItems = $this->getLastStockMovement()->getStockItems();
  2082.         }
  2083.         return $stockItems;
  2084.     }
  2085.     /**
  2086.      * 1 = less, 2 = OK, 3 = more
  2087.      *
  2088.      * @return int|null
  2089.      */
  2090.     public function isAllStockItemsAdded()
  2091.     {
  2092.         return !is_null($this->getLastStockMovement()) ? $this->getLastStockMovement()->isAllStockItemsAdded() : 1;
  2093.     }
  2094.     public function isShippableToday()
  2095.     {
  2096.         return (new \DateTime()) > $this->plannedShipDate;
  2097.     }
  2098.     public function isUsingPlannedShipDate()
  2099.     {
  2100.         return $this->shippingType == DomainShippingType::getShippingTypeId(DomainShippingType::ShippingType_Carrier)
  2101.             || $this->shippingType == DomainShippingType::getShippingTypeId(DomainShippingType::ShippingType_EU_BY_US)
  2102.             || $this->shippingType == DomainShippingType::getShippingTypeId(
  2103.                 DomainShippingType::ShippingType_EU_BY_CUSTOMER
  2104.             );
  2105.     }
  2106.     /**
  2107.      * @return int
  2108.      */
  2109.     public function getDiscount()
  2110.     {
  2111.         return $this->discount;
  2112.     }
  2113.     /**
  2114.      * @param $discount
  2115.      */
  2116.     public function setDiscount($discount)
  2117.     {
  2118.         $this->discount = $discount;
  2119.     }
  2120.     /**
  2121.      * @return ArrayCollection
  2122.      */
  2123.     public function getBillingoDocuments()
  2124.     {
  2125.         return $this->billingoDocuments;
  2126.     }
  2127.     /**
  2128.      * @return string
  2129.      */
  2130.     public function getPrestaOrderCode()
  2131.     {
  2132.         return $this->prestaOrderCode;
  2133.     }
  2134.     /**
  2135.      * @param string $prestaOrderCode
  2136.      */
  2137.     public function setPrestaOrderCode($prestaOrderCode)
  2138.     {
  2139.         $this->prestaOrderCode = $prestaOrderCode;
  2140.     }
  2141.     /**
  2142.      * @return \Doctrine\Common\Collections\ArrayCollection
  2143.      */
  2144.     public function getComments()
  2145.     {
  2146.         return $this->comments;
  2147.     }
  2148.     /**
  2149.      * @param \Doctrine\Common\Collections\ArrayCollection $comments
  2150.      */
  2151.     public function setComments($comments)
  2152.     {
  2153.         $this->comments = $comments;
  2154.     }
  2155. //    public function getOrderChangelog(): array
  2156. //    {
  2157. //        $em = $this->registry->getManager('statistics');
  2158. //        return $em->getRepository(OrderChangelog::class)
  2159. //            ->findBy(
  2160. //                [
  2161. //                    'orderId' => $this->getId()
  2162. //                ]
  2163. //            );
  2164. //    }
  2165. //    /**
  2166. //     * @param int $orderStatus
  2167. //     * @param bool $showFirst
  2168. //     * @return mixed
  2169. //     */
  2170. //    public function getOrderChangelogByStatus(int $orderStatus, bool $showFirst = false): mixed
  2171. //    {
  2172. //        $em = $this->registry->getManager('statistics');
  2173. //        $changeLogs =  $em->getRepository(OrderChangelog::class)
  2174. //            ->findBy(
  2175. //                [
  2176. //                    'orderId' => $this->getId(),
  2177. //                    'status' => $this->getStatus()
  2178. //                ], [
  2179. //                    'created' => $showFirst ? 'ASC' : 'DESC'
  2180. //                ]
  2181. //            );
  2182. //
  2183. //        return $changeLogs[0];
  2184. //    }
  2185.     /**
  2186.      * @param \Doctrine\Common\Collections\ArrayCollection $orderChangelog
  2187.      */
  2188.     public function setOrderChangelog($orderChangelog)
  2189.     {
  2190.         $this->orderChangelog = $orderChangelog;
  2191.     }
  2192.     /**
  2193.      * @return \DateTime
  2194.      */
  2195.     public function getPlannedShipDate()
  2196.     {
  2197.         return $this->plannedShipDate;
  2198.     }
  2199.     /**
  2200.      * @param \DateTime|null $plannedShipDate
  2201.      */
  2202.     public function setPlannedShipDate(?\DateTime $plannedShipDate)
  2203.     {
  2204.         $this->plannedShipDate = $plannedShipDate;
  2205.     }
  2206.     /**
  2207.      * @return \DateTime
  2208.      */
  2209.     public function getDeliveryDate()
  2210.     {
  2211.         return $this->deliveryDate;
  2212.     }
  2213.     /**
  2214.      * @param \DateTime $deliveryDate
  2215.      */
  2216.     public function setDeliveryDate($deliveryDate)
  2217.     {
  2218.         $this->deliveryDate = $deliveryDate;
  2219.     }
  2220.     /**
  2221.      * @return string
  2222.      */
  2223.     public function getTrackingUrl()
  2224.     {
  2225.         return $this->trackingUrl;
  2226.     }
  2227.     /**
  2228.      * @param string $trackingUrl
  2229.      */
  2230.     public function setTrackingUrl($trackingUrl)
  2231.     {
  2232.         $this->trackingUrl = $trackingUrl;
  2233.     }
  2234.     /**
  2235.      * @return string
  2236.      */
  2237.     public function getParcelNumber()
  2238.     {
  2239.         return $this->parcelNumber;
  2240.     }
  2241.     /**
  2242.      * @param string $parcelNumber
  2243.      */
  2244.     public function setParcelNumber($parcelNumber)
  2245.     {
  2246.         $this->parcelNumber = $parcelNumber;
  2247.     }
  2248.     /**
  2249.      * @return string
  2250.      */
  2251.     public function getParcelStatus()
  2252.     {
  2253.         return $this->parcelStatus;
  2254.     }
  2255.     /**
  2256.      * @param string $parcelStatus
  2257.      */
  2258.     public function setParcelStatus($parcelStatus)
  2259.     {
  2260.         $this->parcelStatus = $parcelStatus;
  2261.     }
  2262.     /**
  2263.      * @return boolean
  2264.      */
  2265.     public function isForceFreeShipping()
  2266.     {
  2267.         return $this->forceFreeShipping;
  2268.     }
  2269.     /**
  2270.      * @param boolean $forceFreeShipping
  2271.      */
  2272.     public function setForceFreeShipping($forceFreeShipping)
  2273.     {
  2274.         $this->forceFreeShipping = $forceFreeShipping;
  2275.     }
  2276.     /**
  2277.      * @return int
  2278.      */
  2279.     public function getWarranty()
  2280.     {
  2281.         return $this->warranty;
  2282.     }
  2283.     /**
  2284.      * @param int $warranty
  2285.      */
  2286.     public function setWarranty($warranty)
  2287.     {
  2288.         return $this->warranty = $warranty;
  2289.     }
  2290.     /**
  2291.      * Get end of warranty
  2292.      *
  2293.      * @param \DateTime|null $warrantyStart
  2294.      * @return \DateTime
  2295.      */
  2296.     public function getWarrantyEnd(?\DateTime $warrantyStart = null): \DateTime
  2297.     {
  2298.         if (is_null($warrantyStart)) {
  2299.             $warrantyStart = $this->getCreated();
  2300.         }
  2301.         if (is_null($this->warranty)) {
  2302.             return (clone $warrantyStart)->add(new \DateInterval('P2Y'));
  2303.         }
  2304.         switch ($this->warranty) {
  2305.             case self::WARRANTY_NO:
  2306.                 return (clone $warrantyStart);
  2307.             case self::WARRANTY_30_DAYS:
  2308.                 return (clone $warrantyStart)->add(new \DateInterval('P30D'));
  2309.             case self::WARRANTY_1_YEAR:
  2310.                 return (clone $warrantyStart)->add(new \DateInterval('P1Y'));
  2311.             case self::WARRANTY_2_YEAR:
  2312.                 return (clone $warrantyStart)->add(new \DateInterval('P2Y'));
  2313.             case self::WARRANTY_3_YEAR:
  2314.                 return (clone $warrantyStart)->add(new \DateInterval('P3Y'));
  2315.             case self::WARRANTY_4_YEAR:
  2316.                 return (clone $warrantyStart)->add(new \DateInterval('P4Y'));
  2317.             case self::WARRANTY_5_YEAR:
  2318.                 return (clone $warrantyStart)->add(new \DateInterval('P5Y'));
  2319.         }
  2320.     }
  2321.     /**
  2322.      * @return OrderSetting|null
  2323.      */
  2324.     public function getKlarnaOrderIdSetting(): ?OrderSetting
  2325.     {
  2326.         return $this->getSetting(OrderSetting::TYPE_KLARNA_ORDER_ID);
  2327.     }
  2328.     /**
  2329.      * @return OrderSetting|null
  2330.      */
  2331.     public function getCnCountSetting(): ?OrderSetting
  2332.     {
  2333.         return $this->getSetting(OrderSetting::TYPE_CN_COUNT);
  2334.     }
  2335.     /**
  2336.      * @return string|null
  2337.      */
  2338.     public function getFedexTrackingNumber(): ?string
  2339.     {
  2340.         return $this->getMultipleSettings(OrderSetting::TYPE_FEDEX_TRACKING_NUMBER);
  2341.     }
  2342.     /**
  2343.      * @return string|null
  2344.      */
  2345.     public function getClaimFedexShipmentNumber(): ?string
  2346.     {
  2347.         return $this->getSetting(OrderSetting::TYPE_CLAIM_FEDEX_TRACKING_NUMBER)?->getValue();
  2348.     }
  2349.     /**
  2350.      * @return string|null
  2351.      */
  2352.     public function getClaimImportFedexShipmentNumber(): ?string
  2353.     {
  2354.         return $this->getSetting(OrderSetting::TYPE_CLAIM_IMPORT_FEDEX_TRACKING_NUMBER)?->getValue();
  2355.     }
  2356.     public function isFedexAddressVerified(): ?OrderSetting
  2357.     {
  2358.         return $this->getSetting(OrderSetting::TYPE_FEDEX_ADDRESS_VERIFIED);
  2359.     }
  2360.     /**
  2361.      * @return ArrayCollection
  2362.      */
  2363.     public function getSettings()
  2364.     {
  2365.         return $this->settings;
  2366.     }
  2367.     public function getCetelemCodeSetting()
  2368.     {
  2369.         return $this->getSetting(OrderSetting::TYPE_CETELEM_CODE);
  2370.     }
  2371.     public function getDepositSetting()
  2372.     {
  2373.         return $this->getSetting(OrderSetting::TYPE_DEPOSIT);
  2374.     }
  2375.     public function getLabelPrintedSetting()
  2376.     {
  2377.         return $this->getSetting(OrderSetting::TYPE_LABEL_PRINTED);
  2378.     }
  2379.     public function getPickupPointSetting()
  2380.     {
  2381.         return $this->getSetting(OrderSetting::TYPE_PICKUP_POINT_ID);
  2382.     }
  2383.     public function getParentOrderIdSetting()
  2384.     {
  2385.         return $this->getSetting(OrderSetting::TYPE_PARENT_ORDER_ID);
  2386.     }
  2387.     public function getChildOrderIdSetting()
  2388.     {
  2389.         return $this->getSetting(OrderSetting::TYPE_CHILD_ORDER_ID);
  2390.     }
  2391.     public function getPickupPointPartnerNotifiedSetting()
  2392.     {
  2393.         return $this->getSetting(OrderSetting::TYPE_PICKUP_POINT_PARTNER_NOTIFIED);
  2394.     }
  2395.     public function getSimplePayTransactionIdSetting()
  2396.     {
  2397.         return $this->getSetting(OrderSetting::TYPE_SIMPLEPAY_PAYMENT_ID);
  2398.     }
  2399.     public function getSimplePayOrderRefSetting()
  2400.     {
  2401.         return $this->getSetting(OrderSetting::TYPE_SIMPLEPAY_PAYMENT_ORDER_REF);
  2402.     }
  2403.     public function getGoPayTransactionIdSetting()
  2404.     {
  2405.         return $this->getSetting(OrderSetting::TYPE_GOPAY_PAYMENT_ID);
  2406.     }
  2407.     public function getCouponCodeSetting()
  2408.     {
  2409.         return $this->getSetting(OrderSetting::TYPE_COUPON_CODE);
  2410.     }
  2411.     public function getUpsellStatSetting()
  2412.     {
  2413.         return $this->getSetting(OrderSetting::TYPE_UPSELL_STATS);
  2414.     }
  2415.     public function getShippingNotificationSetting()
  2416.     {
  2417.         return $this->getSetting(OrderSetting::TYPE_SHIPPING_NOTIFICATION);
  2418.     }
  2419.     public function getPaidPriceByCardSetting()
  2420.     {
  2421.         return $this->getSetting(OrderSetting::TYPE_PAID_PRICE_BY_CARD);
  2422.     }
  2423.     public function getChosenCarrierSetting()
  2424.     {
  2425.         return $this->getSetting(OrderSetting::TYPE_CHOSEN_CARRIER_ID);
  2426.     }
  2427.     public function getDoneSetting()
  2428.     {
  2429.         return $this->getSetting(OrderSetting::TYPE_DONE);
  2430.     }
  2431.     public function getOrderConfirmedSetting()
  2432.     {
  2433.         return $this->getSetting(OrderSetting::TYPE_ORDER_CONFIRMED);
  2434.     }
  2435.     public function getBillingoInvoiceNoteSetting()
  2436.     {
  2437.         return $this->getSetting(OrderSetting::TYPE_BILLINGO_NOTE);
  2438.     }
  2439.     public function getPacketaBranchIdSetting()
  2440.     {
  2441.         return $this->getSetting(OrderSetting::TYPE_PACKETA_BRANCH_ID);
  2442.     }
  2443.     public function getPacketaBranchNameSetting()
  2444.     {
  2445.         return $this->getSetting(OrderSetting::TYPE_PACKETA_BRANCH_NAME);
  2446.     }
  2447.     public function getPacketaCarrierIdSetting()
  2448.     {
  2449.         return $this->getSetting(OrderSetting::TYPE_PACKETA_CARRIER_ID);
  2450.     }
  2451.     /**
  2452.      * @return OrderSetting|null
  2453.      */
  2454.     public function getEuPersonalTaxIdSetting(): ?OrderSetting
  2455.     {
  2456.         $orderSetting = $this->getSetting(OrderSetting::TYPE_EU_PERSONAL_TAX_ID);
  2457.         if ($orderSetting) {
  2458.             if (trim($orderSetting->getValue()) == 'NIF') {
  2459.                 return null;
  2460.             }
  2461.         }
  2462.         return $orderSetting;
  2463.     }
  2464.     /**
  2465.      * @return OrderSetting|null
  2466.      */
  2467.     public function getClonedOrderSetting(): ?OrderSetting
  2468.     {
  2469.         return $this->getSetting(OrderSetting::TYPE_CLONED_ORDER);
  2470.     }
  2471.     /**
  2472.      * @return OrderSetting|null
  2473.      */
  2474.     public function getFinishedByMarketplaceAPISetting(): ?OrderSetting
  2475.     {
  2476.         return $this->getSetting(OrderSetting::TYPE_FINISHED_BY_MARKETPLACE_API);
  2477.     }
  2478.     /**
  2479.      * @return OrderSetting|null
  2480.      */
  2481.     public function getInstacashApplicationIdSetting(): ?OrderSetting
  2482.     {
  2483.         return $this->getSetting(OrderSetting::TYPE_INSTACASH_APPLICATION_ID);
  2484.     }
  2485.     /**
  2486.      * @return OrderSetting|null
  2487.      */
  2488.     public function getInstacashApplicationStatusSetting(): ?OrderSetting
  2489.     {
  2490.         return $this->getSetting(OrderSetting::TYPE_INSTACASH_APPLICATION_STATUS);
  2491.     }
  2492.     /**
  2493.      * @return array
  2494.      */
  2495.     public function getInstacashPaymentSettings(): array
  2496.     {
  2497.         return $this->getOrderSettings(OrderSetting::TYPE_INSTACASH_PAYMENT);
  2498.     }
  2499.     /**
  2500.      * @return OrderSetting|null
  2501.      */
  2502.     public function getMilpayApplicationIdSetting(): ?OrderSetting
  2503.     {
  2504.         return $this->getSetting(OrderSetting::TYPE_MILPAY_APPLICATION_ID);
  2505.     }
  2506.     /**
  2507.      * @return OrderSetting|null
  2508.      */
  2509.     public function getMilpayApplicationStatusSetting(): ?OrderSetting
  2510.     {
  2511.         return $this->getSetting(OrderSetting::TYPE_MILPAY_APPLICATION_STATUS);
  2512.     }
  2513.     /**
  2514.      * @return array
  2515.      */
  2516.     public function getMilpayPaymentSettings(): array
  2517.     {
  2518.         return $this->getOrderSettings(OrderSetting::TYPE_MILPAY_PAYMENT);;
  2519.     }
  2520.     /**
  2521.      * @return array
  2522.      */
  2523.     public function getPastPayPaymentSettings(): array
  2524.     {
  2525.         return $this->getOrderSettings(OrderSetting::TYPE_PAST_PAY_RESERVE);
  2526.     }
  2527.     /**
  2528.      * @return array
  2529.      */
  2530.     public function getPastPayFinalizedSettings(): array
  2531.     {
  2532.         return $this->getOrderSettings(OrderSetting::TYPE_PAST_PAY_FINALIZED);
  2533.     }
  2534.     /**
  2535.      * @return array
  2536.      */
  2537.     public function getPastPayCanceledSettings(): array
  2538.     {
  2539.         return $this->getOrderSettings(OrderSetting::TYPE_PAST_PAY_RESERVATION_CANCELED);
  2540.     }
  2541.     /**
  2542.      * @return OrderSetting|null
  2543.      */
  2544.     public function getDisableInvoiceCreationSetting(): ?OrderSetting
  2545.     {
  2546.         return $this->getSetting(OrderSetting::TYPE_DISABLE_INVOICE_CREATION);
  2547.     }
  2548.     /**
  2549.      * @return OrderSetting|null
  2550.      */
  2551.     public function getPBHTrackingNumberSetting(): ?OrderSetting
  2552.     {
  2553.         return $this->getSetting(OrderSetting::TYPE_TRACKING_NUMBER_FROM_PBH);
  2554.     }
  2555.     /**
  2556.      * @return OrderSetting|null
  2557.      */
  2558.     public function getIsCanceledAtMarketplaceSetting(): ?OrderSetting
  2559.     {
  2560.         return $this->getSetting(OrderSetting::TYPE_CANCELED_ORDER);
  2561.     }
  2562.     /**
  2563.      * @return OrderSetting|null
  2564.      */
  2565.     public function getPriceByMarketplaceApiSetting(): ?OrderSetting
  2566.     {
  2567.         return $this->getSetting(OrderSetting::TYPE_PRICE_BY_MARKETPLACE_API);
  2568.     }
  2569.     /**
  2570.      * @return OrderSetting|null
  2571.      */
  2572.     public function getSaveAnywayInfoSettings(): ?array
  2573.     {
  2574.         return $this->getOrderSettings(OrderSetting::TYPE_FORCE_SAVING_USER);
  2575.     }
  2576.     /**
  2577.      * @return OrderSetting|null
  2578.      */
  2579.     public function getPaypalTransactionIdSetting(): ?OrderSetting
  2580.     {
  2581.         return $this->getSetting(OrderSetting::TYPE_PAYPAL_TRANSACTION_ID);
  2582.     }
  2583.     /**
  2584.      * @return OrderSetting|null
  2585.      */
  2586.     public function getKlarnaPaymentSessionIdSetting(bool $getOriginal = true): ?OrderSetting
  2587.     {
  2588.         $settings = [];
  2589.         foreach ($this->settings as $setting) {
  2590.             if ($setting->getType() == OrderSetting::TYPE_KLARNA_PAYMENT_SESSION_ID) {
  2591.                 $settings[] = $setting;
  2592.             }
  2593.         }
  2594.         usort($settings, function ($a, $b) {
  2595.             return $a->getCreated() > $b->getCreated();
  2596.         });
  2597.         return $settings[$getOriginal ? 0 : count($settings) - 1] ?? null;
  2598.     }
  2599.     public function getAllKlarnaPaymentSessionIdSettings(): array
  2600.     {
  2601.         $settings = [];
  2602.         foreach ($this->settings as $setting) {
  2603.             if ($setting->getType() == OrderSetting::TYPE_KLARNA_PAYMENT_SESSION_ID) {
  2604.                 $settings[] = $setting;
  2605.             }
  2606.         }
  2607.         return $settings;
  2608.     }
  2609.     /**
  2610.      * @return OrderSetting|null
  2611.      *
  2612.      */
  2613.     public function getRequiredQualityCheckSetting(): ?OrderSetting
  2614.     {
  2615.         return $this->getSetting(OrderSetting::TYPE_REQUIRED_QUALITY_CHECK);
  2616.     }
  2617.     public function getSalesRiskSetting(): ?OrderSetting
  2618.     {
  2619.         return $this->getSetting(OrderSetting::TYPE_SALES_RISK);
  2620.     }
  2621.     public function getQualityMayVarySetting(): ?OrderSetting
  2622.     {
  2623.         return $this->getSetting(OrderSetting::TYPE_QUALITY_MAY_VARY);
  2624.     }
  2625.     public function getUnasOrderDomainSetting(): ?OrderSetting
  2626.     {
  2627.         return $this->getSetting(OrderSetting::TYPE_UNAS_ORDER_DOMAIN);
  2628.     }
  2629.     public function getUnasCustomerIsRegisteredSetting(): ?OrderSetting
  2630.     {
  2631.         return $this->getSetting(OrderSetting::TYPE_UNAS_USER_IS_REGISTERED);
  2632.     }
  2633.     public function getStripeIdSetting(): ?OrderSetting
  2634.     {
  2635.         return $this->getSetting(OrderSetting::TYPE_STRIPE_ID);
  2636.     }
  2637.     public function getAlternativeV2ProductSetting(): ?OrderSetting
  2638.     {
  2639.         return $this->getSetting(OrderSetting::TYPE_ALTERNATIVE_V2_PRODUCT);
  2640.     }
  2641.     public function getLaseredProductsSetting(): ?OrderSetting
  2642.     {
  2643.         return $this->getSetting(OrderSetting::TYPE_LASERED_PRODUCTS);
  2644.     }
  2645.     private function getSetting($settingCode)
  2646.     {
  2647.         foreach ($this->settings as $setting) {
  2648.             if ($setting->getType() == $settingCode) {
  2649.                 return $setting;
  2650.             }
  2651.         }
  2652.         return null;
  2653.     }
  2654.     private function getMultipleSettings($settingCode)
  2655.     {
  2656.         $result = [];
  2657.         foreach ($this->settings as $setting) {
  2658.             if ($setting->getType() == $settingCode) {
  2659.                 $result[] = $setting->getValue();
  2660.             }
  2661.         }
  2662.         if (count($result)) {
  2663.             return join(', ', $result);
  2664.         }
  2665.         return null;
  2666.     }
  2667.     /**
  2668.      * @param int $settingCode
  2669.      * @return array
  2670.      */
  2671.     private function getOrderSettings(int $settingCode): array
  2672.     {
  2673.         $settings = [];
  2674.         foreach ($this->settings as $setting) {
  2675.             if ($setting->getType() == $settingCode) {
  2676.                 $settings[] = $setting;
  2677.             }
  2678.         }
  2679.         return $settings;
  2680.     }
  2681.     public function isClonedOrder()
  2682.     {
  2683.         return !is_null($this->getSetting(OrderSetting::TYPE_CLONED_ORDER));
  2684.     }
  2685.     /**
  2686.      * @return User
  2687.      */
  2688.     public function getMessageDoneBy()
  2689.     {
  2690.         return $this->messageDoneBy;
  2691.     }
  2692.     /**
  2693.      * @param User $messageDoneBy
  2694.      */
  2695.     public function setMessageDoneBy($messageDoneBy)
  2696.     {
  2697.         $this->messageDoneBy = $messageDoneBy;
  2698.     }
  2699.     /**
  2700.      * @return \DateTime
  2701.      */
  2702.     public function getMessageDoneTime()
  2703.     {
  2704.         return $this->messageDoneTime;
  2705.     }
  2706.     /**
  2707.      * @param \DateTime $messageDoneTime
  2708.      */
  2709.     public function setMessageDoneTime($messageDoneTime)
  2710.     {
  2711.         $this->messageDoneTime = $messageDoneTime;
  2712.     }
  2713.     /**
  2714.      * @return bool
  2715.      */
  2716.     public function hasTimedSale()
  2717.     {
  2718.         $hasTimedSale = false;
  2719.         foreach ($this->getOrderItems() as $item) {
  2720.             if ($hasTimedSale) {
  2721.                 continue;
  2722.             }
  2723.             $hasTimedSale = $item->isFromTimedSale();
  2724.         }
  2725.         return $hasTimedSale;
  2726.     }
  2727.     /**
  2728.      * @return int
  2729.      */
  2730.     public function getExternalOrderSource(): ?int
  2731.     {
  2732.         return $this->externalOrderSource;
  2733.     }
  2734.     /**
  2735.      * @param int $externalOrderSource
  2736.      */
  2737.     public function setExternalOrderSource($externalOrderSource): Order
  2738.     {
  2739.         $this->externalOrderSource = $externalOrderSource;
  2740.         return $this;
  2741.     }
  2742.     /**
  2743.      * @return string
  2744.      */
  2745.     public function getExternalOrderCode()
  2746.     {
  2747.         return $this->externalOrderCode;
  2748.     }
  2749.     /**
  2750.      * @param string $externalOrderCode
  2751.      */
  2752.     public function setExternalOrderCode($externalOrderCode)
  2753.     {
  2754.         $this->externalOrderCode = $externalOrderCode;
  2755.     }
  2756.     /**
  2757.      * @return ArrayCollection
  2758.      */
  2759.     public function getPackages()
  2760.     {
  2761.         return $this->packages;
  2762.     }
  2763.     public function removeAllPackages()
  2764.     {
  2765.         $this->packages = new ArrayCollection();
  2766.     }
  2767.     /**
  2768.      * @return ArrayCollection
  2769.      */
  2770.     public function setPackages($packages)
  2771.     {
  2772.         $this->packages = $packages;
  2773.     }
  2774.     public function hasPackageLabels(): bool
  2775.     {
  2776.         $parcelIds = array_map(fn(OrderPackage $p) => $p->getParcelId(), $this->packages->toArray());
  2777.         return array_filter($parcelIds) !== [];
  2778.     }
  2779.     /**
  2780.      * @return string
  2781.      */
  2782.     public function getDhlShipmentNumber()
  2783.     {
  2784.         return $this->dhlShipmentNumber;
  2785.     }
  2786.     /**
  2787.      * @param string $dhlShipmentNumber
  2788.      */
  2789.     public function setDhlShipmentNumber($dhlShipmentNumber)
  2790.     {
  2791.         $this->dhlShipmentNumber = $dhlShipmentNumber;
  2792.     }
  2793.     /**
  2794.      * @return bool
  2795.      */
  2796.     public function hasStockItemsForWorkbench(): bool
  2797.     {
  2798.         $availableProductTypes = [44, 52, 60, 90, 116]; // Monitor, Notebook, PC, Tablet, All in one
  2799.         foreach ($this->getOrderItems() as $orderItem) {
  2800.             if (in_array($orderItem->getProduct()->getType()->getId(), $availableProductTypes)) {
  2801.                 if ($orderItem->getStockMovementItem() && $orderItem->getStockMovementItem()->getItems()->count() > 0) {
  2802.                     return true;
  2803.                 }
  2804.             }
  2805.         }
  2806.         return false;
  2807.     }
  2808.     /**
  2809.      * @return string|null
  2810.      */
  2811.     public function getShippingTime(): ?string
  2812.     {
  2813.         $settings = $this->settings;
  2814.         if (count($settings) > 0) {
  2815.             foreach ($settings as $key => $setting) {
  2816.                 if ($setting->getType() == OrderSetting::TYPE_SHIPPING_DATETIME) {
  2817.                     return $setting->getValue();
  2818.                 }
  2819.             }
  2820.         }
  2821.         return null;
  2822.     }
  2823.     /**
  2824.      * @return bool
  2825.      */
  2826.     public function isPriority(): bool
  2827.     {
  2828.         return $this->priority;
  2829.     }
  2830.     /**
  2831.      * @param bool $priority
  2832.      */
  2833.     public function setPriority(bool $priority)
  2834.     {
  2835.         $this->priority = $priority;
  2836.     }
  2837.     /**
  2838.      * @return bool
  2839.      */
  2840.     public function isConfirmed(): bool
  2841.     {
  2842.         $orderSetting = $this->getOrderConfirmedSetting();
  2843.         if (!is_null($orderSetting)) {
  2844.             return true;
  2845.         }
  2846.         return false;
  2847.     }
  2848.     /**
  2849.      * @return int
  2850.      */
  2851.     public function getChosenCarrierId(): int
  2852.     {
  2853.         if ($this->getChosenCarrierSetting()) {
  2854.             return $this->getChosenCarrierSetting()->getValue();
  2855.         }
  2856.         if (!in_array($this->getShippingType(), [
  2857.             DomainShippingType::ShippingType_Carrier_Id,
  2858.             DomainShippingType::SHIPPING_TYPE_CARRIER_EXPRESS_ID,
  2859.             DomainShippingType::SHIPPING_TYPE_PACKETA_PICKUP_POINT_ID,
  2860.             DomainShippingType::SHIPPING_TYPE_PACKETA_PICKUP_POINT_ID,
  2861.         ])) {
  2862.             return 0;
  2863.         }
  2864.         if (in_array($this->getShippingType(), [
  2865.             DomainShippingType::SHIPPING_TYPE_PACKETA_PICKUP_POINT_ID, DomainShippingType::SHIPPING_TYPE_PACKETA_PICKUP_POINT_ID
  2866.         ])) {
  2867.             return OrderPackage::CARRIER_PACKETA;
  2868.         } else {
  2869.             if ($this->getDomain()->getId() == Domain::DOMAIN_ID_B2C_EU) {
  2870.                 return OrderPackage::CARRIER_DHL_AIR;
  2871.             } else {
  2872.                 return OrderPackage::CARRIER_GLS;
  2873.             }
  2874.         }
  2875.     }
  2876.     /**
  2877.      * @return string
  2878.      */
  2879.     public function getChosenCarrierTitle(): string
  2880.     {
  2881.         $carrierId = $this->getChosenCarrierId();
  2882.         if ( $carrierId == 0 || !isset(OrderPackage::getCarrierChoices()[$carrierId]) ) {
  2883.             return '';
  2884.         }
  2885.         return OrderPackage::getCarrierChoices()[$carrierId];
  2886.     }
  2887.     /**
  2888.      * @return string
  2889.      */
  2890.     public function getChosenCarrierNormalizedName(): string
  2891.     {
  2892.         $carrierId = $this->getChosenCarrierId();
  2893.         if ($carrierId == 0) {
  2894.             return '';
  2895.         }
  2896.         return OrderPackage::getFinalizingFormatCarrierName()[$carrierId];
  2897.     }
  2898.     /**
  2899.      * @return bool
  2900.      */
  2901.     public function isB2B(): bool
  2902.     {
  2903.         return $this->getCustomer()->isB2B();
  2904.     }
  2905.     public function getOrderConfigChangeMovementOut()
  2906.     {
  2907.         foreach ($this->getConfigChangeStockMovements() as $stockMovement) {
  2908.             if ($stockMovement->getSubType() == StockMovement::SUB_TYPE_OUT_ORDER_CONFIG_CHANGE) {
  2909.                 return $stockMovement;
  2910.             }
  2911.         }
  2912.         return null;
  2913.     }
  2914.     public function getOrderConfigChangeMovementIn()
  2915.     {
  2916.         foreach ($this->getConfigChangeStockMovements() as $stockMovement) {
  2917.             if ($stockMovement->getSubType() == StockMovement::SUB_TYPE_IN_ORDER_CONFIG_CHANGE) {
  2918.                 return $stockMovement;
  2919.             }
  2920.         }
  2921.         return null;
  2922.     }
  2923.     public function getOrderNeutralMovement()
  2924.     {
  2925.         foreach ($this->getStockMovements() as $stockMovement) {
  2926.             if ($stockMovement->getType() == StockMovement::TYPE_NEUTRAL) {
  2927.                 return $stockMovement;
  2928.             }
  2929.         }
  2930.         return null;
  2931.     }
  2932.     /**
  2933.      * @return ArrayCollection
  2934.      */
  2935.     public function getConfigChangeStockMovements()
  2936.     {
  2937.         return $this->configChangeStockMovements;
  2938.     }
  2939.     public function getPriorityContext(ManagerRegistry $registry): PriorityContext
  2940.     {
  2941.         $orderChangeLogService = new OrderChangeLogService();
  2942.         $orderChangeLogService->setDoctrine($registry);
  2943.         $firstProcessableStatus = $orderChangeLogService->getOrderChangelogByStatus($this, self::STATUS_PROCESSABLE, true);
  2944.         $processableDate = $firstProcessableStatus ? $firstProcessableStatus->getCreated() : null;
  2945.         return new PriorityContext(
  2946.             $this->getDomain()->getId(),
  2947.             $this->getCreated(),
  2948.             $processableDate
  2949.         );
  2950.     }
  2951.     /**
  2952.      * @return int|null
  2953.      */
  2954.     public function getBaseOrderId(): ?int
  2955.     {
  2956.         return $this->baseOrderId;
  2957.     }
  2958.     /**
  2959.      * @param int $baseOrderId
  2960.      */
  2961.     public function setBaseOrderId($baseOrderId)
  2962.     {
  2963.         $this->baseOrderId = $baseOrderId;
  2964.     }
  2965.     public function setVat(?float $vat): void
  2966.     {
  2967.         $this->vat = $vat;
  2968.     }
  2969.     /**
  2970.      * @return string
  2971.      */
  2972.     public function getMarketplace(): string
  2973.     {
  2974.         return self::getMarketplaces()[$this->externalOrderSource] ?? '';
  2975.     }
  2976.     public function isRefurbedCH()
  2977.     {
  2978.         return !is_null($this->getExternalOrderSource()) && $this->getExternalOrderSource() == self::EXTERNAL_ORDER_SOURCE_REFURBED && $this->getBillingCountry() == 'CH';
  2979.     }
  2980. }