mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-19 19:55:02 +00:00
- client and invoice scaffolding
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Oasis;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ClientController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Oasis;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
use Laravel\Cashier\Cashier;
|
||||
|
||||
/**
|
||||
* @param $invoice
|
||||
* @param false $format
|
||||
* @return float|int|mixed|string
|
||||
*/
|
||||
function invoice_total_discount($invoice, $format = false)
|
||||
{
|
||||
// Percent discount
|
||||
if ($invoice['discount_type'] === 'percent') {
|
||||
|
||||
$discount = invoice_total_net($invoice) * ($invoice['discount_rate'] / 100);
|
||||
|
||||
if ($format) {
|
||||
return Cashier::formatAmount($discount * 100, $invoice['currency'], 'cs');
|
||||
}
|
||||
|
||||
return $discount;
|
||||
}
|
||||
|
||||
// Value discount
|
||||
if ($invoice['discount_type'] === 'value') {
|
||||
|
||||
if ($format) {
|
||||
return Cashier::formatAmount($invoice['discount_rate'] * 100, $invoice['currency'], 'cs');
|
||||
}
|
||||
|
||||
return $invoice['discount_rate'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $invoice
|
||||
* @param false $format
|
||||
* @return float|int|string
|
||||
*/
|
||||
function invoice_total_net($invoice, $format = false)
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
foreach ($invoice['items'] as $item) {
|
||||
$total += $item['amount'] * $item['price'];
|
||||
}
|
||||
|
||||
if ($format) {
|
||||
return Cashier::formatAmount(($total * 100), $invoice['currency'], 'cs');
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $invoice
|
||||
* @param false $format
|
||||
* @return float|int|string
|
||||
*/
|
||||
function invoice_total_tax($invoice, $format = false)
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
foreach ($invoice['items'] as $item) {
|
||||
$total += ($item['amount'] * $item['price']) * ($item['tax_rate'] / 100);
|
||||
}
|
||||
|
||||
if ($format) {
|
||||
return Cashier::formatAmount(($total * 100), $invoice['currency'], 'cs');
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Oasis;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Client extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $guarded = ['id'];
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany(Invoice::class, 'client_id', 'id');
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($order) {
|
||||
$order->id = Str::uuid();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Oasis;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Invoice extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $casts = [
|
||||
'items' => 'array',
|
||||
'user' => 'array',
|
||||
'client' => 'array',
|
||||
];
|
||||
|
||||
public $guarded = ['id'];
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
public function client()
|
||||
{
|
||||
return $this->hasOne(Client::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($order) {
|
||||
$order->id = Str::uuid();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Models\Oasis\Client;
|
||||
use App\Models\Oasis\Invoice;
|
||||
use App\Models\Oasis\SubscriptionRequest;
|
||||
|
||||
trait Oasis
|
||||
@@ -15,4 +17,14 @@ trait Oasis
|
||||
{
|
||||
return $this->hasOne(SubscriptionRequest::class);
|
||||
}
|
||||
|
||||
public function clients()
|
||||
{
|
||||
return $this->hasMany(Client::class);
|
||||
}
|
||||
|
||||
public function createdInvoices()
|
||||
{
|
||||
return $this->hasMany(Invoice::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user