Skip to content

Commit a141d9f

Browse files
authored
Merge pull request #1939 from Blair2004/v5.0.x
V5.0.x
2 parents f117fe5 + 85d4af1 commit a141d9f

File tree

220 files changed

+9658
-8785
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+9658
-8785
lines changed

app/Classes/Currency.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public static function fresh( $amount ): CurrencyService
2424

2525
public static function raw( $amount )
2626
{
27-
return ns()->currency->getRaw( $amount );
27+
return ns()->currency->define( $amount )->toFloat();
2828
}
2929
}

app/Console/Commands/SetupCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Console\Commands;
44

5+
use App\Services\Helper;
56
use App\Services\SetupService;
67
use Illuminate\Console\Command;
78

@@ -78,6 +79,10 @@ public function handle()
7879
return $this->error( __( 'Unable to proceed, looks like the database can\'t be used.' ) );
7980
}
8081

82+
if ( Helper::installed() ) {
83+
return $this->error( __( 'NexoPOS is already installed.' ) );
84+
}
85+
8186
$this->setupLanguage();
8287
$this->setupStoreName();
8388
$this->setupAdminUsername();

app/Crud/UnitCrud.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace App\Crud;
44

5+
use App\Classes\CrudForm;
6+
use App\Classes\FormInput;
57
use App\Models\Unit;
68
use App\Models\UnitGroup;
79
use App\Services\CrudEntry;
@@ -125,6 +127,67 @@ public function isEnabled( $feature ): bool
125127
*/
126128
public function getForm( $entry = null )
127129
{
130+
return CrudForm::form(
131+
main: FormInput::text(
132+
label: __( 'Name' ),
133+
name: 'name',
134+
value: $entry->name ?? '',
135+
description: __( 'Provide a name to the resource.' ),
136+
validation: 'required',
137+
),
138+
tabs: CrudForm::tabs(
139+
CrudForm::tab(
140+
identifier: 'general',
141+
label: __( 'General' ),
142+
fields: CrudForm::fields(
143+
FormInput::text(
144+
label: __( 'Identifier' ),
145+
name: 'identifier',
146+
description: __( 'Provide a unique value for this unit. Might be composed from a name but shouldn\'t include space or special characters.' ),
147+
validation: 'required|unique:' . Hook::filter( 'ns-table-name', 'nexopos_units' ) . ',identifier' . ( $entry !== null ? ',' . $entry->id : '' ),
148+
value: $entry->identifier ?? '',
149+
),
150+
FormInput::media(
151+
label: __( 'Preview URL' ),
152+
name: 'preview_url',
153+
description: __( 'Preview of the unit.' ),
154+
value: $entry->preview_url ?? '',
155+
),
156+
FormInput::text(
157+
label: __( 'Value' ),
158+
name: 'value',
159+
description: __( 'Define the value of the unit.' ),
160+
validation: 'required|numeric',
161+
value: $entry->value ?? '',
162+
),
163+
FormInput::searchSelect(
164+
component: 'nsCrudForm',
165+
props: UnitGroupCrud::getFormConfig(),
166+
name: 'group_id',
167+
validation: 'required',
168+
options: Helper::toJsOptions( UnitGroup::get(), [ 'id', 'name' ] ),
169+
label: __( 'Group' ),
170+
description: __( 'Define to which group the unit should be assigned.' ),
171+
value: $entry->group_id ?? '',
172+
),
173+
FormInput::switch(
174+
name: 'base_unit',
175+
validation: 'required',
176+
options: Helper::kvToJsOptions( [ __( 'No' ), __( 'Yes' ) ] ),
177+
label: __( 'Base Unit' ),
178+
description: __( 'Determine if the unit is the base unit from the group.' ),
179+
value: $entry ? ( $entry->base_unit ? 1 : 0 ) : 0,
180+
),
181+
FormInput::textarea(
182+
label: __( 'Description' ),
183+
name: 'description',
184+
description: __( 'Provide a short description about the unit.' ),
185+
value: $entry->description ?? '',
186+
)
187+
)
188+
)
189+
)
190+
);
128191
return [
129192
'main' => [
130193
'label' => __( 'Name' ),

app/Exceptions/NotAllowedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function render( $request )
2525
'title' => __( 'Not Allowed Action' ),
2626
'message' => $this->getMessage(),
2727
'back' => Helper::getValidPreviousUrl( $request ),
28-
] );
28+
], $this->getStatusCode() );
2929
}
3030

3131
return JsonResponse::error(

app/Exceptions/NotEnoughPermissionException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public function render( $request )
2424
'title' => __( 'Not Enough Permissions' ),
2525
'message' => $this->getMessage(),
2626
'back' => Helper::getValidPreviousUrl( $request ),
27-
] );
27+
], 403 );
2828
}
2929

