From 1e344d017e227da971009a3829e928db8f6dd0b3 Mon Sep 17 00:00:00 2001 From: Roberto Guido Date: Sat, 14 Sep 2024 19:45:37 +0200 Subject: [PATCH] ordine viene archiviato dopo pagamento. closes #285 --- .../MovementType/DonationFromGas.php | 18 +------- .../MovementType/InvoicePayment.php | 21 +-------- .../Parameters/MovementType/OrderPayment.php | 8 ++++ code/resources/views/order/edit.blade.php | 5 ++- .../Services/FastBookingsServiceTest.php | 7 ++- code/tests/Services/OrdersServiceTest.php | 43 +++++++++++++++++++ 6 files changed, 65 insertions(+), 37 deletions(-) diff --git a/code/app/Parameters/MovementType/DonationFromGas.php b/code/app/Parameters/MovementType/DonationFromGas.php index 31c9aa6e..a5534760 100644 --- a/code/app/Parameters/MovementType/DonationFromGas.php +++ b/code/app/Parameters/MovementType/DonationFromGas.php @@ -2,7 +2,7 @@ namespace App\Parameters\MovementType; -class DonationFromGas extends MovementType +class DonationFromGas extends GasExpense { public function identifier() { @@ -11,22 +11,8 @@ public function identifier() public function initNew($type) { + $type = parent::initNew($type); $type->name = _i('Donazione dal GAS'); - $type->sender_type = 'App\Gas'; - $type->target_type = null; - - $type->function = json_encode($this->voidFunctions([ - (object) [ - 'method' => 'cash', - 'sender' => $this->format(['cash' => 'decrement', 'gas' => 'decrement']), - ], - (object) [ - 'method' => 'bank', - 'sender' => $this->format(['bank' => 'decrement', 'gas' => 'decrement']), - 'is_default' => true, - ], - ])); - return $type; } } diff --git a/code/app/Parameters/MovementType/InvoicePayment.php b/code/app/Parameters/MovementType/InvoicePayment.php index 8659d4a1..9e453da0 100644 --- a/code/app/Parameters/MovementType/InvoicePayment.php +++ b/code/app/Parameters/MovementType/InvoicePayment.php @@ -4,7 +4,7 @@ use App\Movement; -class InvoicePayment extends MovementType +class InvoicePayment extends OrderPayment { public function identifier() { @@ -13,26 +13,9 @@ public function identifier() public function initNew($type) { + $type = parent::initNew($type); $type->name = _i('Pagamento fattura a fornitore'); - $type->sender_type = 'App\Gas'; $type->target_type = 'App\Invoice'; - $type->visibility = false; - $type->system = true; - - $type->function = json_encode($this->voidFunctions([ - (object) [ - 'method' => 'cash', - 'target' => $this->format(['bank' => 'decrement']), - 'sender' => $this->format(['cash' => 'decrement']), - ], - (object) [ - 'method' => 'bank', - 'target' => $this->format(['bank' => 'decrement']), - 'sender' => $this->format(['bank' => 'decrement']), - 'is_default' => true, - ] - ])); - return $type; } diff --git a/code/app/Parameters/MovementType/OrderPayment.php b/code/app/Parameters/MovementType/OrderPayment.php index b0bbcc4f..87f3e8c7 100644 --- a/code/app/Parameters/MovementType/OrderPayment.php +++ b/code/app/Parameters/MovementType/OrderPayment.php @@ -41,9 +41,17 @@ public function systemInit($mov) $mov->callbacks = [ 'post' => function (Movement $movement) { $movement->attachToTarget(); + + $order = $movement->target; + $order->status = 'archived'; + $order->save(); }, 'delete' => function(Movement $movement) { $movement->detachFromTarget(); + + $order = $movement->target; + $order->status = 'shipped'; + $order->save(); } ]; diff --git a/code/resources/views/order/edit.blade.php b/code/resources/views/order/edit.blade.php index 57d583f5..2355031f 100644 --- a/code/resources/views/order/edit.blade.php +++ b/code/resources/views/order/edit.blade.php @@ -116,7 +116,10 @@ 'label' => _i('Pagamento'), 'default' => \App\Movement::generate('order-payment', $currentgas, $order, $summary->price_delivered ?? 0), 'to_modal' => [ - 'amount_editable' => true + 'amount_editable' => true, + 'extra' => [ + 'reload-loadable' => '#order-list', + ], ], 'help_popover' => _i("Da qui è possibile immettere il movimento contabile di pagamento dell'ordine nei confronti del fornitore, che andrà ad alterare il relativo saldo"), ]) diff --git a/code/tests/Services/FastBookingsServiceTest.php b/code/tests/Services/FastBookingsServiceTest.php index 7fe3c245..b1a8520c 100644 --- a/code/tests/Services/FastBookingsServiceTest.php +++ b/code/tests/Services/FastBookingsServiceTest.php @@ -26,10 +26,12 @@ public function testFastShipping() $this->populateOrder($this->sample_order); $this->actingAs($this->userWithShippingPerms); - app()->make('FastBookingsService')->fastShipping($this->userWithShippingPerms, $this->sample_order->aggregate, null); + $order = app()->make('OrdersService')->show($this->sample_order->id); + app()->make('FastBookingsService')->fastShipping($this->userWithShippingPerms, $order->aggregate, null); $this->nextRound(); $order = app()->make('OrdersService')->show($this->sample_order->id); + $this->assertTrue($order->bookings->count() > 0); foreach($order->bookings as $booking) { $this->assertEquals($booking->status, 'shipped'); @@ -41,6 +43,9 @@ public function testFastShipping() $this->assertEquals($booking->payment->amount, $booking->getValue('effective', true)); } + + $summary = $order->aggregate->reduxData(); + $this->assertTrue($summary->price_delivered > 0); } /* diff --git a/code/tests/Services/OrdersServiceTest.php b/code/tests/Services/OrdersServiceTest.php index c2c8a563..404be14c 100644 --- a/code/tests/Services/OrdersServiceTest.php +++ b/code/tests/Services/OrdersServiceTest.php @@ -630,4 +630,47 @@ public function testChangeProductVariantPrice() $new_product = $order->products->firstWhere('id', $product->id); $this->assertFalse($product->comparePrices($new_product)); } + + /* + Registra il pagamento al fornitore + */ + public function testOrderPayment() + { + $this->populateOrder($this->order); + + $this->nextRound(); + + $this->actingAs($this->userWithShippingPerms); + $order = app()->make('OrdersService')->show($this->order->id); + $this->assertTrue($order->bookings()->count() > 0); + app()->make('FastBookingsService')->fastShipping($this->userWithShippingPerms, $order->aggregate, null); + + $this->nextRound(); + + $this->actingAs($this->userReferrer); + $order = app()->make('OrdersService')->show($this->order->id); + $summary = $order->aggregate->reduxData(); + $this->assertTrue($summary->price > 0); + + $this->actingAs($this->userAdmin); + $currency = defaultCurrency(); + + app()->make('MovementsService')->store(array( + 'type' => 'order-payment', + 'method' => 'bank', + 'sender_id' => $this->gas->id, + 'sender_type' => 'App\Gas', + 'target_id' => $this->order->id, + 'target_type' => 'App\Order', + 'currency_id' => $currency->id, + 'amount' => $summary->price, + )); + + $this->nextRound(); + + $this->actingAs($this->userReferrer); + $order = app()->make('OrdersService')->show($this->order->id); + $this->assertNotNull($order->payment); + $this->assertEquals('archived', $order->status); + } }