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') . '
' . 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' => ' ' . $this->l('Spakuj') . ''
),
'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' => '