Now I tell the gpg the <home dir> of the keyring
[breadcrumbs.git] / src / lib / Bcd / Commands / TreasurerAcknowledgedCommand.pm
blobfefe9f97b56c86ced6941fcef9d7ec7d2a2f7bff
1 package Bcd::Commands::TreasurerAcknowledgedCommand;
3 # This file is part of the breadcrumbs daemon (bcd).
4 # Copyright (C) 2007 Pasqualino Ferrentino
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
21 # Contact: lino.ferrentino@yahoo.it (in Italian, English or German).
23 use strict;
24 use warnings;
26 use base(qq/Bcd::Commands::SessionCommand/);
27 use Bcd::Errors::ErrorCodes;
28 use Bcd::Data::RealCurrency;
30 use Data::Dumper;
32 use constant NAME => "bk.treasurer_acknowledged";
34 sub get_name{
35 return NAME;
38 sub new {
39 my $class = shift;
40 my $self = $class->SUPER::new(@_);
42 #only the treasurer can make this
43 $self->{"privilege_required"} = Bcd::Data::Users::TREASURER_ROLE;
45 #I can have simply the booking id, not the token...
46 push (@{$self->{"parameters"}}, "id");
48 bless ($self, $class);
49 return $self;
52 sub _exec{
53 my ($self, $stash) = @_;
55 #this is a rather straigthforward command, I should simply control
56 #that the booking exists and it is in the right state...
58 my $booking_hash = Bcd::Data::Deposits->get_booking_from_id_hash($stash, $self->{id});
60 if (!defined($booking_hash)){
61 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_UNKNOWN_DEPOSIT;
62 return;
65 #let's see if it is in the right state
66 if ( $booking_hash->{status} != Bcd::Constants::DepositsConstants::CREATION_STATE){
67 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_INVALID_STATE;
68 return;
71 #this is only valid for a deposit...
72 if ( $booking_hash->{is_deposit} == 0){
73 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_THIS_BOOKING_IS_A_WITHDRAWAL;
74 return;
78 #let's see if the deposits are online...
79 my $code = $stash->get_session_post_code($self->{session_id});
81 my $online = Bcd::Data::Configuration->get_ant_nest_value
82 ($stash, $code, Bcd::Constants::ConfigurationKeys::DEPOSITS_ONLINE);
84 if ($online == 1){
85 #ok, I can send an email with the full receipt token
87 my $human_value = Bcd::Data::RealCurrency::humanize_this_string($booking_hash->{amount});
89 my $template_vars =
91 full_token => $booking_hash->{full_receipt_token},
92 amount => $human_value,
95 $self->_send_mail_to_user_with_id
96 ($stash, 'confirmed_online_deposit.tt2',
97 $booking_hash->{id_user}, $template_vars);
99 } else {
100 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_NOT_IMPLEMENTED;
101 return;
104 #Ok, seems all ok, now...
105 #Bcd::Data::Deposits->treasurer_acknowledged($stash, $self->{id});
106 Bcd::Data::Deposits->change_state_to_booking
107 ($stash, $booking_hash->{id}, Bcd::Constants::DepositsConstants::DEPOSIT_TAKEN_ONLINE);
109 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_OK;
113 #no specific output