Просмотр исходного кода

Ticket #5306 - Payments: Add setting to enable/disable commissions calculation.

AntonLV 10 месяцев назад
Родитель
Сommit
f9c5c6cf19

+ 7 - 0
modules/base/payment/classes/BxBaseModPaymentConfig.php

@@ -33,6 +33,7 @@ class BxBaseModPaymentConfig extends BxBaseModGeneralConfig
             // some params
             'PARAM_CURRENCY_CODE' => $this->_sName . '_default_currency_code',
 
+            'PARAM_CMSN_ENABLE' => true,
             'PARAM_CMSN_INVOICE_ISSUE_DAY' => 1, //the first day of month
             'PARAM_CMSN_INVOICE_LIFETIME' => 4, //in days
             'PARAM_CMSN_INVOICE_EXPIRATION_NOTIFY' => 1, //in days, before expiration date
@@ -140,6 +141,12 @@ class BxBaseModPaymentConfig extends BxBaseModGeneralConfig
         return $this->_bSingleSeller;
     }
 
+    public function isCommissions()
+    {
+        $sKey = 'PARAM_CMSN_ENABLE';
+        return is_bool($this->CNF[$sKey]) ? $this->CNF[$sKey] : $this->_oDb->getParam($this->CNF[$sKey]) == 'on';
+    }
+
     public function getInvoiceIssueDay()
     {
         $sKey = 'PARAM_CMSN_INVOICE_ISSUE_DAY';

+ 1 - 0
modules/boonex/payment/classes/BxPaymentConfig.php

@@ -56,6 +56,7 @@ class BxPaymentConfig extends BxBaseModPaymentConfig
 
             // some params
             'PARAM_CURRENCY_EXCHANGE_API' => 'bx_payment_currency_exchange_api',
+            'PARAM_CMSN_ENABLE' => 'bx_payment_commissions',
             'PARAM_CMSN_INVOICE_ISSUE_DAY' => 'bx_payment_inv_issue_day', //some day of month
             'PARAM_CMSN_INVOICE_LIFETIME' => 'bx_payment_inv_lifetime', //in days
             'PARAM_CMSN_INVOICE_EXPIRATION_NOTIFY' => 'bx_payment_inv_expiraction_notify', //in days, before expiration date

+ 23 - 21
modules/boonex/payment/classes/BxPaymentModule.php

@@ -1477,7 +1477,8 @@ class BxPaymentModule extends BxBaseModPaymentModule
         if(!defined('BX_DOL_CRON_EXECUTE'))
             return;
 
-        $CNF = &$this->_oConfig->CNF;
+        if(!$this->_oConfig->isCommissions())
+            return;
 
         if((int)date('j') == $this->_oConfig->getInvoiceIssueDay())
             $this->_invoicesIssue();
@@ -1501,17 +1502,17 @@ class BxPaymentModule extends BxBaseModPaymentModule
         $aCommissionsInfo = array();
         $aAclLevels = BxDolAcl::getInstance()->getMemberships(false, true, false, true);
         foreach($aAclLevels as $iAclLevelId => $sAclLevelTitle)
-            $aCommissionsInfo[$iAclLevelId] = $this->_oDb->getCommissions(array('type' => 'acl_id', 'acl_id' => $iAclLevelId));
+            $aCommissionsInfo[$iAclLevelId] = $this->_oDb->getCommissions(['type' => 'acl_id', 'acl_id' => $iAclLevelId]);
 
         $iMainSellerId = $this->_oConfig->getSiteAdmin();
 
-        $aVendors = $this->_oDb->getOrderProcessed(array('type' => 'income', 'period_start' => $iPeriodStart, 'period_end' => $iPeriodEnd));
+        $aVendors = $this->_oDb->getOrderProcessed(['type' => 'income', 'period_start' => $iPeriodStart, 'period_end' => $iPeriodEnd]);
         foreach($aVendors as $aVendor) {
             $iVendorId = (int)$aVendor['id'];
             if($iVendorId == $iMainSellerId)
                 continue;
 
-            $aInvoice = $this->_oDb->getInvoices(array('type' => 'committent_id', 'committent_id' => $iVendorId, 'period_start' => $iPeriodStart, 'period_end' => $iPeriodEnd));
+            $aInvoice = $this->_oDb->getInvoices(['type' => 'committent_id', 'committent_id' => $iVendorId, 'period_start' => $iPeriodStart, 'period_end' => $iPeriodEnd]);
             if(!empty($aInvoice) && is_array($aInvoice))
                 continue;
 
@@ -1526,28 +1527,29 @@ class BxPaymentModule extends BxBaseModPaymentModule
                 if((float)$aCommission['installment'] > 0)
                     $fCommission += (float)$aCommission['installment'];
             }
-            
-            $this->alert('calculate_commission', 0, 0, array(
+
+            $this->alert('calculate_commission', 0, 0, [
                 'vendor' => $aVendor,
                 'commissions' => $aCommissions,
                 'override_result' => &$fCommission,
-            ));
+            ]);
 
-            $this->_oDb->insertInvoice(array(
-                'name' => sprintf($sInvoiceNameMask, $iMainSellerId, $iVendorId, $this->_oDb->getInvoices(array(
-                    'type' => 'index', 
+            if($fCommission > 0)
+                $this->_oDb->insertInvoice([
+                    'name' => sprintf($sInvoiceNameMask, $iMainSellerId, $iVendorId, $this->_oDb->getInvoices([
+                        'type' => 'index', 
+                        'commissionaire_id' => $iMainSellerId, 
+                        'committent_id' => $iVendorId
+                    ])),
                     'commissionaire_id' => $iMainSellerId, 
-                    'committent_id' => $iVendorId
-                ))),
-                'commissionaire_id' => $iMainSellerId, 
-                'committent_id' => $iVendorId,
-                'amount' => $fCommission,
-                'period_start' => $iPeriodStart,
-                'period_end' => $iPeriodEnd,
-                'date_issue' => $iDateIssue,
-                'date_due' => $iDateDue,
-                'status' => BX_PAYMENT_INV_STATUS_UNPAID
-            ));
+                    'committent_id' => $iVendorId,
+                    'amount' => $fCommission,
+                    'period_start' => $iPeriodStart,
+                    'period_end' => $iPeriodEnd,
+                    'date_issue' => $iDateIssue,
+                    'date_due' => $iDateDue,
+                    'status' => BX_PAYMENT_INV_STATUS_UNPAID
+                ]);
         }
     }
 

+ 1 - 0
modules/boonex/payment/install/sql/enable.sql

@@ -29,6 +29,7 @@ VALUES (@iTypeId, 'bx_payment_commissions', '_bx_payment_options_category_commis
 SET @iCategoryId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_params`, `check_error`, `extra`, `order`) VALUES
+('bx_payment_commissions', '', @iCategoryId, '_bx_payment_option_commissions', 'checkbox', '', '', '', '', 0),
 ('bx_payment_inv_issue_day', '1', @iCategoryId, '_bx_payment_option_inv_issue_day', 'digit', '', '', '', '', 1),
 ('bx_payment_inv_lifetime', '4', @iCategoryId, '_bx_payment_option_inv_lifetime', 'digit', '', '', '', '', 2),
 ('bx_payment_inv_expiraction_notify', '1', @iCategoryId, '_bx_payment_option_inv_expiraction_notify', 'digit', '', '', '', '', 3);