BxPaymentGridInvoices.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 BxPaymentGridInvoices extends BxBaseModPaymentGridInvoices
  12. {
  13. public function __construct ($aOptions, $oTemplate = false)
  14. {
  15. $this->_sModule = 'bx_payment';
  16. parent::__construct ($aOptions, $oTemplate);
  17. }
  18. public function performActionEdit()
  19. {
  20. $CNF = &$this->_oModule->_oConfig->CNF;
  21. $aIds = bx_get('ids');
  22. if(!$aIds || !is_array($aIds)) {
  23. $iId = (int)bx_get('id');
  24. if(!$iId)
  25. return echoJson(array());
  26. $aIds = array($iId);
  27. }
  28. $iId = (int)array_shift($aIds);
  29. $aInvoice = $this->_oModule->_oDb->getInvoices(array('type' => 'id', 'id' => $iId));
  30. if(empty($aInvoice) || !is_array($aInvoice))
  31. return echoJson(array());
  32. $sAction = 'edit';
  33. $oForm = $this->_getFormObject($sAction, $iId);
  34. $oForm->initChecker($aInvoice);
  35. if($oForm->isSubmittedAndValid()) {
  36. if($oForm->update($iId) !== false)
  37. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  38. else
  39. $aRes = array('msg' => _t('_bx_payment_err_cannot_perform'));
  40. return echoJson($aRes);
  41. }
  42. $sId = $this->_oModule->_oConfig->getHtmlIds('invoice', 'popup_' . $sAction);
  43. $sTitle = _t($this->_sLangsPrefix . 'popup_title_cms_' . $sAction);
  44. $sContent = BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $this->_oModule->_oTemplate->parseHtmlByName('commission_form.html', array(
  45. 'form_id' => $oForm->aFormAttrs['id'],
  46. 'form' => $oForm->getCode(true),
  47. 'object' => $this->_sObject,
  48. 'action' => $sAction
  49. )));
  50. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  51. }
  52. protected function _getFormObject($sAction, $iId = 0)
  53. {
  54. $sFormObject = $this->_oModule->_oConfig->getObject('form_invoices');
  55. $sFormDisplay = $this->_oModule->_oConfig->getObject('form_display_invoices_' . $sAction);
  56. $aParams = array('o' => $this->_sObject, 'a' => $sAction);
  57. if(!empty($iId))
  58. $aParams['id'] = $iId;
  59. $oForm = BxDolForm::getObjectInstance($sFormObject, $sFormDisplay);
  60. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . bx_append_url_params('grid.php', $aParams);
  61. return $oForm;
  62. }
  63. }
  64. /** @} */