first commit

This commit is contained in:
2024-11-05 12:22:50 +01:00
commit e5682a3912
19641 changed files with 2948548 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
<?php
class AdminPocztaPolskaController extends AdminController {
public function __construct() {
parent::__construct();
$this->module = Module::getInstanceByName('pocztapolskaen');
$this->bootstrap = true;
$this->context = Context::getContext();
$this->_conf[33] = $this->l('Operacja Wyślij do Urzędu została wykonana pomyślnie');
$this->_conf[34] = $this->l('Operacja Przeniesienia przesyłek została wykonana pomyślnie');
$this->_conf[35] = sprintf($this->l('Zostało wysłane zamówienie po Kuriera data: %s godzina: %s. Kurier skontaktuje się z Państwem w celu ustalenia sczegółow przybycia.'), date('d-m-Y'), date('H:i:s'));
$this->_conf[36] = $this->l('Przesyłki zostały usunięte');
$this->_conf[41] = $this->l('Zbiór został usunięty');
$this->_conf[43] = $this->l('Zbiór został utworzony');
$this->_conf[44] = $this->l('Zbiór został zaktualizowany');
}
/**
* Metoda odpowiedzialna za inicjalizacje procesów
*/
public function initProcess() {
parent::initProcess();
$action = Tools::getValue('action', '');
if (!empty($action)) {
$this->action = $action;
}
}
}

View File

@@ -0,0 +1,334 @@
<?php
require_once(__DIR__ . '/AdminPocztaPolskaController.php');
/**
* Klasa odpowiadajaca za obsluge zamawiania kuriera
*/
class AdminPocztaPolskaCouriersController extends AdminPocztaPolskaController {
public function __construct() {
parent::__construct();
$this->module = Module::getInstanceByName('pocztapolskaen');
$this->bootstrap = true;
$this->context = Context::getContext();
$this->table = 'pp_courier';
$this->list_id = 'pp_courier';
$this->identifier = 'id_pp_courier';
$this->className = 'PPCourier';
$this->lang = true;
$this->_defaultOrderBy = '';
$this->display = 'add';
$this->multiple_fieldsets = true;
$this->page_header_toolbar_title = $this->l('Dodaj nowe zamówienie');
$this->_prepareFormFields();
}
/**
* Metoda odpowiedzialna za przygotowanie pol formularza
*/
protected function _prepareFormFields() {
$this->fields_form[0] = array(
'form' => array(
'panelClass' => 'col-lg-12',
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Szacowana masa przesyłek'),
'name' => 'shipment_mass',
'required' => true,
'class' => 'fixed-width-xxl',
'col' => '9',
'suffix' => 'kg',
),
array(
'type' => 'date',
'label' => $this->l('Data odbioru'),
'name' => 'receipt_date',
'maxlength' => 10,
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('Szacowana ilość przesyłek'),
'name' => 'shipment_quantity',
'class' => 'fixed-width-xxl',
'required' => true,
'col' => '9',
),
array(
'type' => 'select',
'label' => $this->l('Oczekiwana godzina odbioru'),
'name' => 'receipt_hour',
'required' => true,
'col' => '9',
'default_value' => 0,
'options' => array(
'query' => PocztaPolskaEn::getReceptionTime(),
'id' => 'id',
'name' => 'name'
),
),
array(
'type' => 'text',
'label' => $this->l('Adres email do potwierdzenia kuriera'),
'name' => 'confirm_email',
'class' => 'fixed-width-xxl',
'col' => '9',
'required' => true,
),
),
),
);
$this->fields_form[1] = array(
'form' => array(
'panelClass' => 'col-lg-6',
'legend' => array(
'title' => $this->l('Nadawca'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Nazwa'),
'name' => 'sender_name',
'required' => true,
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Ulica'),
'name' => 'sender_street',
'required' => true,
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Numer domu'),
'name' => 'sender_home_number',
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Numer mieszkania'),
'name' => 'sender_local_number',
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Kod pocztowy'),
'name' => 'sender_postal_code',
'required' => true,
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Miejscowość'),
'name' => 'sender_place',
'required' => true,
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Kraj'),
'name' => 'sender_country',
'required' => true,
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Email'),
'name' => 'sender_email',
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Telefon kom'),
'name' => 'sender_mobile_phone',
'col' => '9',
),
)
),
);
$this->fields_form[2] = array(
'form' => array(
'panelClass' => 'col-lg-6',
'legend' => array(
'title' => $this->l('Miejsce odbioru'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Nazwa'),
'name' => 'customer_name',
'required' => true,
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Ulica'),
'name' => 'customer_street',
'required' => true,
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Numer domu'),
'name' => 'customer_home_number',
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Numer mieszkania'),
'name' => 'customer_local_number',
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Kod pocztowy'),
'name' => 'customer_postal_code',
'required' => true,
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Miejscowość'),
'name' => 'customer_place',
'required' => true,
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Kraj'),
'name' => 'customer_country',
'required' => true,
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Email'),
'name' => 'customer_email',
'col' => '9',
),
array(
'type' => 'text',
'label' => $this->l('Telefon kom'),
'name' => 'customer_mobile_phone',
'col' => '9',
),
),
),
);
$this->fields_form[3] = array(
'form' => array(
'panelClass' => 'col-lg-12',
'submit' => array(
'title' => $this->l('Wyślij'),
)
),
);
$this->fields_value = array(
'receipt_date' => date('Y-m-d'),
);
$this->base_tpl_form = 'views/templates/admin/controllers/couriers/form.tpl';
}
/**
* Metoda odpowiedzialna za renderowanie formularza
*/
public function renderForm() {
if (!$this->default_form_language) {
$this->getLanguages();
}
if (Tools::getValue('submitFormAjax')) {
$this->content .= $this->context->smarty->fetch('form_submit_ajax.tpl');
}
if ($this->fields_form && is_array($this->fields_form)) {
if (!$this->multiple_fieldsets) {
$this->fields_form = array(array('form' => $this->fields_form));
}
// For add a fields via an override of $fields_form, use $fields_form_override
if (is_array($this->fields_form_override) && !empty($this->fields_form_override)) {
$this->fields_form[0]['form']['input'] = array_merge($this->fields_form[0]['form']['input'], $this->fields_form_override);
}
$fields_value = $this->getFieldsValue($this->object);
Hook::exec('action' . $this->controller_name . 'FormModifier', array(
'fields' => &$this->fields_form,
'fields_value' => &$fields_value,
'form_vars' => &$this->tpl_form_vars,
));
$helper = new HelperForm($this);
$helper->base_folder = _PS_MODULE_DIR_ . $this->module->name . DIRECTORY_SEPARATOR;
$this->setHelperDisplay($helper);
$helper->fields_value = $fields_value;
$helper->submit_action = $this->submit_action;
$helper->tpl_vars = $this->getTemplateFormVars();
$helper->show_cancel_button = (isset($this->show_form_cancel_button)) ? $this->show_form_cancel_button : ($this->display == 'add' || $this->display == 'edit');
$back = Tools::safeOutput(Tools::getValue('back', ''));
if (empty($back)) {
$back = self::$currentIndex . '&token=' . $this->token;
}
if (!Validate::isCleanHtml($back)) {
die(Tools::displayError());
}
$helper->back_url = $back;
!is_null($this->base_tpl_form) ? $helper->base_tpl = $this->base_tpl_form : '';
if ($this->tabAccess['view']) {
if (Tools::getValue('back')) {
$helper->tpl_vars['back'] = Tools::safeOutput(Tools::getValue('back'));
} else {
$helper->tpl_vars['back'] = Tools::safeOutput(Tools::getValue(self::$currentIndex . '&token=' . $this->token));
}
}
$form = $helper->generateForm($this->fields_form);
return $form;
}
}
public function setMedia($isNewTheme = false) {
parent::setMedia();
$this->addCSS(__PS_BASE_URI__ . 'modules/' . $this->module->name . '/views/templates/admin/css/couriers.css');
}
/**
* Metoda odpowiedzialna za zapis kuriera
*/
public function processSave() {
if (!isset($this->className) || empty($this->className)) {
return false;
}
$this->validateRules();
if (count($this->errors) <= 0) {
$this->object = new $this->className();
$this->copyFromPost($this->object, $this->table);
$this->beforeAdd($this->object);
if (!$this->object->add()) {
$this->errors = $this->object->errors;
}
}
$this->display = 'add';
$this->errors = array_unique($this->errors);
if (!empty($this->errors)) {
$temp = $this->errors;
$this->errors = array();
foreach ($temp as $error) {
$this->errors[] = $error;
}
return $this->errors;
}
$this->redirect_after = self::$currentIndex . '&conf=35&token=' . $this->token;
return $this->object;
}
}

View File

