diff --git a/app/Http/Requests/Expense/StoreExpenseRequest.php b/app/Http/Requests/Expense/StoreExpenseRequest.php
index 22aee8ca7c0a..741cb6fabbde 100644
--- a/app/Http/Requests/Expense/StoreExpenseRequest.php
+++ b/app/Http/Requests/Expense/StoreExpenseRequest.php
@@ -37,23 +37,13 @@ class StoreExpenseRequest extends Request
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['settings'] = new ValidExpenseGroupSettingsRule();
+
$rules['contacts.*.email'] = 'nullable|distinct';
$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;
}
diff --git a/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php b/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php
index 4dfbde5e2298..4ae379757df3 100644
--- a/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php
+++ b/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php
@@ -55,15 +55,27 @@ class UniqueExpenseNumberRule implements Rule
*/
private function checkIfExpenseNumberUnique() : bool
{
- $expense = Expense::where('client_id', $this->input['client_id'])
- ->where('number', $this->input['number'])
- ->withTrashed()
- ->exists();
+ if(empty($this->input['number']))
+ return true;
- if ($expense) {
- return false;
- }
+ $expense = Expense::query()
+ ->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;
}
}
diff --git a/app/Models/Presenters/VendorPresenter.php b/app/Models/Presenters/VendorPresenter.php
new file mode 100644
index 000000000000..b74212cf67a8
--- /dev/null
+++ b/app/Models/Presenters/VendorPresenter.php
@@ -0,0 +1,160 @@
+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).'
';
+ }
+ if ($address2 = $vendor->address2) {
+ $str .= e($address2).'
';
+ }
+ if ($cityState = $this->getCityState()) {
+ $str .= e($cityState).'
';
+ }
+ if ($country = $vendor->country) {
+ $str .= e($country->name).'
';
+ }
+
+ return $str;
+ }
+
+ public function shipping_address()
+ {
+ $str = '';
+ $vendor = $this->entity;
+
+ if ($address1 = $vendor->shipping_address1) {
+ $str .= e($address1).'
';
+ }
+ if ($address2 = $vendor->shipping_address2) {
+ $str .= e($address2).'
';
+ }
+ if ($cityState = $this->getCityState()) {
+ $str .= e($cityState).'
';
+ }
+ if ($country = $vendor->country) {
+ $str .= e($country->name).'
';
+ }
+
+ 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).'
';
+ }
+ if ($settings->address2) {
+ $str .= e($settings->address2).'
';
+ }
+ if ($cityState = $this->getCityState()) {
+ $str .= e($cityState).'
';
+ }
+ if ($country = Country::find($settings->country_id)) {
+ $str .= e($country->name).'
';
+ }
+
+ 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;
+ }
+ }
+}
diff --git a/database/migrations/2020_10_19_101823_project_name_unique_removal.php b/database/migrations/2020_10_19_101823_project_name_unique_removal.php
index ff0610f77f13..970e6a14bb89 100644
--- a/database/migrations/2020_10_19_101823_project_name_unique_removal.php
+++ b/database/migrations/2020_10_19_101823_project_name_unique_removal.php
@@ -21,6 +21,9 @@ class ProjectNameUniqueRemoval extends Migration
Schema::table('expenses', function (Blueprint $table) {
$table->unsignedInteger('invoice_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) {