Skip to content

Commit

Permalink
[REWE] Show informations about markets
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu committed Dec 30, 2020
1 parent 784a6b7 commit ea373d0
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 4 deletions.
19 changes: 19 additions & 0 deletions app/Http/Controllers/ReweController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\ReweBon;
use App\ReweBonPosition;
use App\ReweProduct;
use App\ReweShop;
use App\User;
use App\UserSettings;
use Illuminate\Contracts\Support\Renderable;
Expand Down Expand Up @@ -217,4 +218,22 @@ public function showProduct(int $id): Renderable {
]);
}

public function showShop(int $id): Renderable {
$shop = ReweShop::findOrFail($id);

$history = ReweBon::where('user_id', Auth::user()->id)
->where('shop_id', $shop->id)
->orderBy('timestamp_bon', 'DESC')
->select(['id', 'cashregister_nr', 'paymentmethod', 'user_id', 'shop_id', 'timestamp_bon', 'total'])
->paginate(7);

$countOther = ReweBon::where('shop_id', $shop->id)->select(['user_id'])->groupBy(['user_id'])->count();

return view('rewe_ebon.shop', [
'shop' => $shop,
'history' => $history,
'countOther' => $countOther - 1
]);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddUserShopIndexToReweBons extends Migration {

public function up(): void {
Schema::table('rewe_bons', function(Blueprint $table) {
$table->index(['user_id', 'shop_id']);
});
}


public function down(): void {
Schema::table('rewe_bons', function(Blueprint $table) {
$table->dropIndex(['user_id', 'shop_id']);
});
}
}
6 changes: 4 additions & 2 deletions resources/views/rewe_ebon/overview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ class="mdi mdi-trending-up"
<tr>
<td data-order="{{$bon->timestamp_bon}}">{{$bon->timestamp_bon->format('d.m.Y H:i')}}</td>
<td>
{{$bon->shop->name}}<br/>
{{$bon->shop->zip}} {{$bon->shop->city}}
<a href="{{route('rewe.shop', ['id' => $bon->shop->id])}}">
Markt {{$bon->shop->id}}<br/>
<small>in {{$bon->shop->zip}} {{$bon->shop->city}}</small>
</a>
</td>
<td>{{$bon->cashregister_nr}}</td>
<td>{{$bon->paymentmethod}}</td>
Expand Down
6 changes: 4 additions & 2 deletions resources/views/rewe_ebon/receipt_details.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
<tr>
<td>{{__('receipts.market')}}</td>
<td>
{{$bon->shop->name}}<br/>
{{$bon->shop->zip}} {{$bon->shop->city}}
<a href="{{route('rewe.shop', ['id' => $bon->shop->id])}}">
Markt {{$bon->shop->id}}<br/>
<small>in {{$bon->shop->zip}} {{$bon->shop->city}}</small>
</a>
</td>
</tr>
<tr>
Expand Down
70 changes: 70 additions & 0 deletions resources/views/rewe_ebon/shop.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@extends('layout.app')

@section('title') REWE Markt {{$shop->id}} in {{$shop->zip}} {{$shop->city}} @endsection

@section('content')
<div class="row">
<div class="col-md-7">
<div class="card">
<div class="card-body">
<table class="table">
<thead>
<tr>
<th>Zeitpunkt</th>
<th>Kasse</th>
<th>Zahlungsmethode</th>
<th>Betrag</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach($history as $receipt)
<tr>
<td>{{$receipt->timestamp_bon->format('d.m.Y H:i')}}</td>
<td>{{$receipt->cashregister_nr}}</td>
<td>{{$receipt->paymentmethod}}</td>
<td>{{number_format($receipt->total, 2, ",", ".")}} €</td>
<td><a href="{{ route('rewe_receipt', [$receipt->id]) }}">Details</a></td>
</tr>
@endforeach
</tbody>
</table>
{{$history->links()}}
</div>
</div>
</div>
<div class="col-md-5">
<div class="card">
<div class="card-body" style="font-size: 16px;">
<h2>Einkaufsfreunde</h2>
@if($countOther == 0)
<p>Du bist bisher <b>der einzige KStats-Nutzer</b>, welcher in diesem REWE-Markt einkaufen war!
</p>
@elseif($countOther > 1)
<p>Du hast <b>einen</b> Einkaufsfreund, denn neben dir hat <b>ein weiterer KStats-Nutzer</b> in
diesem
REWE-Markt eingekauft.</p>
@else
<p>Dieser REWE-Markt scheint beliebt zu sein. Neben dir haben hier bereits <b>{{$countOther}}
andere KStats-Nutzer</b> eingekauft!</p>
@endif
</div>
</div>

<div class="card">
<div class="card-body">
<h2>{{$shop->name}}</h2>
{{$shop->address}}<br/>
{{$shop->zip}} {{$shop->city}}<br/>
<hr/>
@isset($shop->phone)
{{$shop->phone}}<br/>
@endisset
@isset($shop->opening_hours)
{{$shop->opening_hours}}<br/>
@endisset
</div>
</div>
</div>
</div>
@endsection
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
->name('download_raw_rewe_receipt');
Route::get('/rewe/product/{id}', [ReweController::class, 'showProduct'])
->name('rewe.product');
Route::get('/rewe/shop/{id}', [ReweController::class, 'showShop'])
->name('rewe.shop');

Route::get('/crowdsourcing/rewe/', [CrowdsourceController::class, 'renderRewe'])
->name('crowdsourcing_rewe');
Expand Down

0 comments on commit ea373d0

Please sign in to comment.