Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit 8bef436

Browse files
author
Mario Basic
committed
Tax number on clients is no longer unique and required.
1 parent e1b63f2 commit 8bef436

File tree

8 files changed

+515
-7
lines changed

8 files changed

+515
-7
lines changed

app/Category.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
class Category extends Model
99
{
10+
/**
11+
* The attributes that are mass assignable.
12+
*
13+
* @var array
14+
*/
1015
protected $fillable = ['name'];
1116

1217
/**

app/Client.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@
77

88
class Client extends Model
99
{
10+
/**
11+
* The attributes that are mass assignable.
12+
*
13+
* @var array
14+
*/
1015
protected $fillable = ['name', 'tax_number', 'street', 'city', 'postal_code'];
1116

17+
/**
18+
* Get services which belong to this client.
19+
*
20+
* @return [type]
21+
*/
1222
public function services()
1323
{
1424
return $this->hasMany(Service::class);

app/Http/Controllers/ClientController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public function create()
3939
public function store(Request $request)
4040
{
4141
$this->validate($request, [
42-
'name' => 'required|max:255',
43-
'tax_number' => 'required|max:255|unique:clients',
42+
'name' => 'required|string|max:255',
43+
'tax_number' => 'string|max:255|unique:clients',
4444
'street' => 'string|max:255',
4545
'city' => 'string|max:255',
4646
'postal_code' => 'integer',
@@ -84,8 +84,8 @@ public function update(Request $request, $id)
8484
$client = Client::findOrFail($id);
8585

8686
$this->validate($request, [
87-
'name' => 'required|max:255',
88-
'tax_number' => 'required|max:255|unique:clients,tax_number,' . $client->id,
87+
'name' => 'required|string|max:255',
88+
'tax_number' => 'string|max:255|unique:clients,tax_number,' . $client->id,
8989
'street' => 'string|max:255',
9090
'city' => 'string|max:255',
9191
'postal_code' => 'integer',

app/Occurrence.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,58 @@
77

88
class Occurrence extends Model
99
{
10+
/**
11+
* The attributes that are mass assignable.
12+
*
13+
* @var array
14+
*/
1015
protected $fillable = ['occurs_at', 'offer_sent', 'payment_received', 'receipt_sent'];
1116

17+
/**
18+
* The attributes that should be mutated to dates.
19+
*
20+
* @var array
21+
*/
1222
protected $dates = ['occurs_at'];
1323

24+
/**
25+
* Gets a service that belongs to this occurrence.
26+
*
27+
* @return [type]
28+
*/
1429
public function service()
1530
{
1631
return $this->belongsTo(Service::class);
1732
}
1833

34+
/**
35+
* If the offer_sent is set to true, this
36+
* returns false.
37+
*
38+
* @return [type]
39+
*/
1940
public function getFutureOfferState()
2041
{
2142
return $this->offer_sent ? 0 : 1;
2243
}
2344

45+
/**
46+
* If the payment_received is set to true
47+
* this returns false.
48+
*
49+
* @return [type]
50+
*/
2451
public function getFuturePaymentState()
2552
{
2653
return $this->payment_received ? 0 : 1;
2754
}
2855

56+
/**
57+
* If the receipt_sent is set to true
58+
* this returns false.
59+
*
60+
* @return [type]
61+
*/
2962
public function getFutureReceiptState()
3063
{
3164
return $this->receipt_sent ? 0 : 1;

app/Service.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class Service extends Model
1313
{
1414
use FormAccessible;
1515

16+
/**
17+
* The attributes that are mass assignable.
18+
*
19+
* @var array
20+
*/
1621
protected $fillable = ['title', 'note', 'month', 'day', 'cost', 'currency', 'active', 'exchange_rate'];
1722

1823
/**
@@ -68,6 +73,16 @@ public function getFormattedCostAttribute()
6873
return number_format($this->cost / 100, 2, ',', '.') . ' ' . strtoupper($this->currency);
6974
}
7075

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+
*/
7186
public function getSum(Collection $services = null)
7287
{
7388
if(!($services instanceof Collection)) {
@@ -87,6 +102,16 @@ public function getSum(Collection $services = null)
87102
return number_format($sum, 2, ',', '.') . ' ' . $preferredCurrency;
88103
}
89104

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+
*/
90115
public function getSumForMonth(int $month, $onlyActive = false)
91116
{
92117
$services = $this->where('month', $month);

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"laravelcollective/html": "^5.2",
2121
"laravelista/ekko": "^1.2",
2222
"laracasts/flash": "^2.0",
23-
"florianv/laravel-swap": "^0.4.0"
23+
"florianv/laravel-swap": "^0.4.0",
24+
"doctrine/dbal": "^2.5"
2425
},
2526
"require-dev": {
2627
"fzaninotto/faker": "~1.4",

0 commit comments

Comments
 (0)