Invoice.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\Core\Models\Whmcs;
  3. use \Illuminate\Database\Eloquent\Model as EloquentModel;
  4. /**
  5. * Description of Product
  6. *
  7. * @author Paweł Złamaniec <pawel.zl@thurdata.com>
  8. */
  9. class Invoice extends EloquentModel
  10. {
  11. /**
  12. * Table name
  13. *
  14. * @var string
  15. */
  16. protected $table = 'tblinvoices';
  17. protected $primaryKey = 'id';
  18. /**
  19. * Eloquent guarded parameters
  20. * @var array
  21. */
  22. protected $guarded = ['id'];
  23. /**
  24. * Eloquent fillable parameters
  25. * @var array
  26. */
  27. protected $fillable = ['userid', 'invoicenum', 'date', 'duedate', 'datepaid', 'subtotal', 'credit', 'tax', 'tax2', 'total', 'taxrate', 'taxrate2', 'status', 'paymentmethod', 'notes'];
  28. /**
  29. * Indicates if the model should soft delete.
  30. *
  31. * @var bool
  32. */
  33. protected $softDelete = false;
  34. /**
  35. * Indicates if the model should be timestamped.
  36. *
  37. * @var bool
  38. */
  39. public $timestamps = false;
  40. public function __construct(array $attributes = [])
  41. {
  42. parent::__construct($attributes);
  43. }
  44. /**
  45. * Add relation to invoice items
  46. *
  47. * @return type
  48. */
  49. public function items()
  50. {
  51. return $this->hasMany("ThurData\Servers\KerioEmail\Core\Models\Whmcs\InvoiceItem", "invoiceid");
  52. }
  53. public function transactions()
  54. {
  55. return $this->hasMany("ThurData\Servers\KerioEmail\Core\Models\Whmcs\Transaction", "invoiceid");
  56. }
  57. public function client()
  58. {
  59. return $this->belongsTo("ThurData\Servers\KerioEmail\Core\Models\Whmcs\Client", "userid");
  60. }
  61. public function order()
  62. {
  63. return $this->belongsTo("ThurData\Servers\KerioEmail\Core\Models\Whmcs\Order", "id", "invoiceid");
  64. }
  65. public function getAmountpaidAttribute()
  66. {
  67. $total = 0;
  68. foreach ($this->transactions as $trans)
  69. {
  70. $total += $trans->amountin - $trans->amountout;
  71. }
  72. return $total;
  73. }
  74. }