@@ -13,6 +13,11 @@ class Service extends Model
13
13
{
14
14
use FormAccessible;
15
15
16
+ /**
17
+ * The attributes that are mass assignable.
18
+ *
19
+ * @var array
20
+ */
16
21
protected $ fillable = ['title ' , 'note ' , 'month ' , 'day ' , 'cost ' , 'currency ' , 'active ' , 'exchange_rate ' ];
17
22
18
23
/**
@@ -68,6 +73,16 @@ public function getFormattedCostAttribute()
68
73
return number_format ($ this ->cost / 100 , 2 , ', ' , '. ' ) . ' ' . strtoupper ($ this ->currency );
69
74
}
70
75
76
+ /**
77
+ * Gets the sum of all services, converted to user's
78
+ * preferred currency with current exchange rate.
79
+ *
80
+ * It is possible to pass a collection of services to this method,
81
+ * and it will return the sum of that collection.
82
+ *
83
+ * @param Collection|null $services
84
+ * @return [type]
85
+ */
71
86
public function getSum (Collection $ services = null )
72
87
{
73
88
if (!($ services instanceof Collection)) {
@@ -87,6 +102,16 @@ public function getSum(Collection $services = null)
87
102
return number_format ($ sum , 2 , ', ' , '. ' ) . ' ' . $ preferredCurrency ;
88
103
}
89
104
105
+ /**
106
+ * Gets the sum of all services, converted to user's
107
+ * preferred currency with current exchange rate for the entered month.
108
+ *
109
+ * By default, all services are included (active and non active).
110
+ *
111
+ * @param int $month
112
+ * @param boolean $onlyActive
113
+ * @return [type]
114
+ */
90
115
public function getSumForMonth (int $ month , $ onlyActive = false )
91
116
{
92
117
$ services = $ this ->where ('month ' , $ month );
0 commit comments