Skip to content

Commit 1bbf036

Browse files
Change wine alc total to acidity
Signed-off-by: Christoph Wurst <[email protected]>
1 parent 75d2cac commit 1bbf036

File tree

12 files changed

+90
-39
lines changed

12 files changed

+90
-39
lines changed

Diff for: app/Http/Controllers/WineController.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,8 @@ public function store(Competition $competition, Request $request): RedirectRespo
224224
if (isset($data['alcohol'])) {
225225
$data['alcohol'] = $this->commaToDot($data['alcohol']);
226226
}
227-
if (isset($data['alcoholtot'])) {
228-
if (! empty($data['alcoholtot'])) {
229-
$data['alcoholtot'] = $this->commaToDot($data['alcoholtot']);
230-
} else {
231-
unset($data['alcoholtot']);
232-
}
227+
if (isset($data['acidity'])) {
228+
$data['acidity'] = $this->commaToDot($data['acidity']);
233229
}
234230
if (isset($data['sugar'])) {
235231
$data['sugar'] = $this->commaToDot($data['sugar']);
@@ -332,10 +328,8 @@ public function update(Wine $wine, Request $request): RedirectResponse
332328
if (isset($data['alcohol'])) {
333329
$data['alcohol'] = $this->commaToDot($data['alcohol']);
334330
}
335-
if (isset($data['alcoholtot']) && $data['alcoholtot'] !== '') {
336-
$data['alcoholtot'] = $this->commaToDot($data['alcoholtot']);
337-
} else {
338-
$data['alcoholtot'] = null;
331+
if (isset($data['acidity'])) {
332+
$data['acidity'] = $this->commaToDot($data['acidity']);
339333
}
340334
if (isset($data['sugar'])) {
341335
$data['sugar'] = $this->commaToDot($data['sugar']);

Diff for: app/Wine.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* @property string $label
4646
* @property int $vintage
4747
* @property float $alcohol
48-
* @property float $alcoholtot
48+
* @property float $acidity
4949
* @property float $sugar
5050
* @property string $approvalnr
5151
* @property bool $kdb
@@ -79,7 +79,7 @@ class Wine extends Model implements AdministrateModel
7979
'winequality_id',
8080
'vintage',
8181
'alcohol',
82-
'alcoholtot',
82+
'acidity',
8383
'sugar',
8484
'kdb',
8585
'sosi',

Diff for: app/Wine/EnrollmentForm.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ private function addWineData(FPDF &$pdf)
147147
};
148148

149149
$pdf->Ln(10);
150-
$pdf->Cell(70, 10, 'vorhandener Alkohol: '.$commaToDot($this->wine->alcohol).'%vol');
151-
$pdf->Cell(85, 10, 'Gesamtalkohol (berechnet): '.$commaToDot($this->wine->alcoholtot).'%vol');
150+
$pdf->Cell(70, 10, 'Vorhandener Alkohol: '.$commaToDot($this->wine->alcohol).'%vol');
151+
$pdf->Cell(85, 10, 'Säure: '.$commaToDot($this->wine->acidity).'g/l');
152152
$pdf->Cell(70, 10, 'Zucker: '.$commaToDot($this->wine->sugar).'g/l');
153153

154154
$pdf->Ln(20);

Diff for: app/Wine/WineValidator.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ protected function getAttributeNames()
5757
'winesort_id' => 'Sorte',
5858
'winequality_id' => 'Qualit&auml;tsstufe',
5959
'vintage' => 'Jahrgang',
60-
'alcohol' => 'Alkohol',
61-
'alcoholtot' => 'Alkohol gesamt',
60+
'alcohol' => 'Vorhandener Alkohol',
61+
'acidity' => 'S&auml;ure',
6262
'sugar' => 'Zucker',
6363
'approvalnr' => 'Pr&uuml;fnummer',
6464
'kdb_certificate' => 'KdB-Urkunde',
@@ -102,7 +102,7 @@ protected function getCreateRules(array $data)
102102
'winequality_id' => 'Exists:winequality,id',
103103
'vintage' => 'required|integer|between:2000,2030',
104104
'alcohol' => 'required|numeric|between:0.1,30.0',
105-
'alcoholtot' => 'numeric|between:0.1,99.9',
105+
'acidity' => 'required|numeric|between:0.1,99.9',
106106
'sugar' => 'required|numeric|between:0.1,300.0',
107107
'approvalnr' => 'sometimes|alpha_num|max:20',
108108
'kdb_certificate' => 'sometimes|boolean',
@@ -131,7 +131,7 @@ protected function getUpdateRules(array $data, Model $model = null)
131131
'winequality_id' => 'Exists:winequality,id',
132132
'vintage' => 'required|integer|between:2000,2030',
133133
'alcohol' => 'required|numeric|between:0.1,30.0',
134-
'alcoholtot' => 'numeric|between:0.1,99.9',
134+
'acidity' => 'required|numeric|between:0.1,99.9',
135135
'sugar' => 'required|numeric|between:0.1,300.0',
136136
'approvalnr' => 'sometimes|alpha_num|max:20',
137137
'kdb_certificate' => 'sometimes|boolean',

Diff for: app/WineExport.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ class WineExport
6363
'Adresse',
6464
'WeinstandNr',
6565
'Weinstand',
66-
'Alkohol',
67-
'Alkohol ges.',
66+
'Vorhandener Alkohol',
67+
'Säure',
6868
'Zucker',
6969
'1. Bewertung',
7070
'2. Bewertung',
@@ -125,6 +125,7 @@ private function setExcelData(Worksheet $sheet)
125125
//data
126126
$row = 2;
127127
foreach ($this->wines as $w) {
128+
/* @var WineDetails $w */
128129
$sheet->setCellValue("A$row", $w->nr);
129130
$sheet->setCellValue("B$row", $w->winesort_order);
130131
$sheet->setCellValue("C$row", $w->winesort_name);
@@ -150,7 +151,7 @@ private function setExcelData(Worksheet $sheet)
150151
$sheet->setCellValue("Q$row", $w->applicant->association->id);
151152
$sheet->setCellValue("R$row", $w->applicant->association->name);
152153
$sheet->setCellValue("S$row", $w->alcohol);
153-
$sheet->setCellValue("T$row", $w->alcoholtot);
154+
$sheet->setCellValue("T$row", $w->acidity);
154155
$sheet->setCellValue("U$row", $w->sugar);
155156
if ($w->rating1) {
156157
$sheet->setCellValue("V$row", $w->rating1);

Diff for: database/factories/ModelFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function () {
9090
'label' => str_random(10),
9191
'vintage' => rand(2005, 2020),
9292
'alcohol' => rand(1, 200) / 10,
93-
'alcoholtot' => rand(1, 200) / 10,
93+
'acidity' => rand(1, 200) / 10,
9494
'sugar' => rand(1, 300) / 10,
9595
'approvalnr' => str_random(15),
9696
'winesort_id' => function () {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\DB;
8+
use Illuminate\Support\Facades\Schema;
9+
10+
class ChangeWineProps extends Migration
11+
{
12+
public function up(): void
13+
{
14+
Schema::table('wine', function (Blueprint $table) {
15+
$table->decimal('acidity', 3, 1)->default(0.0);
16+
$table->dropColumn('alcoholtot');
17+
});
18+
19+
$this->rebuildWineDetailsView();
20+
}
21+
22+
public function down(): void
23+
{
24+
Schema::table('wine', function (Blueprint $table) {
25+
$table->dropColumn('acidity');
26+
$table->decimal('alcoholtot', 3, 1)->default(0.0);
27+
});
28+
29+
$this->rebuildWineDetailsView();
30+
}
31+
32+
private function rebuildWineDetailsView(): void
33+
{
34+
$sql = <<<'SQL'
35+
CREATE OR REPLACE VIEW `wine_details` AS
36+
SELECT 1 as x, w.*, ws.`order` AS winesort_order, ws.name AS winesort_name, wq.id AS quality_id, wq.label AS quality_label, uapp.username AS applicant_username, uass.username AS association_username, harm_mean(tn1.id) AS rating1, harm_mean(tn2.id) AS rating2
37+
FROM wine w
38+
JOIN applicant app
39+
ON app.id = w.applicant_id
40+
JOIN association ass
41+
ON ass.id = app.association_id
42+
JOIN winesort ws
43+
ON ws.id = w.winesort_id
44+
LEFT OUTER JOIN winequality wq
45+
ON wq.id = w.winequality_id
46+
LEFT OUTER JOIN wuser uapp
47+
ON uapp.username = app.wuser_username
48+
LEFT OUTER JOIN wuser uass
49+
ON uass.username = ass.wuser_username
50+
LEFT OUTER JOIN tastingnumber AS tn1
51+
ON w.id = tn1.wine_id
52+
AND tn1.tastingstage_id = 1
53+
LEFT OUTER JOIN tastingnumber AS tn2
54+
ON w.id = tn2.wine_id
55+
AND tn2.tastingstage_id IN (2, NULL);
56+
SQL;
57+
58+
DB::unprepared($sql);
59+
}
60+
}

Diff for: database/seeders/WineTableSeeder.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private function randomWineSort()
4949
* @param string $label
5050
* @param int $vintage
5151
* @param float $alcohol
52-
* @param float $alcoholtot
52+
* @param float $acidity
5353
* @param float $sugar
5454
* @param int $competition
5555
* @param int $applicant
@@ -58,14 +58,14 @@ private function randomWineSort()
5858
* @param int $winequality
5959
* @return Wine
6060
*/
61-
public static function createWine($nr, $label, $vintage, $alcohol, $alcoholtot, $sugar, $competition, $applicant, $association, $winesort, $winequality)
61+
public static function createWine($nr, $label, $vintage, $alcohol, $acidity, $sugar, $competition, $applicant, $association, $winesort, $winequality)
6262
{
6363
return Wine::create([
6464
'nr' => $nr,
6565
'label' => $label,
6666
'vintage' => $vintage,
6767
'alcohol' => $alcohol,
68-
'alcoholtot' => $alcoholtot,
68+
'acidity' => $acidity,
6969
'sugar' => $sugar,
7070
'competition_id' => $competition,
7171
'association_id' => $association,

Diff for: resources/views/competition/wines/form.blade.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@
7171
</div>
7272
</div>
7373
<div class="form-group">
74-
{!! Form::Label('alcohol', 'Alkohol', array('class' => 'col-sm-2 col-md-2 control-label')) !!}
74+
{!! Form::Label('alcohol', 'Vorhandener Alkohol [%]', array('class' => 'col-sm-2 col-md-2 control-label')) !!}
7575
<div class="col-sm-10 col-md-1">
7676
{!! Form::text('alcohol', ($edit ? str_replace(".", ",", $wine['alcohol']) : ''), array('class' => 'form-control')) !!}
7777
</div>
7878
</div>
7979
<div class="form-group">
80-
{!! Form::Label('alcoholtot', 'Alkohol gesamt', array('class' => 'col-sm-2 col-md-2 control-label')) !!}
80+
{!! Form::Label('acidity', 'Säure [g/l]', array('class' => 'col-sm-2 col-md-2 control-label')) !!}
8181
<div class="col-sm-10 col-md-1">
82-
{!! Form::text('alcoholtot', ($edit ? str_replace(".", ",", $wine['alcoholtot']) : ''), array('class' => 'form-control')) !!}
82+
{!! Form::text('acidity', ($edit ? str_replace(".", ",", $wine['acidity']) : ''), array('class' => 'form-control')) !!}
8383
</div>
8484
</div>
8585
<div class="form-group">
86-
{!! Form::Label('sugar', 'Zucker', array('class' => 'col-sm-2 col-md-2 control-label')) !!}
86+
{!! Form::Label('sugar', 'Zucker [g/l]', array('class' => 'col-sm-2 col-md-2 control-label')) !!}
8787
<div class="col-sm-10 col-md-1">
8888
{!! Form::text('sugar', ($edit ? str_replace(".", ",", $wine['sugar']) : ''), array('class' => 'form-control')) !!}
8989
</div>

Diff for: resources/views/competition/wines/show.blade.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,14 @@ class="btn btn-default">
8181
</div>
8282

8383
<div class="col-md-6">
84-
Alkohol
84+
Säure
8585
</div>
8686
<div class="col-md-6">
87-
@if (!is_null($wine->alcoholtot))
88-
{{ str_replace(".", ",", $wine->alcoholtot) }}
89-
@else
90-
-
91-
@endif
87+
{{ str_replace(".", ",", $wine->acidity) }}
9288
</div>
9389

9490
<div class="col-md-6">
95-
Alkohol gesamt
91+
Vorhandener Alkohol
9692
</div>
9793
<div class="col-md-6">
9894
{{ str_replace(".", ",", $wine->alcohol) }}
@@ -110,4 +106,4 @@ class="btn btn-default">
110106
</div>
111107

112108

113-
@stop
109+
@stop

Diff for: src/templates/wine.hb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{{#if winequality}}{{ winequality.abbr }}{{else}}-{{/if}}
1818
</td>
1919
<td class="text-center">{{l10nFloat alcohol }}</td>
20-
<td class="text-center">{{#if alcoholtot}}{{ l10nFloat alcoholtot }}{{else}}-{{/if}}</td>
20+
<td class="text-center">{{l10nFloat acidity }}</td>
2121
<td class="text-center">{{l10nFloat sugar }}</td>
2222
{{#if show_rating1 }}
2323
<td class="text-center">{{#if rating1}}{{l10nFloat rating1 }}{{else}}-{{/if}}</td>{{/if}}

Diff for: src/templates/wine_table.hb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<th>Jahr</th>
1212
<th class="text-center">Qualit&auml;t</th>
1313
<th class="text-center">Alk.</th>
14-
<th class="text-center">Alk. ges.</th>
14+
<th class="text-center">Säure</th>
1515
<th class="text-center">Zucker</th>
1616
{{#if show_rating1 }}
1717
<th class="text-center">1. Bewertung</th>{{/if}}

0 commit comments

Comments
 (0)