BxPaymentGridProcessed.php 5.0 KB

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