diff --git a/app/Http/Controllers/DesignController.php b/app/Http/Controllers/DesignController.php index 8f516c7488..7dfb8f5ddb 100644 --- a/app/Http/Controllers/DesignController.php +++ b/app/Http/Controllers/DesignController.php @@ -14,6 +14,7 @@ namespace App\Http\Controllers; use App\Factory\DesignFactory; use App\Filters\DesignFilters; use App\Http\Requests\Design\CreateDesignRequest; +use App\Http\Requests\Design\DefaultDesignRequest; use App\Http\Requests\Design\DestroyDesignRequest; use App\Http\Requests\Design\EditDesignRequest; use App\Http\Requests\Design\ShowDesignRequest; @@ -487,4 +488,36 @@ class DesignController extends BaseController return $this->listResponse(Design::withTrashed()->whereIn('id', $this->transformKeys($ids))); } + + public function default(DefaultDesignRequest $request) + { + $design_id = $request->int('design_id'); + $entity = $request->input('entity'); + $company = auth()->user()->getCompany(); + + $design = Design::where('company_id', $company->id) + ->where('id', $design_id) + ->exists(); + + if(!$design) + return response()->json(['message' => 'Design does not exist.'], 400); + + switch ($entity) { + case 'invoice': + $company->invoices()->update(['design_id' => $design_id]); + break; + case 'quote': + $company->quotes()->update(['design_id' => $design_id]); + break; + case 'credit': + $company->credits()->update(['design_id' => $design_id]); + break; + + default: + // code... + break; + } + + return response()->json(['message' = > 'success'],200); + } } diff --git a/app/Http/Requests/Design/DefaultDesignRequest.php b/app/Http/Requests/Design/DefaultDesignRequest.php new file mode 100644 index 0000000000..5e523ae6d1 --- /dev/null +++ b/app/Http/Requests/Design/DefaultDesignRequest.php @@ -0,0 +1,44 @@ +user()->isAdmin(); + } + + public function rules() + { + return [ + 'entity' => 'required', + 'design_id' => 'required', + ]; + } + + protected function prepareForValidation() + { + $input = $this->all(); + + $input = $this->decodePrimaryKeys($input); + + $this->replace($input); + } +} diff --git a/app/Jobs/Company/CompanyExport.php b/app/Jobs/Company/CompanyExport.php index 537083a660..77f9240769 100644 --- a/app/Jobs/Company/CompanyExport.php +++ b/app/Jobs/Company/CompanyExport.php @@ -506,10 +506,12 @@ class CompanyExport implements ShouldQueue $t = app('translator'); $t->replace(Ninja::transformTranslations($this->company->settings)); + $company_reference = Company::find($this->company->id);; + $nmo = new NinjaMailerObject; - $nmo->mailable = new DownloadBackup($storage_file_path, $this->company); + $nmo->mailable = new DownloadBackup($storage_file_path, $company_reference); $nmo->to_user = $this->user; - $nmo->company = $this->company; + $nmo->company = $company_reference; $nmo->settings = $this->company->settings; NinjaMailerJob::dispatch($nmo); diff --git a/routes/api.php b/routes/api.php index 7cc0055bf3..8e230cf3bf 100644 --- a/routes/api.php +++ b/routes/api.php @@ -67,7 +67,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::resource('designs', 'DesignController'); // name = (payments. index / create / show / update / destroy / edit Route::post('designs/bulk', 'DesignController@bulk')->name('designs.bulk'); - + Route::post('designs/set/default', 'DesignController@default')->name('designs.default'); Route::resource('documents', 'DocumentController'); // name = (documents. index / create / show / update / destroy / edit Route::get('documents/{document}/download', 'DocumentController@download')->name('documents.download');