AbstractAccounting.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ 2WsMNNNDj0TclgB0DHZdu59pP8slMnF4TXqN60b/5gs=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2015 Online Ventures Software & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.5
  11. */
  12. /**
  13. * abstract accounting/transactions table row object model
  14. */
  15. namespace Ppb\Db\Table\Row;
  16. abstract class AbstractAccounting extends AbstractRow
  17. {
  18. /**
  19. *
  20. * accounting/transactions row invoice details link
  21. *
  22. * @return array
  23. */
  24. public function link()
  25. {
  26. $array = array(
  27. 'action' => 'view-invoice',
  28. );
  29. $array['type'] = ($this->getData('transaction_type') == 'receipt') ? 'transactions' : 'accounting';
  30. if ($this->getData('listing_id')) {
  31. $array['listing_id'] = $this->getData('listing_id');
  32. }
  33. else {
  34. $array['id'] = $this->getData('id');
  35. }
  36. return $array;
  37. }
  38. /**
  39. *
  40. * only the admin and the owner can view the row
  41. *
  42. * @return bool
  43. */
  44. public function canView()
  45. {
  46. $user = $this->getUser();
  47. if ($user->getData('id') == $this->getData('user_id') || $user->getData('role') == 'Admin') {
  48. return true;
  49. }
  50. return false;
  51. }
  52. /**
  53. *
  54. * return the amount without tax
  55. *
  56. * @return float
  57. */
  58. public function amountNoTax()
  59. {
  60. return $this->getData('amount') - $this->taxAmount();
  61. }
  62. /**
  63. *
  64. * return the tax amount
  65. *
  66. * @return float
  67. */
  68. public function taxAmount()
  69. {
  70. $amount = $this->getData('amount');
  71. $taxRate = (1 + $this->getData('tax_rate') / 100);
  72. return round(($amount - ($amount / $taxRate)), 2);
  73. }
  74. /**
  75. *
  76. * return total amount
  77. *
  78. * @return float
  79. */
  80. public function totalAmount()
  81. {
  82. return $this->getData('amount');
  83. }
  84. /**
  85. *
  86. * return the name of the transaction row for display purposes
  87. *
  88. * @return string
  89. */
  90. public function displayName()
  91. {
  92. $name = \Ppb\Utility::unserialize($this->getData('name'));
  93. if (is_array($name)) {
  94. $translate = $this->getTranslate();
  95. $string = (null !== $translate) ? $translate->_($name['string']) : $name['string'];
  96. return vsprintf($string, $name['args']);
  97. }
  98. return $name;
  99. }
  100. abstract public function caption();
  101. }