Payment summary improvements, removed invoice/payment API calls

This commit is contained in:
Deon George
2020-07-21 17:41:24 +10:00
parent 444f2cf52d
commit c97835edd1
10 changed files with 132 additions and 185 deletions

View File

@@ -7,16 +7,6 @@ use App\User;
class UserServicesController extends Controller
{
public function invoices(User $o)
{
return ['data'=>$o->invoices_due->values()];
}
public function payments(User $o)
{
return ['data'=>$o->payment_history->values()];
}
public function services(User $o)
{
return ['data'=>$o->services_active->values()];

View File

@@ -27,21 +27,6 @@ class Invoice extends Model
// Array of items that can be updated with PushNew
protected $pushable = ['items'];
protected $appends = [
'date_due',
'due',
'invoice_id_url',
'total',
];
protected $visible = [
'date_due',
'due',
'id',
'invoice_id_url',
'total',
];
protected $with = [
'account.country.currency',
'items.taxes',
@@ -97,21 +82,11 @@ class Invoice extends Model
return $this->date_orig->format('Y-m-d');
}
public function getInvoiceIdAttribute()
{
return sprintf('%06s',$this->id);
}
public function getInvoiceAccountIdAttribute()
{
return sprintf('%02s-%04s-%06s',$this->site_id,$this->account_id,$this->invoice_id);
}
public function getInvoiceIdUrlAttribute()
{
return sprintf('<a href="/u/invoice/%s">%s</a>',$this->id,$this->invoice_account_id);
}
public function getInvoiceTextAttribute()
{
return sprintf('Thank you for using %s for your Internet Services.',config('SITE_SETUP')->site_name);

View File

@@ -20,19 +20,6 @@ class Payment extends Model
protected $dateFormat = 'U';
protected $with = ['account.country.currency','items'];
protected $appends = [
'date_paid',
'payment_id_url',
'total',
];
protected $visible = [
'date_paid',
'id',
'payment_id_url',
'total',
];
public function account()
{
return $this->belongsTo(Account::class);
@@ -48,16 +35,6 @@ class Payment extends Model
return $this->date_payment->format('Y-m-d');
}
public function getPaymentIdAttribute()
{
return sprintf('%02s-%04s+%05s',$this->site_id,$this->account_id,$this->id);
}
public function getPaymentIdUrlAttribute()
{
return sprintf('<a href="/u/payment/view/%s">%s</a>',$this->id,$this->payment_id);
}
public function getTotalAttribute()
{
return sprintf('%3.'.$this->currency()->rounding.'f',$this->total_amt);

View File

@@ -614,6 +614,32 @@ class User extends Authenticatable
->from($summary,'summary');
}
public function query_payment_summary()
{
$payment = (new Payment)
->select([
'payment_id',
DB::raw('SUM(allocate) AS allocate'),
])
->from($this->query_payment_items(),'PI')
//->where('ab_payment.active',TRUE) // @todo To implement
->groupBy(['payment_id']);
return (new Payment)
->select([
DB::raw('payment_id AS id'),
'date_orig',
'date_payment',
'total_amt',
//'fees_amt',
DB::raw('total_amt-allocate AS balance'),
])
->join('ab_payment',['ab_payment.id'=>'payment_id'])
->whereIN('account_id',$this->all_accounts()->pluck('id')->unique()->toArray())
->from($payment,'summary');
}
public function role()
{
// If I have agents and no parent, I am the wholesaler