BxPaymentGridProcessed.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Payment Payment
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. class BxPaymentGridProcessed extends BxBaseModPaymentGridOrders
  12. {
  13. public function __construct ($aOptions, $oTemplate = false)
  14. {
  15. $this->MODULE = 'bx_payment';
  16. parent::__construct ($aOptions, $oTemplate);
  17. $this->_sOrdersType = 'processed';
  18. }
  19. public function performActionAdd()
  20. {
  21. $sAction = 'add';
  22. $sJsObject = $this->_oModule->_oConfig->getJsObject('processed');
  23. $sFormObject = $this->_oModule->_oConfig->getObject('form_processed');
  24. $sFormDisplay = $this->_oModule->_oConfig->getObject('display_processed_add');
  25. $oForm = BxDolForm::getObjectInstance($sFormObject, $sFormDisplay, $this->_oModule->_oTemplate);
  26. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction;
  27. $oForm->aInputs['seller_id']['value'] = $this->_aQueryAppend['seller_id'];
  28. $oForm->aInputs['client_id']['attrs'] = array(
  29. 'id' => $this->_oModule->_oConfig->getHtmlIds('processed', 'order_processed_client_id'),
  30. );
  31. $oForm->aInputs['client']['attrs'] = array(
  32. 'id' => $this->_oModule->_oConfig->getHtmlIds('processed', 'order_processed_client'),
  33. );
  34. $oForm->aInputs['module_id']['attrs'] = array(
  35. 'onchange' => 'javascript:' . $sJsObject . '.paOnSelectModule(this);'
  36. );
  37. $oForm->aInputs['module_id']['values'] = array(
  38. array('key' => '0', 'value' => _t('_Select_one'))
  39. );
  40. $aModules = $this->_oModule->_oDb->getModules();
  41. foreach($aModules as $aModule)
  42. $oForm->aInputs['module_id']['values'][] = array('key' => $aModule['id'], 'value' => $aModule['title']);
  43. $oForm->aInputs['items']['content'] = $this->_oModule->_oTemplate->displayItems();
  44. $oForm->initChecker();
  45. if($oForm->isSubmittedAndValid()) {
  46. $sFormMethod = $oForm->aFormAttrs['method'];
  47. $aItemIds = $oForm->getSubmittedValue('items', $sFormMethod);
  48. if(empty($aItemIds) || !is_array($aItemIds))
  49. return echoJson(array('msg' => $this->_sLangsPrefix . 'err_empty_items'));
  50. $aItems = array();
  51. foreach($aItemIds as $iItemId) {
  52. $iItemId = (int)$iItemId;
  53. $fItemPrice = (float)$oForm->getSubmittedValue('item-price-' . $iItemId, $sFormMethod);
  54. $iItemQuantity = (int)$oForm->getSubmittedValue('item-quantity-' . $iItemId, $sFormMethod);
  55. if($iItemQuantity <= 0)
  56. return echoJson(array('msg' => $this->_sLangsPrefix . 'err_wrong_quantity'));
  57. $aItems[] = array('id' => $iItemId, 'price' => $fItemPrice, 'quantity' => $iItemQuantity);
  58. }
  59. $mixedResult = $this->_oModule->getObjectOrders()->addOrder(array(
  60. 'client_id' => $oForm->getCleanValue('client_id'),
  61. 'seller_id' => $oForm->getCleanValue('seller_id'),
  62. 'provider' => 'manual',
  63. 'type' => BX_PAYMENT_TYPE_SINGLE,
  64. 'order' => $oForm->getCleanValue('order'),
  65. 'error_code' => 0,
  66. 'error_msg' => 'Manually processed',
  67. 'module_id' => $oForm->getCleanValue('module_id'),
  68. 'items' => $aItems
  69. ));
  70. if(is_array($mixedResult))
  71. return echoJson($mixedResult);
  72. $iPendingId = (int)$mixedResult;
  73. if(!$this->_oModule->registerPayment($iPendingId))
  74. return echoJson(array('msg' => _t($this->_sLangsPrefix . 'err_cannot_perform')));
  75. $aOrders = $this->_oModule->_oDb->getOrderProcessed(array('type' => 'pending_id', 'pending_id' => $iPendingId, 'with_key' => 'id'));
  76. return echoJson(array('grid' => $this->getCode(false), 'blink' => array_keys($aOrders)));
  77. }
  78. $sKey = 'order_' . $this->_sOrdersType . '_add';
  79. $sId = $this->_oModule->_oConfig->getHtmlIds($sKey);
  80. $sTitle = _t($this->_sLangsPrefix . 'grid_orders_popup_' . $sKey);
  81. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($sId, $sTitle, $this->_oModule->_oTemplate->parseHtmlByName('order_processed_add.html', array(
  82. 'js_object' => $sJsObject,
  83. 'form_id' => $oForm->aFormAttrs['id'],
  84. 'form' => $oForm->getCode(true),
  85. 'object' => $this->_sObject,
  86. 'action' => $sAction
  87. )));
  88. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  89. }
  90. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  91. {
  92. if(empty($this->_aQueryAppend['seller_id']))
  93. return array();
  94. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepare(" AND `tt`.`seller_id`=?", $this->_aQueryAppend['seller_id']);
  95. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  96. }
  97. }
  98. /** @} */