|
1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
|
2
|
|
|
|
|
3
|
|
|
use App\Http\Controllers\Controller; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* ClientOrderController |
|
7
|
|
|
* |
|
8
|
|
|
* This is the controller for the shop clients orders |
|
9
|
|
|
* @author Matthijs Neijenhuijs <[email protected]> |
|
10
|
|
|
* @version 0.1 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
use Hideyo\Ecommerce\Framework\Services\Client\Entity\ClientRepository; |
|
14
|
|
|
use Hideyo\Ecommerce\Framework\Services\Client\Entity\ClientAddressRepository; |
|
15
|
|
|
use Hideyo\Ecommerce\Framework\Services\Order\Entity\OrderRepository; |
|
16
|
|
|
use Illuminate\Http\Request; |
|
17
|
|
|
use Form; |
|
18
|
|
|
use DataTables; |
|
19
|
|
|
|
|
20
|
|
|
class ClientOrderController extends Controller |
|
21
|
|
|
{ |
|
22
|
|
|
public function __construct( |
|
23
|
|
|
Request $request, |
|
24
|
|
|
ClientAddressRepository $clientAddress, |
|
25
|
|
|
ClientRepository $client, |
|
26
|
|
|
OrderRepository $order) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->clientAddress = $clientAddress; |
|
|
|
|
|
|
29
|
|
|
$this->client = $client; |
|
|
|
|
|
|
30
|
|
|
$this->order = $order; |
|
|
|
|
|
|
31
|
|
|
$this->request = $request; |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function index($clientId) |
|
35
|
|
|
{ |
|
36
|
|
|
$client = $this->client->find($clientId); |
|
37
|
|
|
if ($this->request->wantsJson()) { |
|
38
|
|
|
|
|
39
|
|
|
$order = $this->order->getModel()->select( |
|
40
|
|
|
['id', 'created_at', 'generated_custom_order_id', 'order_status_id', 'client_id', 'delivery_order_address_id', 'bill_order_address_id', |
|
41
|
|
|
'price_with_tax'] |
|
42
|
|
|
)->with(array('orderStatus', 'orderPaymentMethod', 'orderSendingMethod', 'products', 'client', 'orderBillAddress', 'orderDeliveryAddress'))->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id)->where('client_id', '=', $clientId); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
$datatables = DataTables::of($order) |
|
46
|
|
|
|
|
47
|
|
|
->addColumn('status', function ($order) { |
|
48
|
|
|
if ($order->orderStatus) { |
|
49
|
|
|
return $order->orderStatus->title; |
|
50
|
|
|
} |
|
51
|
|
|
}) |
|
52
|
|
|
|
|
53
|
|
|
->addColumn('created_at', function ($order) { |
|
54
|
|
|
return date('d F H:i', strtotime($order->created_at)); |
|
55
|
|
|
}) |
|
56
|
|
|
->addColumn('status', function ($order) { |
|
57
|
|
|
if ($order->orderStatus) { |
|
58
|
|
|
if ($order->orderStatus->color) { |
|
59
|
|
|
return '<a href="/admin/order/'.$order->id.'" style="text-decoration:none;"><span style="background-color:'.$order->orderStatus->color.'; padding: 10px; line-height:30px; text-align:center; color:white;">'.$order->orderStatus->title.'</span></a>'; |
|
60
|
|
|
} |
|
61
|
|
|
return $order->orderStatus->title; |
|
62
|
|
|
} |
|
63
|
|
|
}) |
|
64
|
|
|
->addColumn('client', function ($order) { |
|
65
|
|
|
if ($order->client) { |
|
66
|
|
|
if ($order->orderBillAddress) { |
|
67
|
|
|
return $order->orderBillAddress->firstname.' '.$order->orderBillAddress->lastname; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
}) |
|
71
|
|
|
->addColumn('products', function ($order) { |
|
72
|
|
|
if ($order->products) { |
|
73
|
|
|
return $order->products->count(); |
|
74
|
|
|
} |
|
75
|
|
|
}) |
|
76
|
|
|
->addColumn('price_with_tax', function ($order) { |
|
77
|
|
|
$money = '€ '.$order->getPriceWithTaxNumberFormat(); |
|
78
|
|
|
return $money; |
|
79
|
|
|
}) |
|
80
|
|
|
->addColumn('paymentMethod', function ($order) { |
|
81
|
|
|
if ($order->orderPaymentMethod) { |
|
82
|
|
|
return $order->orderPaymentMethod->title; |
|
83
|
|
|
} |
|
84
|
|
|
}) |
|
85
|
|
|
->addColumn('sendingMethod', function ($order) { |
|
86
|
|
|
if ($order->orderSendingMethod) { |
|
87
|
|
|
return $order->orderSendingMethod->title; |
|
88
|
|
|
} |
|
89
|
|
|
}) |
|
90
|
|
|
->addColumn('action', function ($order) { |
|
91
|
|
|
$download = '<a href="/admin/order/'.$order->id.'/download" class="btn btn-default btn-sm btn-info"><i class="entypo-pencil"></i>Download</a> '; |
|
92
|
|
|
$links = '<a href="/admin/order/'.$order->id.'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Show</a> '.$download; |
|
93
|
|
|
|
|
94
|
|
|
return $links; |
|
95
|
|
|
}); |
|
96
|
|
|
|
|
97
|
|
|
return $datatables->rawColumns(['status', 'action'])->make(true); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return view('backend.client_order.index')->with(array('client' => $client)); |
|
101
|
|
|
} |
|
102
|
|
|
} |