Vendor Notifications

This commit is contained in:
David Bomba 2023-11-23 23:54:42 +11:00
parent b1d11c0bbe
commit 9ec383ce93
5 changed files with 100 additions and 43 deletions

View File

@ -28,34 +28,45 @@ class StoreExpenseRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('create', Expense::class); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('create', Expense::class);
} }
public function rules() public function rules()
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = []; $rules = [];
if ($this->number) { if ($this->number) {
$rules['number'] = Rule::unique('expenses')->where('company_id', auth()->user()->company()->id); $rules['number'] = Rule::unique('expenses')->where('company_id', $user->company()->id);
} }
if ($this->client_id) { if ($this->client_id) {
$rules['client_id'] = 'bail|sometimes|exists:clients,id,company_id,'.auth()->user()->company()->id; $rules['client_id'] = 'bail|sometimes|exists:clients,id,company_id,'.$user->company()->id;
} }
$rules['category_id'] = 'bail|nullable|sometimes|exists:expense_categories,id,company_id,'.auth()->user()->company()->id.',is_deleted,0'; $rules['category_id'] = 'bail|nullable|sometimes|exists:expense_categories,id,company_id,'.$user->company()->id.',is_deleted,0';
$rules['payment_date'] = 'bail|nullable|sometimes|date:Y-m-d';
$rules['date'] = 'bail|sometimes|date:Y-m-d';
return $this->globalRules($rules); return $this->globalRules($rules);
} }
public function prepareForValidation() public function prepareForValidation()
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
$input = $this->all(); $input = $this->all();
$input = $this->decodePrimaryKeys($input); $input = $this->decodePrimaryKeys($input);
if (! array_key_exists('currency_id', $input) || strlen($input['currency_id']) == 0) { if (! array_key_exists('currency_id', $input) || strlen($input['currency_id']) == 0) {
$input['currency_id'] = (string) auth()->user()->company()->settings->currency_id; $input['currency_id'] = (string) $user->company()->settings->currency_id;
} }
if (array_key_exists('color', $input) && is_null($input['color'])) { if (array_key_exists('color', $input) && is_null($input['color'])) {
@ -80,7 +91,6 @@ class StoreExpenseRequest extends Request
public function messages() public function messages()
{ {
return [ return [
// 'unique' => ctrans('validation.unique', ['attribute' => 'number']),
]; ];
} }
} }

View File

