AntonLV 6 năm trước cách đây
mục cha
commit
11f5e33188

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

@@ -34,6 +34,7 @@ class BxBaseModPaymentConfig extends BxBaseModGeneralConfig
 
             'DIVIDER_DESCRIPTOR' => '_',
             'DIVIDER_DESCRIPTORS' => ':',
+            'DIVIDER_GRID_FILTERS' => '#-#',
         ));
 
         $this->_aPrefixes = array(

+ 56 - 11
modules/base/payment/classes/BxBaseModPaymentGridOrders.php

@@ -16,6 +16,7 @@ class BxBaseModPaymentGridOrders extends BxTemplGrid
 
     protected $_sOrdersType;
 
+    protected $_sJsObject;
     protected $_sLangsPrefix;
     protected $_sCurrencySign;
 
@@ -30,37 +31,37 @@ class BxBaseModPaymentGridOrders extends BxTemplGrid
 
         $this->_sDefaultSortingOrder = 'DESC';
 
-	    $iSellerId = bx_get('seller_id');
+        $iSellerId = bx_get('seller_id');
         if($iSellerId !== false)
             $this->_aQueryAppend['seller_id'] = (int)$iSellerId;
 
-	    $iClientId = bx_get('client_id');
+        $iClientId = bx_get('client_id');
         if($iClientId !== false)
             $this->_aQueryAppend['client_id'] = (int)$iClientId;
     }
 
     public function addQueryParam($sKey, $sValue)
     {
-    	if(empty($sKey) || !isset($sValue))
-    		return;
+        if(empty($sKey) || !isset($sValue))
+            return;
 
-		$this->_aQueryAppend[$sKey] = $sValue;
+        $this->_aQueryAppend[$sKey] = $sValue;
     }
 
     public function performActionViewOrder()
     {
-    	$aIds = bx_get('ids');
+        $aIds = bx_get('ids');
         if(!$aIds || !is_array($aIds)) 
-        	return echoJson(array());
+            return echoJson(array());
 
         $iId = (int)$aIds[0];
 
         $sKey = 'order_' . $this->_sOrdersType . '_view';
-    	$sId = $this->_oModule->_oConfig->getHtmlIds($this->_sOrdersType, $sKey);
-    	$sTitle = _t($this->_sLangsPrefix . 'popup_title_ods_' . $sKey);
-    	$sContent = $this->_oModule->getObjectOrders()->getOrder($this->_sOrdersType, $iId);
+        $sId = $this->_oModule->_oConfig->getHtmlIds($this->_sOrdersType, $sKey);
+        $sTitle = _t($this->_sLangsPrefix . 'popup_title_ods_' . $sKey);
+        $sContent = $this->_oModule->getObjectOrders()->getOrder($this->_sOrdersType, $iId);
 
-    	return echoJson(array('popup' => BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $sContent)));
+        return echoJson(array('popup' => BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $sContent)));
     }
 
     public function performActionCancel()
@@ -119,6 +120,50 @@ class BxBaseModPaymentGridOrders extends BxTemplGrid
     {
         return parent::_getCellDefault(bx_time_js($mixedValue, BX_FORMAT_DATE, true), $sKey, $aField, $aRow);
     }
