AbstractAccounting.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * accounting table rowset class
  14. * @7.5 added currency method, to get the currency of the rowset - required in case the default currency has been changed
  15. */
  16. namespace Ppb\Db\Table\Rowset;
  17. use Ppb\Db\Table\Row\AbstractAccounting as AbstractAccountingRow;
  18. abstract class AbstractAccounting extends AbstractRowset
  19. {
  20. /**
  21. *
  22. * calculate the amount w/o tax for the selected rowset
  23. *
  24. * @return float
  25. */
  26. public function amountNoTax()
  27. {
  28. $amount = 0;
  29. /** @var \Ppb\Db\Table\Row\AbstractAccounting $row */
  30. foreach ($this->_rows as $row) {
  31. $amount += $row->amountNoTax();
  32. }
  33. return $amount;
  34. }
  35. /**
  36. *
  37. * calculate the total amount for the selected rowset
  38. *
  39. * @return float
  40. */
  41. public function totalAmount()
  42. {
  43. $amount = 0;
  44. /** @var \Ppb\Db\Table\Row\AbstractAccounting $row */
  45. foreach ($this->_rows as $row) {
  46. $amount += $row->totalAmount();
  47. }
  48. return $amount;
  49. }
  50. /**
  51. *
  52. * calculate the tax amount for the selected rowset
  53. *
  54. * @return float
  55. */
  56. public function taxAmount()
  57. {
  58. return $this->totalAmount() - $this->amountNoTax();
  59. }
  60. /**
  61. *
  62. * get rowset currency
  63. *
  64. * @return string|null
  65. */
  66. public function currency()
  67. {
  68. /** @var \Ppb\Db\Table\Row\AbstractAccounting $row */
  69. $row = $this->_rows[0];
  70. if ($row instanceof AbstractAccountingRow) {
  71. return $row->getData('currency');
  72. }
  73. return null;
  74. }
  75. }