diff --git a/app/Datatables/Shop/InvoicesDataTable.php b/app/Datatables/Shop/InvoicesDataTable.php
index 85c07b55..f7a44200 100644
--- a/app/Datatables/Shop/InvoicesDataTable.php
+++ b/app/Datatables/Shop/InvoicesDataTable.php
@@ -5,6 +5,7 @@ namespace App\Datatables\Shop;
use Yajra\DataTables\Html\Column;
use App\Datatables\ParentDataTable as DataTable;
use App\Models\Shop\Invoice;
+use App\Repositories\Shop\Invoices;
class InvoicesDataTable extends DataTable
{
@@ -15,11 +16,29 @@ class InvoicesDataTable extends DataTable
return $this->buildQuery($model);
}
+ public function modifier($datatables)
+ {
+ $datatables
+ ->editColumn('status', function (Invoice $invoice) {
+ return Invoices::getStatus($invoice->status);
+ })
+ ->editColumn('created_at', function (Invoice $invoice) {
+ return $invoice->created_at->toDateTimeString();
+ })
+ ->editColumn('customer.last_name', function (Invoice $invoice) {
+ return $invoice->customer->last_name . ' ' . $invoice->customer->first_name;
+ })
+ ->rawColumns(['action']);
+ return parent::modifier($datatables);
+ }
+
protected function getColumns()
{
return [
- Column::make('status.name'),
- Column::make('customer.name'),
+
+ Column::make('status'),
+ Column::make('created_at')->title('Date'),
+ Column::make('customer.last_name'),
Column::make('total'),
$this->makeColumnButtons(),
];
diff --git a/app/Datatables/Shop/OrdersDataTable.php b/app/Datatables/Shop/OrdersDataTable.php
index 2a6f5217..3038b2db 100644
--- a/app/Datatables/Shop/OrdersDataTable.php
+++ b/app/Datatables/Shop/OrdersDataTable.php
@@ -12,6 +12,9 @@ use App\Repositories\Shop\Orders;
class OrdersDataTable extends DataTable
{
public $model_name = 'orders';
+ public $sortedColumn = 1;
+ public $sortedOrder = 'desc';
+ public $stateSave = true;
public function query(Order $model)
{
diff --git a/app/Http/Controllers/Admin/HomeController.php b/app/Http/Controllers/Admin/HomeController.php
index 37bacaa5..969a57fd 100644
--- a/app/Http/Controllers/Admin/HomeController.php
+++ b/app/Http/Controllers/Admin/HomeController.php
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
+use App\Repositories\Shop\Dashboards;
class HomeController extends Controller
{
@@ -14,6 +15,7 @@ class HomeController extends Controller
public function index()
{
- return view('Admin.Shop.Dashboard.index');
+ $data = Dashboards::getStats();
+ return view('Admin.Shop.Dashboard.index', $data);
}
}
diff --git a/app/Http/Controllers/Admin/Shop/OrderController.php b/app/Http/Controllers/Admin/Shop/OrderController.php
index 148b3794..473d91e2 100644
--- a/app/Http/Controllers/Admin/Shop/OrderController.php
+++ b/app/Http/Controllers/Admin/Shop/OrderController.php
@@ -28,9 +28,7 @@ class OrderController extends Controller
public function edit($id)
{
- $data['order'] = Orders::edit($id)->toArray();
- // dump($data);
- // exit;
+ $data = Orders::edit($id);
return view('Admin.Shop.Orders.edit', $data);
}
diff --git a/app/Models/Shop/Order.php b/app/Models/Shop/Order.php
index 9cec3501..5ee1ab81 100644
--- a/app/Models/Shop/Order.php
+++ b/app/Models/Shop/Order.php
@@ -3,12 +3,19 @@
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+use Venturecraft\Revisionable\RevisionableTrait;
class Order extends Model
{
+ use RevisionableTrait, SoftDeletes;
+
protected $guarded = ['id'];
protected $table = 'shop_orders';
-
+ protected $revisionCreationsEnabled = false;
+ protected $keepRevisionOf = ['customer_address_id', 'delivery_id', 'payment_type', 'status'];
+
public function customer()
{
return $this->belongsTo(Customer::class);
diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php
index 3fe1d425..5d2ccd62 100644
--- a/app/Repositories/Shop/Articles.php
+++ b/app/Repositories/Shop/Articles.php
@@ -458,17 +458,17 @@ class Articles
$images = count($article->images) ? $article->images : collect([]);
switch ($article->product_type) {
case 'App\Models\Botanic\Variety':
- $variety = $article->product;
- $specie = $variety->specie;
+ $variety = $article->product ?? false;
+ $specie = $variety->specie ?? false;
$images = $variety ? (count($variety->images) ? $images->merge($variety->images) : $images) : $images;
$images = $specie ? (count($specie->images) ? $images->merge($specie->images) : $images) : $images;
break;
case 'App\Models\Botanic\Specie':
- $specie = $article->product;
- $images = count($specie->images) ? $specie->images : $images;
+ $specie = $article->product ?? false;
+ $images = count($specie->images ?? []) ? $specie->images : $images;
break;
case 'App\Models\Shop\Merchandise':
- $merchandise = $article->product;
+ $merchandise = $article->product ?? false;
$images = count($merchandise->images) ? $merchandise->images : $images;
break;
}
@@ -488,20 +488,13 @@ class Articles
}
switch ($article->product_type) {
case 'App\Models\Botanic\Variety':
- $variety = $article->product;
- $image = $variety->image ?? false;
- if (!$image) {
- $specie = $variety->specie;
- $image = $specie->image ?? false;
- }
+ $image = $article->product->image ?? ($article->product->specie->image ?? false);
break;
case 'App\Models\Botanic\Specie':
- $specie = $article->product;
- $image = $specie->image ?? false;
+ $image = $article->product->image ?? false;
break;
case 'App\Models\Shop\Merchandise':
- $merchandise = $article->product;
- $image = $merchandise->image ?? false;
+ $image = $article->product->image ?? false;
break;
}
return $image;
@@ -509,16 +502,16 @@ class Articles
public static function storeFull($data)
{
- $images = isset($data['images']) ? $data['images'] : false;
+ $images = $data['images'] ?? false;
unset($data['images']);
- $categories = isset($data['categories']) ? $data['categories'] : false;
+ $categories = $data['categories'] ?? false;
unset($data['categories']);
- $tags = isset($data['tags']) ? $data['tags'] : false;
+ $tags = $data['tags'] ?? false;
unset($data['tags']);
- $prices = isset($data['prices']) ? $data['prices'] : false;
+ $prices = $data['prices'] ?? false;
unset($data['prices']);
$article = self::store($data);
diff --git a/app/Repositories/Shop/Customers.php b/app/Repositories/Shop/Customers.php
index 3665f242..b5fefe1b 100644
--- a/app/Repositories/Shop/Customers.php
+++ b/app/Repositories/Shop/Customers.php
@@ -15,14 +15,11 @@ class Customers
public static function editProfile($id = false)
{
$id = $id ? $id : self::getId();
- dump($id);
- exit;
$data = [
- 'customer' => self::get($id, ['addresses', 'deliveries', 'orders']),
+ 'customer' => self::get($id, ['addresses', 'deliveries', 'orders'])->toArray(),
'deliveries' => Deliveries::getAll('sale_channel')->toArray(),
];
dump($data);
- exit;
return $data;
}
diff --git a/app/Repositories/Shop/Dashboards.php b/app/Repositories/Shop/Dashboards.php
new file mode 100644
index 00000000..b087fb40
--- /dev/null
+++ b/app/Repositories/Shop/Dashboards.php
@@ -0,0 +1,18 @@
+ Orders::countByMonth(),
+ 'orders_sum' => Orders::sumByMonth(),
+ 'orders_avg' => Orders::avgByMonth(),
+ ];
+ }
+}
diff --git a/app/Repositories/Shop/Invoices.php b/app/Repositories/Shop/Invoices.php
index cc1db812..4af55d61 100644
--- a/app/Repositories/Shop/Invoices.php
+++ b/app/Repositories/Shop/Invoices.php
@@ -3,7 +3,7 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
-
+use Carbon\Carbon;
use App\Models\Shop\Invoice;
class Invoices
@@ -19,6 +19,17 @@ class Invoices
return $relations ? Invoice::with($relations)->findOrFail($id) : Invoice::findOrFail($id);
}
+ public static function count()
+ {
+ return Invoice::count();
+ }
+
+ public static function countByMonth()
+ {
+ $start = Carbon::now()->beginOfMonth();
+ return Invoice::where('created_at', '>', $start);
+ }
+
public static function store($data)
{
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
@@ -53,4 +64,9 @@ class Invoices
$last_ref = Invoice::orderBy('ref', 'desc')->where('ref', '>', $ref)->first();
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
}
+
+ public static function statuses()
+ {
+ return ['En attente', 'Non soldée', 'Soldée'];
+ }
}
diff --git a/app/Repositories/Shop/Orders.php b/app/Repositories/Shop/Orders.php
index b05d52cd..d904aac2 100644
--- a/app/Repositories/Shop/Orders.php
+++ b/app/Repositories/Shop/Orders.php
@@ -2,6 +2,7 @@
namespace App\Repositories\Shop;
+use Carbon\Carbon;
use App\Models\Shop\Order;
class Orders
@@ -24,9 +25,36 @@ class Orders
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
}
+ public static function count()
+ {
+ return Order::count();
+ }
+
+ public static function countByMonth()
+ {
+ $start = Carbon::now()->startOfMonth();
+ return Order::where('created_at', '>', $start)->count();
+ }
+
+ public static function sumByMonth()
+ {
+ $start = Carbon::now()->startOfMonth();
+ return Order::where('created_at', '>', $start)->sum('total_shipped');
+ }
+
+ public static function avgByMonth()
+ {
+ return self::countByMonth() ? round(self::sumByMonth() / self::countByMonth(), 2) : 0;
+ }
+
public static function edit($id)
{
- return Orders::get($id, ['customer', 'address', 'delivery', 'detail']);
+ return [
+ 'order' => self::get($id, ['customer', 'address', 'detail']),
+ 'statuses' => self::statuses(),
+ 'payment_types' => self::payment_types(),
+ 'sale_channels' => SaleChannels::getOptions(),
+ ];
}
public static function get($id, $relations = false)
@@ -65,10 +93,16 @@ class Orders
public static function statuses()
{
- return [
- 'En attente',
- 'Expédié',
- 'Livré',
- ];
+ return ['En attente', 'Expédié', 'Livré'];
+ }
+
+ public static function getPaymentType($id)
+ {
+ return self::payment_types()[$id] ?? false;
+ }
+
+ public static function payment_types()
+ {
+ return ['', 'CARTE BANCAIRE', 'CHEQUE', 'VIREMENT BANCAIRE'];
}
}
diff --git a/composer.json b/composer.json
index f2633822..14483abb 100644
--- a/composer.json
+++ b/composer.json
@@ -96,6 +96,7 @@
"thomasjohnkane/snooze": "^2.2",
"toin0u/geocoder-laravel": "^4.2",
"unicodeveloper/laravel-password": "^1.0",
+ "venturecraft/revisionable": "^1.39",
"watson/rememberable": "^5.0",
"wildside/userstamps": "^2.1",
"yadahan/laravel-authentication-log": "^1.2",
diff --git a/config/revisionable.php b/config/revisionable.php
new file mode 100644
index 00000000..32e590ce
--- /dev/null
+++ b/config/revisionable.php
@@ -0,0 +1,13 @@
+ Venturecraft\Revisionable\Revision::class,
+
+ 'additional_fields' => [],
+
+];
diff --git a/database/migrations/2013_04_09_062329_create_revisions_table.php b/database/migrations/2013_04_09_062329_create_revisions_table.php
new file mode 100644
index 00000000..8d3d2d2a
--- /dev/null
+++ b/database/migrations/2013_04_09_062329_create_revisions_table.php
@@ -0,0 +1,37 @@
+bigIncrements('id');
+ $table->string('revisionable_type');
+ $table->unsignedBigInteger('revisionable_id');
+ $table->unsignedBigInteger('user_id')->nullable();
+ $table->string('key');
+ $table->text('old_value')->nullable();
+ $table->text('new_value')->nullable();
+ $table->timestamps();
+
+ $table->index(array('revisionable_id', 'revisionable_type'));
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('revisions');
+ }
+}
diff --git a/database/migrations/2022_05_11_202752_teamwork_setup_tables.php b/database/migrations/2022_05_11_202752_teamwork_setup_tables.php
deleted file mode 100644
index 144f40c9..00000000
--- a/database/migrations/2022_05_11_202752_teamwork_setup_tables.php
+++ /dev/null
@@ -1,83 +0,0 @@
-integer('current_team_id')->unsigned()->nullable();
- });
-
- Schema::create(\Config::get('teamwork.teams_table'), function (Blueprint $table) {
- $table->increments('id')->unsigned();
- $table->integer('owner_id')->unsigned()->nullable();
- $table->string('name');
- $table->timestamps();
- });
-
- Schema::create(\Config::get('teamwork.team_user_table'), function (Blueprint $table) {
- $table->bigInteger('user_id')->unsigned();
- $table->integer('team_id')->unsigned();
- $table->timestamps();
-
- $table->foreign('user_id')
- ->references(\Config::get('teamwork.user_foreign_key'))
- ->on(\Config::get('teamwork.users_table'))
- ->onUpdate('cascade')
- ->onDelete('cascade');
-
- $table->foreign('team_id')
- ->references('id')
- ->on(\Config::get('teamwork.teams_table'))
- ->onDelete('cascade');
- });
-
- Schema::create(\Config::get('teamwork.team_invites_table'), function (Blueprint $table) {
- $table->increments('id');
- $table->bigInteger('user_id')->unsigned();
- $table->integer('team_id')->unsigned();
- $table->enum('type', ['invite', 'request']);
- $table->string('email');
- $table->string('accept_token');
- $table->string('deny_token');
- $table->timestamps();
- $table->foreign('team_id')
- ->references('id')
- ->on(\Config::get('teamwork.teams_table'))
- ->onDelete('cascade');
- });
- }
-
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::table(\Config::get('teamwork.users_table'), function (Blueprint $table) {
- $table->dropColumn('current_team_id');
- });
-
- Schema::table(\Config::get('teamwork.team_user_table'), function (Blueprint $table) {
- if (DB::getDriverName() !== 'sqlite') {
- $table->dropForeign(\Config::get('teamwork.team_user_table').'_user_id_foreign');
- }
- if (DB::getDriverName() !== 'sqlite') {
- $table->dropForeign(\Config::get('teamwork.team_user_table').'_team_id_foreign');
- }
- });
-
- Schema::drop(\Config::get('teamwork.team_user_table'));
- Schema::drop(\Config::get('teamwork.team_invites_table'));
- Schema::drop(\Config::get('teamwork.teams_table'));
- }
-}
diff --git a/resources/lang/fr/shop.php b/resources/lang/fr/shop.php
index 9dedf4e6..ec978847 100644
--- a/resources/lang/fr/shop.php
+++ b/resources/lang/fr/shop.php
@@ -247,4 +247,30 @@ return [
'successdel' => 'La déclinaison a été correctement effacée',
'confirmdelete' => 'Confirmez-vous la suppression de la déclinaison ?',
],
+ 'orders' => [
+ 'title' => 'Commandes',
+ 'name' => 'Commande',
+ 'description' => 'Gérer les commandes',
+ 'add' => 'Ajouter une commande',
+ 'edit' => 'Editer une commande',
+ 'del' => 'Effacer une commande',
+ 'list' => 'Liste des commandes',
+ 'successadd' => 'La commande a été correctement ajoutée',
+ 'successmod' => 'La commande a été correctement modifiée',
+ 'successdel' => 'La commande a été correctement effacée',
+ 'confirmdelete' => 'Confirmez-vous la suppression de la commande ?',
+ ],
+ 'invoices' => [
+ 'title' => 'Factures',
+ 'name' => 'Facture',
+ 'description' => 'Gérer les factures',
+ 'add' => 'Ajouter une facture',
+ 'edit' => 'Editer une facture',
+ 'del' => 'Effacer une facture',
+ 'list' => 'Liste des factures',
+ 'successadd' => 'La facture a été correctement ajoutée',
+ 'successmod' => 'La facture a été correctement modifiée',
+ 'successdel' => 'La facture a été correctement effacée',
+ 'confirmdelete' => 'Confirmez-vous la suppression de la facture ?',
+ ],
];
diff --git a/resources/views/Admin/Shop/Dashboard/_partials/counter.blade.php b/resources/views/Admin/Shop/Dashboard/_partials/counter.blade.php
index 9f2cd85d..ae354310 100644
--- a/resources/views/Admin/Shop/Dashboard/_partials/counter.blade.php
+++ b/resources/views/Admin/Shop/Dashboard/_partials/counter.blade.php
@@ -1,30 +1,27 @@
diff --git a/resources/views/Admin/Shop/Orders/edit.blade.php b/resources/views/Admin/Shop/Orders/edit.blade.php
index 5eefd822..c851a0f1 100644
--- a/resources/views/Admin/Shop/Orders/edit.blade.php
+++ b/resources/views/Admin/Shop/Orders/edit.blade.php
@@ -1,54 +1,70 @@
@extends('layout.index', [
- 'title' => 'Commandes',
- 'subtitle' => 'Edition d\'une commandes',
+ 'title' => __('shop.orders.title'),
+ 'subtitle' => __('shop.orders.list'),
'breadcrumb' => ['Commandes']
])
@section('content')
- {{ Form::open(['route' => 'Admin.Shop.Orders.update', 'id' => 'order-form', 'autocomplete' => 'off']) }}
+ {{ Form::open(['route' => 'Admin.Shop.Orders.store', 'id' => 'order-form', 'autocomplete' => 'off']) }}
-
- {{ $order['customer']['last_name'] }} {{ $order['customer']['first_name'] }}
-
- {{ $order['delivery']['name'] }}
-
-
- @if ($order['address'])
- {{ $order['address']['address'] }}
- @isset ($order['address']['address2']) {{ $order['address']['address2'] }} @endisset
- {{ $order['address']['zipcode'] }} {{ $order['address']['city'] }}
- @endif
-
-
-
-
-
-
-
-
-
- Quantité
- Nom
- Prix
- Total
-
-
- @foreach ($order['detail'] as $detail)
-
- {{ $detail['quantity'] }}
- {{ $detail['name'] }}
- {{ $detail['price'] }}
- {{ $detail['total'] }}
-
- @endforeach
-
-
+
+
+
{{ $order['customer']['last_name'] }} {{ $order['customer']['first_name'] }}
+
{{ $order['delivery']['name'] }}
+
+
+ @if ($order['address'])
+ {{ $order['address']['address'] }}
+ @isset ($order['address']['address2']) {{ $order['address']['address2'] }} @endisset
+ {{ $order['address']['zipcode'] }} {{ $order['address']['city'] }}
+ @endif
+
-
+
+
+
+ Commande
+ du {{ Carbon\Carbon::parse($order['created_at'])->isoFormat('LLLL') }}
+
+
+ Canal de vente
+ @include('components.form.select', [
+ 'name' => 'sale_channel_id',
+ 'list' => $sale_channels ?? [],
+ 'value' => $order['sale_channel_id'],
+ 'class' => 'select2',
+ ])
+
+
+
+
+ Statut
+ @include('components.form.select', [
+ 'name' => 'status',
+ 'list' => $statuses ?? [],
+ 'value' => $order['status'],
+ 'class' => 'select2',
+ ])
+
+
+ Règlement
+ @include('components.form.select', [
+ 'name' => 'payment_type',
+ 'list' => $payment_types ?? [],
+ 'value' => $order['payment_type'],
+ 'class' => 'select2',
+ ])
+
+
+
+
+
+
+ @include('Admin.Shop.Orders.partials.detail')
+
+
-
-
-
+ {{ Form::close() }}
@endsection
diff --git a/resources/views/Admin/Shop/Orders/partials/detail.blade.php b/resources/views/Admin/Shop/Orders/partials/detail.blade.php
new file mode 100644
index 00000000..01cf21cc
--- /dev/null
+++ b/resources/views/Admin/Shop/Orders/partials/detail.blade.php
@@ -0,0 +1,46 @@
+
+
+
+
+
+ Nom
+ Quantité
+ Prix unitaire
+ Total
+
+
+ @foreach ($order['detail'] as $detail)
+
+ {{ $detail['name'] }}
+ {{ $detail['quantity'] }}
+ {{ $detail['price_taxed'] }}
+ {{ $detail['total_taxed'] }}
+
+ @endforeach
+
+
+
+ Total
+
+
+ {{ $order['total_taxed'] }}
+
+ @if ($order['shipping'] ?? false)
+
+ Livraison
+
+
+ {{ $order['shipping'] }}
+
+
+ Total à payer
+
+
+ {{ $order['total_shipped'] }}
+
+ @endif
+
+
+
+
+
diff --git a/resources/views/Shop/Customers/partials/user.blade.php b/resources/views/Shop/Customers/partials/user.blade.php
index bd8ed870..a2ad4cd9 100644
--- a/resources/views/Shop/Customers/partials/user.blade.php
+++ b/resources/views/Shop/Customers/partials/user.blade.php
@@ -1,10 +1,10 @@
Mes coordonnées
-
+
{{ $customer['first_name'] }} {{ $customer['first_name'] }} {{ $customer['company'] }}
{{ $customer['address'] }}
{{ $customer['address2'] }}
{{ $customer['phone'] }}
{{ $customer['email'] }}
-
Compte créé le {{ $customer['created_at'] }}
\ No newline at end of file
+
Compte créé le {{ Carbon\Carbon::parse($customer['created_at'])->format('d-m-Y') }}
\ No newline at end of file