Fixes for validation

This commit is contained in:
David Bomba 2021-01-08 21:19:26 +11:00
parent 0797c8e4af
commit 13420a93b9
14 changed files with 109 additions and 9 deletions

View File

@ -66,6 +66,10 @@ class UpdateExpenseRequest extends Request
$input['category_id'] = $this->decodePrimaryKey($input['category_id']);
}
if (array_key_exists('documents', $input)) {
unset($input['documents']);
}
if (! array_key_exists('currency_id', $input) || strlen($input['currency_id']) == 0) {
$input['currency_id'] = (string)auth()->user()->company()->settings->currency_id;
}

View File

@ -42,6 +42,9 @@ class StoreExpenseCategoryRequest extends Request
$input = $this->decodePrimaryKeys($input);
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '#fff';
$this->replace($input);
}
}
}

View File

@ -13,6 +13,7 @@ namespace App\Http\Requests\ExpenseCategory;
use App\Http\Requests\Request;
use App\Utils\Traits\ChecksEntityStatus;
use Illuminate\Validation\Rule;
class UpdateExpenseCategoryRequest extends Request
{
@ -33,9 +34,21 @@ class UpdateExpenseCategoryRequest extends Request
$rules = [];
if ($this->input('name')) {
$rules['name'] = 'unique:expense_categories,name,'.$this->id.',id,company_id,'.$this->expense_category->company_id;
// $rules['name'] = 'unique:expense_categories,name,'.$this->id.',id,company_id,'.$this->expense_category->company_id;
$rules['name'] = Rule::unique('expense_categories')->where('company_id', auth()->user()->company()->id)->ignore($this->expense_category->id);
}
return $rules;
}
protected function prepareForValidation()
{
$input = $this->all();
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '#fff';
$this->replace($input);
}
}

View File

@ -67,6 +67,10 @@ class UpdateInvoiceRequest extends Request
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
if (array_key_exists('documents', $input)) {
unset($input['documents']);
}
$this->replace($input);
}

View File

@ -73,6 +73,10 @@ class UpdateQuoteRequest extends Request
$input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']);
}
if (array_key_exists('documents', $input)) {
unset($input['documents']);
}
$input['id'] = $this->quote->id;
$this->replace($input);

View File

@ -91,6 +91,10 @@ class UpdateRecurringInvoiceRequest extends Request
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
}
if (array_key_exists('documents', $input)) {
unset($input['documents']);
}
$this->replace($input);
}

View File

@ -13,6 +13,7 @@ namespace App\Http\Requests\TaskStatus;
use App\Http\Requests\Request;
use App\Utils\Traits\MakesHash;
use Illuminate\Validation\Rule;
class UpdateTaskStatusRequest extends Request
{
@ -33,9 +34,11 @@ class UpdateTaskStatusRequest extends Request
$rules = [];
if ($this->input('name')) {
$rules['name'] = 'unique:task_statuses,name,'.$this->id.',id,company_id,'.$this->task_status->company_id;
//$rules['name'] = 'unique:task_statuses,name,'.$this->id.',id,company_id,'.$this->task_status->company_id;
$rules['name'] = Rule::unique('task_statuses')->where('company_id', auth()->user()->company()->id)->ignore($this->task_status->id);
}
return $rules;
}

View File

@ -88,7 +88,7 @@ class CreditEmailEngine extends BaseEmailEngine
->setViewText(ctrans('texts.view_credit'));
if ($this->client->getSetting('pdf_email_attachment') !== false) {
$this->setAttachments([$this->credit->pdf_file_path()]);
$this->setAttachments(['path' => $this->credit->pdf_file_path(), 'name' => basename($this->credit->pdf_file_path())]);
}
return $this;

View File

@ -98,6 +98,19 @@ class InvoiceEmailEngine extends BaseEmailEngine
if ($this->client->getSetting('pdf_email_attachment') !== false) {
$this->setAttachments([$this->invoice->pdf_file_path()]);
// $this->setAttachments(['path' => $this->invoice->pdf_file_path(), 'name' => basename($this->invoice->pdf_file_path())]);
}
//attach third party documents
if($this->client->getSetting('document_email_attachment') !== false){
// Storage::url
foreach($this->invoice->documents as $document){
// $this->setAttachments(['path'=>$document->filePath(),'name'=>$document->name]);
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => $document->type]]);
}
}
return $this;

View File

@ -88,7 +88,9 @@ class QuoteEmailEngine extends BaseEmailEngine
->setViewText(ctrans('texts.view_quote'));
if ($this->client->getSetting('pdf_email_attachment') !== false) {
$this->setAttachments([$this->invitation->pdf_file_path()]);
// $this->setAttachments([$this->quote->pdf_file_path()]);
$this->setAttachments(['path' => $this->quote->pdf_file_path(), 'name' => basename($this->quote->pdf_file_path())]);
}
return $this;

View File

@ -84,8 +84,18 @@ class TemplateEmail extends Mailable
//conditionally attach files
if ($settings->pdf_email_attachment !== false && ! empty($this->build_email->getAttachments())) {
nlog(count($this->build_email->getAttachments()));
nlog($this->build_email->getAttachments());
foreach ($this->build_email->getAttachments() as $file) {
$this->attach($file);
nlog($file);
if(count(array_keys($file)) > 1)
$this->attach($file['path'], ['as' => $file['name'], 'mime' => $file['mime']]);
else
$this->attach($file);
}
}

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ExpensesTableAdditionalFields extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('expenses', function (Blueprint $table) {
$table->decimal('tax_amount1', 20, 6)->change();
$table->decimal('tax_amount2', 20, 6)->change();
$table->decimal('tax_amount3', 20, 6)->change();
$table->boolean('uses_inclusive_taxes')->default(0);
$table->boolean('amount_is_pretax')->default(1);
});
Schema::table('companies', function (Blueprint $table) {
$table->boolean('expense_inclusive_taxes')->default(0);
$table->boolean('expense_amount_is_pretax')->default(1);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -99,8 +99,8 @@
function invokeServiceWorkerUpdateFlow() {
// you have a better UI here, reloading is not a great user experince here.
const confirmed = confirm('New version of the app is available. Refresh now');
if (confirmed) {
const confirmed = alert('New version of the app is available. Refresh now');
if (confirmed == true) {
window.location.reload();
}
}

View File

@ -540,7 +540,7 @@ trait MockAccountData
$data[1]['fee_tax_rate2'] = '';
$data[1]['fee_tax_name3'] = '';
$data[1]['fee_tax_rate3'] = 0;
$data[1]['fee_cap'] = '';
$cg = new CompanyGateway;
$cg->company_id = $this->company->id;
$cg->user_id = $this->user->id;