KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Rounding of decimal values #3410

Open chris rogers opened this topic on on Jan 9 - 2 comments

chris rogers commented on Jan 9

I have been using the pro versio nkoolreport for a few years now with much problem - thanks :)

Recently I upgraded from Laravel 8 to 11 and PHP 8.1 to 8.2. I notice my reports are now having rounded values for example what was 22.50 is now becoming 23 on the reports. I checked the the data generate by logging to laravel logs and the data is indeed 22.50. I also tried changing "sum(if(ift.type="material",it.total_amount,"")) AS Material" to " sum(if(ift.type="material",it.total_amount,0.0)) AS Material,ROUND(sum(if(ift.type="material",it.total_amount,0.0)), 2) AS Material" and this worked.

Can you confirm this is a result of either upgrading my Laravel or PHP and if there is anything I can do with KoolReports, so I dont need to edit every column in every report. I have included snippets of my controller and blade for your reference below.

Thanks in advance.

Chris


$data = DB::table('invoice_items AS it')
            ->selectRaw('
                ROW_NUMBER() OVER (ORDER BY invoices.invoice_number ASC) AS "S/N",
                invoices.invoice_number AS Invoice, 
                invoices.invoice_date AS Date,
                students.display_name AS Student, 
                students.guardian1_display AS Parent, 
                invoices.revenue_start_date AS "Rev Date", 
                sum(if(ift.type="deposit",it.total_amount,"")) AS Deposit, 
                sum(if(ift.type="admin",it.total_amount,"")) AS Admin, 
                sum(if(ift.type="material",it.total_amount,"")) AS MaterialOld,
                sum(if(ift.type="material",it.total_amount,0.0)) AS Material,ROUND(sum(if(ift.type="material",it.total_amount,0.0)), 2) AS Material,
                sum(if(ift.type="term",it.total_amount,"")) AS Term, 
                sum(if(ift.type="workshop",it.total_amount,"")) AS Workshop, 
                sum(if(ift.type="adhoc",it.total_amount,"")) AS Adhoc, 
                sum(if(ift.type NOT IN ("deposit","admin","material","term","workshop","adhoc"),it.total_amount,"")) AS Other, 
                sum(it.total_amount) AS AR
            ')
            ->join('invoices', 'it.invoice_id', 'invoices.id')
            ->join('students', 'invoices.student_id', 'students.id')
            ->join('invoice_fee_types AS ift', 'it.invoice_fee_type_id', 'ift.id')
            ->leftjoin('classers', 'it.classer_id', 'classers.id')
            ->where('invoices.centre_id', '=', $centre_id)
            ->whereYear('invoices.invoice_date', $selected_year)
            ->where('invoices.status', '=', 'Approved')
            ->whereMonth('invoices.invoice_date', '=', $selected_month_number)
            ->groupBy('it.invoice_id', 'invoices.invoice_number', 'invoices.invoice_date', 'students.display_name', 'students.guardian1_display', 'invoices.revenue_start_date')
            ->orderByRaw('invoices.invoice_number ASC')
            ->get();

        $data = $data->toArray();

        return view('reports.invoicemonthly', compact('data', 'year_options', 'month_options', 'selected_year', 'selected_month_option', 'centreShortName'));


@extends(backpack_view('blank'))

@section('content')
    <div class="container">
        <h2 class="text-center">1. AR Invoice Monthly: {{ $centreShortName }}</h2>

        <form method="GET" action="{{ route('report.invoicemonthly') }}">
            <select name="year" id="year">
                @foreach ($year_options as $year)
                    <option value="{{ $year }}" {{ $year == $selected_year ? 'selected' : '' }}>{{ $year }}</option>
                @endforeach
            </select>

            <select name="month" id="month">
                @foreach ($month_options as $month)
                    @php
                        list($month_number, $month_display) = explode('|', $month);
                    @endphp
                    <option value="{{ $month_number }}" {{ $month_number == $selected_month_option ? 'selected' : '' }}>{{ $month_display }}</option>
                @endforeach
            </select>
            <button type="submit">Filter</button>
        </form>

    @php
        use \koolreport\widgets\koolphp\Table;
    @endphp

    <style>
    .small-font {
        font-size: 12px !important; // set CSS rule for this class
    }
    </style>


    {!! Table::create([
        "dataSource" => $data,
        "showFooter" => ["top"],
        "cssClass" => [
            "table" => "table table-striped table-bordered ",
            "tr" => "small-font",
        ]
    ]) !!}



    </div>
@endsection
Sebastian Morales commented on Jan 13

Pls test this code and let us know the result:

    {!! Table::create([
        "dataSource" => $data,
        "columns" => [
            "MaterialOld" => [
                "type" => "number",
                "decimals" => 2,
            ]
        ],
        "showFooter" => ["top"],
        "cssClass" => [ 
            "table" => "table table-striped table-bordered ",
            "tr" => "small-font",
        ]
    ]) !!}
chris rogers commented on Jan 13

Thanks. I previously tried that, but did again anyway, and get that one column of data only.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None