1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
This commit is contained in:
David Bomba 2020-08-13 16:15:46 +10:00
parent f86a57c632
commit 1415434d34
6 changed files with 153 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Requests\Credit;
use App\Http\ValidationRules\Credit\UniqueCreditNumberRule;
use App\Models\Credit;
use App\Utils\Traits\CleanLineItems;
use App\Utils\Traits\MakesHash;
@ -43,6 +44,8 @@ class StoreCreditRequest extends FormRequest
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
$rules['number'] = new UniqueCreditNumberRule($this->all());
return $rules;
}

View File

@ -0,0 +1,70 @@
<?php
/**
* Credit Ninja (https://creditninja.com)
*
* @link https://github.com/creditninja/creditninja source repository
*
* @copyright Copyright (c) 2020. Credit Ninja LLC (https://creditninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\ValidationRules\Credit;
use App\Libraries\MultiDB;
use App\Models\Credit;
use App\Models\User;
use Illuminate\Contracts\Validation\Rule;
/**
* Class UniqueCreditNumberRule
* @package App\Http\ValidationRules
*/
class UniqueCreditNumberRule implements Rule
{
public $input;
public function __construct($input)
{
$this->input = $input;
}
/**
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return $this->checkIfCreditNumberUnique(); //if it exists, return false!
}
/**
* @return string
*/
public function message()
{
return "Credit number already taken";
}
/**
* @param $email
*
* //off,when_sent,when_paid
*
* @return bool
*/
private function checkIfCreditNumberUnique() : bool
{
$credit = Credit::where('client_id', $this->input['client_id'])
->where('number', $this->input['number'])
->withTrashed()
->exists();
if($credit)
return false;
return true;
}
}

View File

@ -42,6 +42,9 @@ class UpdateCreditRequest extends FormRequest
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
if($this->input('number'))
$rules['number'] = 'unique:quotes,number,' . $this->id . ',id,company_id,' . $this->invoice->company_id;
return $rules;
}

View File

@ -12,6 +12,7 @@
namespace App\Http\Requests\Quote;
use App\Http\Requests\Request;
use App\Http\ValidationRules\Quote\UniqueQuoteNumberRule;
use App\Models\Quote;
use App\Utils\Traits\CleanLineItems;
use App\Utils\Traits\MakesHash;
@ -93,6 +94,8 @@ class StoreQuoteRequest extends Request
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
$rules['number'] = new UniqueQuoteNumberRule($this->all());
return $rules;
}

View File

@ -0,0 +1,70 @@
<?php
/**
* Quote Ninja (https://quoteninja.com)
*
* @link https://github.com/quoteninja/quoteninja source repository
*
* @copyright Copyright (c) 2020. Quote Ninja LLC (https://quoteninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\ValidationRules\Quote;
use App\Libraries\MultiDB;
use App\Models\Quote;
use App\Models\User;
use Illuminate\Contracts\Validation\Rule;
/**
* Class UniqueQuoteNumberRule
* @package App\Http\ValidationRules
*/
class UniqueQuoteNumberRule implements Rule
{
public $input;
public function __construct($input)
{
$this->input = $input;
}
/**
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return $this->checkIfQuoteNumberUnique(); //if it exists, return false!
}
/**
* @return string
*/
public function message()
{
return "Quote number already taken";
}
/**
* @param $email
*
* //off,when_sent,when_paid
*
* @return bool
*/
private function checkIfQuoteNumberUnique() : bool
{
$quote = Quote::where('client_id', $this->input['client_id'])
->where('number', $this->input['number'])
->withTrashed()
->exists();
if($quote)
return false;
return true;
}
}

View File

@ -50,6 +50,10 @@ class UpdateQuoteRequest extends Request
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
if($this->input('number'))
$rules['number'] = 'unique:quotes,number,' . $this->id . ',id,company_id,' . $this->invoice->company_id;
return $rules;
}