akaunting 3.0 (the last dance)
This commit is contained in:
@ -2,25 +2,48 @@
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Events\Banking\TransactionPrinting;
|
||||
use App\Models\Banking\Transaction;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait Transactions
|
||||
{
|
||||
public function isIncome()
|
||||
public function isIncome(): bool
|
||||
{
|
||||
$type = $this->type ?? $this->transaction->type ?? $this->model->type ?? 'income';
|
||||
|
||||
return in_array($type, $this->getIncomeTypes());
|
||||
}
|
||||
|
||||
public function isExpense()
|
||||
public function isNotIncome(): bool
|
||||
{
|
||||
return ! $this->isIncome();
|
||||
}
|
||||
|
||||
public function isExpense(): bool
|
||||
{
|
||||
$type = $this->type ?? $this->transaction->type ?? $this->model->type ?? 'expense';
|
||||
|
||||
return in_array($type, $this->getExpenseTypes());
|
||||
}
|
||||
|
||||
public function isNotExpense()
|
||||
{
|
||||
return ! $this->isExpense();
|
||||
}
|
||||
|
||||
public function isRecurringTransaction(): bool
|
||||
{
|
||||
$type = $this->type ?? $this->transaction->type ?? $this->model->type ?? 'income';
|
||||
|
||||
return Str::endsWith($type, '-recurring');
|
||||
}
|
||||
|
||||
public function isNotRecurringTransaction(): bool
|
||||
{
|
||||
return ! $this->isRecurring();
|
||||
}
|
||||
|
||||
public function getIncomeTypes($return = 'array')
|
||||
{
|
||||
return $this->getTransactionTypes('income', $return);
|
||||
@ -76,13 +99,13 @@ trait Transactions
|
||||
protected function getSettingKey($type, $setting_key)
|
||||
{
|
||||
$key = '';
|
||||
$alias = config('type.' . $type . '.alias');
|
||||
$alias = config('type.transaction.' . $type . '.alias');
|
||||
|
||||
if (!empty($alias)) {
|
||||
$key .= $alias . '.';
|
||||
}
|
||||
|
||||
$prefix = config('type.' . $type . '.setting.prefix');
|
||||
$prefix = config('type.transaction.' . $type . '.setting.prefix');
|
||||
|
||||
$key .= $prefix . '.' . $setting_key;
|
||||
|
||||
@ -91,9 +114,9 @@ trait Transactions
|
||||
|
||||
public function storeTransactionPdfAndGetPath($transaction)
|
||||
{
|
||||
event(new \App\Events\Banking\TransactionPrinting($transaction));
|
||||
event(new TransactionPrinting($transaction));
|
||||
|
||||
$view = view($transaction->template_path, ['revenue' => $transaction, 'transaction' => $transaction])->render();
|
||||
$view = view('banking.transactions.print_default', ['transaction' => $transaction])->render();
|
||||
$html = mb_convert_encoding($view, 'HTML-ENTITIES', 'UTF-8');
|
||||
|
||||
$pdf = app('dompdf.wrapper');
|
||||
@ -108,4 +131,62 @@ trait Transactions
|
||||
|
||||
return $pdf_path;
|
||||
}
|
||||
|
||||
public function getTranslationsForConnect($type = 'income')
|
||||
{
|
||||
$document_type = config('type.transaction.' . $type . '.document_type');
|
||||
$contact_type = config('type.transaction.' . $type . '.contact_type');
|
||||
|
||||
return [
|
||||
'title' => trans('general.connect') . ' ' . trans_choice('general.' . Str::plural($document_type), 1),
|
||||
'cancel' => trans('general.cancel'),
|
||||
'save' => trans('general.save'),
|
||||
'action' => trans('general.actions'),
|
||||
'document' => trans_choice('general.' . Str::plural($document_type), 1),
|
||||
'total' => trans('invoices.total'),
|
||||
'category' => trans_choice('general.categories', 1),
|
||||
'account' => trans_choice('general.accounts', 1),
|
||||
'amount' => trans('general.amount'),
|
||||
'number' => trans_choice('general.numbers', 1),
|
||||
'notes' => trans_choice('general.notes', 2),
|
||||
'contact' => trans_choice('general.' . Str::plural($contact_type), 1),
|
||||
'no_data' => trans('general.no_data'),
|
||||
'placeholder_search' => trans('general.placeholder.search'),
|
||||
'add_an' => trans('general.form.add_an', ['field' => trans_choice('general.' . Str::plural($document_type), 1)]),
|
||||
'transaction' => trans_choice('general.' . Str::plural($type), 1),
|
||||
'difference' => trans('general.difference'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTransactionFormRoutesOfType($type)
|
||||
{
|
||||
return [
|
||||
'contact_index' => route(Str::plural(config('type.transaction.' . $type . '.contact_type')) . '.index'),
|
||||
'contact_modal' => route('modals.' . Str::plural(config('type.transaction.' . $type . '.contact_type')) . '.create'),
|
||||
'category_index' => route('modals.categories.create', ['type' => $type]),
|
||||
'category_modal' => route('categories.index', ['search' => 'type:' . $type]),
|
||||
];
|
||||
}
|
||||
|
||||
public function getRealTypeOfRecurringTransaction(string $recurring_type): string
|
||||
{
|
||||
return Str::replace('-recurring', '', $recurring_type);
|
||||
}
|
||||
|
||||
public function getNextTransactionNumber($suffix = ''): string
|
||||
{
|
||||
$prefix = setting('transaction' . $suffix . '.number_prefix');
|
||||
$next = setting('transaction' . $suffix . '.number_next');
|
||||
$digit = setting('transaction' . $suffix . '.number_digit');
|
||||
|
||||
return $prefix . str_pad($next, $digit, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function increaseNextTransactionNumber($suffix = ''): void
|
||||
{
|
||||
$next = setting('transaction' . $suffix . '.number_next', 1) + 1;
|
||||
|
||||
setting(['transaction' . $suffix . '.number_next' => $next]);
|
||||
setting()->save();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user