added import and export recurring transactions
This commit is contained in:
parent
bd15a1cd0e
commit
f2ec9ffe0c
28
app/Exports/Banking/RecurringTransactions.php
Normal file
28
app/Exports/Banking/RecurringTransactions.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Banking;
|
||||||
|
|
||||||
|
use App\Exports\Banking\Sheets\Recurring;
|
||||||
|
use App\Exports\Banking\Sheets\RecurringTransactions as Base;
|
||||||
|
use Maatwebsite\Excel\Concerns\Exportable;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||||
|
|
||||||
|
class RecurringTransactions implements WithMultipleSheets
|
||||||
|
{
|
||||||
|
use Exportable;
|
||||||
|
|
||||||
|
public $ids;
|
||||||
|
|
||||||
|
public function __construct($ids = null)
|
||||||
|
{
|
||||||
|
$this->ids = $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sheets(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new Recurring($this->ids),
|
||||||
|
new Base($this->ids),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
36
app/Exports/Banking/Sheets/Recurring.php
Normal file
36
app/Exports/Banking/Sheets/Recurring.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Banking\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Export;
|
||||||
|
use App\Models\Common\Recurring as Model;
|
||||||
|
|
||||||
|
class Recurring extends Export
|
||||||
|
{
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
return Model::transaction()->cursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($model): array
|
||||||
|
{
|
||||||
|
$model->transaction_number = $model->recurable->number;
|
||||||
|
|
||||||
|
return parent::map($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'recurable_type',
|
||||||
|
'transaction_number',
|
||||||
|
'frequency',
|
||||||
|
'interval',
|
||||||
|
'started_at',
|
||||||
|
'status',
|
||||||
|
'limit_by',
|
||||||
|
'limit_count',
|
||||||
|
'auto_send',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
53
app/Exports/Banking/Sheets/RecurringTransactions.php
Normal file
53
app/Exports/Banking/Sheets/RecurringTransactions.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exports\Banking\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Export;
|
||||||
|
use App\Models\Banking\Transaction as Model;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
|
||||||
|
class RecurringTransactions extends Export implements WithColumnFormatting
|
||||||
|
{
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
return Model::with('account', 'category', 'contact', 'document')->isRecurring()->cursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($model): array
|
||||||
|
{
|
||||||
|
$model->account_name = $model->account->name;
|
||||||
|
$model->contact_email = $model->contact->email;
|
||||||
|
$model->category_name = $model->category->name;
|
||||||
|
$model->invoice_bill_number = $model->document->document_number ?? 0;
|
||||||
|
|
||||||
|
return parent::map($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type',
|
||||||
|
'number',
|
||||||
|
'paid_at',
|
||||||
|
'amount',
|
||||||
|
'currency_code',
|
||||||
|
'currency_rate',
|
||||||
|
'account_name',
|
||||||
|
'invoice_bill_number',
|
||||||
|
'contact_email',
|
||||||
|
'category_name',
|
||||||
|
'description',
|
||||||
|
'payment_method',
|
||||||
|
'reference',
|
||||||
|
'reconciled',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function columnFormats(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'C' => NumberFormat::FORMAT_DATE_YYYYMMDD,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,10 @@
|
|||||||
namespace App\Http\Controllers\Banking;
|
namespace App\Http\Controllers\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Http\Controller;
|
use App\Abstracts\Http\Controller;
|
||||||
|
use App\Exports\Banking\RecurringTransactions as Export;
|
||||||
use App\Http\Requests\Banking\Transaction as Request;
|
use App\Http\Requests\Banking\Transaction as Request;
|
||||||
|
use App\Http\Requests\Common\Import as ImportRequest;
|
||||||
|
use App\Imports\Banking\RecurringTransactions as Import;
|
||||||
use App\Jobs\Banking\CreateTransaction;
|
use App\Jobs\Banking\CreateTransaction;
|
||||||
use App\Jobs\Banking\UpdateTransaction;
|
use App\Jobs\Banking\UpdateTransaction;
|
||||||
use App\Models\Banking\Account;
|
use App\Models\Banking\Account;
|
||||||
@ -97,7 +100,7 @@ class RecurringTransactions extends Controller
|
|||||||
if ($response['success']) {
|
if ($response['success']) {
|
||||||
$response['redirect'] = route('recurring-transactions.show', $response['data']->id);
|
$response['redirect'] = route('recurring-transactions.show', $response['data']->id);
|
||||||
|
|
||||||
$message = trans('messages.success.added', ['type' => trans_choice('general.transactions', 1)]);
|
$message = trans('messages.success.added', ['type' => trans_choice('general.recurring_transactions', 1)]);
|
||||||
|
|
||||||
flash($message)->success();
|
flash($message)->success();
|
||||||
} else {
|
} else {
|
||||||
@ -122,13 +125,37 @@ class RecurringTransactions extends Controller
|
|||||||
{
|
{
|
||||||
$clone = $recurring_transaction->duplicate();
|
$clone = $recurring_transaction->duplicate();
|
||||||
|
|
||||||
$message = trans('messages.success.duplicated', ['type' => trans_choice('general.transactions', 1)]);
|
$message = trans('messages.success.duplicated', ['type' => trans_choice('general.recurring_transactions', 1)]);
|
||||||
|
|
||||||
flash($message)->success();
|
flash($message)->success();
|
||||||
|
|
||||||
return redirect()->route('recurring-transactions.edit', $clone->id);
|
return redirect()->route('recurring-transactions.edit', $clone->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import the specified resource.
|
||||||
|
*
|
||||||
|
* @param ImportRequest $request
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function import(ImportRequest $request)
|
||||||
|
{
|
||||||
|
$response = $this->importExcel(new Import, $request, trans_choice('general.recurring_transactions', 2));
|
||||||
|
|
||||||
|
if ($response['success']) {
|
||||||
|
$response['redirect'] = route('recurring-transactions.index');
|
||||||
|
|
||||||
|
flash($response['message'])->success();
|
||||||
|
} else {
|
||||||
|
$response['redirect'] = route('import.create', ['banking', 'recurring-transactions']);
|
||||||
|
|
||||||
|
flash($response['message'])->error()->important();
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
@ -174,7 +201,7 @@ class RecurringTransactions extends Controller
|
|||||||
if ($response['success']) {
|
if ($response['success']) {
|
||||||
$response['redirect'] = route('recurring-transactions.show', $recurring_transaction->id);
|
$response['redirect'] = route('recurring-transactions.show', $recurring_transaction->id);
|
||||||
|
|
||||||
$message = trans('messages.success.updated', ['type' => trans_choice('general.transactions', 1)]);
|
$message = trans('messages.success.updated', ['type' => trans_choice('general.recurring_transactions', 1)]);
|
||||||
|
|
||||||
flash($message)->success();
|
flash($message)->success();
|
||||||
} else {
|
} else {
|
||||||
@ -188,6 +215,16 @@ class RecurringTransactions extends Controller
|
|||||||
return response()->json($response);
|
return response()->json($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export the specified resource.
|
||||||
|
*
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function export()
|
||||||
|
{
|
||||||
|
return $this->exportExcel(new Export, trans_choice('general.recurring_transactions', 2));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End recurring template.
|
* End recurring template.
|
||||||
*
|
*
|
||||||
|
18
app/Imports/Banking/RecurringTransactions.php
Normal file
18
app/Imports/Banking/RecurringTransactions.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports\Banking;
|
||||||
|
|
||||||
|
use App\Abstracts\ImportMultipleSheets;
|
||||||
|
use App\Imports\Banking\Sheets\Recurring;
|
||||||
|
use App\Imports\Banking\Sheets\RecurringTransactions as Base;
|
||||||
|
|
||||||
|
class RecurringTransactions extends ImportMultipleSheets
|
||||||
|
{
|
||||||
|
public function sheets(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'recurring_transactions' => new Base(),
|
||||||
|
'recurring' => new Recurring(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
24
app/Imports/Banking/Sheets/Recurring.php
Normal file
24
app/Imports/Banking/Sheets/Recurring.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports\Banking\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Import;
|
||||||
|
use App\Models\Banking\Transaction;
|
||||||
|
use App\Models\Common\Recurring as Model;
|
||||||
|
|
||||||
|
class Recurring extends Import
|
||||||
|
{
|
||||||
|
public function model(array $row)
|
||||||
|
{
|
||||||
|
return new Model($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($row): array
|
||||||
|
{
|
||||||
|
$row = parent::map($row);
|
||||||
|
|
||||||
|
$row['recurable_id'] = (int) Transaction::isRecurring()->number($row['transaction_number'])->pluck('id')->first();
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
}
|
38
app/Imports/Banking/Sheets/RecurringTransactions.php
Normal file
38
app/Imports/Banking/Sheets/RecurringTransactions.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports\Banking\Sheets;
|
||||||
|
|
||||||
|
use App\Abstracts\Import;
|
||||||
|
use App\Models\Document\Document;
|
||||||
|
use App\Models\Banking\Transaction as Model;
|
||||||
|
use App\Http\Requests\Banking\Transaction as Request;
|
||||||
|
|
||||||
|
class RecurringTransactions extends Import
|
||||||
|
{
|
||||||
|
public $request_class = Request::class;
|
||||||
|
|
||||||
|
public function model(array $row)
|
||||||
|
{
|
||||||
|
return new Model($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($row): array
|
||||||
|
{
|
||||||
|
$row = parent::map($row);
|
||||||
|
|
||||||
|
$transaction_type = str_replace('-recurring', '', $row['type']);
|
||||||
|
|
||||||
|
$row['currency_code'] = $this->getCurrencyCode($row);
|
||||||
|
$row['account_id'] = $this->getAccountId($row);
|
||||||
|
$row['category_id'] = $this->getCategoryId($row, $transaction_type);
|
||||||
|
$row['contact_id'] = $this->getContactId($row, $transaction_type);
|
||||||
|
|
||||||
|
if ($transaction_type == 'income') {
|
||||||
|
$row['document_id'] = Document::invoiceRecurring()->number($row['invoice_bill_number'])->pluck('id')->first();
|
||||||
|
} else {
|
||||||
|
$row['document_id'] = Document::billRecurring()->number($row['invoice_bill_number'])->pluck('id')->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,24 @@
|
|||||||
@endcan
|
@endcan
|
||||||
</x-slot>
|
</x-slot>
|
||||||
|
|
||||||
|
<x-slot name="moreButtons">
|
||||||
|
<x-dropdown id="dropdown-more-actions">
|
||||||
|
<x-slot name="trigger">
|
||||||
|
<span class="material-icons pointer-events-none">more_horiz</span>
|
||||||
|
</x-slot>
|
||||||
|
|
||||||
|
@can('create-banking-transactions')
|
||||||
|
<x-dropdown.link href="{{ route('import.create', ['banking', 'recurring-transactions']) }}">
|
||||||
|
{{ trans('import.import') }}
|
||||||
|
</x-dropdown.link>
|
||||||
|
@endcan
|
||||||
|
|
||||||
|
<x-dropdown.link href="{{ route('recurring-transactions.export', request()->input()) }}">
|
||||||
|
{{ trans('general.export') }}
|
||||||
|
</x-dropdown.link>
|
||||||
|
</x-dropdown>
|
||||||
|
</x-slot>
|
||||||
|
|
||||||
<x-slot name="content">
|
<x-slot name="content">
|
||||||
@if ($transactions->count() || request()->get('search', false))
|
@if ($transactions->count() || request()->get('search', false))
|
||||||
<x-index.container>
|
<x-index.container>
|
||||||
@ -141,23 +159,29 @@
|
|||||||
<x-empty-page
|
<x-empty-page
|
||||||
group="banking"
|
group="banking"
|
||||||
page="recurring_templates"
|
page="recurring_templates"
|
||||||
hide-button-import
|
|
||||||
permission-create="create-banking-transactions"
|
permission-create="create-banking-transactions"
|
||||||
:buttons="[
|
:buttons="[
|
||||||
[
|
[
|
||||||
'url' => route('recurring-transactions.create', ['type' => 'income-recurring']),
|
'url' => route('recurring-transactions.create', ['type' => 'income-recurring']),
|
||||||
'permission' => 'create-banking-transactions',
|
'permission' => 'create-banking-transactions',
|
||||||
'text' => trans('general.title.new', ['type' => trans_choice('general.recurring_incomes', 1)]),
|
'text' => trans('general.title.new', ['type' => trans_choice('general.recurring_incomes', 1)]),
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'active_badge' => true,
|
'active_badge' => true,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'url' => route('recurring-transactions.create', ['type' => 'expense-recurring']),
|
'url' => route('recurring-transactions.create', ['type' => 'expense-recurring']),
|
||||||
'permission' => 'create-banking-transactions',
|
'permission' => 'create-banking-transactions',
|
||||||
'text' => trans('general.title.new', ['type' => trans_choice('general.recurring_expenses', 1)]),
|
'text' => trans('general.title.new', ['type' => trans_choice('general.recurring_expenses', 1)]),
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'active_badge' => true,
|
'active_badge' => true,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'url' => route('import.create', ['banking', 'recurring-transactions']),
|
||||||
|
'permission' => 'create-banking-transactions',
|
||||||
|
'text' => trans('import.title', ['type' => trans_choice('general.recurring_transactions', 2)]),
|
||||||
|
'description' => trans('general.empty.actions.import', ['type' => strtolower(trans_choice('general.recurring_transactions', 2))]),
|
||||||
|
'active_badge' => false,
|
||||||
|
],
|
||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
@endif
|
@endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user