Skip to content

Commit

Permalink
Merge pull request invoiceninja#9291 from turbo124/v5-develop
Browse files Browse the repository at this point in the history
Fixes for openapi spec
  • Loading branch information
turbo124 authored Feb 13, 2024
2 parents 8cd530c + ae8fbc8 commit a720585
Show file tree
Hide file tree
Showing 42 changed files with 5,907 additions and 5,834 deletions.
1 change: 1 addition & 0 deletions app/Console/Commands/OpenApiYaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function handle()
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components.yaml'));

Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/examples.yaml'));

Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/responses.yaml'));

$directory = new DirectoryIterator($path . '/components/responses/');
Expand Down
16 changes: 0 additions & 16 deletions app/Export/CSV/ClientExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,6 @@ private function decorateAdvancedFields(Client $client, array $entity): array
$entity['client.assigned_user'] = $client->assigned_user ? $client->user->present()->name() : '';
}

// if (in_array('client.country_id', $this->input['report_keys'])) {
// $entity['client.country_id'] = $client->country ? ctrans("texts.country_{$client->country->name}") : '';
// }

// if (in_array('client.shipping_country_id', $this->input['report_keys'])) {
// $entity['client.shipping_country_id'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : '';
// }

// if (in_array('client.currency_id', $this->input['report_keys'])) {
// $entity['client.currency_id'] = $client->currency() ? $client->currency()->code : $client->company->currency()->code;
// }

// if (in_array('client.industry_id', $this->input['report_keys'])) {
// $entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : '';
// }

if (in_array('client.classification', $this->input['report_keys']) && isset($client->classification)) {
$entity['client.classification'] = ctrans("texts.{$client->classification}") ?? '';
}
Expand Down
5 changes: 5 additions & 0 deletions app/Filters/ClientFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public function sort(string $sort = ''): Builder

$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';

if($sort_col[0] == 'number')
{
return $this->builder->orderByRaw('ABS(number) ' . $dir);
}

return $this->builder->orderBy($sort_col[0], $dir);
}

Expand Down
5 changes: 5 additions & 0 deletions app/Filters/CreditFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ public function sort(string $sort = ''): Builder
->whereColumn('clients.id', 'credits.client_id'), $dir);
}


if($sort_col[0] == 'number') {
return $this->builder->orderByRaw('ABS(number) ' . $dir);
}

return $this->builder->orderBy($sort_col[0], $dir);
}

Expand Down
6 changes: 6 additions & 0 deletions app/Filters/ExpenseFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public function sort(string $sort = ''): Builder
return $this->builder;
}

$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';

if ($sort_col[0] == 'client_id' && in_array($sort_col[1], ['asc', 'desc'])) {
return $this->builder
->orderByRaw('ISNULL(client_id), client_id '. $sort_col[1])
Expand All @@ -194,6 +196,10 @@ public function sort(string $sort = ''): Builder
->whereColumn('expense_categories.id', 'expenses.category_id'), $sort_col[1]);
}

if($sort_col[0] == 'number') {
return $this->builder->orderByRaw('ABS(number) ' . $dir);
}

if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['public_notes', 'date', 'id_number', 'custom_value1', 'custom_value2', 'custom_value3', 'custom_value4'])) {
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}
Expand Down
7 changes: 6 additions & 1 deletion app/Filters/InvoiceFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,16 @@ public function sort(string $sort = ''): Builder

if ($sort_col[0] == 'client_id') {

return $this->builder->orderBy(\App\Models\Client::select('name')
return $this->builder->orderBy(\App\Models\Client::select ('name')
->whereColumn('clients.id', 'invoices.client_id'), $dir);

}

if($sort_col[0] == 'number')
{
return $this->builder->orderByRaw('ABS(number) ' . $dir);
}

return $this->builder->orderBy($sort_col[0], $dir);
}

Expand Down
8 changes: 6 additions & 2 deletions app/Filters/PaymentFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,18 @@ public function sort(string $sort = ''): Builder
return $this->builder;
}

$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';

if ($sort_col[0] == 'client_id') {
return $this->builder->orderBy(\App\Models\Client::select('name')
->whereColumn('clients.id', 'payments.client_id'), $sort_col[1]);
->whereColumn('clients.id', 'payments.client_id'), $dir);
}

if($sort_col[0] == 'number') {
return $this->builder->orderByRaw('ABS(number) ' . $dir);
}

return $this->builder->orderBy($sort_col[0], $sort_col[1]);
return $this->builder->orderBy($sort_col[0], $dir);
}

