mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 06:34:34 -04:00
Fixes for templates and bulk actions (#3112)
* change route names from camelcase to snake case * Fixes for bulk actions * fixes for bulk actions * fixes for templates * fixes for templates
This commit is contained in:
parent
25514b43cf
commit
abcd2fd1bb
@ -526,8 +526,10 @@ class InvoiceController extends BaseController
|
|||||||
|
|
||||||
$invoices->each(function ($invoice, $key) use($action){
|
$invoices->each(function ($invoice, $key) use($action){
|
||||||
|
|
||||||
|
// $this->invoice_repo->{$action}($invoice);
|
||||||
|
|
||||||
if(auth()->user()->can('edit', $invoice))
|
if(auth()->user()->can('edit', $invoice))
|
||||||
$this->invoice_repo->{$action}($invoice);
|
$this->performAction($invoice, $action, true);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -605,9 +607,16 @@ class InvoiceController extends BaseController
|
|||||||
public function action(ActionInvoiceRequest $request, Invoice $invoice, $action)
|
public function action(ActionInvoiceRequest $request, Invoice $invoice, $action)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
return $this->performAction($invoice, $action);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function performAction(Invoice $invoice, $action, $bulk = false)
|
||||||
|
{
|
||||||
|
/*If we are using bulk actions, we don't want to return anything */
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'clone_to_invoice':
|
case 'clone_to_invoice':
|
||||||
$invoice = CloneInvoiceFactory::create($invocie, auth()->user()->id);
|
$invoice = CloneInvoiceFactory::create($invoice, auth()->user()->id);
|
||||||
return $this->itemResponse($invoice);
|
return $this->itemResponse($invoice);
|
||||||
break;
|
break;
|
||||||
case 'clone_to_quote':
|
case 'clone_to_quote':
|
||||||
@ -625,10 +634,14 @@ class InvoiceController extends BaseController
|
|||||||
return $this->errorResponse(['message' => 'Invoice has no balance owing'], 400);
|
return $this->errorResponse(['message' => 'Invoice has no balance owing'], 400);
|
||||||
|
|
||||||
$invoice = MarkInvoicePaid::dispatchNow($invoice);
|
$invoice = MarkInvoicePaid::dispatchNow($invoice);
|
||||||
|
|
||||||
|
if(!$bulk)
|
||||||
return $this->itemResponse($invoice);
|
return $this->itemResponse($invoice);
|
||||||
break;
|
break;
|
||||||
case 'mark_sent':
|
case 'mark_sent':
|
||||||
$invoice->markSent();
|
$invoice->markSent();
|
||||||
|
|
||||||
|
if(!$bulk)
|
||||||
return $this->itemResponse($invoice);
|
return $this->itemResponse($invoice);
|
||||||
break;
|
break;
|
||||||
case 'download':
|
case 'download':
|
||||||
@ -636,13 +649,19 @@ class InvoiceController extends BaseController
|
|||||||
break;
|
break;
|
||||||
case 'archive':
|
case 'archive':
|
||||||
$this->invoice_repo->archive($invoice);
|
$this->invoice_repo->archive($invoice);
|
||||||
|
|
||||||
|
if(!$bulk)
|
||||||
return $this->listResponse($invoice);
|
return $this->listResponse($invoice);
|
||||||
break;
|
break;
|
||||||
case 'delete':
|
case 'delete':
|
||||||
$this->invoice_repo->delete($invoice);
|
$this->invoice_repo->delete($invoice);
|
||||||
|
|
||||||
|
if(!$bulk)
|
||||||
return $this->listResponse($invoice);
|
return $this->listResponse($invoice);
|
||||||
break;
|
break;
|
||||||
case 'email':
|
case 'email':
|
||||||
|
|
||||||
|
if(!$bulk)
|
||||||
return response()->json(['message'=>'email sent'],200);
|
return response()->json(['message'=>'email sent'],200);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -651,5 +670,5 @@ class InvoiceController extends BaseController
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,8 @@ class TemplateController extends BaseController
|
|||||||
|
|
||||||
if(request()->has('entity') && request()->has('entity_id')){
|
if(request()->has('entity') && request()->has('entity_id')){
|
||||||
|
|
||||||
$class = 'App\Models\\'.ucfirst($entity);
|
$class = 'App\Models\\'.ucfirst(request()->input('entity'));
|
||||||
$entity_obj = $class::find($entity_id)->company();
|
$entity_obj = $class::whereId(request()->input('entity_id'))->company()->first();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,7 +537,7 @@ class UserController extends BaseController
|
|||||||
* Attach an existing user to a company.
|
* Attach an existing user to a company.
|
||||||
*
|
*
|
||||||
* @OA\Post(
|
* @OA\Post(
|
||||||
* path="/api/v1/users/{user}/attachToCompany",
|
* path="/api/v1/users/{user}/attach_to_company",
|
||||||
* operationId="attachUser",
|
* operationId="attachUser",
|
||||||
* tags={"users"},
|
* tags={"users"},
|
||||||
* summary="Attach an existing user to a company",
|
* summary="Attach an existing user to a company",
|
||||||
@ -586,7 +586,7 @@ class UserController extends BaseController
|
|||||||
* Detach an existing user to a company.
|
* Detach an existing user to a company.
|
||||||
*
|
*
|
||||||
* @OA\Delete(
|
* @OA\Delete(
|
||||||
* path="/api/v1/users/{user}/detachFromCompany",
|
* path="/api/v1/users/{user}/detach_from_company",
|
||||||
* operationId="detachUser",
|
* operationId="detachUser",
|
||||||
* tags={"users"},
|
* tags={"users"},
|
||||||
* summary="Detach an existing user to a company",
|
* summary="Detach an existing user to a company",
|
||||||
|
@ -370,7 +370,6 @@ class Invoice extends BaseModel
|
|||||||
|
|
||||||
$balance_adjustment = floatval($balance_adjustment);
|
$balance_adjustment = floatval($balance_adjustment);
|
||||||
|
|
||||||
\Log::error("adjusting balance from ". $this->balance. " to ". ($this->balance + $balance_adjustment));
|
|
||||||
$this->balance = $this->balance + $balance_adjustment;
|
$this->balance = $this->balance + $balance_adjustment;
|
||||||
|
|
||||||
if($this->balance == 0) {
|
if($this->balance == 0) {
|
||||||
|
@ -10,7 +10,7 @@ $factory->define(App\Models\Company::class, function (Faker $faker) {
|
|||||||
'ip' => $faker->ipv4,
|
'ip' => $faker->ipv4,
|
||||||
'db' => config('database.default'),
|
'db' => config('database.default'),
|
||||||
'settings' => CompanySettings::defaults(),
|
'settings' => CompanySettings::defaults(),
|
||||||
'custom_fields' => (object) ['custom1' => '1', 'custom2' => '2', 'custom3'=>3],
|
'custom_fields' => (object) ['custom1' => '1', 'custom2' => '2', 'custom3'=>'3'],
|
||||||
|
|
||||||
// 'address1' => $faker->secondaryAddress,
|
// 'address1' => $faker->secondaryAddress,
|
||||||
// 'address2' => $faker->address,
|
// 'address2' => $faker->address,
|
||||||
|
@ -70,8 +70,8 @@ Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefi
|
|||||||
|
|
||||||
// Route::resource('users', 'UserController')->middleware('password_protected'); // name = (users. index / create / show / update / destroy / edit
|
// Route::resource('users', 'UserController')->middleware('password_protected'); // name = (users. index / create / show / update / destroy / edit
|
||||||
Route::resource('users', 'UserController'); // name = (users. index / create / show / update / destroy / edit
|
Route::resource('users', 'UserController'); // name = (users. index / create / show / update / destroy / edit
|
||||||
Route::post('users/{user}/attachToCompany', 'UserController@attach');
|
Route::post('users/{user}/attach_to_company', 'UserController@attach');
|
||||||
Route::delete('users/{user}/detachFromCompany','UserController@detach');
|
Route::delete('users/{user}/detach_from_company','UserController@detach');
|
||||||
|
|
||||||
|
|
||||||
Route::post('users/bulk', 'UserController@bulk')->name('users.bulk')->middleware('password_protected');
|
Route::post('users/bulk', 'UserController@bulk')->name('users.bulk')->middleware('password_protected');
|
||||||
|
@ -90,7 +90,7 @@ class UserTest extends TestCase
|
|||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $this->token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/attachToCompany?include=company_user');
|
])->post('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/attach_to_company?include=company_user');
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ class UserTest extends TestCase
|
|||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $this->token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->delete('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/detachFromCompany?include=company_user');
|
])->delete('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/detach_from_company?include=company_user');
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user