Bug correction in amount for users when guests are here

This commit is contained in:
Phyks 2013-09-23 23:07:37 +02:00
parent 8ac3a84f6a
commit 05b2a1c929

View File

@ -19,7 +19,7 @@
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
$this->users_in = new UsersIn(); $this->users_in = new UsersIn('invoice');
} }
// Getters // Getters
@ -89,11 +89,15 @@
// Get the amount to pay by person // Get the amount to pay by person
// =============================== // ===============================
public function getAmountPerPerson($id) { public function getAmountPerPerson($id) {
$guests = $this->users_in->get(); $users_in = $this->users_in->get();
$guests = $guests[(int) $id]; $guests = 0;
foreach($users_in as $user=>$guests_user) {
$guests += (int) $guests_user;
}
// Amount is stored in cents // Amount is stored in cents
return round($this->amount / 100 / (count($this->users_in->get()) + $guests), 2); return round($this->amount / 100 / (count($users_in) + $guests) * (1 + $users_in[(int) $id]), 2); // Note : $users_in[(int) $id] is the number of guests for user $id
} }
// Maps htmlspecialchars on the class before display // Maps htmlspecialchars on the class before display