Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/extmag/dhlshipping2/Helper/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/extmag/dhlshipping2/Helper/DataPrepare.php
<?php
/**
 * Copyright © Extmag. All rights reserved.
 */

namespace Extmag\DhlShipping\Helper;

use Exception;
use Extmag\Shiplab\Model\Label;

class DataPrepare extends \Extmag\Shiplab\Helper\DataPrepare
{
    /**
     * @var string
     */
    protected $carrier = 'dhl';

    /**
     * Get Pickup Data
     *
     * @param Label[] $labels
     * @param int $cronHour
     * @return array
     * @throws Exception
     */
    public function getPickupData(array $labels, $cronHour = -1)
    {
        $i = 0;
        $data = [];
        foreach ($labels as $label) {
            $this->manager->setConfigScopeFilter($label->getStoreId(), null, null);
            $hour = (int)$this->manager->getConfig($this->carrier . '_pickup/schedule/time');
            $bySchedule = $this->manager->getConfig($this->carrier . '_pickup/schedule/active');
            $daysOfWeek = explode(
                ",",
                $this->manager->getConfig($this->carrier . '_pickup/schedule/days_of_week') ?? ''
            );

            if ($cronHour === -1
                || (
                    $bySchedule === 'by_schedule'
                    && $hour == $cronHour
                    && in_array($this->timezone->date()->format("w"), $daysOfWeek)
                )
            ) {
                $request = json_decode($label->getRequest(), true);
                if ($i == 0) {
                    $data = $request;
                    unset(
                        $data['packages'],
                        $data['products'],
                        $data['invoice_products'],
                        $data['service_codes'],
                        $data['notification_active'],
                        $data['notification_message']
                    );

                    if ($this->manager->getConfig($this->carrier . '_pickup/general/close_time')) {
                        $data['pickup_close_time'] = implode(
                            ":",
                            array_slice(
                                explode(
                                    ",",
                                    $this->manager->getConfig(
                                        $this->carrier . '_pickup/general/close_time'
                                    )
                                ),
                                0,
                                2
                            )
                        );
                    }

                    if ($this->manager->getConfig($this->carrier . '_pickup/general/ready_time')) {
                        $data['pickup_ready_time'] = implode(
                            ":",
                            array_slice(
                                explode(
                                    ",",
                                    $this->manager->getConfig(
                                        $this->carrier . '_pickup/general/ready_time'
                                    )
                                ),
                                0,
                                2
                            )
                        );
                    }

                    $data['pickup_date'] = $this->timezone->date($this->getTimezoneByAccount())
                        ->format('Y-m-d');
                    $data['pickup_special_instruction'] = $this->manager->getConfig(
                        $this->carrier . '_pickup/general/special_instructions'
                    );

                    $data['pickup_total_weight'] = 0;
                    $data['pickup_total_packages'] = 0;
                }

                $data['label_ids'][] = $label->getId();

                $data['pickup_total_packages'] += count($request['packages']);
                foreach ($request['packages'] as $package) {
                    $data['pickup_total_weight'] += ceil((float)$package['weight']);
                }

                $i++;
            }
        }

        return $data;
    }

    /**
     * Get Tracking Data
     *
     * @param Label $label
     * @return mixed
     */
    public function getTrackingData(Label $label)
    {
        $data = json_decode($label->getRequest(), true);
        unset(
            $data['packages'],
            $data['products'],
            $data['invoice_products'],
            $data['service_codes'],
            $data['notification_service_code']
        );
        $data['master_id'] = $label->getMasterId();

        return $data;
    }

    /**
     * @inheritDoc
     */
    public function getStepOne()
    {
        parent::getStepOne();
        $this->data['is_dutiable'] = $this->manager->getConfig($this->carrier . "_payment/general/is_dutiable");

        return $this->data;
    }

