Skip to content

Commit 98a6b23

Browse files
authored
Merge pull request #308 from Blair2004/v4.5.x
V4.5.x
2 parents 221ae3e + f706b01 commit 98a6b23

33 files changed

+266
-141
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ public/mapping.json
3737
storage/module.zip
3838
tests/database.sqlite
3939
tests/database.sqlite-journal
40+
storage/snapshots/*.sql

app/Console/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Kernel extends ConsoleKernel
3333
*/
3434
protected function schedule(Schedule $schedule)
3535
{
36+
$schedule->command( 'telescope:prune' )->daily();
3637
$schedule->job( new TaskSchedulingPingJob )->hourly();
3738
$schedule->job( new ExecuteExpensesJob )->daily( '00:01' );
3839
$schedule->job( new StockProcurementJob() )->daily( '00:05' );

app/Exceptions/Handler.php

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

33
namespace App\Exceptions;
44

5+
use App\Exceptions\QueryException as ExceptionsQueryException;
56
use Illuminate\Auth\AuthenticationException;
7+
use Illuminate\Database\QueryException;
68
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
79
use Illuminate\Validation\ValidationException as MainValidationException;
810
use Throwable;
@@ -45,6 +47,8 @@ public function report(Throwable $exception)
4547
/**
4648
* We want to use our defined route
4749
* instead of what is provided by laravel.
50+
* @return \Illuminate\Routing\Redirector
51+
*
4852
*/
4953
protected function unauthenticated($request, AuthenticationException $exception)
5054
{
@@ -71,6 +75,11 @@ public function render($request, Throwable $exception)
7175
->render( $request );
7276
}
7377

78+
if ( $exception instanceof QueryException ) {
79+
return ( new ExceptionsQueryException( $exception->getMessage() ) )
80+
->render( $request );
81+
}
82+
7483
return parent::render($request, $exception);
7584
}
7685
}

app/Exceptions/QueryException.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
7+
class QueryException extends Exception
8+
{
9+
public function render( $message )
10+
{
11+
$message = $this->getMessage();
12+
$title = __( 'Query Exception' );
13+
return response()->view( 'pages.errors.db-exception', compact( 'message', 'title' ), 500 );
14+
}
15+
}

app/Http/Controllers/Dashboard/CustomersController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use App\Crud\CustomerCrud;
1414
use App\Crud\CustomerOrderCrud;
1515
use App\Crud\CustomerRewardCrud;
16+
use App\Exceptions\NotFoundException;
1617
use App\Models\Customer;
1718

1819
use Illuminate\Http\Request;
@@ -65,8 +66,12 @@ public function get( $customer_id = null )
6566
{
6667
$customer = Customer::with( 'group' )->find( $customer_id );
6768

68-
if ( $customer instanceof Customer ) {
69-
return $customer;
69+
if ( $customer_id !== null ) {
70+
if ( $customer instanceof Customer ) {
71+
return $customer;
72+
}
73+
74+
throw new NotFoundException( __( 'The requested customer cannot be fonud.' ) );
7075
}
7176

7277
return $this->customerService->get();

app/Providers/ModulesServiceProvider.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class ModulesServiceProvider extends ServiceProvider
1010
{
1111
protected $modulesCommands = [];
12+
protected $modules;
1213

1314
/**
1415
* Bootstrap the application services.
@@ -43,16 +44,16 @@ public function register()
4344
{
4445
// register module singleton
4546
$this->app->singleton( ModulesService::class, function( $app ) {
46-
$modules = new ModulesService;
47-
$modules->load();
48-
49-
collect( $modules->getEnabled() )->each( fn( $module ) => $modules->boot( $module ) );
50-
47+
$this->modules = new ModulesService;
48+
$this->modules->load();
49+
50+
collect( $this->modules->getEnabled() )->each( fn( $module ) => $this->modules->boot( $module ) );
51+
5152
/**
5253
* trigger register method only for enabled modules
5354
* service providers that extends ModulesServiceProvider.
5455
*/
55-
collect( $modules->getEnabled() )->each( function( $module ) use ( $modules ) {
56+
collect( $this->modules->getEnabled() )->each( function( $module ) {
5657
/**
5758
* register module commands
5859
*/
@@ -61,12 +62,12 @@ public function register()
6162
array_keys( $module[ 'commands' ] )
6263
);
6364

64-
$modules->triggerServiceProviders( $module, 'register', ServiceProvider::class );
65+
$this->modules->triggerServiceProviders( $module, 'register', ServiceProvider::class );
6566
});
6667

67-
event( new ModulesLoadedEvent( $modules->get() ) );
68+
event( new ModulesLoadedEvent( $this->modules->get() ) );
6869

69-
return $modules;
70+
return $this->modules;
7071
});
7172
}
7273
}

app/Services/Helpers/App.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
22
namespace App\Services\Helpers;
33

4+
use App\Classes\Hook;
5+
use Illuminate\Support\Facades\DB;
46
use Jackiedo\DotenvEditor\Facades\DotenvEditor;
57
use Illuminate\Support\Facades\View;
68
use Illuminate\Support\Facades\Log;
9+
use Illuminate\Support\Facades\Schema;
710

811
trait App {
912
/**
@@ -12,12 +15,13 @@ trait App {
1215
*/
1316
static function installed()
1417
{
15-
if ( DotenvEditor::keyExists( 'NS_VERSION' ) ) {
16-
$version = DotenvEditor::getValue( 'NS_VERSION' );
17-
return ! in_array( $version, [ null, false ]);
18+
try {
19+
if( DB::connection()->getPdo() ){
20+
return Schema::hasTable( 'nexopos_options' );
21+
}
22+
} catch (\Exception $e) {
23+
return false;
1824
}
19-
20-
return false;
2125
}
2226

2327
/**
@@ -32,6 +36,8 @@ static function LoadInterface( $path, $data = [] )
3236

3337
static function pageTitle( $string )
3438
{
35-
return sprintf( __( '%s &mdash; NexoPOS 4' ), $string );
39+
return sprintf(
40+
Hook::filter( 'ns-page-title', __( '%s &mdash; NexoPOS 4' ) ),
41+
$string );
3642
}
3743
}

app/Services/OrdersService.php

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -752,20 +752,6 @@ public function makeOrderSinglePayment( $payment, Order $order )
752752
if ( $paymentToday->count() === 0 ) {
753753
throw new NotFoundException( __( 'No payment is expected at the moment. If the customer want to pay early, consider adjusting instalment payments date.' ) );
754754
}
755-
756-
/**
757-
* @todo don't think this restriction is actually necessary.
758-
*/
759-
// if (
760-
// ns()->currency->getRaw( $paymentToday->sum( 'amount' ) ) !==
761-
// ns()->currency->getRaw( $payment[ 'value' ] ) ) {
762-
// throw new NotAllowedException(
763-
// sprintf(
764-
// __( 'The provided payment doesn\'t match the expected payment : %s. If the customer want to pay a different amount, consider adjusting the instalment amount.' ),
765-
// ( string ) Currency::define( $paymentToday->sum( 'amount' ) )
766-
// )
767-
// );
768-
// }
769755
}
770756

771757
$this->__saveOrderSinglePayment( $payment, $order );
@@ -1536,7 +1522,7 @@ public function computeOrderTaxes( Order $order )
15361522
$taxType = ns()->option->get( 'ns_pos_tax_type' );
15371523
$subTotal = $order->products()->sum( 'total_price' );
15381524
$taxValue = $order->taxes->map( function( $tax ) use ( $taxType, $subTotal ) {
1539-
$tax->tax_value = $this->taxService->getComputedTaxValue( $taxType, $tax->rate, $subTotal );
1525+
$tax->tax_value = $this->taxService->getVatValue( $taxType, $tax->rate, $subTotal );
15401526
$tax->save();
15411527

15421528
return $tax->tax_value;
@@ -2365,8 +2351,8 @@ public function void( Order $order, $reason )
23652351
public function getPaidSales( $startDate, $endDate )
23662352
{
23672353
return Order::paid()
2368-
->where( 'created_at', '>=', Carbon::parse( $startDate )->startOfDay()->toDateTimeString() )
2369-
->where( 'created_at', '<=', Carbon::parse( $endDate )->endOfDay()->toDateTimeString() )
2354+
->where( 'created_at', '>=', Carbon::parse( $startDate )->toDateTimeString() )
2355+
->where( 'created_at', '<=', Carbon::parse( $endDate )->toDateTimeString() )
23702356
->get();
23712357
}
23722358

@@ -2378,8 +2364,8 @@ public function getPaidSales( $startDate, $endDate )
23782364
*/
23792365
public function getSoldStock( $startDate, $endDate )
23802366
{
2381-
$rangeStarts = Carbon::parse( $startDate )->startOfDay()->toDateTimeString();
2382-
$rangeEnds = Carbon::parse( $endDate )->endOfDay()->toDateTimeString();
2367+
$rangeStarts = Carbon::parse( $startDate )->toDateTimeString();
2368+
$rangeEnds = Carbon::parse( $endDate )->toDateTimeString();
23832369

23842370
$products = OrderProduct::whereHas( 'order', function( Builder $query ) {
23852371
$query->where( 'payment_status', Order::PAYMENT_PAID );

app/Services/ProductCategoryService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function getUsingName( $name )
3939
* @param array details
4040
* @return array
4141
*/
42-
public function create( $data )
42+
public function create( $data, ProductCategory $productCategory = null )
4343
{
44-
$category = new ProductCategory;
44+
$category = $productCategory === null ? new ProductCategory : $productCategory;
4545
$category->author = Auth::id();
4646
$category->description = $data[ 'description' ] ?? '';
4747
$category->preview_url = $data[ 'preview_url' ] ?? '';

config/filesystems.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
'root' => storage_path('app'),
4949
],
5050

51+
'snapshots' => [
52+
'driver' => 'local',
53+
'root' => storage_path( 'snapshots' )
54+
],
55+
5156
'public' => [
5257
'driver' => 'local',
5358
'root' => storage_path('app/public'),

0 commit comments

Comments
 (0)