#!/usr/bin/perl -Ilibs

package API::Purchasing;

use strict;
use warnings;
use autodie;

use Carp;
use Moose;
use Try::Tiny;

use API::Controller;
extends 'API::Controller';

use ECS::Purchasing::PR;
use PerlX::Maybe;

__PACKAGE__->meta->make_immutable;

return 1;

###############################################################################

sub receive {
    my $self = (shift)->new({'input' => shift || {}});

    croak "Missing prID" unless $self->input->{'prID'};


    my %result;
    chomp(
        @result{qw/success error/} = ECS::Purchasing::PR::sendToReceiving({
            'DBH'  => $self->dbh,
            'prID' => $self->input->{'prID'},
            'info' => {
                maybe 'employee_id' => $self->input->{'employee_id'},
                maybe 'vendorPortalUserID' => $self->input->{'vendorPortalUserID'},
                maybe 'printer'     => $self->input->{'printer'},
            },
        })
    );
    if ($result{success}) {
        $self->success(1);
    } else {
        $self->error( $result{error} || "" );
    }

    return $self->result;
}

###############################################################################
