1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge branch 'v5-develop' of https://github.com/turbo124/invoiceninja into v5-develop

This commit is contained in:
David Bomba 2022-01-27 16:15:56 +11:00
commit 2de19e83f7
3 changed files with 110 additions and 1 deletions

View File

@ -18,6 +18,7 @@ use App\Factory\CloneQuoteToInvoiceFactory;
use App\Factory\QuoteFactory;
use App\Filters\QuoteFilters;
use App\Http\Requests\Quote\ActionQuoteRequest;
use App\Http\Requests\Quote\BulkActionQuoteRequest;
use App\Http\Requests\Quote\CreateQuoteRequest;
use App\Http\Requests\Quote\DestroyQuoteRequest;
use App\Http\Requests\Quote\EditQuoteRequest;
@ -510,7 +511,7 @@ class QuoteController extends BaseController
* ),
* )
*/
public function bulk()
public function bulk(BulkActionQuoteRequest $request)
{
$action = request()->input('action');

View File

@ -0,0 +1,41 @@
<?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\Quote;
use App\Http\Requests\Request;
use App\Http\ValidationRules\Quote\ConvertableQuoteRule;
class BulkActionQuoteRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return true;
}
public function rules()
{
$input = $this->all();
$rules = [];
if($input['action'] == 'convert_to_invoice')
$rules['action'] = [new ConvertableQuoteRule()];
return $rules;
}
}

View File

@ -0,0 +1,67 @@
<?php
/**
* Quote Ninja (https://quoteninja.com).
*
* @link https://github.com/quoteninja/quoteninja source repository
*
* @copyright Copyright (c) 2021. Quote Ninja LLC (https://quoteninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\ValidationRules\Quote;
use App\Models\Quote;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Validation\Rule;
/**
* Class ConvertableQuoteRule.
*/
class ConvertableQuoteRule implements Rule
{
use MakesHash;
public function __construct()
{
}
/**
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return $this->checkQuoteIsConvertable(); //if it exists, return false!
}
/**
* @return string
*/
public function message()
{
return ctrans('texts.quote_has_expired');
}
/**
* @return bool
*/
private function checkQuoteIsConvertable() : bool
{
$ids = request()->input('ids');
$quotes = Quote::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
foreach($quotes as $quote){
if(!$quote->service()->isConvertable())
return false;
}
return true;
}
}