mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Merge pull request #6670 from turbo124/v5-develop
Set company as a reference for Company Export
This commit is contained in:
commit
68232f9f32
@ -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);
|
||||
}
|
||||
}
|
||||
|
44
app/Http/Requests/Design/DefaultDesignRequest.php
Normal file
44
app/Http/Requests/Design/DefaultDesignRequest.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\Design;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class DefaultDesignRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->isAdmin();
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'entity' => 'required',
|
||||
'design_id' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
$input = $this->decodePrimaryKeys($input);
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user