1011 lines
40 KiB
PHP
1011 lines
40 KiB
PHP
<?php
|
|
/**
|
|
* Module allow edit existing orders and set rules for automatically generating numbers for orders and other documents
|
|
*
|
|
* @author Keshva <keshvathakur47@gmail.com>
|
|
* @copyright 2021 Keshva
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
|
|
require_once(_PS_MODULE_DIR_.'modrefchange/classes/DocumentReferences.php');
|
|
|
|
class ModRefChange extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'modrefchange';
|
|
$this->tab = 'administration';
|
|
$this->version = '6.1.12';
|
|
$this->author = 'Keshva';
|
|
$this->module_key = '37801fb306a536cc9f00aea584c2dcfc';
|
|
$this->need_instance = 0;
|
|
$this->ps_versions_compliancy = array('min' => '1.6.0.4', 'max' => (version_compare(_PS_VERSION_, '1.6', '<') ? '1.6' : _PS_VERSION_ ));
|
|
$this->bootstrap = true;
|
|
parent::__construct();
|
|
$this->displayName = $this->l('Custom Order Reference Number , Invoice , delivery and credit slips number - Advanced');
|
|
$this->description = $this->l('Custom Order Reference Module allow edit existing orders and set rules for automatically generating numbers for orders and other documents');
|
|
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
|
|
|
|
if (!Configuration::get($this->name))
|
|
$this->warning = $this->l('No name provided');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
if (file_exists(_PS_ROOT_DIR_.'/cache/class_index.php'))
|
|
unlink(_PS_ROOT_DIR_.'/cache/class_index.php');
|
|
|
|
$referenceNumbersData = $this->initReferenceNumbersData();
|
|
$employeesData = $this->initEmployeesData();
|
|
$counterNumberData = $this->initCounterNumberData();
|
|
|
|
$tab = new Tab();
|
|
$tab->active = 1;
|
|
$tab->class_name = 'AdminEditOrder';
|
|
$tab->name = array();
|
|
foreach (Language::getLanguages(true) as $lang)
|
|
$tab->name[$lang['id_lang']] = 'EditOrder';
|
|
$tab->id_parent = -1;
|
|
$tab->module = $this->name;
|
|
|
|
return $tab->add()
|
|
&& parent::install()
|
|
&& $this->registerHook('displayBackOfficeHeader')
|
|
&& $this->registerHook('displayAdminOrderMain')
|
|
&& $this->registerHook('actionObjectOrderSlipAddAfter')
|
|
&& $this->registerHook('actionObjectOrderInvoiceAddAfter')
|
|
&& $this->registerHook('actionAdminControllerSetMedia')
|
|
&& Configuration::updateGlobalValue($this->name, json_encode($referenceNumbersData))
|
|
&& Configuration::updateGlobalValue('counterNumberData', json_encode($counterNumberData))
|
|
&& Configuration::updateGlobalValue('employeesData', json_encode($employeesData))
|
|
&& $this->modifyTables(true);
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
if (file_exists(_PS_ROOT_DIR_.'/cache/class_index.php'))
|
|
unlink(_PS_ROOT_DIR_.'/cache/class_index.php');
|
|
|
|
$id_tab = (int)Tab::getIdFromClassName('AdminEditOrder');
|
|
if ($id_tab) {
|
|
$tab = new Tab($id_tab);
|
|
$tab->delete();
|
|
}
|
|
return parent::uninstall()
|
|
&& $this->unregisterHook('displayBackOfficeHeader')
|
|
&& $this->unregisterHook('displayAdminOrderMain')
|
|
&& $this->unregisterHook('actionObjectOrderSlipAddAfter')
|
|
&& $this->unregisterHook('actionObjectOrderInvoiceAddAfter')
|
|
&& $this->unregisterHook('actionAdminControllerSetMedia')
|
|
&& Configuration::deleteByName($this->name)
|
|
&& Configuration::deleteByName('counterNumberData')
|
|
&& Configuration::deleteByName('employeesData')
|
|
&& $this->modifyTables(false);
|
|
}
|
|
|
|
public function modifyTables($isInstall) {
|
|
if ($isInstall) {
|
|
if (!Db::getInstance()->execute("CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."document_references` (
|
|
`id_document_reference` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
`id_document` int(10) unsigned NOT NULL,
|
|
`document_type` varchar(32) NOT NULL,
|
|
`reference` varchar(255) DEFAULT NULL,
|
|
PRIMARY KEY (`id_document_reference`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;") ||
|
|
!Db::getInstance()->execute("CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."order_note` (
|
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
`id_order` int(10) UNSIGNED NOT NULL,
|
|
`note` text,
|
|
`show_on_invoice` tinyint(1) NOT NULL DEFAULT '0',
|
|
`date_add` datetime NOT NULL,
|
|
`date_upd` datetime NOT NULL,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;"))
|
|
return false;
|
|
DocumentReferences::addMissingReferences();
|
|
return true;
|
|
}
|
|
else
|
|
return Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'document_references`') && Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'order_note`');
|
|
}
|
|
|
|
public function getContent() {
|
|
DocumentReferences::checkForCounterReset(0);
|
|
DocumentReferences::checkForCounterReset(1);
|
|
DocumentReferences::checkForCounterReset(2);
|
|
DocumentReferences::checkForCounterReset(3);
|
|
$getAllCounterData = json_decode(Configuration::getGlobalValue('counterNumberData'), true);
|
|
if (Tools::isSubmit('submitCustomReferenceNumber')) {
|
|
$settingsUpdated = '';
|
|
$settingsUpdated .= $this->displayConfirmation($this->l('Settings updated'));
|
|
$this->storeReferenceNumbers();
|
|
return $settingsUpdated . $this->displayList() . $this->getAssetsList() . $this->displayEmployees();
|
|
}
|
|
else if (Tools::isSubmit('update' . $this->name)) {
|
|
return ((int)Tools::getValue('id_reference_number') == 1 ? $this->displayWarning($this->l('Make sure your final reference number is no longer than 9 characters, because it is database limit for storing.')) : '').$this->displayForm() . $this->getAssetsForm() . $this->getHowToUse();
|
|
}
|
|
else if (Tools::isSubmit('status' . $this->name)) {
|
|
$settingsUpdated = '';
|
|
$settingsUpdated .= $this->displayConfirmation($this->l('Settings updated'));
|
|
$this->setReferenceNumberStatus();
|
|
return $settingsUpdated . $this->displayList() . $this->getAssetsList() . $this->displayEmployees();
|
|
}
|
|
else if (Tools::isSubmit('submitEmployees')) {
|
|
$settingsUpdated = '';
|
|
$settingsUpdated .= $this->displayConfirmation($this->l('Settings updated'));
|
|
$this->storeEmployees();
|
|
return $settingsUpdated . $this->displayList() . $this->getAssetsList() . $this->displayEmployees();
|
|
}
|
|
else
|
|
return $this->displayList() . $this->getAssetsList() . $this->displayEmployees();
|
|
}
|
|
|
|
protected function displayList()
|
|
{
|
|
$this->fields_list = array();
|
|
$this->fields_list['id_reference_number'] = array(
|
|
'title' => $this->l('#'),
|
|
'type' => 'hidden',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
);
|
|
$this->fields_list['reference_number_name'] = array(
|
|
'title' => $this->l('Reference number type'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false
|
|
);
|
|
|
|
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP)
|
|
$this->fields_list['reference_number_name'] = array(
|
|
'title' => $this->l('Reference number of'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false
|
|
);
|
|
|
|
$this->fields_list['reference_number_format'] = array(
|
|
'title' => $this->l('Reference number format'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false
|
|
);
|
|
$this->fields_list['activate_reference_number'] = array(
|
|
'title' => $this->l('Status'),
|
|
'active' => 'status',
|
|
'type' => 'bool',
|
|
'filter' => false,
|
|
'search' => false
|
|
);
|
|
|
|
|
|
$helper = new HelperList();
|
|
$helper->shopLinkType = '';
|
|
$helper->simple_header = false;
|
|
$helper->identifier = 'id_reference_number';
|
|
$helper->actions = array('edit');
|
|
$helper->show_toolbar = false;
|
|
$helper->title = $this->l('Set automatically generated reference numbers for orders, invoices, delivery slips and credit slips');
|
|
$helper->table = $this->name;
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
|
|
return $helper->generateList($this->getReferenceNumbersData(), $this->fields_list);
|
|
}
|
|
|
|
private function getReferenceNumbersData()
|
|
{
|
|
$referenceNumbersData = json_decode(Configuration::get($this->name), true);
|
|
if (!is_array($referenceNumbersData)) {
|
|
$referenceNumbersData = array();
|
|
}
|
|
$needsUpdate = false;
|
|
foreach ($this->initReferenceNumbersData() as $key => $defaultValue) {
|
|
if (!isset($referenceNumbersData[$key]) || !is_array($referenceNumbersData[$key])) {
|
|
$referenceNumbersData[$key] = $defaultValue;
|
|
$needsUpdate = true;
|
|
}
|
|
}
|
|
if ($needsUpdate) {
|
|
Configuration::updateValue($this->name, json_encode($referenceNumbersData));
|
|
}
|
|
return $referenceNumbersData;
|
|
}
|
|
|
|
public function displayForm()
|
|
{
|
|
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
$helper = new Helper();
|
|
$selectRandomLength = array(
|
|
array(
|
|
'id_option' => '1',
|
|
'name' => 1
|
|
),
|
|
array(
|
|
'id_option' => '2',
|
|
'name' => 2
|
|
),
|
|
array(
|
|
'id_option' => '3',
|
|
'name' => 3
|
|
),
|
|
array(
|
|
'id_option' => '4',
|
|
'name' => 4
|
|
),
|
|
array(
|
|
'id_option' => '5',
|
|
'name' => 5
|
|
),
|
|
array(
|
|
'id_option' => '6',
|
|
'name' => 6
|
|
),
|
|
array(
|
|
'id_option' => '7',
|
|
'name' => 7
|
|
),
|
|
array(
|
|
'id_option' => '8',
|
|
'name' => 8
|
|
),
|
|
array(
|
|
'id_option' => '9',
|
|
'name' => 9
|
|
),
|
|
);
|
|
$selectCounterLength = array(
|
|
array(
|
|
'id_option' => '2',
|
|
'name' => 2
|
|
),
|
|
array(
|
|
'id_option' => '3',
|
|
'name' => 3
|
|
),
|
|
array(
|
|
'id_option' => '4',
|
|
'name' => 4
|
|
),
|
|
array(
|
|
'id_option' => '5',
|
|
'name' => 5
|
|
),
|
|
array(
|
|
'id_option' => '6',
|
|
'name' => 6
|
|
),
|
|
array(
|
|
'id_option' => '7',
|
|
'name' => 7
|
|
),
|
|
array(
|
|
'id_option' => '8',
|
|
'name' => 8
|
|
),
|
|
array(
|
|
'id_option' => '9',
|
|
'name' => 9
|
|
)
|
|
);
|
|
$fields_form = array();
|
|
$fields_form[0]['form'] = array(
|
|
'legend' => array(
|
|
'title' => $this->l('Settings'),
|
|
),
|
|
'input' => array(
|
|
array(
|
|
'type'=>'radio',
|
|
'label' => $this->l('Activate this reference number:'),
|
|
'name' => 'activate_reference_number',
|
|
'required' => false,
|
|
'class' => 'activateReferenceNumber',
|
|
'is_bool' => true,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'activate_reference_number_on',
|
|
'value' => true,
|
|
'label' => $this->l('Active')
|
|
),
|
|
array(
|
|
'id' => 'activate_reference_number_off',
|
|
'value' => false,
|
|
'label' => $this->l('Inactive')
|
|
)
|
|
),
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Reference number format'),
|
|
'name' => 'reference_number_format',
|
|
'class' => 'referenceNumberFormat',
|
|
'required' => false,
|
|
'desc' => $this->l('Enter the format of the reference number (e.g. : INV-{COUNTER}/{WEEK}). All available tags are display in "DESCRIPTION OF THE AVAILABLE TAGS" table.')
|
|
),
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Random number length:'),
|
|
'desc' => $this->l('Length of random number reference'),
|
|
'name' => 'random_number_length',
|
|
'required' => false,
|
|
'options' => array(
|
|
'query' => $selectRandomLength,
|
|
'id' => 'id_option',
|
|
'name' => 'name'
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Random alphabetic length:'),
|
|
'desc' => $this->l('Length of random alphabetic reference'),
|
|
'name' => 'random_alphabetic_length',
|
|
'required' => false,
|
|
'options' => array(
|
|
'query' => $selectRandomLength,
|
|
'id' => 'id_option',
|
|
'name' => 'name'
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Random alphanumeric length:'),
|
|
'desc' => $this->l('Length of random alphanumeric reference'),
|
|
'name' => 'random_alphanumeric_length',
|
|
'required' => false,
|
|
'options' => array(
|
|
'query' => $selectRandomLength,
|
|
'id' => 'id_option',
|
|
'name' => 'name'
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Counter number start at:'),
|
|
'desc' => $this->l('Starting value of counter reference. Each time you set this value to another, counter will be reset to retype value.'),
|
|
'class' => 'counterStartAt',
|
|
'name' => 'counter_start_at',
|
|
'required' => false
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Counter step by:'),
|
|
'desc' => $this->l('This field represent counter value rising. For example if you starting value is 10 and step by value is 5, the counter will generate this reference: 10, 15, 20, 25, ...'),
|
|
'class' => 'CounterIncrementBy',
|
|
'name' => 'counter_increment_by',
|
|
'required' => false
|
|
),
|
|
array(
|
|
'type'=>'radio',
|
|
'label' => $this->l('Intervals of reseting counter:'),
|
|
'desc' => $this->l('You can set how often will reset your counter automatically. Everytime after reset, counter value will set to number from "Counter number start at" field. If you choose 3rd or 4th option (reached selected number or reach selected date), system will automatically display field for entering the number or entering the date.'),
|
|
'name' => 'counter_reset_interval',
|
|
'required' => false,
|
|
'class' => 'ResetCounterInterval',
|
|
'values' => array(
|
|
array(
|
|
'id' => 'counter_reset_interval_week',
|
|
'value' => 0,
|
|
'label' => $this->l('Each week')
|
|
),
|
|
array(
|
|
'id' => 'counter_reset_interval_month',
|
|
'value' => 1,
|
|
'label' => $this->l('Each month')
|
|
),
|
|
array(
|
|
'id' => 'counter_reset_interval_year',
|
|
'value' => 2,
|
|
'label' => $this->l('Each year')
|
|
),
|
|
array(
|
|
'id' => 'counter_reset_interval_number',
|
|
'value' => 3,
|
|
'label' => $this->l('If counter value will reach selected number')
|
|
),
|
|
array(
|
|
'id' => 'counter_reset_interval_date',
|
|
'value' => 4,
|
|
'label' => $this->l('If date will reach selected date')
|
|
),
|
|
array(
|
|
'id' => 'counter_reset_interval_never',
|
|
'value' => 5,
|
|
'label' => $this->l('Never')
|
|
)
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Reset counter if value will reach number:'),
|
|
'desc' => $this->l('If counter will reach bigger number as you set in this field, counter value will automatically reset to value from "Counter number start at" field.'),
|
|
'class' => 'CounterResetNumber',
|
|
'name' => 'counter_reset_number',
|
|
'required' => false
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Reset counter if date will reach date:'),
|
|
'desc' => $this->l('If current date will reach this date, or later date as you set in this field, counter value will automatically reset to value from "Counter number start at" field. Format of date is "YYYY-MM-DD" (YEAR-MONTH-DAY).'),
|
|
'class' => 'CounterResetDate',
|
|
'name' => 'counter_reset_date',
|
|
'required' => false
|
|
),
|
|
array(
|
|
'type'=>'radio',
|
|
'label' => $this->l('Reset counter now:'),
|
|
'desc' => $this->l('You can reset actual counter value to value, which is set in "Counter number start at" field.'),
|
|
'name' => 'counter_reset_now',
|
|
'required' => false,
|
|
'class' => 'CounterResetNow',
|
|
'is_bool' => true,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'counter_reset_now_on',
|
|
'value' => 1,
|
|
'label' => $this->l('Yes')
|
|
),
|
|
array(
|
|
'id' => 'counter_reset_now_off',
|
|
'value' => 0,
|
|
'label' => $this->l('No')
|
|
)
|
|
)
|
|
),
|
|
array(
|
|
'type'=>'radio',
|
|
'label' => $this->l('Set counter reference length:'),
|
|
'desc' => $this->l('If you want to get static length of counter value you can set counter reference length. If you set this field to "active", system will display options to set counter reference length. For example if you set this value to "5" and your current counter value will be "10", final counter value will look like this: 00010. For current counter value = "100", it will be 00100. For current counter value = "1000", it will be 01000. After save, you can see live preview on the top in "next counter value" info field.'),
|
|
'name' => 'counter_reference_length_in_use',
|
|
'required' => false,
|
|
'class' => 'CounterReferenceLength',
|
|
'is_bool' => true,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'counter_reference_length_in_use_on',
|
|
'value' => 1,
|
|
'label' => $this->l('Active')
|
|
),
|
|
array(
|
|
'id' => 'counter_reference_length_in_use_off',
|
|
'value' => 0,
|
|
'label' => $this->l('Inactive')
|
|
)
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Counter length:'),
|
|
'desc' => $this->l('You can set length of final counter reference. If counter value length will be shorter as counter length, system automatically add zeros as prefix of counter value.'),
|
|
'name' => 'counter_reference_length',
|
|
'required' => false,
|
|
'options' => array(
|
|
'query' => $selectCounterLength,
|
|
'id' => 'id_option',
|
|
'name' => 'name'
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'hidden',
|
|
'class' => 'counterActualValue',
|
|
'name' => 'counter_actual_value',
|
|
'required' => false
|
|
),
|
|
array(
|
|
'type' => 'hidden',
|
|
'class' => 'idReferenceNumber',
|
|
'name' => 'id_reference_number',
|
|
'required' => true
|
|
),
|
|
),
|
|
'submit' => array(
|
|
'title' => $this->l('Save'),
|
|
'name' => 'submitCustomReferenceNumber',
|
|
)
|
|
);
|
|
$id_reference_number = (int)Tools::getValue('id_reference_number');
|
|
$referenceNumbersData = $this->getReferenceNumbersData();
|
|
$getAllCounterData = json_decode(Configuration::getGlobalValue('counterNumberData'), true);
|
|
$helper = new HelperForm();
|
|
$helper->module = $this;
|
|
$helper->name_controller = $this->name;
|
|
$helper->identifier = $this->identifier;
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
|
|
$helper->default_form_language = $default_lang;
|
|
$helper->allow_employee_form_lang = $default_lang;
|
|
$helper->title = $this->displayName;
|
|
$helper->show_toolbar = false;
|
|
$helper->toolbar_scroll = false;
|
|
$helper->submit_action = 'submit'.$this->name;
|
|
$helper->tpl_vars = array(
|
|
'fields_value' => array_merge($referenceNumbersData[$id_reference_number - 1], $getAllCounterData[$id_reference_number - 1]),
|
|
'languages' => $this->context->controller->getLanguages(),
|
|
'id_language' => $this->context->language->id
|
|
);
|
|
return $helper->generateForm($fields_form);
|
|
}
|
|
|
|
private function displayEmployees() {
|
|
$fields_form = array();
|
|
$fields_form[0]['form'] = array(
|
|
'legend' => array(
|
|
'title' => $this->l('All Superadmins can edit existing order'),
|
|
),
|
|
'input' => array(),
|
|
'submit' => array(
|
|
'title' => $this->l('Save'),
|
|
'name' => 'submitEmployees',
|
|
)
|
|
);
|
|
$employees = $this->getEmployeesWithEmails();
|
|
if (count($employees) > 0) {
|
|
foreach ($employees as $key => $value) {
|
|
array_push($fields_form[0]['form']['input'], array(
|
|
'type' =>'checkbox',
|
|
'label' => '',
|
|
'name' => 'employee_'.$value['id_employee'],
|
|
'required' => false,
|
|
'class' => 'employees',
|
|
'values' => array(
|
|
'query' => array(
|
|
array(
|
|
'id_option' => '1',
|
|
'name' => $value['firstname']." ".$value['lastname'].' ('.$value['email'].')'
|
|
)
|
|
),
|
|
'id' => 'id_option',
|
|
'name' => 'name'
|
|
),
|
|
));
|
|
}
|
|
}
|
|
$helper = new HelperForm();
|
|
$helper->module = $this;
|
|
$helper->name_controller = $this->name;
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
|
|
$helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
$helper->allow_employee_form_lang = true;
|
|
$helper->title = $this->displayName;
|
|
$helper->show_toolbar = false;
|
|
$helper->toolbar_scroll = false;
|
|
$helper->submit_action = 'submit'.$this->name;
|
|
$helper->tpl_vars = array(
|
|
'fields_value' => json_decode(Configuration::get('employeesData'), true),
|
|
'languages' => $this->context->controller->getLanguages(),
|
|
'id_language' => $this->context->language->id
|
|
);
|
|
|
|
return $helper->generateForm($fields_form);
|
|
}
|
|
|
|
public function hookDisplayBackOfficeHeader($params)
|
|
{
|
|
if ($this->context->controller instanceof AdminOrdersController) {
|
|
if (!Tools::getValue('ajax') && (int)Tools::getValue('id_order') > 0) {
|
|
DocumentReferences::addMissingReferences((int)Tools::getValue('id_order'));
|
|
$order = new Order((int)Tools::getValue('id_order'));
|
|
$invoice_collection = $order->getInvoicesCollection();
|
|
$invoices = array();
|
|
foreach ($invoice_collection as $invoice) {
|
|
$invoice->name = $invoice->getInvoiceNumberFormatted(Context::getContext()->language->id, (int)$order->id_shop);
|
|
$invoices[] = $invoice;
|
|
}
|
|
|
|
$iso = $this->context->language->iso_code;
|
|
$this->smarty->assign(
|
|
array(
|
|
'editOrderAjaxLink' => $this->context->link->getAdminLink('AdminEditOrder'),
|
|
'adminThemeDir' => _PS_BO_ALL_THEMES_DIR_,
|
|
'documents' => json_encode(DocumentReferences::getAllDocuments()),
|
|
'invoices' => json_encode($invoices),
|
|
'carriers' => json_encode(Carrier::getCarriers($this->context->language->id, true, false, false, null, Carrier::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE)),
|
|
'shipping' => '{"values" : '.json_encode($order->getShipping()).', "tax" : '.$order->carrier_tax_rate.'}',
|
|
'hasBeenDelivered' => $order->hasBeenDelivered(),
|
|
'orderNote' => json_encode($this->getOrderNote($order->id)),
|
|
'psVersionLess1607' => (version_compare(_PS_VERSION_, '1.6.0.7', '<') ? 1 : 0),
|
|
'psVersion17' => (version_compare(_PS_VERSION_, '1.7', '>') ? 1 : 0),
|
|
'trans' => json_encode($this->orderEditTrans()),
|
|
'iso' => file_exists(_PS_CORE_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en',
|
|
'path_css' => _THEME_CSS_DIR_,
|
|
'ad' => __PS_BASE_URI__.basename(_PS_ADMIN_DIR_),
|
|
'idOrder' => (int)Tools::getValue('id_order')
|
|
)
|
|
);
|
|
return $this->display(__FILE__, 'hookDisplayBackOfficeHeader.tpl');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hookDisplayAdminOrderMain($params) {
|
|
if (!Tools::getValue('ajax') && version_compare(_PS_VERSION_, '1.7.7', '>=')) {
|
|
DocumentReferences::addMissingReferences((int)Tools::getValue('id_order'));
|
|
$order = new Order((int)Tools::getValue('id_order'));
|
|
$invoice_collection = $order->getInvoicesCollection();
|
|
$invoices = array();
|
|
foreach ($invoice_collection as $invoice) {
|
|
$invoice->name = $invoice->getInvoiceNumberFormatted(Context::getContext()->language->id, (int)$order->id_shop);
|
|
$invoices[] = $invoice;
|
|
}
|
|
|
|
$iso = $this->context->language->iso_code;
|
|
$this->smarty->assign(
|
|
array(
|
|
'editOrderAjaxLink' => $this->context->link->getAdminLink('AdminEditOrder'),
|
|
'adminThemeDir' => _PS_BO_ALL_THEMES_DIR_,
|
|
'documents' => json_encode(DocumentReferences::getAllDocuments()),
|
|
'invoices' => json_encode($invoices),
|
|
'carriers' => json_encode(Carrier::getCarriers($this->context->language->id, true, false, false, null, Carrier::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE)),
|
|
'shipping' => '{"values" : '.json_encode($order->getShipping()).', "tax" : '.$order->carrier_tax_rate.'}',
|
|
'hasBeenDelivered' => $order->hasBeenDelivered(),
|
|
'orderNote' => json_encode($this->getOrderNote($order->id)),
|
|
'psVersionLess1607' => (version_compare(_PS_VERSION_, '1.6.0.7', '<') ? 1 : 0),
|
|
'psVersion17' => (version_compare(_PS_VERSION_, '1.7', '>') ? 1 : 0),
|
|
'trans' => json_encode($this->orderEditTrans()),
|
|
'iso' => file_exists(_PS_CORE_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en',
|
|
'path_css' => _THEME_CSS_DIR_,
|
|
'ad' => __PS_BASE_URI__.basename(_PS_ADMIN_DIR_),
|
|
'idOrder' => (int)$params['id_order']
|
|
)
|
|
);
|
|
return $this->display(__FILE__, 'hookDisplayBackOfficeHeader.tpl');
|
|
}
|
|
}
|
|
|
|
public function hookActionAdminControllerSetMedia()
|
|
{
|
|
if ($this->context->controller instanceof AdminOrdersController) {
|
|
if (!Tools::getValue('ajax') && (int)Tools::getValue('id_order') > 0) {
|
|
$this->context->controller->addCSS($this->_path.'/views/css/orderDetail.css');
|
|
if (!$this->employeeHasAccess($this->context->employee->id)) {
|
|
$this->context->controller->addCSS($this->_path.'/views/css/orderDetailNoPermission.css');
|
|
}
|
|
$this->context->controller->addJS(_PS_JS_DIR_.'tiny_mce/tiny_mce.js');
|
|
$this->context->controller->addJS(_PS_JS_DIR_.(version_compare(_PS_VERSION_, '1.6.0.11', '>') ? 'admin/' : '').'tinymce.inc.js');
|
|
$this->context->controller->addJS($this->_path.'views/js/orderDetail.js');
|
|
}
|
|
} else if (version_compare(_PS_VERSION_, '1.7.7', '>=') && Tools::getValue('controller') == 'AdminOrders' && !Tools::getValue('ajax')) {
|
|
$this->context->controller->addCSS($this->_path.'/views/css/orderDetail177X.css');
|
|
if (!$this->employeeHasAccess($this->context->employee->id)) {
|
|
$this->context->controller->addCSS($this->_path.'/views/css/orderDetailNoPermission.css');
|
|
}
|
|
$this->context->controller->addJS(_PS_JS_DIR_.'tiny_mce/tiny_mce.js');
|
|
$this->context->controller->addJS(_PS_JS_DIR_.(version_compare(_PS_VERSION_, '1.6.0.11', '>') ? 'admin/' : '').'tinymce.inc.js');
|
|
//$this->context->controller->addJquery();
|
|
$this->context->controller->addJqueryUI([
|
|
'ui.core',
|
|
'ui.widget',
|
|
]);
|
|
|
|
$this->context->controller->addJS([
|
|
_PS_JS_DIR_ . 'jquery/plugins/timepicker/jquery-ui-timepicker-addon.js',
|
|
]);
|
|
$this->context->controller->addJs($this->_path.'views/js/orderDetailGET177X.js');
|
|
$this->context->controller->addCSS([
|
|
_PS_JS_DIR_ . 'jquery/plugins/timepicker/jquery-ui-timepicker-addon.css',
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function hookActionObjectOrderSlipAddAfter($params)
|
|
{
|
|
// generovanie cisla credit slip
|
|
DocumentReferences::storeReference('credit_slip', $params['object']->id_order, $params['object']->id);
|
|
}
|
|
|
|
public function hookActionObjectOrderInvoiceAddAfter($params)
|
|
{
|
|
// pokial sa pridava na objednavku viac ako jedna faktura tak sa generuje cislo faktury z tadeto
|
|
// tato situacia sa moze stat ked sa pridava novy produkt do objednavky a vybere sa ze ho treba dat na novu fakturu
|
|
// prva faktura sa vzdy genereuje cez pretazenu metodu Order->setInvoice()
|
|
if (DocumentReferences::orderInvoiceRecordsCountByOrderID($params['object']->id_order) > 1) {
|
|
DocumentReferences::storeReference('invoice', $params['object']->id_order, $params['object']->id);
|
|
}
|
|
}
|
|
|
|
private function storeReferenceNumbers()
|
|
{
|
|
$customReferenceNumbersArray = array();
|
|
$counterNumbersArray = array();
|
|
$id_reference_number = (int)Tools::getValue('id_reference_number');
|
|
$getAllReferenceNumberData = $this->getReferenceNumbersData();
|
|
$getAllCounterData = json_decode(Configuration::getGlobalValue('counterNumberData'), true);
|
|
$currentCustomOrderReferenceArray = $getAllReferenceNumberData[$id_reference_number - 1];
|
|
$currentCounterData = $getAllCounterData[$id_reference_number - 1];
|
|
$customReferenceNumbersArray['id_reference_number'] = $currentCustomOrderReferenceArray['id_reference_number'];
|
|
$customReferenceNumbersArray['activate_reference_number'] = Tools::getValue('activate_reference_number');
|
|
$customReferenceNumbersArray['reference_number_name'] = $currentCustomOrderReferenceArray['reference_number_name'];
|
|
$customReferenceNumbersArray['reference_number_format'] = Tools::getValue('reference_number_format');
|
|
$customReferenceNumbersArray['random_number_length'] = (int)Tools::getValue('random_number_length');
|
|
$customReferenceNumbersArray['random_alphabetic_length'] = (int)Tools::getValue('random_alphabetic_length');
|
|
$customReferenceNumbersArray['random_alphanumeric_length'] = (int)Tools::getValue('random_alphanumeric_length');
|
|
if ((int)Tools::getValue('counter_reset_now') || (int)Tools::getValue('counter_start_at') != $currentCounterData['counter_start_at'])
|
|
$counterNumbersArray['counter_actual_value'] = (int)Tools::getValue('counter_start_at');
|
|
else
|
|
$counterNumbersArray['counter_actual_value'] = (int)$currentCounterData['counter_actual_value'];
|
|
$counterNumbersArray['counter_reset_now'] = '0';
|
|
$counterNumbersArray['counter_start_at'] = (int)Tools::getValue('counter_start_at');
|
|
$counterNumbersArray['counter_increment_by'] = (int)Tools::getValue('counter_increment_by');
|
|
$counterNumbersArray['counter_reset_interval'] = (int)Tools::getValue('counter_reset_interval');
|
|
$counterNumbersArray['counter_reset_number'] = (int)Tools::getValue('counter_reset_number');
|
|
$counterNumbersArray['counter_reset_date'] = Tools::getValue('counter_reset_date');
|
|
$counterNumbersArray['counter_reference_length_in_use'] = (int)Tools::getValue('counter_reference_length_in_use');
|
|
$counterNumbersArray['counter_reference_length'] = (int)Tools::getValue('counter_reference_length');
|
|
$counterNumbersArray['counter_last_set_date'] = $currentCounterData['counter_last_set_date'];
|
|
$getAllReferenceNumberData[$id_reference_number - 1] = $customReferenceNumbersArray;
|
|
$getAllCounterData[$id_reference_number - 1] = $counterNumbersArray;
|
|
Configuration::updateValue($this->name, json_encode($getAllReferenceNumberData));
|
|
Configuration::updateGlobalValue('counterNumberData', json_encode($getAllCounterData));
|
|
}
|
|
|
|
private function storeEmployees()
|
|
{
|
|
$employees = Employee::getEmployees();
|
|
$employeesArray = array();
|
|
if (count($employees) > 0)
|
|
{
|
|
foreach ($employees as $key => $value)
|
|
{
|
|
$employee = new Employee($value['id_employee']);
|
|
if(!$employee->isSuperAdmin())
|
|
$employeesArray['employee_'.$value['id_employee'].'_1'] = Tools::getValue('employee_'.$value['id_employee'].'_1');
|
|
}
|
|
}
|
|
Configuration::updateValue('employeesData', json_encode($employeesArray));
|
|
}
|
|
|
|
private function setReferenceNumberStatus()
|
|
{
|
|
$id_reference_number = (int)Tools::getValue('id_reference_number');
|
|
$getAllReferenceNumberData = $this->getReferenceNumbersData();
|
|
if ($getAllReferenceNumberData[$id_reference_number - 1]['activate_reference_number'])
|
|
$getAllReferenceNumberData[$id_reference_number - 1]['activate_reference_number'] = false;
|
|
else
|
|
$getAllReferenceNumberData[$id_reference_number - 1]['activate_reference_number'] = true;
|
|
Configuration::updateValue($this->name, json_encode($getAllReferenceNumberData));
|
|
}
|
|
|
|
private function getAssetsForm()
|
|
{
|
|
$id_reference_number = (int)Tools::getValue('id_reference_number');
|
|
$getAllCounterData = json_decode(Configuration::getGlobalValue('counterNumberData'), true);
|
|
$currentCounterData = $getAllCounterData[$id_reference_number - 1];
|
|
$this->smarty->assign(
|
|
array(
|
|
'counterActualValue' => (int)$currentCounterData['counter_actual_value'],
|
|
'translate' => json_encode($this->orderEditTrans()),
|
|
'psLT1606' => version_compare(_PS_VERSION_, '1.6.0.6', '<'),
|
|
'modulePath' => $this->_path
|
|
)
|
|
);
|
|
return $this->display(__FILE__, 'assetsForm.tpl');
|
|
|
|
}
|
|
|
|
private function getAssetsList()
|
|
{
|
|
$this->smarty->assign(
|
|
array(
|
|
'translate' => json_encode($this->orderEditTrans()),
|
|
'modulePath' => $this->_path
|
|
)
|
|
);
|
|
return $this->display(__FILE__, 'assetsList.tpl');
|
|
}
|
|
|
|
private function getHowToUse()
|
|
{
|
|
$this->smarty->assign(
|
|
array(
|
|
'translate' => $this->orderEditTrans(),
|
|
)
|
|
);
|
|
return $this->display(__FILE__, 'howToUse.tpl');
|
|
}
|
|
|
|
private function initReferenceNumbersData()
|
|
{
|
|
$referenceNumbersData = array();
|
|
$referenceNumbersData[0] = array(
|
|
'id_reference_number' => 1,
|
|
'activate_reference_number' => true,
|
|
'reference_number_name' => 'Orders',
|
|
'reference_number_format' => 'ORD-{RANDOM_ALPHABETIC}',
|
|
'random_number_length' => '5',
|
|
'random_alphabetic_length' => '5',
|
|
'random_alphanumeric_length' => '5'
|
|
);
|
|
$referenceNumbersData[1] = array(
|
|
'id_reference_number' => 2,
|
|
'activate_reference_number' => true,
|
|
'reference_number_name' => 'Invoices',
|
|
'reference_number_format' => 'INV-{RANDOM_ALPHABETIC}',
|
|
'random_number_length' => '9',
|
|
'random_alphabetic_length' => '6',
|
|
'random_alphanumeric_length' => '6'
|
|
);
|
|
$referenceNumbersData[2] = array(
|
|
'id_reference_number' => 3,
|
|
'activate_reference_number' => true,
|
|
'reference_number_name' => 'Delivery slips',
|
|
'reference_number_format' => 'DEL-{RANDOM_ALPHABETIC}',
|
|
'random_number_length' => '9',
|
|
'random_alphabetic_length' => '6',
|
|
'random_alphanumeric_length' => '6'
|
|
);
|
|
$referenceNumbersData[3] = array(
|
|
'id_reference_number' => 4,
|
|
'activate_reference_number' => true,
|
|
'reference_number_name' => 'Credit slips',
|
|
'reference_number_format' => 'SLIP-{RANDOM_ALPHABETIC}',
|
|
'random_number_length' => '9',
|
|
'random_alphabetic_length' => '6',
|
|
'random_alphanumeric_length' => '6'
|
|
);
|
|
return $referenceNumbersData;
|
|
}
|
|
|
|
private function initCounterNumberData()
|
|
{
|
|
$counterNumberData = array();
|
|
$counterNumberData[0] = array(
|
|
'counter_start_at' => '',
|
|
'counter_increment_by' => '',
|
|
'counter_actual_value' => '',
|
|
'counter_reset_interval' => '5',
|
|
'counter_reset_number' => '',
|
|
'counter_reset_date' => '',
|
|
'counter_reset_now' => '0',
|
|
'counter_reference_length_in_use' => '0',
|
|
'counter_reference_length' => '4',
|
|
'counter_last_set_date' => date("Y-m-d")
|
|
);
|
|
$counterNumberData[1] = array(
|
|
'counter_start_at' => '',
|
|
'counter_increment_by' => '',
|
|
'counter_actual_value' => '',
|
|
'counter_reset_interval' => '5',
|
|
'counter_reset_number' => '',
|
|
'counter_reset_date' => '',
|
|
'counter_reset_now' => '0',
|
|
'counter_reference_length_in_use' => '0',
|
|
'counter_reference_length' => '4',
|
|
'counter_last_set_date' => date("Y-m-d")
|
|
);
|
|
$counterNumberData[2] = array(
|
|
'counter_start_at' => '',
|
|
'counter_increment_by' => '',
|
|
'counter_actual_value' => '',
|
|
'counter_reset_interval' => '5',
|
|
'counter_reset_number' => '',
|
|
'counter_reset_date' => '',
|
|
'counter_reset_now' => '0',
|
|
'counter_reference_length_in_use' => '0',
|
|
'counter_reference_length' => '4',
|
|
'counter_last_set_date' => date("Y-m-d")
|
|
);
|
|
$counterNumberData[3] = array(
|
|
'counter_start_at' => '',
|
|
'counter_increment_by' => '',
|
|
'counter_actual_value' => '',
|
|
'counter_reset_interval' => '5',
|
|
'counter_reset_number' => '',
|
|
'counter_reset_date' => '',
|
|
'counter_reset_now' => '0',
|
|
'counter_reference_length_in_use' => '0',
|
|
'counter_reference_length' => '4',
|
|
'counter_last_set_date' => date("Y-m-d")
|
|
);
|
|
return $counterNumberData;
|
|
}
|
|
|
|
private function initEmployeesData()
|
|
{
|
|
$employeesData = array();
|
|
$employees = Employee::getEmployees();
|
|
if (count($employees) > 0) {
|
|
foreach ($employees as $key => $value) {
|
|
$employee = new Employee($value['id_employee']);
|
|
if(!$employee->isSuperAdmin()) {
|
|
$employeesData['employee_'.$value['id_employee'].'_1'] = 'on';
|
|
}
|
|
}
|
|
}
|
|
return $employeesData;
|
|
}
|
|
|
|
private function getOrderNote($idOrder) {
|
|
$orderNote = array(
|
|
'note' => '',
|
|
'show_on_invoice' => 0
|
|
);
|
|
if ($row = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'order_note WHERE id_order = '.(int)$idOrder)) {
|
|
$orderNote = array(
|
|
'note' => $row['note'],
|
|
'show_on_invoice' => $row['show_on_invoice']
|
|
);
|
|
}
|
|
return $orderNote;
|
|
}
|
|
|
|
private function getEmployeesWithEmails()
|
|
{
|
|
return Db::getInstance()->executeS('
|
|
SELECT `id_employee`, `firstname`, `lastname`, `email`
|
|
FROM `'._DB_PREFIX_.'employee`
|
|
WHERE `active` = 1 AND `id_profile` <> '.(int)_PS_ADMIN_PROFILE_.'
|
|
ORDER BY `lastname` ASC
|
|
');
|
|
}
|
|
|
|
private function employeeHasAccess($employeeId)
|
|
{
|
|
$editOrderProData = json_decode(Configuration::get('employeesData'), true);
|
|
$employees = Employee::getEmployees();
|
|
if (count($employees) > 0)
|
|
foreach ($employees as $key => $value)
|
|
{
|
|
$employee = new Employee((int)$value['id_employee']);
|
|
if((int)$value['id_employee'] == (int)$employeeId) {
|
|
if ($employee->isSuperAdmin()) {
|
|
return true;
|
|
}
|
|
if (array_key_exists('employee_'.$value['id_employee'].'_1', $editOrderProData)) {
|
|
if ($editOrderProData['employee_'.$value['id_employee'].'_1'] == 'on') {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private function orderEditTrans()
|
|
{
|
|
$trans = array();
|
|
$trans['cancel'] = $this->l('Cancel');
|
|
$trans['update'] = $this->l('Update');
|
|
$trans['remove'] = $this->l('Delete');
|
|
$trans['edit'] = $this->l('Edit');
|
|
$trans['add_product'] = $this->l('Add a product');
|
|
$trans['resend_email'] = $this->l('Resend email');
|
|
$trans['can_not_be_stored'] = $this->l('Can not be stored, maybe login session expired');
|
|
$trans['order_status_removed'] = $this->l('Order status can not be removed');
|
|
$trans['payment_removed'] = $this->l('Payment can not be removed');
|
|
$trans['document_removed'] = $this->l('Document can not be removed');
|
|
$trans['mail_can_not_be_send'] = $this->l('Mail can not be send');
|
|
$trans['tax_excl_price'] = $this->l('Tax Excl price');
|
|
$trans['tax_incl_price'] = $this->l('Tax Incl price');
|
|
$trans['tax'] = $this->l('Tax');
|
|
$trans['tax_excl'] = $this->l('Tax excl');
|
|
$trans['tax_incl'] = $this->l('Tax incl');
|
|
$trans['missing_employees'] = $this->l('You have to add one or more employees with no superadmin profile, to work with this section');
|
|
$trans['config_title'] = $this->l('Allow edit existing order functionality of this module also for these employees');
|
|
$trans['numberReferenceFormatError'] = $this->l('Counter number start at field or Counter step by field can not be empty and have to be a positive number');
|
|
$trans['counterResetNumberError'] = $this->l('Reached number can not be empty and have to be a positive number');
|
|
$trans['counterResetDateError'] = $this->l('Reached date can not be empty and date have to start from tomorrow');
|
|
$trans['numberReferenceFormatEmptyError'] = $this->l('Reference number format field can not be empty');
|
|
$trans['descOfAvailableTags'] = $this->l('DESCRIPTION OF THE AVAILABLE TAGS');
|
|
$trans['tagDescription'] = $this->l('Tag description');
|
|
$trans['tagRandomNumber'] = $this->l('This tag generate random number. If you use this tag, system automaticaly display field "Random number length" to select length of random number.');
|
|
$trans['tagAlphabeticRef'] = $this->l('This tag generate alphabetic reference. If you use this tag, system automaticaly display field "Random alphabetic length" to select length of random alphabetic reference.');
|
|
$trans['tagAlphanumericRef'] = $this->l('This tag generate alphanumeric (numbers and alphabetical characters together) reference. If you use this tag, system automaticaly display field "Random alphanumeric length" to select length of random alphanumeric reference.');
|
|
$trans['tagCounterValue'] = $this->l('This tag generated automatically counted values. You can choose starting value of counter and a step, which represent counter value rising. You can reset counter every time you want when you set "Counter number start at" field to another value.');
|
|
$trans['tagOrderID'] = $this->l('This tag generate order ID number.');
|
|
$trans['tagShopID'] = $this->l('This tag generate shop ID number.');
|
|
$trans['tagYearNumber'] = $this->l('This tag generate actual year number.');
|
|
$trans['tagYearNumberShort'] = $this->l('This tag generate shortcut of actual year, for example 15,16,17.');
|
|
$trans['tagMonthNumber'] = $this->l('This tag generate actual month number.');
|
|
$trans['tagWeekNumber'] = $this->l('This tag generate actual week number.');
|
|
$trans['tagDayInWeekNumber'] = $this->l('This tag generate actual day in week number.');
|
|
$trans['tagDayInMonthNumber'] = $this->l('This tag generate actual day in month number.');
|
|
$trans['orderNoteTitle'] = $this->l('Order Note');
|
|
$trans['orderNoteInInvoice'] = $this->l('Show this order note on invoice');
|
|
$trans['orderNoteStored'] = $this->l('Order note stored');
|
|
$trans['orderNoteNotStored'] = $this->l('Order note can not be stored');
|
|
$trans['save'] = $this->l('Save');
|
|
return $trans;
|
|
}
|
|
} |