Merge pull request #3835 from turbo124/v2

Documents
This commit is contained in:
David Bomba 2020-06-24 20:18:05 +10:00 committed by GitHub
commit 822c814914
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 145 additions and 50 deletions

View File

@ -137,7 +137,10 @@ class InvoiceController extends Controller
//if only 1 pdf, output to buffer for download //if only 1 pdf, output to buffer for download
if ($invoices->count() == 1) { if ($invoices->count() == 1) {
return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($invoices->first()->pdf_file_path())); return response()->streamDownload(function () use($invoices) {
echo file_get_contents($invoices->first()->pdf_file_path());
}, basename($invoices->first()->pdf_file_path()));
//return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($invoices->first()->pdf_file_path()));
} }
# enable output of HTTP headers # enable output of HTTP headers

View File

@ -74,7 +74,10 @@ class QuoteController extends Controller
} }
if ($quotes->count() == 1) { if ($quotes->count() == 1) {
return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($quotes->first()->pdf_file_path())); return response()->streamDownload(function () use($invoices) {
echo file_get_contents($invoices->first()->pdf_file_path());
}, basename($invoices->first()->pdf_file_path()));
//return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($quotes->first()->pdf_file_path()));
} }
# enable output of HTTP headers # enable output of HTTP headers

View File

@ -527,7 +527,10 @@ class CreditController extends BaseController
} }
break; break;
case 'download': case 'download':
return response()->download(TempFile::path($credit->pdf_file_path()), basename($credit->pdf_file_path())); return response()->streamDownload(function () use($credit) {
echo file_get_contents($credit->pdf_file_path());
}, basename($credit->pdf_file_path()));
//return response()->download(TempFile::path($credit->pdf_file_path()), basename($credit->pdf_file_path()));
break; break;
case 'archive': case 'archive':
$this->credit_repository->archive($credit); $this->credit_repository->archive($credit);

View File

