Merge branch 'master' of github.com:akaunting/akaunting

This commit is contained in:
Cüneyt Şentürk
2022-07-20 10:24:00 +03:00
23 changed files with 229 additions and 99 deletions

View File

@ -37,7 +37,7 @@ abstract class Controller extends BaseController
*
* @return LengthAwarePaginator
*/
public function paginate($items, $perPage = 15, $page = null, $options = [])
public function paginate($items, $perPage = null, $page = null, $options = [])
{
$perPage = $perPage ?: (int) request('limit', setting('default.list_limit', '25'));

View File

@ -47,7 +47,7 @@ class Transactions extends Export implements WithColumnFormatting
public function columnFormats(): array
{
return [
'B' => NumberFormat::FORMAT_DATE_YYYYMMDD,
'C' => NumberFormat::FORMAT_DATE_YYYYMMDD,
];
}
}

View File

@ -53,7 +53,7 @@ class BillTransactions extends Export implements WithColumnFormatting
public function columnFormats(): array
{
return [
'B' => NumberFormat::FORMAT_DATE_YYYYMMDD,
'C' => NumberFormat::FORMAT_DATE_YYYYMMDD,
];
}
}

View File

@ -53,7 +53,7 @@ class InvoiceTransactions extends Export implements WithColumnFormatting
public function columnFormats(): array
{
return [
'B' => NumberFormat::FORMAT_DATE_YYYYMMDD,
'C' => NumberFormat::FORMAT_DATE_YYYYMMDD,
];
}
}

View File

@ -10,9 +10,9 @@ use App\Jobs\Banking\UpdateAccount;
use App\Models\Banking\Account;
use App\Models\Banking\Transaction;
use App\Models\Banking\Transfer;
use App\Utilities\Reports as Utility;
use App\Utilities\Date;
use App\Utilities\Reports;
use App\Models\Setting\Currency;
use Date;
class Accounts extends Controller
{
@ -35,23 +35,27 @@ class Accounts extends Controller
*/
public function show(Account $account)
{
// Handle transactions
$transactions = Transaction::with('account', 'category')->where('account_id', $account->id)->collect('paid_at');
$transactions = Transaction::with('category', 'contact', 'document')->where('account_id', $account->id)->collect(['paid_at'=> 'desc']);
$transfers = Transfer::with('expense_transaction', 'income_transaction')->get()->filter(function ($transfer) use($account) {
if ($transfer->expense_account->id == $account->id || $transfer->income_account->id == $account->id) {
return true;
}
$transfers = Transfer::with('expense_transaction', 'expense_transaction.account', 'income_transaction', 'income_transaction.account')
->whereHas('expense_transaction', fn ($query) => $query->where('account_id', $account->id))
->orWhereHas('income_transaction', fn ($query) => $query->where('account_id', $account->id))
->collect(['expense_transaction.paid_at' => 'desc']);
return false;
})->sortByDesc(function ($transfer) {
return $transfer->expense_transaction->paid_at;
});
$incoming_amount = money($account->income_balance, $account->currency_code, true);
$outgoing_amount = money($account->expense_balance, $account->currency_code, true);
$current_amount = money($account->balance, $account->currency_code, true);
$limit = (int) request('limit', setting('default.list_limit', '25'));
$transfers = $this->paginate($transfers, $limit);
$summary_amounts = [
'incoming_exact' => $incoming_amount->format(),
'incoming_for_humans' => $incoming_amount->formatForHumans(),
'outgoing_exact' => $outgoing_amount->format(),
'outgoing_for_humans' => $outgoing_amount->formatForHumans(),
'current_exact' => $current_amount->format(),
'current_for_humans' => $current_amount->formatForHumans(),
];
return view('banking.accounts.show', compact('account', 'transactions', 'transfers'));
return view('banking.accounts.show', compact('account', 'transactions', 'transfers', 'summary_amounts'));
}
/**
@ -248,7 +252,7 @@ class Accounts extends Controller
'account_id' => $account->id,
];
$report = Utility::getClassInstance('App\Reports\IncomeExpenseSummary');
$report = Reports::getClassInstance('App\Reports\IncomeExpenseSummary');
if (empty($report) || empty($report->model)) {
$message = trans('accounts.create_report');

View File

@ -155,7 +155,7 @@ class Tiles extends Controller
$modules = $this->getSearchModules($data);
$installed = Module::all()->pluck('enabled', 'alias')->toArray();
return view('modules.tiles.index', compact('title', 'modules', 'keyword', 'installed'));
return $this->response('modules.tiles.index', compact('modules', 'title', 'keyword', 'installed'));
}
public function loadMore($type, Request $request)

View File

@ -20,6 +20,7 @@ class Transactions extends Import
$row['account_id'] = $this->getAccountId($row);
$row['category_id'] = $this->getCategoryId($row);
$row['contact_id'] = $this->getContactId($row);
$row['currency_code'] = $this->getCurrencyCode($row);
$row['document_id'] = $this->getDocumentId($row);
return $row;

View File

@ -27,9 +27,11 @@ class Transfers extends Import
$row['transferred_at'] = Date::parse($row['transferred_at'])->format('Y-m-d');
$row['from_account_id'] = $this->getFromAccountId($row);
$row['to_account_id'] = $this->getToAccountId($row);
$row['from_currency_code'] = $this->getFromCurrencyCode($row);
$row['to_currency_code'] = $this->getToCurrencyCode($row);
$row['expense_transaction_id'] = $this->getExpenseTransactionId($row);
$row['income_transaction_id'] = $this->getIncomeTransactionId($row);
return $row;
}
@ -124,4 +126,20 @@ class Transfers extends Import
return $this->getAccountId($row);
}
private function getFromCurrencyCode($row)
{
$row['currency_code'] = $row['from_currency_code'] ?? null;
$row['currency_rate'] = $row['from_currency_rate'] ?? null;
return $this->getCurrencyCode($row);
}
private function getToCurrencyCode($row)
{
$row['currency_code'] = $row['to_currency_code'] ?? null;
$row['currency_rate'] = $row['to_currency_rate'] ?? null;
return $this->getCurrencyCode($row);
}
}

View File

@ -25,6 +25,7 @@ class BillTransactions extends Import
$row['account_id'] = $this->getAccountId($row);
$row['category_id'] = $this->getCategoryId($row, 'expense');
$row['contact_id'] = $this->getContactId($row, 'vendor');
$row['currency_code'] = $this->getCurrencyCode($row);
$row['document_id'] = $this->getDocumentId($row);
$row['number'] = $row['transaction_number'];

View File

@ -28,6 +28,7 @@ class Bills extends Import
$row['issued_at'] = $row['billed_at'];
$row['category_id'] = $this->getCategoryId($row, 'expense');
$row['contact_id'] = $this->getContactId($row, 'vendor');
$row['currency_code'] = $this->getCurrencyCode($row);
$row['type'] = Model::BILL_TYPE;
$row['contact_country'] = !empty($country) ? $country : null;

View File

@ -21,6 +21,7 @@ class Vendors extends Import
$row['type'] = 'vendor';
$row['country'] = !empty($country) ? $country : null;
$row['currency_code'] = $this->getCurrencyCode($row);
$row['user_id'] = null;
return $row;

View File

@ -21,6 +21,7 @@ class Customers extends Import
$row['type'] = 'customer';
$row['country'] = !empty($country) ? $country : null;
$row['currency_code'] = $this->getCurrencyCode($row);
$row['user_id'] = null;
return $row;

View File

@ -25,6 +25,7 @@ class InvoiceTransactions extends Import
$row['account_id'] = $this->getAccountId($row);
$row['category_id'] = $this->getCategoryId($row, 'income');
$row['contact_id'] = $this->getContactId($row, 'customer');
$row['currency_code'] = $this->getCurrencyCode($row);
$row['document_id'] = $this->getDocumentId($row);
$row['number'] = $row['transaction_number'];

View File

@ -28,6 +28,7 @@ class Invoices extends Import
$row['issued_at'] = $row['invoiced_at'];
$row['category_id'] = $this->getCategoryId($row, 'income');
$row['contact_id'] = $this->getContactId($row, 'customer');
$row['currency_code'] = $this->getCurrencyCode($row);
$row['type'] = Model::INVOICE_TYPE;
$row['contact_country'] = !empty($country) ? $country : null;

View File

@ -6,17 +6,20 @@ use App\Http\Requests\Banking\Account as AccountRequest;
use App\Http\Requests\Common\Contact as ContactRequest;
use App\Http\Requests\Common\Item as ItemRequest;
use App\Http\Requests\Setting\Category as CategoryRequest;
use App\Http\Requests\Setting\Currency as CurrencyRequest;
use App\Http\Requests\Setting\Tax as TaxRequest;
use App\Jobs\Banking\CreateAccount;
use App\Jobs\Common\CreateContact;
use App\Jobs\Common\CreateItem;
use App\Jobs\Setting\CreateCategory;
use App\Jobs\Setting\CreateCurrency;
use App\Jobs\Setting\CreateTax;
use App\Models\Banking\Account;
use App\Models\Common\Contact;
use App\Models\Common\Item;
use App\Models\Document\Document;
use App\Models\Setting\Category;
use App\Models\Setting\Currency;
use App\Models\Setting\Tax;
use App\Traits\Jobs;
use Illuminate\Support\Facades\Validator;
@ -74,6 +77,33 @@ trait Import
return is_null($id) ? $id : (int) $id;
}
public function getCurrencyCode($row)
{
$currency = Currency::where('code', $row['currency_code'])->first();
if (!empty($currency)) {
return $currency->code;
}
$data = [
'company_id' => company_id(),
'code' => $row['currency_code'],
'name' => isset($row['currency_name']) ? $row['currency_name'] : config('money.' . $row['currency_code'] . '.name'),
'rate' => isset($row['currency_rate']) ? $row['currency_rate'] : 1,
'symbol' => isset($row['currency_symbol']) ? $row['currency_symbol'] : config('money.' . $row['currency_code'] . '.symbol'),
'precision' => isset($row['currency_precision']) ? $row['currency_precision'] : config('money.' . $row['currency_code'] . '.precision'),
'decimal_mark' => isset($row['currency_decimal_mark']) ? $row['currency_decimal_mark'] : config('money.' . $row['currency_code'] . '.decimal_mark'),
'created_from' => $row['created_from'],
'created_by' => $row['created_by'],
];
Validator::validate($data, [(new CurrencyRequest)->rules()]);
$currency = $this->dispatch(new CreateCurrency($data));
return $currency->code;
}
public function getDocumentId($row)
{
$id = isset($row['document_id']) ? $row['document_id'] : null;

View File

@ -2,6 +2,7 @@
namespace App\Utilities;
use Akaunting\Money\Money;
use App\Models\Setting\Currency;
class Overrider
@ -58,6 +59,9 @@ class Overrider
app()->setLocale($locale);
}
// Set locale for Money package
Money::setLocale(app()->getLocale());
// Set app url dynamically if empty
if (! config('app.url')) {
config(['app.url' => url('/')]);

View File

@ -74,9 +74,8 @@ class Content extends Component
$this->totals = $totals;
$limit = (int) request('limit', setting('default.list_limit', '25'));
$this->transactions = $this->paginate($this->transactions->sortByDesc('paid_at'), $limit);
$this->documents = $this->paginate($this->documents->sortByDesc('issued_at'), $limit);
$this->transactions = $this->paginate($this->transactions->sortByDesc('paid_at'));
$this->documents = $this->paginate($this->documents->sortByDesc('issued_at'));
return view('components.contacts.show.content');
}
@ -91,7 +90,7 @@ class Content extends Component
*
* @return LengthAwarePaginator
*/
public function paginate($items, $perPage = 15, $page = null, $options = [])
public function paginate($items, $perPage = null, $page = null, $options = [])
{
$perPage = $perPage ?: (int) request('limit', setting('default.list_limit', '25'));