public function date_range(string $date_range = ''): Builder
Expand Down
17 changes: 10 additions & 7 deletions app/Filters/ProjectFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,24 @@ public function number(string $number = ''): Builder
public function sort(string $sort = ''): Builder
{
$sort_col = explode('|', $sort);

if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
}

$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';

if ($sort_col[0] == 'client_id') {
return $this->builder->orderBy(\App\Models\Client::select('name')
->whereColumn('clients.id', 'projects.client_id'), $sort_col[1]);
->whereColumn('clients.id', 'projects.client_id'), $dir);
}

if (!is_array($sort_col) || count($sort_col) != 2) {
return $this->builder;
if($sort_col[0] == 'number') {
return $this->builder->orderByRaw('ABS(number) ' . $dir);
}

if (is_array($sort_col) && in_array($sort_col[1], ['asc','desc'])) {
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}
return $this->builder->orderBy($sort_col[0], $dir);

return $this->builder;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions app/Filters/PurchaseOrderFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public function sort(string $sort = ''): Builder
->whereColumn('vendors.id', 'purchase_orders.vendor_id'), $dir);
}

if($sort_col[0] == 'number') {
return $this->builder->orderByRaw('ABS(number) ' . $dir);
}

return $this->builder->orderBy($sort_col[0], $dir);
}

Expand Down
4 changes: 4 additions & 0 deletions app/Filters/QuoteFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ public function sort(string $sort = ''): Builder

}

if($sort_col[0] == 'number') {
return $this->builder->orderByRaw('ABS(number) ' . $dir);
}

if ($sort_col[0] == 'valid_until') {
$sort_col[0] = 'due_date';
}
Expand Down
6 changes: 6 additions & 0 deletions app/Filters/RecurringExpenseFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public function sort(string $sort = ''): Builder
return $this->builder;
}

$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';

if ($sort_col[0] == 'client_id' && in_array($sort_col[1], ['asc', 'desc'])) {
return $this->builder
->orderByRaw('ISNULL(client_id), client_id '. $sort_col[1])
Expand All @@ -162,6 +164,10 @@ public function sort(string $sort = ''): Builder
->whereColumn('expense_categories.id', 'expenses.category_id'), $sort_col[1]);
}

if($sort_col[0] == 'number') {
return $this->builder->orderByRaw('ABS(number) ' . $dir);
}

if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['public_notes', 'date', 'id_number', 'custom_value1', 'custom_value2', 'custom_value3', 'custom_value4'])) {
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}
Expand Down
4 changes: 4 additions & 0 deletions app/Filters/TaskFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public function sort(string $sort = ''): Builder
->whereColumn('users.id', 'tasks.user_id'), $dir);
}

if($sort_col[0] == 'number') {
return $this->builder->orderByRaw('ABS(number) ' . $dir);
}

return $this->builder->orderBy($sort_col[0], $dir);
}

Expand Down
4 changes: 4 additions & 0 deletions app/Filters/VendorFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function sort(string $sort = ''): Builder

$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';

if($sort_col[0] == 'number') {
return $this->builder->orderByRaw('ABS(number) ' . $dir);
}

return $this->builder->orderBy($sort_col[0], $dir);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/Client/StoreClientRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function rules()

$rules['number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)];
$rules['id_number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)];
$rules['classification'] = 'bail|sometimes|nullable|in:individual,business,partnership,trust,charity,government,other';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other';

return $rules;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/Client/UpdateClientRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function rules()
$rules['size_id'] = 'integer|nullable';
$rules['country_id'] = 'integer|nullable';
$rules['shipping_country_id'] = 'integer|nullable';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,business,partnership,trust,charity,government,other';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other';

if ($this->id_number) {
$rules['id_number'] = Rule::unique('clients')->where('company_id', $user->company()->id)->ignore($this->client->id);
Expand Down
12 changes: 10 additions & 2 deletions app/Http/Requests/ExpenseCategory/StoreExpenseCategoryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace App\Http\Requests\ExpenseCategory;

use App\Models\Expense;
use App\Http\Requests\Request;
use App\Models\ExpenseCategory;

Expand All @@ -23,14 +24,21 @@ class StoreExpenseCategoryRequest extends Request
*/
public function authorize(): bool
{
return auth()->user()->can('create', ExpenseCategory::class);
/** @var \App\Models\User $user */
$user = auth()->user();

return $user->can('create', ExpenseCategory::class) || $user->can('create', Expense::class);
}

public function rules()
{

/** @var \App\Models\User $user */
$user = auth()->user();

$rules = [];

$rules['name'] = 'required|unique:expense_categories,name,null,null,company_id,'.auth()->user()->companyId();
$rules['name'] = 'required|unique:expense_categories,name,null,null,company_id,'.$user->companyId();

return $this->globalRules($rules);
}
Expand Down
12 changes: 10 additions & 2 deletions app/Http/Requests/ExpenseCategory/UpdateExpenseCategoryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,24 @@ class UpdateExpenseCategoryRequest extends Request
*/
public function authorize(): bool
{
return auth()->user()->can('edit', $this->expense_category);

/** @var \App\Models\User $user */
$user = auth()->user();

return $user->can('edit', $this->expense_category);
}

public function rules()
{

/** @var \App\Models\User $user */
$user = auth()->user();

$rules = [];

if ($this->input('name')) {
// $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);
$rules['name'] = Rule::unique('expense_categories')->where('company_id', $user->company()->id)->ignore($this->expense_category->id);
}

return $rules;
Expand Down
12 changes: 12 additions & 0 deletions app/Http/Requests/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ public function decodePrimaryKeys($input)
}
}

if(isset($input['public_notes']))
$input['public_notes'] = str_replace("</sc","<-", $input['public_notes']);

if(isset($input['footer']))
$input['footer'] = str_replace("</sc", "<-", $input['footer']);

if(isset($input['terms']))
$input['terms'] = str_replace("</sc", "<-", $input['terms']);

if(isset($input['private_notes']))
$input['private_notes'] = str_replace("</sc", "<-", $input['private_notes']);

return $input;
}

Expand Down
6 changes: 5 additions & 1 deletion app/Http/Requests/Vendor/StoreVendorRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function rules()
}

