BxBaseModPaymentGridInvoices.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 BasePayment Base classes for Payment like modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModPaymentGridInvoices extends BxTemplGrid
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_oPayment;
  16. protected $_sLangsPrefix;
  17. protected $_aJsCodes;
  18. protected $_bAllowManage;
  19. protected $_iMainSeller;
  20. public function __construct ($aOptions, $oTemplate = false)
  21. {
  22. parent::__construct ($aOptions, $oTemplate);
  23. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  24. $this->_oPayment = BxDolPayments::getInstance();
  25. $this->_sLangsPrefix = $this->_oModule->_oConfig->getPrefix('langs');
  26. $this->_aJsCodes = array();
  27. $this->_bAllowManage = $this->_oModule->isAllowedManageInvoices() === true;
  28. if(!$this->_bAllowManage) {
  29. $iProfileId = bx_get('profile_id');
  30. $this->_aQueryAppend['profile_id'] = $iProfileId !== false ? (int)$iProfileId : bx_get_logged_profile_id();
  31. }
  32. $this->_iMainSeller = $this->_oModule->_oConfig->getSiteAdmin();
  33. }
  34. public function getCode($isDisplayHeader = true)
  35. {
  36. return parent::getCode($isDisplayHeader) . $this->getJsCode();
  37. }
  38. public function getJsCode()
  39. {
  40. if(empty($this->_aJsCodes) || !is_array($this->_aJsCodes))
  41. return '';
  42. return implode('', $this->_aJsCodes);
  43. }
  44. protected function _getActionEdit ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  45. {
  46. if(!$this->_bAllowManage)
  47. return '';
  48. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  49. }
  50. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  51. {
  52. if(!$this->_bAllowManage)
  53. return '';
  54. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  55. }
  56. protected function _getActionPay ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  57. {
  58. if($aRow['committent_id'] != bx_get_logged_profile_id() || (float)$aRow['amount'] == 0 || $aRow['status'] == BX_PAYMENT_INV_STATUS_PAID)
  59. return '';
  60. $aJs = $this->_oPayment->getAddToCartJs($this->_iMainSeller, $this->_sModule, $aRow['id'], 1, true);
  61. if(!empty($aJs) && is_array($aJs)) {
  62. list($sJsCode, $sJsMethod) = $aJs;
  63. $sJsCodeCheckSum = md5($sJsCode);
  64. if(!isset($this->_aJsCodes[$sJsCodeCheckSum]))
  65. $this->_aJsCodes[$sJsCodeCheckSum] = $sJsCode;
  66. $a['attr'] = array(
  67. 'title' => bx_html_attribute(_t('_bx_payment_grid_action_title_inv_pay')),
  68. 'onclick' => $sJsMethod
  69. );
  70. }
  71. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  72. }
  73. protected function _getCellHeaderCommissionaireId ($sKey, $aField)
  74. {
  75. if(!$this->_bAllowManage)
  76. return '';
  77. return parent::_getCellHeaderDefault($sKey, $aField);
  78. }
  79. protected function _getCellCommissionaireId($mixedValue, $sKey, $aField, $aRow)
  80. {
  81. if(!$this->_bAllowManage)
  82. return '';
  83. return parent::_getCellDefault($this->_oModule->_oTemplate->displayProfileLink($mixedValue), $sKey, $aField, $aRow);
  84. }
  85. protected function _getCellCommittentId($mixedValue, $sKey, $aField, $aRow)
  86. {
  87. return parent::_getCellDefault($this->_oModule->_oTemplate->displayProfileLink($mixedValue), $sKey, $aField, $aRow);
  88. }
  89. protected function _getCellPeriodStart($mixedValue, $sKey, $aField, $aRow)
  90. {
  91. return parent::_getCellDefault($this->_oModule->_oConfig->formatDate($mixedValue), $sKey, $aField, $aRow);
  92. }
  93. protected function _getCellPeriodEnd($mixedValue, $sKey, $aField, $aRow)
  94. {
  95. return parent::_getCellDefault($this->_oModule->_oConfig->formatDate($mixedValue), $sKey, $aField, $aRow);
  96. }
  97. protected function _getCellDateIssue($mixedValue, $sKey, $aField, $aRow)
  98. {
  99. return $this->_getCellDefaultDate($mixedValue, $sKey, $aField, $aRow);
  100. }
  101. protected function _getCellDateDue($mixedValue, $sKey, $aField, $aRow)
  102. {
  103. return $this->_getCellDefaultDate($mixedValue, $sKey, $aField, $aRow);
  104. }
  105. protected function _getCellStatus($mixedValue, $sKey, $aField, $aRow)
  106. {
  107. return parent::_getCellDefault(_t('_bx_payment_txt_status_' . $mixedValue), $sKey, $aField, $aRow);
  108. }
  109. protected function _getCellDefaultDate($mixedValue, $sKey, $aField, $aRow)
  110. {
  111. return parent::_getCellDefault(bx_time_js($mixedValue, BX_FORMAT_DATE, true), $sKey, $aField, $aRow);
  112. }
  113. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  114. {
  115. if(!$this->_bAllowManage) {
  116. if(empty($this->_aQueryAppend['profile_id']))
  117. return array();
  118. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `committent_id`=?", $this->_aQueryAppend['profile_id']);
  119. }
  120. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  121. }
  122. }
  123. /** @} */