mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 00:44:35 -04:00
Working on unique rules for numbers
This commit is contained in:
parent
1f00fe7b17
commit
b841fe7000
@ -16,6 +16,7 @@ use App\Http\Requests\Request;
|
|||||||
use App\Http\ValidationRules\ValidClientGroupSettingsRule;
|
use App\Http\ValidationRules\ValidClientGroupSettingsRule;
|
||||||
use App\Utils\Traits\ChecksEntityStatus;
|
use App\Utils\Traits\ChecksEntityStatus;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class UpdateClientRequest extends Request
|
class UpdateClientRequest extends Request
|
||||||
{
|
{
|
||||||
@ -52,7 +53,14 @@ class UpdateClientRequest extends Request
|
|||||||
$rules['country_id'] = 'integer|nullable';
|
$rules['country_id'] = 'integer|nullable';
|
||||||
$rules['shipping_country_id'] = 'integer|nullable';
|
$rules['shipping_country_id'] = 'integer|nullable';
|
||||||
//$rules['id_number'] = 'unique:clients,id_number,,id,company_id,' . auth()->user()->company()->id;
|
//$rules['id_number'] = 'unique:clients,id_number,,id,company_id,' . auth()->user()->company()->id;
|
||||||
$rules['id_number'] = 'unique:clients,id_number,'.$this->id.',id,company_id,'.$this->company_id;
|
//$rules['id_number'] = 'unique:clients,id_number,'.$this->id.',id,company_id,'.$this->company_id;
|
||||||
|
|
||||||
|
if($this->id_number)
|
||||||
|
$rules['id_number'] = Rule::unique('clients')->where('company_id', auth()->user()->company()->id)->ignore($this->client->id);
|
||||||
|
|
||||||
|
if($this->number)
|
||||||
|
$rules['number'] = Rule::unique('clients')->where('company_id', auth()->user()->company()->id)->ignore($this->client->id);
|
||||||
|
|
||||||
$rules['settings'] = new ValidClientGroupSettingsRule();
|
$rules['settings'] = new ValidClientGroupSettingsRule();
|
||||||
$rules['contacts.*.email'] = 'bail|nullable|distinct|sometimes|email';
|
$rules['contacts.*.email'] = 'bail|nullable|distinct|sometimes|email';
|
||||||
$rules['contacts.*.password'] = [
|
$rules['contacts.*.password'] = [
|
||||||
@ -72,7 +80,6 @@ class UpdateClientRequest extends Request
|
|||||||
public function messages()
|
public function messages()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'unique' => ctrans('validation.unique', ['attribute' => 'email']),
|
|
||||||
'email' => ctrans('validation.email', ['attribute' => 'email']),
|
'email' => ctrans('validation.email', ['attribute' => 'email']),
|
||||||
'name.required' => ctrans('validation.required', ['attribute' => 'name']),
|
'name.required' => ctrans('validation.required', ['attribute' => 'name']),
|
||||||
'required' => ctrans('validation.required', ['attribute' => 'email']),
|
'required' => ctrans('validation.required', ['attribute' => 'email']),
|
||||||
|
@ -35,12 +35,15 @@ class UpdatePaymentRequest extends Request
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'number' => 'nullable|unique:payments,number,'.$this->id.',id,company_id,'.$this->payment->company_id,
|
|
||||||
'invoices' => ['array', new PaymentAppliedValidAmount, new ValidCreditsPresentRule],
|
'invoices' => ['array', new PaymentAppliedValidAmount, new ValidCreditsPresentRule],
|
||||||
'invoices.*.invoice_id' => 'distinct',
|
'invoices.*.invoice_id' => 'distinct',
|
||||||
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
|
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($this->input('number')) {
|
||||||
|
$rules['number'] = 'nullable|unique:payments,number,'.$this->id.',id,company_id,'.$this->payment->company_id;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->input('documents') && is_array($this->input('documents'))) {
|
if ($this->input('documents') && is_array($this->input('documents'))) {
|
||||||
$documents = count($this->input('documents'));
|
$documents = count($this->input('documents'));
|
||||||
|
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddUniqueConstraintsOnAllEntities extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('expenses', function (Blueprint $table) {
|
||||||
|
$table->unique(['company_id', 'number']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('tasks', function (Blueprint $table) {
|
||||||
|
$table->unique(['company_id', 'number']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('vendors', function (Blueprint $table) {
|
||||||
|
$table->unique(['company_id', 'number']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('payments', function (Blueprint $table) {
|
||||||
|
$table->unique(['company_id', 'number']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('projects', function (Blueprint $table) {
|
||||||
|
$table->unique(['company_id', 'number']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('clients', function (Blueprint $table) {
|
||||||
|
$table->unique(['company_id', 'number']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('payment_hashes', function (Blueprint $table) {
|
||||||
|
$table->unique(['hash']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('recurring_invoices', function (Blueprint $table) {
|
||||||
|
$table->string('number')->change();
|
||||||
|
$table->unique(['company_id', 'number']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('recurring_invoice_invitations', function (Blueprint $table) {
|
||||||
|
$table->unique(['client_contact_id', 'recurring_invoice_id'],'recur_invoice_client_unique');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user