$rules['language_id'] = 'bail|nullable|sometimes|exists:languages,id';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,company,partnership,trust,charity,government,other';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other';

return $rules;
}
Expand All @@ -89,6 +89,10 @@ public function prepareForValidation()
$input['currency_id'] = $user->company()->settings->currency_id;
}

if (isset($input['name'])) {
$input['name'] = strip_tags($input['name']);
}

$input = $this->decodePrimaryKeys($input);

$this->replace($input);
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Requests/Vendor/UpdateVendorRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function rules()
}

$rules['language_id'] = 'bail|nullable|sometimes|exists:languages,id';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,company,partnership,trust,charity,government,other';
$rules['classification'] = 'bail|sometimes|nullable|in:individual,business,company,partnership,trust,charity,government,other';

return $rules;
}
Expand All @@ -92,8 +92,8 @@ public function prepareForValidation()
{
$input = $this->all();

if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) {
$input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']);
if (isset($input['name'])) {
$input['name'] = strip_tags($input['name']);
}

if (array_key_exists('country_id', $input) && is_null($input['country_id'])) {
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Pdf/PdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ public function getClientDetails(): self
public function productTable(): array
{
$product_items = collect($this->service->config->entity->line_items)->filter(function ($item) {
return $item->type_id == 1 || $item->type_id == 6 || $item->type_id == 5;
return $item->type_id == 1 || $item->type_id == 6 || $item->type_id == 5 || $item->type_id == 4;
});

if (count($product_items) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion app/Services/PdfMaker/Design.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public function deliveryNoteTable(): array
public function productTable(): array
{
$product_items = collect($this->entity->line_items)->filter(function ($item) {
return $item->type_id == 1 || $item->type_id == 6 || $item->type_id == 5;
return $item->type_id == 1 || $item->type_id == 6 || $item->type_id == 5 || $item->type_id == 4;
});

if (count($product_items) == 0) {
Expand Down
1 change: 0 additions & 1 deletion app/Services/Subscription/PaymentLinkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ public function handleNoPaymentRequired(array $data): \Illuminate\Routing\Redire
/**
* @param Invoice $invoice
* @return true
* @throws BindingResolutionException
*/
public function planPaid(Invoice $invoice)
{
Expand Down
6 changes: 6 additions & 0 deletions app/Utils/Traits/CleanLineItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ private function cleanLineItem($item)

}

if(isset($item['notes']))
$item['notes'] = str_replace("</", "<-", $item['notes']);

if(isset($item['product_key']))
$item['product_key'] = str_replace("</", "<-", $item['product_key']);

}

if (array_key_exists('id', $item) || array_key_exists('_id', $item)) {
Expand Down
2 changes: 1 addition & 1 deletion lang/en/texts.php
Original file line number Diff line number Diff line change
Expand Up @@ -5120,7 +5120,7 @@
'set_private' => 'Set private',
'individual' => 'Individual',
'business' => 'Business',
'partnership' => 'partnership',
'partnership' => 'Partnership',
'trust' => 'Trust',
'charity' => 'Charity',
'government' => 'Government',
Expand Down
Loading

0 comments on commit a720585

Please sign in to comment.