@ -41,6 +41,12 @@ class ExpenseRepository extends BaseRepository
*/ */
public function save(array $data, Expense $expense): Expense public function save(array $data, Expense $expense): Expense
{ {
if(isset($data['payment_date']) && $data['payment_date'] == $expense->payment_date) {
//do nothing
} elseif(isset($data['payment_date']) && strlen($data['payment_date']) > 1 && $expense->company->notify_vendor_when_paid) {
nlog("NOT SAME");
}
$expense->fill($data); $expense->fill($data);
if (!$expense->id) { if (!$expense->id) {
@ -50,8 +56,8 @@ class ExpenseRepository extends BaseRepository
if (empty($expense->number)) { if (empty($expense->number)) {
$expense = $this->findAndSaveNumber($expense); $expense = $this->findAndSaveNumber($expense);
} }
else
$expense->saveQuietly(); $expense->saveQuietly();
if (array_key_exists('documents', $data)) { if (array_key_exists('documents', $data)) {
$this->saveDocuments($data['documents'], $expense); $this->saveDocuments($data['documents'], $expense);

File diff suppressed because one or more lines are too long

View File

@ -468,6 +468,7 @@ class TemplateService
'balance' => Number::formatMoney($invoice->balance, $invoice->client), 'balance' => Number::formatMoney($invoice->balance, $invoice->client),
'status_id' => $invoice->status_id, 'status_id' => $invoice->status_id,
'status' => Invoice::stringStatus($invoice->status_id), 'status' => Invoice::stringStatus($invoice->status_id),
'amount_raw' => $invoice->amount ,
'balance_raw' => $invoice->balance, 'balance_raw' => $invoice->balance,
'number' => $invoice->number ?: '', 'number' => $invoice->number ?: '',
'discount' => $invoice->discount, 'discount' => $invoice->discount,

View File

@ -8707,7 +8707,6 @@ paths:
format: string format: string
example: D2J234DFA example: D2J234DFA
requestBody: requestBody:
description: "File Upload Body"
required: true required: true
content: content:
multipart/form-data: multipart/form-data:
@ -8716,12 +8715,10 @@ paths:
properties: properties:
_method: _method:
type: string type: string
example: PUT example: POST
documents: documents:
type: array type: array
items: items:
description: "Array of binary documents for upload"
type: string
format: binary format: binary
responses: responses:
200: 200:
@ -18062,18 +18059,22 @@ components:
description: 'The hashed if of the contact' description: 'The hashed if of the contact'
type: string type: string
example: Opnel5aKBz example: Opnel5aKBz
readOnly: true
user_id: user_id:
description: 'The hashed id of the user who created the contact' description: 'The hashed id of the user who created the contact'
type: string type: string
example: Opnel5aKBz example: Opnel5aKBz
readOnly: true
company_id: company_id:
description: 'The hashed id of the company' description: 'The hashed id of the company'
type: string type: string
example: Opnel5aKBz example: Opnel5aKBz
readOnly: true
client_id: client_id:
description: 'The hashed id of the client' description: 'The hashed id of the client'
type: string type: string
example: Opnel5aKBz example: Opnel5aKBz
readOnly: true
first_name: first_name:
description: 'The first name of the contact' description: 'The first name of the contact'
type: string type: string
@ -18110,18 +18111,26 @@ components:
description: 'The terms of service which the contact has accpeted' description: 'The terms of service which the contact has accpeted'
type: string type: string
example: 'A long set of ToS' example: 'A long set of ToS'
readOnly: true
password: password:
description: 'The hashed password of the contact' description: 'The hashed password of the contact'
type: string type: string
example: '*****' example: '*****'
confirmation-code: confirmation_code:
description: 'The confirmation code used to authenticate the contacts email address' description: 'The confirmation code used to authenticate the contacts email address'
type: string type: string
example: 333-sdjkh34gbasd example: 333-sdjkh34gbasd
readOnly: true
token: token:
description: 'A uuid based token.' description: 'A uuid based token.'
type: string type: string
example: 333-sdjkh34gbasd example: 333-sdjkh34gbasd
readOnly: true
contact_key:
description: 'A unique identifier for the contact'
type: string
example: JD0X52bkfZlJRiroCJ0tcSiAjsJTntZ5uqKdiZ0a
readOnly: true
is_primary: is_primary:
description: 'Defines is this contact is the primary contact for the client' description: 'Defines is this contact is the primary contact for the client'
type: boolean type: boolean
@ -18143,31 +18152,37 @@ components:
type: number type: number
format: integer format: integer
example: '3' example: '3'
readOnly: true
email_verified_at: email_verified_at:
description: 'The date which the contact confirmed their email' description: 'The date which the contact confirmed their email'
type: number type: number
format: integer format: integer
example: '134341234234' example: '134341234234'
readOnly: true
last_login: last_login:
description: Timestamp description: Timestamp
type: number type: number
format: integer format: integer
example: '134341234234' example: '134341234234'
readOnly: true
created_at: created_at:
description: Timestamp description: Timestamp
type: number type: number
format: integer format: integer
example: '134341234234' example: '134341234234'
readOnly: true
updated_at: updated_at:
description: Timestamp description: Timestamp
type: number type: number
format: integer format: integer
example: '134341234234' example: '134341234234'
readOnly: true
deleted_at: deleted_at:
description: Timestamp description: Timestamp
type: number type: number
format: integer format: integer
example: '134341234234' example: '134341234234'
readOnly: true
type: object type: object
ClientContactRequest: ClientContactRequest:
properties: properties:
@ -18228,14 +18243,17 @@ components:
description: 'The hashed id of the user id' description: 'The hashed id of the user id'
type: string type: string
example: Opnel5aKBz example: Opnel5aKBz
readOnly: true
company_id: company_id:
description: 'The hashed id of the company' description: 'The hashed id of the company'
type: string type: string
example: Opnel5aKBz example: Opnel5aKBz
readOnly: true
vendor_id: vendor_id:
description: 'The hashed id of the vendor' description: 'The hashed id of the vendor'
type: string type: string
example: Opnel5aKBz example: Opnel5aKBz
readOnly: true
first_name: first_name:
description: 'The first name of the contact' description: 'The first name of the contact'
type: string type: string
@ -18244,6 +18262,16 @@ components:
description: 'The last name of the contact' description: 'The last name of the contact'
type: string type: string
example: Windsor example: Windsor
contact_key:
description: 'A unique identifier for the contact'
type: string
example: JD0X52bkfZlJRiroCJ0tcSiAjsJTntZ5uqKdiZ0a
readOnly: true
confirmation_code:
description: 'The confirmation code used to authenticate the contacts email address'
type: string
example: 333-sdjkh34gbasd
readOnly: true
phone: phone:
description: 'The contacts phone number' description: 'The contacts phone number'
type: string type: string
@ -18268,6 +18296,16 @@ components:
description: 'The contact email address' description: 'The contact email address'
type: string type: string
example: harry@windsor.com example: harry@windsor.com
email_verified_at:
description: 'The date which the contact confirmed their email'
type: number
format: integer
example: '134341234234'
readOnly: true
password:
description: 'The hashed password of the contact'
type: string
example: '*****'
is_primary: is_primary:
description: 'Boolean flag determining if the contact is the primary contact for the vendor' description: 'Boolean flag determining if the contact is the primary contact for the vendor'
type: boolean type: boolean
@ -19599,10 +19637,6 @@ components:
description: 'The hashed id of the company. This is a unique identifier for the company.' description: 'The hashed id of the company. This is a unique identifier for the company.'
type: string type: string
example: Opnel5aKBz example: Opnel5aKBz
client_id:
description: 'The hashed id of the client. This is a unique identifier for the client.'
type: string
example: Opnel5aKBz
contacts: contacts:
type: array type: array
items: items:
@ -19732,8 +19766,6 @@ components:
type: string type: string
example: 'Bob the vendor' example: 'Bob the vendor'
readOnly: true readOnly: true
settings:
$ref: '#/components/schemas/CompanySettings'
type: object type: object
ClientSettings: ClientSettings:
required: required:
@ -20838,27 +20870,31 @@ components:
id: id:
description: 'The expense hashed id' description: 'The expense hashed id'
type: string type: string
example: Opnel5aKBz example: 'Opnel5aKBz'
user_id: user_id:
description: 'The user hashed id' description: 'The user hashed id'
type: string type: string
example: '' example: 'Opnel5aKBz'
assigned_user_id: assigned_user_id:
description: 'The assigned user hashed id' description: 'The assigned user hashed id'
type: string type: string
example: '' example: 'Opnel5aKBz'
project_id:
description: 'The associated project_id'
type: string
example: 'Opnel5aKBz'
company_id: company_id:
description: 'The company hashed id' description: 'The company hashed id'
type: string type: string
example: '' example: 'Opnel5aKBz'
client_id: client_id:
description: 'The client hashed id' description: 'The client hashed id'
type: string type: string
example: '' example: 'Opnel5aKBz'
invoice_id: invoice_id:
description: 'The related invoice hashed id' description: 'The related invoice hashed id'
type: string type: string
example: '' example: 'Opnel5aKBz'
bank_id: bank_id:
description: 'The bank id related to this expense' description: 'The bank id related to this expense'
type: string type: string
@ -20866,15 +20902,15 @@ components:
invoice_currency_id: invoice_currency_id:
description: 'The currency id of the related invoice' description: 'The currency id of the related invoice'
type: string type: string
example: '' example: '1'
expense_currency_id: expense_currency_id:
description: 'The currency id of the expense' description: 'The currency id of the expense'
type: string type: string
example: '' example: '2'
invoice_category_id: invoice_category_id:
description: 'The invoice category id' description: 'The invoice category id'
type: string type: string
example: '' example: 'Opnel5aKBz'
payment_type_id: payment_type_id:
description: 'The payment type id' description: 'The payment type id'
type: string type: string
@ -20882,7 +20918,7 @@ components:
recurring_expense_id: recurring_expense_id:
description: 'The related recurring expense this expense was created from' description: 'The related recurring expense this expense was created from'
type: string type: string
example: '' example: 'Opnel5aKBz'
private_notes: private_notes:
description: 'The private notes of the expense' description: 'The private notes of the expense'
type: string type: string
@ -20915,30 +20951,34 @@ components:
description: 'A custom value' description: 'A custom value'
type: string type: string
example: '' example: ''
tax_amount:
description: 'The tax amount'
type: number
example: 10.00
tax_name1: tax_name1:
description: 'Tax name' description: 'Tax Name 1'
type: string type: string
example: '' example: 'GST'
tax_name2: tax_name2:
description: 'Tax name' description: 'Tax Name 2'
type: string type: string
example: '' example: 'VAT'
tax_name3:
description: 'Tax Name 3'
type: string
example: 'IVA'
tax_rate1: tax_rate1:
description: 'Tax rate' description: 'Tax rate 1'
type: number type: number
format: float format: float
example: '10.00' example: '10.00'
tax_rate2: tax_rate2:
description: 'Tax rate' description: 'Tax rate 2'
type: number type: number
format: float format: float
example: '10.00' example: '10.00'
tax_name3:
description: 'Tax name'
type: string
example: ''
tax_rate3: tax_rate3:
description: 'Tax rate' description: 'Tax rate 3'
type: number type: number
format: float format: float
example: '10.00' example: '10.00'
@ -20958,13 +20998,13 @@ components:
format: float format: float
example: '0.80' example: '0.80'
date: date:
description: 'The expense date formate Y-m-d' description: 'The expense date format Y-m-d'
type: string type: string
example: '2022-12-01' example: '2022-12-01'
payment_date: payment_date:
description: 'The date of payment for the expense, format Y-m-d' description: 'The date of payment for the expense, format Y-m-d'
type: string type: string
example: '' example: '2022-12-01'
should_be_invoiced: should_be_invoiced:
description: 'Flag whether the expense should be invoiced' description: 'Flag whether the expense should be invoiced'
type: boolean type: boolean