Skip to content

Commit

Permalink
movimenti extra in pagamento fattura. closes #287
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Oct 7, 2024
1 parent c4bc2e6 commit 7496803
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
14 changes: 10 additions & 4 deletions code/app/Movement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 12 additions & 1 deletion code/app/MovementType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
}

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

0 comments on commit 7496803

Please sign in to comment.