Skip to content

Commit

Permalink
ordine viene archiviato dopo pagamento. closes #285
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Sep 14, 2024
1 parent 671f1ba commit 1e344d0
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 37 deletions.
18 changes: 2 additions & 16 deletions code/app/Parameters/MovementType/DonationFromGas.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Parameters\MovementType;

class DonationFromGas extends MovementType
class DonationFromGas extends GasExpense
{
public function identifier()
{
Expand All @@ -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;
}
}
21 changes: 2 additions & 19 deletions code/app/Parameters/MovementType/InvoicePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Movement;

class InvoicePayment extends MovementType
class InvoicePayment extends OrderPayment
{
public function identifier()
{
Expand All @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions code/app/Parameters/MovementType/OrderPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
];

Expand Down
5 changes: 4 additions & 1 deletion code/resources/views/order/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
])
Expand Down
7 changes: 6 additions & 1 deletion code/tests/Services/FastBookingsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
}

/*
Expand Down
43 changes: 43 additions & 0 deletions code/tests/Services/OrdersServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 1e344d0

Please sign in to comment.