X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=acqui%2Finvoice.pl;h=5971ed161a2e5465cf3195e0cdc2d71aec9df5e2;hb=09953f836de01a68a3117227965719b74f543844;hp=28f3841135dfa4a2a09b1327cd405da9ae2d81a8;hpb=bf803c521fc4a2320a7bc990bcdcb58f15307a33;p=koha_fer diff --git a/acqui/invoice.pl b/acqui/invoice.pl index 28f3841135..5971ed161a 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -37,91 +37,117 @@ use C4::Bookseller qw/GetBookSellerFromId/; use C4::Budgets; my $input = new CGI; -my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( { - template_name => 'acqui/invoice.tmpl', - query => $input, - type => 'intranet', - authnotrequired => 0, - flagsrequired => { 'acquisition' => '*' }, - debug => 1, -} ); +my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( + { + template_name => 'acqui/invoice.tmpl', + query => $input, + type => 'intranet', + authnotrequired => 0, + flagsrequired => { 'acquisition' => '*' }, + debug => 1, + } +); my $invoiceid = $input->param('invoiceid'); -my $op = $input->param('op'); +my $op = $input->param('op'); -if($op && $op eq 'close') { +if ( $op && $op eq 'close' ) { CloseInvoice($invoiceid); my $referer = $input->param('referer'); - if($referer) { + if ($referer) { print $input->redirect($referer); exit 0; } -}elsif($op && $op eq 'reopen') { +} +elsif ( $op && $op eq 'reopen' ) { ReopenInvoice($invoiceid); my $referer = $input->param('referer'); - if($referer) { + if ($referer) { print $input->redirect($referer); exit 0; } -}elsif($op && $op eq 'mod') { - my $shipmentdate = $input->param('shipmentdate'); - my $billingdate = $input->param('billingdate'); - my $shipmentcost = $input->param('shipmentcost'); +} +elsif ( $op && $op eq 'mod' ) { + my $shipmentdate = $input->param('shipmentdate'); + my $billingdate = $input->param('billingdate'); + my $shipmentcost = $input->param('shipmentcost'); my $shipment_budget_id = $input->param('shipment_budget_id'); ModInvoice( - invoiceid => $invoiceid, - shipmentdate => C4::Dates->new($shipmentdate)->output("iso"), - billingdate => C4::Dates->new($billingdate)->output("iso"), - shipmentcost => $shipmentcost, + invoiceid => $invoiceid, + shipmentdate => C4::Dates->new($shipmentdate)->output("iso"), + billingdate => C4::Dates->new($billingdate)->output("iso"), + shipmentcost => $shipmentcost, shipmentcost_budgetid => $shipment_budget_id ); - $template->param(modified => 1); + if ($input->param('reopen')) { + ReopenInvoice($invoiceid); + } elsif ($input->param('close')) { + CloseInvoice($invoiceid); + } elsif ($input->param('merge')) { + my @sources = $input->param('merge'); + MergeInvoices($invoiceid, \@sources); + } + $template->param( modified => 1 ); +} +elsif ( $op && $op eq 'delete' ) { + DelInvoice($invoiceid); + my $referer = $input->param('referer') || 'invoices.pl'; + if ($referer) { + print $input->redirect($referer); + exit 0; + } } -my $details = GetInvoiceDetails($invoiceid); -my $bookseller = GetBookSellerFromId($details->{booksellerid}); +my $details = GetInvoiceDetails($invoiceid); +my $bookseller = GetBookSellerFromId( $details->{booksellerid} ); my @orders_loop = (); -my $orders = $details->{'orders'}; +my $orders = $details->{'orders'}; my $qty_total; my @books_loop; my @book_foot_loop; my %foot; my $total_quantity = 0; -my $total_rrp = 0; -my $total_est = 0; +my $total_rrp = 0; +my $total_est = 0; + foreach my $order (@$orders) { - my $line = get_infos( $order, $bookseller); + my $line = get_infos( $order, $bookseller ); $total_quantity += $$line{quantity}; - $total_rrp += $order->{quantity} * $order->{rrp}; - $total_est += $order->{quantity} * $order->{'ecost'}; + $total_rrp += $order->{quantity} * $order->{rrp}; + $total_est += $order->{quantity} * $order->{'ecost'}; - my %row = (%$order, %$line); + my %row = ( %$order, %$line ); push @orders_loop, \%row; } my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; -my $discount = $bookseller->{'discount'} ? ($bookseller->{discount} / 100) : 0; +my $discount = + $bookseller->{'discount'} ? ( $bookseller->{discount} / 100 ) : 0; my $total_est_gste; my $total_est_gsti; -my $total_rrp_gsti; # RRP Total, GST included -my $total_rrp_gste; # RRP Total, GST excluded +my $total_rrp_gsti; # RRP Total, GST included +my $total_rrp_gste; # RRP Total, GST excluded my $gist_est; my $gist_rrp; -if ($gist){ +if ($gist) { + # if we have GST if ( $bookseller->{'listincgst'} ) { + # if prices already includes GST # we know $total_rrp_gsti $total_rrp_gsti = $total_rrp; + # and can reverse compute other values $total_rrp_gste = $total_rrp_gsti / ( $gist + 1 ); $gist_rrp = $total_rrp_gsti - $total_rrp_gste; $total_est_gste = $total_rrp_gste - ( $total_rrp_gste * $discount ); $total_est_gsti = $total_est; - } else { + } + else { # if prices does not include GST # then we use the common way to compute other values @@ -130,34 +156,37 @@ if ($gist){ $total_rrp_gsti = $total_rrp_gste + $gist_rrp; $total_est_gste = $total_est; $total_est_gsti = $total_rrp_gsti - ( $total_rrp_gsti * $discount ); - } - $gist_est = $gist_rrp - ( $gist_rrp * $discount ); -} else { + } + $gist_est = $gist_rrp - ( $gist_rrp * $discount ); +} +else { $total_rrp_gste = $total_rrp_gsti = $total_rrp; $total_est_gste = $total_est_gsti = $total_est; - $gist_rrp = $gist_est = 0; + $gist_rrp = $gist_est = 0; } my $total_gsti_shipment = $total_est_gsti + $details->{shipmentcost}; my $format = "%.2f"; $template->param( - total_rrp_gste => sprintf($format, $total_rrp_gste), - total_rrp_gsti => sprintf($format, $total_rrp_gsti), - total_est_gste => sprintf($format, $total_est_gste), - total_est_gsti => sprintf($format, $total_est_gsti), - gist_rrp => sprintf($format, $gist_rrp), - gist_est => sprintf($format, $gist_est), - total_gsti_shipment => sprintf($format, $total_gsti_shipment), - gist => sprintf($format, $gist * 100), + total_rrp_gste => sprintf( $format, $total_rrp_gste ), + total_rrp_gsti => sprintf( $format, $total_rrp_gsti ), + total_est_gste => sprintf( $format, $total_est_gste ), + total_est_gsti => sprintf( $format, $total_est_gsti ), + gist_rrp => sprintf( $format, $gist_rrp ), + gist_est => sprintf( $format, $gist_est ), + total_gsti_shipment => sprintf( $format, $total_gsti_shipment ), + gist => sprintf( $format, $gist * 100 ), ); my $budgets = GetBudgets(); my @budgets_loop; my $shipmentcost_budgetid = $details->{shipmentcost_budgetid}; foreach my $budget (@$budgets) { - next unless CanUserUseBudget($loggedinuser, $budget, $flags); - my %line = %{ $budget }; - if($shipmentcost_budgetid and $budget->{budget_id} == $shipmentcost_budgetid) { + next unless CanUserUseBudget( $loggedinuser, $budget, $flags ); + my %line = %{$budget}; + if ( $shipmentcost_budgetid + and $budget->{budget_id} == $shipmentcost_budgetid ) + { $line{selected} = 1; } push @budgets_loop, \%line; @@ -167,33 +196,32 @@ $template->param( invoiceid => $details->{'invoiceid'}, invoicenumber => $details->{'invoicenumber'}, suppliername => $details->{'suppliername'}, - supplierid => $details->{'booksellerid'}, + booksellerid => $details->{'booksellerid'}, datereceived => $details->{'datereceived'}, shipmentdate => $details->{'shipmentdate'}, billingdate => $details->{'billingdate'}, invoiceclosedate => $details->{'closedate'}, - shipmentcost => sprintf($format, $details->{'shipmentcost'} || 0), + shipmentcost => sprintf( $format, $details->{'shipmentcost'} || 0 ), orders_loop => \@orders_loop, total_quantity => $total_quantity, invoiceincgst => $bookseller->{invoiceincgst}, currency => $bookseller->{listprice}, - DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), - budgets_loop => \@budgets_loop, + budgets_loop => \@budgets_loop, ); sub get_infos { - my $order = shift; + my $order = shift; my $bookseller = shift; - my $qty = $order->{'quantity'} || 0; + my $qty = $order->{'quantity'} || 0; if ( !defined $order->{quantityreceived} ) { $order->{quantityreceived} = 0; } my $budget = GetBudget( $order->{'budget_id'} ); - my %line = %{ $order }; + my %line = %{$order}; $line{order_received} = ( $qty == $order->{'quantityreceived'} ); $line{budget_name} = $budget->{budget_name}; - $line{total} = $qty * $order->{ecost}; + $line{total} = $qty * $order->{ecost}; if ( $line{uncertainprice} ) { $line{rrp} .= ' (Uncertain)'; @@ -203,7 +231,8 @@ sub get_infos { my $seriestitle = $order->{'seriestitle'}; $line{'title'} .= " / $seriestitle" if $seriestitle; $line{'title'} .= " / $volume" if $volume; - } else { + } + else { $line{'title'} = "Deleted bibliographic notice, can't find title."; }