From 7496803f6147b6427dd9a14103a9c0187aeaffc6 Mon Sep 17 00:00:00 2001 From: Roberto Guido Date: Mon, 7 Oct 2024 10:53:18 +0200 Subject: [PATCH 1/3] movimenti extra in pagamento fattura. closes #287 --- code/app/Movement.php | 14 ++++++++++---- code/app/MovementType.php | 13 ++++++++++++- code/app/Services/InvoicesService.php | 7 ------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/code/app/Movement.php b/code/app/Movement.php index e990203f..0211cbbd 100644 --- a/code/app/Movement.php +++ b/code/app/Movement.php @@ -226,10 +226,16 @@ public static function generate($type, $sender, $target, $amount) { $ret = new self(); $ret->type = $type; - $ret->sender_type = get_class($sender); - $ret->sender_id = $sender->id; - $ret->target_type = get_class($target); - $ret->target_id = $target->id; + + if ($sender) { + $ret->sender_type = get_class($sender); + $ret->sender_id = $sender->id; + } + + if ($target) { + $ret->target_type = get_class($target); + $ret->target_id = $target->id; + } $type_descr = movementTypes($type); if ($type_descr->fixed_value != false) { diff --git a/code/app/MovementType.php b/code/app/MovementType.php index de5713b1..cc1d7d78 100644 --- a/code/app/MovementType.php +++ b/code/app/MovementType.php @@ -31,11 +31,22 @@ public function hasPayment($type) return array_key_exists($type, $valid); } + /* + Per identificare i tipi di movimento contabile che possono essere + utilizzati in fase di pagamento di una fattura. + Da notare che - controintuitivamente - vengono accolti anche i movimenti + circoscritti al GAS e che non coinvolgono il fornitore (o la fattura + stessa), per dare la possibilità di registrare altri movimenti in + qualche modo correlati (e.g. il costo del bonifico bancario, che non + intacca il saldo del fornitore ma solo quello del GAS) + */ public function validForInvoices() { return ( ($this->sender_type == 'App\Gas' && ($this->target_type == 'App\Supplier' || $this->target_type == 'App\Invoice')) || - ($this->sender_type == 'App\Supplier' && $this->target_type == 'App\Gas') + ($this->sender_type == 'App\Supplier' && $this->target_type == 'App\Gas') || + ($this->sender_type == 'App\Gas' && $this->target_type == null) || + ($this->sender_type == null && $this->target_type == 'App\Gas') ); } diff --git a/code/app/Services/InvoicesService.php b/code/app/Services/InvoicesService.php index 211c257c..59309650 100644 --- a/code/app/Services/InvoicesService.php +++ b/code/app/Services/InvoicesService.php @@ -185,9 +185,6 @@ private function guessPeer($invoice, $mov_target_type, $user) else if ($mov_target_type == Gas::class) { $peer = $user->gas; } - else { - \Log::error(_('Tipo movimento non riconosciuto durante il salvataggio della fattura')); - } return $peer; } @@ -219,10 +216,6 @@ public function saveMovements($id, $request) $type = $movement_types[$i]; list($sender, $target) = $this->movementAttach($type, $user, $invoice); - if (is_null($sender) || is_null($target)) { - continue; - } - $amount = $movement_amounts[$i]; $mov = Movement::generate($type, $sender, $target, $amount); $mov->notes = $movement_notes[$i]; From 1084232865bfe6ad22498ab43c1a62a32356c21e Mon Sep 17 00:00:00 2001 From: Roberto Guido Date: Sun, 13 Oct 2024 12:07:42 +0200 Subject: [PATCH 2/3] piccolo fix in gestione prodotti nelle prenotazioni --- code/app/Booking.php | 8 +++----- code/tests/Services/ModifiersServiceTest.php | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/code/app/Booking.php b/code/app/Booking.php index 26181b97..6f5469da 100644 --- a/code/app/Booking.php +++ b/code/app/Booking.php @@ -239,7 +239,6 @@ public function getValue($type, $with_friends, $force_recalculate = false) } foreach ($products as $booked) { - $booked->setRelation('booking', $obj); $value += $booked->getValue($type); } } @@ -384,6 +383,7 @@ public function getProductsWithFriendsAttribute() */ $products = new Collection(); foreach($this->products as $p) { + $p->setRelation('booking', $obj); $products->push($p); } @@ -391,6 +391,8 @@ public function getProductsWithFriendsAttribute() foreach($friends as $sub) { foreach($sub->products as $sub_p) { + $sub_p->setRelation('booking', $sub); + $master_p = $products->firstWhere('product_id', $sub_p->product_id); if (is_null($master_p)) { @@ -420,10 +422,6 @@ public function getProductsWithFriendsAttribute() return $a->product->name <=> $b->product->name; }); - $products = $products->map(function($a) use ($obj) { - return $a->setRelation('booking', $obj); - }); - return $products; }); } diff --git a/code/tests/Services/ModifiersServiceTest.php b/code/tests/Services/ModifiersServiceTest.php index 4c3a3594..ae9345cf 100644 --- a/code/tests/Services/ModifiersServiceTest.php +++ b/code/tests/Services/ModifiersServiceTest.php @@ -836,6 +836,7 @@ public function testWithFriend() $mods = $booking->applyModifiers(null, true); $this->assertEquals($mods->count(), 1); $second_initial_amount = $booking->getValue('booked', true); + $this->assertTrue($second_initial_amount > 0); $this->assertEquals($second_initial_amount, $initial_amount + $amount_of_friend); $second_initial_amount = $booking->getValue('effective', true); $this->assertEquals(round($second_initial_amount, 2), round(($initial_amount + $amount_of_friend) * 1.10, 2)); From 6d56d7730b1f5c41b5b2d6add3d37acd1b58a74c Mon Sep 17 00:00:00 2001 From: Roberto Guido Date: Sun, 13 Oct 2024 12:12:47 +0200 Subject: [PATCH 3/3] identificativo movimento in importazione csv. closes #292 --- code/app/Importers/CSV/Movements.php | 5 +++++ code/resources/views/import/csvmovementsselect.blade.php | 1 + 2 files changed, 6 insertions(+) diff --git a/code/app/Importers/CSV/Movements.php b/code/app/Importers/CSV/Movements.php index 0bc85301..0bdf9681 100644 --- a/code/app/Importers/CSV/Movements.php +++ b/code/app/Importers/CSV/Movements.php @@ -23,6 +23,9 @@ public function fields() 'amount' => (object) [ 'label' => _i('Valore'), ], + 'identifier' => (object) [ + 'label' => _i('Identificativo'), + ], 'notes' => (object) [ 'label' => _i('Note'), ], @@ -234,6 +237,7 @@ public function run($request) $types = $request->input('mtype', []); $methods = $request->input('method', []); $amounts = $request->input('amount', []); + $identifiers = $request->input('identifier', []); $currencies = $request->input('currency_id', []); $errors = []; @@ -249,6 +253,7 @@ public function run($request) $m->date = $dates[$index]; $m->type = $types[$index]; $m->amount = $amounts[$index]; + $m->identifier = $identifiers[$index]; $m->method = $methods[$index]; $m->currency_id = $currencies[$index]; $m->notes = $notes[$index]; diff --git a/code/resources/views/import/csvmovementsselect.blade.php b/code/resources/views/import/csvmovementsselect.blade.php index f3c21adb..456823d3 100644 --- a/code/resources/views/import/csvmovementsselect.blade.php +++ b/code/resources/views/import/csvmovementsselect.blade.php @@ -91,6 +91,7 @@ {{ printablePriceCurrency($mov->amount) }} +