use Modern::Perl;
-use Carp;
+use Carp qw( carp croak );
use Text::CSV_XS;
use C4::Context;
-use C4::Debug;
-use C4::Suggestions;
-use C4::Biblio;
-use C4::Contract;
-use C4::Debug;
+use C4::Suggestions qw( GetSuggestion GetSuggestionFromBiblionumber ModSuggestion );
+use C4::Biblio qw( GetMarcFromKohaField GetMarcStructure IsMarcStructureInternal );
+use C4::Contract qw( GetContract );
+use C4::Log qw( logaction );
use C4::Templates qw(gettemplate);
use Koha::DateUtils qw( dt_from_string output_pref );
use Koha::Acquisition::Baskets;
use C4::Koha;
use MARC::Field;
-use MARC::Record;
+use JSON qw( to_json );
-use Time::localtime;
-
-use vars qw(@ISA @EXPORT);
+our (@ISA, @EXPORT_OK);
BEGIN {
require Exporter;
- @ISA = qw(Exporter);
- @EXPORT = qw(
- &GetBasket &NewBasket &CloseBasket &ReopenBasket &DelBasket &ModBasket
- &GetBasketAsCSV &GetBasketGroupAsCSV
- &GetBasketsByBookseller &GetBasketsByBasketgroup
- &GetBasketsInfosByBookseller
-
- &GetBasketUsers &ModBasketUsers
- &CanUserManageBasket
-
- &ModBasketHeader
-
- &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
- &GetBasketgroups &ReOpenBasketgroup
-
- &ModOrder &GetOrder &GetOrders &GetOrdersByBiblionumber
- &GetOrderFromItemnumber
- &SearchOrders &GetHistory &GetRecentAcqui
- &ModReceiveOrder &CancelReceipt
- &TransferOrder
- &ModItemOrder
-
- &GetParcels
-
- &GetInvoices
- &GetInvoice
- &GetInvoiceDetails
- &AddInvoice
- &ModInvoice
- &CloseInvoice
- &ReopenInvoice
- &DelInvoice
- &MergeInvoices
-
- &AddClaim
- &GetBiblioCountByBasketno
-
- &GetOrderUsers
- &ModOrderUsers
- &NotifyOrderUsers
-
- &FillWithDefaultValues
-
- &get_rounded_price
- &get_rounding_sql
+ @ISA = qw(Exporter);
+ @EXPORT_OK = qw(
+ GetBasket NewBasket ReopenBasket ModBasket
+ GetBasketAsCSV GetBasketGroupAsCSV
+ GetBasketsByBookseller GetBasketsByBasketgroup
+ GetBasketsInfosByBookseller
+
+ GetBasketUsers ModBasketUsers
+ CanUserManageBasket
+
+ ModBasketHeader
+
+ ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroup CloseBasketgroup
+ GetBasketgroups ReOpenBasketgroup
+
+ ModOrder GetOrder GetOrders GetOrdersByBiblionumber
+ GetOrderFromItemnumber
+ SearchOrders GetHistory GetRecentAcqui
+ ModReceiveOrder CancelReceipt
+ populate_order_with_prices
+ TransferOrder
+ ModItemOrder
+
+ GetParcels
+
+ GetInvoices
+ GetInvoice
+ GetInvoiceDetails
+ AddInvoice
+ ModInvoice
+ CloseInvoice
+ ReopenInvoice
+ DelInvoice
+ MergeInvoices
+
+ AddClaim
+ GetBiblioCountByBasketno
+
+ GetOrderUsers
+ ModOrderUsers
+ NotifyOrderUsers
+
+ FillWithDefaultValues
+
+ get_rounded_price
+ get_rounding_sql
);
}
$basketname ||= q{}; # default to empty strings
$basketnote ||= q{};
$basketbooksellernote ||= q{};
- ModBasketHeader( $basket, $basketname, $basketnote, $basketbooksellernote,
- $basketcontractnumber, $booksellerid, $deliveryplace, $billingplace, $is_standing, $create_items );
- return $basket;
-}
-
-#------------------------------------------------------------#
-
-=head3 CloseBasket
- &CloseBasket($basketno);
-
-close a basket (becomes unmodifiable, except for receives)
-
-=cut
+ # Log the basket creation
+ if (C4::Context->preference("AcquisitionLog")) {
+ my $created = Koha::Acquisition::Baskets->find( $basket );
+ logaction(
+ 'ACQUISITIONS',
+ 'ADD_BASKET',
+ $basket,
+ to_json($created->unblessed)
+ );
+ }
-sub CloseBasket {
- my ($basketno) = @_;
- my $dbh = C4::Context->dbh;
- $dbh->do('UPDATE aqbasket SET closedate=now() WHERE basketno=?', {}, $basketno );
+ ModBasketHeader( $basket, $basketname, $basketnote, $basketbooksellernote,
+ $basketcontractnumber, $booksellerid, $deliveryplace, $billingplace, $is_standing, $create_items );
- $dbh->do(
-q{UPDATE aqorders SET orderstatus = 'ordered' WHERE basketno = ? AND orderstatus NOT IN ( 'complete', 'cancelled')},
- {}, $basketno
- );
- return;
+ return $basket;
}
=head3 ReopenBasket
WHERE basketno = ?
AND orderstatus NOT IN ( 'complete', 'cancelled' )
}, {}, $basketno);
+
+ # Log the basket reopening
+ if (C4::Context->preference("AcquisitionLog")) {
+ my $reopened = Koha::Acquisition::Baskets->find( $basketno );
+ logaction(
+ 'ACQUISITIONS',
+ 'REOPEN_BASKET',
+ $basketno,
+ to_json($reopened->unblessed)
+ );
+ }
return;
}
#------------------------------------------------------------#
-
-=head3 DelBasket
-
- &DelBasket($basketno);
-
-Deletes the basket that has basketno field $basketno in the aqbasket table.
-
-=over
-
-=item C<$basketno> is the primary key of the basket in the aqbasket table.
-
-=back
-
-=cut
-
-sub DelBasket {
- my ( $basketno ) = @_;
- my $query = "DELETE FROM aqbasket WHERE basketno=?";
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare($query);
- $sth->execute($basketno);
- return;
-}
-
-#------------------------------------------------------------#
-
=head3 ModBasket
&ModBasket($basketinfo);
my $sth = $dbh->prepare($query);
$sth->execute(@params);
+ # Log the basket update
+ if (C4::Context->preference("AcquisitionLog")) {
+ my $modified = Koha::Acquisition::Baskets->find(
+ $basketinfo->{basketno}
+ );
+ logaction(
+ 'ACQUISITIONS',
+ 'MODIFY_BASKET',
+ $basketinfo->{basketno},
+ to_json($modified->unblessed)
+ );
+ }
+
return;
}
my $sth2 = $dbh->prepare($query2);
$sth2->execute($contractnumber,$basketno);
}
+
+ # Log the basket update
+ if (C4::Context->preference("AcquisitionLog")) {
+ my $modified = Koha::Acquisition::Baskets->find(
+ $basketno
+ );
+ logaction(
+ 'ACQUISITIONS',
+ 'MODIFY_BASKET_HEADER',
+ $basketno,
+ to_json($modified->unblessed)
+ );
+ }
+
return;
}
foreach my $basketuser_id (@basketusers_ids) {
$sth->execute($basketno, $basketuser_id);
}
+
+ # Log the basket update
+ if (C4::Context->preference("AcquisitionLog")) {
+ logaction(
+ 'ACQUISITIONS',
+ 'MODIFY_BASKET_USERS',
+ $basketno,
+ to_json({
+ basketno => $basketno,
+ basketusers => @basketusers_ids
+ })
+ );
+ }
+
return;
}
my $isbn = $params{isbn};
my $ean = $params{ean};
my $name = $params{name};
+ my $internalnote = $params{internalnote};
+ my $vendornote = $params{vendornote};
my $from_placed_on = $params{from_placed_on};
my $to_placed_on = $params{to_placed_on};
my $basket = $params{basket};
aqorders.biblionumber,
aqorders.orderstatus,
aqorders.parent_ordernumber,
+ aqorders.order_internalnote,
+ aqorders.order_vendornote,
aqbudgets.budget_name
";
$query .= ", aqbudgets.budget_id AS budget" if defined $budget;
}
}
+ if ( $internalnote ) {
+ $query .= " AND aqorders.order_internalnote LIKE ? ";
+ push @query_params, "%$internalnote%";
+ }
+
+ if ( $vendornote ) {
+ $query .= " AND aqorders.order_vendornote LIKE ?";
+ push @query_params, "%$vendornote%";
+ }
+
if ($booksellerinvoicenumber) {
$query .= " AND aqinvoices.invoicenumber LIKE ? ";
push @query_params, "%$booksellerinvoicenumber%";
push @query_params, @$ordernumbers;
}
if ( @$additional_fields ) {
- my @baskets = Koha::Acquisition::Baskets->filter_by_additional_fields($additional_fields);
+ my @baskets = Koha::Acquisition::Baskets->filter_by_additional_fields($additional_fields)->as_list;
return [] unless @baskets;
# tax value = quantity * ecost tax excluded * tax rate
# we should use the unitprice if included
- my $cost_tax_included = $order->{unitprice_tax_included} || $order->{ecost_tax_included};
- my $cost_tax_excluded = $order->{unitprice_tax_excluded} || $order->{ecost_tax_excluded};
+ my $cost_tax_included = $order->{unitprice_tax_included} == 0 ? $order->{ecost_tax_included} : $order->{unitprice_tax_included};
+ my $cost_tax_excluded = $order->{unitprice_tax_excluded} == 0 ? $order->{ecost_tax_excluded} : $order->{unitprice_tax_excluded};
$order->{tax_value_on_ordering} = ( get_rounded_price($cost_tax_included) - get_rounded_price($cost_tax_excluded) ) * $order->{quantity};
}
# tax value = quantity * ecost tax included * tax rate
# we should use the unitprice if included
- my $cost_tax_excluded = $order->{unitprice_tax_excluded} || $order->{ecost_tax_excluded};
+ my $cost_tax_excluded = $order->{unitprice_tax_excluded} == 0 ? $order->{ecost_tax_excluded} : $order->{unitprice_tax_excluded};
$order->{tax_value_on_ordering} = $order->{quantity} * get_rounded_price($cost_tax_excluded) * $order->{tax_rate_on_ordering};
}
}