<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package FixMyStreet::App::Form::Waste::Garden;

use utf8;
use HTML::FormHandler::Moose;
extends 'FixMyStreet::App::Form::Waste';

has_field service_id =&gt; ( type =&gt; 'Hidden' );

sub details_update_fields {
    my $form = shift;
    my $data = $form-&gt;saved_data;
    my $c = $form-&gt;{c};

    # From first question
    my $existing = $data-&gt;{existing_number} || 0;
    $existing = 0 if $data-&gt;{existing} eq 'no';

    # From main form
    my $current_bins = $c-&gt;get_param('current_bins') || $form-&gt;saved_data-&gt;{current_bins} || $existing;
    my $bin_count = $c-&gt;get_param('bins_wanted') || $form-&gt;saved_data-&gt;{bins_wanted} || $existing;
    my $new_bins = $bin_count - $current_bins;

    my $cost_pa = $bin_count == 0 ? 0 : $form-&gt;{c}-&gt;cobrand-&gt;garden_waste_cost_pa($bin_count);
    my $cost_now_admin = $form-&gt;{c}-&gt;cobrand-&gt;garden_waste_new_bin_admin_fee($new_bins);
    $c-&gt;stash-&gt;{cost_pa} = $cost_pa / 100;
    $c-&gt;stash-&gt;{cost_now_admin} = $cost_now_admin / 100;
    if ($data-&gt;{apply_discount}) {
        (
            $c-&gt;stash-&gt;{cost_pa},
            $c-&gt;stash-&gt;{cost_now_admin},
            $c-&gt;stash-&gt;{per_bin_cost},
            $c-&gt;stash-&gt;{per_new_bin_cost},
            $c-&gt;stash-&gt;{per_new_bin_first_cost},
            ) =
        $c-&gt;cobrand-&gt;apply_garden_waste_discount(
            $c-&gt;stash-&gt;{cost_pa},
            $c-&gt;stash-&gt;{cost_now_admin},
            $c-&gt;stash-&gt;{per_bin_cost},
            $c-&gt;stash-&gt;{per_new_bin_cost},
            $c-&gt;stash-&gt;{per_new_bin_first_cost},
            );
    }
    $c-&gt;stash-&gt;{cost_now} = $c-&gt;stash-&gt;{cost_now_admin} + $c-&gt;stash-&gt;{cost_pa};
    my $max_bins = $c-&gt;stash-&gt;{garden_form_data}-&gt;{max_bins};

    return {
        current_bins =&gt; { default =&gt; $existing, range_end =&gt; $max_bins },
        bins_wanted =&gt; { default =&gt; $bin_count, range_end =&gt; $max_bins },
    };
}

sub with_sacks_choice { 0 }

has_page intro =&gt; (
    title_ggw =&gt; 'Subscribe to the %s',
    template =&gt; 'waste/garden/subscribe_intro.html',
    fields =&gt; ['continue', 'apply_discount'],
    update_field_list =&gt; sub {
        my $form = shift;
        my $data = $form-&gt;saved_data;
        $data-&gt;{_garden_sacks} = 1 if $form-&gt;with_sacks_choice;
        return {};
    },
    field_ignore_list =&gt; sub {
        my $page = shift;
        my $c = $page-&gt;form-&gt;c;
        if (!($c-&gt;stash-&gt;{waste_features}-&gt;{ggw_discount_as_percent}) || !($c-&gt;stash-&gt;{is_staff})) {
            return ['apply_discount']
        }
    },
    next =&gt; sub {
        return 'choice' if $_[0]-&gt;{_garden_sacks};
        'existing';
    }
);

has_page existing =&gt; (
    title_ggw =&gt; 'Subscribe to the %s',
    template =&gt; 'waste/garden/subscribe_existing.html',
    fields =&gt; ['existing', 'existing_number', 'continue'],
    next =&gt; 'details',
);

has_page details =&gt; (
    title_ggw =&gt; 'Subscribe to the %s',
    template =&gt; 'waste/garden/subscribe_details.html',
    fields =&gt; ['current_bins', 'bins_wanted', 'payment_method', 'cheque_reference', 'name', 'email', 'phone', 'password', 'email_renewal_reminders', 'continue_review'],
    field_ignore_list =&gt; sub {
        my $page = shift;
        my $c = $page-&gt;form-&gt;c;
        my @fields;
        push @fields, 'email_renewal_reminders' if !$c-&gt;cobrand-&gt;garden_subscription_email_renew_reminder_opt_in;
        push @fields, 'password' if $c-&gt;stash-&gt;{staff_payments_allowed} or $c-&gt;cobrand-&gt;call_hook('waste_password_hidden');
        push @fields, ('payment_method', 'cheque_reference') if $c-&gt;stash-&gt;{staff_payments_allowed} &amp;&amp; !$c-&gt;cobrand-&gt;waste_staff_choose_payment_method;
        return \@fields;
    },
    update_field_list =&gt; \&amp;details_update_fields,
    next =&gt; 'summary',
);

has_page summary =&gt; (
    fields =&gt; ['tandc', 'submit'],
    title =&gt; 'Submit container request',
    template =&gt; 'waste/garden/subscribe_summary.html',
    update_field_list =&gt; sub {
        my $form = shift;
        my $data = $form-&gt;saved_data;
        my $c = $form-&gt;{c};

        # Might not have these fields (e.g. SLWP), so include defaults
        my $current_bins = $data-&gt;{current_bins} || 0;
        my $bin_count = $data-&gt;{bins_wanted} || 1;
        my $new_bins = $bin_count - $current_bins;
        my $cost_pa;
        if (($data-&gt;{container_choice}||'') eq 'sack') {
            $cost_pa = $c-&gt;cobrand-&gt;garden_waste_sacks_cost_pa() * $bin_count;
        } else {
            $cost_pa = $c-&gt;cobrand-&gt;garden_waste_cost_pa($bin_count);
        }
        my $cost_now_admin = $c-&gt;cobrand-&gt;garden_waste_new_bin_admin_fee($new_bins);
        if ($data-&gt;{apply_discount}) {
            ($cost_pa, $cost_now_admin) = $c-&gt;cobrand-&gt;apply_garden_waste_discount(
                $cost_pa, $cost_now_admin);
        }

        my $total = $cost_now_admin + $cost_pa;

        $data-&gt;{cost_now_admin} = $cost_now_admin / 100;
        $data-&gt;{cost_pa} = $cost_pa / 100;
        $data-&gt;{display_total} = $total / 100;

        my $button_text = 'Continue to payment';
        my $features = $c-&gt;cobrand-&gt;feature('waste_features');
        if ($c-&gt;stash-&gt;{is_staff} &amp;&amp; $features-&gt;{text_for_waste_payment}) {
            $button_text = $features-&gt;{text_for_waste_payment};
        }
        return { submit =&gt; { value =&gt; $button_text }};
    },
    finished =&gt; sub {
        return $_[0]-&gt;wizard_finished('process_garden_data');
    },
    next =&gt; 'done',
);

has_page done =&gt; (
    title =&gt; 'Container request sent',
    template =&gt; 'waste/confirmation.html',
);

has_field existing =&gt; (
    type =&gt; 'Select',
    label =&gt; 'Do you already have one of these bins?',
    required =&gt; 1,
    tags =&gt; {
        hint =&gt; "For example, it may have been left at your house by the previous owner.",
    },
    widget =&gt; 'RadioGroup',
    options =&gt; [
        { value =&gt; 'yes', label =&gt; 'Yes', data_show =&gt; '#form-existing_number-row' },
        { value =&gt; 'no', label =&gt; 'No', data_hide =&gt; '#form-existing_number-row' },
    ],
);

