2018-10-17 07:21:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
2019-04-09 08:35:57 +00:00
|
|
|
namespace Webkul\Shop\Http\Controllers;
|
2018-10-17 07:21:47 +00:00
|
|
|
|
|
|
|
|
use Webkul\Sales\Repositories\OrderRepository;
|
2018-11-01 13:48:59 +00:00
|
|
|
use Webkul\Sales\Repositories\InvoiceRepository;
|
|
|
|
|
use PDF;
|
2018-10-17 07:21:47 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Customer controlller for the customer basically for the tasks of customers
|
|
|
|
|
* which will be done after customer authenticastion.
|
|
|
|
|
*
|
|
|
|
|
* @author Prashant Singh <prashant.singh852@webkul.com>
|
|
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class OrderController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* OrderrRepository object
|
|
|
|
|
*
|
2019-07-01 11:33:36 +00:00
|
|
|
* @var Object
|
2018-10-17 07:21:47 +00:00
|
|
|
*/
|
2019-07-01 11:33:36 +00:00
|
|
|
protected $orderRepository;
|
2018-10-17 07:21:47 +00:00
|
|
|
|
2018-11-01 13:48:59 +00:00
|
|
|
/**
|
|
|
|
|
* InvoiceRepository object
|
|
|
|
|
*
|
2019-07-01 11:33:36 +00:00
|
|
|
* @var Object
|
2018-11-01 13:48:59 +00:00
|
|
|
*/
|
2019-07-01 11:33:36 +00:00
|
|
|
protected $invoiceRepository;
|
2018-11-01 13:48:59 +00:00
|
|
|
|
2018-10-17 07:21:47 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
2019-07-01 11:33:36 +00:00
|
|
|
* @param \Webkul\Order\Repositories\OrderRepository $orderRepository
|
|
|
|
|
* @param \Webkul\Order\Repositories\InvoiceRepository $invoiceRepository
|
2018-10-17 07:21:47 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2018-11-01 13:48:59 +00:00
|
|
|
public function __construct(
|
2019-07-01 11:33:36 +00:00
|
|
|
OrderRepository $orderRepository,
|
|
|
|
|
InvoiceRepository $invoiceRepository
|
2018-11-01 13:48:59 +00:00
|
|
|
)
|
2018-10-17 07:21:47 +00:00
|
|
|
{
|
|
|
|
|
$this->middleware('customer');
|
|
|
|
|
|
2019-07-01 11:33:36 +00:00
|
|
|
$this->orderRepository = $orderRepository;
|
2018-11-01 13:48:59 +00:00
|
|
|
|
2019-07-01 11:33:36 +00:00
|
|
|
$this->invoiceRepository = $invoiceRepository;
|
2020-02-06 11:48:51 +00:00
|
|
|
|
|
|
|
|
parent::__construct();
|
2018-10-17 07:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
2019-12-11 09:55:19 +00:00
|
|
|
* @return \Illuminate\View\View
|
2018-10-17 07:21:47 +00:00
|
|
|
*/
|
2019-06-28 14:18:52 +00:00
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
return view($this->_config['view']);
|
2018-10-17 07:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the view for the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
2019-12-11 09:55:19 +00:00
|
|
|
* @return \Illuminate\View\View
|
2018-10-17 07:21:47 +00:00
|
|
|
*/
|
|
|
|
|
public function view($id)
|
|
|
|
|
{
|
2019-07-01 11:33:36 +00:00
|
|
|
$order = $this->orderRepository->findOneWhere([
|
2019-04-09 08:35:57 +00:00
|
|
|
'customer_id' => auth()->guard('customer')->user()->id,
|
2020-03-04 06:32:53 +00:00
|
|
|
'id' => $id,
|
2019-04-09 08:35:57 +00:00
|
|
|
]);
|
2019-03-31 20:02:58 +00:00
|
|
|
|
2020-02-20 07:05:51 +00:00
|
|
|
if (! $order) {
|
2019-04-09 08:35:57 +00:00
|
|
|
abort(404);
|
2020-02-20 07:05:51 +00:00
|
|
|
}
|
2019-03-31 20:02:58 +00:00
|
|
|
|
2019-04-09 08:35:57 +00:00
|
|
|
return view($this->_config['view'], compact('order'));
|
2018-10-17 07:21:47 +00:00
|
|
|
}
|
2018-11-01 13:48:59 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Print and download the for the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function print($id)
|
|
|
|
|
{
|
2019-07-01 11:33:36 +00:00
|
|
|
$invoice = $this->invoiceRepository->findOrFail($id);
|
2018-11-01 13:48:59 +00:00
|
|
|
|
|
|
|
|
$pdf = PDF::loadView('shop::customers.account.orders.pdf', compact('invoice'))->setPaper('a4');
|
|
|
|
|
|
|
|
|
|
return $pdf->download('invoice-' . $invoice->created_at->format('d-m-Y') . '.pdf');
|
|
|
|
|
}
|
2019-04-09 08:35:57 +00:00
|
|
|
}
|