Skip to content

Commit 3ac6fac

Browse files
authored
Merge pull request #1108 from Blair2004/v4.8.x
V4.8.x
2 parents 1d73523 + b8dd60a commit 3ac6fac

File tree

68 files changed

+468
-198
lines changed

Some content is hidden

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

68 files changed

+468
-198
lines changed

app/Console/Commands/CrudGeneratorCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function askNamespace()
135135
} elseif ( $name == 'Q' ) {
136136
return;
137137
}
138-
$this->error( __( 'Please provide a valid value' ) );
138+
$this->error( __( 'Please provide a valid value.' ) );
139139

140140
return $this->askNamespace();
141141
}

app/Crud/CustomerCrud.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,16 @@ public function bulkAction( Request $request )
659659
'failed' => 0,
660660
];
661661

662-
foreach ( $request->input( 'entries_id' ) as $id ) {
662+
foreach ( $request->input( 'entries' ) as $id ) {
663663
$entity = $this->model::find( $id );
664664
if ( $entity instanceof Customer ) {
665+
666+
/**
667+
* We want to check if we're allowed to delete
668+
* the selected customer by checking his dependencies.
669+
*/
670+
$this->handleDependencyForDeletion( $entity );
671+
665672
$entity->delete();
666673
$status[ 'success' ]++;
667674
} else {

app/Crud/ProductCrud.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,8 @@ public function setActions( CrudEntry $entry, $namespace )
704704
$entry->type = match ( $entry->type ) {
705705
'materialized' => __( 'Materialized' ),
706706
'dematerialized' => __( 'Dematerialized' ),
707-
'grouped' => __( 'Grouped' )
707+
'grouped' => __( 'Grouped' ),
708+
default => sprintf( __( 'Unknown Type: %s' ), $entry->type ),
708709
};
709710

710711
$entry->type = '<strong class="' . $class . ' ">' . $entry->type . '</strong>';

app/Crud/RegisterHistoryCrud.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ public function setActions( $entry, $namespace )
427427
case RegisterHistory::ACTION_CASHOUT:
428428
$entry->{ '$cssClass' } = 'warning border';
429429
break;
430+
case RegisterHistory::ACTION_CHANGE:
431+
$entry->{ '$cssClass' } = 'warning border';
432+
break;
430433
case RegisterHistory::ACTION_CLOSING:
431434
$entry->{ '$cssClass' } = 'warning border';
432435
break;

app/Crud/UserCrud.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public function canAccess( $fields )
350350
*
351351
* @return void
352352
*/
353-
public function beforeDelete( $namespace, $id, $model )
353+
public function beforeDelete( $namespace, int $id, $model )
354354
{
355355
if ( $namespace == 'ns.users' ) {
356356
$this->allowedTo( 'delete' );

app/Http/Controllers/Dashboard/CashRegistersController.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@
2121

2222
class CashRegistersController extends DashboardController
2323
{
24-
/**
25-
* @var CashRegistersService
26-
*/
27-
protected $registersService;
28-
2924
public function __construct(
30-
CashRegistersService $registersService
25+
protected CashRegistersService $registersService
3126
) {
3227
parent::__construct();
33-
$this->registersService = $registersService;
3428
}
3529

3630
public function listRegisters()
@@ -150,6 +144,9 @@ public function getSessionHistory( Register $register )
150144
case RegisterHistory::ACTION_CASHOUT:
151145
$session->label = __( 'Cash Out' );
152146
break;
147+
case RegisterHistory::ACTION_CHANGE:
148+
$session->label = __( 'Give Change' );
149+
break;
153150
case RegisterHistory::ACTION_CLOSING:
154151
$session->label = __( 'Closing' );
155152
break;

app/Http/Controllers/Dashboard/CrudController.php

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -52,75 +52,7 @@ public function crudDelete( $namespace, $id )
5252
throw new NotFoundException( __( 'Unable to delete an entry that no longer exists.' ) );
5353
}
5454

55-
if ( method_exists( $model, 'getDeclaredDependencies' ) ) {
56-
/**
57-
* Let's verify if the current model
58-
* is a dependency for other models.
59-
*/
60-
$declaredDependencies = $model->getDeclaredDependencies();
61-
62-
foreach ( $declaredDependencies as $class => $indexes ) {
63-
$localIndex = $indexes[ 'local_index' ] ?? 'id';
64-
$request = $class::where( $indexes[ 'foreign_index' ], $model->$localIndex );
65-
$dependencyFound = $request->first();
66-
$countDependency = $request->count() - 1;
67-
68-
if ( $dependencyFound instanceof $class ) {
69-
if ( isset( $model->{ $indexes[ 'local_name' ] } ) && ! empty( $indexes[ 'foreign_name' ] ) ) {
70-
/**
71-
* if the foreign name is an array
72-
* we'll pull the first model set as linked
73-
* to the item being deleted.
74-
*/
75-
if ( is_array( $indexes[ 'foreign_name' ] ) ) {
76-
$relatedSubModel = $indexes[ 'foreign_name' ][0]; // model name
77-
$localIndex = $indexes[ 'foreign_name' ][1]; // local index on the dependency table $dependencyFound
78-
$foreignIndex = $indexes[ 'foreign_name' ][2] ?? 'id'; // foreign index on the related table $model
79-
$labelColumn = $indexes[ 'foreign_name' ][3] ?? 'name'; // foreign index on the related table $model
80-
81-
/**
82-
* we'll find if we find the model
83-
* for the provided details.
84-
*/
85-
$result = $relatedSubModel::where( $foreignIndex, $dependencyFound->$localIndex )->first();
86-
87-
/**
88-
* the model might exists. If that doesn't exists
89-
* then probably it's not existing. There might be a misconfiguration
90-
* on the relation.
91-
*/
92-
if ( $result instanceof $relatedSubModel ) {
93-
$foreignName = $result->$labelColumn ?? __( 'Unidentified Item' );
94-
} else {
95-
$foreignName = $result->$labelColumn ?? __( 'Unexisting Item' );
96-
}
97-
} else {
98-
$foreignName = $dependencyFound->{ $indexes[ 'foreign_name' ] } ?? __( 'Unidentified Item' );
99-
}
100-
101-
/**
102-
* The local name will always pull from
103-
* the related model table.
104-
*/
105-
$localName = $model->{ $indexes[ 'local_name' ] };
106-
107-
throw new NotAllowedException( sprintf(
108-
__( 'Unable to delete "%s" as it\'s a dependency for "%s"%s' ),
109-
$localName,
110-
$foreignName,
111-
$countDependency >= 1 ? ' ' . trans_choice( '{1} and :count more item.|[2,*] and :count more items.', $countDependency, [ 'count' => $countDependency ] ) : '.'
112-
) );
113-
} else {
114-
throw new NotAllowedException( sprintf(
115-
$countDependency === 1 ?
116-
__( 'Unable to delete this resource as it has %s dependency with %s item.' ) :
117-
__( 'Unable to delete this resource as it has %s dependency with %s items.' ),
118-
$class
119-
) );
120-
}
121-
}
122-
}
123-
}
55+
$resource->handleDependencyForDeletion( $model );
12456

12557
/**
12658
* Run the filter before deleting

app/Http/Controllers/Dashboard/CustomersController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use App\Services\CustomerService;
2525
use App\Services\OrdersService;
2626
use Exception;
27+
use Illuminate\Database\Eloquent\Collection;
2728
use Illuminate\Http\Request;
2829
use Illuminate\Support\Facades\Validator;
2930
use Illuminate\Support\Facades\View;
@@ -66,6 +67,16 @@ public function listCustomers()
6667
return CustomerCrud::table();
6768
}
6869

70+
/**
71+
* Retreive few customers ordered by
72+
* their recent activity
73+
* @return Collection
74+
*/
75+
public function getRecentlyActive()
76+
{
77+
return $this->customerService->getRecentlyActive(10);
78+
}
79+
6980
/**
7081
* get list of avialable customers
7182
*

app/Jobs/ProcessCashRegisterHistoryFromPaymentJob.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Illuminate\Foundation\Bus\Dispatchable;
1212
use Illuminate\Queue\InteractsWithQueue;
1313

14+
/**
15+
* @deprecated
16+
*/
1417
class ProcessCashRegisterHistoryFromPaymentJob implements ShouldQueue
1518
{
1619
use Dispatchable, InteractsWithQueue, Queueable, NsSerialize;
@@ -32,9 +35,6 @@ public function __construct( public Order $order, public OrderPayment $orderPaym
3235
*/
3336
public function handle( CashRegistersService $cashRegistersService )
3437
{
35-
$cashRegistersService->increaseFromOrderPayment(
36-
order: $this->order,
37-
orderPayment: $this->orderPayment
38-
);
38+
// ...
3939
}
4040
}

app/Jobs/ProcessCashRegisterHistoryJob.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
namespace App\Jobs;
44

55
use App\Models\Order;
6-
use App\Models\Register;
7-
use App\Models\RegisterHistory;
6+
use App\Services\CashRegistersService;
87
use Illuminate\Bus\Queueable;
98
use Illuminate\Contracts\Queue\ShouldQueue;
109
use Illuminate\Foundation\Bus\Dispatchable;
@@ -30,23 +29,16 @@ public function __construct( public Order $order )
3029
*
3130
* @return void
3231
*/
33-
public function handle()
32+
public function handle( CashRegistersService $cashRegistersService )
3433
{
3534
/**
3635
* If the payment status changed from
3736
* supported payment status to a "Paid" status.
3837
*/
3938
if ( $this->order->register_id !== null && $this->order->payment_status === Order::PAYMENT_PAID ) {
40-
$register = Register::find( $this->order->register_id );
41-
42-
$registerHistory = new RegisterHistory;
43-
$registerHistory->balance_before = $register->balance;
44-
$registerHistory->value = $this->order->total;
45-
$registerHistory->balance_after = $register->balance + $this->order->total;
46-
$registerHistory->register_id = $this->order->register_id;
47-
$registerHistory->action = RegisterHistory::ACTION_SALE;
48-
$registerHistory->author = $this->order->author;
49-
$registerHistory->save();
39+
$cashRegistersService->recordCashRegisterHistorySale(
40+
order: $this->order
41+
);
5042
}
5143
}
5244
}

0 commit comments

Comments
 (0)