Updated openapi spec

This commit is contained in:
David Bomba 2025-05-24 11:19:42 +10:00
parent 6ef54471c2
commit dc02eacfaa
16 changed files with 176 additions and 316 deletions

View File

@ -0,0 +1,156 @@
<?php
namespace App\Services\Report;
use Carbon\Carbon;
use App\Utils\Ninja;
use App\Utils\Number;
use League\Csv\Writer;
use App\Models\Company;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Activity;
use App\Utils\Translator;
use App\Libraries\MultiDB;
use Illuminate\Support\Str;
use App\Export\CSV\BaseExport;
use App\Utils\Traits\MakesDates;
use League\Csv\CharsetConverter;
use Illuminate\Support\Facades\App;
use Illuminate\Database\Query\Builder;
class RefundReport extends BaseExport
{
use MakesDates;
public Writer $csv;
private string $template = '/views/templates/reports/refund_report.html';
public array $report_keys = [
'refund_date',
'refund_amount',
'payment_number',
'invoice_number',
'invoice_amount',
'gateway_refund',
];
/**
* @param array $input
* [
* 'date_range',
* 'start_date',
* 'end_date',
* 'clients',
* 'client_id',
* ]
*/
public function __construct(public Company $company, public array $input)
{
}
public function run()
{
MultiDB::setDb($this->company->db);
App::forgetInstance('translator');
App::setLocale($this->company->locale());
$t = app('translator');
$t->replace(Ninja::transformTranslations($this->company->settings));
$this->csv = Writer::createFromString();
\League\Csv\CharsetConverter::addTo($this->csv, 'UTF-8', 'UTF-8');
$this->csv->insertOne([]);
$this->csv->insertOne([]);
$this->csv->insertOne([]);
$this->csv->insertOne([]);
$this->csv->insertOne([ctrans('texts.refund_report')]);
$this->csv->insertOne([ctrans('texts.created_on'), ' ', $this->translateDate(now()->format('Y-m-d'), $this->company->date_format(), $this->company->locale())]);
if (count($this->input['report_keys']) == 0) {
$this->input['report_keys'] = $this->report_keys;
}
$this->csv->insertOne($this->buildHeader());
// Get all refund activities
$query = Activity::query()
->where('company_id', $this->company->id)
->where('activity_type_id', 40) // Refund activity type
->with(['payment', 'payment.client']);
$query = $this->addDateRange($query, 'activities');
$refundActivities = $query->cursor();
foreach ($refundActivities as $activity) {
/** @var Activity $activity */
// Extract refund amount from notes using regex
preg_match('/Refunded : (\d+) -/', $activity->notes, $matches);
$refundAmount = $matches[1] ?? 0;
// Get payment details
$payment = $activity->payment;
// Get gateway refund status from refund_meta
$gatewayRefund = false;
if ($payment && $payment->refund_meta) {
foreach ($payment->refund_meta as $refund) {
if (isset($refund['gateway_refund']) && $refund['gateway_refund']) {
$gatewayRefund = true;
break;
}
}
}
// Get invoice details from refund_meta
$invoices = [];
if ($payment && $payment->refund_meta) {
foreach ($payment->refund_meta as $refund) {
if (isset($refund['invoices'])) {
foreach ($refund['invoices'] as $invoiceRefund) {
$invoice = Invoice::query()
->where('company_id', $this->company->id)
->where('id', $invoiceRefund['invoice_id'])
->first();
if ($invoice) {
$invoices[] = [
'number' => $invoice->number,
'amount' => $invoiceRefund['amount']
];
}
}
}
}
}
// Create a row for each refunded invoice
foreach ($invoices as $invoice) {
$this->csv->insertOne([
$this->translateDate(\Carbon\Carbon::parse($activity->created_at)->format('Y-m-d'), $this->company->date_format(), $this->company->locale()),
Number::formatMoney($refundAmount, $this->company),
$payment ? $payment->number : '',
$invoice['number'],
Number::formatMoney($invoice['amount'], $this->company),
$gatewayRefund ? 'Yes' : 'No',
]);
}
}
return $this->csv->toString();
}
public function buildHeader(): array
{
$header = [];
foreach ($this->input['report_keys'] as $value) {
$header[] = ctrans("texts.{$value}");
}
return $header;
}
}

View File

