Skip to content

Commit

Permalink
potenziato seeder per demo
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Nov 12, 2023
1 parent 6bcfc02 commit b486c2d
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 43 deletions.
2 changes: 1 addition & 1 deletion code/database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function roleInit($gas)

private function categoryInit()
{
$categories = ['Non Specificato', 'Frutta', 'Verdura', 'Cosmesi', 'Bevande'];
$categories = ['Non Specificato', 'Frutta', 'Verdura', 'Cosmesi', 'Bevande', 'Pezzi'];
foreach ($categories as $cat) {
Category::create([
'id' => Str::slug($cat),
Expand Down
241 changes: 202 additions & 39 deletions code/database/seeders/DemoSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Hash;

use Hash;
use Carbon\Carbon;

use App\Gas;
use App\User;
use App\Role;
use App\Supplier;
use App\Aggregate;
use App\Order;
use App\Product;
use App\Variant;
use App\VariantValue;
use App\Date;
use App\Measure;
use App\Category;
use App\VatRate;
use App\Delivery;
use App\Modifier;

class DemoSeeder extends Seeder
{
Expand All @@ -26,60 +34,215 @@ public function run()
$gas->message = "Questa istanza permette di avere una idea del funzionamento di GASdottoNG.\n\nPer accedere:\nUtente amministratore: username: root, password: root\nUtente non privilegiato: username: user, password: user\n\nL'inoltro di messaggi email da questa istanza è deliberatamente disabilitato, per evitare abusi.\n\nQuesta istanza viene quotidianamente rinnovata con le ultimissime modifiche (al contrario delle istanze hostate su gasdotto.net, sulle quali viene condotto qualche test in più prima della pubblicazione). GASdottoNG è un progetto in continua evoluzione: se noti qualcosa che non va, o una funzione che manca, mandaci una mail a [email protected]";
$gas->save();

User::create([
'id' => str_slug('Utente Normale'),
'gas_id' => $gas->id,
'member_since' => date('Y-m-d', time()),
'username' => 'user',
'firstname' => 'Mario',
'lastname' => 'Rossi',
'password' => Hash::make('user'),
]);
$del = new Delivery();
$del->name = 'Cooperativa Pippo';
$del->address = 'Via Roma 42, Torino, 10100';
$del->default = 1;
$del->save();

$mod = new Modifier();
$mod->modifier_type_id = 'spese-trasporto';
$mod->target_type = Delivery::class;
$mod->target_id = $del->id;
$mod->applies_target = 'booking';
$mod->definition = '[{"threshold":9223372036854775807,"amount":"3"}]';
$mod->movement_type_id = 'donation-to-gas';
$mod->save();

$users = [
['user', 'Giuseppe', 'Garibaldi'],
['verdi', 'Giuseppe', 'Verdi'],
['mazzini', 'Giuseppe', 'Mazzini'],
['azeglio', 'Massimo', "D'Azeglio"],
['pisacane', 'Carlo', 'Pisacane'],
['bandiera', 'Attilio', 'Bandiera'],
['benso', 'Camillo', 'Benso'],
];

foreach($users as $user) {
$u = new User();
$u->gas_id = $gas->id;
$u->member_since = date('Y-m-d');
$u->username = $user[0];
$u->firstname = $user[1];
$u->lastname = $user[2];
$u->password = Hash::make('user');
$u->save();
}

$role = roleByIdentifier('user');
$role->enableAction('users.subusers');

$referrer_role = Role::where('name', 'Referente')->first();
$administrator = User::where('username', 'root')->first();

$data = [
'Fornitore delle Mele' => [
'Mele Rosse',
'Mele Gialle',
'Mele Verdi',
],
'Fornitore delle Arance' => [
'Arance',
'Mandarini',
'Clementine',
],
];
$u = new User();
$u->gas_id = $gas->id;
$u->parent_id = $administrator->id;
$u->member_since = date('Y-m-d');
$u->username = 'luigi';
$u->firstname = 'Luigi';
$u->lastname = 'Verdi';
$u->password = Hash::make('user');
$u->save();

$measure = Measure::where('name', '=', 'Chili')->first();
$category = Category::where('name', '=', 'Frutta')->first();
$vat_rate = VatRate::where('percentage', '=', '22')->first();
$suppliers = [
['La Zucchina Dorata', 'Verdure di stagione, prenotazioni settimanali', 'Bonifico bancario IBAN IT01234567890', 'Mandare una mail con le prenotazioni a Luisa: [email protected]', 'IT01234567890'],
['Mele e Pere', '', '', '', ''],
['Panetteria da Pasquale', '', '', '', ''],
['Luigi il Macellaio', '', '', '', ''],
];

foreach ($data as $s_name => $products) {
foreach ($suppliers as $index => $data) {
$s = Supplier::create([
'id' => str_slug($s_name),
'name' => $s_name,
'order_method' => '',
'payment_method' => ''
'name' => $data[0],
'description' => $data[1],
'payment_method' => $data[2],
'order_method' => $data[3],
'vat' => $data[4],
]);

$gas->suppliers()->attach($s->id);

foreach ($products as $p_name) {
Product::create([
'id' => str_slug($p_name),
'name' => $p_name,
if ($index == 0) {
$category = Category::where('name', 'Verdura')->first();
$kg_measure = Measure::where('name', 'Chili')->first();
$portion_measure = Measure::where('name', 'Pezzi')->first();
$vat_rate = VatRate::inRandomOrder()->first();

$products = [
(object) [
'name' => 'Finocchi',
'price' => 3.00,
'unit_measure' => $kg_measure->id,
'category' => $category->id,
'min_quantity' => 3,
'variants' => []
],
(object) [
'name' => 'Melanzane',
'price' => 2.00,
'unit_measure' => $kg_measure->id,
'category' => $category->id,
'variants' => [
'Forma' => ['Tonda', 'Ovale', 'Lunga'],
'Colore' => ['Nera', 'Viola']
]
],
(object) [
'name' => 'Peperoncino piccante',
'price' => 0.50,
'unit_measure' => $portion_measure->id,
'category' => $category->id,
'variants' => [
'Piccantezza' => ['Poco piccante', 'Molto piccante']
]
],
(object) [
'name' => 'Zucchine',
'price' => 2.50,
'unit_measure' => $kg_measure->id,
'category' => $category->id,
'max_available' => 3,
'variants' => []
],
];

foreach ($products as $index => $p) {
$prod = Product::create([
'name' => $p->name,
'supplier_id' => $s->id,
'active' => true,
'price' => $p->price,
'measure_id' => $p->unit_measure,
'category_id' => $p->category,
'vat_rate_id' => $vat_rate->id
]);

foreach($p->variants as $name => $values) {
$v = new Variant();
$v->name = $name;
$v->product_id = $prod->id;
$v->save();

foreach($values as $value) {
$val = new VariantValue();
$val->variant_id = $v->id;
$val->value = $value;
$val->save();
}
}

if ($index == 0) {
$mod = new Modifier();
$mod->modifier_type_id = 'sconto';
$mod->target_type = Product::class;
$mod->target_id = $prod->id;
$mod->value = 'price';
$mod->arithmetic = 'apply';
$mod->scale = 'major';
$mod->applies_type = 'quantity';
$mod->applies_target = 'order';
$mod->definition = '[{"threshold":"40","amount":"2.20"},{"threshold":"20","amount":"2.50"}]';
$mod->save();
}

if ($index == 2) {
$mod = new Modifier();
$mod->modifier_type_id = 'sconto';
$mod->target_type = Product::class;
$mod->target_id = $prod->id;
$mod->value = 'percentage';
$mod->arithmetic = 'sub';
$mod->scale = 'major';
$mod->applies_type = 'quantity';
$mod->applies_target = 'product';
$mod->definition = '[{"threshold":"15","amount":"20"},{"threshold":"5","amount":"10"}]';
$mod->save();
}

if ($index == 3) {
$mod = new Modifier();
$mod->modifier_type_id = 'sconto';
$mod->target_type = Product::class;
$mod->target_id = $prod->id;
$mod->value = 'percentage';
$mod->arithmetic = 'sub';
$mod->applies_target = 'product';
$mod->definition = '[{"threshold":9223372036854775807,"amount":"5"}]';
$mod->save();
}
}

$aggregate = Aggregate::create([]);

Order::create([
'supplier_id' => $s->id,
'active' => true,
'price' => rand(200, 500) / 100,
'measure_id' => $measure->id,
'category_id' => $category->id,
'vat_rate_id' => $vat_rate->id
'aggregate_id' => $aggregate->id,
'status' => 'open',
'start' => Carbon::today()->subDays(2)->format('Y-m-d'),
'end' => Carbon::today()->addDays(10)->format('Y-m-d'),
'shipping' => Carbon::today()->addDays(15)->format('Y-m-d'),
]);
}

$administrator->addRole($referrer_role, $s);
}

$d = new Date();
$d->type = 'order';
$d->description = '{"end":"10","shipping":"12","comment":"","suspend":"true"}';
$d->target_type = Supplier::class;
$d->target_id = 'la-zucchina-dorata';
$d->recurring = '{"day":"thursday","cycle":"biweekly","from":"' Carbon::today()->subMonths(1)->endOfMonth()->format('Y-m-d') '","to":"' . Carbon::today()->addMonths(2)->endOfMonth()->format('Y-m-d') . '"}';
$d->save();

$d = new Date();
$d->type = 'order';
$d->description = '{"end":"10","shipping":"15","comment":"","suspend":"true"}';
$d->target_type = Supplier::class;
$d->target_id = 'luigi-il-macellaio';
$d->recurring = '{"day":"wednesday","cycle":"month_third","from":"' Carbon::today()->subMonths(1)->endOfMonth()->format('Y-m-d') '","to":"' . Carbon::today()->addMonths(2)->endOfMonth()->format('Y-m-d') . '"}';
$d->save();
}
}
4 changes: 2 additions & 2 deletions code/resources/views/commons/manyrows.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<tr>
@foreach($columns as $column)
@if($column['type'] != 'hidden')
<td>
<th {!! isset($column['width']) ? 'width="' . $column['width']. '%"' : '' !!}>
{{ $column['label'] }}

@if(isset($column['help']))
<x-larastrap::pophelp :text="$column['help']" />
@endif
</td>
</th>
@endif
@endforeach

Expand Down
6 changes: 6 additions & 0 deletions code/resources/views/dates/orders.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'label' => _i('Fornitore'),
'field' => 'target_id',
'type' => 'selectobj',
'width' => 15,
'extra' => [
'options' => $currentuser->targetsByAction('supplier.orders')
]
Expand All @@ -41,11 +42,13 @@
'label' => _i('Ricorrenza'),
'field' => 'recurring',
'type' => 'periodic',
'width' => 30,
],
[
'label' => _i('Chiusura dopo...'),
'field' => 'end',
'type' => 'number',
'width' => 10,
'extra' => [
'textappend' => 'giorni'
]
Expand All @@ -54,6 +57,7 @@
'label' => _i('Consegna dopo...'),
'field' => 'shipping',
'type' => 'number',
'width' => 10,
'extra' => [
'textappend' => 'giorni',
'attributes' => [
Expand All @@ -65,6 +69,7 @@
'label' => _i('Commento'),
'field' => 'comment',
'type' => 'text',
'width' => 20,
'extra' => [
'max_length' => 40
]
Expand All @@ -73,6 +78,7 @@
'label' => _i('Sospendi'),
'field' => 'suspend',
'type' => 'check',
'width' => 10,
'help' => _i("Se un ordine automatico viene sospeso, le prossime aperture verranno ignorate. Usa questa opzione per gestire i periodi di inattività del GAS, ad esempio durante le festività."),
'extra' => [
'reviewCallback' => function($component, $params) {
Expand Down
2 changes: 1 addition & 1 deletion code/resources/views/modifier/modtarget.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<x-larastrap::radios name="applies_target" :label="_i('Riferimento su cui applicare il modificatore')" :options="$applies_targets" />

<div class="distribution_type_selection {{ $modifier->applies_target != 'order' ? 'd-none' : '' }}">
<div class="distribution_type_selection {{ $modifier->applies_target != 'order' || $modifier->value == 'price' ? 'd-none' : '' }}">
<x-larastrap::radios name="distribution_type" :label="_i('Distribuzione sulle prenotazioni in base a')" :options="['none' => (object) ['label' => _i('Nessuno'), 'hidden' => true], 'quantity' => _i('Quantità'), 'price' => _i('Valore'), 'weight' => _i('Peso')]" />
</div>

0 comments on commit b486c2d

Please sign in to comment.