Skip to content

Commit

Permalink
Ticket unacms#3134
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Jan 12, 2021
1 parent bd68e93 commit 5de5454
Show file tree
Hide file tree
Showing 32 changed files with 1,853 additions and 117 deletions.
47 changes: 32 additions & 15 deletions inc/classes/BxDolPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

class BxDolPayments extends BxDolFactory implements iBxDolSingleton
{
protected $_oDb;
protected $_oDb;

protected $_aObjects;
protected $_sActive;
protected $_aObjects;
protected $_sActive;

protected function __construct()
{
Expand All @@ -24,17 +24,17 @@ protected function __construct()
$this->_sActive = getParam('sys_default_payment');
}

static public function getInstance()
static public function getInstance()
{
if(!isset($GLOBALS['bxDolClasses']['BxDolPayments']))
$GLOBALS['bxDolClasses']['BxDolPayments'] = new BxDolPayments();
$GLOBALS['bxDolClasses']['BxDolPayments'] = new BxDolPayments();

return $GLOBALS['bxDolClasses']['BxDolPayments'];
return $GLOBALS['bxDolClasses']['BxDolPayments'];
}

public function setActive($sActive)
public function setActive($sActive)
{
$this->_sActive = $sActive;
$this->_sActive = $sActive;
}

public function getActive()
Expand Down Expand Up @@ -153,14 +153,14 @@ public function getProductsNames($iVendor = 0, $iLimit = 1000)
public function getPayments()
{
$aPayments = array(
'' => _t('_Select_one')
'' => _t('_Select_one')
);
foreach($this->_aObjects as $aObject) {
if(empty($aObject) || !is_array($aObject))
continue;
foreach($this->_aObjects as $aObject) {
if(empty($aObject) || !is_array($aObject))
continue;

$aPayments[$aObject['object']] = _t($aObject['title']);
}
$aPayments[$aObject['object']] = _t($aObject['title']);
}

return $aPayments;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public function getOrdersUrl()

return bx_srv($this->_sActive, 'get_orders_url', array(), 'Orders');
}

public function getOrdersCount($sType)
{
if(!BxDolRequest::serviceExists($this->_sActive, 'get_orders_count', 'Orders'))
Expand Down Expand Up @@ -243,6 +243,23 @@ public function getSubscriptionsInfo($aConditions, $bCheckInProvider = false)
return bx_srv($this->_sActive, 'get_subscriptions_info', $aSrvParams, 'Subscriptions');
}

public function getInvoicesUrl()
{
if(!BxDolRequest::serviceExists($this->_sActive, 'get_invoices_url', 'Commissions'))
return '';

return bx_srv($this->_sActive, 'get_invoices_url', array(), 'Commissions');
}

public function getInvoicesCount($sType)
{
if(!BxDolRequest::serviceExists($this->_sActive, 'get_invoices_count', 'Commissions'))
return array();

$aSrvParams = array($sType);
return bx_srv($this->_sActive, 'get_invoices_count', $aSrvParams, 'Commissions');
}

public function getCartUrl($iVendor = 0)
{
if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_url', 'Cart'))
Expand Down
9 changes: 6 additions & 3 deletions install/sql/system.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4173,6 +4173,7 @@ INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `tit
('sys_account_notifications', 'system', 'studio', '_sys_menu_item_title_system_studio', '_sys_menu_item_title_studio', '{studio_url}', '', '', 'wrench', '', '', 2147483646, 1, 0, 5),
('sys_account_notifications', 'system', 'cart', '_sys_menu_item_title_system_cart', '_sys_menu_item_title_cart', 'cart.php', '', '', 'cart-plus col-red3', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:20:"get_cart_items_count";s:6:"params";a:0:{}s:5:"class";s:21:"TemplPaymentsServices";}', '', 2147483646, 1, 1, 6),
('sys_account_notifications', 'system', 'orders', '_sys_menu_item_title_system_orders', '_sys_menu_item_title_orders', 'orders.php', '', '', 'cart-arrow-down col-green3', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:16:"get_orders_count";s:6:"params";a:1:{i:0;s:3:"new";}s:5:"class";s:21:"TemplPaymentsServices";}', '', 2147483646, 0, 1, 7),
('sys_account_notifications', 'system', 'invoices', '_sys_menu_item_title_system_invoices', '_sys_menu_item_title_invoices', 'invoices.php', '', '', 'file-invoice col-green3', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:18:"get_invoices_count";s:6:"params";a:1:{i:0;s:6:"unpaid";}s:5:"class";s:21:"TemplPaymentsServices";}', '', 2147483646, 0, 1, 8),
('sys_account_notifications', 'system', 'logout', '_sys_menu_item_title_system_logout', '_sys_menu_item_title_logout', 'logout.php', '', '', 'sign-out-alt', '', '', 2147483646, 1, 1, 9999);

-- account settings menu
Expand All @@ -4190,8 +4191,9 @@ INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `tit
-- account dashboard
INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES
('sys_account_dashboard', 'system', 'dashboard', '_sys_menu_item_title_system_account_dashboard', '_sys_menu_item_title_account_dashboard', 'page.php?i=dashboard', '', '', 'tachometer-alt', '', '', 2147483646, 1, 1, 1),
('sys_account_dashboard', 'system', 'dashboard-subscriptions', '_sys_menu_item_title_system_subscriptions', '_sys_menu_item_title_subscriptions', 'subscriptions.php', '', '', 'money col-blue3', '', '', 2147483646, 1, 1, 2),
('sys_account_dashboard', 'system', 'dashboard-orders', '_sys_menu_item_title_system_orders', '_sys_menu_item_title_orders', 'orders.php', '', '', 'cart-arrow-down col-green3', '', '', 2147483646, 1, 1, 3);
('sys_account_dashboard', 'system', 'dashboard-subscriptions', '_sys_menu_item_title_system_subscriptions', '_sys_menu_item_title_subscriptions', 'subscriptions.php', '', '', 'credit-card col-blue3', '', '', 2147483646, 1, 1, 2),
('sys_account_dashboard', 'system', 'dashboard-orders', '_sys_menu_item_title_system_orders', '_sys_menu_item_title_orders', 'orders.php', '', '', 'cart-arrow-down col-green3', '', '', 2147483646, 1, 1, 3),
('sys_account_dashboard', 'system', 'dashboard-invoices', '_sys_menu_item_title_system_invoices', '_sys_menu_item_title_invoices', 'invoices.php', '', '', 'file-invoice col-green3', '', '', 2147483646, 1, 1, 4);

-- comment manage menu
INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES
Expand Down Expand Up @@ -5202,7 +5204,8 @@ CREATE TABLE `sys_objects_live_updates` (

INSERT INTO `sys_objects_live_updates`(`name`, `init`, `frequency`, `service_call`, `active`) VALUES
('sys_payments_cart', 0, 1, 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:21:"get_live_updates_cart";s:6:"params";a:3:{i:0;a:2:{s:11:"menu_object";s:18:"sys_toolbar_member";s:9:"menu_item";s:7:"account";}i:1;a:2:{s:11:"menu_object";s:25:"sys_account_notifications";s:9:"menu_item";s:4:"cart";}i:2;s:7:"{count}";}s:5:"class";s:21:"TemplPaymentsServices";}', 1),
('sys_payments_orders', 0, 1, 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:23:"get_live_updates_orders";s:6:"params";a:3:{i:0;a:2:{s:11:"menu_object";s:18:"sys_toolbar_member";s:9:"menu_item";s:7:"account";}i:1;a:2:{s:11:"menu_object";s:25:"sys_account_notifications";s:9:"menu_item";s:6:"orders";}i:2;s:7:"{count}";}s:5:"class";s:21:"TemplPaymentsServices";}', 1);
('sys_payments_orders', 0, 1, 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:23:"get_live_updates_orders";s:6:"params";a:3:{i:0;a:2:{s:11:"menu_object";s:18:"sys_toolbar_member";s:9:"menu_item";s:7:"account";}i:1;a:2:{s:11:"menu_object";s:25:"sys_account_notifications";s:9:"menu_item";s:6:"orders";}i:2;s:7:"{count}";}s:5:"class";s:21:"TemplPaymentsServices";}', 1),
('sys_payments_invoices', 0, 1, 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:25:"get_live_updates_invoices";s:6:"params";a:3:{i:0;a:2:{s:11:"menu_object";s:18:"sys_toolbar_member";s:9:"menu_item";s:7:"account";}i:1;a:2:{s:11:"menu_object";s:25:"sys_account_notifications";s:9:"menu_item";s:8:"invoices";}i:2;s:7:"{count}";}s:5:"class";s:21:"TemplPaymentsServices";}', 1);

-- --------------------------------------------------------

Expand Down
24 changes: 24 additions & 0 deletions invoices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaCore UNA Core
* @{
*/

require_once('./inc/header.inc.php');
require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");

bx_import('BxDolLanguages');

check_logged();

$sUrl = BxDolPayments::getInstance()->getInvoicesUrl();
if(empty($sUrl))
BxDolTemplate::getInstance()->displayPageNotFound();

header('Location: ' . $sUrl);
exit;

/** @} */
81 changes: 81 additions & 0 deletions modules/base/payment/classes/BxBaseModPaymentCommissions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup BasePayment Base classes for Payment like modules
* @ingroup UnaModules
*
* @{
*/

class BxBaseModPaymentCommissions extends BxDol
{
protected $_sModule;
protected $_oModule;

function __construct()
{
parent::__construct();

$this->_oModule = BxDolModule::getInstance($this->_sModule);
}

/**
* @page service Service Calls
* @section bx_base_payment Base Payment
* @subsection bx_base_payment-integration Integration
* @subsubsection bx_base_payment-get_invoices_url get_invoices_url
*
* @code bx_srv('bx_payment', 'get_invoices_url', [...], 'Commissions'); @endcode
*
* Get invoices page URL.
*
* @return string with invoices page URL.
*
* @see BxBaseModPaymentOrders::serviceGetOrdersUrl
*/
/**
* @ref bx_base_payment-get_invoices_url "get_invoices_url"
*/
public function serviceGetInvoicesUrl()
{
if(!$this->_oModule->isLogged())
return '';

return $this->_oModule->_oConfig->getUrl('URL_INVOICES');
}

/**
* @page service Service Calls
* @section bx_base_payment Base Payment
* @subsection bx_base_payment-integration Integration
* @subsubsection bx_base_payment-get_invoices_count get_invoices_count
*
* @code bx_srv('bx_payment', 'get_invoices_count', [...], 'Commissions'); @endcode
*
* Get invoices count by type.
*
* @param $sType string value with type.
* @param $iProfileId (optional) integer value with profile ID. If empty value is provided then currently logged in profile will be used.
* @return integer value with invoices count.
*
* @see BxBaseModPaymentOrders::serviceGetOrdersCount
*/
/**
* @ref bx_base_payment-get_invoices_count "get_invoices_count"
*/
public function serviceGetInvoicesCount($sType, $iProfileId = 0)
{
if(!in_array($sType, array('unpaid', 'overdue')))
return 0;

$iProfileId = !empty($iProfileId) ? $iProfileId : $this->_oModule->getProfileId();
if(empty($iProfileId))
return 0;

return $this->_oModule->_oDb->getInvoices(array('type' => 'status', 'status' => $sType, 'committent_id' => $iProfileId, 'count' => true));
}
}

/** @} */
37 changes: 31 additions & 6 deletions modules/base/payment/classes/BxBaseModPaymentConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ function __construct($aModule)
parent::__construct($aModule);

$this->CNF = array_merge($this->CNF, array(
// some params
'PARAM_CMSN_INVOICE_ISSUE_DAY' => 12, //the first day of month
'PARAM_CMSN_INVOICE_LIFETIME' => 4, //in days
'PARAM_CMSN_INVOICE_EXPIRATION_NOTIFY' => 1, //in days, before expiration date
'PARAM_CMSN_DATE_FORMAT' => 'd.m.Y',
'PARAM_CMSN_DATE_TIME_FORMAT' => 'd.m.Y H:i',

// objects
'OBJECT_FORM_PRELISTS_CURRENCIES' => '',

'KEY_SESSION_PENDING' => $this->_sName . '_pending_id',
Expand All @@ -49,8 +57,13 @@ function __construct($aModule)
$this->_aObjects = array_merge($this->_aObjects, array(
'form_pendings' => $this->_sName . '_form_pendings',
'form_processed' => $this->_sName . '_form_processed',
'display_pendings_process' => $this->_sName . '_form_pendings_process',
'display_processed_add' => $this->_sName . '_form_processed_add',
'form_display_pendings_process' => $this->_sName . '_form_pendings_process',
'form_display_processed_add' => $this->_sName . '_form_processed_add',
'form_commissions' => $this->_sName . '_form_commissions',
'form_display_commissions_add' => $this->_sName . '_form_commissions_add',
'form_display_commissions_edit' => $this->_sName . '_form_commissions_edit',
'form_invoices' => $this->_sName . '_form_invoices',
'form_display_invoices_edit' => $this->_sName . '_form_invoices_edit',

'menu_dashboard' => 'sys_account_dashboard',
'menu_cart_submenu' => $this->_sName . '_menu_cart_submenu',
Expand All @@ -62,6 +75,8 @@ function __construct($aModule)
'grid_history' => $this->_sName . '_grid_orders_history',
'grid_processed' => $this->_sName . '_grid_orders_processed',
'grid_pending' => $this->_sName . '_grid_orders_pending',
'grid_commissions' => $this->_sName . '_grid_commissions',
'grid_invoices' => $this->_sName . '_grid_invoices',
'grid_carts' => $this->_sName . '_grid_carts',
'grid_cart' => $this->_sName . '_grid_cart',
'grid_sbs_list_my' => $this->_sName . '_grid_sbs_list_my',
Expand Down Expand Up @@ -141,7 +156,7 @@ public function getUrl($sType, $aParams = array(), $bSsl = false)
return $bSsl ? $this->http2https($sResult) : $sResult;
}

public function getDivider($sType)
public function getDivider($sType)
{
$sResult = '';
if(empty($sType) || !isset($this->CNF[$sType]))
Expand All @@ -150,15 +165,15 @@ public function getDivider($sType)
return $this->CNF[$sType];
}

public function getPerPage($sType = 'default')
public function getPerPage($sType = 'default')
{
if(empty($sType))
return $this->_aPerPage;

return isset($this->_aPerPage[$sType]) ? $this->_aPerPage[$sType] : '';
}

public function getHtmlIds($sType, $sKey = '')
public function getHtmlIds($sType, $sKey = '')
{
if(empty($sKey))
return isset($this->_aHtmlIds[$sType]) ? $this->_aHtmlIds[$sType] : array();
Expand All @@ -171,7 +186,7 @@ public function getAnimationEffect()
return $this->_sAnimationEffect;
}

public function getAnimationSpeed()
public function getAnimationSpeed()
{
return $this->_iAnimationSpeed;
}
Expand All @@ -197,6 +212,16 @@ public function getLicense()

return $sResult;
}

public function formatDate($iTs)
{
return gmdate($this->CNF['PARAM_CMSN_DATE_FORMAT'], $iTs);
}

public function formatDateTime($iTs)
{
return gmdate($this->CNF['PARAM_CMSN_DATE_TIME_FORMAT'], $iTs);
}
}

/** @} */
54 changes: 54 additions & 0 deletions modules/base/payment/classes/BxBaseModPaymentGridCommissions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup BasePayment Base classes for Payment like modules
* @ingroup UnaModules
*
* @{
*/

class BxBaseModPaymentGridCommissions extends BxTemplGrid
{
protected $_sModule;
protected $_oModule;

protected $_sLangsPrefix;

protected $_aAclLevels;

public function __construct ($aOptions, $oTemplate = false)
{
parent::__construct ($aOptions, $oTemplate);

$this->_oModule = BxDolModule::getInstance($this->_sModule);

$this->_sLangsPrefix = $this->_oModule->_oConfig->getPrefix('langs');

$this->_aAclLevels = BxDolAcl::getInstance()->getMemberships(false, true, true, true);
}

protected function _getCellAclId($mixedValue, $sKey, $aField, $aRow)
{
$mixedValue = isset($this->_aAclLevels[$mixedValue]) > 0 ? $this->_aAclLevels[$mixedValue] : _t('_all');

return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
}

protected function _getCellPercentage($mixedValue, $sKey, $aField, $aRow)
{
$mixedValue = (float)$mixedValue > 0 ? $mixedValue . '%' : '';

return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
}

protected function _getCellInstallment($mixedValue, $sKey, $aField, $aRow)
{
$mixedValue = (float)$mixedValue > 0 ? _t_format_currency($mixedValue) : '';

return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
}
}

/** @} */
Loading

0 comments on commit 5de5454

Please sign in to comment.