issue #242 - make app caluclate number of vouchers for angels

main
tike 9 years ago
parent 1da3cba5a7
commit 661e5595c4

@ -47,6 +47,12 @@ $shift_sum_formula = "SUM(
))*(`Shifts`.`end` - `Shifts`.`start`)*(1 - 3 * `ShiftEntry`.`freeloaded`) ))*(`Shifts`.`end` - `Shifts`.`start`)*(1 - 3 * `ShiftEntry`.`freeloaded`)
)"; )";
// voucher calculation
$voucher_settings = array(
"initial_vouchers" => 2,
"shifts_per_voucher" => 1
);
// weigh every shift the same // weigh every shift the same
// $shift_sum_formula = "SUM(`end` - `start`)"; // $shift_sum_formula = "SUM(`end` - `start`)";

@ -84,6 +84,23 @@ function ShiftEntries_upcoming_for_user($user) {
"); ");
} }
/**
* Returns shifts completed by the given user.
*
* @param User $user
*/
function ShiftEntries_finished_by_user($user){
return sql_select("
SELECT *
FROM `ShiftEntry`
JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`)
JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id`
WHERE `ShiftEntry`.`UID`=" . sql_escape($user['UID']) . "
AND `Shifts`.`end` < " . sql_escape(time()) . "
ORDER BY `Shifts`.`end`
");
}
/** /**
* Returns all shift entries in given shift for given angeltype. * Returns all shift entries in given shift for given angeltype.
* *

@ -260,4 +260,19 @@ function User_generate_password_recovery_token(&$user) {
return $user['password_recovery_token']; return $user['password_recovery_token'];
} }
function User_get_eligable_voucher_count(&$user) {
global $voucher_settings;
$shifts_done = count(ShiftEntries_finished_by_user($user));
$earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers'];
$elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;
if ( $elegible_vouchers < 0) {
return 0;
}
return $elegible_vouchers;
}
?> ?>

@ -45,8 +45,10 @@ function User_edit_vouchers_view($user) {
buttons([ buttons([
button(user_link($user), glyph('chevron-left') . _("back")) button(user_link($user), glyph('chevron-left') . _("back"))
]), ]),
heading(sprintf(_("angel should receive at least %d vouchers."), User_get_eligable_voucher_count($user)), 3),
heading(_("This is a automatically calculated MINIMUM value, you can of course give out more if appropriate!"), 4),
form([ form([
form_spinner('vouchers', _("Number of vouchers"), $user['got_voucher']), form_spinner('vouchers', _("Number of vouchers given out"), $user['got_voucher']),
form_submit('submit', _("Save")) form_submit('submit', _("Save"))
], page_link_to('users') . '&action=edit_vouchers&user_id=' . $user['UID']) ], page_link_to('users') . '&action=edit_vouchers&user_id=' . $user['UID'])
]); ]);

@ -2402,6 +2402,24 @@ msgstr ""
"Du hast keinen Zugriff auf diese Seite. Registriere Dich und logge Dich " "Du hast keinen Zugriff auf diese Seite. Registriere Dich und logge Dich "
"bitte ein, um Zugriff zu erhalten!" "bitte ein, um Zugriff zu erhalten!"
#: /Users/msquare/workspace/projects/engelsystem/includes/view/User_view.php:49
msgid ""
"angel should receive at least %d vouchers."
msgstr ""
"Engel sollte mindestens %d voucher bekommen."
#: /Users/msquare/workspace/projects/engelsystem/includes/view/User_view.php:49
msgid ""
" vouchers."
msgstr ""
" Vouchers."
#: /Users/msquare/workspace/projects/engelsystem/includes/view/User_view.php:50
msgid ""
"This is a automatically calculated MINIMUM value, you can of course give out more if appropriate!"
msgstr ""
"Dies ist ein automatisch berechneter MINIMAL Wert, du kannst natürlich mehr ausgeben, wenn du es für angemessen hälst!"
#~ msgid "You have been signed off from the shift." #~ msgid "You have been signed off from the shift."
#~ msgstr "Du wurdest aus der Schicht ausgetragen." #~ msgstr "Du wurdest aus der Schicht ausgetragen."

Loading…
Cancel
Save