217 lines
7.6 KiB
PHP
217 lines
7.6 KiB
PHP
<?php
|
||
/*
|
||
* 2012 Firmes
|
||
* Mechanizmy obs<62>ugi rozszerzenia FirmesLink B2B
|
||
* Obsluga wyswietlania historii dokumentow
|
||
*/
|
||
|
||
if (!defined('_CAN_LOAD_FILES_'))
|
||
exit;
|
||
|
||
class FirmesB2B extends Module
|
||
{
|
||
public $page_number = 0;
|
||
public $results_on_page = 25;
|
||
|
||
public function __construct()
|
||
{
|
||
$this->name = 'firmesb2b';
|
||
$this->tab = 'front_office_features';
|
||
$this->version = 1.4;
|
||
$this->author = 'Firmes';
|
||
$this->need_instance = 0;
|
||
|
||
parent::__construct();
|
||
|
||
$this->displayName = $this->l('FirmesB2B');
|
||
$this->description = $this->l('Rozszerzenie B2B programu FirmesLink');
|
||
}
|
||
|
||
public function install()
|
||
{
|
||
if (!parent::install()
|
||
|| !$this->registerHook('displayMyAccountBlock')
|
||
|| !$this->registerHook('displayCustomerAccount')
|
||
|| !$this->registerHook('displayMyAccountBlockfooter')
|
||
|| !$this->registerHook('displayHeader')
|
||
|| !$this->registerHook('displayLeftColumn')
|
||
|| !$this->registerHook('displayAdminCustomers')
|
||
|| !$this->registerHook('displayRightColumn')
|
||
)
|
||
return false;
|
||
|
||
return true;
|
||
}
|
||
|
||
public function uninstall()
|
||
{
|
||
if (!parent::uninstall())
|
||
return false;
|
||
return true;
|
||
}
|
||
|
||
public function hookDisplayAdminCustomers($params)
|
||
{
|
||
$page_number = 0;
|
||
$results_on_page = 25; // limit dokumentow na strone
|
||
$start = $page_number * $results_on_page;
|
||
|
||
$customerInfo = $this->getCustomerInfo();
|
||
if ($customerInfo['customerId'] > 0) {
|
||
|
||
if (file_exists(_PS_ROOT_DIR_ . '/modules/firmesb2b/B2BDocument.php')) {
|
||
require_once(_PS_ROOT_DIR_ . '/modules/firmesb2b/B2BDocument.php');
|
||
}
|
||
$this->smarty->assign('customerInfo', $customerInfo);
|
||
$this->smarty->assign('in_footer', false);
|
||
$this->smarty->assign('customer_is_related', true);
|
||
// $ps_version_int = str_replace(".","",_PS_VERSION_);
|
||
// $this->smarty->assign('_PS_VERSION_', $ps_version_int);
|
||
|
||
|
||
$result = B2BDocument::getCustomerDocumentsCount((int)$customerInfo['customerId'],$results_on_page ,$start);
|
||
$documentCount = (int)$result['count'];
|
||
|
||
$B2Bdocuments = array();
|
||
|
||
if ($documentCount > 0) {
|
||
$B2Bdocuments = B2BDocument::getCustomerDocuments((int)$customerInfo['customerId']);
|
||
}
|
||
|
||
$this->smarty->assign(array(
|
||
'B2Bdocuments' => $B2Bdocuments,
|
||
'documentCount' => $documentCount,
|
||
'current_page' => $page_number,
|
||
'pages' => (int)(ceil($documentCount/$results_on_page)-1),
|
||
// 'module_dir' => $this->module->getPathUri(),
|
||
'module_template_dir' => __PS_BASE_URI__.'modules/'.$this->name.'/'
|
||
));
|
||
}
|
||
else {
|
||
$this->smarty->assign('customer_is_related', false);
|
||
}
|
||
|
||
$ps_version_int = str_replace(".","",_PS_VERSION_);
|
||
if($ps_version_int<1760)
|
||
{
|
||
return $this->display(__FILE__, 'account-block-admin_ps175.tpl');
|
||
}
|
||
else
|
||
{
|
||
return $this->display(__FILE__, 'account-block-admin.tpl');
|
||
}
|
||
}
|
||
|
||
public function hookDisplayCustomerAccount($params)
|
||
{
|
||
$customerInfo = $this->getCustomerInfo();
|
||
if ($customerInfo['customerId'] > 0) {
|
||
|
||
// obsluga danych opiekuna z zewnetrznych zrodel
|
||
// np. subiekt bez gestora
|
||
if (file_exists(_PS_ROOT_DIR_ . '/modules/firmesb2b/consultants.php')) {
|
||
include_once(_PS_ROOT_DIR_ . '/modules/firmesb2b/consultants.php');
|
||
}
|
||
|
||
if (isset($consultantInfo) AND isset($consultantInfo[$customerInfo['consultantId']])) {
|
||
$customerInfo['consultant'] = $consultantInfo[$customerInfo['consultantId']]['name'];
|
||
$customerInfo['consultantEmail'] = $consultantInfo[$customerInfo['consultantId']]['email'];
|
||
$customerInfo['consultantPhone'] = $consultantInfo[$customerInfo['consultantId']]['phone'];
|
||
}
|
||
|
||
$this->smarty->assign('customerInfo', $customerInfo);
|
||
|
||
|
||
}
|
||
|
||
$this->smarty->assign('in_footer', false);
|
||
return $this->display(__FILE__, 'my-account.tpl');
|
||
}
|
||
|
||
public function hookDisplayMyAccountBlock($params)
|
||
{
|
||
$this->smarty->assign('in_footer', true);
|
||
return $this->display(__FILE__, 'my-account-footer.tpl');
|
||
}
|
||
public function hookDisplayMyAccountBlockfooter($params)
|
||
{
|
||
return $this->display(__FILE__, 'my-account-block-footer.tpl');
|
||
}
|
||
|
||
public function hookDisplayHeader($params)
|
||
{
|
||
$this->context->controller->addCSS($this->_path.'firmesb2b.css', 'all');
|
||
}
|
||
|
||
public function hookDisplayLeftColumn($params)
|
||
{
|
||
$customerInfo = $this->getCustomerInfo();
|
||
if ($customerInfo['customerId'] > 0) {
|
||
|
||
$this->smarty->assign('customerInfo', $customerInfo);
|
||
$this->smarty->assign('in_footer', false);
|
||
|
||
return $this->display(__FILE__, 'block-my-account.tpl');
|
||
}
|
||
else {
|
||
return '';
|
||
}
|
||
}
|
||
|
||
public function hookDisplayRightColumn($params)
|
||
{
|
||
$customerInfo = $this->getCustomerInfo();
|
||
if ($customerInfo['customerId'] > 0) {
|
||
|
||
$this->smarty->assign('customerInfo', $customerInfo);
|
||
$this->smarty->assign('in_footer', false);
|
||
|
||
return $this->display(__FILE__, 'block-my-account.tpl');
|
||
}
|
||
else {
|
||
return '';
|
||
}
|
||
}
|
||
|
||
private function getCustomerInfo() {
|
||
|
||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS("
|
||
SELECT ci_shopCustomerId AS 'customerId', ci_creditLimit AS 'creditLimit', ci_creditUsed AS 'creditUsed', ci_creditOverdue AS 'creditOverdue', ci_discount AS 'discount', g.reduction AS 'shopDiscount'
|
||
,ci_consultantId AS 'consultantId', ci_consultant AS 'consultant', ci_consultantEmail AS 'consultantEmail', ci_consultantPhone AS 'consultantPhone', ci_timestamp
|
||
FROM yfi_customerinfo
|
||
LEFT JOIN "._DB_PREFIX_."customer c ON ci_shopCustomerId = id_customer
|
||
LEFT JOIN "._DB_PREFIX_."group g ON c.id_default_group = g.id_group
|
||
WHERE ci_shopCustomerId = '" . (int)Context::getContext()->customer->id . "'
|
||
ORDER BY ci_sourceId DESC LIMIT 1 ");
|
||
|
||
if (isset($res[0])) {
|
||
|
||
$customerInfo = $res[0];
|
||
$customerInfo['creditLimit'] = round($customerInfo['creditLimit'],2);
|
||
$customerInfo['creditUsed'] = round($customerInfo['creditUsed'],2);
|
||
$customerInfo['creditOverdue'] = round($customerInfo['creditOverdue'],2);
|
||
// obsluga danych opiekuna z zewnetrznych zrodel
|
||
// np. subiekt bez gestora
|
||
if (file_exists(_PS_ROOT_DIR_ . '/modules/firmesb2b/consultants.php')) {
|
||
include_once(_PS_ROOT_DIR_ . '/modules/firmesb2b/consultants.php');
|
||
}
|
||
|
||
if (isset($consultantInfo) AND isset($consultantInfo[$customerInfo['consultantId']])) {
|
||
$customerInfo['consultant'] = $consultantInfo[$customerInfo['consultantId']]['name'];
|
||
$customerInfo['consultantEmail'] = $consultantInfo[$customerInfo['consultantId']]['email'];
|
||
$customerInfo['consultantPhone'] = $consultantInfo[$customerInfo['consultantId']]['phone'];
|
||
}
|
||
|
||
return $customerInfo;
|
||
|
||
|
||
}
|
||
else {
|
||
return array('customerId' => 0);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|