Skip to content

Commit

Permalink
Merge pull request #1 from AndreasSchantl/v1.1
Browse files Browse the repository at this point in the history
V1.1
  • Loading branch information
andjsch authored Jan 21, 2020
2 parents 7d69c40 + b545476 commit c1ade6d
Show file tree
Hide file tree
Showing 48 changed files with 109,422 additions and 52,780 deletions.
12 changes: 12 additions & 0 deletions app/Bill.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@

class Bill extends Model
{
protected $fillable = [
'description',
'date',
'amount',
'type',
'guarantee',
];

protected $dates = [
'date',
'created_at',
'updated_at'
];

protected $attributes = [
'guarantee' => false
];

public function typeO()
{
return $this->hasOne(ExpenseType::class, 'id', 'type');
Expand Down
60 changes: 20 additions & 40 deletions app/Http/Controllers/BillController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace App\Http\Controllers;

use App\Bill;
use App\ExpenseType;
use Carbon\Carbon;
use Ramsey\Uuid\Exception\UnsupportedOperationException;

class BillController extends Controller
{
Expand All @@ -17,34 +17,31 @@ public function index()
{
$this->validate(request(), [
'month' => 'numeric',
'year' => 'numeric'
'year' => 'numeric',
]);

$month = request('month') ?? Carbon::now()->month;
$year = request('year') ?? Carbon::now()->year;

if($month != 0) {
if ($month != 0) {
$billBuilder = Bill::whereMonth('date', '=', $month)->whereYear('date', '=', $year);
} else {
$billBuilder = Bill::whereYear('date', '=', $year);
}

if (request('search')) {
$types = ExpenseType::where('name', 'LIKE', '%' . request('search') . '%')->get()->pluck('id')->toArray();

$billBuilder = $billBuilder->where('description', 'LIKE', '%' . request('search') . '%')
->orWhereIn('type', $types);
}

$bills = $billBuilder->orderBy('date')->get();
$total = $billBuilder->sum('amount');

return view('bills.index', array('month' => $month, 'year' => $year, 'bills' => $bills, 'total' => $total));
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
throw new UnsupportedOperationException();
}

/**
* Store a newly created resource in storage.
*
Expand All @@ -57,15 +54,11 @@ public function store()
'description' => 'required|min:3|max:70',
'amount' => 'required|numeric',
'type' => 'required',
'date' => 'required|date'
'date' => 'required|date',
'guarantee' => 'boolean'
]);

$bill = new Bill();
$bill->description = request('description');
$bill->amount = request('amount');
$bill->type = request('type');
$bill->date = request('date');
$bill->guarantee = (boolean)request('guarantee');
$bill = Bill::create(request()->all());

try {
$bill->save();
Expand All @@ -75,17 +68,6 @@ public function store()
}
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
throw new UnsupportedOperationException();
}

/**
* Show the form for editing the specified resource.
*
Expand All @@ -111,27 +93,25 @@ public function update($id)
'description' => 'required|min:3|max:70',
'amount' => 'required|numeric',
'type' => 'required',
'date' => 'required|date'
'date' => 'required|date',
'guarantee' => 'boolean'
]);

$bill = Bill::findOrFail($id);
$bill->description = request('description');
$bill->amount = request('amount');
$bill->type = request('type');
$bill->date = request('date');
$bill->guarantee = (boolean)request('guarantee');
$bill->guarantee = false;
$bill->fill(request()->all());

try {
$bill->save();

return redirect('/expenses')->with('info', __('app.exp_info_updated', ['date' => $bill->date->format(env('DATE_FORMAT')), 'desc' => $bill->description]));
} catch(\Exception $e) {
} catch (\Exception $e) {
return back()->withErrors($e->getMessage());
}
}

/**
* Remove the specified resource from storage.
* Remove a bill
*
* @param int $id
* @return \Illuminate\Http\Response
Expand All @@ -144,7 +124,7 @@ public function destroy($id)
try {
$bill->delete();
return back()->with('info', __('app.exp_info_deleted', ['date' => $bill->date->format(env('DATE_FORMAT')), 'desc' => $bill->description]));
} catch(\Exception $e) {
} catch (\Exception $e) {
return back()->withErrors($e->getMessage());
}
}
Expand Down
50 changes: 25 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@
"license": "MIT",
"type": "project",
"require": {
"php": "^7.1.3",
"php": "^7.2",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.6.*",
"laravel/tinker": "^1.0"
"laravel/framework": "^6.2",
"laravel/tinker": "^2.0",
"marvinlabs/laravel-discord-logger": "^1.1"
},
"require-dev": {
"filp/whoops": "^2.0",
"facade/ignition": "^1.4",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0"
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^8.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"classmap": [
Expand All @@ -31,29 +42,18 @@
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover"
"@php artisan key:generate --ansi"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
Loading

0 comments on commit c1ade6d

Please sign in to comment.