2020-06-23 13:05:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-06-24 14:22:44 +02:00
|
|
|
use App\Http\Requests\Document\DestroyDocumentRequest;
|
2020-06-24 10:59:56 +02:00
|
|
|
use App\Http\Requests\Document\EditDocumentRequest;
|
|
|
|
use App\Http\Requests\Document\ShowDocumentRequest;
|
|
|
|
use App\Http\Requests\Document\StoreDocumentRequest;
|
|
|
|
use App\Http\Requests\Document\UpdateDocumentRequest;
|
|
|
|
use App\Models\Document;
|
2020-06-24 12:17:42 +02:00
|
|
|
use App\Repositories\DocumentRepository;
|
|
|
|
use App\Transformers\DocumentTransformer;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-06-23 13:05:41 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
2020-06-24 10:59:56 +02:00
|
|
|
class DocumentController extends BaseController
|
2020-06-23 13:05:41 +02:00
|
|
|
{
|
2020-06-24 12:17:42 +02:00
|
|
|
use MakesHash;
|
|
|
|
|
|
|
|
protected $entity_type = Document::class;
|
|
|
|
|
|
|
|
protected $entity_transformer = DocumentTransformer::class;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var DocumentRepository
|
|
|
|
*/
|
|
|
|
protected $document_repo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DocumentController constructor.
|
|
|
|
* @param DocumentRepository $document_repo
|
|
|
|
*/
|
|
|
|
public function __construct(DocumentRepository $document_repo)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
2020-08-11 05:21:43 +02:00
|
|
|
$this->middleware('password_protected', ['only' => ['destroy']]);
|
|
|
|
|
2020-06-24 12:17:42 +02:00
|
|
|
$this->document_repo = $document_repo;
|
|
|
|
}
|
|
|
|
|
2020-06-23 13:05:41 +02:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-24 10:59:56 +02:00
|
|
|
public function store(StoreDocumentRequest $request)
|
2020-06-23 13:05:41 +02:00
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-24 10:59:56 +02:00
|
|
|
public function show(ShowDocumentRequest $request, Document $document)
|
2020-06-23 13:05:41 +02:00
|
|
|
{
|
2020-06-24 12:17:42 +02:00
|
|
|
return $this->itemResponse($document);
|
|
|
|
}
|
2020-06-24 10:59:56 +02:00
|
|
|
|
2020-06-24 14:12:43 +02:00
|
|
|
public function download(ShowDocumentRequest $request, Document $document)
|
2020-06-24 12:17:42 +02:00
|
|
|
{
|
|
|
|
return response()->streamDownload(function () use($document) {
|
|
|
|
echo file_get_contents($document->generateUrl());
|
|
|
|
}, basename($document->generateUrl()));
|
2020-06-23 13:05:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-24 10:59:56 +02:00
|
|
|
public function edit(EditDocumentRegquest $request, Document $document)
|
2020-06-23 13:05:41 +02:00
|
|
|
{
|
2020-06-24 14:12:43 +02:00
|
|
|
return $this->itemResponse($document);
|
2020-06-23 13:05:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-24 10:59:56 +02:00
|
|
|
public function update(UpdateDocumentRequest $request, Document $document)
|
2020-06-23 13:05:41 +02:00
|
|
|
{
|
2020-06-24 14:12:43 +02:00
|
|
|
return $this->itemResponse($document);
|
2020-06-23 13:05:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-24 10:59:56 +02:00
|
|
|
public function destroy(DestroyDocumentRequest $request, Document $document)
|
2020-06-23 13:05:41 +02:00
|
|
|
{
|
2020-08-11 05:21:43 +02:00
|
|
|
|
2020-06-24 12:17:42 +02:00
|
|
|
$this->document_repo->delete($document);
|
|
|
|
|
|
|
|
return response()->json(['message'=>'success']);
|
2020-06-23 13:05:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function bulk()
|
|
|
|
{
|
2020-06-24 12:17:42 +02:00
|
|
|
|
|
|
|
$action = request()->input('action');
|
|
|
|
|
|
|
|
$ids = request()->input('ids');
|
|
|
|
|
|
|
|
$documents = Document::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
|
|
|
|
|
|
|
|
if (!$invoices) {
|
|
|
|
return response()->json(['message' => 'No Documents Found']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the other actions to the switch
|
|
|
|
*/
|
|
|
|
$documents->each(function ($document, $key) use ($action) {
|
|
|
|
if (auth()->user()->can('edit', $document)) {
|
|
|
|
$this->{$action}($document);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Need to understand which permission are required for the given bulk action ie. view / edit */
|
|
|
|
|
|
|
|
return $this->listResponse(Document::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
|
2020-06-23 13:05:41 +02:00
|
|
|
}
|
|
|
|
}
|