Merge pull request #48 from FahimAnzamDip/dev
Made the Price Customizable for Sales, Purchase
This commit is contained in:
commit
475f8cb7d1
|
@ -5,6 +5,7 @@ namespace App\Livewire;
|
|||
use Gloudemans\Shoppingcart\Facades\Cart;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Livewire\Component;
|
||||
use Modules\Product\Entities\Product;
|
||||
|
||||
class ProductCart extends Component
|
||||
{
|
||||
|
@ -19,8 +20,11 @@ class ProductCart extends Component
|
|||
public $check_quantity;
|
||||
public $discount_type;
|
||||
public $item_discount;
|
||||
public $unit_price;
|
||||
public $data;
|
||||
|
||||
private $product;
|
||||
|
||||
public function mount($cartInstance, $data = null) {
|
||||
$this->cart_instance = $cartInstance;
|
||||
|
||||
|
@ -39,6 +43,7 @@ class ProductCart extends Component
|
|||
foreach ($cart_items as $cart_item) {
|
||||
$this->check_quantity[$cart_item->id] = [$cart_item->options->stock];
|
||||
$this->quantity[$cart_item->id] = $cart_item->qty;
|
||||
$this->unit_price[$cart_item->id] = $cart_item->price;
|
||||
$this->discount_type[$cart_item->id] = $cart_item->options->product_discount_type;
|
||||
if ($cart_item->options->product_discount_type == 'fixed') {
|
||||
$this->item_discount[$cart_item->id] = $cart_item->options->product_discount;
|
||||
|
@ -52,6 +57,7 @@ class ProductCart extends Component
|
|||
$this->shipping = 0.00;
|
||||
$this->check_quantity = [];
|
||||
$this->quantity = [];
|
||||
$this->unit_price = [];
|
||||
$this->discount_type = [];
|
||||
$this->item_discount = [];
|
||||
}
|
||||
|
@ -78,6 +84,8 @@ class ProductCart extends Component
|
|||
return;
|
||||
}
|
||||
|
||||
$this->product = $product;
|
||||
|
||||
$cart->add([
|
||||
'id' => $product['id'],
|
||||
'name' => $product['product_name'],
|
||||
|
@ -174,10 +182,36 @@ class ProductCart extends Component
|
|||
session()->flash('discount_message' . $product_id, 'Discount added to the product!');
|
||||
}
|
||||
|
||||
public function calculate($product) {
|
||||
$product_price = $product['product_price'];
|
||||
if ($this->cart_instance == 'purchase' || $this->cart_instance == 'purchase_return') {
|
||||
$product_price = $product['product_cost'];
|
||||
public function updatePrice($row_id, $product_id) {
|
||||
$product = Product::findOrFail($product_id);
|
||||
|
||||
$cart_item = Cart::instance($this->cart_instance)->get($row_id);
|
||||
|
||||
Cart::instance($this->cart_instance)->update($row_id, ['price' => $this->unit_price[$product['id']]]);
|
||||
|
||||
Cart::instance($this->cart_instance)->update($row_id, [
|
||||
'options' => [
|
||||
'sub_total' => $this->calculate($product, $this->unit_price[$product['id']])['sub_total'],
|
||||
'code' => $cart_item->options->code,
|
||||
'stock' => $cart_item->options->stock,
|
||||
'unit' => $cart_item->options->unit,
|
||||
'product_tax' => $this->calculate($product, $this->unit_price[$product['id']])['product_tax'],
|
||||
'unit_price' => $this->calculate($product, $this->unit_price[$product['id']])['unit_price'],
|
||||
'product_discount' => $cart_item->options->product_discount,
|
||||
'product_discount_type' => $cart_item->options->product_discount_type,
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function calculate($product, $new_price = null) {
|
||||
if ($new_price) {
|
||||
$product_price = $new_price;
|
||||
} else {
|
||||
$this->unit_price[$product['id']] = $product['product_price'];
|
||||
if ($this->cart_instance == 'purchase' || $this->cart_instance == 'purchase_return') {
|
||||
$this->unit_price[$product['id']] = $product['product_cost'];
|
||||
}
|
||||
$product_price = $this->unit_price[$product['id']];
|
||||
}
|
||||
$price = 0;
|
||||
$unit_price = 0;
|
||||
|
|
|
@ -23,76 +23,100 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-center">
|
||||
<div class="{{ Route::has('register') ? 'col-md-8' : 'col-md-5' }}">
|
||||
<div class="col-md-5">
|
||||
@if(Session::has('account_deactivated'))
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ Session::get('account_deactivated') }}
|
||||
</div>
|
||||
@endif
|
||||
<div class="card-group">
|
||||
<div class="card p-4 border-0 shadow-sm">
|
||||
<div class="card-body">
|
||||
<form method="post" action="{{ url('/login') }}">
|
||||
@csrf
|
||||
<h1>Login</h1>
|
||||
<p class="text-muted">Sign In to your account</p>
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<div class="card p-4 border-0 shadow-sm">
|
||||
<div class="card-body">
|
||||
<form id="login" method="post" action="{{ url('/login') }}">
|
||||
@csrf
|
||||
<h1>Login</h1>
|
||||
<p class="text-muted">Sign In to your account</p>
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">
|
||||
<i class="bi bi-person"></i>
|
||||
</span>
|
||||
</div>
|
||||
<input type="email" class="form-control @error('email') is-invalid @enderror"
|
||||
name="email" value="{{ old('email') }}"
|
||||
placeholder="Email">
|
||||
@error('email')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="input-group mb-4">
|
||||
<div class="input-group-prepend">
|
||||
<input id="email" type="email" class="form-control @error('email') is-invalid @enderror"
|
||||
name="email" value="{{ old('email') }}"
|
||||
placeholder="Email">
|
||||
@error('email')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="input-group mb-4">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">
|
||||
<i class="bi bi-lock"></i>
|
||||
</span>
|
||||
</div>
|
||||
<input type="password"
|
||||
class="form-control @error('password') is-invalid @enderror"
|
||||
placeholder="Password" name="password">
|
||||
@error('password')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<button class="btn btn-primary px-4" type="submit">Login</button>
|
||||
</div>
|
||||
<div class="col-8 text-right">
|
||||
<a class="btn btn-link px-0" href="{{ route('password.request') }}">
|
||||
Forgot password?
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@if(Route::has('register'))
|
||||
<div class="card text-white bg-primary py-5 d-md-down-none" style="width:44%">
|
||||
<div class="card-body text-center">
|
||||
<div>
|
||||
<h2>Sign up</h2>
|
||||
<p>Sign in to start your session</p>
|
||||
<a class="btn btn-lg btn-outline-light mt-3" href="{{ route('register') }}">Register Now!</a>
|
||||
<input id="password" type="password"
|
||||
class="form-control @error('password') is-invalid @enderror"
|
||||
placeholder="Password" name="password">
|
||||
@error('password')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<button id="submit" class="btn btn-primary px-4 d-flex align-items-center"
|
||||
type="submit">
|
||||
Login
|
||||
<div id="spinner" class="spinner-border text-info" role="status"
|
||||
style="height: 20px;width: 20px;margin-left: 5px;display: none;">
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-8 text-right">
|
||||
<a class="btn btn-link px-0" href="{{ route('password.request') }}">
|
||||
Forgot password?
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<p class="text-center mt-5 lead">
|
||||
Developed By
|
||||
<a href="https://fahimanzam.netlify.app" class="font-weight-bold text-primary">Fahim Anzam Dip</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CoreUI -->
|
||||
<script src="{{ mix('js/app.js') }}" defer></script>
|
||||
<script>
|
||||
let login = document.getElementById('login');
|
||||
let submit = document.getElementById('submit');
|
||||
let email = document.getElementById('email');
|
||||
let password = document.getElementById('password');
|
||||
let spinner = document.getElementById('spinner')
|
||||
|
||||
login.addEventListener('submit', (e) => {
|
||||
submit.disabled = true;
|
||||
email.readonly = true;
|
||||
password.readonly = true;
|
||||
|
||||
spinner.style.display = 'block';
|
||||
|
||||
login.submit();
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
submit.disabled = false;
|
||||
email.readonly = false;
|
||||
password.readonly = false;
|
||||
|
||||
spinner.style.display = 'none';
|
||||
}, 3000);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<div class="input-group d-flex justify-content-center">
|
||||
<input wire:model="unit_price.{{ $cart_item->id }}" style="min-width: 40px;max-width: 90px;" type="text" class="form-control" min="0">
|
||||
<div class="input-group-append">
|
||||
<button @click="open{{ $cart_item->id }} = !open{{ $cart_item->id }}" type="button" wire:click="updatePrice('{{ $cart_item->rowId }}', {{ $cart_item->id }})" class="btn btn-info">
|
||||
<i class="bi bi-check"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
|
@ -1,10 +1,8 @@
|
|||
<form wire:submit="updateQuantity('{{ $cart_item->rowId }}', '{{ $cart_item->id }}')">
|
||||
<div class="input-group">
|
||||
<input wire:model="quantity.{{ $cart_item->id }}" style="min-width: 40px;max-width: 90px;" type="number" class="form-control" value="{{ $cart_item->qty }}" min="1">
|
||||
<div class="input-group-append">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-check"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="input-group d-flex justify-content-center">
|
||||
<input wire:model="quantity.{{ $cart_item->id }}" style="min-width: 40px;max-width: 90px;" type="number" class="form-control" value="{{ $cart_item->qty }}" min="1">
|
||||
<div class="input-group-append">
|
||||
<button type="button" wire:click="updateQuantity('{{ $cart_item->rowId }}', {{ $cart_item->id }})" class="btn btn-info">
|
||||
<i class="bi bi-check"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -20,13 +20,13 @@
|
|||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th class="align-middle">Product</th>
|
||||
<th class="align-middle">Net Unit Price</th>
|
||||
<th class="align-middle">Stock</th>
|
||||
<th class="align-middle">Quantity</th>
|
||||
<th class="align-middle">Discount</th>
|
||||
<th class="align-middle">Tax</th>
|
||||
<th class="align-middle">Sub Total</th>
|
||||
<th class="align-middle">Action</th>
|
||||
<th class="align-middle text-center">Net Unit Price</th>
|
||||
<th class="align-middle text-center">Stock</th>
|
||||
<th class="align-middle text-center">Quantity</th>
|
||||
<th class="align-middle text-center">Discount</th>
|
||||
<th class="align-middle text-center">Tax</th>
|
||||
<th class="align-middle text-center">Sub Total</th>
|
||||
<th class="align-middle text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -41,25 +41,31 @@
|
|||
@include('livewire.includes.product-cart-modal')
|
||||
</td>
|
||||
|
||||
<td class="align-middle">{{ format_currency($cart_item->options->unit_price) }}</td>
|
||||
<td x-data="{ open{{ $cart_item->id }}: false }" class="align-middle text-center">
|
||||
<span x-show="!open{{ $cart_item->id }}" @click="open{{ $cart_item->id }} = !open{{ $cart_item->id }}">{{ format_currency($cart_item->price) }}</span>
|
||||
|
||||
<td class="align-middle text-center">
|
||||
<div x-show="open{{ $cart_item->id }}">
|
||||
@include('livewire.includes.product-cart-price')
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="align-middle text-center text-center">
|
||||
<span class="badge badge-info">{{ $cart_item->options->stock . ' ' . $cart_item->options->unit }}</span>
|
||||
</td>
|
||||
|
||||
<td class="align-middle">
|
||||
<td class="align-middle text-center">
|
||||
@include('livewire.includes.product-cart-quantity')
|
||||
</td>
|
||||
|
||||
<td class="align-middle">
|
||||
<td class="align-middle text-center">
|
||||
{{ format_currency($cart_item->options->product_discount) }}
|
||||
</td>
|
||||
|
||||
<td class="align-middle">
|
||||
<td class="align-middle text-center">
|
||||
{{ format_currency($cart_item->options->product_tax) }}
|
||||
</td>
|
||||
|
||||
<td class="align-middle">
|
||||
<td class="align-middle text-center">
|
||||
{{ format_currency($cart_item->options->sub_total) }}
|
||||
</td>
|
||||
|
||||
|
|
Loading…
Reference in New Issue