+
+    protected function _getFilterSelectAll($sName, $aParams = array())
+    {
+        $sJsObject = !empty($aParams['js_object']) ? $aParams['js_object'] : $this->_sJsObject;
+        $sJsOnChange = !empty($aParams['js_onchange']) ? $aParams['js_onchange'] : 'onChangeFilter(this)';
+        
+        $aAttrs = array(
+            'id' => 'bx-grid-' . $sName . '-' . $this->_sObject,
+            'onChange' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.' . $sJsOnChange,
+            'onBlur' => 'javascript:' . $sJsObject . '.' . $sJsOnChange,
+        );
+        if(!empty($aParams['attrs']) && is_array($aParams['attrs']))
+            $aAttrs = array_merge($aAttrs, $aParams['attrs']);
+
+        $aInput = array(
+            'type' => 'select',
+            'name' => $sName,
+            'tr_attrs' => array(
+                'class' => 'bx-grid-filter-' . $sName,
+            ),
+            'attrs' => $aAttrs,
+            'value' => !empty($aParams['value']) ? $aParams['value'] : '',
+            'values' => !empty($aParams['values']) && is_array($aParams['values']) ? $aParams['values'] : array()
+        );
+
+        $oForm = new BxTemplFormView(array());
+        return $oForm->genRow($aInput);
+    }
+
+    protected function _getSearchInput()
+    {
+        $aInput = array(
+            'type' => 'text',
+            'name' => 'keyword',
+            'attrs' => array(
+                'id' => 'bx-grid-search-' . $this->_sObject,
+                'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $this->_sJsObject . '.onChangeFilter(this)',
+                'placeholder' => bx_html_attribute(_t('_sys_grid_search'))
+            )
+        );
+
+        $oForm = new BxTemplStudioFormView(array());
+        return $oForm->genRow($aInput);
+    }
 }
 
 /** @} */

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

@@ -263,6 +263,16 @@ class BxPaymentConfig extends BxBaseModPaymentConfig
 
         return 'https://' . bx_ltrim_str($s, 'http://');
     }
+
+    public function sortByColumn($sColumn, &$aValues)
+    {
+        return usort($aValues, function($aV1, $aV2) use ($sColumn) {
+            if($aV1[$sColumn] == $aV2[$sColumn])
+                return 0;
+
+            return $aV1[$sColumn] < $aV2[$sColumn] ? -1 : 1;
+        });
+    }
 }
 
 /** @} */

+ 24 - 24
modules/boonex/payment/classes/BxPaymentDb.php

