View | Details | Raw Unified | Return to bug 20922
Collapse All | Expand All

(-)a/installer/data/mysql/updatedatabase.pl (-23 / +23 lines)
Lines 13519-13571 if ( CheckVersion($DBversion) ) { Link Here
13519
        WHERE ordernumber = ?
13519
        WHERE ordernumber = ?
13520
    |);
13520
    |);
13521
13521
13522
    require Koha::Number::Price;
13522
    require Number::Format;
13523
    my $format = Number::Format->new;
13524
    my $precision = 2;
13523
    for my $order ( @$orders ) {
13525
    for my $order ( @$orders ) {
13524
        $sth_get_bookseller->execute( $order->{ordernumber} );
13526
        $sth_get_bookseller->execute( $order->{ordernumber} );
13525
        my ( $bookseller ) = $sth_get_bookseller->fetchrow_hashref;
13527
        my ( $bookseller ) = $sth_get_bookseller->fetchrow_hashref;
13526
        $order->{rrp}   = Koha::Number::Price->new( $order->{rrp} )->round;
13528
        $order->{rrp}   = $format->round( $order->{rrp}, $precision );
13527
        $order->{ecost} = Koha::Number::Price->new( $order->{ecost} )->round;
13529
        $order->{ecost} = $format->round( $order->{ecost}, $precision );
13528
        $order->{tax_rate} ||= 0 ; # tax_rate can be NULL in DB
13530
        $order->{tax_rate} ||= 0 ; # tax_rate can be NULL in DB
13529
        # Ordering
13531
        # Ordering
13530
        if ( $bookseller->{listincgst} ) {
13532
        if ( $bookseller->{listincgst} ) {
13531
            $order->{rrp_tax_included} = $order->{rrp};
13533
            $order->{rrp_tax_included} = $order->{rrp};
13532
            $order->{rrp_tax_excluded} = Koha::Number::Price->new(
13534
            $order->{rrp_tax_excluded} = $format->round(
13533
                $order->{rrp_tax_included} / ( 1 + $order->{tax_rate} ) )->round;
13535
                $order->{rrp_tax_included} / ( 1 + $order->{tax_rate} ), $precision );
13534
            $order->{ecost_tax_included} = $order->{ecost};
13536
            $order->{ecost_tax_included} = $order->{ecost};
13535
            $order->{ecost_tax_excluded} = Koha::Number::Price->new(
13537
            $order->{ecost_tax_excluded} = $format->round(
13536
                $order->{ecost} / ( 1 + $order->{tax_rate} ) )->round;
13538
                $order->{ecost} / ( 1 + $order->{tax_rate} ), $precision );
13537
        }
13539
        }
13538
        else {
13540
        else {
13539
            $order->{rrp_tax_excluded} = $order->{rrp};
13541
            $order->{rrp_tax_excluded} = $order->{rrp};
13540
            $order->{rrp_tax_included} = Koha::Number::Price->new(
13542
            $order->{rrp_tax_included} = $format->round(
13541
                $order->{rrp} * ( 1 + $order->{tax_rate} ) )->round;
13543
                $order->{rrp} * ( 1 + $order->{tax_rate} ), $precision );
13542
            $order->{ecost_tax_excluded} = $order->{ecost};
13544
            $order->{ecost_tax_excluded} = $order->{ecost};
13543
            $order->{ecost_tax_included} = Koha::Number::Price->new(
13545
            $order->{ecost_tax_included} = $format->round(
13544
                $order->{ecost} * ( 1 + $order->{tax_rate} ) )->round;
13546
                $order->{ecost} * ( 1 + $order->{tax_rate} ), $precision );
13545
        }
13547
        }
13546
13548
13547
        #receiving
13549
        #receiving
13548
        if ( $bookseller->{listincgst} ) {
13550
        if ( $bookseller->{listincgst} ) {
13549
            $order->{unitprice_tax_included} = Koha::Number::Price->new( $order->{unitprice} )->round;
13551
            $order->{unitprice_tax_included} = $format->round( $order->{unitprice}, $precision );
13550
            $order->{unitprice_tax_excluded} = Koha::Number::Price->new(
13552
            $order->{unitprice_tax_excluded} = $format->round(
13551
              $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate} ) )->round;
13553
              $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate} ), $precision );
13552
        }
13554
        }
13553
        else {
13555
        else {
13554
            $order->{unitprice_tax_excluded} = Koha::Number::Price->new( $order->{unitprice} )->round;
13556
            $order->{unitprice_tax_excluded} = $format->round( $order->{unitprice}, $precision );
13555
            $order->{unitprice_tax_included} = Koha::Number::Price->new(
13557
            $order->{unitprice_tax_included} = $format->round(
13556
              $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate} ) )->round;
13558
              $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate} ), $precision );
13557
        }
13559
        }
13558
13560
13559
        # If the order is received, the tax is calculated from the unit price
13561
        # If the order is received, the tax is calculated from the unit price
13560
        if ( $order->{orderstatus} eq 'complete' ) {
13562
        if ( $order->{orderstatus} eq 'complete' ) {
13561
            $order->{tax_value} = Koha::Number::Price->new(
13563
            $order->{tax_value} = $format->round(
13562
              ( $order->{unitprice_tax_included} - $order->{unitprice_tax_excluded} )
13564
              ( $order->{unitprice_tax_included} - $order->{unitprice_tax_excluded} )
13563
              * $order->{quantity} )->round;
13565
              * $order->{quantity}, $precision );
13564
        } else {
13566
        } else {
13565
            # otherwise the ecost is used
13567
            # otherwise the ecost is used
13566
            $order->{tax_value} = Koha::Number::Price->new(
13568
            $order->{tax_value} = $format->round(
13567
                ( $order->{ecost_tax_included} - $order->{ecost_tax_excluded} ) *
13569
                ( $order->{ecost_tax_included} - $order->{ecost_tax_excluded} ) *
13568
                  $order->{quantity} )->round;
13570
                  $order->{quantity}, $precision );
13569
        }
13571
        }
13570
13572
13571
        $sth_update_order->execute(
13573
        $sth_update_order->execute(
Lines 13608-13614 if ( CheckVersion($DBversion) ) { Link Here
13608
        WHERE ordernumber = ?
13610
        WHERE ordernumber = ?
13609
    |);
13611
    |);
13610
13612
13611
    require Koha::Number::Price;
13612
    for my $order (@$orders) {
13613
    for my $order (@$orders) {
13613
        my $tax_value_on_ordering =
13614
        my $tax_value_on_ordering =
13614
          $order->{quantity} *
13615
          $order->{quantity} *
13615
- 

Return to bug 20922