Skip to content

Commit

Permalink
Merge branch 'master' into aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Oct 13, 2024
2 parents 942d4db + 6d56d77 commit 95b0b79
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 17 deletions.
8 changes: 3 additions & 5 deletions code/app/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -385,13 +384,16 @@ public function getProductsWithFriendsAttribute()
*/
$products = new Collection();
foreach($this->products as $p) {
$p->setRelation('booking', $obj);
$products->push($p);
}

$friends = $this->friends_bookings;

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)) {
Expand Down Expand Up @@ -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;
});
}
Expand Down
5 changes: 5 additions & 0 deletions code/app/Importers/CSV/Movements.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public function fields()
'amount' => (object) [
'label' => _i('Valore'),
],
'identifier' => (object) [
'label' => _i('Identificativo'),
],
'notes' => (object) [
'label' => _i('Note'),
],
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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];
Expand Down
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
1 change: 1 addition & 0 deletions code/resources/views/import/csvmovementsselect.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<td>
{{ printablePriceCurrency($mov->amount) }}
<x-larastrap::hidden name="amount" npostfix="[]" />
<x-larastrap::hidden name="identifier" npostfix="[]" />
</td>
<td>
<x-larastrap::selectobj name="currency_id" npostfix="[]" squeeze :options="$currencies" classes="csv_movement_currency_select" />
Expand Down
1 change: 1 addition & 0 deletions code/tests/Services/ModifiersServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,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));
Expand Down

0 comments on commit 95b0b79

Please sign in to comment.