@@ -304,7 +304,9 @@ class BxPaymentDb extends BxBaseModPaymentDb
     {
     	$aMethod = array('name' => 'getRow', 'params' => array(0 => 'query'));
 
+        $sSelectClause = "`tt`.`id`, `tt`.`license`, `ttp`.`type`, `tt`.`client_id`, `tt`.`seller_id`, `tt`.`module_id`, `tt`.`item_id`, `tt`.`item_count`, `tt`.`amount`, `tt`.`date`, `ttp`.`order`, `ttp`.`error_msg`, `ttp`.`provider`";
         $sWhereClause = "";
+
         switch($aParams['type']) {
             case 'id':
             	$aMethod['params'][1] = array(
@@ -317,30 +319,40 @@ class BxPaymentDb extends BxBaseModPaymentDb
             case 'new':
                 $aMethod['name'] = 'getAll';
                 $aMethod['params'][1] = array(
-                	'seller_id' => $aParams['seller_id']
+                    'seller_id' => $aParams['seller_id']
                 );
 
                 $sWhereClause = " AND `tt`.`seller_id`=:seller_id AND `tt`.`new`='1'";
                 break;
 
-			case 'pending_id':
+            case 'pending_id':
                 if(empty($aParams['with_key'])) {
-                	$aMethod['name'] = 'getAll';
-                	$aMethod['params'][1] = array(
-						'pending_id' => $aParams['pending_id']
-					);
+                    $aMethod['name'] = 'getAll';
+                    $aMethod['params'][1] = array(
+                        'pending_id' => $aParams['pending_id']
+                    );
                 }
                 else {
-                	$aMethod['name'] = 'getAllWithKey';
-					$aMethod['params'][1] = $aParams['with_key'];
-					$aMethod['params'][2] = array(
-						'pending_id' => $aParams['pending_id']
-					);
+                    $aMethod['name'] = 'getAllWithKey';
+                    $aMethod['params'][1] = $aParams['with_key'];
+                    $aMethod['params'][2] = array(
+                        'pending_id' => $aParams['pending_id']
+                    );
                 }
 
                 $sWhereClause = " AND `tt`.`pending_id`=:pending_id";
                 break;
 
+            case 'clients':
+                $aMethod['name'] = 'getColumn';
+                $aMethod['params'][1] = array(
+                    'seller_id' => $aParams['seller_id']
+                );
+
+                $sSelectClause = "DISTINCT `tt`.`client_id`";
+                $sWhereClause = " AND `tt`.`seller_id`=:seller_id";
+                break;
+
             case 'license':
                 $aMethod['name'] = 'getAll';
                 $aMethod['params'][1] = array(
@@ -359,19 +371,7 @@ class BxPaymentDb extends BxBaseModPaymentDb
         }
 
         $aMethod['params'][0] = "SELECT
-        		`tt`.`id`,
-                `tt`.`license`,
-                `ttp`.`type`,
-                `tt`.`client_id`,
-                `tt`.`seller_id`,
-                `tt`.`module_id`,
-                `tt`.`item_id`,
-                `tt`.`item_count`,
-                `tt`.`amount`,
-                `tt`.`date`,
-                `ttp`.`order`,
-                `ttp`.`error_msg`,
-                `ttp`.`provider`
+                " . $sSelectClause . "
             FROM `" . $this->_sPrefix . "transactions` AS `tt`
             LEFT JOIN `" . $this->_sPrefix . "transactions_pending` AS `ttp` ON `tt`.`pending_id`=`ttp`.`id`
             WHERE 1" . $sWhereClause;

+ 147 - 68
modules/boonex/payment/classes/BxPaymentGridProcessed.php

@@ -19,13 +19,15 @@ class BxPaymentGridProcessed extends BxBaseModPaymentGridOrders
         parent::__construct ($aOptions, $oTemplate);
 
         $this->_sOrdersType = 'processed';
+
+        $this->_sJsObject = $this->_oModule->_oConfig->getJsObject('processed');
     }
 
     public function performActionAdd()
     {
-    	$sType = BX_PAYMENT_TYPE_SINGLE;
-    	$sAction = 'add';
-    	$sJsObject = $this->_oModule->_oConfig->getJsObject('processed');
+        $sType = BX_PAYMENT_TYPE_SINGLE;
+        $sAction = 'add';
+        $sJsObject = $this->_oModule->_oConfig->getJsObject('processed');
 
         $sFormObject = $this->_oModule->_oConfig->getObject('form_processed');
         $sFormDisplay = $this->_oModule->_oConfig->getObject('display_processed_add');
@@ -36,23 +38,23 @@ class BxPaymentGridProcessed extends BxBaseModPaymentGridOrders
         $oForm->aInputs['seller_id']['value'] = $this->_aQueryAppend['seller_id'];
 
         $oForm->aInputs['client_id']['attrs'] = array(
-        	'id' => $this->_oModule->_oConfig->getHtmlIds('processed', 'order_processed_client_id'),
+            'id' => $this->_oModule->_oConfig->getHtmlIds('processed', 'order_processed_client_id'),
         );
 
-		$oForm->aInputs['client']['attrs'] = array(
-        	'id' => $this->_oModule->_oConfig->getHtmlIds('processed', 'order_processed_client')			
+        $oForm->aInputs['client']['attrs'] = array(
+            'id' => $this->_oModule->_oConfig->getHtmlIds('processed', 'order_processed_client')			
         );
 
-		$oForm->aInputs['client']['ajax_get_suggestions'] = BX_DOL_URL_ROOT . 'modules/?r=' . $this->_oModule->_oConfig->getUri() . '/get_clients';
+        $oForm->aInputs['client']['ajax_get_suggestions'] = BX_DOL_URL_ROOT . 'modules/?r=' . $this->_oModule->_oConfig->getUri() . '/get_clients';
 
-		$oForm->aInputs['client']['custom'] = array(
-			'only_once' => true,
-			'on_select' => "function(oObject){{$sJsObject}.showPopup(oObject);}"
-		);
+        $oForm->aInputs['client']['custom'] = array(
+            'only_once' => true,
+            'on_select' => "function(oObject){{$sJsObject}.showPopup(oObject);}"
+        );
 
         $oForm->aInputs['module_id']['attrs'] = array(
-			'onchange' => 'javascript:' . $sJsObject . '.selectModule(this);'
-		);
+            'onchange' => 'javascript:' . $sJsObject . '.selectModule(this);'
+        );
         $oForm->aInputs['module_id']['values'] = array(
             array('key' => '0', 'value' => _t('_Select_one'))
         );
@@ -61,76 +63,153 @@ class BxPaymentGridProcessed extends BxBaseModPaymentGridOrders
         foreach($aModules as $aModule)
            $oForm->aInputs['module_id']['values'][] = array('key' => $aModule['id'], 'value' => $aModule['title']);
 
-		$oForm->aInputs['items']['content'] = $this->_oModule->_oTemplate->displayItems($sType);
+        $oForm->aInputs['items']['content'] = $this->_oModule->_oTemplate->displayItems($sType);
 
         $oForm->initChecker();
         if($oForm->isSubmittedAndValid()) {
-        	$sFormMethod = $oForm->aFormAttrs['method'];
-
-        	$aItemIds = $oForm->getSubmittedValue('items', $sFormMethod);
-        	if(empty($aItemIds) || !is_array($aItemIds))
-            	return echoJson(array('msg' => $this->_sLangsPrefix . 'err_empty_items'));
-
-			$aItems = array();
-			$sPriceKey = $this->_oModule->_oConfig->getKey('KEY_ARRAY_PRICE_SINGLE');
-			foreach($aItemIds as $iItemId) {
-	            $iItemId = (int)$iItemId;
-	            $fItemPrice = (float)$oForm->getSubmittedValue('item-price-' . $iItemId, $sFormMethod);
-	            $iItemQuantity = (int)$oForm->getSubmittedValue('item-quantity-' . $iItemId, $sFormMethod);
-
-	            if($iItemQuantity <= 0)
-	                return echoJson(array('msg' => $this->_sLangsPrefix . 'err_wrong_quantity'));
-
-				$aItems[] = array(
-					'id' => $iItemId, 
-					 $sPriceKey => $fItemPrice, 
-					'quantity' => $iItemQuantity
-				);
-			}
-
-        	$mixedResult = $this->_oModule->getObjectOrders()->addOrder(array(
-        		'client_id' => $oForm->getCleanValue('client_id'),
-        		'seller_id' => $oForm->getCleanValue('seller_id'),
-        		'provider' => 'manual',
-        		'type' => $sType,
-        		'order' => $oForm->getCleanValue('order'),
-        		'error_code' => 0,
-        		'error_msg' => 'Manually processed',        		
-        		'module_id' => $oForm->getCleanValue('module_id'),
-        		'items' => $aItems
-        	));
-        	if(is_array($mixedResult))
-        		return echoJson($mixedResult);
-
-			$iPendingId = (int)$mixedResult;
-        	if(!$this->_oModule->registerPayment($iPendingId))
-        		return echoJson(array('msg' => _t($this->_sLangsPrefix . 'err_cannot_perform')));
-
-			$aOrders = $this->_oModule->_oDb->getOrderProcessed(array('type' => 'pending_id', 'pending_id' => $iPendingId, 'with_key' => 'id'));
+            $sFormMethod = $oForm->aFormAttrs['method'];
+
+            $aItemIds = $oForm->getSubmittedValue('items', $sFormMethod);
+            if(empty($aItemIds) || !is_array($aItemIds))
+                return echoJson(array('msg' => $this->_sLangsPrefix . 'err_empty_items'));
+
+            $aItems = array();
+            $sPriceKey = $this->_oModule->_oConfig->getKey('KEY_ARRAY_PRICE_SINGLE');
+            foreach($aItemIds as $iItemId) {
+                $iItemId = (int)$iItemId;
+                $fItemPrice = (float)$oForm->getSubmittedValue('item-price-' . $iItemId, $sFormMethod);
+                $iItemQuantity = (int)$oForm->getSubmittedValue('item-quantity-' . $iItemId, $sFormMethod);
+
+                if($iItemQuantity <= 0)
+                    return echoJson(array('msg' => $this->_sLangsPrefix . 'err_wrong_quantity'));
+
+                $aItems[] = array(
+                    'id' => $iItemId, 
+                     $sPriceKey => $fItemPrice, 
+                    'quantity' => $iItemQuantity
+                );
+            }
+
+            $mixedResult = $this->_oModule->getObjectOrders()->addOrder(array(
+                'client_id' => $oForm->getCleanValue('client_id'),
+                'seller_id' => $oForm->getCleanValue('seller_id'),
+                'provider' => 'manual',
+                'type' => $sType,
+                'order' => $oForm->getCleanValue('order'),
+                'error_code' => 0,
+                'error_msg' => 'Manually processed',        		
+                'module_id' => $oForm->getCleanValue('module_id'),
+                'items' => $aItems
+            ));
+            if(is_array($mixedResult))
+                return echoJson($mixedResult);
+
+            $iPendingId = (int)$mixedResult;
+            if(!$this->_oModule->registerPayment($iPendingId))
+                return echoJson(array('msg' => _t($this->_sLangsPrefix . 'err_cannot_perform')));
+
+            $aOrders = $this->_oModule->_oDb->getOrderProcessed(array('type' => 'pending_id', 'pending_id' => $iPendingId, 'with_key' => 'id'));
             return echoJson(array('grid' => $this->getCode(false), 'blink' => array_keys($aOrders)));
         }
 
         $sKey = 'order_' . $this->_sOrdersType . '_add';
         $sId = $this->_oModule->_oConfig->getHtmlIds('processed', $sKey);
-    	$sTitle = _t($this->_sLangsPrefix . 'popup_title_ods_' . $sKey);
+        $sTitle = _t($this->_sLangsPrefix . 'popup_title_ods_' . $sKey);
+
+        $sContent = BxTemplStudioFunctions::getInstance()->popupBox($sId, $sTitle, $this->_oModule->_oTemplate->parseHtmlByName('order_processed_add.html', array(
+            'js_object' => $sJsObject,
+            'form_id' => $oForm->aFormAttrs['id'],
+            'form' => $oForm->getCode(true),
+            'object' => $this->_sObject,
+            'action' => $sAction
+        )));
+
+        echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
+    }
+
+    protected function _getFilterClients()
+    {
+        $aIds = $this->_oModule->_oDb->getOrderProcessed(array('type' => 'clients', 'seller_id' => $this->_aQueryAppend['seller_id']));
+
+        $aValues = array(
+            array('key' => '', 'value' => _t('_bx_payment_txt_all_clients'))
+        );
+        foreach($aIds as $iId)
+            if(($oClient = BxDolProfile::getInstanceMagic($iId)) !== false)
+                $aValues[] = array('key' => $iId, 'value' => $oClient->getDisplayName());
+
+        $this->_oModule->_oConfig->sortByColumn('value', $aValues);
+
+        return $this->_getFilterSelectAll('client', array(
+            'values' => $aValues
+        ));
+    }
+
+    protected function _getFilterModules()
+    {
+        $aModules = $this->_oModule->_oDb->getModules();
+        
+        $aValues = array(
+            array('key' => '', 'value' => _t('_bx_payment_txt_all_modules'))
+        );
+        foreach($aModules as $aModule) {
+            $sLangKey = '_' . $aModule['name'];
+            $sLangValue = _t($sLangKey);
+
+            $aValues[] = array('key' => $aModule['id'], 'value' => $sLangKey != $sLangValue ? $sLangValue : $aModule['title']);
+        }
+
+        $this->_oModule->_oConfig->sortByColumn('value', $aValues);
+
+        return $this->_getFilterSelectAll('module', array(
+            'js_onchange' => 'onChangeFilterModule(this, ' . $this->_aQueryAppend['seller_id'] . ')',
+            'values' => $aValues
+        ));
+    }
+
+    protected function _getFilterItems()
+    {
+        $aValues = array(
+            array('key' => '', 'value' => _t('_bx_payment_txt_all_items'))
+        );
+
+        return $this->_getFilterSelectAll('item', array(
+            'attrs' => array('disabled' => 'disabled'),
+            'values' => $aValues
+        ));
+    }
 
-		$sContent = BxTemplStudioFunctions::getInstance()->popupBox($sId, $sTitle, $this->_oModule->_oTemplate->parseHtmlByName('order_processed_add.html', array(
-			'js_object' => $sJsObject,
-			'form_id' => $oForm->aFormAttrs['id'],
-			'form' => $oForm->getCode(true),
-			'object' => $this->_sObject,
-			'action' => $sAction
-		)));
+    protected function _getFilterControls ()
+    {
+        parent::_getFilterControls();
 
-		echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
+        return $this->_getFilterClients() . $this->_getFilterModules() . $this->_getFilterItems() . $this->_getSearchInput();
     }
 
-	protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
+    protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
     {
     	if(empty($this->_aQueryAppend['seller_id']))
-    		return array();
+            return array();
+
+        $sParamsDivider = $this->_oModule->_oConfig->getDivider('DIVIDER_GRID_FILTERS');
+
+        $iClient = $iModule = $iItem = 0;
+        if(strpos($sFilter, $sParamsDivider) !== false)
+            list($iClient, $iModule, $iItem, $sFilter) = explode($sParamsDivider, $sFilter);
+
+        $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tt`.`seller_id`=?", $this->_aQueryAppend['seller_id']);
+
+        $iClient = (int)$iClient;
+        if($iClient != 0)
+            $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tt`.`client_id`=?", $iClient);
+        
+        $iModule = (int)$iModule;
+        if($iModule != 0)
+            $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tt`.`module_id`=?", $iModule);
 
-		$this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tt`.`seller_id`=?", $this->_aQueryAppend['seller_id']);
+        $iItem = (int)$iItem;
+        if($iItem != 0)
+            $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tt`.`item_id`=?", $iItem);
 
         return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
     }

+ 27 - 10
modules/boonex/payment/classes/BxPaymentModule.php

@@ -95,17 +95,17 @@ class BxPaymentModule extends BxBaseModPaymentModule
         $this->_iUserId = $this->getProfileId();
 
         $this->_aOrderTypes = array(
-        	BX_PAYMENT_ORDERS_TYPE_PENDING, 
-        	BX_PAYMENT_ORDERS_TYPE_PROCESSED, 
-        	BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION, 
-        	BX_PAYMENT_ORDERS_TYPE_HISTORY
+            BX_PAYMENT_ORDERS_TYPE_PENDING, 
+            BX_PAYMENT_ORDERS_TYPE_PROCESSED, 
+            BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION, 
+            BX_PAYMENT_ORDERS_TYPE_HISTORY
         );
     }
 
     /**
      * Manage Orders Methods
      */
-	public function actionGetClients()
+    public function actionGetClients()
     {
         $sTerm = bx_get('term');
 
@@ -119,11 +119,28 @@ class BxPaymentModule extends BxBaseModPaymentModule
     	$iSellerId = $this->getProfileId();
         $aItems = $this->callGetCartItems((int)$iModuleId, array($iSellerId));
 
-		echoJson(array(
-			'code' => 0, 
-		 	'eval' => $this->_oConfig->getJsObject('processed') . '.onSelectModule(oData);', 
-			'data' => $this->_oTemplate->displayItems($sType, $aItems)
-		));
+        echoJson(array(
+            'code' => 0, 
+            'eval' => $this->_oConfig->getJsObject('processed') . '.onSelectModule(oData);', 
+            'data' => $this->_oTemplate->displayItems($sType, $aItems)
+        ));
+    }
+
+    public function actionGetFilterValuesItem($iSellerId, $iModuleId)
+    {
+        $sItems = '<option value="">' . _t('_bx_payment_txt_all_items') . '</option>';
+
+        if(empty($iSellerId) || empty($iModuleId))
+            return echoJson(array('code' => 1, 'content' => $sItems));
+
+        $aItems = $this->callGetCartItems((int)$iModuleId, array($iSellerId));
+
+        $this->_oConfig->sortByColumn('title', $aItems);
+
+        foreach($aItems as $aItem)
+            $sItems .= '<option value="' . $aItem['id'] . '">' . $aItem['title'] . '</option>';
+
+        echoJson(array('code' => 0, 'content' => $sItems));
     }
 
     public function serviceGetSafeServices()

+ 10 - 5
modules/boonex/payment/classes/BxPaymentTemplate.php

@@ -210,16 +210,21 @@ class BxPaymentTemplate extends BxBaseModPaymentTemplate
         return 'Details would be here';
     }
 
-	public function displayBlockOrders($sType, $iSellerId)
+    public function displayBlockOrders($sType, $iSellerId)
     {
-    	$oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getObject('grid_' . $sType));
+        $sGrid = $this->_oConfig->getObject('grid_' . $sType);
+        $oGrid = BxDolGrid::getObjectInstance($sGrid);
         if(!$oGrid || empty($iSellerId))
             return MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
 
-		$oGrid->addQueryParam('seller_id', $iSellerId);
+        $oGrid->addQueryParam('seller_id', $iSellerId);
 
-		$this->addJsCssOrders();
-        return $this->displayJsCode($sType) . $oGrid->getCode();
+        $this->addJsCssOrders();
+        return $this->displayJsCode($sType, array(
+            'sObjNameGrid' => $sGrid,
+            'sParamsDivider' => $this->_oConfig->getDivider('DIVIDER_GRID_FILTERS'),
+            'sTextSearchInput' => _t('_sys_grid_search')
+        )) . $oGrid->getCode();
     }
 
     public function displayOrder($sType, $iId)

+ 3 - 0
modules/boonex/payment/install/langs/en.xml

@@ -274,6 +274,9 @@
 	<string name="_bx_payment_txt_no"><![CDATA[No]]></string>
         <string name="_bx_payment_txt_unsubscribe_yes"><![CDATA[Cancel automatically]]></string>
         <string name="_bx_payment_txt_unsubscribe_no"><![CDATA[Do not cancel]]></string>
+        <string name="_bx_payment_txt_all_clients"><![CDATA[All Clients]]></string>
+        <string name="_bx_payment_txt_all_modules"><![CDATA[All Modules]]></string>
+        <string name="_bx_payment_txt_all_items"><![CDATA[All Items]]></string>
 
         <!-- Credits payment provider -->
 	<string name="_bx_payment_cdt_cpt"><![CDATA[Credits]]></string>

+ 84 - 3
modules/boonex/payment/js/orders.js

@@ -13,15 +13,96 @@ function BxPaymentOrders(oOptions) {
 }
 
 BxPaymentOrders.prototype.init = function(oOptions) {
-	if($.isEmptyObject(oOptions))
-		return;
+    if($.isEmptyObject(oOptions))
+        return;
 
-	this._sActionsUrl = oOptions.sActionUrl;
+    this._sActionsUrl = oOptions.sActionUrl;
+    this._sObjNameGrid = oOptions.sObjNameGrid == undefined ? '' : oOptions.sObjNameGrid;
     this._sObjName = oOptions.sObjName == undefined ? 'oPaymentOrders' : oOptions.sObjName;
     this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
     this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
     this._iTimeout = (oOptions.iTimeout == undefined ? 5 : oOptions.iTimeout) * 1000;
     this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
+    this._sParamsDivider = oOptions.sParamsDivider == undefined ? '#-#' : oOptions.sParamsDivider;
+    this._sTextSearchInput = oOptions.sTextSearchInput == undefined ? '' : oOptions.sTextSearchInput;
+
+    this._iSearchTimeoutId = false;
+
+    var $this = this;
+    $(document).ready(function() {
+        $('#bx-grid-search-' + $this._sObjNameGrid).unbind('focusout');
+    });
+};
+
+/*--- Grid Filter function ---*/
+BxPaymentOrders.prototype.onChangeFilter = function(oElement) {
+    if(!this._sObjNameGrid)
+        return;
+
+    var $this = this;
+
+    var oClient = $('#bx-grid-client-' + this._sObjNameGrid);
+    var bClient = oClient.length > 0;
+    var sClient = bClient ? oClient.val() : '';
+
+    var oModule = $('#bx-grid-module-' + this._sObjNameGrid);
+    var bModule = oModule.length > 0;
+    var sModule = bModule ? oModule.val() : '';
+
+    var oItem = $('#bx-grid-item-' + this._sObjNameGrid);
+    var bItem = oItem.length > 0;
+    var sItem = bItem ? oItem.val() : '';
+
+    var sSearch = $('#bx-grid-search-' + this._sObjNameGrid).val();
+    if(sSearch == this._sTextSearchInput)
+        sSearch = '';
+
+    clearTimeout($this._iSearchTimeoutId);
+    $this._iSearchTimeoutId = setTimeout(function () {
+        var sValue = '';
+        if(bClient)
+            sValue += sClient + $this._sParamsDivider;
+        if(bModule)
+            sValue += sModule + $this._sParamsDivider;
+        if(bItem)
+            sValue += sItem + $this._sParamsDivider;
+        sValue += sSearch;
+
+    	glGrids[$this._sObjNameGrid].setFilter(sValue, true);
+    }, 500);
+};
+
+BxPaymentOrders.prototype.onChangeFilterModule = function(oElement, iSeller) {
+    var $this = this;
+    var oDate = new Date();
+
+    var iModule = parseInt($(oElement).val());
+    if(!iModule)
+        iModule = 0;
+
+    $.get(
+        this._sActionsUrl + 'get_filter_values_item/' + iSeller + '/' + iModule + '/',
+        {
+            _t:oDate.getTime()
+        },
+        function(oData) {
+            var oFilterItem = $('#bx-grid-item-' + $this._sObjNameGrid);
+
+            if(oData && oData.code != undefined)
+                switch(oData.code) {
+                    case 0:
+                        oFilterItem.html(oData.content).removeAttr('disabled');
+                        break;
+
+                    case 1:
+                        oFilterItem.html(oData.content).attr('disabled', 'disabled');
+                        break;
+                }
+
+            $this.onChangeFilter(oElement);
+        },
+        'json'
+    );
 };
 
 /*--- Manual Order function ---*/

+ 18 - 0
modules/boonex/payment/template/css/orders.css

@@ -71,3 +71,21 @@ div.bx-payment-vo-items {
     -o-text-overflow: ellipsis;
     white-space: nowrap;
 }
+
+
+/*--- Filters ---*/
+#bx-grid-wrap-bx_payment_grid_orders_processed div.bx-grid-header div.bx-form-element-wrapper {
+    position: relative;
+    float: left;
+    width: 165px;
+}
+#bx-grid-wrap-bx_payment_grid_orders_processed div.bx-grid-header div#bx-form-element-client,
+#bx-grid-wrap-bx_payment_grid_orders_processed div.bx-grid-header div#bx-form-element-module,
+#bx-grid-wrap-bx_payment_grid_orders_processed div.bx-grid-header div#bx-form-element-item {
+    margin-right: 20px;
+}
+#bx-grid-wrap-bx_payment_grid_orders_processed div.bx-grid-header div#bx-form-element-module,
+#bx-grid-wrap-bx_payment_grid_orders_processed div.bx-grid-header div#bx-form-element-item,
+#bx-grid-wrap-bx_payment_grid_orders_processed div.bx-grid-header div#bx-form-element-keyword {
+    margin-top: 0px;
+}