public function generateMultiple($package_ids, $output_doc_format = 'PDF', $output_doc_page_format = 'LBL_PRINTER', $policy = 'STOP_ON_FIRST_ERROR')
 {
     $session_type = '';
     $package_number = null;
     foreach ($package_ids as $id_package_ws) {
         $package = new DpdPolandPackage((int) $id_package_ws);
         if (!$session_type || $session_type == $package->getSessionType()) {
             $session_type = $package->getSessionType();
             if ($package_number === null) {
                 $package_number = $package->payerNumber;
             } elseif ($package_number !== $package->payerNumber) {
                 $package_number = 'null';
             }
         } else {
             self::$errors[] = $this->l('Manifests of DOMESTIC shipments cannot be mixed with INTERNATIONAL shipments');
             return false;
         }
     }
     $params = array('dpdServicesParamsV1' => array('pickupAddress' => $package->getSenderAddress($package_number), 'policy' => $policy, 'session' => array('sessionType' => $session_type, 'packages' => array())), 'outputDocFormatV1' => $output_doc_format, 'outputDocPageFormatV1' => $output_doc_page_format);
     foreach ($package_ids as $id_package_ws) {
         $params['dpdServicesParamsV1']['session']['packages'][] = array('packageId' => (int) $id_package_ws);
     }
     $result = $this->generateProtocolV1($params);
     if (isset($result['session']) && isset($result['session']['statusInfo']) && $result['session']['statusInfo']['status'] == 'OK') {
         foreach ($package_ids as $id_package_ws) {
             $manifest = new DpdPolandManifest();
             $manifest->id_manifest_ws = (int) $result['documentId'];
             $manifest->id_package_ws = (int) $id_package_ws;
             if (!$manifest->save()) {
                 return false;
             }
         }
         return $result['documentData'];
     } else {
         if (isset($result['session']['statusInfo']['description'])) {
             self::$errors[] = $result['session']['statusInfo']['description'];
         } elseif (isset($result['session']['statusInfo']['status'])) {
             self::$errors[] = $result['session']['statusInfo']['status'];
         }
         return false;
     }
 }
Example #2
0
 public static function separatePackagesBySession($ids)
 {
     $international_packages = array();
     $domestic_packages = array();
     foreach ($ids as $id_package_ws) {
         $package = new DpdPolandPackage((int) $id_package_ws);
         $session_type = $package->getSessionType();
         if ($session_type == 'INTERNATIONAL') {
             $international_packages[] = (int) $id_package_ws;
         } elseif ($session_type == 'DOMESTIC') {
             $domestic_packages[] = (int) $id_package_ws;
         }
     }
     return array('INTERNATIONAL' => $international_packages, 'DOMESTIC' => $domestic_packages);
 }
