# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-use strict;
-use warnings;
+use Modern::Perl;
use Carp;
use C4::Context;
use C4::Debug;
use MARC::Record;
use C4::Suggestions;
use C4::Biblio;
+use C4::Contract;
use C4::Debug;
-use C4::SQLHelper qw(InsertInTable UpdateInTable);
use C4::Bookseller qw(GetBookSellerFromId);
use C4::Templates qw(gettemplate);
&NewOrderItem &ModItemOrder
&GetParcels &GetParcel
- &GetContracts &GetContract
&GetInvoices
&GetInvoice
my ($basketno, $cgi) = @_;
my $basket = GetBasket($basketno);
my @orders = GetOrders($basketno);
- my $contract = GetContract($basket->{'contractnumber'});
+ my $contract = GetContract({
+ contractnumber => $basket->{'contractnumber'}
+ });
my $template = C4::Templates::gettemplate("acqui/csv/basket.tt", "intranet", $cgi);
my @rows;
for my $basket (@$baskets) {
- my @orders = GetOrders( $$basket{basketno} );
- my $contract = GetContract( $$basket{contractnumber} );
+ my @orders = GetOrders( $basket->{basketno} );
+ my $contract = GetContract({
+ contractnumber => $basket->{contractnumber}
+ });
my $bookseller = GetBookSellerFromId( $$basket{booksellerid} );
my $basketgroup = GetBasketgroup( $$basket{basketgroupid} );
croak "Mandatory parameter $key missing" unless $orderinfo->{$key};
}
- if ( defined $orderinfo->{subscription} && $orderinfo->{'subscription'} eq 'yes' ) {
- $orderinfo->{'subscription'} = 1;
- } else {
- $orderinfo->{'subscription'} = 0;
- }
$orderinfo->{'entrydate'} ||= C4::Dates->new()->output("iso");
if (!$orderinfo->{quantityreceived}) {
$orderinfo->{quantityreceived} = 0;
}
- my $ordernumber=InsertInTable("aqorders",$orderinfo);
- if (not $orderinfo->{parent_ordernumber}) {
+ # get only the columns of Aqorder
+ my $schema = Koha::Database->new()->schema;
+ my $columns = ' '.join(' ', $schema->source('Aqorder')->columns).' ';
+ my $new_order = { map { $columns =~ / $_ / ? ($_ => $orderinfo->{$_}) : () } keys(%$orderinfo) };
+
+ my $rs = $schema->resultset('Aqorder');
+ my $ordernumber = $rs->create($new_order)->id;
+ if (not $new_order->{parent_ordernumber}) {
my $sth = $dbh->prepare("
UPDATE aqorders
SET parent_ordernumber = ordernumber
");
$sth->execute($ordernumber);
}
- return ( $orderinfo->{'basketno'}, $ordernumber );
+ return ( $new_order->{'basketno'}, $ordernumber );
}
$sth->execute( $bibnum, $ordernumber );
my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
foreach my $itemnumber (@itemnumbers){
- C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
+ C4::Items::DelItem(
+ {
+ biblionumber => $bibnum,
+ itemnumber => $itemnumber
+ }
+ );
}
return;
}
return $results;
}
-=head3 GetContracts
-
- $contractlist = &GetContracts($booksellerid, $activeonly);
-
-Looks up the contracts that belong to a bookseller
-
-Returns a list of contracts
-
-=over
-
-=item C<$booksellerid> is the "id" field in the "aqbooksellers" table.
-
-=item C<$activeonly> if exists get only contracts that are still active.
-
-=back
-
-=cut
-
-sub GetContracts {
- my ( $booksellerid, $activeonly ) = @_;
- my $dbh = C4::Context->dbh;
- my $query;
- if (! $activeonly) {
- $query = "
- SELECT *
- FROM aqcontract
- WHERE booksellerid=?
- ";
- } else {
- $query = "SELECT *
- FROM aqcontract
- WHERE booksellerid=?
- AND contractenddate >= CURDATE( )";
- }
- my $result_set =
- $dbh->selectall_arrayref( $query, { Slice => {} }, $booksellerid );
- return @{$result_set};
-}
-
#------------------------------------------------------------#
-=head3 GetContract
-
- $contract = &GetContract($contractID);
-
-Looks up the contract that has PRIMKEY (contractnumber) value $contractID
-
-Returns a contract
-
-=cut
-
-sub GetContract {
- my ( $contractno ) = @_;
- my $dbh = C4::Context->dbh;
- my $query = "
- SELECT *
- FROM aqcontract
- WHERE contractnumber=?
- ";
-
- my $sth = $dbh->prepare($query);
- $sth->execute( $contractno );
- my $result = $sth->fetchrow_hashref;
- return $result;
-}
-
=head3 AddClaim
=over