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
21 # Contact: lino.ferrentino@yahoo.it (in Italian, English or German).
26 use base
(qq/Bcd::Commands::SessionCommand/);
27 use Bcd
::Errors
::ErrorCodes
;
28 use Bcd
::Data
::RealCurrency
;
32 use constant NAME
=> "bk.treasurer_acknowledged";
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);
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
;
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
;
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
;
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
);
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
});
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);
100 $self->{exit_code
} = Bcd
::Errors
::ErrorCodes
::BEC_NOT_IMPLEMENTED
;
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
;