From 0e8e9b43a1b5a40279d2370375010a9b46cc4af3 Mon Sep 17 00:00:00 2001 From: adeliaala Date: Fri, 18 Apr 2025 18:49:23 +0700 Subject: [PATCH] 14 april --- .../2021_07_31_201003_create_sales_table.php | 4 -- Modules/Sale/Entities/Sale.php | 23 +++++---- .../Sale/Http/Controllers/PosController.php | 3 +- .../Sale/Http/Controllers/SaleController.php | 3 +- Modules/Sale/Resources/views/create.blade.php | 26 +++------- .../Resources/views/sales/create.blade.php | 11 +++++ .../Sale/Resources/views/sales/edit.blade.php | 11 +++++ app/Helpers/PriceHelper.php | 14 ++++++ app/Helpers/SettingsHelper.php | 13 +++++ app/Helpers/helpers.php | 31 +++--------- app/Livewire/Pos/Checkout.php | 6 +-- app/Livewire/ProductCart.php | 49 ++++++------------- .../views/livewire/pos/checkout.blade.php | 26 +++++----- .../pos/includes/checkout-modal.blade.php | 20 ++++---- .../views/livewire/product-cart.blade.php | 29 +++++------ 15 files changed, 135 insertions(+), 134 deletions(-) create mode 100644 Modules/Sale/Resources/views/sales/create.blade.php create mode 100644 Modules/Sale/Resources/views/sales/edit.blade.php create mode 100644 app/Helpers/PriceHelper.php create mode 100644 app/Helpers/SettingsHelper.php diff --git a/Modules/Sale/Database/Migrations/2021_07_31_201003_create_sales_table.php b/Modules/Sale/Database/Migrations/2021_07_31_201003_create_sales_table.php index 8b9bbf4c..d5a0e82b 100644 --- a/Modules/Sale/Database/Migrations/2021_07_31_201003_create_sales_table.php +++ b/Modules/Sale/Database/Migrations/2021_07_31_201003_create_sales_table.php @@ -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(); diff --git a/Modules/Sale/Entities/Sale.php b/Modules/Sale/Entities/Sale.php index 9998fb8a..4cbb3539 100644 --- a/Modules/Sale/Entities/Sale.php +++ b/Modules/Sale/Entities/Sale.php @@ -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; } diff --git a/Modules/Sale/Http/Controllers/PosController.php b/Modules/Sale/Http/Controllers/PosController.php index 4b4ede75..d144cd0e 100644 --- a/Modules/Sale/Http/Controllers/PosController.php +++ b/Modules/Sale/Http/Controllers/PosController.php @@ -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, diff --git a/Modules/Sale/Http/Controllers/SaleController.php b/Modules/Sale/Http/Controllers/SaleController.php index 20aef6fd..27292632 100644 --- a/Modules/Sale/Http/Controllers/SaleController.php +++ b/Modules/Sale/Http/Controllers/SaleController.php @@ -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, diff --git a/Modules/Sale/Resources/views/create.blade.php b/Modules/Sale/Resources/views/create.blade.php index 740c8aed..9d256b2d 100644 --- a/Modules/Sale/Resources/views/create.blade.php +++ b/Modules/Sale/Resources/views/create.blade.php @@ -60,28 +60,16 @@
- - + + + + +
-
-
-
- - -
-
-
diff --git a/Modules/Sale/Resources/views/sales/create.blade.php b/Modules/Sale/Resources/views/sales/create.blade.php new file mode 100644 index 00000000..5ba1439a --- /dev/null +++ b/Modules/Sale/Resources/views/sales/create.blade.php @@ -0,0 +1,11 @@ +
+ + +
+
+ + +
+
+ + \ No newline at end of file diff --git a/Modules/Sale/Resources/views/sales/edit.blade.php b/Modules/Sale/Resources/views/sales/edit.blade.php new file mode 100644 index 00000000..8390c5bf --- /dev/null +++ b/Modules/Sale/Resources/views/sales/edit.blade.php @@ -0,0 +1,11 @@ +
+ + +
+
+ + +
+
+ + \ No newline at end of file diff --git a/app/Helpers/PriceHelper.php b/app/Helpers/PriceHelper.php new file mode 100644 index 00000000..7c780aeb --- /dev/null +++ b/app/Helpers/PriceHelper.php @@ -0,0 +1,14 @@ +currency->symbol . ' ' . number_format($price, 0, $settings->currency->decimal_separator, $settings->currency->thousand_separator) . ',-'; + } +} \ No newline at end of file diff --git a/app/Helpers/SettingsHelper.php b/app/Helpers/SettingsHelper.php new file mode 100644 index 00000000..fbec2202 --- /dev/null +++ b/app/Helpers/SettingsHelper.php @@ -0,0 +1,13 @@ +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) . ',-'; } } diff --git a/app/Livewire/Pos/Checkout.php b/app/Livewire/Pos/Checkout.php index fa606ab1..03142f15 100644 --- a/app/Livewire/Pos/Checkout.php +++ b/app/Livewire/Pos/Checkout.php @@ -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!'); - } + $this->dispatch('showCheckoutModal'); } public function calculateTotal() { diff --git a/app/Livewire/ProductCart.php b/app/Livewire/ProductCart.php index 6ddc14ab..be85c766 100644 --- a/app/Livewire/ProductCart.php +++ b/app/Livewire/ProductCart.php @@ -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; + $price = $product_price; + $unit_price = $product_price; + $sub_total = $product_price; - 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], diff --git a/resources/views/livewire/pos/checkout.blade.php b/resources/views/livewire/pos/checkout.blade.php index 65fe43ff..b7f160ae 100644 --- a/resources/views/livewire/pos/checkout.blade.php +++ b/resources/views/livewire/pos/checkout.blade.php @@ -85,27 +85,27 @@
- + {{-- - + --}} - + {{-- - + --}} @php - $total_with_shipping = Cart::instance($cart_instance)->total() + (float) $shipping - @endphp - + $total_with_discount = Cart::instance($cart_instance)->total() + @endphp +
Order Tax ({{ $global_tax }}%) (+) {{ format_currency(Cart::instance($cart_instance)->tax()) }}
Discount ({{ $global_discount }}%) (-) {{ format_currency(Cart::instance($cart_instance)->discount()) }}
Shipping (+) {{ format_currency($shipping) }}
Grand Total - (=) {{ format_currency($total_with_shipping) }} - + (=) {{ format_currency($total_with_discount) }} +
@@ -113,24 +113,24 @@
-
+ {{--
-
+
--}}
-
+ {{--
-
+
--}}
diff --git a/resources/views/livewire/pos/includes/checkout-modal.blade.php b/resources/views/livewire/pos/includes/checkout-modal.blade.php index 40e0895d..bb392cb3 100644 --- a/resources/views/livewire/pos/includes/checkout-modal.blade.php +++ b/resources/views/livewire/pos/includes/checkout-modal.blade.php @@ -25,9 +25,9 @@
- + {{-- --}} - + {{-- --}}
@@ -68,26 +68,26 @@ - - Order Tax ({{ $global_tax }}%) - (+) {{ format_currency(Cart::instance($cart_instance)->tax()) }} - + {{-- + Order Tax ({{ $global_tax }}%) + (+) {{ format_currency(Cart::instance($cart_instance)->tax()) }} + --}} Discount ({{ $global_discount }}%) (-) {{ format_currency(Cart::instance($cart_instance)->discount()) }} - + {{-- Shipping (+) {{ format_currency($shipping) }} - + --}} Grand Total @php - $total_with_shipping = Cart::instance($cart_instance)->total() + (float) $shipping + $total_with_discount = Cart::instance($cart_instance)->total() @endphp - (=) {{ format_currency($total_with_shipping) }} + (=) {{ format_currency($total_with_discount) }} diff --git a/resources/views/livewire/product-cart.blade.php b/resources/views/livewire/product-cart.blade.php index 8e124e5d..c543d344 100644 --- a/resources/views/livewire/product-cart.blade.php +++ b/resources/views/livewire/product-cart.blade.php @@ -94,53 +94,54 @@
- + {{-- - + --}} - + {{-- - + --}} @php - $total_with_shipping = Cart::instance($cart_instance)->total() + (float) $shipping - @endphp - + $total_with_discount = Cart::instance($cart_instance)->total() +@endphp + +
Tax ({{ $global_tax }}%) (+) {{ format_currency(Cart::instance($cart_instance)->tax()) }}
Discount ({{ $global_discount }}%) (-) {{ format_currency(Cart::instance($cart_instance)->discount()) }}
Shipping (+) {{ format_currency($shipping) }}
Grand Total - (=) {{ format_currency($total_with_shipping) }} - + (=) {{ format_currency($total_with_discount) }} +
- + {{-- --}}
-
+ {{--
-
+
--}}
-
+ {{--
-
+
--}}