move on to mysql, change coin to poin
parent
2431def267
commit
eca09a6cd6
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Customer;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CoinHistory;
|
||||
|
||||
class CoinController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$coins = CoinHistory::where('customer_id', auth()->id())
|
||||
->orderBy('updated_at', 'desc');
|
||||
|
||||
return inertia('Coin/Index', [
|
||||
'coins' => $coins->paginate(20),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(CoinHistory $coin)
|
||||
{
|
||||
return inertia('Coin/Detail', [
|
||||
'coin' => $coin,
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Customer;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\poinHistory;
|
||||
|
||||
class PoinController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$poins = PoinHistory::where('customer_id', auth()->id())
|
||||
->orderBy('updated_at', 'desc');
|
||||
|
||||
return inertia('Poin/Index', [
|
||||
'poins' => $poins->paginate(20),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(poinHistory $poin)
|
||||
{
|
||||
return inertia('Poin/Detail', [
|
||||
'poin' => $poin,
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class PoinHistory extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'debit',
|
||||
'credit',
|
||||
'description',
|
||||
'customer_id',
|
||||
'related_type',
|
||||
'related_id',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'amount',
|
||||
'format_human_created_at',
|
||||
'format_created_at',
|
||||
];
|
||||
|
||||
public function formatHumanCreatedAt(): Attribute
|
||||
{
|
||||
return Attribute::make(get: function () {
|
||||
return Carbon::parse($this->created_at)->locale('id')->translatedFormat('d F Y');
|
||||
});
|
||||
}
|
||||
|
||||
public function formatCreatedAt(): Attribute
|
||||
{
|
||||
return Attribute::make(get: function () {
|
||||
return Carbon::parse($this->created_at)->locale('id')->translatedFormat('d F Y H:i:s');
|
||||
});
|
||||
}
|
||||
|
||||
public function amount(): Attribute
|
||||
{
|
||||
return Attribute::make(get: function () {
|
||||
if ($this->credit == 0) {
|
||||
return number_format($this->debit, is_float($this->debit) ? 2 : 0, ',', '.');
|
||||
}
|
||||
|
||||
return number_format($this->credit, is_float($this->credit) ? 2 : 0, ',', '.');
|
||||
});
|
||||
}
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
public function update_customer_balance()
|
||||
{
|
||||
$customer = Customer::find($this->customer_id);
|
||||
$customer->update(['poin_balance' => $customer->poin_balance + $this->debit - $this->credit]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue