Skip to content

Commit 5327480

Browse files
authored
Merge pull request #1225 from Blair2004/v4.8.x
V4.8.x
2 parents 3d9ef9b + c6fe5fb commit 5327480

File tree

13 files changed

+181
-113
lines changed

13 files changed

+181
-113
lines changed

app/Console/Commands/ModuleSymlinkCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Services\ModulesService;
66
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\Storage;
78

89
class ModuleSymlinkCommand extends Command
910
{
@@ -36,6 +37,12 @@ public function handle()
3637
} else {
3738
$modules = $moduleService->get();
3839

40+
/**
41+
* let's clear all existing links
42+
*/
43+
Storage::disk( 'ns' )->deleteDirectory( 'public/modules' );
44+
Storage::disk( 'ns' )->makeDirectory( 'public/modules' );
45+
3946
$this->withProgressBar( $modules, function( $module ) use ( $moduleService ) {
4047
$moduleService->createSymLink( $module[ 'namespace' ] );
4148
});

app/Console/Commands/ResetCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ResetCommand extends Command
1515
*
1616
* @var string
1717
*/
18-
protected $signature = 'ns:reset {--mode=soft} {--user=default}';
18+
protected $signature = 'ns:reset {--mode=soft} {--user=default} {--with-sales} {--with-procurements}';
1919

2020
/**
2121
* The console command description.
@@ -70,8 +70,8 @@ public function handle()
7070
$this->initializeRole();
7171
$this->demoService->run([
7272
'mode' => 'grocery',
73-
'create_sales' => true,
74-
'create_procurements' => true,
73+
'create_sales' => $this->option( 'with-sales' ) && $this->option( 'with-procurements' ) ? true : false,
74+
'create_procurements' => $this->option( 'with-procurements' ) ? true : false,
7575
]);
7676
$this->info( __( 'The demo has been enabled.' ) );
7777
break;

app/Models/Provider.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22

33
namespace App\Models;
44

5+
use App\Traits\NsDependable;
56
use Illuminate\Database\Eloquent\Factories\HasFactory;
67

78
class Provider extends NsModel
89
{
9-
use HasFactory;
10+
use HasFactory, NsDependable;
1011

1112
protected $table = 'nexopos_' . 'providers';
1213

1314
protected $guarded = [];
1415

16+
protected $isDependencyFor = [
17+
Procurement::class => [
18+
'local_name' => 'name',
19+
'local_index' => 'id',
20+
'foreign_name' => 'code',
21+
'foreign_index' => 'provider_id',
22+
],
23+
];
24+
1525
public function procurements()
1626
{
1727
return $this->hasMany( Procurement::class );

app/Services/DemoCoreService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function createAccountingAccounts()
134134
'account' => '008',
135135
]);
136136

137-
ns()->option->set( 'ns_customer_debitting_cashflow_account', AccountType::account( '007' )->first()->id );
137+
ns()->option->set( 'ns_customer_debitting_cashflow_account', AccountType::account( '008' )->first()->id );
138138
}
139139

140140
public function createCustomers()

app/Services/Options.php

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ public function setDefault( $options = [] ): void
4444
{
4545
Option::truncate();
4646

47+
$types = app()->make( OrdersService::class )->getTypeLabels();
48+
4749
$defaultOptions = [
4850
'ns_registration_enabled' => false,
4951
'ns_store_name' => 'NexoPOS 4.x',
50-
'ns_pos_order_types' => [ 'takeaway', 'delivery' ],
52+
'ns_pos_order_types' => array_keys( $types ),
5153
];
5254

5355
$options = array_merge( $defaultOptions, $options );
@@ -103,38 +105,7 @@ public function set( $key, $value, $expiration = null )
103105
* it will save the new value and update
104106
* the option object.
105107
*/
106-
$foundOption = collect( $this->rawOptions )->map( function( $option, $index ) use ( $value, $key, $expiration ) {
107-
if ( $key === $index ) {
108-
$this->hasFound = true;
109-
110-
switch ( $value ) {
111-
case is_array( $value ) :
112-
$option->value = json_encode( $value );
113-
break;
114-
case empty( $value ) && ! (bool) preg_match( '/[0-9]{1,}/', $value ) :
115-
$option->value = '';
116-
break;
117-
default:
118-
$option->value = $value;
119-
break;
120-
}
121-
122-
$option->expire_on = $expiration;
123-
124-
/**
125-
* this should be overridable
126-
* from a user option or any
127-
* extending this class
128-
*/
129-
$option = $this->beforeSave( $option );
130-
$option->save();
131-
132-
return $option;
133-
}
134-
135-
return false;
136-
})
137-
->filter();
108+
$foundOption = collect( $this->rawOptions )->filter( fn( $option, $index ) => $index === $key );
138109

139110
/**
140111
* if the option hasn't been found
@@ -143,33 +114,30 @@ public function set( $key, $value, $expiration = null )
143114
*/
144115
if ( $foundOption->isEmpty() ) {
145116
$option = new Option;
146-
$option->key = trim( strtolower( $key ) );
147-
$option->array = false;
148-
149-
switch ( $value ) {
150-
case is_array( $value ) :
151-
$option->value = json_encode( $value );
152-
break;
153-
case empty( $value ) && ! (bool) preg_match( '/[0-9]{1,}/', $value ) :
154-
$option->value = '';
155-
break;
156-
default:
157-
$option->value = $value;
158-
break;
159-
}
117+
} else {
118+
$option = $foundOption->first();
119+
}
160120

161-
$option->expire_on = $expiration;
121+
$option->key = trim( strtolower( $key ) );
122+
$option->array = false;
162123

163-
/**
164-
* this should be overridable
165-
* from a user option or any
166-
* extending this class
167-
*/
168-
$option = $this->beforeSave( $option );
169-
$option->save();
124+
if ( is_array( $value ) ) {
125+
$option->value = json_encode( $value );
126+
} else if ( empty( $value ) && ! (bool) preg_match( '/[0-9]{1,}/', $value ) ) {
127+
$option->value = '';
170128
} else {
171-
$option = $foundOption->first();
129+
$option->value = $value;
172130
}
131+
132+
$option->expire_on = $expiration;
133+
134+
/**
135+
* this should be overridable
136+
* from a user option or any
137+
* extending this class
138+
*/
139+
$option = $this->beforeSave( $option );
140+
$option->save();
173141

174142
/**
175143
* Let's save the new option

app/Services/OrdersService.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,12 +1032,16 @@ private function __saveOrderProducts($order, $products)
10321032
$gross = 0;
10331033

10341034
$orderProducts = $products->map(function ($product) use (&$subTotal, &$taxes, &$order, &$gross) {
1035+
1036+
$previousQuantity = 0;
1037+
10351038
/**
10361039
* if the product id is provided
10371040
* then we can use that id as a reference.
10381041
*/
10391042
if ( isset( $product[ 'id' ] ) ) {
10401043
$orderProduct = OrderProduct::find( $product[ 'id' ] );
1044+
$previousQuantity = $orderProduct->quantity;
10411045
} else {
10421046
$orderProduct = new OrderProduct;
10431047
}
@@ -1113,7 +1117,15 @@ private function __saveOrderProducts($order, $products)
11131117
'total_price' => $orderProduct->total_price,
11141118
];
11151119

1116-
$this->productService->stockAdjustment( ProductHistory::ACTION_SOLD, $history );
1120+
/**
1121+
* __deleteUntrackedProducts will delete all products that
1122+
* already exists and which are edited. We'll here only records
1123+
* products that doesn't exists yet.
1124+
*/
1125+
if ( $orderProduct->wasRecentlyCreated ) {
1126+
$this->productService->stockAdjustment( ProductHistory::ACTION_SOLD, $history );
1127+
}
1128+
11171129
}
11181130

11191131
event( new OrderProductAfterSavedEvent( $orderProduct, $order, $product ) );

app/Services/ProviderService.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,17 @@ public function cancelPaymentForProcurement( Procurement $procurement )
189189
{
190190
$provider = Provider::find( $procurement->provider_id );
191191

192-
if ( $procurement->payment_status === 'paid' ) {
193-
$provider->amount_paid -= $procurement->cost;
194-
} else {
195-
$provider->amount_due -= $procurement->cost;
192+
if ( $provider instanceof Provider ) {
193+
194+
if ( $procurement->payment_status === 'paid' ) {
195+
$provider->amount_paid -= $procurement->cost;
196+
} else {
197+
$provider->amount_due -= $procurement->cost;
198+
}
199+
200+
$provider->save();
196201
}
197202

198-
$provider->save();
199-
200203
return [
201204
'status' => 'succecss',
202205
'message' => __( 'The procurement payment has been deducted.' ),

app/Services/Setup.php

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

1515
class Setup
1616
{
17+
public Options $options;
18+
1719
/**
1820
* Attempt database and save db informations
1921
*

config/nexopos.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
return [
4-
'version' => '4.8.10',
4+
'version' => '4.8.11',
55
'languages' => [
66
'en' => 'English',
77
'fr' => 'Français',

database/migrations/create/2021_11_17_215824_update_create_options_for_order_type.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)