@ -116,7 +116,6 @@ paths:
items:
$ref: '#/components/schemas/Activity'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -381,7 +380,6 @@ paths:
items:
$ref: '#/components/schemas/BankIntegration'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -837,7 +835,6 @@ paths:
items:
$ref: '#/components/schemas/BankTransaction'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -1244,7 +1241,6 @@ paths:
items:
$ref: '#/components/schemas/BankTransactionRule'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -1620,7 +1616,6 @@ paths:
items:
$ref: '#/components/schemas/ClientGatewayToken'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -1913,7 +1908,6 @@ paths:
items:
$ref: '#/components/schemas/Company'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -2349,7 +2343,6 @@ paths:
items:
$ref: '#/components/schemas/CompanyGateway'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -2671,7 +2664,6 @@ paths:
items:
$ref: '#/components/schemas/CompanyLedger'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -2783,7 +2775,6 @@ paths:
items:
$ref: '#/components/schemas/Design'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -3099,7 +3090,6 @@ paths:
items:
$ref: '#/components/schemas/Document'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -3216,7 +3206,6 @@ paths:
items:
$ref: '#/components/schemas/ExpenseCategory'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -3520,7 +3509,6 @@ paths:
items:
$ref: '#/components/schemas/Expense'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -3913,7 +3901,6 @@ paths:
items:
$ref: '#/components/schemas/GroupSetting'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -4609,7 +4596,6 @@ paths:
items:
$ref: '#/components/schemas/PaymentTerm'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -5051,7 +5037,6 @@ paths:
items:
$ref: '#/components/schemas/RecurringExpense'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -5418,7 +5403,6 @@ paths:
items:
$ref: '#/components/schemas/RecurringQuote'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -6322,7 +6306,6 @@ paths:
items:
$ref: '#/components/schemas/Subscription'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -6671,7 +6654,6 @@ paths:
items:
$ref: '#/components/schemas/SystemLog'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -6984,7 +6966,6 @@ paths:
items:
$ref: '#/components/schemas/TaskStatus'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -7297,7 +7278,6 @@ paths:
items:
$ref: '#/components/schemas/TaxRate'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -7614,7 +7594,6 @@ paths:
items:
$ref: '#/components/schemas/CompanyToken'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -7922,7 +7901,6 @@ paths:
items:
$ref: '#/components/schemas/User'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -8378,7 +8356,6 @@ paths:
items:
$ref: '#/components/schemas/Webhook'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -8987,18 +8964,6 @@ paths:
$ref: "#/components/headers/X-RateLimit-Remaining"
X-RateLimit-Limit:
$ref: "#/components/headers/X-RateLimit-Limit"
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Credit"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:
@ -9206,9 +9171,6 @@ paths:
type: array
items:
$ref: '#/components/schemas/Location'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: '#/components/responses/401'
403:
@ -9615,15 +9577,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/Location'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: '#/components/responses/401'
403:
@ -10163,15 +10117,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/RecurringInvoice"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:
@ -10669,15 +10615,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Task"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:
@ -11449,15 +11387,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Quote"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:
@ -12399,18 +12329,6 @@ paths:
$ref: "#/components/headers/X-RateLimit-Remaining"
X-RateLimit-Limit:
$ref: "#/components/headers/X-RateLimit-Limit"
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Invoice"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:
@ -13009,15 +12927,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Project"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:
@ -13420,15 +13330,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Vendor"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:
@ -13944,15 +13846,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Payment"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:
@ -14304,15 +14198,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/Client'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: '#/components/responses/401'
403:
@ -14832,15 +14718,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/Client'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: '#/components/responses/401'
403:
@ -15592,18 +15470,6 @@ paths:
$ref: "#/components/headers/X-RateLimit-Remaining"
X-RateLimit-Limit:
$ref: "#/components/headers/X-RateLimit-Limit"
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/PurchaseOrder"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:
@ -16291,15 +16157,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Product"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: '#/components/responses/401'
403:
@ -18100,12 +17958,6 @@ components:
example: 1.00
description: 'The total amount of tax applied to the product offered for this line item'
readOnly: true
date:
type: string
format: date-time
example: '2023-03-19T00:00:00Z'
description: 'Deprecated'
deprecated: true
custom_value1:
type: string
example: 'Custom value 1'

View File