Example #3
0
 public function hookAdminOrder($params)
 {
     if (!$this->soapClientExists()) {
         return '';
     }
     $order = new Order((int) $params['id_order']);
     if (!DpdPolandConfiguration::checkRequiredConfiguration()) {
         $this->context->smarty->assign(array('displayBlock' => false, 'moduleSettingsLink' => $this->context->link->getAdminLink('AdminModules') . '&configure=' . $this->name . '&menu=configuration'));
     } else {
         $this->displayFlashMessagesIfIsset();
         // PDF error might be set as flash error
         $order = new Order((int) $params['id_order']);
         $package = DpdPolandPackage::getInstanceByIdOrder((int) $order->id);
         $parcels = DpdPolandParcel::getParcels($order, $package->id_package_ws);
         $products = DpdPolandParcelProduct::getShippedProducts($order, DpdPolandParcelProduct::getProductDetailsByParcels($parcels));
         $customer = new Customer((int) $order->id_customer);
         $settings = new DpdPolandConfiguration();
         if (version_compare(_PS_VERSION_, '1.5', '<')) {
             $this->addJS(_PS_JS_DIR_ . 'jquery/jquery.scrollTo-1.4.2-min.js');
             $this->addJS(_PS_JS_DIR_ . 'jquery/jquery-ui-1.8.10.custom.min.js');
             $this->addJS(_PS_JS_DIR_ . 'jquery/accordion/accordion.ui.js');
             $this->addJS(_PS_JS_DIR_ . 'jquery/jquery.autocomplete.js');
             $this->addJS(_DPDPOLAND_JS_URI_ . 'adminOrder.js');
             $this->addCSS(_DPDPOLAND_CSS_URI_ . 'adminOrder.css');
             $this->addCSS(_PS_CSS_DIR_ . 'jquery-ui-1.8.10.custom.css');
         } else {
             $this->context->controller->addJqueryUI(array('ui.core', 'ui.widget', 'ui.accordion'));
             $this->context->controller->addJqueryPlugin('scrollTo');
             $this->context->controller->addJS(_DPDPOLAND_JS_URI_ . 'adminOrder.js');
             $this->context->controller->addCSS(_DPDPOLAND_CSS_URI_ . 'adminOrder.css');
         }
         $selectedPayerNumber = $package->payerNumber ? $package->payerNumber : $settings->client_number;
         $selectedRecipientIdAddress = $package->id_address_delivery ? $package->id_address_delivery : $order->id_address_delivery;
         $id_currency_pl = Currency::getIdByIsoCode(_DPDPOLAND_CURRENCY_ISO_, (int) $this->context->shop->id);
         $currency_to = new Currency((int) $id_currency_pl);
         $currency_from = new Currency($order->id_currency);
         $id_method = $this->getMethodIdByCarrierId((int) $order->id_carrier);
         if ($id_method) {
             $payment_method_compatible = false;
             $is_cod_module = Configuration::get(DpdPolandConfiguration::COD_MODULE_PREFIX . $order->module);
             if ($id_method == _DPDPOLAND_STANDARD_COD_ID_ && $is_cod_module || $id_method == _DPDPOLAND_STANDARD_ID_ && !$is_cod_module || $id_method == _DPDPOLAND_CLASSIC_ID_ && !$is_cod_module) {
                 $payment_method_compatible = true;
             }
         } else {
             $payment_method_compatible = true;
         }
         if (!$payment_method_compatible) {
             $error_message = $this->l('Your payment method and Shipping method is not compatible.') . '<br />';
             $error_message .= ' ' . $this->l('If delivery address is not Poland, then COD payment method is not supported.') . '<br />';
             $error_message .= ' ' . $this->l('If delivery address is not Poland, then COD payment method is not supported.') . '<br />';
             $error_message .= ' ' . $this->l('If delivery address is Poland and payment method is COD please use shipping method DPD Domestic + COD.') . '<br />';
             $error_message .= ' ' . $this->l('If delivery address is Poland and no COD payment is used please select DPD Domestic shipping method.');
             $this->context->smarty->assign('compatibility_warning_message', $error_message);
         }
         if (!$this->validateAddressForPackageSession((int) $selectedRecipientIdAddress, (int) $id_method)) {
             $error_message = $this->l('Your develivery address is not compatible with the selected shipping method.') . ' ' . $this->l('DPD Poland Domestic is available only if develivery address is Poland.') . ' ' . $this->l('DPD Internationl shipping method is available only if delivery address is not Poland.');
             $this->context->smarty->assign('address_warning_message', $error_message);
         }
         $cookie = new Cookie(_DPDPOLAND_COOKIE_);
         $this->context->smarty->assign(array('displayBlock' => true, 'order' => $order, 'messages' => $this->html, 'package' => $package, 'selected_id_method' => self::getMethodIdByCarrierId($order->id_carrier), 'settings' => $settings, 'payerNumbers' => DpdPolandPayerNumber::getPayerNumbers(), 'selectedPayerNumber' => $selectedPayerNumber, 'products' => $products, 'parcels' => $parcels, 'senderAddress' => $this->getSenderAddress($settings, $package->id_address_sender), 'recipientAddresses' => $customer->getAddresses($this->context->language->id), 'selectedRecipientIdAddress' => $selectedRecipientIdAddress, 'recipientAddress' => $this->getRecipientAddress($selectedRecipientIdAddress), 'currency_from' => $currency_from, 'currency_to' => $currency_to, 'redirect_and_open' => $cookie->dpdpoland_package_id, 'printout_format' => $cookie->dpdpoland_printout_format));
         $this->setGlobalVariablesForAjax();
     }
     if (version_compare(_PS_VERSION_, '1.6', '<')) {
         return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_ . 'hook/adminOrder.tpl');
     }
     return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_ . 'hook/adminOrder_16.tpl');
 }
 public static function printLabels($printout_format)
 {
     $module_instance = Module::getinstanceByName('dpdpoland');
     if ($package_ids = Tools::getValue('PackagesBox')) {
         $package = new DpdPolandPackage();
         $separated_packages = DpdPolandPackage::separatePackagesBySession($package_ids);
         $international_packages = $separated_packages['INTERNATIONAL'];
         $domestic_packages = $separated_packages['DOMESTIC'];
         if ($international_packages) {
             $result = self::createLabelPDFDocument($package, $module_instance, $international_packages, $printout_format, 'international_labels.pdf');
             if ($result !== true) {
                 return $module_instance->outputHTML($result);
             }
         }
         if ($domestic_packages) {
             $result = self::createLabelPDFDocument($package, $module_instance, $domestic_packages, $printout_format, 'domestic_labels.pdf');
             if ($result !== true) {
                 return $module_instance->outputHTML($result);
             }
         }
         include_once _PS_MODULE_DIR_ . 'dpdpoland/libraries/PDFMerger/PDFMerger.php';
         $pdf = new PDFMerger();
         if ($international_packages && $domestic_packages) {
             if (file_exists(_PS_MODULE_DIR_ . 'dpdpoland/labels_multisession.pdf') && !unlink(_PS_MODULE_DIR_ . 'dpdpoland/labels_multisession.pdf')) {
                 $error_message = $module_instance->l('Could not delete old PDF file. Please check module folder permissions', self::FILENAME);
                 $error = $module_instance->displayError($error_message);
                 return $module_instance->outputHTML($error);
             }
             $international_pdf_path = _PS_MODULE_DIR_ . 'dpdpoland/international_labels.pdf';
             $domestic_pdf_path = _PS_MODULE_DIR_ . 'dpdpoland/domestic_labels.pdf';
             $multisession_pdf_path = _PS_MODULE_DIR_ . 'dpdpoland/labels_multisession.pdf';
             $pdf->addPDF($international_pdf_path, 'all')->addPDF($domestic_pdf_path, 'all')->merge('file', $multisession_pdf_path);
         }
         ob_end_clean();
         header('Content-type: application/pdf');
         header('Content-Disposition: attachment; filename="labels_' . time() . '.pdf"');
         if ($international_packages && $domestic_packages) {
             readfile(_PS_MODULE_DIR_ . 'dpdpoland/labels_multisession.pdf');
         } elseif ($international_packages) {
             readfile(_PS_MODULE_DIR_ . 'dpdpoland/international_labels.pdf');
         } elseif ($domestic_packages) {
             readfile(_PS_MODULE_DIR_ . 'dpdpoland/domestic_labels.pdf');
         } else {
             $error_message = $module_instance->l('No labels were found', self::FILENAME);
             $error = $module_instance->displayError($error_message);
             return $module_instance->outputHTML($error);
         }
         self::deletePDFFiles();
     }
 }
    $cookie = new Cookie(_DPDPOLAND_COOKIE_);
    if (isset($cookie->dpdpoland_package_id)) {
        $package_id = $cookie->dpdpoland_package_id;
        $printout_format = $cookie->dpdpoland_printout_format;
        unset($cookie->dpdpoland_package_id);
        unset($cookie->dpdpoland_printout_format);
        $cookie->write();
        $package = new DpdPolandPackage((int) $package_id);
        $pdf_file_contents = $package->generateLabels('PDF', $printout_format);
        ob_end_clean();
        header('Content-type: application/pdf');
        header('Content-Disposition: attachment; filename="package_labels_' . (int) Tools::getValue('id_package_ws') . '.pdf"');
        echo $pdf_file_contents;
        exit;
    }
    $package = new DpdPolandPackage((int) Tools::getValue('id_package_ws'));
    if ($pdf_file_contents = $package->generateLabels()) {
        $cookie->dpdpoland_package_id = (int) Tools::getValue('id_package_ws');
        $printout_format = Tools::getValue('printout_format');
        if (!in_array($printout_format, array(DpdPolandConfiguration::PRINTOUT_FORMAT_A4, DpdPolandConfiguration::PRINTOUT_FORMAT_LABEL))) {
            $printout_format = DpdPolandConfiguration::PRINTOUT_FORMAT_A4;
        }
        $cookie->dpdpoland_printout_format = $printout_format;
        Tools::redirectAdmin(Tools::getValue('returnOnErrorTo') . '&scrollToShipment');
        exit;
    } else {
        DpdPoland::addFlashError(reset(DpdPolandPackageWS::$errors));
        Tools::redirectAdmin(Tools::getValue('returnOnErrorTo') . '&scrollToShipment');
        exit;
    }
}
 public function generateLabelsForMultiplePackages($package_ids, $outputDocFormat, $outputDocPageFormat, $policy)
 {
     $sessionType = '';
     $packages = array();
     foreach ($package_ids as $id_package_ws) {
         $package = new DpdPolandPackage((int) $id_package_ws);
         if (!$sessionType || $sessionType == $package->getSessionType()) {
             $sessionType = $package->getSessionType();
         } else {
             self::$errors[] = $this->l('Manifests of DOMESTIC shipments cannot be mixed with INTERNATIONAL shipments');
             return false;
         }
         $packages[] = array('packageId' => (int) $id_package_ws);
     }
     $this->prepareSenderAddress();
     $params = array('dpdServicesParamsV1' => array('policy' => $policy, 'session' => array('packages' => $packages, 'sessionType' => $sessionType)), 'outputDocFormatV1' => $outputDocFormat, 'outputDocPageFormatV1' => $outputDocPageFormat, 'pickupAddress' => $this->sender);
     if (!($result = $this->generateSpedLabelsV1($params))) {
         return false;
     }
     if (isset($result['session']['statusInfo']['status']) && $result['session']['statusInfo']['status'] == 'OK') {
         foreach ($packages as $id_package_ws) {
             $package = new DpdPolandPackage($id_package_ws);
             $package->labels_printed = 1;
             $package->update();
         }
         return $result['documentData'];
     } else {
         $packages = $result['session']['statusInfo'];
         $packages = array_values($packages) === $packages ? $packages : array($packages);
         // array must be multidimentional
         foreach ($packages as $package) {
             if (isset($package['description'])) {
                 self::$errors[] = $package['description'];
             } elseif (isset($package['status'])) {
                 self::$errors[] = $package['status'];
             }
         }
         return false;
     }
 }