Skip to content

Commit 3f3074a

Browse files
committed
Update
- Fixed: Migration For MultiStore - Removed: Unecessary code
1 parent 89b8e95 commit 3f3074a

File tree

19 files changed

+101
-286840
lines changed

19 files changed

+101
-286840
lines changed

app/Classes/Currency.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
<?php
22
namespace App\Classes;
33

4+
use App\Services\CurrencyService;
5+
46
class Currency
57
{
68
public static function define( $amount )
79
{
810
return ns()->currency->define( $amount );
911
}
1012

13+
/**
14+
* Will return a new intance using
15+
* the default value.
16+
*
17+
* @param float $amount
18+
* @return CurrencyService
19+
*/
20+
public static function fresh( $amount ): CurrencyService
21+
{
22+
return ns()->currency->fresh( $amount );
23+
}
24+
1125
public static function raw( $amount )
1226
{
1327
return ns()->currency->getRaw( $amount );

app/Services/CurrencyService.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,38 @@ public function __construct( $value, $config = [])
3838
$this->thousand_separator = $thousand_separator ?? self::$_thousand_separator;
3939
}
4040

41+
/**
42+
* Will intanciate a new instance
43+
* using the default value
44+
*
45+
* @param int|float $value
46+
* @return CurrencyService
47+
*/
48+
public function fresh( $value )
49+
{
50+
return new CurrencyService( $value, [
51+
'currency_iso' => $this->currency_iso,
52+
'currency_symbol' => $this->currency_symbol,
53+
'currency_position' => $this->currency_position,
54+
'decimal_precision' => $this->decimal_precision,
55+
'decimal_separator' => $this->decimal_separator,
56+
'prefered_currency' => $this->prefered_currency,
57+
'thousand_separator' => $this->thousand_separator,
58+
]);
59+
}
60+
61+
/**
62+
* Set a value for the current instance
63+
* @param int|float $amount
64+
* @return CurrencyService
65+
*/
4166
private static function __defineAmount( $amount ): CurrencyService
4267
{
43-
return app()->make( CurrencyService::class )->value( $amount );
68+
/**
69+
* @var CurrencyService
70+
*/
71+
$currencyService = app()->make( CurrencyService::class );
72+
return $currencyService->value( $amount );
4473
}
4574

4675
/**

app/Services/OrdersService.php

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -957,28 +957,35 @@ private function __computeOrderTotal($data)
957957
* increase the total with the
958958
* shipping fees and subtract the discounts
959959
*/
960-
$order->total = $this->currencyService->define(
961-
( $order->subtotal + $order->shipping + ( $order->tax_type === 'exclusive' ? $order->tax_value : 0 ) ) -
962-
( $order->total_coupons + $order->discount )
960+
$order->total = Currency::fresh( $order->subtotal )
961+
->additionateBy( $order->shipping )
962+
->additionateBy(
963+
( $order->tax_type === 'exclusive' ? $order->tax_value : 0 )
963964
)
964-
->get();
965+
->subtractBy(
966+
Currency::fresh( $order->total_coupons )
967+
->additionateBy( $order->discount )
968+
->getRaw()
969+
)
970+
->getRaw();
965971

966972
$order->gross_total = $order->total;
967973

968-
dump( 'tendered =>' . $order->tendered );
969-
dump( 'total =>' . $order->total );
970-
971974
/**
972975
* compute change
973976
*/
974-
$order->change = Currency::raw( $order->tendered - $order->total );
977+
$order->change = Currency::fresh( $order->tendered )
978+
->subtractBy( $order->total )
979+
->getRaw();
975980

976981
/**
977982
* compute gross total
978983
*/
979-
$order->net_total = $this->currencyService
980-
->define( $order->subtotal - $order->discount - $order->total_coupons - $order->tax_value )
981-
->get();
984+
$order->net_total = Currency::fresh( $order->subtotal )
985+
->subtractBy( $order->discount )
986+
->subtractBy( $order->total_coupons )
987+
->subtractBy( $order->tax_value )
988+
->getRaw();
982989

983990
return $order;
984991
}
@@ -1989,8 +1996,19 @@ public function refreshOrder(Order $order)
19891996
$order->subtotal = $productTotal;
19901997
$order->gross_total = $productGrossTotal;
19911998
$order->discount = $this->computeOrderDiscount( $order );
1992-
$order->total = ( $productTotal + $orderShipping + ( $order->tax_type === 'exclusive' ? $order->tax_value : 0 ) ) - ( $order->discount + $order->total_coupons );
1993-
$order->change = Currency::raw( $order->tendered - $order->total );
1999+
$order->total = Currency::fresh( $productTotal )
2000+
->additionateBy( $orderShipping )
2001+
->additionateBy(
2002+
( $order->tax_type === 'exclusive' ? $order->tax_value : 0 )
2003+
)
2004+
->subtractBy(
2005+
ns()->currency->fresh( $order->discount )
2006+
->additionateBy( $order->total_coupons )
2007+
->getRaw()
2008+
)
2009+
->getRaw();
2010+
2011+
$order->change = Currency::fresh( $order->tendered )->subtractBy( $order->total )->getRaw();
19942012

19952013
$refunds = $order->refund;
19962014
$totalRefunds = $refunds->map( fn( $refund ) => $refund->total )->sum();

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"picqer/php-barcode-generator": "^2.1",
3030
"pusher/pusher-php-server": "~3.0",
3131
"rct567/dom-query": "^0.8.0",
32-
"sentry/sentry-laravel": "^2.10",
3332
"spatie/laravel-db-snapshots": "^1.7",
3433
"tormjens/eventy": "^0.7.0"
3534
},

database/migrations/schema-updates/2021_11_25_032153_update_procurement_table_nov2521.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class UpdateProcurementTableNov2521 extends Migration
1414
public function up()
1515
{
1616
Schema::table( 'nexopos_procurements', function( Blueprint $table ) {
17-
if ( Schema::hasColumn( 'nexopos_procurements', 'value' ) ) {
17+
if ( Schema::hasColumn( 'nexopos_procurements', 'value' ) && ! Schema::hasColumn( 'nexopos_procurements', 'cost' ) ) {
1818
$table->renameColumn( 'value', 'cost' );
1919
}
2020
});
@@ -34,8 +34,8 @@ public function up()
3434
public function down()
3535
{
3636
Schema::table( 'nexopos_procurements', function( Blueprint $table ) {
37-
if ( Schema::hasColumn( 'nexopos_procurements', 'value' ) ) {
38-
$table->dropColumn( 'cost', 18, 5 );
37+
if ( ! Schema::hasColumn( 'nexopos_procurements', 'value' ) && Schema::hasColumn( 'nexopos_procurements', 'cost' ) ) {
38+
$table->renameColumn( 'cost', 'value' );
3939
}
4040
});
4141
}

public/css/app.css

Lines changed: 3 additions & 281976 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/app.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/auth.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/bootstrap.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/cashier.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)