@ -82,12 +82,6 @@
example: 1.00
description: 'The total amount of tax applied to the product offered for this line item'
readOnly: true
date:
type: string
format: date-time
example: '2023-03-19T00:00:00Z'
description: 'Deprecated'
deprecated: true
custom_value1:
type: string
example: 'Custom value 1'

View File

@ -33,7 +33,6 @@ paths:
items:
$ref: '#/components/schemas/Activity'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -298,7 +297,6 @@ paths:
items:
$ref: '#/components/schemas/BankIntegration'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -754,7 +752,6 @@ paths:
items:
$ref: '#/components/schemas/BankTransaction'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -1161,7 +1158,6 @@ paths:
items:
$ref: '#/components/schemas/BankTransactionRule'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -1537,7 +1533,6 @@ paths:
items:
$ref: '#/components/schemas/ClientGatewayToken'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -1830,7 +1825,6 @@ paths:
items:
$ref: '#/components/schemas/Company'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -2266,7 +2260,6 @@ paths:
items:
$ref: '#/components/schemas/CompanyGateway'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -2588,7 +2581,6 @@ paths:
items:
$ref: '#/components/schemas/CompanyLedger'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -2700,7 +2692,6 @@ paths:
items:
$ref: '#/components/schemas/Design'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -3016,7 +3007,6 @@ paths:
items:
$ref: '#/components/schemas/Document'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -3133,7 +3123,6 @@ paths:
items:
$ref: '#/components/schemas/ExpenseCategory'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -3437,7 +3426,6 @@ paths:
items:
$ref: '#/components/schemas/Expense'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -3830,7 +3818,6 @@ paths:
items:
$ref: '#/components/schemas/GroupSetting'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -4526,7 +4513,6 @@ paths:
items:
$ref: '#/components/schemas/PaymentTerm'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -4968,7 +4954,6 @@ paths:
items:
$ref: '#/components/schemas/RecurringExpense'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -5335,7 +5320,6 @@ paths:
items:
$ref: '#/components/schemas/RecurringQuote'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -6239,7 +6223,6 @@ paths:
items:
$ref: '#/components/schemas/Subscription'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -6588,7 +6571,6 @@ paths:
items:
$ref: '#/components/schemas/SystemLog'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -6901,7 +6883,6 @@ paths:
items:
$ref: '#/components/schemas/TaskStatus'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -7214,7 +7195,6 @@ paths:
items:
$ref: '#/components/schemas/TaxRate'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -7531,7 +7511,6 @@ paths:
items:
$ref: '#/components/schemas/CompanyToken'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -7839,7 +7818,6 @@ paths:
items:
$ref: '#/components/schemas/User'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
@ -8295,7 +8273,6 @@ paths:
items:
$ref: '#/components/schemas/Webhook'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"

View File

@ -220,15 +220,7 @@
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/Client'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: '#/components/responses/401'
403:
@ -748,15 +740,7 @@
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/Client'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: '#/components/responses/401'
403:

View File

@ -329,18 +329,6 @@
$ref: "#/components/headers/X-RateLimit-Remaining"
X-RateLimit-Limit:
$ref: "#/components/headers/X-RateLimit-Limit"
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Credit"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:

View File

@ -770,18 +770,6 @@
$ref: "#/components/headers/X-RateLimit-Remaining"
X-RateLimit-Limit:
$ref: "#/components/headers/X-RateLimit-Limit"
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Invoice"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:

View File

@ -88,9 +88,6 @@
type: array
items:
$ref: '#/components/schemas/Location'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: '#/components/responses/401'
403:
@ -497,15 +494,7 @@
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/Location'
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: '#/components/responses/401'
403:

View File

@ -439,15 +439,7 @@
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Payment"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:

View File

@ -516,15 +516,7 @@
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Product"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: '#/components/responses/401'
403:

View File

@ -326,15 +326,7 @@
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Project"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:

View File

@ -325,18 +325,6 @@
$ref: "#/components/headers/X-RateLimit-Remaining"
X-RateLimit-Limit:
$ref: "#/components/headers/X-RateLimit-Limit"
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/PurchaseOrder"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:

View File

@ -662,15 +662,7 @@
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Quote"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:

View File

@ -526,15 +526,7 @@
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/RecurringInvoice"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:

View File

@ -326,15 +326,7 @@
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Task"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403:

View File

@ -326,15 +326,7 @@
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Vendor"
meta:
type: object
$ref: '#/components/schemas/Meta'
401:
$ref: "#/components/responses/401"
403: