486 lines
16 KiB
PHP
486 lines
16 KiB
PHP
<?php
|
|
|
|
use_helper('stAdminGenerator', 'Countries');
|
|
|
|
function st_poczta_polska_list_order_number(PocztaPolskaPaczka $paczka)
|
|
{
|
|
return '<a href="'.st_url_for('@stOrder?action=edit&id='.$paczka->getOrderId()).'">'.$paczka->getOrder()->getNumber().'</a>';
|
|
}
|
|
|
|
function st_poczta_polska_uslugi($name, $value, array $params = array())
|
|
{
|
|
$options = array();
|
|
|
|
$defaults = array('include_custom' => '---');
|
|
|
|
if ($params) {
|
|
$params = array_merge($defaults, $params);
|
|
} else {
|
|
$params = $defaults;
|
|
}
|
|
|
|
$deliveryPointOnly = isset($params['delivery_point_only']) && $params['delivery_point_only'];
|
|
|
|
$ppks = stPocztaPolskaClient::getCourierServiceList();
|
|
|
|
foreach (stPocztaPolskaClient::getServices() as $n => $service)
|
|
{
|
|
if ($deliveryPointOnly && in_array($n, $ppks)) continue;
|
|
|
|
$options[$n] = __($service['label'], null, 'stPocztaPolskaBackend');
|
|
}
|
|
|
|
natsort($options);
|
|
|
|
return select_tag($name, options_for_select($options, $value, $params));
|
|
}
|
|
|
|
function st_poczta_polska_adres_type($name, ?adresType $adres = null, array $params = [])
|
|
{
|
|
$zwrot = isset($params['zwrot']) ? $params['zwrot'] : null;
|
|
$simple = isset($params['simple']) && $params['simple'];
|
|
|
|
if (null === $adres && $zwrot)
|
|
{
|
|
$adres = clone $zwrot;
|
|
}
|
|
|
|
ob_start();
|
|
|
|
echo st_admin_get_form_field($name.'[nazwa]', __('Nazwisko/Imię/Nazwa'), $adres->nazwa, 'input_tag', array('size' => 40, 'maxlength' => 60));
|
|
|
|
if ($simple)
|
|
{
|
|
echo st_admin_get_form_field($name.'[nazwa2]', __('Nazwisko/Imię/Nazwa cd'), $adres->nazwa2, 'input_tag', array('size' => 40, 'maxlength' => 60));
|
|
echo st_admin_get_form_field($name.'[email]', __('Adres e-mail'), $adres->email, 'input_tag', array('size' => 40, 'maxlength' => 50));
|
|
echo st_admin_get_form_field($name.'[telefon]', __('Telefon'), $adres->telefon, 'input_tag');
|
|
}
|
|
else
|
|
{
|
|
if (null === $zwrot)
|
|
{
|
|
echo st_admin_get_form_field($name.'[nazwa2]', __('Nazwisko/Imię/Nazwa cd'), $adres->nazwa2, 'input_tag', array('size' => 40, 'maxlength' => 60));
|
|
}
|
|
|
|
$address = $adres->ulica;
|
|
|
|
if ($adres->numerDomu)
|
|
{
|
|
$address .= ' ' . $adres->numerDomu;
|
|
|
|
if ($adres->numerLokalu)
|
|
{
|
|
$address .= '/' . $adres->numerLokalu;
|
|
}
|
|
}
|
|
|
|
echo st_admin_get_form_field($name.'[ulica]', __('Adres'), trim($address), 'input_tag', array('size' => 40, 'maxlength' => 255));
|
|
echo st_admin_get_form_field($name.'[kod_pocztowy]', __('Kod pocztowy'), $adres->kodPocztowy, 'input_tag');
|
|
echo st_admin_get_form_field($name.'[miejscowosc]', __('Miejscowość'), $adres->miejscowosc, 'input_tag');
|
|
|
|
if (null === $zwrot)
|
|
{
|
|
echo st_admin_get_form_field($name.'[kraj]', __('Kraj'), $adres->kraj, 'st_poczta_polska_countries_select_tag');
|
|
echo st_admin_get_form_field($name.'[mobile]', __('Telefon komórkowy'), $adres->mobile, 'input_tag');
|
|
echo st_admin_get_form_field($name.'[email]', __('Adres e-mail'), $adres->email, 'input_tag', array('size' => 40, 'maxlength' => 50));
|
|
echo st_admin_get_form_field($name.'[telefon]', __('Telefon'), $adres->telefon, 'input_tag');
|
|
}
|
|
}
|
|
|
|
return ob_get_clean();
|
|
}
|
|
|
|
function st_poczta_polska_zawartosc($name, $value)
|
|
{
|
|
$config = stConfig::getInstance('stPocztaPolskaBackend');
|
|
$slownik = $config->get('slownik');
|
|
$additionalOptions = [];
|
|
|
|
if (!empty($slownik))
|
|
{
|
|
foreach (explode("|", $slownik) as $label)
|
|
{
|
|
$label = trim($label);
|
|
$additionalOptions[$label] = $label;
|
|
}
|
|
}
|
|
|
|
if (!is_object($value) || get_class($value) != zawartoscPocztex2021Type::class)
|
|
{
|
|
$options = [
|
|
__('Standardowe') => array_map(function($label) {
|
|
return __($label, null, 'stPocztaPolskaBackend');
|
|
}, stPocztaPolskaClient::getPocztex1Zawartosc()),
|
|
__('Własne') => $additionalOptions,
|
|
];
|
|
|
|
return select_tag($name, options_for_select($options, $value));
|
|
}
|
|
|
|
$options = [
|
|
'' => __('Wybierz', null, 'stPocztaPolskaBackend'),
|
|
__('Standardowe') => array_map(function($label) {
|
|
return __($label, null, 'stPocztaPolskaBackend');
|
|
}, stPocztaPolskaClient::getPocztex2Zawartosc()),
|
|
__('Własne') => $additionalOptions,
|
|
];
|
|
|
|
if (isset($additionalOptions[$value->zawartoscInna]))
|
|
{
|
|
$value->zawartoscSpecjalna = $value->zawartoscInna;
|
|
$value->zawartoscInna = null;
|
|
}
|
|
|
|
$content = select_tag($name . '[zawartoscSpecjalna]', options_for_select($options, null === $value->zawartoscSpecjalna ? 'NULL' : $value->zawartoscSpecjalna)) . ' ' . input_tag($name . '[zawartoscInna]', $value->zawartoscInna, ['class' => 'bs-d-none']);
|
|
|
|
$id = get_id_from_name($name . '[zawartoscSpecjalna]');
|
|
|
|
$idCustomInput = get_id_from_name($name . '[zawartoscInna]');
|
|
|
|
$content .=<<<JS
|
|
<script>
|
|
jQuery(function(\$) {
|
|
\$('#$id').change(function() {
|
|
const select = \$(this);
|
|
|
|
if ('NULL' == select.val()) {
|
|
\$('#$idCustomInput').removeClass('bs-d-none');
|
|
} else {
|
|
\$('#$idCustomInput').addClass('bs-d-none');
|
|
}
|
|
}).change();
|
|
});
|
|
</script>
|
|
JS;
|
|
|
|
return $content;
|
|
}
|
|
|
|
function st_poczta_polska_ubezpieczenie($name, $value, $params)
|
|
{
|
|
$serviceName = $params['serviceName'];
|
|
unset($params['serviceName']);
|
|
|
|
if (!isset($params['disabled']))
|
|
{
|
|
$params['disabled'] = null === $value || "" === $value;
|
|
}
|
|
|
|
$options = array(
|
|
1000 => '1000',
|
|
5000 => '5000',
|
|
10000 => '10000',
|
|
20000 => '20000',
|
|
50000 => '50000',
|
|
"custom" => __('określona wartość', null, 'stPocztaPolskaBackend'),
|
|
);
|
|
|
|
if ($value !== null && $value < 50001 && !isset($options[$value]))
|
|
{
|
|
foreach ($options as $val => $label)
|
|
{
|
|
if (is_numeric($val) && $value < $val)
|
|
{
|
|
$value = $val;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
$content = '';
|
|
|
|
$fieldContent = st_admin_checkbox_tag('', 1, !$params['disabled'], array(
|
|
'id' => 'st_poczta_polska_ubezpieczenie_trigger'
|
|
));
|
|
|
|
$fieldContent .= content_tag('div', select_tag($name, options_for_select($options, $value > 50000 ? "custom" : $value), array(
|
|
'id' => 'st_poczta_polska_ubezpieczenie',
|
|
'disabled' => $params['disabled'],
|
|
)), array('class' => 'bs-d-inline-block bs-ms-2'));
|
|
|
|
$fieldContent .= ' '.input_tag($name, $value, array(
|
|
'id' => 'st_poczta_polska_ubezpieczenie_custom',
|
|
'disabled' => $params['disabled']
|
|
));
|
|
|
|
$content .= content_tag('div', $fieldContent, array('class' => 'bs-d-inline-block'));
|
|
|
|
$content .=<<<JS
|
|
<script>
|
|
jQuery(function($) {
|
|
|
|
var custom = $('#st_poczta_polska_ubezpieczenie_custom');
|
|
|
|
var select = $('#st_poczta_polska_ubezpieczenie');
|
|
|
|
select.change(function() {
|
|
if (select.val() == "custom") {
|
|
custom.show();
|
|
custom.prop('disabled', false);
|
|
custom.val(50001);
|
|
select.removeAttr('name');
|
|
} else {
|
|
custom.hide();
|
|
custom.prop('disabled', true);
|
|
select.attr('name', custom.attr('name'));
|
|
}
|
|
}).change();
|
|
|
|
custom.change(function() {
|
|
|
|
custom.val(stPrice.fixNumberFormat(custom.val(), 0));
|
|
var value = Number(custom.val());
|
|
|
|
if (value < 50001) {
|
|
value = 50001;
|
|
} else if (value > 250000) {
|
|
value = 250000;
|
|
}
|
|
|
|
custom.val(value);
|
|
});
|
|
|
|
$('#st_poczta_polska_ubezpieczenie_trigger').change(function() {
|
|
var checked = $(this).prop('checked');
|
|
custom.prop('disabled', !checked);
|
|
select.prop('disabled', !checked);
|
|
select.selectBox('update');
|
|
});
|
|
});
|
|
</script>
|
|
JS;
|
|
|
|
return $content;
|
|
}
|
|
|
|
function st_poczta_polska_przesylka_biznesowa_gabaryt_select_tag($name, $selected = null, array $params = array())
|
|
{
|
|
return select_tag($name, options_for_select(stPocztaPolskaClient::getGabarytyBiznesowa(), $selected ? $selected : 'M'), $params);
|
|
}
|
|
|
|
|
|
function st_poczta_polska_countries_select_tag($name, $selected = null, array $params = array())
|
|
{
|
|
$params['country_name'] = true;
|
|
return st_countries_select_tag($name, $selected, $params);
|
|
}
|
|
|
|
function st_poczta_polska_sent_list_actions(PocztaPolskaPaczka $paczka)
|
|
{
|
|
$content = st_get_admin_button('download', __('Etykieta', null, 'stPocztaPolskaBackend'), '@stPocztaPolskaBackend?action=downloadAddressLabel&paczka_id='.$paczka->getId(), array(
|
|
'size' => 'small',
|
|
));
|
|
$content .= st_get_admin_button('download', __('Książka adresowa', null, 'stPocztaPolskaBackend'), '@stPocztaPolskaBackend?action=downloadOutboxBook&paczka_id='.$paczka->getId(), array(
|
|
'size' => 'small',
|
|
));
|
|
$content .= st_get_admin_button('default', __('Śledź przesyłkę', null, 'stPocztaPolskaBackend'), $paczka->getTrackingUrl(), array(
|
|
'size' => 'small',
|
|
));
|
|
|
|
return $content;
|
|
}
|
|
|
|
function st_poczta_polska_package_list_actions(PocztaPolskaPaczka $paczka)
|
|
{
|
|
$services = stPocztaPolskaClient::getServices();
|
|
|
|
$content = st_get_admin_button('download',__('Etykieta', null, 'stPocztaPolskaBackend'), '@stPocztaPolskaBackend?action=downloadParcelDocument&paczka_id='.$paczka->getId(), array(
|
|
'size' => 'small',
|
|
));
|
|
|
|
if ($paczka->getServiceName() && isset($services[$paczka->getServiceName()]))
|
|
{
|
|
$service = $services[$paczka->getServiceName()];
|
|
|
|
if (property_exists($service['class'], 'deklaracjaCelna2'))
|
|
{
|
|
$content .= st_get_admin_button('download',__('Deklaracja celna', null, 'stPocztaPolskaBackend'), '@stPocztaPolskaBackend?action=downloadParcelDocument&paczka_id='.$paczka->getId().'&kind='.PrintKindEnum::CUSTOMS_DECLARATION, array(
|
|
'size' => 'small',
|
|
));
|
|
}
|
|
}
|
|
|
|
$content .= st_get_admin_button('download', __('Blankiety pobrań', null, 'stPocztaPolskaBackend'), '@stPocztaPolskaBackend?action=downloadParcelDocument&paczka_id='.$paczka->getId().'&kind='.PrintKindEnum::COLLECT_ON_DELIVERY_FORM, array(
|
|
'size' => 'small',
|
|
));
|
|
|
|
return $content;
|
|
}
|
|
|
|
function st_poczta_polska_list_urzad_nadania(PocztaPolskaBufor $bufor)
|
|
{
|
|
$client = stPocztaPolskaClient::getInstance();
|
|
|
|
try
|
|
{
|
|
$options = $client->getUrzedyNadania();
|
|
}
|
|
catch(Exception $e)
|
|
{
|
|
$options = array();
|
|
}
|
|
|
|
return isset($options[$bufor->getUrzadNadania()]) ? $options[$bufor->getUrzadNadania()] : null;
|
|
}
|
|
|
|
function st_karty_select($name, $value)
|
|
{
|
|
$client = stPocztaPolskaClient::getInstance();
|
|
|
|
$options = array();
|
|
|
|
$selected = null;
|
|
|
|
if (sfContext::getInstance()->getRequest()->hasErrors())
|
|
{
|
|
$selected = sfContext::getInstance()->getRequest()->getRequestParameter($name);
|
|
}
|
|
|
|
try
|
|
{
|
|
foreach ($client->getKarty() as $karta)
|
|
{
|
|
if (null === $selected && $karta->aktywna || $karta->idKarta == $selected)
|
|
{
|
|
$selected = $karta->idKarta;
|
|
}
|
|
|
|
$options[$karta->idKarta] = $karta->idKarta;
|
|
}
|
|
}
|
|
catch(Exception $e)
|
|
{
|
|
}
|
|
|
|
return select_tag($name, options_for_select($options, $selected, array('include_custom' => __('Wybierz', null, 'stPocztaPolskaBackend'))));
|
|
}
|
|
|
|
function st_urzedy_nadania_select($name, $value)
|
|
{
|
|
$request = sfContext::getInstance()->getRequest();
|
|
|
|
if ($request->getMethod() == sfRequest::POST && $request->hasParameter('config'))
|
|
{
|
|
$data = $request->getParameter('config');
|
|
$client = new stPocztaPolskaClient($data['login'], $data['password'], isset($data['test_mode']));
|
|
}
|
|
else
|
|
{
|
|
$client = stPocztaPolskaClient::getInstance();
|
|
}
|
|
|
|
try
|
|
{
|
|
$disable_cache = $request->getMethod() == sfRequest::POST && $request->hasParameter('config');
|
|
$options = $client->getUrzedyNadania(!$disable_cache);
|
|
}
|
|
catch(Exception $e)
|
|
{
|
|
$options = array();
|
|
}
|
|
|
|
return select_tag($name, options_for_select($options, $value, array('include_custom' => __('Wybierz', null, 'stPocztaPolskaBackend'))));
|
|
}
|
|
|
|
function st_poczta_polska_profile_select($name, $value)
|
|
{
|
|
$client = stPocztaPolskaClient::getInstance();
|
|
|
|
$response = $client->getProfilList(new getProfileList());
|
|
}
|
|
|
|
function st_poczta_polska_optional_input($name, $value, $options)
|
|
{
|
|
return st_admin_optional_input($name, $value, $options);
|
|
}
|
|
|
|
|
|
function st_poczta_polska_rachunki($name, $value)
|
|
{
|
|
$config = stConfig::getInstance('stPocztaPolskaBackend');
|
|
|
|
$options = array();
|
|
|
|
if ($config->get('rachunek1'))
|
|
{
|
|
$options[str_replace(" ", "", $config->get('rachunek1'))] = $config->get('rachunek1');
|
|
}
|
|
|
|
if ($config->get('rachunek2'))
|
|
{
|
|
$options[str_replace(" ", "", $config->get('rachunek2'))] = $config->get('rachunek2');
|
|
}
|
|
|
|
if ($config->get('rachunek3'))
|
|
{
|
|
$options[str_replace(" ", "", $config->get('rachunek3'))] = $config->get('rachunek3');
|
|
}
|
|
|
|
return select_tag($name, options_for_select($options, $value));
|
|
}
|
|
|
|
function st_poczta_polska_punkt_odbioru($name, $pni, array $options)
|
|
{
|
|
$pointName = null;
|
|
$id = get_id_from_name($name);
|
|
$widget_id = 'punkt_odbioru_'.uniqid();
|
|
$placowkaPocztowa = !empty($pni) ? stPocztaPolskaClient::getInstance()->getPlacowkaPocztowa($pni) : null;
|
|
|
|
if (null !== $placowkaPocztowa)
|
|
{
|
|
$pointName = stPocztaPolskaClient::getPointNameFromPlacowkaPocztowa($placowkaPocztowa);
|
|
}
|
|
|
|
$content = input_tag($widget_id, $pointName , [
|
|
'readonly' => true,
|
|
'size' => 50,
|
|
'data-point' => null !== $placowkaPocztowa ? json_encode([
|
|
'name' => $placowkaPocztowa->nazwa,
|
|
'street' => stPocztaPolskaClient::getStreetFromPlacowkaPocztowa($placowkaPocztowa),
|
|
'city' => $placowkaPocztowa->miejscowosc,
|
|
'zipCode' => $placowkaPocztowa->kodPocztowy,
|
|
]) : null,
|
|
]);
|
|
|
|
// $content .= '<br><a href="#" id="'.$id.'_choose" style="vertical-align: middle">'.__('Zmień punkt odbioru', null, 'stPocztaPolskaBackend').'</a>';
|
|
|
|
$content .= content_tag('div', st_get_admin_button('default', __('Zmień punkt odbioru', null, 'stPocztaPolskaBackend'), '#', array('id' => $id.'_choose', 'size' => 'small')), array('class' => 'bs-mt-2'));
|
|
|
|
$content .= input_hidden_tag($name, $pni);
|
|
|
|
$content .= '<script src="https://mapa.ecommerce.poczta-polska.pl/widget/scripts/ppwidget.js?v1"></script>';
|
|
|
|
$cod = $options['cod'];
|
|
|
|
|
|
$content .= "
|
|
<script>
|
|
jQuery(function($) {
|
|
const cod = $cod;
|
|
|
|
const input = $('#$id');
|
|
const widgetInput = $('#$widget_id');
|
|
|
|
const widgetOptions = {
|
|
callback: function(point) {
|
|
widgetInput.val(point.name + ', ' + point.street + ', ' + point.zipCode + ' ' + point.city);
|
|
input.val(point.pni);
|
|
},
|
|
payOnPickup: Boolean(cod),
|
|
payOnPickupMax: cod,
|
|
};
|
|
|
|
$('#{$id}_choose').click(function() {
|
|
if (widgetInput.val().length) {
|
|
let address = widgetInput.val().split(',').slice(1).join(', ');
|
|
widgetOptions.address = address;
|
|
}
|
|
|
|
PPWidgetApp.toggleMap(widgetOptions);
|
|
});
|
|
});
|
|
</script>
|
|
";
|
|
|
|
return $content;
|
|
} |