14 april
This commit is contained in:
parent
6b66ac8bd7
commit
0e8e9b43a1
|
@ -19,15 +19,11 @@ class CreateSalesTable extends Migration
|
|||
$table->string('reference');
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
$table->string('customer_name');
|
||||
$table->integer('tax_percentage')->default(0);
|
||||
$table->integer('tax_amount')->default(0);
|
||||
$table->integer('discount_percentage')->default(0);
|
||||
$table->integer('discount_amount')->default(0);
|
||||
$table->integer('shipping_amount')->default(0);
|
||||
$table->integer('total_amount');
|
||||
$table->integer('paid_amount');
|
||||
$table->integer('due_amount');
|
||||
$table->string('status');
|
||||
$table->string('payment_status');
|
||||
$table->string('payment_method');
|
||||
$table->text('note')->nullable();
|
||||
|
|
|
@ -9,7 +9,20 @@ class Sale extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
protected $fillable = [
|
||||
'date',
|
||||
'reference',
|
||||
'customer_id',
|
||||
'customer_name',
|
||||
'discount_percentage',
|
||||
'discount_amount',
|
||||
'total_amount',
|
||||
'paid_amount',
|
||||
'due_amount',
|
||||
'payment_status',
|
||||
'payment_method',
|
||||
'note'
|
||||
];
|
||||
|
||||
public function saleDetails() {
|
||||
return $this->hasMany(SaleDetails::class, 'sale_id', 'id');
|
||||
|
@ -32,10 +45,6 @@ class Sale extends Model
|
|||
return $query->where('status', 'Completed');
|
||||
}
|
||||
|
||||
public function getShippingAmountAttribute($value) {
|
||||
return $value / 100;
|
||||
}
|
||||
|
||||
public function getPaidAmountAttribute($value) {
|
||||
return $value / 100;
|
||||
}
|
||||
|
@ -48,10 +57,6 @@ class Sale extends Model
|
|||
return $value / 100;
|
||||
}
|
||||
|
||||
public function getTaxAmountAttribute($value) {
|
||||
return $value / 100;
|
||||
}
|
||||
|
||||
public function getDiscountAmountAttribute($value) {
|
||||
return $value / 100;
|
||||
}
|
||||
|
|
|
@ -44,14 +44,13 @@ class PosController extends Controller
|
|||
'date' => now()->format('Y-m-d'),
|
||||
'reference' => 'PSL',
|
||||
'customer_id' => $request->customer_id,
|
||||
'customer_name' => Customer::findOrFail($request->customer_id)->customer_name,
|
||||
'customer_name' => $request->customer_id ? Customer::findOrFail($request->customer_id)->customer_name : 'Walk-in Customer',
|
||||
'tax_percentage' => $request->tax_percentage,
|
||||
'discount_percentage' => $request->discount_percentage,
|
||||
'shipping_amount' => $request->shipping_amount * 100,
|
||||
'paid_amount' => $request->paid_amount * 100,
|
||||
'total_amount' => $request->total_amount * 100,
|
||||
'due_amount' => $due_amount * 100,
|
||||
'status' => 'Completed',
|
||||
'payment_status' => $payment_status,
|
||||
'payment_method' => $request->payment_method,
|
||||
'note' => $request->note,
|
||||
|
|
|
@ -48,6 +48,7 @@ class SaleController extends Controller
|
|||
|
||||
$sale = Sale::create([
|
||||
'date' => $request->date,
|
||||
'reference' => $request->reference,
|
||||
'customer_id' => $request->customer_id,
|
||||
'customer_name' => Customer::findOrFail($request->customer_id)->customer_name,
|
||||
'tax_percentage' => $request->tax_percentage,
|
||||
|
@ -56,7 +57,6 @@ class SaleController extends Controller
|
|||
'paid_amount' => $request->paid_amount * 100,
|
||||
'total_amount' => $request->total_amount * 100,
|
||||
'due_amount' => $due_amount * 100,
|
||||
'status' => $request->status,
|
||||
'payment_status' => $payment_status,
|
||||
'payment_method' => $request->payment_method,
|
||||
'note' => $request->note,
|
||||
|
@ -181,7 +181,6 @@ class SaleController extends Controller
|
|||
'paid_amount' => $request->paid_amount * 100,
|
||||
'total_amount' => $request->total_amount * 100,
|
||||
'due_amount' => $due_amount * 100,
|
||||
'status' => $request->status,
|
||||
'payment_status' => $payment_status,
|
||||
'payment_method' => $request->payment_method,
|
||||
'note' => $request->note,
|
||||
|
|
|
@ -59,17 +59,6 @@
|
|||
|
||||
<div class="form-row">
|
||||
<div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="status">Status <span class="text-danger">*</span></label>
|
||||
<select class="form-control" name="status" id="status" required>
|
||||
<option value="Pending">Pending</option>
|
||||
<option value="Shipped">Shipped</option>
|
||||
<option value="Completed">Completed</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="from-group">
|
||||
<div class="form-group">
|
||||
<label for="payment_method">Payment Method <span class="text-danger">*</span></label>
|
||||
<select class="form-control" name="payment_method" id="payment_method" required>
|
||||
|
@ -81,7 +70,6 @@
|
|||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="paid_amount">Amount Received <span class="text-danger">*</span></label>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<div class="form-group">
|
||||
<label for="discount_percentage">Discount Percentage</label>
|
||||
<input type="number" class="form-control" id="discount_percentage" name="discount_percentage" min="0" max="100" value="0">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="discount_amount">Discount Amount</label>
|
||||
<input type="number" class="form-control" id="discount_amount" name="discount_amount" min="0" value="0" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="total_amount">Total Amount</label>
|
||||
<input type="number" class="form-control" id="total_amount" name="total_amount" min="0" value="0" readonly>
|
|
@ -0,0 +1,11 @@
|
|||
<div class="form-group">
|
||||
<label for="discount_percentage">Discount Percentage</label>
|
||||
<input type="number" class="form-control" id="discount_percentage" name="discount_percentage" min="0" max="100" value="{{ $sale->discount_percentage }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="discount_amount">Discount Amount</label>
|
||||
<input type="number" class="form-control" id="discount_amount" name="discount_amount" min="0" value="{{ $sale->discount_amount }}" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="total_amount">Total Amount</label>
|
||||
<input type="number" class="form-control" id="total_amount" name="total_amount" min="0" value="{{ $sale->total_amount }}" readonly>
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
|
||||
class PriceHelper
|
||||
{
|
||||
public static function formatPrice($price)
|
||||
{
|
||||
$settings = SettingsHelper::settings();
|
||||
return $settings->currency->symbol . ' ' . number_format($price, 0, $settings->currency->decimal_separator, $settings->currency->thousand_separator) . ',-';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Modules\Setting\Entities\Setting;
|
||||
|
||||
class SettingsHelper
|
||||
{
|
||||
public static function settings()
|
||||
{
|
||||
return Setting::first();
|
||||
}
|
||||
}
|
|
@ -1,34 +1,19 @@
|
|||
<?php
|
||||
|
||||
if (!function_exists('settings')) {
|
||||
function settings() {
|
||||
$settings = cache()->remember('settings', 24*60, function () {
|
||||
return \Modules\Setting\Entities\Setting::firstOrFail();
|
||||
});
|
||||
use Modules\Setting\Entities\Setting;
|
||||
|
||||
return $settings;
|
||||
if (!function_exists('settings')) {
|
||||
function settings()
|
||||
{
|
||||
return Setting::first();
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('format_currency')) {
|
||||
function format_currency($value, $format = true) {
|
||||
if (!$format) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
function format_currency($price)
|
||||
{
|
||||
$settings = settings();
|
||||
$position = $settings->default_currency_position;
|
||||
$symbol = $settings->currency->symbol;
|
||||
$decimal_separator = $settings->currency->decimal_separator;
|
||||
$thousand_separator = $settings->currency->thousand_separator;
|
||||
|
||||
if ($position == 'prefix') {
|
||||
$formatted_value = $symbol . number_format((float) $value, 2, $decimal_separator, $thousand_separator);
|
||||
} else {
|
||||
$formatted_value = number_format((float) $value, 2, $decimal_separator, $thousand_separator) . $symbol;
|
||||
}
|
||||
|
||||
return $formatted_value;
|
||||
return $settings->currency->symbol . ' ' . number_format($price, 0, $settings->currency->decimal_separator, $settings->currency->thousand_separator) . ',-';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,11 +49,7 @@ class Checkout extends Component
|
|||
}
|
||||
|
||||
public function proceed() {
|
||||
if ($this->customer_id != null) {
|
||||
$this->dispatch('showCheckoutModal');
|
||||
} else {
|
||||
session()->flash('message', 'Please Select Customer!');
|
||||
}
|
||||
}
|
||||
|
||||
public function calculateTotal() {
|
||||
|
|
|
@ -14,7 +14,7 @@ class ProductCart extends Component
|
|||
|
||||
public $cart_instance;
|
||||
public $global_discount;
|
||||
public $global_tax;
|
||||
//public $global_tax;
|
||||
public $shipping;
|
||||
public $quantity;
|
||||
public $check_quantity;
|
||||
|
@ -32,10 +32,10 @@ class ProductCart extends Component
|
|||
$this->data = $data;
|
||||
|
||||
$this->global_discount = $data->discount_percentage;
|
||||
$this->global_tax = $data->tax_percentage;
|
||||
//$this->global_tax = $data->tax_percentage;
|
||||
$this->shipping = $data->shipping_amount;
|
||||
|
||||
$this->updatedGlobalTax();
|
||||
//$this->updatedGlobalTax();
|
||||
$this->updatedGlobalDiscount();
|
||||
|
||||
$cart_items = Cart::instance($this->cart_instance)->content();
|
||||
|
@ -53,7 +53,7 @@ class ProductCart extends Component
|
|||
}
|
||||
} else {
|
||||
$this->global_discount = 0;
|
||||
$this->global_tax = 0;
|
||||
//$this->global_tax = 0;
|
||||
$this->shipping = 0.00;
|
||||
$this->check_quantity = [];
|
||||
$this->quantity = [];
|
||||
|
@ -99,7 +99,7 @@ class ProductCart extends Component
|
|||
'code' => $product['product_code'],
|
||||
'stock' => $product['product_quantity'],
|
||||
'unit' => $product['product_unit'],
|
||||
'product_tax' => $this->calculate($product)['product_tax'],
|
||||
//'product_tax' => $this->calculate($product)['product_tax'],
|
||||
'unit_price' => $this->calculate($product)['unit_price']
|
||||
]
|
||||
]);
|
||||
|
@ -114,9 +114,9 @@ class ProductCart extends Component
|
|||
Cart::instance($this->cart_instance)->remove($row_id);
|
||||
}
|
||||
|
||||
public function updatedGlobalTax() {
|
||||
Cart::instance($this->cart_instance)->setGlobalTax((integer)$this->global_tax);
|
||||
}
|
||||
// public function updatedGlobalTax() {
|
||||
// Cart::instance($this->cart_instance)->setGlobalTax((integer)$this->global_tax);
|
||||
// }
|
||||
|
||||
public function updatedGlobalDiscount() {
|
||||
Cart::instance($this->cart_instance)->setGlobalDiscount((integer)$this->global_discount);
|
||||
|
@ -140,7 +140,7 @@ class ProductCart extends Component
|
|||
'code' => $cart_item->options->code,
|
||||
'stock' => $cart_item->options->stock,
|
||||
'unit' => $cart_item->options->unit,
|
||||
'product_tax' => $cart_item->options->product_tax,
|
||||
//'product_tax' => $cart_item->options->product_tax,
|
||||
'unit_price' => $cart_item->options->unit_price,
|
||||
'product_discount' => $cart_item->options->product_discount,
|
||||
'product_discount_type' => $cart_item->options->product_discount_type,
|
||||
|
@ -195,7 +195,7 @@ class ProductCart extends Component
|
|||
'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'],
|
||||
//'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,
|
||||
|
@ -217,34 +217,17 @@ class ProductCart extends Component
|
|||
// Check if wholesale price should be applied
|
||||
if (isset($product['min_quantity_for_wholesale']) &&
|
||||
isset($product['wholesale_discount_percentage']) &&
|
||||
isset($this->quantity[$product['id']]) &&
|
||||
$this->quantity[$product['id']] >= $product['min_quantity_for_wholesale']) {
|
||||
$discount = $product['wholesale_discount_percentage'] / 100;
|
||||
$product_price = $product_price * (1 - $discount);
|
||||
}
|
||||
|
||||
$price = 0;
|
||||
$unit_price = 0;
|
||||
$product_tax = 0;
|
||||
$sub_total = 0;
|
||||
|
||||
if ($product['product_tax_type'] == 1) {
|
||||
$price = $product_price + ($product_price * ($product['product_order_tax'] / 100));
|
||||
$unit_price = $product_price;
|
||||
$product_tax = $product_price * ($product['product_order_tax'] / 100);
|
||||
$sub_total = $product_price + ($product_price * ($product['product_order_tax'] / 100));
|
||||
} elseif ($product['product_tax_type'] == 2) {
|
||||
$price = $product_price;
|
||||
$unit_price = $product_price - ($product_price * ($product['product_order_tax'] / 100));
|
||||
$product_tax = $product_price * ($product['product_order_tax'] / 100);
|
||||
$sub_total = $product_price;
|
||||
} else {
|
||||
$price = $product_price;
|
||||
$unit_price = $product_price;
|
||||
$product_tax = 0.00;
|
||||
$sub_total = $product_price;
|
||||
}
|
||||
|
||||
return ['price' => $price, 'unit_price' => $unit_price, 'product_tax' => $product_tax, 'sub_total' => $sub_total];
|
||||
return ['price' => $price, 'unit_price' => $unit_price, 'sub_total' => $sub_total];
|
||||
}
|
||||
|
||||
public function updateCartOptions($row_id, $product_id, $cart_item, $discount_amount) {
|
||||
|
@ -253,7 +236,7 @@ class ProductCart extends Component
|
|||
'code' => $cart_item->options->code,
|
||||
'stock' => $cart_item->options->stock,
|
||||
'unit' => $cart_item->options->unit,
|
||||
'product_tax' => $cart_item->options->product_tax,
|
||||
//'product_tax' => $cart_item->options->product_tax,
|
||||
'unit_price' => $cart_item->options->unit_price,
|
||||
'product_discount' => $discount_amount,
|
||||
'product_discount_type' => $this->discount_type[$product_id],
|
||||
|
|
|
@ -85,26 +85,26 @@
|
|||
<div class="col-md-12">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
{{-- <tr>
|
||||
<th>Order Tax ({{ $global_tax }}%)</th>
|
||||
<td>(+) {{ format_currency(Cart::instance($cart_instance)->tax()) }}</td>
|
||||
</tr>
|
||||
</tr> --}}
|
||||
<tr>
|
||||
<th>Discount ({{ $global_discount }}%)</th>
|
||||
<td>(-) {{ format_currency(Cart::instance($cart_instance)->discount()) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
{{-- <tr>
|
||||
<th>Shipping</th>
|
||||
<input type="hidden" value="{{ $shipping }}" name="shipping_amount">
|
||||
<td>(+) {{ format_currency($shipping) }}</td>
|
||||
</tr>
|
||||
</tr> --}}
|
||||
<tr class="text-primary">
|
||||
<th>Grand Total</th>
|
||||
@php
|
||||
$total_with_shipping = Cart::instance($cart_instance)->total() + (float) $shipping
|
||||
$total_with_discount = Cart::instance($cart_instance)->total()
|
||||
@endphp
|
||||
<th>
|
||||
(=) {{ format_currency($total_with_shipping) }}
|
||||
(=) {{ format_currency($total_with_discount) }}
|
||||
</th>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -113,24 +113,24 @@
|
|||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="col-lg-4">
|
||||
{{-- <div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="tax_percentage">Order Tax (%)</label>
|
||||
<input wire:model.blur="global_tax" type="number" class="form-control" min="0" max="100" value="{{ $global_tax }}" required>
|
||||
</div>
|
||||
</div>
|
||||
</div> --}}
|
||||
<div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="discount_percentage">Discount (%)</label>
|
||||
<input wire:model.blur="global_discount" type="number" class="form-control" min="0" max="100" value="{{ $global_discount }}" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
{{-- <div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="shipping_amount">Shipping</label>
|
||||
<input wire:model.blur="shipping" type="number" class="form-control" min="0" value="0" required step="0.01">
|
||||
</div>
|
||||
</div>
|
||||
</div> --}}
|
||||
</div>
|
||||
|
||||
<div class="form-group d-flex justify-content-center flex-wrap mb-0">
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
<div class="row">
|
||||
<div class="col-lg-7">
|
||||
<input type="hidden" value="{{ $customer_id }}" name="customer_id">
|
||||
<input type="hidden" value="{{ $global_tax }}" name="tax_percentage">
|
||||
{{-- <input type="hidden" value="{{ $global_tax }}" name="tax_percentage"> --}}
|
||||
<input type="hidden" value="{{ $global_discount }}" name="discount_percentage">
|
||||
<input type="hidden" value="{{ $shipping }}" name="shipping_amount">
|
||||
{{-- <input type="hidden" value="{{ $shipping }}" name="shipping_amount"> --}}
|
||||
<div class="form-row">
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
|
@ -68,26 +68,26 @@
|
|||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
{{-- <tr>
|
||||
<th>Order Tax ({{ $global_tax }}%)</th>
|
||||
<td>(+) {{ format_currency(Cart::instance($cart_instance)->tax()) }}</td>
|
||||
</tr>
|
||||
</tr> --}}
|
||||
<tr>
|
||||
<th>Discount ({{ $global_discount }}%)</th>
|
||||
<td>(-) {{ format_currency(Cart::instance($cart_instance)->discount()) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
{{-- <tr>
|
||||
<th>Shipping</th>
|
||||
<input type="hidden" value="{{ $shipping }}" name="shipping_amount">
|
||||
<td>(+) {{ format_currency($shipping) }}</td>
|
||||
</tr>
|
||||
</tr> --}}
|
||||
<tr class="text-primary">
|
||||
<th>Grand Total</th>
|
||||
@php
|
||||
$total_with_shipping = Cart::instance($cart_instance)->total() + (float) $shipping
|
||||
$total_with_discount = Cart::instance($cart_instance)->total()
|
||||
@endphp
|
||||
<th>
|
||||
(=) {{ format_currency($total_with_shipping) }}
|
||||
(=) {{ format_currency($total_with_discount) }}
|
||||
</th>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -94,53 +94,54 @@
|
|||
<div class="col-md-4">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
{{-- <tr>
|
||||
<th>Tax ({{ $global_tax }}%)</th>
|
||||
<td>(+) {{ format_currency(Cart::instance($cart_instance)->tax()) }}</td>
|
||||
</tr>
|
||||
</tr> --}}
|
||||
<tr>
|
||||
<th>Discount ({{ $global_discount }}%)</th>
|
||||
<td>(-) {{ format_currency(Cart::instance($cart_instance)->discount()) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
{{-- <tr>
|
||||
<th>Shipping</th>
|
||||
<input type="hidden" value="{{ $shipping }}" name="shipping_amount">
|
||||
<td>(+) {{ format_currency($shipping) }}</td>
|
||||
</tr>
|
||||
</tr> --}}
|
||||
<tr>
|
||||
<th>Grand Total</th>
|
||||
@php
|
||||
$total_with_shipping = Cart::instance($cart_instance)->total() + (float) $shipping
|
||||
@endphp
|
||||
<th>
|
||||
(=) {{ format_currency($total_with_shipping) }}
|
||||
</th>
|
||||
$total_with_discount = Cart::instance($cart_instance)->total()
|
||||
@endphp
|
||||
<th>
|
||||
(=) {{ format_currency($total_with_discount) }}
|
||||
</th>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="total_amount" value="{{ $total_with_shipping }}">
|
||||
{{-- <input type="hidden" name="total_amount" value="{{ $total_with_shipping }}"> --}}
|
||||
|
||||
<div class="form-row">
|
||||
<div class="col-lg-4">
|
||||
{{-- <div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="tax_percentage">Tax (%)</label>
|
||||
<input wire:model.blur="global_tax" type="number" class="form-control" name="tax_percentage" min="0" max="100" value="{{ $global_tax }}" required>
|
||||
</div>
|
||||
</div>
|
||||
</div> --}}
|
||||
<div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="discount_percentage">Discount (%)</label>
|
||||
<input wire:model.blur="global_discount" type="number" class="form-control" name="discount_percentage" min="0" max="100" value="{{ $global_discount }}" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
{{-- <div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="shipping_amount">Shipping</label>
|
||||
<input wire:model.blur="shipping" type="number" class="form-control" name="shipping_amount" min="0" value="0" required step="0.01">
|
||||
</div>
|
||||
</div>
|
||||
</div> --}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue