#!perl # This plugin must at the end in the plugins file. HELP1 "deposit " => "Deposit into an account"; sub command :Tab(deposit) ($self, $cart, $command, @) { $command eq 'deposit' or return NEXT; my $prompt = "Amount to deposit into your account"; call_hooks("deposit_command", \$prompt, $self->{alternatives} = []); return $prompt, \&amount; } sub amount :Tab(13.37,42) ($self, $cart, $input, @) { for my $sub (@{ $self->{alternatives} }) { my @rv = $sub->(undef, $cart, $input); return @rv if $rv[0] != NEXT; } $self->{amount} = my $amount = parse_amount($input) or return REJECT, "Invalid input."; call_hooks("deposit_methods", \my $message, $self->{deposit_methods} = {}); return $message . "How are we receiving this $amount?", \&how if keys %{ $self->{deposit_methods} }; $cart ->add(+$amount, "Deposit", { is_deposit => 1 }) ->add_contra("-deposits/other", -$amount, "Deposited by \$you"); return ACCEPT; } sub how :Tab(&how_tab) ($self, $cart, $input, @) { my %methods = %{ $self->{deposit_methods} }; my $how = $self->{how} = $methods{$input} or return REJECT, "'$input' is not a valid answer."; $how->{_key} = $input; if (@{ $how->{prompts} // [] }) { return shift @{ $how->{prompts} }, \&how_prompt; } if ( ($input eq "iban") && ($self->{amount} < 10 || $self->{amount} == 25) ) { return REJECT, "\n\e[31;1mPlease transfer at least 10 EUR and not 25 or 32 EUR when using iban\e[0m\n\n"; } my $contra = $how->{_key} eq 'cash' ? '-cash' : $how->{_key} eq 'reimburse' ? '-expenses/reimbursed' : "-deposits/$how->{_key}"; $cart ->add(+$self->{amount}, $how->{description}, { is_deposit => 1, method => $how->{_key} }) ->add_contra($contra, -$self->{amount}, "$how->{description} by \$you"); return ACCEPT; } sub how_tab($self, @) { return keys %{ $self->{deposit_methods} }; } sub how_prompt($self, $cart, $input, @) { my $how = $self->{how}; push @{ $how->{answers} }, $input; if (@{ $how->{prompts} }) { return shift @{ $how->{prompts} }, \&how_prompt; } my $desc = sprintf $how->{description}, @{ $how->{answers} }; my $contra = $how->{_key} eq 'cash' ? '-cash' : "-deposits/$how->{_key}"; $cart ->add(+$self->{amount}, $desc, { is_deposit => 1, method => $how->{_key} }) ->add_contra($contra, -$self->{amount}, "$desc by \$you"); return ACCEPT; }