has_field existing_number =&gt; (
    type =&gt; 'Integer',
    build_label_method =&gt; sub {
        my $self = shift;
        my $max_bins = $self-&gt;parent-&gt;{c}-&gt;stash-&gt;{garden_form_data}-&gt;{max_bins};
        return "How many? (1-$max_bins)";
    },
    validate_method =&gt; sub {
        my $self = shift;
        my $max_bins = $self-&gt;parent-&gt;{c}-&gt;stash-&gt;{garden_form_data}-&gt;{max_bins};
        if ( $self-&gt;parent-&gt;field('existing')-&gt;value eq 'yes' ) {
            $self-&gt;add_error('Please specify how many bins you already have')
                unless length $self-&gt;value;
            $self-&gt;add_error("Existing bin count must be between 1 and $max_bins")
                if $self-&gt;value &lt; 1 || $self-&gt;value &gt; $max_bins;
        } else {
            return 1;
        }
    },
);

has_field current_bins =&gt; (
    type =&gt; 'Integer',
    build_label_method =&gt; sub {
        my $self = shift;
        my $max_bins = $self-&gt;parent-&gt;{c}-&gt;stash-&gt;{garden_form_data}-&gt;{max_bins};
        return "Number of bins currently on site (0-$max_bins)";
    },
    required =&gt; 1,
    readonly =&gt; 1,
    range_start =&gt; 0,
);

sub bins_wanted_label_method {
    my ($self, $max_bins) = @_;
    $max_bins ||= $self-&gt;parent-&gt;{c}-&gt;stash-&gt;{garden_form_data}-&gt;{max_bins};
    return "Number of bins to be emptied (including bins already on site) (0-$max_bins)";
}

has_field bins_wanted =&gt; (
    type =&gt; 'Integer',
    build_label_method =&gt; \&amp;bins_wanted_label_method,
    required =&gt; 1,
    range_start =&gt; 1,
    tags =&gt; {
        hint =&gt; 'We will deliver, or remove, bins if this is different from the number of bins already on the property',
    },
);

has_field apply_discount =&gt; (
    type =&gt; 'Checkbox',
    build_label_method =&gt; sub {
        my $self = shift;
        my $percent = $self-&gt;parent-&gt;{c}-&gt;stash-&gt;{waste_features}-&gt;{ggw_discount_as_percent};
        return "$percent" . '% Customer discount';
    },
    option_label =&gt; 'Check box if customer is entitled to a discount',
);

with 'FixMyStreet::App::Form::Waste::Billing';

has_field password =&gt; (
    type =&gt; 'Password',
    label =&gt; 'Password (optional)',
    tags =&gt; {
        hint =&gt; 'Choose a password to sign in and manage your account in the future. If you donâ€™t pick a password, you will still be able to sign in by clicking a link in an email we send to you.',
    },
);

with 'FixMyStreet::App::Form::Waste::Garden::EmailRenewalReminders';

with 'FixMyStreet::App::Form::Waste::GardenTandC';

has_field continue =&gt; (
    type =&gt; 'Submit',
    value =&gt; 'Continue',
    element_attr =&gt; { class =&gt; 'govuk-button' },
    order =&gt; 999,
);

has_field continue_review =&gt; (
    type =&gt; 'Submit',
    value =&gt; 'Review subscription',
    element_attr =&gt; { class =&gt; 'govuk-button' },
);

has_field submit =&gt; (
    type =&gt; 'Submit',
    element_attr =&gt; { class =&gt; 'govuk-button' },
    order =&gt; 999,
);

sub validate {
    my $self = shift;
    $self-&gt;add_form_error('Please specify how many bins you already have')
        unless $self-&gt;field('existing')-&gt;is_inactive || $self-&gt;field('existing')-&gt;value eq 'no' || length $self-&gt;field('existing_number')-&gt;value;

    my $max_bins = $self-&gt;{c}-&gt;stash-&gt;{garden_form_data}-&gt;{max_bins};
    unless ( $self-&gt;field('current_bins')-&gt;is_inactive ) {
        my $total = $self-&gt;field('bins_wanted')-&gt;value;
        $self-&gt;add_form_error('The total number of bins cannot exceed ' . $max_bins)
            if $total &gt; $max_bins;

        $self-&gt;add_form_error('The total number of bins must be at least 1')
            if $total == 0;
    }

    $self-&gt;next::method();
}

1;
</pre></body></html>