@ -2,10 +2,40 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
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;
use App\Repositories\DocumentRepository;
use App\Transformers\DocumentTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class DocumentController extends Controller class DocumentController extends BaseController
{ {
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();
$this->document_repo = $document_repo;
}
/** /**
* Display a listing of the resource. * Display a listing of the resource.
* *
@ -32,7 +62,7 @@ class DocumentController extends Controller
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function store(Request $request) public function store(StoreDocumentRequest $request)
{ {
// //
} }
@ -43,9 +73,16 @@ class DocumentController extends Controller
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function show($id) public function show(ShowDocumentRequest $request, Document $document)
{ {
// return $this->itemResponse($document);
}
public function download(DownloadDocumentRequest $request, Document $document)
{
return response()->streamDownload(function () use($document) {
echo file_get_contents($document->generateUrl());
}, basename($document->generateUrl()));
} }
/** /**
@ -54,7 +91,7 @@ class DocumentController extends Controller
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function edit($id) public function edit(EditDocumentRegquest $request, Document $document)
{ {
// //
} }
@ -66,7 +103,7 @@ class DocumentController extends Controller
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function update(Request $request, $id) public function update(UpdateDocumentRequest $request, Document $document)
{ {
// //
} }
@ -77,13 +114,37 @@ class DocumentController extends Controller
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function destroy($id) public function destroy(DestroyDocumentRequest $request, Document $document)
{ {
// $this->document_repo->delete($document);
return response()->json(['message'=>'success']);
} }
public function bulk() public function bulk()
{ {
$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());
} }
} }

View File

@ -660,7 +660,10 @@ class InvoiceController extends BaseController
} }
break; break;
case 'download': case 'download':
return response()->download(TempFile::path($invoice->pdf_file_path()), basename($invoice->pdf_file_path())); return response()->streamDownload(function () use($invoice) {
echo file_get_contents($invoice->pdf_file_path());
}, basename($invoice->pdf_file_path()));
//return response()->download(TempFile::path($invoice->pdf_file_path()), basename($invoice->pdf_file_path()));
break; break;
case 'restore': case 'restore':
$this->invoice_repo->restore($invoice); $this->invoice_repo->restore($invoice);

View File

@ -661,7 +661,10 @@ class QuoteController extends BaseController
# code... # code...
break; break;
case 'download': case 'download':
return response()->download(TempFile::path($quote->pdf_file_path()), basename($quote->pdf_file_path())); return response()->streamDownload(function () use($quote) {
echo file_get_contents($quote->pdf_file_path());
}, basename($quote->pdf_file_path()));
//return response()->download(TempFile::path($quote->pdf_file_path()), basename($quote->pdf_file_path()));
break; break;
case 'archive': case 'archive':
$this->invoice_repo->archive($quote); $this->invoice_repo->archive($quote);

View File

@ -134,6 +134,11 @@ class Company extends BaseModel
self::ENTITY_RECURRING_QUOTE => 2048, self::ENTITY_RECURRING_QUOTE => 2048,
]; ];
public function documents()
{
return $this->morphMany(Document::class, 'documentable');
}
public function getEntityType() public function getEntityType()
{ {
return Company::class; return Company::class;

View File

@ -112,4 +112,16 @@ class Document extends BaseModel
return null; return null;
} }
public function generateRoute($absolute = false)
{
return route('api.documents.show', ['document' => $this->hashed_id]);
//return route('document.show', ['document' => $this->hashed_id]);
}
public function deleteFile()
{
Storage::disk($this->disk)->delete($this->url);
}
} }

View File

@ -37,7 +37,7 @@ class DocumentTransformer extends EntityTransformer
'assigned_user_id' => $this->encodePrimaryKey($document->assigned_user_id), 'assigned_user_id' => $this->encodePrimaryKey($document->assigned_user_id),
'project_id' => $this->encodePrimaryKey($document->project_id), 'project_id' => $this->encodePrimaryKey($document->project_id),
'vendor_id' => $this->encodePrimaryKey($document->vendor_id), 'vendor_id' => $this->encodePrimaryKey($document->vendor_id),
'url' => (string) $document->generateUrl() ?: '', 'url' => (string) $document->generateRoute() ?: '',
'preview' => (string) $document->preview ?: '', 'preview' => (string) $document->preview ?: '',
'name' => (string) $document->name, 'name' => (string) $document->name,
'type' => (string) $document->type, 'type' => (string) $document->type,

View File

@ -25,7 +25,9 @@ class PaymentTransformer extends EntityTransformer
protected $serializer; protected $serializer;
protected $defaultIncludes = ['invoices']; protected $defaultIncludes = [
// 'invoices'
];
protected $availableIncludes = [ protected $availableIncludes = [
'client', 'client',

View File

@ -265,29 +265,29 @@ class RandomDataSeeder extends Seeder
]); ]);
// if (config('ninja.testvars.stripe')) { if (config('ninja.testvars.stripe')) {
// $cg = new CompanyGateway; $cg = new CompanyGateway;
// $cg->company_id = $company->id; $cg->company_id = $company->id;
// $cg->user_id = $user->id; $cg->user_id = $user->id;
// $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
// $cg->require_cvv = true; $cg->require_cvv = true;
// $cg->show_billing_address = true; $cg->show_billing_address = true;
// $cg->show_shipping_address = true; $cg->show_shipping_address = true;
// $cg->update_details = true; $cg->update_details = true;
// $cg->config = encrypt(config('ninja.testvars.stripe')); $cg->config = encrypt(config('ninja.testvars.stripe'));
// $cg->save(); $cg->save();
// $cg = new CompanyGateway; $cg = new CompanyGateway;
// $cg->company_id = $company->id; $cg->company_id = $company->id;
// $cg->user_id = $user->id; $cg->user_id = $user->id;
// $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
// $cg->require_cvv = true; $cg->require_cvv = true;
// $cg->show_billing_address = true; $cg->show_billing_address = true;
// $cg->show_shipping_address = true; $cg->show_shipping_address = true;
// $cg->update_details = true; $cg->update_details = true;
// $cg->config = encrypt(config('ninja.testvars.stripe')); $cg->config = encrypt(config('ninja.testvars.stripe'));
// $cg->save(); $cg->save();
// } }
// if (config('ninja.testvars.paypal')) { // if (config('ninja.testvars.paypal')) {
// $cg = new CompanyGateway; // $cg = new CompanyGateway;
@ -315,18 +315,18 @@ class RandomDataSeeder extends Seeder
// $cg->save(); // $cg->save();
// } // }
if(config('ninja.testvars.authorize')) { // if(config('ninja.testvars.authorize')) {
$cg = new CompanyGateway; // $cg = new CompanyGateway;
$cg->company_id = $company->id; // $cg->company_id = $company->id;
$cg->user_id = $user->id; // $cg->user_id = $user->id;
$cg->gateway_key = '3b6621f970ab18887c4f6dca78d3f8bb'; // $cg->gateway_key = '3b6621f970ab18887c4f6dca78d3f8bb';
$cg->require_cvv = true; // $cg->require_cvv = true;
$cg->show_billing_address = true; // $cg->show_billing_address = true;
$cg->show_shipping_address = true; // $cg->show_shipping_address = true;
$cg->update_details = true; // $cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.authorize')); // $cg->config = encrypt(config('ninja.testvars.authorize'));
$cg->save(); // $cg->save();
} // }
} }
} }