    /**
     * @inheritDoc
     */
    public function getStepTwo()
    {
        parent::getStepTwo();
        /* Printing */
        $this->data['printing_template'] = $this->manager->getConfig($this->carrier . "_printing/general/template");
        $this->data['printing_dpi'] = $this->manager->getConfig($this->carrier . "_printing/general/resolution");
        if (empty($this->data['printing_dpi'])) {
            $this->data['printing_dpi'] = 203;
        }
        $this->data['archive_doc'] = $this->manager->getConfig($this->carrier . "_printing/general/archive_doc");
        $this->data['archive_doc_number'] = $this->manager->getConfig(
            $this->carrier . "_printing/general/archive_doc_number"
        );
        /* END Printing */

        /* General group */
        $this->data['delivery_confirmation'] = $this->manager->getConfig(
            $this->carrier . "_other/general/delivery_confirmation"
        );
        $this->data['door_to'] = $this->manager->getConfig(
            $this->carrier . "_other/general/door_to"
        );

        $this->data['carbon_neutral'] = $this->manager->getConfig(
            $this->carrier . "_other/general/carbon_neutral"
        );
        $this->data['carbon_footprint'] = $this->manager->getConfig(
            $this->carrier . "_other/general/carbon_footprint"
        );
        $this->data['carbon_estimate'] = $this->manager->getConfig(
            $this->carrier . "_other/general/carbon_estimate"
        );

        $this->data['reference_id'] = $this->setMacroPastes(
            $this->manager->getConfig(
                $this->carrier . "_reference/reference_number/id"
            )
        );
        $this->prePackage['type'] = $this->manager->getConfig($this->carrier . "_packaging/general/type");

        $this->prePackage['reference_value_1'] = $this->setMacroPastes(
            $this->manager->getConfig($this->carrier . "_packaging/general/reference_value_1")
        );
        $this->prePackage['barcode_1'] = $this->manager->getConfig(
            $this->carrier . "_packaging/general/barcode_1"
        );

        /* Notification */
        $this->data['notification_active'] = $this->manager->getConfig(
            $this->carrier . "_notification/general/active"
        );
        $this->data['notification_message'] = $this->manager->getConfig(
            $this->carrier . "_notification/general/message"
        );
        /* END Notification */

        $this->calculatePackages();

        /* International Invoice */
        $this->data['invoice_active'] = (int)$this->manager->getConfig(
            $this->carrier . "_international_invoice/general/active"
        );
        $this->data['invoice_type'] = $this->manager->getConfig(
            $this->carrier . "_international_invoice/general/type"
        );
        $this->data['invoice_terms_of_shipment'] = $this->manager->getConfig(
            $this->carrier . "_international_invoice/general/terms_of_shipment"
        );
        $this->data['invoice_reason_for_export'] = $this->manager->getConfig(
            $this->carrier . "_international_invoice/general/reason_for_export"
        );
        $this->data['invoice_invoice_number'] = $this->setMacroPastes(
            $this->manager->getConfig($this->carrier . "_international_invoice/general/invoice_number")
        );
        $this->data['invoice_invoice_date'] = $this->date->date('Y-m-d');
        $this->data['invoice_comments'] = $this->setMacroPastes(
            $this->manager->getConfig($this->carrier . "_international_invoice/general/comments")
        );
        $this->data['invoice_declaration_statement'] = $this->manager->getConfig(
            $this->carrier . "_international_invoice/general/declaration_statement"
        );
        $this->data['invoice_place_of_incoterm'] = $this->manager->getConfig(
            $this->carrier . "_international_invoice/general/invoice_place_of_incoterm"
        );

        $this->data['products'] = $this->products;
        $this->data['invoice_products'] = $this->invoiceProducts;
        $this->data['packages'] = $this->packages;

        //print_r($this->data);exit;
        //print_r($this->data['packages']);exit;

        return $this->data;
    }

    /**
     * Get Code By Province Name
     *
     * @param $code
     * @param $country
     * @return int|string
     */
    protected function getCodeByProvinceName($code, $country)
    {
        $regions = $this->provinceCodes->toArray();
        if (!empty($regions[$country])) {
            foreach ($regions[$country] as $key => $region) {
                if ($region['name'] == $code || $region['default_name'] == $code) {
                    return $key;
                }
            }
        }

        if (in_array($country, ['US', 'CA', 'IE'])) {
            return $code;
        }

        return '';
    }

    /**
     * Check Configuration
     *
     * @return array|bool
     * @throws Exception
     */
    public function checkConfiguration()
    {
        if (!$this->manager->getConfig($this->carrier . "_pickup/general/ready_time")
            || !$this->manager->getConfig($this->carrier . "_pickup/general/close_time")
        ) {
            $this->errors[] = [
                'title' => __('Pickup Time is undefined'),
                'check_link' => $this->manager->getBackendUrl(
                    '*/configuration/edit/section/' . $this->carrier . '_pickup'
                ),
            ];
        }

        return parent::checkConfiguration();
    }
}

Spamworldpro Mini