On the way to have the offline deposits and withdrawals
[breadcrumbs.git] / src / lib / Bcd / Commands / TreasurerAcknowledgedCommand.pm
blob74d17421ac79893bf05070432b65b71d01748fe7
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 threads;
27 use threads::shared;
29 use base(qq/Bcd::Commands::SessionCommand/);
30 use Bcd::Errors::ErrorCodes;
31 use Bcd::Data::RealCurrency;
33 use Data::Dumper;
36 sub get_name{
37 return "bk.treasurer_acknowledged";
40 sub new {
41 my $class = shift;
42 my $self = $class->SUPER::new(@_);
44 #only the treasurer can make this
45 $self->{"privilege_required"} = Bcd::Data::Users::TREASURER_ROLE;
47 #I can have simply the booking id, not the token...
48 push (@{$self->{"parameters"}}, "id");
50 bless ($self, $class);
51 return $self;
54 sub _exec{
55 my ($self, $stash) = @_;
57 #this is a rather straigthforward command, I should simply control
58 #that the booking exists and it is in the right state...
60 my $booking_hash = Bcd::Data::Deposits->get_booking_from_id_hash($stash, $self->{id});
62 if (!defined($booking_hash)){
63 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_UNKNOWN_DEPOSIT;
64 return;
67 #let's see if it is in the right state
68 if ( $booking_hash->{status} != Bcd::Constants::DepositsConstants::CREATION_STATE){
69 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_INVALID_STATE;
70 return;
73 #this is only valid for a deposit...
74 if ( $booking_hash->{is_deposit} == 0){
75 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_THIS_BOOKING_IS_A_WITHDRAWAL;
76 return;
80 #let's see if the deposits are online...
81 my $code = $stash->get_session_post_code($self->{session_id});
83 my $online = Bcd::Data::Configuration->get_ant_nest_value
84 ($stash, $code, Bcd::Constants::ConfigurationKeys::DEPOSITS_ONLINE);
86 if ($online == 1){
87 #ok, I can send an email with the full receipt token
89 my $human_value = Bcd::Data::RealCurrency::humanize_this_string($booking_hash->{amount});
91 my $template_vars =
93 full_token => $booking_hash->{full_receipt_token},
94 amount => $human_value,
97 $self->_send_mail_to_user_with_id
98 ($stash, 'confirmed_online_deposit.tt2',
99 $booking_hash->{id_user}, $template_vars);
101 } else {
102 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_NOT_IMPLEMENTED;
103 return;
106 #Ok, seems all ok, now...
107 #Bcd::Data::Deposits->treasurer_acknowledged($stash, $self->{id});
108 Bcd::Data::Deposits->change_state_to_booking
109 ($stash, $booking_hash->{id}, Bcd::Constants::DepositsConstants::DEPOSIT_TAKEN_ONLINE);
111 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_OK;
115 #no specific output