mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 08:54:34 -04:00
Fixes for required expense fields
This commit is contained in:
parent
9c324f187e
commit
8b49c83a67
@ -37,23 +37,13 @@ class StoreExpenseRequest extends Request
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Ensure we have a client name, and that all emails are unique*/
|
|
||||||
//$rules['name'] = 'required|min:1';
|
|
||||||
$rules['id_number'] = 'unique:expenses,id_number,'.$this->id.',id,company_id,'.$this->company_id;
|
$rules['id_number'] = 'unique:expenses,id_number,'.$this->id.',id,company_id,'.$this->company_id;
|
||||||
//$rules['settings'] = new ValidExpenseGroupSettingsRule();
|
|
||||||
$rules['contacts.*.email'] = 'nullable|distinct';
|
$rules['contacts.*.email'] = 'nullable|distinct';
|
||||||
|
|
||||||
$rules['number'] = new UniqueExpenseNumberRule($this->all());
|
$rules['number'] = new UniqueExpenseNumberRule($this->all());
|
||||||
|
|
||||||
// $contacts = request('contacts');
|
|
||||||
|
|
||||||
// if (is_array($contacts)) {
|
|
||||||
// for ($i = 0; $i < count($contacts); $i++) {
|
|
||||||
|
|
||||||
// //$rules['contacts.' . $i . '.email'] = 'nullable|email|distinct';
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,15 +55,27 @@ class UniqueExpenseNumberRule implements Rule
|
|||||||
*/
|
*/
|
||||||
private function checkIfExpenseNumberUnique() : bool
|
private function checkIfExpenseNumberUnique() : bool
|
||||||
{
|
{
|
||||||
$expense = Expense::where('client_id', $this->input['client_id'])
|
if(empty($this->input['number']))
|
||||||
->where('number', $this->input['number'])
|
return true;
|
||||||
->withTrashed()
|
|
||||||
->exists();
|
|
||||||
|
|
||||||
if ($expense) {
|
$expense = Expense::query()
|
||||||
return false;
|
->where('number', $this->input['number'])
|
||||||
}
|
->withTrashed();
|
||||||
|
|
||||||
return true;
|
// if(isset($this->input['client_id']))
|
||||||
|
// $expense->where('client_id', $this->input['client_id']);
|
||||||
|
|
||||||
|
return $expense->exists();
|
||||||
|
|
||||||
|
// $expense = Expense::where('client_id', $this->input['client_id'])
|
||||||
|
// ->where('number', $this->input['number'])
|
||||||
|
// ->withTrashed()
|
||||||
|
// ->exists();
|
||||||
|
|
||||||
|
// if ($expense) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
160
app/Models/Presenters/VendorPresenter.php
Normal file
160
app/Models/Presenters/VendorPresenter.php
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Models\Presenters;
|
||||||
|
|
||||||
|
use App\Models\Country;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class VendorPresenter.
|
||||||
|
*/
|
||||||
|
class VendorPresenter extends EntityPresenter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function name()
|
||||||
|
{
|
||||||
|
if ($this->entity->name) {
|
||||||
|
return $this->entity->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$contact = $this->entity->primary_contact->first();
|
||||||
|
|
||||||
|
$contact_name = 'No Contact Set';
|
||||||
|
|
||||||
|
if ($contact && (strlen($contact->first_name) >= 1 || strlen($contact->last_name) >= 1)) {
|
||||||
|
$contact_name = $contact->first_name.' '.$contact->last_name;
|
||||||
|
} elseif ($contact && (strlen($contact->email))) {
|
||||||
|
$contact_name = $contact->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $contact_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function primary_contact_name()
|
||||||
|
{
|
||||||
|
return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->first_name.' '.$this->entity->primary_contact->first()->last_name : 'No primary contact set';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function email()
|
||||||
|
{
|
||||||
|
return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->email : 'No Email Set';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function address()
|
||||||
|
{
|
||||||
|
$str = '';
|
||||||
|
$vendor = $this->entity;
|
||||||
|
|
||||||
|
if ($address1 = $vendor->address1) {
|
||||||
|
$str .= e($address1).'<br/>';
|
||||||
|
}
|
||||||
|
if ($address2 = $vendor->address2) {
|
||||||
|
$str .= e($address2).'<br/>';
|
||||||
|
}
|
||||||
|
if ($cityState = $this->getCityState()) {
|
||||||
|
$str .= e($cityState).'<br/>';
|
||||||
|
}
|
||||||
|
if ($country = $vendor->country) {
|
||||||
|
$str .= e($country->name).'<br/>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shipping_address()
|
||||||
|
{
|
||||||
|
$str = '';
|
||||||
|
$vendor = $this->entity;
|
||||||
|
|
||||||
|
if ($address1 = $vendor->shipping_address1) {
|
||||||
|
$str .= e($address1).'<br/>';
|
||||||
|
}
|
||||||
|
if ($address2 = $vendor->shipping_address2) {
|
||||||
|
$str .= e($address2).'<br/>';
|
||||||
|
}
|
||||||
|
if ($cityState = $this->getCityState()) {
|
||||||
|
$str .= e($cityState).'<br/>';
|
||||||
|
}
|
||||||
|
if ($country = $vendor->country) {
|
||||||
|
$str .= e($country->name).'<br/>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function phone()
|
||||||
|
{
|
||||||
|
return $this->entity->phone ?: '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function website()
|
||||||
|
{
|
||||||
|
return $this->entity->website ?: '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculated company data fields
|
||||||
|
* using settings.
|
||||||
|
*/
|
||||||
|
public function company_name()
|
||||||
|
{
|
||||||
|
$settings = $this->entity->company->settings;;
|
||||||
|
|
||||||
|
return $settings->name ?: ctrans('texts.untitled_account');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function company_address()
|
||||||
|
{
|
||||||
|
$settings = $this->entity->company->settings;;
|
||||||
|
|
||||||
|
$str = '';
|
||||||
|
|
||||||
|
if ($settings->address1) {
|
||||||
|
$str .= e($settings->address1).'<br/>';
|
||||||
|
}
|
||||||
|
if ($settings->address2) {
|
||||||
|
$str .= e($settings->address2).'<br/>';
|
||||||
|
}
|
||||||
|
if ($cityState = $this->getCityState()) {
|
||||||
|
$str .= e($cityState).'<br/>';
|
||||||
|
}
|
||||||
|
if ($country = Country::find($settings->country_id)) {
|
||||||
|
$str .= e($country->name).'<br/>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCityState()
|
||||||
|
{
|
||||||
|
$settings = $this->entity->company->settings;;
|
||||||
|
|
||||||
|
$country = false;
|
||||||
|
|
||||||
|
if ($settings->country_id) {
|
||||||
|
$country = Country::find($settings->country_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$swap = $country && $country->swap_postal_code;
|
||||||
|
|
||||||
|
$city = e($settings->city ?: '');
|
||||||
|
$state = e($settings->state ?: '');
|
||||||
|
$postalCode = e($settings->postal_code ?: '');
|
||||||
|
|
||||||
|
if ($city || $state || $postalCode) {
|
||||||
|
return $this->cityStateZip($city, $state, $postalCode, $swap);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,9 @@ class ProjectNameUniqueRemoval extends Migration
|
|||||||
Schema::table('expenses', function (Blueprint $table) {
|
Schema::table('expenses', function (Blueprint $table) {
|
||||||
$table->unsignedInteger('invoice_currency_id')->nullable()->change();
|
$table->unsignedInteger('invoice_currency_id')->nullable()->change();
|
||||||
$table->unsignedInteger('expense_currency_id')->nullable()->change();
|
$table->unsignedInteger('expense_currency_id')->nullable()->change();
|
||||||
|
$table->text('private_notes')->nullable()->change();
|
||||||
|
$table->text('public_notes')->nullable()->change();
|
||||||
|
$table->text('transaction_reference')->nullable()->change();
|
||||||
});
|
});
|
||||||
|
|
||||||
Schema::table('companies', function (Blueprint $table) {
|
Schema::table('companies', function (Blueprint $table) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user