Files
interblue.pl/modules/GeisLogistic/views/lib/insertexport.php
2024-10-25 14:16:28 +02:00

203 lines
8.0 KiB
PHP

<?php
/**
* 2007-2019 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
include (dirname(__file__) . '/../../../../config/config.inc.php');
include (dirname(__file__) . '/../../../../init.php');
const CHARSET = 'UTF-8';
const REPLACE_FLAGS = ENT_COMPAT;
$geistoken = Tools::getValue('secure_key');
if ($geistoken == 'GeisLogistic') {
$apicode = Configuration::get('GEISLOGISTIC_CODE'); // CustomerCode
$apikey = Configuration::get('GEISLOGISTIC_API'); //Password
$testmode = Configuration::get('GEISLOGISTIC_TEST');
$country = Configuration::get('GEISLOGISTIC_COUNTRY');
$counter = Tools::getValue('geiscounter');
$oidlabel = Configuration::get('GEISLOGISTIC_OID');
if ($oidlabel == '1') {$orderref = Tools::getValue('geisidorder'); }else{$orderref = '0';}
$cod = Tools::getValue('geiscod');
$typeservice = Configuration::get('GEISLOGISTIC_TYPE');
$services = array();
if ($cod != '0') {
if ($typeservice <= '19') {$typec = '2';}else{$typec = '1002';}
$services[] = array(
'Code' => '2',
'Parameter_1' => Tools::getValue('geiscodvalue'),
'Parameter_2' => Tools::getValue('geiscurrencyiso'),
'Parameter_3' => Tools::getValue('geisorder'),
'Parameter_4' => Configuration::get('GEISLOGISTIC_COD_TXT'),
);
}
$adz = Tools::getValue('geisadz');
if ($adz != '0' && $typeservice <= '19') {
$services[] = array(
'Code' => '28',
'Parameter_1' => Configuration::get('GEISLOGISTIC_ADZ_TXT'),
);
}
$poj = Configuration::get('GEISLOGISTIC_POJ');
if ($poj != 0) {
if ($typeservice <= '19') {$typepoj = '3';}else{$typepoj = '1005';}
$services[] = array(
'Code' => $typepoj,
'Parameter_1' => Configuration::get('GEISLOGISTIC_POJ_VAL'),
'Parameter_2' => Configuration::get('GEISLOGISTIC_POJ_ISO'),
);
}
$avi = Tools::getValue('geisavi');
if ($avi != '0' && $typeservice <= '19') {
$services[] = array(
'Code' => '9',
'Parameter_1' => Tools::getValue('geisphone'),
);
}
$avisms = Tools::getValue('geissms');
if ($avisms != '0' && $typeservice <= '19') {
$services[] = array(
'Code' => '30',
'Parameter_1' => Tools::getValue('geisphone'),
);
}
$aviemail = Tools::getValue('geissemail');
if ($aviemail != '0' && $typeservice >= '19') {
$services[] = array(
'Code' => '1091',
'Parameter_1' => Tools::getValue('geisemail'),
);
}
$privperson = Tools::getValue('geisprivate');
if ($privperson != '0' && $typeservice <= '19') {
$services[] = array(
'Code' => '31',
'Parameter_1' => Tools::getValue('geisphone'),
);
}
$addfee = Tools::getValue('geisaddfee');
if ($addfee != '0' && $typeservice <= '19') {
$services[] = array(
'Code' => '128',
);
}
if ($counter == '2'){
$item = array(
'MergedItem' => array(
'Note' => Tools::getValue('geisdecription'),
'PackNumber' => '2',
'Weight' => Tools::getValue('geisweight1'),
),
); }
if ($counter == '3'){
$item = array(
'MergedItem' => array(
'Note' => Tools::getValue('geisdecription'),
'PackNumber' => '2',
'Weight' => Tools::getValue('geisweight1'),
), );
$item[] = array(
'MergedItem' => array(
'Note' => Tools::getValue('geisdecription'),
'PackNumber' => '3',
'Weight' => Tools::getValue('geisweight2'),
), );
}
if ($testmode == '0') {
if ($country == 'PL') {
$wsdl = 'https://gclient.geis.pl/GService/GService.svc?wsdl';
}else{
$wsdl = 'https://gclient.geis.cz/GService/GService.svc?wsdl';
}
}else{
if ($country == 'PL') {
$wsdl = 'https://gclient.geis.pl/GServiceTest/GService.svc?wsdl';
}else{
$wsdl = 'https://gclient.geis.cz/GServiceTest/GService.svc?wsdl';
}
}
ini_set("soap.wsdl_cache_enabled", "0");
try
{
$client = new SoapClient($wsdl, array("trace" => 1));
$data['Request']['Header'] = array(
'CustomerCode' => $apicode,
'Language' => $country,
'Password' => $apikey,
);
$data['Request']['RequestObject']['DeliveryAddress'] = array(
'City' => Tools::getValue('geiscity'),
'Country' => Tools::getValue('geiscountry'),
'Name' => Tools::getValue('geisnazwa'),
'Street' => Tools::getValue('geisstreet'),
'ZipCode' => Tools::getValue('geiszipcode'),
);
$data['Request']['RequestObject']['DeliveryContact'] = array(
'Email' => Tools::getValue('geisemail'),
'FullName' => Tools::getValue('geisname'),
'Phone' => Tools::getValue('geisphone'),
);
$data['Request']['RequestObject']['DistributionChannel'] = Tools::getValue('geischannel');
$data['Request']['RequestObject']['Note'] = Tools::getValue('geisnote');
$data['Request']['RequestObject']['NoteDriver'] = Tools::getValue('geisnotedriver');
$pickupdate = Tools::getValue('pickupdate');
$pickupdates = new DateTime($pickupdate);
$data['Request']['RequestObject']['PickUpDate'] = $pickupdates->format("Y-m-d");
$data['Request']['RequestObject']['Reference'] = $orderref;
$data['Request']['RequestObject']['Weight'] = Tools::getValue('geisweight');
if ($counter != '1') {
$data['Request']['RequestObject']['MergedShipment'] = 1;
$data['Request']['RequestObject']['MergedPackages'] = $item;
}
$data['Request']['RequestObject']['ExportServices']['ExportService'] = $services;
//var_dump($data);
$result = $client->InsertExport($data);
}
catch (exception $ex) {
print "BLAD: .$ex->faultcode .$ex->faultstring. \n\n";
}
if ($result->InsertExportResult->ErrorCode != '0000' ){
print_r($result->InsertExportResult->ErrorMessage);
}else{
print "Paczka nadana. \n Nr listu przewozowego to: ";
$nr = $result->InsertExportResult->ResponseObject->PackNumber;
print_r($nr);
Db::getInstance()->update('order_carrier',array('tracking_number' => $nr),'`id_order` = '.Tools::getValue('geisorder'));
}
$url = htmlspecialchars($_SERVER['HTTP_REFERER']);
print "\n\n <a href='$url'>Powrót</a>";
}else{
die();
}