Update source into github
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Cart;
|
||||
|
||||
use App\Models\Addon;
|
||||
use Livewire\Component;
|
||||
|
||||
class SummaryAddons extends Component
|
||||
{
|
||||
public $product;
|
||||
public $addons = [];
|
||||
public $index;
|
||||
public $months = 1;
|
||||
public $cachedTotalPrice = null;
|
||||
|
||||
public function mount($product, $index = null, $months = 1)
|
||||
{
|
||||
$this->product = $product;
|
||||
$this->months = $months;
|
||||
|
||||
// Lấy tất cả addon từ database
|
||||
$addonsFromDb = Addon::all()->toArray();
|
||||
|
||||
// Chuyển đổi dữ liệu addon từ database sang định dạng phù hợp với component
|
||||
$this->addons = collect($addonsFromDb)->map(function ($addon) {
|
||||
return [
|
||||
'id' => $addon['id'],
|
||||
'name' => $addon['name'],
|
||||
'price' => $addon['price'],
|
||||
'min' => $addon['min'],
|
||||
'max' => $addon['max'],
|
||||
'step' => $addon['step'],
|
||||
'prefix' => $addon['prefix'],
|
||||
'type_id' => $addon['type_id'],
|
||||
'qty' => 0, // Khởi tạo số lượng ban đầu là 0
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
$this->index = $index;
|
||||
}
|
||||
|
||||
public function increment($key)
|
||||
{
|
||||
if ($this->addons[$key]['qty'] < ($this->addons[$key]['max'] ?? PHP_INT_MAX)) {
|
||||
$this->addons[$key]['qty'] += ($this->addons[$key]['step'] ?? 1);
|
||||
}
|
||||
|
||||
$this->calculateTotal();
|
||||
$this->dispatch('addonUpdated', addons: $this->addons);
|
||||
}
|
||||
|
||||
public function decrement($key)
|
||||
{
|
||||
if ($this->addons[$key]['qty'] > ($this->addons[$key]['min'] ?? 0)) {
|
||||
$this->addons[$key]['qty'] -= ($this->addons[$key]['step'] ?? 1);
|
||||
}
|
||||
|
||||
$this->calculateTotal();
|
||||
$this->dispatch('addonUpdated', addons: $this->addons);
|
||||
}
|
||||
|
||||
// Triggered when input fields are updated directly
|
||||
public function updated($name, $value)
|
||||
{
|
||||
// Check if the updated property is related to addon quantity
|
||||
if (strpos($name, 'addons.') !== false && strpos($name, '.qty') !== false) {
|
||||
$parts = explode('.', $name);
|
||||
$key = $parts[1] ?? null;
|
||||
|
||||
if ($key !== null && isset($this->addons[$key])) {
|
||||
// Ensure quantity is within bounds
|
||||
$min = $this->addons[$key]['min'] ?? 0;
|
||||
$max = $this->addons[$key]['max'] ?? PHP_INT_MAX;
|
||||
$step = $this->addons[$key]['step'] ?? 1;
|
||||
|
||||
// Round to the nearest step
|
||||
$this->addons[$key]['qty'] = round($value / $step) * $step;
|
||||
|
||||
// Apply min/max constraints
|
||||
$this->addons[$key]['qty'] = max($min, $this->addons[$key]['qty']);
|
||||
$this->addons[$key]['qty'] = min($max, $this->addons[$key]['qty']);
|
||||
|
||||
// Ensure total is recalculated immediately
|
||||
$this->calculateTotal();
|
||||
|
||||
// Notify listeners that addon has been updated
|
||||
$this->dispatch('addonUpdated', addons: $this->addons);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hydrate()
|
||||
{
|
||||
// This method is called on every Livewire request
|
||||
// Perfect place to make sure our computed properties are up-to-date
|
||||
$this->calculateTotal();
|
||||
}
|
||||
|
||||
protected function calculateTotal()
|
||||
{
|
||||
// Lấy giá sản phẩm ưu tiên sale nếu có
|
||||
$basePrice = $this->product->price_sale ?: $this->product->price;
|
||||
|
||||
// Nhân với số tháng
|
||||
$total = $basePrice * $this->months;
|
||||
|
||||
foreach ($this->addons as $addon) {
|
||||
$total += $addon['qty'] * $addon['price'] * $this->months;
|
||||
}
|
||||
|
||||
$this->cachedTotalPrice = $total;
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function getTotalAddonPriceProperty()
|
||||
{
|
||||
return collect($this->addons)->sum(function ($addon) {
|
||||
return $addon['qty'] * ($addon['price'] ?? 0) * $this->months;
|
||||
});
|
||||
}
|
||||
|
||||
public function getTotalPriceProperty()
|
||||
{
|
||||
// Use cached value if available, otherwise calculate
|
||||
return $this->cachedTotalPrice ?? $this->calculateTotal();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.cart.summary-addons');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Mail;
|
||||
use Illuminate\Http\Request;
|
||||
use Livewire\Component;
|
||||
|
||||
class CustomerEmailHistory extends Component
|
||||
{
|
||||
public $search = '';
|
||||
public function render(Request $request)
|
||||
{
|
||||
return view('livewire.customer-email-history',[
|
||||
'emails' => Mail::where('customer_id',auth('users')->id())
|
||||
->where('subject', 'like',"%$this->search%")
|
||||
->latest('id')
|
||||
->paginate(10)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Invoice as CustomerInvoice;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class Invoice extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
public $status = "full";
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
return view('livewire.invoice', [
|
||||
'invoice' => CustomerInvoice::where(function ($query) {
|
||||
switch ($this->status) {
|
||||
case "0":
|
||||
case "1":
|
||||
case "2":
|
||||
$query->where('status', $this->status);
|
||||
break;
|
||||
}
|
||||
})
|
||||
->where('customer_id', customer()->id)
|
||||
->latest()
|
||||
->paginate(10)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Module;
|
||||
|
||||
use App\Repositories\vCenter\vCenterRepositoryInterface;
|
||||
use Livewire\Component;
|
||||
|
||||
class Vcenter extends Component
|
||||
{
|
||||
public $model;
|
||||
public $vcenters = [];
|
||||
|
||||
protected $vCenterRepository;
|
||||
|
||||
public function boot(vCenterRepositoryInterface $vCenterRepository)
|
||||
{
|
||||
$this->vCenterRepository = $vCenterRepository;
|
||||
}
|
||||
|
||||
public function mount($model = null)
|
||||
{
|
||||
$this->model = $model;
|
||||
|
||||
$this->vcenters = $this->vCenterRepository->filter(
|
||||
['status' => 1],
|
||||
[],
|
||||
[],
|
||||
['id', 'host']
|
||||
);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.module.vcenter');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Repositories\Invoice\InvoiceRepositoryInterface;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithoutUrlPagination;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class MyService extends Component
|
||||
{
|
||||
use WithPagination, WithoutUrlPagination;
|
||||
|
||||
public int|string $status = 'full';
|
||||
public $type = '';
|
||||
public $search = '';
|
||||
protected $invoiceRepository;
|
||||
|
||||
public function mount(InvoiceRepositoryInterface $invoiceRepository)
|
||||
{
|
||||
$this->invoiceRepository = $invoiceRepository;
|
||||
}
|
||||
|
||||
public function updatedSearch()
|
||||
{
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
public function updatedStatus()
|
||||
{
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
public function updatedType()
|
||||
{
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$query = Invoice::where('customer_id', customer()->id)
|
||||
->with([
|
||||
'invoiceItem.hosting',
|
||||
'invoiceItem.vps',
|
||||
'invoiceItem.os.osGroup',
|
||||
'invoiceItem.addons.addonItems'
|
||||
]);
|
||||
|
||||
// Filter by type if specified
|
||||
if (!empty($this->type)) {
|
||||
$query->whereHas('invoiceItem', function($q) {
|
||||
$q->where('product_type', $this->type);
|
||||
});
|
||||
}
|
||||
|
||||
// Filter by server_name search if specified
|
||||
if (!empty($this->search)) {
|
||||
$query->whereHas('invoiceItem', function($q) {
|
||||
$q->where('server_name', 'like', '%' . $this->search . '%');
|
||||
});
|
||||
}
|
||||
|
||||
return view('livewire.my-service', [
|
||||
'services' => $query->orderBy('created_at', 'desc')->paginate(10)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Order;
|
||||
|
||||
use App\Models\Order as CustomerOrder;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithoutUrlPagination;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class OrderList extends Component
|
||||
{
|
||||
|
||||
use WithPagination, WithoutUrlPagination;
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.order.order-list', [
|
||||
'orders' => CustomerOrder::where('customer_id', customer()->id)
|
||||
->latest()
|
||||
->paginate(10)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\Ticket as CustomerSupport;
|
||||
use Illuminate\Http\Request;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class Ticket extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
public $search = '';
|
||||
|
||||
public function render(Request $request)
|
||||
{
|
||||
return view('livewire.ticket',[
|
||||
'tickets' => CustomerSupport::where('customer_id',$request->user('users')->id)
|
||||
->where('subject', 'like',"%$this->search%")
|
||||
->where('customer_id',auth('users')->id())
|
||||
->paginate(10)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Transaction as Trans;
|
||||
use Illuminate\Http\Request;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class Transaction extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public $search = '';
|
||||
|
||||
public function render(Request $request)
|
||||
{
|
||||
return view('livewire.transaction', [
|
||||
'transactions' => Trans::where(function ($query) use ($request) {
|
||||
$query->where('customer_id', $request->user('users')->id);
|
||||
if (! empty($this->search))
|
||||
{
|
||||
$query->where('trans','LIKE',"%$this->search%");
|
||||
}
|
||||
})
|
||||
->paginate(10)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Livewire\Component;
|
||||
|
||||
class UserSettings extends Component
|
||||
{
|
||||
public bool $email_marketing;
|
||||
public bool $receive_deposit;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$user = auth('users')->user();
|
||||
|
||||
// Gán giá trị bool từ database tinyInteger
|
||||
$this->email_marketing = (bool) $user->email_marketing;
|
||||
$this->receive_deposit = (bool) $user->receive_deposit;
|
||||
}
|
||||
|
||||
public function updated($propertyName)
|
||||
{
|
||||
$user = auth('users')->user();
|
||||
|
||||
// Cập nhật database với giá trị int 0 hoặc 1
|
||||
$user->update([
|
||||
$propertyName => $this->$propertyName ? 1 : 0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.user-settings', [
|
||||
'user' => auth('users')->user(), // Truyền user để hiển thị thông tin
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Repositories\Module\Datacenter\DatacenterRepositoryInterface;
|
||||
use App\Repositories\vCenter\vCenterRepositoryInterface;
|
||||
use Livewire\Component;
|
||||
|
||||
class VcenterDatacenterSelect extends Component
|
||||
{
|
||||
public $vcenter_id;
|
||||
public $datacenter_id;
|
||||
public $vcenters = [];
|
||||
public $datacenters = [];
|
||||
|
||||
protected $vCenterRepository;
|
||||
protected $datacenterRepository;
|
||||
|
||||
public function boot(
|
||||
vCenterRepositoryInterface $vCenterRepository,
|
||||
DatacenterRepositoryInterface $datacenterRepository
|
||||
)
|
||||
{
|
||||
$this->vCenterRepository = $vCenterRepository;
|
||||
$this->datacenterRepository = $datacenterRepository;
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->vcenters = $this->vCenterRepository->filter(['status' => 1], [], [], ['id', 'host']);
|
||||
}
|
||||
|
||||
public function updatedVcenterId($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$this->datacenters = $this->datacenterRepository->filter(
|
||||
['vcenter_id' => $value],
|
||||
[],
|
||||
[],
|
||||
['id', 'name']
|
||||
);
|
||||
} else {
|
||||
$this->datacenters = [];
|
||||
}
|
||||
$this->datacenter_id = null; // reset datacenter nếu vcenter đổi
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.vcenter-datacenter-select',
|
||||
[
|
||||
'vcenters' => $this->vcenters
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user