Merge branch 'master' of github.com:akaunting/akaunting into 2.1-dev

This commit is contained in:
Cüneyt Şentürk
2020-09-08 11:11:36 +03:00
48 changed files with 1230 additions and 279 deletions

View File

@ -3,7 +3,6 @@
namespace App\Abstracts;
use App\Abstracts\Model;
use App\Events\Sale\InvoicePaidCalculated;
use App\Models\Setting\Tax;
use App\Traits\Currencies;
use App\Traits\DateTime;
@ -116,14 +115,9 @@ abstract class DocumentModel extends Model
$this->setAttribute('reconciled', $reconciled);
// TODO: find a cleaner way compatible with observer pattern
$invoice = clone $this;
$invoice->paid_amount = $paid;
event(new InvoicePaidCalculated($invoice));
return round($invoice->paid_amount, $precision);
return round($paid, $precision);
}
/**
* Get the status label.
*

View File

@ -0,0 +1,22 @@
<?php
namespace App\Events\Document;
use Illuminate\Queue\SerializesModels;
class PaidAmountCalculated
{
use SerializesModels;
public $model;
/**
* Create a new event instance.
*
* @param $model
*/
public function __construct($model)
{
$this->model = $model;
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Events\Document;
use Illuminate\Queue\SerializesModels;
class TransactionsCounted
{
use SerializesModels;
public $model;
/**
* Create a new event instance.
*
* @param $model
*/
public function __construct($model)
{
$this->model = $model;
}
}

View File

@ -1,22 +0,0 @@
<?php
namespace App\Events\Sale;
use Illuminate\Queue\SerializesModels;
class InvoicePaidCalculated
{
use SerializesModels;
public $invoice;
/**
* Create a new event instance.
*
* @param $invoice
*/
public function __construct($invoice)
{
$this->invoice = $invoice;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Portal;
use App\Abstracts\Http\Controller;
use App\Http\Requests\Portal\InvoiceShow as Request;
use App\Models\Sale\Invoice;
use App\Models\Setting\Category;
use App\Traits\Currencies;
@ -41,7 +42,7 @@ class Invoices extends Controller
*
* @return Response
*/
public function show(Invoice $invoice)
public function show(Invoice $invoice, Request $request)
{
$payment_methods = Modules::getPaymentMethods();
@ -57,7 +58,7 @@ class Invoices extends Controller
*
* @return Response
*/
public function printInvoice(Invoice $invoice)
public function printInvoice(Invoice $invoice, Request $request)
{
$invoice = $this->prepareInvoice($invoice);
@ -71,7 +72,7 @@ class Invoices extends Controller
*
* @return Response
*/
public function pdfInvoice(Invoice $invoice)
public function pdfInvoice(Invoice $invoice, Request $request)
{
$invoice = $this->prepareInvoice($invoice);
@ -92,22 +93,6 @@ class Invoices extends Controller
protected function prepareInvoice(Invoice $invoice)
{
$paid = 0;
foreach ($invoice->transactions as $item) {
$amount = $item->amount;
if ($invoice->currency_code != $item->currency_code) {
$item->default_currency_code = $invoice->currency_code;
$amount = $item->getAmountConvertedFromDefault();
}
$paid += $amount;
}
$invoice->paid = $paid;
$invoice->template_path = 'sales.invoices.print_' . setting('invoice.template' ,'default');
event(new \App\Events\Sale\InvoicePrinting($invoice));
@ -121,22 +106,6 @@ class Invoices extends Controller
redirect()->route('login');
}
$paid = 0;
foreach ($invoice->transactions as $item) {
$amount = $item->amount;
if ($invoice->currency_code != $item->currency_code) {
$item->default_currency_code = $invoice->currency_code;
$amount = $item->getAmountConvertedFromDefault();
}
$paid += $amount;
}
$invoice->paid = $paid;
$payment_methods = Modules::getPaymentMethods();
$payment_actions = [];

View File

@ -4,11 +4,11 @@ namespace App\Http\Controllers\Portal;
use App\Abstracts\Http\Controller;
use App\Models\Banking\Transaction;
use App\Http\Requests\Portal\PaymentShow as Request;
use App\Utilities\Modules;
class Payments extends Controller
{
/**
* Display a listing of the resource.
*
@ -30,7 +30,7 @@ class Payments extends Controller
*
* @return Response
*/
public function show(Transaction $payment)
public function show(Transaction $payment, Request $request)
{
$payment_methods = Modules::getPaymentMethods('all');

View File

@ -54,7 +54,9 @@ class Settings extends Controller
$settings = [];
foreach ($modules->settings as $alias => $setting) {
if (!user()->can('read-' . $alias . '-settings')) {
$permission = !empty($setting['permission']) ? $setting['permission'] : 'read-' . $alias . '-settings';
if (!user()->can($permission)) {
continue;
}

View File

@ -0,0 +1,34 @@
<?php
namespace App\Http\Requests\Portal;
use App\Abstracts\Http\FormRequest;
class InvoiceShow extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
if (auth()->guest()) {
return true;
}
return $this->invoice->contact_id == user()->contact->id;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests\Portal;
use App\Abstracts\Http\FormRequest;
class PaymentShow extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->payment->contact_id == user()->contact->id;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -6,6 +6,7 @@ use App\Abstracts\Job;
use App\Jobs\Banking\CreateTransaction;
use App\Jobs\Purchase\CreateBillHistory;
use App\Jobs\Sale\CreateInvoiceHistory;
use App\Events\Document\PaidAmountCalculated;
use App\Models\Banking\Transaction;
use App\Models\Sale\Invoice;
use App\Traits\Currencies;
@ -64,11 +65,17 @@ class CreateDocumentTransaction extends Job
protected function prepareRequest()
{
if (!isset($this->request['amount'])) {
$this->model->paid_amount = $this->model->paid;
event(new PaidAmountCalculated($this->model));
$this->request['amount'] = $this->model->amount - $this->model->paid_amount;
}
$this->request['company_id'] = session('company_id');
$this->request['currency_code'] = isset($this->request['currency_code']) ? $this->request['currency_code'] : $this->model->currency_code;
$this->request['type'] = ($this->model instanceof Invoice) ? 'income' : 'expense';
$this->request['paid_at'] = isset($this->request['paid_at']) ? $this->request['paid_at'] : Date::now()->format('Y-m-d');
$this->request['amount'] = isset($this->request['amount']) ? $this->request['amount'] : ($this->model->amount - $this->model->paid);
$this->request['currency_rate'] = config('money.' . $this->request['currency_code'] . '.rate');
$this->request['account_id'] = isset($this->request['account_id']) ? $this->request['account_id'] : setting('default.account');
$this->request['document_id'] = isset($this->request['document_id']) ? $this->request['document_id'] : $this->model->id;
@ -92,8 +99,13 @@ class CreateDocumentTransaction extends Job
$amount = round($converted_amount, $precision);
}
$total_amount = round($this->model->amount - $this->model->paid, $precision);
$this->model->paid_amount = $this->model->paid;
event(new PaidAmountCalculated($this->model));
$total_amount = round($this->model->amount - $this->model->paid_amount, $precision);
unset($this->model->reconciled);
unset($this->model->paid_amount);
$compare = bccomp($amount, $total_amount, $precision);

View File

@ -3,6 +3,7 @@
namespace App\Jobs\Purchase;
use App\Abstracts\Job;
use App\Events\Document\PaidAmountCalculated;
use App\Events\Purchase\BillUpdated;
use App\Events\Purchase\BillUpdating;
use App\Jobs\Purchase\CreateBillItemsAndTotals;
@ -53,14 +54,16 @@ class UpdateBill extends Job
$this->dispatch(new CreateBillItemsAndTotals($this->bill, $this->request));
$bill_paid = $this->bill->paid;
$this->bill->paid_amount = $this->bill->paid;
event(new PaidAmountCalculated($this->bill));
unset($this->bill->reconciled);
if (($bill_paid) && $this->request['amount'] > $bill_paid) {
if ($this->request['amount'] > $this->bill->paid_amount) {
$this->request['status'] = 'partial';
}
unset($this->bill->reconciled);
unset($this->bill->paid_amount);
$this->bill->update($this->request->input());
$this->bill->updateRecurring();

View File

@ -3,6 +3,7 @@
namespace App\Jobs\Sale;
use App\Abstracts\Job;
use App\Events\Document\PaidAmountCalculated;
use App\Events\Sale\InvoiceUpdated;
use App\Events\Sale\InvoiceUpdating;
use App\Jobs\Sale\CreateInvoiceItemsAndTotals;
@ -53,14 +54,16 @@ class UpdateInvoice extends Job
$this->dispatch(new CreateInvoiceItemsAndTotals($this->invoice, $this->request));
$invoice_paid = $this->invoice->paid;
$this->invoice->paid_amount = $this->invoice->paid;
event(new PaidAmountCalculated($this->invoice));
unset($this->invoice->reconciled);
if (($invoice_paid) && $this->request['amount'] > $invoice_paid) {
if ($this->request['amount'] > $this->invoice->paid_amount) {
$this->request['status'] = 'partial';
}
unset($this->invoice->reconciled);
unset($this->invoice->paid_amount);
$this->invoice->update($this->request->all());
$this->invoice->updateRecurring();

View File

@ -291,4 +291,36 @@ class Transaction extends Model
{
return $value ?? trans_choice('general.' . Str::plural($this->type), 1);
}
/**
* Get the route name.
*
* @return string
*/
public function getRouteNameAttribute($value)
{
if ($value) {
return $value;
}
if ($this->isIncome()) {
return !empty($this->document_id) ? 'invoices.show' : 'revenues.edit';
}
if ($this->isExpense()) {
return !empty($this->document_id) ? 'bills.show' : 'payments.edit';
}
return 'transactions.index';
}
/**
* Get the route id.
*
* @return string
*/
public function getRouteIdAttribute($value)
{
return $value ?? $this->document_id ?? $this->id;
}
}

View File

@ -45,7 +45,7 @@ class Reset extends Notification
{
return (new MailMessage)
->line(trans('auth.notification.message_1'))
->action(trans('auth.notification.button'), route('auth.reset', $this->token))
->action(trans('auth.notification.button'), route('reset', $this->token))
->line(trans('auth.notification.message_2'));
}
}

View File

@ -3,6 +3,7 @@
namespace App\Observers;
use App\Abstracts\Observer;
use App\Events\Document\TransactionsCounted;
use App\Jobs\Purchase\CreateBillHistory;
use App\Jobs\Sale\CreateInvoiceHistory;
use App\Models\Banking\Transaction as Model;
@ -33,7 +34,12 @@ class Transaction extends Observer
{
$invoice = $transaction->invoice;
$invoice->status = ($invoice->transactions->count() > 1) ? 'partial' : 'sent';
$invoice->transactions_count = $invoice->transactions->count();
event(new TransactionsCounted($invoice));
$invoice->status = ($invoice->transactions_count > 0) ? 'partial' : 'sent';
unset($invoice->transactions_count);
$invoice->save();
@ -44,7 +50,12 @@ class Transaction extends Observer
{
$bill = $transaction->bill;
$bill->status = ($bill->transactions->count() > 1) ? 'partial' : 'received';
$bill->transactions_count = $bill->transactions->count();
event(new TransactionsCounted($bill));
$bill->status = ($bill->transactions_count > 0) ? 'partial' : 'received';
unset($bill->transactions_count);
$bill->save();

View File

@ -209,7 +209,7 @@ class Installer
'DB_PORT' => $port,
'DB_DATABASE' => $database,
'DB_USERNAME' => $username,
'DB_PASSWORD' => $password,
'DB_PASSWORD' => '"' . $password . '"',
'DB_PREFIX' => $prefix,
]);