bank reconciliation

This commit is contained in:
denisdulici
2018-10-27 17:57:40 +03:00
parent 42f6b00485
commit 268a4aa9d5
29 changed files with 1209 additions and 88 deletions

View File

@ -3,6 +3,7 @@
namespace App\Models\Expense;
use App\Models\Model;
use App\Models\Setting\Currency;
use App\Traits\Currencies;
use App\Traits\DateTime;
use App\Traits\Media;
@ -22,7 +23,7 @@ class Bill extends Model
*
* @var array
*/
protected $appends = ['attachment', 'discount'];
protected $appends = ['attachment', 'discount', 'paid'];
protected $dates = ['deleted_at', 'billed_at', 'due_at'];
@ -199,4 +200,55 @@ class Bill extends Model
return $percent;
}
/**
* Get the paid amount.
*
* @return string
*/
public function getPaidAttribute()
{
$paid = 0;
$reconciled = $reconciled_amount = 0;
if ($this->payments->count()) {
$currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
foreach ($this->payments as $item) {
if ($this->currency_code == $item->currency_code) {
$amount = (double) $item->amount;
} else {
$default_model = new BillPayment();
$default_model->default_currency_code = $this->currency_code;
$default_model->amount = $item->amount;
$default_model->currency_code = $item->currency_code;
$default_model->currency_rate = $currencies[$item->currency_code];
$default_amount = (double) $default_model->getDivideConvertedAmount();
$convert_model = new BillPayment();
$convert_model->default_currency_code = $item->currency_code;
$convert_model->amount = $default_amount;
$convert_model->currency_code = $this->currency_code;
$convert_model->currency_rate = $currencies[$this->currency_code];
$amount = (double) $convert_model->getDynamicConvertedAmount();
}
$paid += $amount;
if ($item->reconciled) {
$reconciled_amount = +$amount;
}
}
}
if ($this->amount == $reconciled_amount) {
$reconciled = 1;
}
$this->setAttribute('reconciled', $reconciled);
return $paid;
}
}