3030
return response()->json( [
3131
'status' => 'error',
3232
'message' => $this->getMessage(),
33-
], 401 );
33+
], 403 );
3434
}
3535
}

app/Http/Middleware/Authenticate.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Middleware;
44

5+
use App\Services\Helper;
56
use Illuminate\Auth\Middleware\Authenticate as Middleware;
67

78
class Authenticate extends Middleware
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use Illuminate\Console\Events\CommandFinished;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Queue\InteractsWithQueue;
8+
use Illuminate\Support\Facades\Cache;
9+
10+
class CommandFinishedListener
11+
{
12+
/**
13+
* Create the event listener.
14+
*/
15+
public function __construct()
16+
{
17+
//
18+
}
19+
20+
/**
21+
* Handle the event.
22+
*/
23+
public function handle( CommandFinished $event): void
24+
{
25+
/**
26+
* because if we're running the reset from the command line
27+
* we might not have this cache entry deleted. We'll delete it when the reset is done.
28+
*/
29+
Cache::delete( 'ns-core-installed' );
30+
}
31+
}

app/Services/Options.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,6 @@ class Options
88
{
99
private $rawOptions = [];
1010

11-
private $options = [];
12-
13-
private $isUserOptions = false;
14-
15-
private $option;
16-
17-
private $user_id;
18-
19-
private $value;
20-
21-
private $hasFound;
22-
23-
private $removableIndex;
24-
2511
public string $tableName;
2612

2713
/**

app/Services/OrdersService.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ public function __saveOrderTaxes( Order $order, $taxes ): float
460460

461461
foreach ( $taxes as $index => $tax ) {
462462
$orderTax = new OrderTax;
463-
$orderTax->tax_name = $tax[ 'tax_name' ];
464-
$orderTax->tax_value = $response[ 'percentages' ][ $index ][ 'tax' ];
463+
$orderTax->tax_name = $tax[ 'name' ];
464+
$orderTax->tax_value = ( $response[ 'percentages' ][ $index ][ 'tax' ] ?? 0 );
465465
$orderTax->rate = $tax[ 'rate' ];
466466
$orderTax->tax_id = $tax[ 'tax_id' ];
467467
$orderTax->order_id = $order->id;
@@ -918,9 +918,9 @@ private function __checkOrderPayments( $fields, ?Order $order, Customer $custome
918918

919919
$totalPayments = 0;
920920

921-
$subtotal = Currency::raw( collect( $fields[ 'products' ] )->map( function ( $product ) {
921+
$subtotal = ns()->currency->define( collect( $fields[ 'products' ] )->map( function ( $product ) {
922922
return floatval( $product['total_price'] );
923-
} )->sum() );
923+
} )->sum() )->toFloat();
924924

925925
$total = $this->currencyService->define(
926926
$subtotal + $this->__getShippingFee( $fields )
@@ -1034,13 +1034,13 @@ protected function __computeOrderTotal( $data )
10341034
* increase the total with the
10351035
* shipping fees and subtract the discounts
10361036
*/
1037-
$order->total = Currency::fresh( $order->subtotal )
1037+
$order->total = Currency::define( $order->subtotal )
10381038
->additionateBy( $order->shipping )
10391039
->additionateBy(
10401040
( $order->tax_type === 'exclusive' ? $order->tax_value : 0 )
10411041
)
10421042
->subtractBy(
1043-
Currency::fresh( $order->total_coupons )
1043+
Currency::define( $order->total_coupons )
10441044
->additionateBy( $order->discount )
10451045
->toFloat()
10461046
)
@@ -1051,7 +1051,7 @@ protected function __computeOrderTotal( $data )
10511051
/**
10521052
* compute change
10531053
*/
1054-
$order->change = Currency::fresh( $order->tendered )
1054+
$order->change = Currency::define( $order->tendered )
10551055
->subtractBy( $order->total )
10561056
->toFloat();
10571057

@@ -1060,7 +1060,7 @@ protected function __computeOrderTotal( $data )
10601060
*
10611061
* @todo not accurate
10621062
*/
1063-
$order->total_without_tax = Currency::fresh( $order->subtotal )
1063+
$order->total_without_tax = Currency::define( $order->subtotal )
10641064
->subtractBy( $order->discount )
10651065
->subtractBy( $order->total_coupons )
10661066
->subtractBy( $order->tax_value )
@@ -1151,7 +1151,7 @@ private function __saveOrderProducts( $order, $products )
11511151

11521152
if ( $product[ 'product' ] instanceof Product ) {
11531153
$orderProduct->total_purchase_price = $this->currencyService->define(
1154-
$product[ 'total_purchase_price' ] ?? Currency::fresh( $this->productService->getCogs(
1154+
$product[ 'total_purchase_price' ] ?? Currency::define( $this->productService->getCogs(
11551155
product: $product[ 'product' ],
11561156
unit: $unit
11571157
) )
@@ -1454,8 +1454,8 @@ public function computeProduct( $fields, ?Product $product = null, ?ProductUnitQ
14541454
price: $sale_price
14551455
)
14561456
)
1457-
->multiplyBy( floatval( $fields[ 'quantity' ] ) )
1458-
->toFloat();
1457+
->multiplyBy( floatval( $fields[ 'quantity' ] ) )
1458+
->toFloat();
14591459
}
14601460

14611461
/**
@@ -1882,7 +1882,7 @@ public function refundSingleProduct( Order $order, OrderRefund $orderRefund, Ord
18821882

18831883
$productRefund->tax_value = $this->computeTaxFromOrderTaxes(
18841884
$order,
1885-
Currency::raw( $details[ 'unit_price' ] * $details[ 'quantity' ] ),
1885+
Currency::define( $details[ 'unit_price' ] )->multipliedBy( $details[ 'quantity' ] )->toFloat(),
18861886
ns()->option->get( 'ns_pos_tax_type' )
18871887
);
18881888

@@ -2146,11 +2146,11 @@ public function refreshOrder( Order $order )
21462146
/**
21472147
* let's refresh all the order values
21482148
*/
2149-
$order->subtotal = Currency::raw( $productTotal );
2149+
$order->subtotal = Currency::define( $productTotal )->toFloat();
21502150
$order->total_without_tax = $productPriceWithoutTax;
21512151
$order->total_with_tax = $productPriceWithTax;
21522152
$order->discount = $this->computeOrderDiscount( $order );
2153-
$order->total = Currency::fresh( $order->subtotal )
2153+
$order->total = Currency::define( $order->subtotal )
21542154
->additionateBy( $orderShipping )
21552155
->additionateBy(
21562156
( $order->tax_type === 'exclusive' ? $order->tax_value : 0 )
@@ -2162,7 +2162,7 @@ public function refreshOrder( Order $order )
21622162
)
21632163
->toFloat();
21642164

2165-
$order->change = Currency::fresh( $order->tendered )->subtractBy( $order->total )->toFloat();
2165+
$order->change = Currency::define( $order->tendered )->subtractBy( $order->total )->toFloat();
21662166

21672167
$refunds = $order->refunds;
21682168

@@ -2851,11 +2851,11 @@ public function createInstalment( Order $order, $fields )
28512851
{
28522852
$totalInstalment = $order->instalments->map( fn( $instalment ) => $instalment->amount )->sum();
28532853

2854-
if ( Currency::raw( $fields[ 'amount' ] ) <= 0 ) {
2854+
if ( Currency::define( $fields[ 'amount' ] )->toFloat() <= 0 ) {
28552855
throw new NotAllowedException( __( 'The defined amount is not valid.' ) );
28562856
}
28572857

2858-
if ( Currency::raw( $totalInstalment ) >= $order->total ) {
2858+
if ( Currency::define( $totalInstalment )->toFloat() >= $order->total ) {
28592859
throw new NotAllowedException( __( 'No further instalments is allowed for this order. The total instalment already covers the order total.' ) );
28602860
}
28612861

app/Services/ReportService.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,10 @@ public function getFromTimeRange( $startDate, $endDate )
410410
/**
411411
* This return the year report
412412
*
413-
* @param string $year
413+
* @param int $year
414414
* @return array $reports
415415
*/
416-
public function getYearReportFor( $year )
416+
public function getYearReportFor( int $year )
417417
{
418418
$date = $this->dateService->now();
419419
$date->year = $year >= 2019 && $year <= 2099 ? $year : 2020; // validate the date
@@ -455,10 +455,6 @@ public function getProductSalesDiff( $startDate, $endDate, $sort )
455455
$endDate = Carbon::parse( $endDate );
456456
$diffInDays = Carbon::parse( $startDate )->diffInDays( $endDate );
457457

458-
$orderProductTable = Hook::filter( 'ns-model-table', 'nexopos_orders_products' );
459-
$productsTable = Hook::filter( 'ns-model-table', 'nexopos_products' );
460-
$unitstable = Hook::filter( 'ns-model-table', 'nexopos_units' );
461-
462458
if ( $diffInDays > 0 ) {
463459
// check if it's the start and end of the month
464460
$isStartOfMonth = Carbon::parse( $startDate )->startOfMonth()->isSameDay( $startDate );
@@ -553,8 +549,6 @@ private function getBestRecords( $previousDates, $sort )
553549
{
554550
$orderProductTable = Hook::filter( 'ns-model-table', 'nexopos_orders_products' );
555551
$orderTable = Hook::filter( 'ns-model-table', 'nexopos_orders' );
556-
$productsTable = Hook::filter( 'ns-model-table', 'nexopos_products' );
557-
$unitstable = Hook::filter( 'ns-model-table', 'nexopos_units' );
558552

559553
switch ( $sort ) {
560554
case 'using_quantity_asc':

0 commit comments

Comments
 (0)