diff --git a/app/Http/Controllers/DocumentController.php b/app/Http/Controllers/DocumentController.php index 9c20cd2acdaf..317b5c436c1c 100644 --- a/app/Http/Controllers/DocumentController.php +++ b/app/Http/Controllers/DocumentController.php @@ -7,10 +7,35 @@ 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; 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. * @@ -50,11 +75,14 @@ class DocumentController extends BaseController */ public function show(ShowDocumentRequest $request, Document $document) { - return response()->streamDownload(function () use($document) { - echo file_get_contents($document->generateUrl()); - }, basename($document->generateUrl())); + return $this->itemResponse($document); + } - //return response()->download($document->generateUrl()); + public function download(DownloadDocumentRequest $request, Document $document) + { + return response()->streamDownload(function () use($document) { + echo file_get_contents($document->generateUrl()); + }, basename($document->generateUrl())); } /** @@ -88,11 +116,35 @@ class DocumentController extends BaseController */ public function destroy(DestroyDocumentRequest $request, Document $document) { - // + $this->document_repo->delete($document); + + return response()->json(['message'=>'success']); } 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()); } } diff --git a/app/Models/Document.php b/app/Models/Document.php index b977c547e85c..63c736dfdfce 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -119,4 +119,9 @@ class Document extends BaseModel //return route('document.show', ['document' => $this->hashed_id]); } + + public function deleteFile() + { + Storage::disk($this->disk)->delete($this->url); + } } diff --git a/app/Transformers/PaymentTransformer.php b/app/Transformers/PaymentTransformer.php index a2f574dabf10..35f87ff45a0b 100644 --- a/app/Transformers/PaymentTransformer.php +++ b/app/Transformers/PaymentTransformer.php @@ -25,7 +25,9 @@ class PaymentTransformer extends EntityTransformer protected $serializer; - protected $defaultIncludes = ['invoices']; + protected $defaultIncludes = [ + // 'invoices' + ]; protected $availableIncludes = [ 'client', diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index c4eed11060dc..855dfecf51dc 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -265,29 +265,29 @@ class RandomDataSeeder extends Seeder ]); - // if (config('ninja.testvars.stripe')) { - // $cg = new CompanyGateway; - // $cg->company_id = $company->id; - // $cg->user_id = $user->id; - // $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; - // $cg->require_cvv = true; - // $cg->show_billing_address = true; - // $cg->show_shipping_address = true; - // $cg->update_details = true; - // $cg->config = encrypt(config('ninja.testvars.stripe')); - // $cg->save(); + if (config('ninja.testvars.stripe')) { + $cg = new CompanyGateway; + $cg->company_id = $company->id; + $cg->user_id = $user->id; + $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; + $cg->require_cvv = true; + $cg->show_billing_address = true; + $cg->show_shipping_address = true; + $cg->update_details = true; + $cg->config = encrypt(config('ninja.testvars.stripe')); + $cg->save(); - // $cg = new CompanyGateway; - // $cg->company_id = $company->id; - // $cg->user_id = $user->id; - // $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; - // $cg->require_cvv = true; - // $cg->show_billing_address = true; - // $cg->show_shipping_address = true; - // $cg->update_details = true; - // $cg->config = encrypt(config('ninja.testvars.stripe')); - // $cg->save(); - // } + $cg = new CompanyGateway; + $cg->company_id = $company->id; + $cg->user_id = $user->id; + $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; + $cg->require_cvv = true; + $cg->show_billing_address = true; + $cg->show_shipping_address = true; + $cg->update_details = true; + $cg->config = encrypt(config('ninja.testvars.stripe')); + $cg->save(); + } // if (config('ninja.testvars.paypal')) { // $cg = new CompanyGateway; @@ -315,18 +315,18 @@ class RandomDataSeeder extends Seeder // $cg->save(); // } - if(config('ninja.testvars.authorize')) { - $cg = new CompanyGateway; - $cg->company_id = $company->id; - $cg->user_id = $user->id; - $cg->gateway_key = '3b6621f970ab18887c4f6dca78d3f8bb'; - $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; - $cg->update_details = true; - $cg->config = encrypt(config('ninja.testvars.authorize')); - $cg->save(); - } + // if(config('ninja.testvars.authorize')) { + // $cg = new CompanyGateway; + // $cg->company_id = $company->id; + // $cg->user_id = $user->id; + // $cg->gateway_key = '3b6621f970ab18887c4f6dca78d3f8bb'; + // $cg->require_cvv = true; + // $cg->show_billing_address = true; + // $cg->show_shipping_address = true; + // $cg->update_details = true; + // $cg->config = encrypt(config('ninja.testvars.authorize')); + // $cg->save(); + // } } }