diff --git a/code/app/Booking.php b/code/app/Booking.php index e0461b70..1877216a 100644 --- a/code/app/Booking.php +++ b/code/app/Booking.php @@ -240,7 +240,6 @@ public function getValue($type, $with_friends, $force_recalculate = false) } foreach ($products as $booked) { - $booked->setRelation('booking', $obj); $value += $booked->getValue($type); } } @@ -385,6 +384,7 @@ public function getProductsWithFriendsAttribute() */ $products = new Collection(); foreach($this->products as $p) { + $p->setRelation('booking', $obj); $products->push($p); } @@ -392,6 +392,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)) { @@ -421,10 +423,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/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/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]; 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 @@