@@ -0,0 +1,947 @@
<?php
require_once(__DIR__ . '/AdminPocztaPolskaController.php');
/**
* Klasa odpowiadajaca za obsulge przesyłek
*/
class AdminPocztaPolskaOrdersController extends AdminPocztaPolskaController {
public $toolbar_title;
protected $statuses_array = array();
protected $actions_available = array('view', 'deleteshipment', 'pack', 'downloadlabel', 'printlabel');
protected $actions = array('view', 'deleteshipment', 'pack', 'downloadlabel', 'printlabel');
public function __construct() {
parent::__construct();
$this->module = Module::getInstanceByName('pocztapolskaen');
$this->bootstrap = true;
$this->table = 'orders';
$this->className = 'PPOrder';
$this->identifier = 'id_pp_order';
$this->lang = false;
$this->explicitSelect = true;
$this->allow_export = false;
$this->multiple_fieldsets = true;
$this->context = Context::getContext();
$this->_use_found_rows = true;
$this->_prepareOrderStatuses();
$this->_prepareListFields();
$this->_prepareListQuery();
}
/**
* Metoda odpowiedzialana za generowanie listy jaka ma sie wyswietlic
*/
public function renderList() {
$this->_prepareMassActions();
$this->tpl_list_vars['order_statuses'] = $this->statuses_array;
if (!($this->fields_list && is_array($this->fields_list))) {
return false;
}
if (!isset($this->context->cookie->pocztapolska_en_reload_data_ts) || time() >= $this->context->cookie->pocztapolska_en_reload_data_ts) {
if((int)Configuration::get(PPSetting::PP_IS_CONNECTED)){
PPPostOffice::reloadData();
PPOrderSet::reloadData();
PPProfileAddress::reloadData();
}
$this->context->cookie->pocztapolska_en_reload_data_ts = time() + PocztaPolskaEn::RELOAD_DATA_INTERVAL;
}
$this->getList($this->context->language->id);
// If list has 'active' field, we automatically create bulk action
if (isset($this->fields_list) && is_array($this->fields_list) && array_key_exists('active', $this->fields_list) && !empty($this->fields_list['active'])) {
if (!is_array($this->bulk_actions)) {
$this->bulk_actions = array();
}
$this->bulk_actions = array_merge(array(
'enableSelection' => array(
'text' => $this->l('Enable selection'),
'icon' => 'icon-power-off text-success'
),
'disableSelection' => array(
'text' => $this->l('Disable selection'),
'icon' => 'icon-power-off text-danger'
),
'divider' => array(
'text' => 'divider'
)
), $this->bulk_actions);
}
$helper = new HelperList();
$helper->module = $this->module;
// Empty list is ok
if (!is_array($this->_list)) {
$this->displayWarning($this->l('Bad SQL query', 'Helper') . '<br />' . htmlspecialchars($this->_list_error));
return false;
}
$this->setHelperDisplay($helper);
$helper->_default_pagination = $this->_default_pagination;
$helper->_pagination = $this->_pagination;
$helper->tpl_vars = $this->getTemplateListVars();
$helper->tpl_delete_link_vars = $this->tpl_delete_link_vars;
// For compatibility reasons, we have to check standard actions in class attributes
foreach ($this->actions_available as $action) {
if (!in_array($action, $this->actions) && isset($this->$action) && $this->$action) {
$this->actions[] = $action;
}
}
$helper->tpl_vars['fields_hidden'] = $this->_getOrderDetail();
$helper->is_cms = $this->is_cms;
$list = $helper->generateList($this->_list, $this->fields_list);
return $list;
}
/**
* Metoda odpowedzialna za przekazanie dodatkowych informacji do listy dla każdego rekordu
*/
private function _getOrderDetail() {
$arr = array();
$url = Context::getContext()->link->getAdminLink('AdminOrders');
foreach ($this->_list as $k => $item) {
$arr[$k]['id_order'] = $item['id_order'];
$arr[$k]['point'] = $item['point'];
$arr[$k]['pni'] = $item['pni'];
$arr[$k]['weight'] = $item['weight'];
$arr[$k]['amount'] = $item['amount'];
$arr[$k]['amount_number'] = $item['amount_number'];
$arr[$k]['total'] = $item['total'];
$arr[$k]['name'] = $item['name'];
$arr[$k]['shipment_number'] = $item['number'];
$arr[$k]['id_envelope'] = $item['id_envelope'];
$arr[$k]['reference'] = $item['reference'];
$arr[$k]['package'] = PPSetting::getPackageByOrderDelvery($item['id_carrier']);
$arr[$k]['is_cod'] = PPSetting::isCarrierIsCod($item['id_carrier']);
$arr[$k]['url'] = $url . '&vieworder&id_order=' . $arr[$k]['id_order'];
$arr[$k]['message'] = $item['message'];
$arr[$k]['address'] = $item['address_pickup'];
}
return $arr;
}
/**
* Metoda odpowiedzialna za kontrukcje url do generowania etykiety
*/
public function displayDownloadlabelLink($token = null, $id) {
if (!array_key_exists('downloadlabel', self::$cache_lang)) {
self::$cache_lang['downloadlabel'] = $this->l('Pobierz etykietę');
}
if (!isset($this->_shipments[$id])) {
return '';
}
$this->context->smarty->assign(array(
'href' => self::$currentIndex .
'&' . $this->identifier . '=' . $id .
'&action=downloadlabel&token=' . ($token != null ? $token : $this->token),
'class' => 'downloadlabel',
'action' => self::$cache_lang['downloadlabel'],
));
return $this->context->smarty->fetch('helpers/list/list_action_default.tpl');
}
/**
* Metoda odpowiedzialna za kontrukcje url do wydruku etykiety
*/
public function displayPrintlabelLink($token = null, $id) {
if (!array_key_exists('printlabel', self::$cache_lang)) {
self::$cache_lang['printlabel'] = $this->l('Drukuj etykietę');
}
if (!isset($this->_shipments[$id])) {
return '';
}
$this->context->smarty->assign(array(
'href' => self::$currentIndex .
'&' . $this->identifier . '=' . $id .
'&action=printlabel&token=' . ($token != null ? $token : $this->token),
'class' => 'printlabel',
'action' => self::$cache_lang['printlabel'],
));
return $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . DIRECTORY_SEPARATOR . 'views/templates/admin/list_action_pack_inline.tpl');
}
/**
* Metoda odpowiedzialna za konstrukcje url do podglądu zamówienia
*/
public function displayViewLink($token = null, $id) {
if (!array_key_exists('view', self::$cache_lang)) {
self::$cache_lang['view'] = $this->l('Zobacz');
}
if($this->module->is1770()){
$href = Context::getContext()->link->getAdminLink('AdminOrders', true, [], ['id_order'=> $id, 'action' => 'vieworder']);
}
else{
$href = Context::getContext()->link->getAdminLink('AdminOrders', true) .
'&id_order=' . $id .
'&vieworder';
}
$this->context->smarty->assign(array(
'href' => $href,
'action' => self::$cache_lang['view'],
));
return $this->context->smarty->fetch('helpers/list/list_action_view.tpl');
}
/**
* Metoda odpowiedzialna za konstrukcje url do akcji pakowania przesyłki
*/
public function displayPackLink($token = null, $id) {
if (!array_key_exists('pack', self::$cache_lang)) {
self::$cache_lang['pack'] = $this->l('Spakuj');
}
if (isset($this->_shipments[$id])) {
return '';
}
$this->context->smarty->assign(array(
'href' => '#',
'class' => 'pack_inline_action',
'action' => self::$cache_lang['pack'],
));
return $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . DIRECTORY_SEPARATOR . 'views/templates/admin/list_action_default.tpl');
}
/**
* metoda inicjujaca toolbar w adminie dla danego controllera
*
* @return mixed
*/
public function initToolbar() {
parent::initToolbar();
unset($this->toolbar_btn['new']);
$this->toolbar_btn[''] = array('desc' => '');
return $this->toolbar_btn;
}
/**
* metoda odpowiedziala na obsluge zadan dla danego controllera
*/
public function initProcess() {
parent::initProcess();
if (Tools::isSubmit('submitBulkdownloadLabelsorders')) {
$this->action = 'bulkDownloadLabels';
} else if (Tools::isSubmit('submitBulkprintLabelsorders')) {
$this->action = 'bulkPrintLabels';
}
}
/**
* metoda odpowiedzialna za obsluge zadania po jego wykonaniu
* @return mixed
*/
public function postProcess() {
if ($this->action == 'view') {
$href = Context::getContext()->link->getAdminLink('AdminOrders');
$href .= '&vieworder&id_order=' . Tools::getValue($this->identifier);
Tools::redirectAdmin($href);
return;
}
return parent::postProcess();
}
/**
* Metoda odpowiedzialna za knstrukcje zapytania sql listy
*/
protected function _prepareListQuery() {
$deliveries = PPSetting::getPPDelivery();
$this->_select = '
a.id_order,
a.id_order as id_pp_order,
o.shipment_number as number,
o.id_buffor as id_buffor,
o.id_shipment,
o.shipment_type,
o.send_date,
a.date_add as order_date,
osl.`name` AS `osname`,
os.`color`,
a.date_add as order_date,
CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,
osl.`name` AS `osname`,
CONCAT(address.address1," ",address.address2,",",address.postcode," ",address.city,",",country_lang.name) as address,
CONCAT(address.address1," ",address.address2,","," ",address.city) as address_pickup,
o.point,
o.pni,
oc.`weight`,
"10000" as amount,
"123" as amount_number,
a.`total_paid_tax_incl` as total,
oset.`id_envelope`,
a.`id_customer`,
a.`reference`,
oc.id_carrier,
(SELECT `message` FROM `'._DB_PREFIX_.'message` WHERE `id_order` = a.id_order ORDER BY `id_message` LIMIT 1) as message
';
$this->_join = '
LEFT JOIN `' . _DB_PREFIX_ . 'pocztapolskaen_order` o ON (o.`id_order` = a.`id_order`)
LEFT JOIN `' . _DB_PREFIX_ . 'pocztapolskaen_order_set` oset ON (oset.`id_en` = o.`id_buffor`)
LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (c.`id_customer` = a.`id_customer`)
LEFT JOIN `' . _DB_PREFIX_ . 'address` address ON address.id_address = a.id_address_delivery
LEFT JOIN `' . _DB_PREFIX_ . 'order_carrier` oc ON (a.`id_order` = oc.`id_order`)
LEFT JOIN `' . _DB_PREFIX_ . 'country` country ON address.id_country = country.id_country
LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` country_lang ON (country.`id_country` = country_lang.`id_country` AND country_lang.`id_lang` = ' . (int) $this->context->language->id . ')
LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON (os.`id_order_state` = a.`current_state`)
LEFT JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = ' . (int) $this->context->language->id . ')';
$this->_orderBy = 'a.id_order';
$this->_orderWay = 'DESC';
$this->_where .= !empty($deliveries) ? ' and (a.id_carrier in(' . implode(PPSetting::PP_SEPARATOR, $deliveries) . ') or not o.id_order is null)' : 'and not o.id_order is null ';
}
/**
* Metoda bydująca tabliece statusów zamówień
*/
protected function _prepareOrderStatuses() {
$statuses = OrderState::getOrderStates((int) $this->context->language->id);
foreach ($statuses as $status) {
$this->statuses_array[$status['id_order_state']] = $status['name'];
}
}
/**
* Metoda odpowiedzialna za przygotowanie kolumn listy
*/
protected function _prepareListFields() {
$this->fields_list = array(
'id_order' => array(
'title' => $this->l('ID'),
'align' => 'text-center',
'class' => 'fixed-width-xs',
'filter_key' => 'o!id_order'
),
'shipment_type' => array(
'title' => $this->l('Rodzaj przesyłki'),
'havingFilter' => true,
'filter_key' => 'o!shipment_type',
'type' => 'select',
'list' => PocztaPolskaEn::getPPPackages(false),
),
'customer' => array(
'title' => $this->l('Klient'),
'havingFilter' => true,
'type' => 'html',
),
'address' => array(
'title' => $this->l('Adres dostawy'),
'havingFilter' => true,
),
'osname' => array(
'title' => $this->l('Status'),
'type' => 'select',
'color' => 'color',
'list' => $this->statuses_array,
'filter_key' => 'os!id_order_state',
'filter_type' => 'int',
'order_key' => 'osname',
'class' => 'fixed-width-xl',
'width' => '100'
),
'number' => array(
'title' => $this->l('Numer przesyłki'),
'havingFilter' => true,
'filter_key' => 'o!shipment_number',
),
'order_date' => array(
'title' => $this->l('Data zamówienia'),
'type' => 'datetime',
'filter_key' => 'a!date_add'
),
'send_date' => array(//ad shipment
'title' => $this->l('Data utworzenia'),
'type' => 'datetime',
'filter_key' => 'o!send_date'
),
'post_date' => array(//send envelope
'title' => $this->l('Data nadania'),
'type' => 'date',
'filter_key' => 'o!post_date'
),
);
}
/**
* Metoda odpowiedzialna za przygotowanie akcji grupowych
*/
protected function _prepareMassActions() {
$this->bulk_actions = array(
'pack' => array(
'text' => $this->l('Spakuj'),
'html' => '<a href="#" id="action_pack_modal"><i class="icon-send"></i>&nbsp;' . $this->l('Spakuj') . '</a>'
),
'downloadLabels' => array(
'text' => $this->l('Pobierz etykiety'),
'icon' => 'icon-send',
),
'printLabels' => array(
'text' => $this->l('Drukuj etykiety'),
'icon' => 'icon-send',
)
);
}
/**
* Metoda incjująca okna modalne
*/
public function initModal() {
$this->_initPackModal();
parent::initModal();
}
/**
* Metoda odpowiadajaca za przekazanie modal do widoku
*/
public function renderModal() {
$modal_render = '';
if (is_array($this->modals) && count($this->modals)) {
foreach ($this->modals as $modal) {
$this->context->smarty->assign($modal);
if ($modal['modal_id'] == 'packModal') {
$modal_render .= $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . DIRECTORY_SEPARATOR . 'views/templates/admin/controllers/orders/pack_modal.tpl');
} else {
$modal_render .= $this->context->smarty->fetch('modal.tpl');
}
}
}
return $modal_render;
}
/**
* Metoda incjująca okno modalne do pakowania przesyłek
*/
protected function _initPackModal() {
$this->setMedia();
require_once(__DIR__ . '/../../helper/AdminPocztaPolskaOrdersHelperForm.php');
$helper = new AdminPocztaPolskaOrdersHelperForm();
$content = $helper->generateForm();
$this->modals[] = array(
'currentToken' => $this->token,
'modal_id' => 'packModal',
'modal_class' => 'modal-lg',
'modal_title' => $this->l('Dodawanie nowej przesyłki dla zamówienia:'),
'modal_content' => '<div id="services" class="modal-body" style="max-height: 70vh;overflow-y: auto;">' . $content . '</div>',
'modal_actions' => array(
array(
'type' => 'link',
'label' => $this->l('Utwórz przesyłkę'),
'href' => '#',
'class' => 'btn btn-primary pack_modal_next_button'
)
)
);
Context::getContext()->override_controller_name_for_translations = null;
}
/**
* metoda odpowiedzialna za dolaczenie dotatkowych plikow do widoku
* @param bool $isNewTheme
*/
public function setMedia($isNewTheme = false) {
parent::setMedia();
$this->addJS(__PS_BASE_URI__ . 'modules/' . $this->module->name . '/views/templates/admin/js/settings.js');
$this->addJS(__PS_BASE_URI__ . 'modules/' . $this->module->name . '/views/templates/admin/js/pack.js');
$this->addJS('https://mapa.ecommerce.poczta-polska.pl/widget/scripts/ppwidget.js');
$this->addCSS(__PS_BASE_URI__ . 'modules/' . $this->module->name . '/views/templates/admin/css/orders.css');
$this->addJS(__PS_BASE_URI__ . 'modules/' . $this->module->name . '/views/templates/admin/js/orders.js');
}
/**
* Metoda odpowidająca za waliadacje paczki
*/
public function ajaxProcessValidatePackage() {
$pp_package = Tools::getValue('pp_packages', '');
$id = Tools::getValue('id_order', '');
$values = PPPackage::getValues($pp_package, PPSetting::getAllValues());
$ppOrder = PPOrder::findByOrder($id);
$package = new PPPackage($pp_package, $ppOrder);
$package->loadFromArray($values);
$result['errors'] = $package->validateFields();
die(Tools::jsonEncode($result));
}
/**
* Metoda odpowidająca za akcje pakowanie paczki.
*/
public function ajaxProcessPackOrder() {
$result = array('success' => true, 'errors' => array(), 'id_buffor' => '', 'id_en' => '');
$id = Tools::getValue('id_order', array());
$order = new Order($id);
$pp_package = Tools::getValue('pp_packages', '');
$ppOrder = PPOrder::findByOrder($id);
$values = PPPackage::getValues($pp_package, PPSetting::getAllValues());
$package = new PPPackage($pp_package, $ppOrder);
$package->loadFromArray($values);
$packageResult = $package->save();
if ($packageResult === false) {
$result['errors'] = $package->errors;
$result['success'] = false;
} else {
if (isset($packageResult[0]['guid'])) {
$ppOrder->id_shipment = $packageResult[0]['guid'];
$ppOrder->shipment_number = $packageResult[0]['numerNadania'];
} else {
$ppOrder->id_shipment = $packageResult['guid'];
$ppOrder->shipment_number = $packageResult['numerNadania'];
}
$ppOrder->id_buffor = $packageResult['id_buffor'];
$ppOrder->shipment_type = $pp_package;
$ppOrder->send_date = date('Y-m-d H:i:s');
$ppOrder->post_date = null;
$ppOrder->id_order = $id;
$ppOrder->id_cart = $order->id_cart;
if ($package->isOdbiorWPunkcie()) {
$ppOrder->pni = $package->pni;
$ppOrder->point = $package->pokaz_mape;
}
if (!$ppOrder->save()) {
$result['errors'] = Tools::displayError($this->l('Błąd zapisu zamówienia'));
$result['success'] = true;
} else {
$result['id_buffor'] = $ppOrder->getOrderSet()->id;
$result['id_en'] = $ppOrder->id_buffor;
$ppOrder->setOrderStatus(PPSetting::PP_STATUS_CREATE);
$ppOrder->setOrderShipment();
}
}
die(Tools::jsonEncode($result));
}
/**
* Metoda odpowiadajaca ca pobranie grupowe etykiet
*/
public function processBulkDownloadLabels() {
$ids = Tools::getValue('ordersBox', array());
if (empty($ids)) {
$this->errors = $this->l('Nie można pobrać etykiet');
return;
}
$pporders = PPOrder::getOrders($ids, false, true);
if ($pporders->count() <= 0) {
$this->errors = $this->l('Nie można pobrać etykiet');
return;
}
$shipments = array();
foreach ($pporders as $order) {
$shipments[] = $order->id_shipment;
}
$pdf = ENadawca::PdfContent();
//$content = $pdf->getAddresLabelByGuidCompact($shipments);
$content = $pdf->getPrintForParcel($shipments);
if ($pdf->hasErrors()) {
$this->errors = $pdf->getErrors();
} else {
foreach ($pporders as $pporder) {
$pporder->setOrderStatus(PPSetting::PP_STATUS_PRINT_LABEL);
}
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="Nalepki adresowe.pdf"');
echo $content;
exit;
}
}
/**
* Metoda odpowiadajaca za drukowanie grupowe etykiet
*/
public function processBulkPrintLabels() {
$ids = Tools::getValue('ordersBox', array());
if (empty($ids)) {
$this->errors = $this->l('Nie można pobrać etykiet');
return;
}
$pporders = PPOrder::getOrders($ids, false, true);
if ($pporders->count() <= 0) {
$this->errors = $this->l('Nie można pobrać etykiet');
return;
}
$shipments = array();
foreach ($pporders as $order) {
$shipments[] = $order->id_shipment;
}
$pdf = ENadawca::PdfContent();
//$content = $pdf->getAddresLabelByGuidCompact($shipments);
$content = $pdf->getPrintForParcel($shipments);
if ($pdf->hasErrors()) {
$this->errors = $pdf->getErrors();
} else {
foreach ($pporders as $pporder) {
$pporder->setOrderStatus(PPSetting::PP_STATUS_PRINT_LABEL);
}
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="Nalepki adresowe.pdf"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
echo $content;
exit;
}
}
/**
* Metoda odpowiadajaca za pobranie danych do wwygenrownia listy
*/
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) {
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
$types = PocztaPolskaEn::getPPPackages(false);
$sets = array();
$buffors = new PrestaShopCollection('PPOrderSet');
$buffors->sqlWhere('(a0.id_envelope is null OR a0.id_envelope=0)');
foreach ($buffors as $c) {
$sets[$c->id_en] = $c;
}
foreach ($this->_list as &$item) {
if (!empty($item['id_shipment'])) {
$this->_shipments[$item['id_order']] = array(
'id_shipment' => $item['id_shipment']
);
}
if (!empty($item['id_buffor']) && isset($sets[$item['id_buffor']])) {
$this->_buffors[$item['id_order']] = $sets[$item['id_buffor']];
}
$item['shipment_type'] = isset($types[$item['shipment_type']]) ? $types[$item['shipment_type']] : $item['shipment_type'];
$item['name'] = $item['reference'] . ',&nbsp;#' . $item['id_order'] . ',&nbsp;' . $item['customer'] . '<br/>' . $item['address'];
$item['total'] = Tools::ps_round($item['total'], _PS_PRICE_DISPLAY_PRECISION_);
$item['weight'] = sprintf("%.3f ", $item['weight']);
if(!$this->module->is16()){
$customerUrl = $this->context->link->getAdminLink('AdminCustomers', true, [], ['id_customer'=> $item['id_customer'], 'action' => 'viewcustomer']);
}
else{
$customerUrl = $this->context->link->getAdminLink('AdminCustomers') . '&viewcustomer&id_customer=' . $item['id_customer'];
}
$item['customer'] = "<a href='{$customerUrl}' traget='_blank' title='{$item['customer']}'>{$item['customer']}</a>";
}
}
/**
* Metodą odpowiadająca za usuwanie przesyłek
*/
public function processDeleteshipment() {
if (Validate::isLoadedObject($object = $this->loadObject())) {
$envelope = ENadawca::Envelope();
$envelope->clearByGuids($object->id_shipment, $object->id_buffor);
if ($envelope->hasErrors()) {
$this->errors = $envelope->getErrors();
} else {
$object->clearShipment();
}
}
if (empty($this->errors)) {
$this->redirect_after = self::$currentIndex . '&conf=36&token=' . $this->token;
}
}
/**
* Metoda odpowidająca za konstrukcje linku do usuwanie przesyłek
*/
public function displayDeleteshipmentLink($token = null, $id) {
if (!array_key_exists('deleteshipment', self::$cache_lang)) {
self::$cache_lang['deleteshipment'] = $this->l('Usuń przesyłki');
}
if (!isset($this->_shipments[$id])) {
return '';
}
if (!isset($this->_buffors[$id])) {
return '';
}
$this->context->smarty->assign(array(
'href' => self::$currentIndex .
'&' . $this->identifier . '=' . $id .
'&action=deleteshipment&token=' . ($token != null ? $token : $this->token),
'class' => 'deleteshipment',
'action' => self::$cache_lang['deleteshipment'],
));
return $this->context->smarty->fetch('helpers/list/list_action_default.tpl');
}
/**
* Metoda odpowidająca za ładowanie pojedyńczego rekordy
*/
protected function loadObject($opt = false) {
if (!isset($this->className) || empty($this->className)) {
return true;
}
$id = (int) Tools::getValue($this->identifier);
if ($id && Validate::isUnsignedId($id)) {
$order = new Order($id);
if (!$this->object) {
$this->object = PPOrder::findByOrder($order->id);
}
if (Validate::isLoadedObject($this->object)) {
return $this->object;
}
// throw exception
$this->errors[] = Tools::displayError($this->l('The object cannot be loaded (or found)'));
return false;
} elseif ($opt) {
if (!$this->object) {
$this->object = new $this->className();
}
return $this->object;
} else {
$this->errors[] = Tools::displayError($this->l('The object cannot be loaded (the identifier is missing or invalid)'));
return false;
}
}
/**
* Metoda odpowiadajaca za pobranie pojedynczej etykiety
*/
public function processDownloadlabel() {
if (Validate::isLoadedObject($object = $this->loadObject())) {
$pdf = ENadawca::PdfContent();
$content = $pdf->getPrintForParcel(array($object->id_shipment));
if ($pdf->hasErrors()) {
$this->errors = $pdf->getErrors();
} else {
$object->setOrderStatus(PPSetting::PP_STATUS_PRINT_LABEL);
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="Nalepki adresowe.pdf"');
echo $content;
exit;
}
}
}
public function ajaxProcessPocztaPolskaOrderForm(){
$idOrder = Tools::getValue('id_order', 0);
require_once($this->module->getLocalPath().'helper/AdminPocztaPolskaOrdersHelperForm.php');
$helper = new AdminPocztaPolskaOrdersHelperForm();
$content = $helper->generateForm();
$modal_conf = array(
'currentToken' => Tools::getAdminTokenLite('AdminPocztaPolskaOrders'),
'modal_id' => 'packModal',
'modal_class' => 'modal-lg',
'modal_title' => $this->l('Dodawanie nowej przesyłki dla zamówienia:'),
'modal_content' => '<div id="services" class="modal-body" style="max-height: 70vh;overflow-y: auto;">' . $content . '</div>',
'modal_actions' => array(
array(
'type' => 'link',
'label' => $this->l('Utwórz przesyłkę'),
'href' => '#',
'class' => 'btn btn-primary pack_modal_next_button'
)
)
);
$this->context->smarty->assign($modal_conf);
$modal_render = '';
$modal_render = $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . DIRECTORY_SEPARATOR . 'views/templates/admin/controllers/orders/pack_modal.tpl');
$module = Module::getInstanceByName('pocztapolskaen');
$order = new Order((int)$idOrder, (int)Configuration::get('PS_LANG_DEFAULT'));
$pp_order = PPOrder::findByCart($order->id_cart, false);
$delivery_address = new Address($order->id_address_delivery);
$shipping = $order->getShipping();
$tab_order = array();
$customer = $order->getCustomer();
$tab_order['name'] = "#".$order->id." ".$order->reference.' '.$this->l('od'). ' '.$customer->firstname.' '.$customer->lastname;
$tab_order['id_order'] = $order->id;
$tab_order['reference'] = $order->reference;
$tab_order['total'] = Tools::ps_round($order->total_paid, _PS_PRICE_DISPLAY_PRECISION_);
$tab_order['weight'] = sprintf("%.3f", $shipping[0]['weight']);
$tab_order['package'] = PPSetting::getPackageByOrderDelvery($order->id_carrier);
$tab_order['is_cod'] = PPSetting::isCarrierIsCod($order->id_carrier);
$tab_order['pni'] = !is_null($pp_order)&&!is_null($pp_order->pni)?$pp_order->pni:'';
$tab_order['point'] = !is_null($pp_order)&&is_string($pp_order->point)?$pp_order->point:'';
$tab_order['shipment_number'] = !is_null($pp_order)&&!empty($pp_order->shipment_number)?$pp_order->shipment_number:'';
$tab_order['message'] = $order->getFirstMessage();
$tab_order['address'] = $delivery_address->address1.' '.$delivery_address->address2.', '.$delivery_address->city;
$tabs = array();
if(!is_null($pp_order)){
if(!empty($pp_order->point)){
$tabs[0] = $this->l('ODBIÓR W PUNKCIE');
}
if(!empty($pp_order->shipment_number)){
$tabs[1] = $this->l('POCZTA POLSKA PRZESYŁKA');
}
if(empty($pp_order->shipment_number) && empty($pp_order->point)){
$tabs[2] = $this->l('POCZTA POLSKA - NADAJ PRZESYŁKĘ');
}
} else {
$tabs[2] = $this->l('POCZTA POLSKA - NADAJ PRZESYŁKĘ');
}
$content = '';
foreach ($tabs as $k => $v) {
$helper = new HelperForm();
$helper->name_controller = 'pocztapolskaen_form';
$helper->multiple_fieldsets = false;
$helper->show_toolbar = false;
$helper->module = $module;
$helper->fields_value = $this->_getFieldsValue($pp_order);
$helper->default_form_language = $this->context->language->id;
$helper->tpl_vars['active_tab'] = '';
$fields = $this->_getOrderFields($v, $k, $tab_order, $modal_render);
$content .= $helper->generateForm($fields);
}
die($content);
}
/**
* metoda zwracaja dodatkowe informacje na temat przesylki PP
* @param $pp_order
* @return array
*/
private function _getFieldsValue($pp_order) {
$module = Module::getInstanceByName('pocztapolskaen');
$tab = array();
$packages = $module::getPPPackages(false);
$orderSet = new PPOrderSet();
if(!is_null($pp_order)){
$buffor = $orderSet->getByBuffor($pp_order->id_buffor);
$tab = array(
'wybrano_punkt' => $pp_order->point,
'numer_nadania' => $pp_order->shipment_number,
'rodzaj' => !empty($pp_order->shipment_type)?$packages[$pp_order->shipment_type]:'',
'data_nadania' =>$buffor->post_date,
//'link' => 'http://emonitoring.poczta-polska.pl/?numer='.$pp_order->shipment_number,
);
}
return $tab;
}
/**
* Metoda przygotowujaca dane do formularza wyswietlajacego podglad przesylki PP w zamowieniu
* @param $title
* @param $tab
* @param $order
* @param $modal
* @return array
*/
protected function _getOrderFields($title, $tab, $order, $modal) {
$fields = array();
switch ($tab) {
case 0:
$fields[]['form'] = array(
'legend' => array(
'icon' => 'icon-plane',
'title' => $this->l($title),
),
'input' => array(
array(
'type' => 'text',
'name' => 'wybrano_punkt',
'label' => $this->l('Wybrano punkt'),
'disabled' => true
),
array(
'type' => 'html',
'name' => 'html_data',
'label' => '',
'html_content' => (empty($order['shipment_number'])?'<button type="button" data-id_order="'.$order['id_order'].'" data-point="'.$order['point'].'" data-pni="'.$order['pni'].'" data-weight="'.$order['weight'].'" data-total="'.$order['total'].'" data-name="'.$order['name'].'" data-reference="'.$order['reference'].'" data-package="'.$order['package'].'" data-is_cod="'.$order['is_cod'].'" data-message="'.$order['message'].'" data-address="'.$order['address'].'" class="btn btn-primary btn_add_package">' . $this->l('Utwórz przesyłkę') . '</button><div class="bootstrap">'.$modal.'</div>':''),
),
),
);
break;
case 1:
$fields[]['form'] = array(
'legend' => array(
'icon' => 'icon-globe',
'title' => $this->l($title),
),
'input' => array(
array(
'type' => 'html',
'name' => 'html_data',
'label' => '<b>' . $this->l('Przesyłki powiązane z tym zamówieniem') . '</b><hr>',
'html_content' => '<a class="btn btn-default" href="'.$this->context->link->getAdminLink('AdminPocztaPolskaOrders', true).'&id_pp_order='.$order['id_order'].'&action=downloadlabel" >'.$this->l('Pobierz etykietę').'</a>&nbsp;<a class="btn btn-default" href="'.$this->context->link->getAdminLink('AdminPocztaPolskaOrders', true).'&id_pp_order='.$order['id_order'].'&action=printlabel" target="_blank">'.$this->l('Drukuj etykietę').'</a>',
),
array(
'type' => 'text',
'name' => 'numer_nadania',
'label' => $this->l('Numer nadania'),
'disabled' => true
),
array(
'type' => 'text',
'name' => 'rodzaj',
'label' => $this->l('Rodzaj'),
'disabled' => true
),
array(
'type' => 'text',
'name' => 'data_nadania',
'label' => $this->l('Data nadania'),
'disabled' => true
),
array(
'type' => 'html',
'name'=>'link',
'html_content' =>'<div style="height:30px; margin-top:8px;"><a target="_blank" style="padding-top:5px;" href="http://emonitoring.poczta-polska.pl/?numer=?'.$order['shipment_number'].'">http://emonitoring.poczta-polska.pl/?numer='.$order['shipment_number'].'</a></div>',
'label' => $this->l('Link do śledzenia'),
),
),
);
break;
case 2:
$fields[]['form'] = array(
'legend' => array(
'icon' => 'icon-plane',
'title' => $this->l($title),
),
'input' => array(
array(
'type' => 'html',
'name' => 'html_data',
'label' => '',
'html_content' => '<button type="button" data-id_order="'.$order['id_order'].'" data-point="'.$order['point'].'" data-pni="'.$order['pni'].'" data-weight="'.$order['weight'].'" data-total="'.$order['total'].'" data-name="'.$order['name'].'" data-reference="'.$order['reference'].'" data-package="'.$order['package'].'" data-is_cod="'.$order['is_cod'].'" data-message="'.$order['message'].'" data-address="'.$order['address'].'" class="btn btn-primary btn_add_package">' . $this->l('Utwórz przesyłkę') . '</button><div class="bootstrap">'.$modal.'</div>',
),
),
);
break;
}
return $fields;
}
/**
* Metoda odpowiadajaca za drukowanie pojedynczej etykiety
*/
public function processPrintlabel() {
if (Validate::isLoadedObject($object = $this->loadObject())) {
$pdf = ENadawca::PdfContent();
$content = $pdf->getPrintForParcel(array($object->id_shipment));
if ($pdf->hasErrors()) {
$this->errors = $pdf->getErrors();
} else {
$object->setOrderStatus(PPSetting::PP_STATUS_PRINT_LABEL);
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="Nalepki adresowe.pdf"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
echo $content;
echo '<script type="text/javascript">alert("ASd");window.print();</script>';
exit;
}
}
}
}

View File

@@ -0,0 +1,776 @@
<?php
require_once(__DIR__ . '/AdminPocztaPolskaController.php');
/**
* Klasa odpowiadajaca za obsulge zbiorow
*/
class AdminPocztaPolskaOrdersSetsController extends AdminPocztaPolskaController {
public $toolbar_title;
protected $statuses_array = array();
protected $actions = array('view','edit', 'delete', 'sendoffice', 'downloadlabel', 'outboxbook', 'transfershipments', 'firmpocztabook', 'setactive');
protected $actions_available = array('view','edit', 'delete', 'sendoffice', 'downloadlabel', 'outboxbook', 'firmpocztabook', 'transfershipments');
public $offices_array;
public function __construct() {
parent::__construct();
$this->module = Module::getInstanceByName('pocztapolskaen');
$this->bootstrap = true;
$this->table = 'pocztapolskaen_order_set';
$this->className = 'PPOrderSet';
$this->lang = false;
$this->explicitSelect = true;
$this->allow_export = false;
$this->context = Context::getContext();
$this->identifier = 'id_order_set';
$offices = PPPostOffice::getCollection();
foreach ($offices as $office) {
$this->offices_array[$office->id_post_office] = $office->name;
}
$this->_prepareListQuery();
$this->_prepareFieldsForm();
$this->_prepareListFields();
}
public function postProcess() {
if ($this->action == 'view') {
$href = Context::getContext()->link->getAdminLink('AdminPocztaPolskaOrdersSetsView', true);
$href .= '&' . $this->identifier . '=' . Tools::getValue($this->identifier);
Tools::redirectAdmin($href);
return;
}
return parent::postProcess();
}
/**
* Metoda odpowiedzialna za knstrukcje zapytania sql listy
*/
protected function _prepareListQuery() {
$this->_select = 'a.`name`,a.`id_envelope`,if(a.active = 1 && a.id_envelope is null,"highlighted","") as class,a.`envelope_status`,po.`name` as post_office,(select COUNT(*) from ' . _DB_PREFIX_ . 'pocztapolskaen_order o WHERE o.`id_buffor` is not null AND o.`id_buffor` = a.`id_en`) as shipment_count';
$this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'pocztapolskaen_post_office` po ON (po.`id_post_office` = a.`id_post_office`)';
$this->_orderBy = 'a.post_date';
$this->_orderWay = 'DESC';
$this->_use_found_rows = false;
}
/**
* Metoda odpowiedzialna za przygotowanie kolumn listy
*/
protected function _prepareListFields() {
$statuses = ENadawca::Envelope()->getStatuses();
$this->fields_list = array(
'id_order_set' => array(
'title' => $this->l('ID'),
'align' => 'text-center',
'class' => 'fixed-width-xs'
),
'name' => array(
'title' => $this->l('Nazwa'),
'havingFilter' => true,
),
'shipment_count' => array(
'title' => $this->l('Ilość przesyłek'),
'havingFilter' => true,
),
'envelope_status' => array(
'title' => $this->l('Status'),
'type' => 'select',
'filter_key' => 'a!envelope_status',
'list' => is_array($statuses)?$statuses:array()
),
'post_office' => array(
'title' => $this->l('Urząd nadania'),
'type' => 'select',
'filter_key' => 'po!id_post_office',
'list' => is_array($this->offices_array)?$this->offices_array:array(),
),
'post_date' => array(
'title' => $this->l('Data nadania'),
'type' => 'date',
),
);
}
/**
* Metoda odpowiedzialna za przygotowanie pol formularza
*/
protected function _prepareFieldsForm() {
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Zbiór'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Nazwa zbioru'),
'name' => 'name',
'required' => true,
'col' => '9',
),
array(
'type' => 'date',
'label' => $this->l('Planowana data nadania'),
'name' => 'post_date',
'maxlength' => 10,
'required' => true,
),
array(
'type' => 'select',
'label' => $this->l('Urząd nadania'),
'name' => 'id_post_office',
'required' => true,
'col' => '9',
'options' => array(
'query' => PPPostOffice::getCollection(true),
'id' => 'id',
'name' => 'name'
),
),
array(
'type' => 'hidden',
'name' => 'set_date',
),
array(
'type' => 'hidden',
'name' => 'change_parcels',
),
),
'submit' => array(
'title' => $this->l('Save'),
'id' =>'OrderSetSave'
)
);
}
/**
* Metoda odpowiedzialana za generowanie listy jaka ma sie wyswietlic
*/
public function renderList() {
if (!($this->fields_list && is_array($this->fields_list))) {
return false;
}
if (!isset($this->context->cookie->pocztapolska_en_reload_data_ts) || time() >= $this->context->cookie->pocztapolska_en_reload_data_ts) {
$expiredSets = PPOrderSet::getExpired('name');
PPPostOffice::reloadData();
PPOrderSet::reloadData(true);
PPProfileAddress::reloadData();
$this->context->cookie->pocztapolska_en_reload_data_ts = time() + PocztaPolskaEn::RELOAD_DATA_INTERVAL;
if (!empty($expiredSets)) {
$this->displayWarning(sprintf($this->l('Następujące zbiory zostały usunięte, ponieważ ich data nadania była starsza niż %s dni: %s'), PocztaPolskaEn::SET_EXPIRED_DAYS, implode(', ', $expiredSets)));
}
}
$this->getList($this->context->language->id);
// If list has 'active' field, we automatically create bulk action
if (isset($this->fields_list) && is_array($this->fields_list) && array_key_exists('active', $this->fields_list) && !empty($this->fields_list['active'])) {
if (!is_array($this->bulk_actions)) {
$this->bulk_actions = array();
}
$this->bulk_actions = array_merge(array(
'enableSelection' => array(
'text' => $this->l('Enable selection'),
'icon' => 'icon-power-off text-success'
),
'disableSelection' => array(
'text' => $this->l('Disable selection'),
'icon' => 'icon-power-off text-danger'
),
'divider' => array(
'text' => 'divider'
)
), $this->bulk_actions);
}
$helper = new HelperList();
$helper->module = $this->module;
// Empty list is ok
if (!is_array($this->_list)) {
$this->displayWarning($this->l('Bad SQL query', 'Helper') . '<br />' . htmlspecialchars($this->_list_error));
return false;
}
$this->setHelperDisplay($helper);
$helper->_default_pagination = $this->_default_pagination;
$helper->_pagination = $this->_pagination;
$helper->tpl_vars = $this->getTemplateListVars();
$helper->tpl_delete_link_vars = $this->tpl_delete_link_vars;
// For compatibility reasons, we have to check standard actions in class attributes
foreach ($this->actions_available as $action) {
if (!in_array($action, $this->actions) && isset($this->$action) && $this->$action) {
$this->actions[] = $action;
}
}
$helper->is_cms = $this->is_cms;
$helper->sql = false;
$list = $helper->generateList($this->_list, $this->fields_list);
return $list;
}
/**
* Metoda odpowiedzialna za wysyłanie przesyłek
*/
public function processSendoffice() {
if (Validate::isLoadedObject($object = $this->loadObject())) {
$postOffice = $object->getPostOffice();
$envelope = ENadawca::Envelope();
if(PPSetting::dateDiff('now',$object->post_date) >=0){
if (!empty($postOffice)) {
$result = $envelope->send($postOffice->id_en, $object->id_en);
if ($envelope->hasErrors()) {
$this->errors = $envelope->getErrors();
} else {
$object->id_envelope = $result['idEnvelope'];
$object->envelope_status = strtolower($result['envelopeStatus']);
$object->save();
$ppOrders = $object->getOrdersByBuffor($object->id_en);
foreach ($ppOrders as $ppOrder) {
$ppOrder->setOrderStatus(PPSetting::PP_STATUS_OFFICE_SEND);
$ppOrder->post_date = $object->post_date;
$ppOrder->save();
}
PPOrderSet::reloadData();
$this->redirect_after = self::$currentIndex . '&conf=33&id_buffor='.$object->id.'&token=' . $this->token;
}
}
} else {
$this->errors[] = $this->l('Data nadania do urzędu nie może być wsteczna. Przejdź od edycji obiektu i zmień datę nadania');
}
} else {
$this->errors[] = Tools::displayError($this->l('An error occurred while updating an object.')) .
' <b>' . $this->table . '</b> ' . Tools::displayError($this->l('(cannot load object)'));
}
}
/**
* Metoda odpowiadajaca za pobranie pojedynczej etykiety
*/
public function processDownloadLabel() {
if (Validate::isLoadedObject($object = $this->loadObject())) {
$pdf = ENadawca::PdfContent();
$guids = $object->getOrdersGuidsByBuffor($object->id_en);
$content = $pdf->getPrintForParcel($guids);
//$content = $pdf->getAddresLabelCompact($object->id_envelope);
if ($pdf->hasErrors()) {
$this->errors = $pdf->getErrors();
} else {
$ppOrders = $object->getOrdersByBuffor($object->id_en);
foreach ($ppOrders as $ppOrder) {
$ppOrder->setOrderStatus(PPSetting::PP_STATUS_PRINT_LABEL);
}
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="Nalepka_adresowa.pdf"');
echo $content;
exit;
}
}
}
/**
* Metoda odpowiadajaca za pobranie pojedynczej poczty firmowej
*/
public function processFirmpocztabook() {
if (Validate::isLoadedObject($object = $this->loadObject())) {
$pdf = ENadawca::PdfContent();
$content = $pdf->getFirmowaPocztaBook($object->id_envelope);
if ($pdf->hasErrors()) {
$this->errors = $pdf->getErrors();
} else {
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="Poczta_firmowa.pdf"');
echo $content;
exit;
}
}
}
/**
* Metoda odpowiadajaca za konstrukcje linku do pobrania poczty firmowej
*/
public function displayFirmpocztabookLink($token = null, $id) {
if (!array_key_exists('firmpocztabook', self::$cache_lang)) {
self::$cache_lang['firmpocztabook'] = $this->l('Poczta firmowa');
}
if (!isset($this->_envelopes[$id])) {
return '';
}
$this->context->smarty->assign(array(
'href' => self::$currentIndex .
'&' . $this->identifier . '=' . $id .
'&action=firmpocztabook&token=' . ($token != null ? $token : $this->token),
'action' => self::$cache_lang['firmpocztabook'],
));
return $this->context->smarty->fetch('helpers/list/list_action_default.tpl');
}
public function displaySetactiveLink($token = null, $id) {
if (!array_key_exists('setactive', self::$cache_lang)) {
self::$cache_lang['setactive'] = $this->l('Ustaw jako domyślny');
}
if (!isset($this->_envelopes[$id])) {
$this->context->smarty->assign(array(
'href' => self::$currentIndex .
'&' . $this->identifier . '=' . $id .
'&action=setactive&token=' . ($token != null ? $token : $this->token),
'action' => self::$cache_lang['setactive'],
));
} else {
return '';
}
return $this->context->smarty->fetch('helpers/list/list_action_default.tpl');
}
/**
* metoda odpowiedzialna za ustawienia wybranego zbioru jako aktywnego
*/
public function processSetactive(){
if (Validate::isLoadedObject($object = $this->loadObject())) {
$active = $object::getActiveCollection();
$buffor = $active->getFirst();
if(is_object($buffor)){
$buffor->active = 0;
$buffor->update();
}
$object->active = 1;
$object->update();
}
}
/**
* Metoda odpowiadajaca za pobranie ksiazki nadawczej
*/
public function processOutboxBook() {
if (Validate::isLoadedObject($object = $this->loadObject())) {
$pdf = ENadawca::PdfContent();
$content = $pdf->getOutboxBook($object->id_envelope);
if ($pdf->hasErrors()) {
$this->errors = $pdf->getErrors();
} else {
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="Ksiazka_nadawcza.pdf"');
echo $content;
exit;
}
}
}
/**
* Metoda odpowiadajaca za konstrukcje linku do pobrania ksiazki nadawczej
*/
public function displayOutboxbookLink($token = null, $id) {
if (!array_key_exists('outboxbook', self::$cache_lang)) {
self::$cache_lang['outboxbook'] = $this->l('Książka nadawcza');
}
if (!isset($this->_envelopes[$id])) {
return '';
}
$this->context->smarty->assign(array(
'href' => self::$currentIndex .
'&' . $this->identifier . '=' . $id .
'&action=outboxbook&token=' . ($token != null ? $token : $this->token),
'action' => self::$cache_lang['outboxbook'],
));
return $this->context->smarty->fetch('helpers/list/list_action_default.tpl');
}
/**
* Metoda odpowiadajaca za konstrukcje linku do przenoszenia przesyłek
*/
public function displayTransfershipmentsLink($token = null, $id) {
if (!array_key_exists('transfershipments', self::$cache_lang)) {
self::$cache_lang['transfershipments'] = $this->l('Przenieś przesyłki');
}
if (isset($this->_envelopes[$id])) {
return '';
}
$href = Context::getContext()->link->getAdminLink('AdminPocztaPolskaTransferSets', true);
$this->context->smarty->assign(array(
'href' => $href .
'&' . $this->identifier . '=' . $id,
'action' => self::$cache_lang['transfershipments'],
));
return $this->context->smarty->fetch('helpers/list/list_action_default.tpl');
}
/**
* Metoda odpowiadajaca za konstrukcje linku do wysylki przesyłek do urzendu
*/
public function displaySendofficeLink($token = null, $id) {
if (!array_key_exists('sendoffice', self::$cache_lang)) {
self::$cache_lang['sendoffice'] = $this->l('Wyślij do urzędu');
}
if (isset($this->_envelopes[$id])) {
return '';
}
if ($this->_shipments[$id]['shipment_count'] <= 0) {
return '';
}
$this->context->smarty->assign(array(
'href' => self::$currentIndex .
'&' . $this->identifier . '=' . $id .
'&action=sendoffice&token=' . ($token != null ? $token : $this->token),
'action' => self::$cache_lang['sendoffice'],
));
return $this->context->smarty->fetch('helpers/list/list_action_default.tpl');
}
/**
* Metoda odpowiadajaca za konstrukcje linku do pobieranie etykiety
*/
public function displayDownloadlabelLink($token = null, $id) {
if (!array_key_exists('downloadlabel', self::$cache_lang)) {
self::$cache_lang['downloadlabel'] = $this->l('Pobierz etykiete');
}
if (!isset($this->_envelopes[$id])) {
return '';
}
$this->context->smarty->assign(array(
'href' => self::$currentIndex .
'&' . $this->identifier . '=' . $id .
'&action=downloadlabel&token=' . ($token != null ? $token : $this->token),
'action' => self::$cache_lang['downloadlabel'],
));
return $this->context->smarty->fetch('helpers/list/list_action_default.tpl');
}
/**
* Metoda odpowiadajaca za dodanie nowego zbioru
*/
public function processAdd() {
if (!isset($this->className) || empty($this->className)) {
return false;
}
$this->validateRules();
if (count($this->errors) <= 0) {
$this->object = new $this->className();
$this->copyFromPost($this->object, $this->table);
$this->beforeAdd($this->object);
if (!$this->object->addEnvelopeBuffor()) {
$this->errors = $this->object->_errors;
$this->display = 'edit';
return false;
}
if (method_exists($this->object, 'add') && !$this->object->add()) {
$this->errors[] = Tools::displayError($this->l('An error occurred while creating an object.')) .
' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
} elseif (($_POST[$this->identifier] = $this->object->id /* voluntary do affectation here */) && $this->postImage($this->object->id) && !count($this->errors) && $this->_redirect) {
PrestaShopLogger::addLog(sprintf($this->l('%s addition', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int) $this->object->id, true, (int) $this->context->employee->id);
$parent_id = (int) Tools::getValue('id_parent', 1);
$this->afterAdd($this->object);
$this->updateAssoShop($this->object->id);
// Save and stay on same form
if (empty($this->redirect_after) && $this->redirect_after !== false && Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
$this->redirect_after = self::$currentIndex . '&' . $this->identifier . '=' . $this->object->id . '&conf=43&update' . $this->table . '&token=' . $this->token;
}
// Save and back to parent
if (empty($this->redirect_after) && $this->redirect_after !== false && Tools::isSubmit('submitAdd' . $this->table . 'AndBackToParent')) {
$this->redirect_after = self::$currentIndex . '&' . $this->identifier . '=' . $parent_id . '&conf=43&token=' . $this->token;
}
// Default behavior (save and back)
if (empty($this->redirect_after) && $this->redirect_after !== false) {
$this->redirect_after = self::$currentIndex. '&' . $this->identifier . '=' . $this->object->id . '&conf=43&token=' . $this->token.'&id_en='.$this->object->id_en;
}
}
}
$this->errors = array_unique($this->errors);
if (!empty($this->errors)) {
// if we have errors, we stay on the form instead of going back to the list
$this->display = 'edit';
return false;
}
return $this->object;
}
/**
* Metoda odpowiadajaca za aktyalizacje zbioru
*/
public function processUpdate() {
/* Checking fields validity */
$this->validateRules();
if (empty($this->errors)) {
$id = (int) Tools::getValue($this->identifier);
/* Object update */
if (isset($id) && !empty($id)) {
/** @var ObjectModel $object */
$object = new $this->className($id);
if (Validate::isLoadedObject($object)) {
$this->copyFromPost($object, $this->table);
if (!$object->updateEnvelopeBuffor()) {
$this->errors = $object->_errors;
$this->display = 'edit';
return false;
}
/* Specific to objects which must not be deleted */
if ($this->deleted && $this->beforeDelete($object)) {
// Create new one with old objet values
/** @var ObjectModel $object_new */
$object_new = $object->duplicateObject();
if (Validate::isLoadedObject($object_new)) {
// Update old object to deleted
$object->deleted = 1;
$object->update();
// Update new object with post values
$this->copyFromPost($object_new, $this->table);
$result = $object_new->update();
if (Validate::isLoadedObject($object_new)) {
$this->afterDelete($object_new, $object->id);
}
}
} else {
$this->copyFromPost($object, $this->table);
$result = $object->update();
$this->afterUpdate($object);
}
if ($object->id) {
$this->updateAssoShop($object->id);
}
if (!$result) {
$this->errors[] = Tools::displayError($this->l('An error occurred while updating an object.')) .
' <b>' . $this->table . '</b> (' . Db::getInstance()->getMsgError() . ')';
} elseif ($this->postImage($object->id) && !count($this->errors) && $this->_redirect) {
$parent_id = (int) Tools::getValue('id_parent', 1);
// Specific back redirect
if ($back = Tools::getValue('back')) {
$this->redirect_after = urldecode($back) . '&conf=44';
}
// Specific scene feature
// @todo change stay_here submit name (not clear for redirect to scene ... )
if (Tools::getValue('stay_here') == 'on' || Tools::getValue('stay_here') == 'true' || Tools::getValue('stay_here') == '1') {
$this->redirect_after = self::$currentIndex . '&' . $this->identifier . '=' . $object->id . '&conf=44&updatescene&token=' . $this->token;
}
// Save and stay on same form
// @todo on the to following if, we may prefer to avoid override redirect_after previous value
if (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
$this->redirect_after = self::$currentIndex . '&' . $this->identifier . '=' . $object->id . '&conf=44&update' . $this->table . '&token=' . $this->token;
}
// Save and back to parent
if (Tools::isSubmit('submitAdd' . $this->table . 'AndBackToParent')) {
$this->redirect_after = self::$currentIndex . '&' . $this->identifier . '=' . $parent_id . '&conf=4&token=' . $this->token;
}
// Default behavior (save and back)
if (empty($this->redirect_after) && $this->redirect_after !== false) {
$this->redirect_after = self::$currentIndex . ($parent_id ? '&' . $this->identifier . '=' . $object->id : '') . '&conf=44&token=' . $this->token;
}
}
PrestaShopLogger::addLog(sprintf($this->l('%s modification', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int) $object->id, true, (int) $this->context->employee->id);
} else {
$this->errors[] = Tools::displayError($this->l('An error occurred while updating an object.')) .
' <b>' . $this->table . '</b> ' . Tools::displayError($this->l('(cannot load object)'));
}
}
}
$this->errors = array_unique($this->errors);
if (!empty($this->errors)) {
// if we have errors, we stay on the form instead of going back to the list
$this->display = 'edit';
return false;
}
if (isset($object)) {
return $object;
}
return;
}
/**
* Metoda odpowiadajaca za usuwanie zbioru
*/
public function processDelete() {
if (Validate::isLoadedObject($object = $this->loadObject())) {
$res = true;
// check if request at least one object with noZeroObject
if (isset($object->noZeroObject) && count(call_user_func(array($this->className, $object->noZeroObject))) <= 1) {
$this->errors[] = Tools::displayError($this->l('You need at least one object.')) .
' <b>' . $this->table . '</b><br />' .
Tools::displayError($this->l('You cannot delete all of the items.'));
} elseif (array_key_exists('delete', $this->list_skip_actions) && in_array($object->id, $this->list_skip_actions['delete'])) { //check if some ids are in list_skip_actions and forbid deletion
$this->errors[] = Tools::displayError($this->l('You cannot delete this item.'));
} else {
if (!$object->deleteEnvelopeBuffor()) {
$this->errors = $object->_errors;
return false;
}
if ($this->deleted) {
if (!empty($this->fieldImageSettings)) {
$res = $object->deleteImage();
}
if (!$res) {
$this->errors[] = Tools::displayError($this->l('Unable to delete associated images.'));
}
$object->deleted = 1;
if ($res = $object->update()) {
$this->redirect_after = self::$currentIndex . '&conf=41&token=' . $this->token;
}
} elseif ($res = $object->delete()) {
PPOrderSet::reloadData();
$this->redirect_after = self::$currentIndex . '&conf=41&token=' . $this->token;
}
$this->errors[] = Tools::displayError($this->l('An error occurred during deletion.'));
if ($res) {
PrestaShopLogger::addLog(sprintf($this->l('%s deletion', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int) $this->object->id, true, (int) $this->context->employee->id);
}
}
} else {
$this->errors[] = Tools::displayError($this->l('An error occurred while deleting the object.')) .
' <b>' . $this->table . '</b> ' .
Tools::displayError($this->l('(cannot load object)'));
}
return $object;
}
/**
* Metoda odpowiadajaca za pobranie danych do wwygenrownia listy
*/
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) {
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
$statuses = ENadawca::Envelope()->getStatuses();
foreach ($this->_list as &$item) {
if (!empty($item['id_envelope'])) {
$this->_envelopes[$item['id_order_set']] = array(
'id_envelope' => $item['id_envelope']
);
}
$this->_shipments[$item['id_order_set']] = array(
'shipment_count' => $item['shipment_count']
);
$item['envelope_status'] = isset($statuses[$item['envelope_status']]) ? $statuses[$item['envelope_status']] : $item['envelope_status'];
}
}
/**
* Metoda odpowiedzialna za konstrukcje url do podglądu zbioru
*/
public function displayViewLink($token = null, $id) {
$href = Context::getContext()->link->getAdminLink('AdminPocztaPolskaOrdersSetsView', true);
$href .= '&' . $this->identifier . '=' . $id;
if (!array_key_exists('view', self::$cache_lang)) {
self::$cache_lang['view'] = $this->l('Zobacz');
}
$this->context->smarty->assign(array(
'href' => $href,
'action' => self::$cache_lang['view'],
));
return $this->context->smarty->fetch('helpers/list/list_action_view.tpl');
}
/**
* Metoda odpowiadajaca za konstrukcje liku do edycji zbioru
*/
public function displayEditLink($token = null, $id, $name = null) {
if (!array_key_exists('Edit', self::$cache_lang)) {
self::$cache_lang['Edit'] = $this->l('Edit', 'Helper');
}
if (isset($this->_envelopes[$id])) {
return '';
}
$this->context->smarty->assign(array(
'href' => self::$currentIndex . '&' . $this->identifier . '=' . $id . '&update' . $this->table .'&token=' . ($token != null ? $token : $this->token),
'action' => self::$cache_lang['Edit'],
'id' => $id
));
return $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . DIRECTORY_SEPARATOR . 'views/templates/admin/list_action_edit.tpl');
}
/**
* Metoda odpowiadajaca za konstrukcje liku do usuwania zbioru
*/
public function displayDeleteLink($token = null, $id, $name = null) {
if (!array_key_exists('Delete', self::$cache_lang)) {
self::$cache_lang['Delete'] = $this->l('Delete', 'Helper');
}
if (!array_key_exists('DeleteItem', self::$cache_lang)) {
self::$cache_lang['DeleteItem'] = $this->l('Delete selected item?', 'Helper', true, false);
}
if (!array_key_exists('Name', self::$cache_lang)) {
self::$cache_lang['Name'] = $this->l('Name:', 'Helper', true, false);
}
if (isset($this->_envelopes[$id])) {
return '';
}
if (!is_null($name)) {
$name = addcslashes('\n\n' . self::$cache_lang['Name'] . ' ' . $name, '\'');
}
$data = array(
$this->identifier => $id,
'href' => self::$currentIndex . '&' . $this->identifier . '=' . $id . '&delete' . $this->table . '&token=' . ($token != null ? $token : $this->token),
'action' => self::$cache_lang['Delete'],
);
if ($this->specificConfirmDelete !== false) {
$data['confirm'] = !is_null($this->specificConfirmDelete) ? '\r' . $this->specificConfirmDelete : Tools::safeOutput(self::$cache_lang['DeleteItem'] . $name);
}
$this->context->smarty->assign(array_merge($this->tpl_delete_link_vars, $data));
return $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . DIRECTORY_SEPARATOR . 'views/templates/admin/list_action_delete.tpl');
}
/**
* metoda inicjujaca toolbar w adminie dla danego controllera
*
* @return mixed
*/
public function initToolbar() {
parent::initToolbar();
$this->toolbar_btn['reload'] = array(
'href' => self::$currentIndex . '&action=reload&' . $this->table . '&token=' . $this->token,
'desc' => $this->l('Odśwież'),
'imgclass' => 'refresh'
);
return $this->toolbar_btn;
}
/**
* Metoda odpowiada za powtorne zaladowanie danych z EN - zbiory i urzendy nadania
*/
public function processReload() {
$this->context->cookie->pocztapolska_en_reload_data_ts = 0;
Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token);
}
public function setMedia($isNewTheme = false) {
parent::setMedia();
$this->addJS(__PS_BASE_URI__ . 'modules/' . $this->module->name . '/views/templates/admin/js/sets.js');
}
public function getFieldsValue($obj) {
parent::getFieldsValue($obj);
$this->fields_value['set_date'] = $obj->post_date;
if(empty($this->fields_value['change_parcels'])) {
$this->fields_value['change_parcels'] = 0;
}
return $this->fields_value ;
}
}

