|
Lines 62-67
BEGIN {
Link Here
|
| 62 |
&GetParcels &GetParcel |
62 |
&GetParcels &GetParcel |
| 63 |
&GetContracts &GetContract |
63 |
&GetContracts &GetContract |
| 64 |
|
64 |
|
|
|
65 |
&GetInvoices |
| 66 |
&GetInvoice |
| 67 |
&GetInvoiceDetails |
| 68 |
&AddInvoice |
| 69 |
&ModInvoice |
| 70 |
&CloseInvoice |
| 71 |
&ReopenInvoice |
| 72 |
|
| 65 |
&GetItemnumbersFromOrder |
73 |
&GetItemnumbersFromOrder |
| 66 |
|
74 |
|
| 67 |
&AddClaim |
75 |
&AddClaim |
|
Lines 1146-1160
sub GetCancelledOrders {
Link Here
|
| 1146 |
=head3 ModReceiveOrder |
1154 |
=head3 ModReceiveOrder |
| 1147 |
|
1155 |
|
| 1148 |
&ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user, |
1156 |
&ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user, |
| 1149 |
$unitprice, $booksellerinvoicenumber, $biblioitemnumber, |
1157 |
$unitprice, $invoiceid, $biblioitemnumber, |
| 1150 |
$freight, $bookfund, $rrp); |
1158 |
$bookfund, $rrp, \@received_itemnumbers); |
| 1151 |
|
1159 |
|
| 1152 |
Updates an order, to reflect the fact that it was received, at least |
1160 |
Updates an order, to reflect the fact that it was received, at least |
| 1153 |
in part. All arguments not mentioned below update the fields with the |
1161 |
in part. All arguments not mentioned below update the fields with the |
| 1154 |
same name in the aqorders table of the Koha database. |
1162 |
same name in the aqorders table of the Koha database. |
| 1155 |
|
1163 |
|
| 1156 |
If a partial order is received, splits the order into two. The received |
1164 |
If a partial order is received, splits the order into two. |
| 1157 |
portion must have a booksellerinvoicenumber. |
|
|
| 1158 |
|
1165 |
|
| 1159 |
Updates the order with bibilionumber C<$biblionumber> and ordernumber |
1166 |
Updates the order with bibilionumber C<$biblionumber> and ordernumber |
| 1160 |
C<$ordernumber>. |
1167 |
C<$ordernumber>. |
|
Lines 1165-1171
C<$ordernumber>.
Link Here
|
| 1165 |
sub ModReceiveOrder { |
1172 |
sub ModReceiveOrder { |
| 1166 |
my ( |
1173 |
my ( |
| 1167 |
$biblionumber, $ordernumber, $quantrec, $user, $cost, |
1174 |
$biblionumber, $ordernumber, $quantrec, $user, $cost, |
| 1168 |
$invoiceno, $freight, $rrp, $budget_id, $datereceived, $received_items |
1175 |
$invoiceid, $rrp, $budget_id, $datereceived, $received_items |
| 1169 |
) |
1176 |
) |
| 1170 |
= @_; |
1177 |
= @_; |
| 1171 |
my $dbh = C4::Context->dbh; |
1178 |
my $dbh = C4::Context->dbh; |
|
Lines 1191-1204
sub ModReceiveOrder {
Link Here
|
| 1191 |
UPDATE aqorders |
1198 |
UPDATE aqorders |
| 1192 |
SET quantityreceived=? |
1199 |
SET quantityreceived=? |
| 1193 |
, datereceived=? |
1200 |
, datereceived=? |
| 1194 |
, booksellerinvoicenumber=? |
1201 |
, invoiceid=? |
| 1195 |
, unitprice=? |
1202 |
, unitprice=? |
| 1196 |
, freight=? |
|
|
| 1197 |
, rrp=? |
1203 |
, rrp=? |
| 1198 |
, quantity=? |
1204 |
, quantity=? |
| 1199 |
WHERE biblionumber=? AND ordernumber=?"); |
1205 |
WHERE biblionumber=? AND ordernumber=?"); |
| 1200 |
|
1206 |
|
| 1201 |
$sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$quantrec,$biblionumber,$ordernumber); |
1207 |
$sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$quantrec,$biblionumber,$ordernumber); |
| 1202 |
$sth->finish; |
1208 |
$sth->finish; |
| 1203 |
|
1209 |
|
| 1204 |
# create a new order for the remaining items, and set its bookfund. |
1210 |
# create a new order for the remaining items, and set its bookfund. |
|
Lines 1222-1231
sub ModReceiveOrder {
Link Here
|
| 1222 |
} |
1228 |
} |
| 1223 |
} else { |
1229 |
} else { |
| 1224 |
$sth=$dbh->prepare("update aqorders |
1230 |
$sth=$dbh->prepare("update aqorders |
| 1225 |
set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?, |
1231 |
set quantityreceived=?,datereceived=?,invoiceid=?, |
| 1226 |
unitprice=?,freight=?,rrp=? |
1232 |
unitprice=?,rrp=? |
| 1227 |
where biblionumber=? and ordernumber=?"); |
1233 |
where biblionumber=? and ordernumber=?"); |
| 1228 |
$sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber); |
1234 |
$sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$biblionumber,$ordernumber); |
| 1229 |
$sth->finish; |
1235 |
$sth->finish; |
| 1230 |
} |
1236 |
} |
| 1231 |
return $datereceived; |
1237 |
return $datereceived; |
|
Lines 1384-1392
sub GetParcel {
Link Here
|
| 1384 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
1390 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
| 1385 |
LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber |
1391 |
LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber |
| 1386 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
1392 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
|
|
1393 |
LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid |
| 1387 |
WHERE |
1394 |
WHERE |
| 1388 |
aqbasket.booksellerid = ? |
1395 |
aqbasket.booksellerid = ? |
| 1389 |
AND aqorders.booksellerinvoicenumber LIKE ? |
1396 |
AND aqinvoices.invoicenumber LIKE ? |
| 1390 |
AND aqorders.datereceived = ? "; |
1397 |
AND aqorders.datereceived = ? "; |
| 1391 |
|
1398 |
|
| 1392 |
my @query_params = ( $supplierid, $code, $datereceived ); |
1399 |
my @query_params = ( $supplierid, $code, $datereceived ); |
|
Lines 1459-1476
sub GetParcels {
Link Here
|
| 1459 |
my $dbh = C4::Context->dbh; |
1466 |
my $dbh = C4::Context->dbh; |
| 1460 |
my @query_params = (); |
1467 |
my @query_params = (); |
| 1461 |
my $strsth =" |
1468 |
my $strsth =" |
| 1462 |
SELECT aqorders.booksellerinvoicenumber, |
1469 |
SELECT aqinvoices.invoicenumber, |
| 1463 |
datereceived,purchaseordernumber, |
1470 |
datereceived,purchaseordernumber, |
| 1464 |
count(DISTINCT biblionumber) AS biblio, |
1471 |
count(DISTINCT biblionumber) AS biblio, |
| 1465 |
sum(quantity) AS itemsexpected, |
1472 |
sum(quantity) AS itemsexpected, |
| 1466 |
sum(quantityreceived) AS itemsreceived |
1473 |
sum(quantityreceived) AS itemsreceived |
| 1467 |
FROM aqorders LEFT JOIN aqbasket ON aqbasket.basketno = aqorders.basketno |
1474 |
FROM aqorders LEFT JOIN aqbasket ON aqbasket.basketno = aqorders.basketno |
|
|
1475 |
LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid |
| 1468 |
WHERE aqbasket.booksellerid = ? and datereceived IS NOT NULL |
1476 |
WHERE aqbasket.booksellerid = ? and datereceived IS NOT NULL |
| 1469 |
"; |
1477 |
"; |
| 1470 |
push @query_params, $bookseller; |
1478 |
push @query_params, $bookseller; |
| 1471 |
|
1479 |
|
| 1472 |
if ( defined $code ) { |
1480 |
if ( defined $code ) { |
| 1473 |
$strsth .= ' and aqorders.booksellerinvoicenumber like ? '; |
1481 |
$strsth .= ' and aqinvoices.invoicenumber like ? '; |
| 1474 |
# add a % to the end of the code to allow stemming. |
1482 |
# add a % to the end of the code to allow stemming. |
| 1475 |
push @query_params, "$code%"; |
1483 |
push @query_params, "$code%"; |
| 1476 |
} |
1484 |
} |
|
Lines 1485-1491
sub GetParcels {
Link Here
|
| 1485 |
push @query_params, $dateto; |
1493 |
push @query_params, $dateto; |
| 1486 |
} |
1494 |
} |
| 1487 |
|
1495 |
|
| 1488 |
$strsth .= "group by aqorders.booksellerinvoicenumber,datereceived "; |
1496 |
$strsth .= "group by aqinvoices.invoicenumber,datereceived "; |
| 1489 |
|
1497 |
|
| 1490 |
# can't use a placeholder to place this column name. |
1498 |
# can't use a placeholder to place this column name. |
| 1491 |
# but, we could probably be checking to make sure it is a column that will be fetched. |
1499 |
# but, we could probably be checking to make sure it is a column that will be fetched. |
|
Lines 1701-1707
sub GetHistory {
Link Here
|
| 1701 |
aqorders.quantityreceived, |
1709 |
aqorders.quantityreceived, |
| 1702 |
aqorders.ecost, |
1710 |
aqorders.ecost, |
| 1703 |
aqorders.ordernumber, |
1711 |
aqorders.ordernumber, |
| 1704 |
aqorders.booksellerinvoicenumber as invoicenumber, |
1712 |
aqinvoices.invoicenumber, |
| 1705 |
aqbooksellers.id as id, |
1713 |
aqbooksellers.id as id, |
| 1706 |
aqorders.biblionumber |
1714 |
aqorders.biblionumber |
| 1707 |
FROM aqorders |
1715 |
FROM aqorders |
|
Lines 1709-1715
sub GetHistory {
Link Here
|
| 1709 |
LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid=aqbasketgroups.id |
1717 |
LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid=aqbasketgroups.id |
| 1710 |
LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id |
1718 |
LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id |
| 1711 |
LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber |
1719 |
LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber |
| 1712 |
LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber"; |
1720 |
LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber |
|
|
1721 |
LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid"; |
| 1713 |
|
1722 |
|
| 1714 |
$query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber" |
1723 |
$query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber" |
| 1715 |
if ( C4::Context->preference("IndependantBranches") ); |
1724 |
if ( C4::Context->preference("IndependantBranches") ); |
|
Lines 1763-1770
sub GetHistory {
Link Here
|
| 1763 |
} |
1772 |
} |
| 1764 |
|
1773 |
|
| 1765 |
if ($booksellerinvoicenumber) { |
1774 |
if ($booksellerinvoicenumber) { |
| 1766 |
$query .= " AND (aqorders.booksellerinvoicenumber LIKE ? OR aqbasket.booksellerinvoicenumber LIKE ?)"; |
1775 |
$query .= " AND aqinvoices.invoicenumber LIKE ? "; |
| 1767 |
push @query_params, "%$booksellerinvoicenumber%", "%$booksellerinvoicenumber%"; |
1776 |
push @query_params, "%$booksellerinvoicenumber%"; |
| 1768 |
} |
1777 |
} |
| 1769 |
|
1778 |
|
| 1770 |
if ( C4::Context->preference("IndependantBranches") ) { |
1779 |
if ( C4::Context->preference("IndependantBranches") ) { |
|
Lines 1905-1911
sub AddClaim {
Link Here
|
| 1905 |
"; |
1914 |
"; |
| 1906 |
my $sth = $dbh->prepare($query); |
1915 |
my $sth = $dbh->prepare($query); |
| 1907 |
$sth->execute($ordernumber); |
1916 |
$sth->execute($ordernumber); |
|
|
1917 |
} |
| 1918 |
|
| 1919 |
=head3 GetInvoices |
| 1920 |
|
| 1921 |
my @invoices = GetInvoices( |
| 1922 |
invoicenumber => $invoicenumber, |
| 1923 |
suppliername => $suppliername, |
| 1924 |
shipmentdatefrom => $shipmentdatefrom, # ISO format |
| 1925 |
shipmentdateto => $shipmentdateto, # ISO format |
| 1926 |
billingdatefrom => $billingdatefrom, # ISO format |
| 1927 |
billingdateto => $billingdateto, # ISO format |
| 1928 |
isbneanissn => $isbn_or_ean_or_issn, |
| 1929 |
title => $title, |
| 1930 |
author => $author, |
| 1931 |
publisher => $publisher, |
| 1932 |
publicationyear => $publicationyear, |
| 1933 |
branchcode => $branchcode, |
| 1934 |
order_by => $order_by |
| 1935 |
); |
| 1936 |
|
| 1937 |
Return a list of invoices that match all given criteria. |
| 1938 |
|
| 1939 |
$order_by is "column_name (asc|desc)", where column_name is any of |
| 1940 |
'invoicenumber', 'booksellerid', 'shipmentdate', 'billingdate', 'closedate', |
| 1941 |
'shipmentcost', 'shipmentcost_budgetid'. |
| 1942 |
|
| 1943 |
asc is the default if omitted |
| 1944 |
|
| 1945 |
=cut |
| 1946 |
|
| 1947 |
sub GetInvoices { |
| 1948 |
my %args = @_; |
| 1949 |
|
| 1950 |
my @columns = qw(invoicenumber booksellerid shipmentdate billingdate |
| 1951 |
closedate shipmentcost shipmentcost_budgetid); |
| 1952 |
|
| 1953 |
my $dbh = C4::Context->dbh; |
| 1954 |
my $query = qq{ |
| 1955 |
SELECT aqinvoices.*, aqbooksellers.name AS suppliername, |
| 1956 |
COUNT( |
| 1957 |
DISTINCT IF( |
| 1958 |
aqorders.datereceived IS NOT NULL, |
| 1959 |
aqorders.biblionumber, |
| 1960 |
NULL |
| 1961 |
) |
| 1962 |
) AS receivedbiblios, |
| 1963 |
SUM(aqorders.quantityreceived) AS receiveditems |
| 1964 |
FROM aqinvoices |
| 1965 |
LEFT JOIN aqbooksellers ON aqbooksellers.id = aqinvoices.booksellerid |
| 1966 |
LEFT JOIN aqorders ON aqorders.invoiceid = aqinvoices.invoiceid |
| 1967 |
LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber |
| 1968 |
LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber |
| 1969 |
LEFT JOIN subscription ON biblio.biblionumber = subscription.biblionumber |
| 1970 |
}; |
| 1971 |
|
| 1972 |
my @bind_args; |
| 1973 |
my @bind_strs; |
| 1974 |
if($args{supplierid}) { |
| 1975 |
push @bind_strs, " aqinvoices.booksellerid = ? "; |
| 1976 |
push @bind_args, $args{supplierid}; |
| 1977 |
} |
| 1978 |
if($args{invoicenumber}) { |
| 1979 |
push @bind_strs, " aqinvoices.invoicenumber LIKE ? "; |
| 1980 |
push @bind_args, "%$args{invoicenumber}%"; |
| 1981 |
} |
| 1982 |
if($args{suppliername}) { |
| 1983 |
push @bind_strs, " aqbooksellers.name LIKE ? "; |
| 1984 |
push @bind_args, "%$args{suppliername}%"; |
| 1985 |
} |
| 1986 |
if($args{shipmentdatefrom}) { |
| 1987 |
push @bind_strs, " aqinvoices.shipementdate >= ? "; |
| 1988 |
push @bind_args, $args{shipementdatefrom}; |
| 1989 |
} |
| 1990 |
if($args{shipmentdateto}) { |
| 1991 |
push @bind_strs, " aqinvoices.shipementdate <= ? "; |
| 1992 |
push @bind_args, $args{shipementdateto}; |
| 1993 |
} |
| 1994 |
if($args{billingdatefrom}) { |
| 1995 |
push @bind_strs, " aqinvoices.billingdate >= ? "; |
| 1996 |
push @bind_args, $args{billingdatefrom}; |
| 1997 |
} |
| 1998 |
if($args{billingdateto}) { |
| 1999 |
push @bind_strs, " aqinvoices.billingdate <= ? "; |
| 2000 |
push @bind_args, $args{billingdateto}; |
| 2001 |
} |
| 2002 |
if($args{isbneanissn}) { |
| 2003 |
push @bind_strs, " (biblioitems.isbn LIKE ? OR biblioitems.ean LIKE ? OR biblioitems.issn LIKE ? ) "; |
| 2004 |
push @bind_args, $args{isbneanissn}, $args{isbneanissn}, $args{isbneanissn}; |
| 2005 |
} |
| 2006 |
if($args{title}) { |
| 2007 |
push @bind_strs, " biblio.title LIKE ? "; |
| 2008 |
push @bind_args, $args{title}; |
| 2009 |
} |
| 2010 |
if($args{author}) { |
| 2011 |
push @bind_strs, " biblio.author LIKE ? "; |
| 2012 |
push @bind_args, $args{author}; |
| 2013 |
} |
| 2014 |
if($args{publisher}) { |
| 2015 |
push @bind_strs, " biblioitems.publishercode LIKE ? "; |
| 2016 |
push @bind_args, $args{publisher}; |
| 2017 |
} |
| 2018 |
if($args{publicationyear}) { |
| 2019 |
push @bind_strs, " biblioitems.publicationyear = ? "; |
| 2020 |
push @bind_args, $args{publicationyear}; |
| 2021 |
} |
| 2022 |
if($args{branchcode}) { |
| 2023 |
push @bind_strs, " aqorders.branchcode = ? "; |
| 2024 |
push @bind_args, $args{branchcode}; |
| 2025 |
} |
| 2026 |
|
| 2027 |
$query .= " WHERE " . join(" AND ", @bind_strs) if @bind_strs; |
| 2028 |
$query .= " GROUP BY aqinvoices.invoiceid "; |
| 2029 |
|
| 2030 |
if($args{order_by}) { |
| 2031 |
my ($column, $direction) = split / /, $args{order_by}; |
| 2032 |
if(grep /^$column$/, @columns) { |
| 2033 |
$direction ||= 'ASC'; |
| 2034 |
$query .= " ORDER BY $column $direction"; |
| 2035 |
} |
| 2036 |
} |
| 1908 |
|
2037 |
|
|
|
2038 |
my $sth = $dbh->prepare($query); |
| 2039 |
$sth->execute(@bind_args); |
| 2040 |
|
| 2041 |
my $results = $sth->fetchall_arrayref({}); |
| 2042 |
return @$results; |
| 2043 |
} |
| 2044 |
|
| 2045 |
=head3 GetInvoice |
| 2046 |
|
| 2047 |
my $invoice = GetInvoice($invoiceid); |
| 2048 |
|
| 2049 |
Get informations about invoice with given $invoiceid |
| 2050 |
|
| 2051 |
Return a hash filled with aqinvoices.* fields |
| 2052 |
|
| 2053 |
=cut |
| 2054 |
|
| 2055 |
sub GetInvoice { |
| 2056 |
my ($invoiceid) = @_; |
| 2057 |
my $invoice; |
| 2058 |
|
| 2059 |
return unless $invoiceid; |
| 2060 |
|
| 2061 |
my $dbh = C4::Context->dbh; |
| 2062 |
my $query = qq{ |
| 2063 |
SELECT * |
| 2064 |
FROM aqinvoices |
| 2065 |
WHERE invoiceid = ? |
| 2066 |
}; |
| 2067 |
my $sth = $dbh->prepare($query); |
| 2068 |
$sth->execute($invoiceid); |
| 2069 |
|
| 2070 |
$invoice = $sth->fetchrow_hashref; |
| 2071 |
return $invoice; |
| 2072 |
} |
| 2073 |
|
| 2074 |
=head3 GetInvoiceDetails |
| 2075 |
|
| 2076 |
my $invoice = GetInvoiceDetails($invoiceid) |
| 2077 |
|
| 2078 |
Return informations about an invoice + the list of related order lines |
| 2079 |
|
| 2080 |
Orders informations are in $invoice->{orders} (array ref) |
| 2081 |
|
| 2082 |
=cut |
| 2083 |
|
| 2084 |
sub GetInvoiceDetails { |
| 2085 |
my ($invoiceid) = @_; |
| 2086 |
my $invoice; |
| 2087 |
|
| 2088 |
return unless $invoiceid; |
| 2089 |
|
| 2090 |
my $dbh = C4::Context->dbh; |
| 2091 |
my $query = qq{ |
| 2092 |
SELECT aqinvoices.*, aqbooksellers.name AS suppliername |
| 2093 |
FROM aqinvoices |
| 2094 |
LEFT JOIN aqbooksellers ON aqinvoices.booksellerid = aqbooksellers.id |
| 2095 |
WHERE invoiceid = ? |
| 2096 |
}; |
| 2097 |
my $sth = $dbh->prepare($query); |
| 2098 |
$sth->execute($invoiceid); |
| 2099 |
|
| 2100 |
$invoice = $sth->fetchrow_hashref; |
| 2101 |
|
| 2102 |
$query = qq{ |
| 2103 |
SELECT aqorders.*, biblio.* |
| 2104 |
FROM aqorders |
| 2105 |
LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber |
| 2106 |
WHERE invoiceid = ? |
| 2107 |
}; |
| 2108 |
$sth = $dbh->prepare($query); |
| 2109 |
$sth->execute($invoiceid); |
| 2110 |
$invoice->{orders} = $sth->fetchall_arrayref({}); |
| 2111 |
$invoice->{orders} ||= []; # force an empty arrayref if fetchall_arrayref fails |
| 2112 |
|
| 2113 |
return $invoice; |
| 2114 |
} |
| 2115 |
|
| 2116 |
=head3 AddInvoice |
| 2117 |
|
| 2118 |
my $invoiceid = AddInvoice( |
| 2119 |
invoicenumber => $invoicenumber, |
| 2120 |
booksellerid => $booksellerid, |
| 2121 |
shipmentdate => $shipmentdate, |
| 2122 |
billingdate => $billingdate, |
| 2123 |
closedate => $closedate, |
| 2124 |
shipmentcost => $shipmentcost, |
| 2125 |
shipmentcost_budgetid => $shipmentcost_budgetid |
| 2126 |
); |
| 2127 |
|
| 2128 |
Create a new invoice and return its id or undef if it fails. |
| 2129 |
|
| 2130 |
=cut |
| 2131 |
|
| 2132 |
sub AddInvoice { |
| 2133 |
my %invoice = @_; |
| 2134 |
|
| 2135 |
return unless(%invoice and $invoice{invoicenumber}); |
| 2136 |
|
| 2137 |
my @columns = qw(invoicenumber booksellerid shipmentdate billingdate |
| 2138 |
closedate shipmentcost shipmentcost_budgetid); |
| 2139 |
|
| 2140 |
my @set_strs; |
| 2141 |
my @set_args; |
| 2142 |
foreach my $key (keys %invoice) { |
| 2143 |
if(0 < grep(/^$key$/, @columns)) { |
| 2144 |
push @set_strs, "$key = ?"; |
| 2145 |
push @set_args, ($invoice{$key} || undef); |
| 2146 |
} |
| 2147 |
} |
| 2148 |
|
| 2149 |
my $rv; |
| 2150 |
if(@set_args > 0) { |
| 2151 |
my $dbh = C4::Context->dbh; |
| 2152 |
my $query = "INSERT INTO aqinvoices SET "; |
| 2153 |
$query .= join (",", @set_strs); |
| 2154 |
my $sth = $dbh->prepare($query); |
| 2155 |
$rv = $sth->execute(@set_args); |
| 2156 |
if($rv) { |
| 2157 |
$rv = $dbh->last_insert_id(undef, undef, 'aqinvoices', undef); |
| 2158 |
} |
| 2159 |
} |
| 2160 |
return $rv; |
| 2161 |
} |
| 2162 |
|
| 2163 |
=head3 ModInvoice |
| 2164 |
|
| 2165 |
ModInvoice( |
| 2166 |
invoiceid => $invoiceid, # Mandatory |
| 2167 |
invoicenumber => $invoicenumber, |
| 2168 |
booksellerid => $booksellerid, |
| 2169 |
shipmentdate => $shipmentdate, |
| 2170 |
billingdate => $billingdate, |
| 2171 |
closedate => $closedate, |
| 2172 |
shipmentcost => $shipmentcost, |
| 2173 |
shipmentcost_budgetid => $shipmentcost_budgetid |
| 2174 |
); |
| 2175 |
|
| 2176 |
Modify an invoice, invoiceid is mandatory. |
| 2177 |
|
| 2178 |
Return undef if it fails. |
| 2179 |
|
| 2180 |
=cut |
| 2181 |
|
| 2182 |
sub ModInvoice { |
| 2183 |
my %invoice = @_; |
| 2184 |
|
| 2185 |
return unless(%invoice and $invoice{invoiceid}); |
| 2186 |
|
| 2187 |
my @columns = qw(invoicenumber booksellerid shipmentdate billingdate |
| 2188 |
closedate shipmentcost shipmentcost_budgetid); |
| 2189 |
|
| 2190 |
my @set_strs; |
| 2191 |
my @set_args; |
| 2192 |
foreach my $key (keys %invoice) { |
| 2193 |
if(0 < grep(/^$key$/, @columns)) { |
| 2194 |
push @set_strs, "$key = ?"; |
| 2195 |
push @set_args, ($invoice{$key} || undef); |
| 2196 |
} |
| 2197 |
} |
| 2198 |
|
| 2199 |
my $dbh = C4::Context->dbh; |
| 2200 |
my $query = "UPDATE aqinvoices SET "; |
| 2201 |
$query .= join(",", @set_strs); |
| 2202 |
$query .= " WHERE invoiceid = ?"; |
| 2203 |
|
| 2204 |
my $sth = $dbh->prepare($query); |
| 2205 |
$sth->execute(@set_args, $invoice{invoiceid}); |
| 2206 |
} |
| 2207 |
|
| 2208 |
=head3 CloseInvoice |
| 2209 |
|
| 2210 |
CloseInvoice($invoiceid); |
| 2211 |
|
| 2212 |
Close an invoice. |
| 2213 |
|
| 2214 |
Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => undef); |
| 2215 |
|
| 2216 |
=cut |
| 2217 |
|
| 2218 |
sub CloseInvoice { |
| 2219 |
my ($invoiceid) = @_; |
| 2220 |
|
| 2221 |
return unless $invoiceid; |
| 2222 |
|
| 2223 |
my $dbh = C4::Context->dbh; |
| 2224 |
my $query = qq{ |
| 2225 |
UPDATE aqinvoices |
| 2226 |
SET closedate = CAST(NOW() AS DATE) |
| 2227 |
WHERE invoiceid = ? |
| 2228 |
}; |
| 2229 |
my $sth = $dbh->prepare($query); |
| 2230 |
$sth->execute($invoiceid); |
| 2231 |
} |
| 2232 |
|
| 2233 |
=head3 ReopenInvoice |
| 2234 |
|
| 2235 |
ReopenInvoice($invoiceid); |
| 2236 |
|
| 2237 |
Reopen an invoice |
| 2238 |
|
| 2239 |
Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => C4::Dates->new()->output('iso')) |
| 2240 |
|
| 2241 |
=cut |
| 2242 |
|
| 2243 |
sub ReopenInvoice { |
| 2244 |
my ($invoiceid) = @_; |
| 2245 |
|
| 2246 |
return unless $invoiceid; |
| 2247 |
|
| 2248 |
my $dbh = C4::Context->dbh; |
| 2249 |
my $query = qq{ |
| 2250 |
UPDATE aqinvoices |
| 2251 |
SET closedate = NULL |
| 2252 |
WHERE invoiceid = ? |
| 2253 |
}; |
| 2254 |
my $sth = $dbh->prepare($query); |
| 2255 |
$sth->execute($invoiceid); |
| 1909 |
} |
2256 |
} |
| 1910 |
|
2257 |
|
| 1911 |
1; |
2258 |
1; |