View File

@@ -0,0 +1,66 @@
<?php
require_once(__DIR__ . '/AdminPocztaPolskaController.php');
require_once(__DIR__ . '/AdminPocztaPolskaTransferSets.php');
class AdminPocztaPolskaOrdersSetsViewController extends AdminPocztaPolskaTransferSetsController {
/**
* metoda odpowiedzialna za renderowanie listy w widoku dla controllera
*
* @return string
*/
public function renderList() {
if (!($this->fields_list && is_array($this->fields_list))) {
return false;
}
$id_order_set = Tools::getValue('id_order_set', '');
if (empty($id_order_set)) {
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminPocztaPolskaOrdersSets'));
}
$orderSet = new PPOrderSet(Tools::getValue('id_order_set'));
$this->_where = ' AND o.`id_buffor`=' . $orderSet->id_en;
$this->page_header_toolbar_title = $this->l('Podgląd przesyłek zbioru').' '.$orderSet->name;
$this->getList($this->context->language->id);
// If list has 'active' field, we automatically create bulk action
if (isset($this->fields_list) && is_array($this->fields_list) && array_key_exists('active', $this->fields_list) && !empty($this->fields_list['active'])) {
if (!is_array($this->bulk_actions)) {
$this->bulk_actions = array();
}
$this->bulk_actions = array();
}
$helper = new HelperList();
$helper->module = $this->module;
// Empty list is ok
if (!is_array($this->_list)) {
$this->displayWarning($this->l('Bad SQL query', 'Helper') . '<br />' . htmlspecialchars($this->_list_error));
return false;
}
$this->setHelperDisplay($helper);
$helper->_default_pagination = $this->_default_pagination;
$helper->_pagination = $this->_pagination;
$helper->tpl_vars = $this->getTemplateListVars();
$helper->tpl_delete_link_vars = $this->tpl_delete_link_vars;
// For compatibility reasons, we have to check standard actions in class attributes
foreach ($this->actions_available as $action) {
if (!in_array($action, $this->actions) && isset($this->$action) && $this->$action) {
$this->actions[] = $action;
}
}
$helper->actions = [];
$helper->bulk_actions = [];
$helper->is_cms = $this->is_cms;
$helper->sql = $this->_listsql;
$helper->simple_header = true;
$list = $helper->generateList($this->_list, $this->fields_list);
return $list;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,373 @@
<?php
require_once(__DIR__ . '/AdminPocztaPolskaController.php');
/**
* Klasa odpowiadajaca za przenoszenie przesyłek pomiedzy zbiorami
*/
class AdminPocztaPolskaTransferSetsController extends AdminPocztaPolskaController {
public function __construct() {
parent::__construct();
$this->module = Module::getInstanceByName('pocztapolskaen');
$this->bootstrap = true;
$this->table = 'orders';
$this->className = 'PPOrder';
$this->identifier = 'id_order';
$this->lang = false;
$this->explicitSelect = true;
$this->allow_export = false;
$this->context = Context::getContext();
$this->force_show_bulk_actions = true;
$this->_use_found_rows = true;
$this->_prepareOrderStatuses();
$this->_prepareListFields();
$this->_prepareListQuery();
$this->_prepareFieldsForm();
$this->_prepareMassActions();
}
/**
* Metoda bydująca tabliece statusów zamówień
*/
protected function _prepareOrderStatuses() {
$statuses = OrderState::getOrderStates((int) $this->context->language->id);
foreach ($statuses as $status) {
$this->statuses_array[$status['id_order_state']] = $status['name'];
}
}
/**
* Metoda odpowiedzialna za przygotowanie kolumn listy
*/
protected function _prepareListFields() {
$this->fields_list = array(
'id_order' => array(
'title' => $this->l('ID'),
'align' => 'text-center',
'class' => 'fixed-width-xs',
'filter_key' => 'o!id_order',
'remove_onclick' => true
),
'shipment_type' => array(
'title' => $this->l('Rodzaj przesyłki'),
'havingFilter' => true,
'filter_key' => 'o!shipment_type',
'type' => 'select',
'list' => PocztaPolskaEn::getPPPackages(false),
'remove_onclick' => true
),
'customer' => array(
'title' => $this->l('Klient'),
'havingFilter' => true,
'type' => 'html',
'remove_onclick' => true
),
'address' => array(
'title' => $this->l('Adres dostawy'),
'havingFilter' => true,
'remove_onclick' => true
),
'osname' => array(
'title' => $this->l('Status'),
'type' => 'select',
'color' => 'color',
'list' => $this->statuses_array,
'filter_key' => 'os!id_order_state',
'filter_type' => 'int',
'order_key' => 'osname',
'remove_onclick' => true
),
'number' => array(
'title' => $this->l('Numer przesyłki'),
'havingFilter' => true,
'filter_key' => 'o!shipment_number',
'remove_onclick' => true
),
'order_date' => array(
'title' => $this->l('Data zamówienia'),
'type' => 'datetime',
'filter_key' => 'a!date_add',
'remove_onclick' => true
),
'send_date' => array(//ad shipment
'title' => $this->l('Data utworzenia'),
'type' => 'datetime',
'filter_key' => 'o!send_date',
'remove_onclick' => true
),
);
}
/**
* Metoda odpowiedzialna za knstrukcje zapytania sql listy
*/
protected function _prepareListQuery() {
$deliveries = PPSetting::getPPDelivery();
$this->_select = '
a.id_order,
o.id_pp_order,
o.shipment_number as number,
o.id_buffor as id_buffor,
o.id_shipment,
o.shipment_type,
o.send_date,
a.date_add as order_date,
osl.`name` AS `osname`,
os.`color`,
a.date_add as order_date,
CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,
osl.`name` AS `osname`,
CONCAT_WS(" ",address.address1,address.address2,address.postcode,address.city,country_lang.name) as address,
o.point,
o.pni,
oc.`weight`,
"10000" as amount,
"123" as amount_number,
a.`total_paid_tax_incl` as total,
oset.`id_envelope`,
a.`id_customer`,
a.`reference`,
oc.id_carrier
';
$this->_join = '
LEFT JOIN `' . _DB_PREFIX_ . 'pocztapolskaen_order` o ON (o.`id_order` = a.`id_order`)
LEFT JOIN `' . _DB_PREFIX_ . 'pocztapolskaen_order_set` oset ON (oset.`id_en` = o.`id_buffor`)
LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (c.`id_customer` = a.`id_customer`)
LEFT JOIN `' . _DB_PREFIX_ . 'address` address ON address.id_address = a.id_address_delivery
LEFT JOIN `' . _DB_PREFIX_ . 'order_carrier` oc ON (a.`id_order` = oc.`id_order`)
LEFT JOIN `' . _DB_PREFIX_ . 'country` country ON address.id_country = country.id_country
LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` country_lang ON (country.`id_country` = country_lang.`id_country` AND country_lang.`id_lang` = ' . (int) $this->context->language->id . ')
LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON (os.`id_order_state` = a.`current_state`)
LEFT JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = ' . (int) $this->context->language->id . ')';
$this->_orderBy = 'a.id_order';
$this->_orderWay = 'DESC';
$this->_where .= !empty($deliveries) ? ' and (a.id_carrier in(' . implode(PPSetting::PP_SEPARATOR, $deliveries) . ') or not o.id_order is null)' : 'and not o.id_order is null ';
}
/**
* Metoda odpowiedzialna za przygotowanie akcji grupowych
*/
protected function _prepareMassActions() {
$this->bulk_actions = array(
'transferSets' => array(
'text' => $this->l('Przenieś przesyłki'),
'icon' => 'icon-send',
'onclick' => 'ppSet.toggle(\'transfer_sets_action\');'
)
);
}
public function setMedia($isNewTheme = false) {
parent::setMedia();
$this->addJS(__PS_BASE_URI__ . 'modules/' . $this->module->name . '/views/templates/admin/js/sets.js');
}
/**
* Metoda odpowiedzialna za przygotowanie pol formularza
*/
protected function _prepareFieldsForm() {
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Zbiór'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Nazwa zbioru'),
'name' => 'name',
'required' => true,
'col' => '9',
),
array(
'type' => 'date',
'label' => $this->l('Planowana data nadania'),
'name' => 'date_from',
'maxlength' => 10,
'required' => true,
),
array(
'type' => 'select',
'label' => $this->l('Urząd nadania'),
'name' => 'customer_name',
'required' => true,
'col' => '9',
'default_value' => (int) $this->context->country->id,
'options' => array(
'query' => PPPostOffice::getCollection(true),
'id' => 'id_en',
'name' => 'name'
),
),
),
'submit' => array(
'title' => $this->l('Zapisz'),
)
);
}
/**
* Metoda odpowiedzialana za generowanie listy jaka ma sie wyswietlic
*/
public function renderList() {
if (!($this->fields_list && is_array($this->fields_list))) {
return false;
}
$id_order_set = Tools::getValue('id_order_set', '');
if (empty($id_order_set)) {
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminPocztaPolskaOrdersSets'));
}
$orderSet = new PPOrderSet(Tools::getValue('id_order_set'));
$this->_where = ' AND o.`id_buffor`=' . $orderSet->id_en;
$this->getList($this->context->language->id);
// If list has 'active' field, we automatically create bulk action
if (isset($this->fields_list) && is_array($this->fields_list) && array_key_exists('active', $this->fields_list) && !empty($this->fields_list['active'])) {
if (!is_array($this->bulk_actions)) {
$this->bulk_actions = array();
}
$this->bulk_actions = array_merge(array(
'enableSelection' => array(
'text' => $this->l('Enable selection'),
'icon' => 'icon-power-off text-success'
),
'disableSelection' => array(
'text' => $this->l('Disable selection'),
'icon' => 'icon-power-off text-danger'
),
'divider' => array(
'text' => 'divider'
)
), $this->bulk_actions);
}
$helper = new HelperList();
$helper->module = $this->module;
$helper->force_show_bulk_actions = $this->force_show_bulk_actions;
// Empty list is ok
if (!is_array($this->_list)) {
$this->displayWarning($this->l('Bad SQL query', 'Helper') . '<br />' . htmlspecialchars($this->_list_error));
return false;
}
$this->setHelperDisplay($helper);
$helper->_default_pagination = $this->_default_pagination;
$helper->_pagination = $this->_pagination;
$helper->tpl_vars = $this->getTemplateListVars();
$helper->tpl_delete_link_vars = $this->tpl_delete_link_vars;
// For compatibility reasons, we have to check standard actions in class attributes
foreach ($this->actions_available as $action) {
if (!in_array($action, $this->actions) && isset($this->$action) && $this->$action) {
$this->actions[] = $action;
}
}
$helper->is_cms = $this->is_cms;
$helper->sql = $this->_listsql;
$helper->simple_header = true;
$list = $helper->generateList($this->_list, $this->fields_list);
return $list;
}
/**
* metoda zwracaja dostakowe parametry do zaladowania w Smarty
*
* @return array - lista parametrow
*/
public function getTemplateListVars() {
$id_order_set = Tools::getValue('id_order_set', '');
$setsCollection = new PrestaShopCollection('PPOrderSet');
$setsCollection->sqlWhere('(a0.id_envelope is null OR a0.id_envelope=0) AND a0.post_date>=CURDATE()');
$setsCollection->where('id_order_set', '<>', $id_order_set);
$sets = array();
foreach ($setsCollection as $set) {
$sets[$set->id_en] = $set->name;
}
$this->tpl_list_vars['id_buffors'] = $sets;
$this->tpl_list_vars['id_order_set'] = $id_order_set;
return $this->tpl_list_vars;
}
/**
* metoda inicjujaca toolbar w adminie dla danego controllera
*
* @return mixed
*/
public function initToolbar() {
parent::initToolbar();
unset($this->toolbar_btn['new']);
$this->toolbar_btn[''] = array('desc' => '');
return $this->toolbar_btn;
}
/**
* Metoda odpowiadająca za przenoszenie zbiorów
*/
public function processBulktransferSets() {
$ordersIds = Tools::getValue('ordersBox', array());
$idBufforTo = Tools::getValue('id_buffor', '');
$id_order_set = Tools::getValue('id_order_set', '');
$set = PPOrderSet::getByBuffor($idBufforTo);
if (!empty($ordersIds)) {
if (!empty($idBufforTo)) {
$orders = PPOrder::getGroupedByBuffer($ordersIds);
$shipment = ENadawca::Shipment();
if (!empty($orders)) {
foreach ($orders as $idBuffor => $v) {
$result = $shipment->move($idBuffor, $idBufforTo, $v['guids']);
$notMovedGuid = array();
if ($result['notMovedGuid']) {
$notMovedGuid = (!is_array($result['notMovedGuid'])) ? array($result['notMovedGuid']) : $result['notMovedGuid'];
}
if (!empty($notMovedGuid)) {
}
if (!$shipment->hasErrors()) {
foreach ($v['orders'] as $order) {
if (!in_array($order->id_shipment, $notMovedGuid)) {
$order->id_buffor = $idBufforTo;
$order->post_date = null;
$order->save();
} else {
$this->errors[] = sprintf($this->l('Przesyłka nr %s nie została przeniesiona'), $order->shipment_number);
}
}
} else {
$errors = $shipment->getErrors();
foreach ($errors as $error) {
$this->errors[] = $error;
}
}
}
} else {
$this->errors[] = $this->l('Brak przesyłek');
}
} else {
$this->errors[] = $this->l('Nie wybrano bufora docelowego');
}
} else {
$this->errors[] = $this->l('Nie wybrano przesyłek');
}
if (!empty($this->errors)) {
return false;
}
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminPocztaPolskaOrdersSets') . '&conf=34&id_buffor=' . $set->id);
}
/**
* Metoda odpowiadajaca za pobranie danych do wwygenrownia listy
*/
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) {
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
$types = PocztaPolskaEn::getPPPackages(false);
foreach ($this->_list as &$item) {
$item['shipment_type'] = isset($types[$item['shipment_type']]) ? $types[$item['shipment_type']] : $item['shipment_type'];
}
}
}

View File

@@ -0,0 +1,29 @@
<?php
class PocztapolskaenAddpointModuleFrontController extends ModuleFrontController
{
/**
* metoda umożliwiajaca wyswietlenie widoku dla controllera
*/
public function displayContent()
{
parent::displayContent();
}
/**
* metoda umowliwiajaca wyswietlenie zadania ajax dla controllera,
* zapisuje wybrany przez klienta punkt odbioru przez klienta
*/
public function displayAjax()
{
$id_cart = Context::getContext()->cart->id;
$ppOrder = PPOrder::findByCart($id_cart);
$ppOrder->pni = Tools::getValue('pni');
$ppOrder->point = Tools::getValue('point');
$ppOrder->cod = Tools::getValue('cod');
$ppOrder->id_carrier = Context::getContext()->cart->id_carrier;
$ppOrder->save();
}
}