KoolReport's Forum

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

Data is not load every time #1580

Open icanstudioz app solutions opened this topic on on Aug 19, 2020 - 3 comments

icanstudioz app solutions commented on Aug 19, 2020

<?php

namespace App\Reports;

use \koolreport\processes\ColumnMeta; use \koolreport\pivot\processes\Pivot; use App\Reports\CustomerAjax; use App\Reports\ProductAjax;

class Supplierogrrecon extends \koolreport\KoolReport {

use \koolreport\export\Exportable;
use \koolreport\excel\ExcelExportable;
use \koolreport\core\SubReport;
use \koolreport\laravel\Friendship;
use \koolreport\inputs\Bindable;
use \koolreport\inputs\POSTBinding;

function settings() {
    return array(
        "subReports" => array(
            "customerAjax" => CustomerAjax::class,
            "productAjax" => ProductAjax::class
        )
    );
}

protected function defaultParamValues() {

    return array(
        "month" => date('Y-m'),
        "group" => array(),
        "customer" => array(),
        "network" => array(),
        "product" => array(),
    );
}

protected function bindParamsToInputs() {
    return array(
        "month",
        "group",
        "customer",
        "network",
        "product"
    );
}

function setup() {
    $month = date('M', strtotime($this->params["month"]));
    $month1 = date('M', strtotime('-1 month', strtotime($this->params["month"])));
    $month2 = date('M', strtotime('-2 month', strtotime($this->params["month"])));

    $node = $this->src('mysql')->query("select c.name as parent,m.income,m.expense,g.code,p.name,s.qty,m.serial_no,DATE_FORMAT(o.process_month, '%Y') as year,DATE_FORMAT(o.process_month, '%b') as month FROM me_ogr_post_process m "
                            . "LEFT JOIN me_import_file o on o.id = m.file_id "
                            . "LEFT JOIN sales_order_detail s on s.id = m.sales_order_detail_id "
                            . "LEFT JOIN customer c on m.customer_id = c.id "
                            . "JOIN customer p ON c.id = p.parent_id "
                            . "LEFT JOIN `group` g on g.id = c.group_id "
                            . "WHERE DATE_FORMAT(o.process_month, '%Y') = YEAR(CURDATE())  AND "
                            . (($this->params["network"] != array()) ? "m.network_id IN (:network) AND " : "")
                            . (($this->params["group"] != array()) ? "c.group_id IN (:group) AND " : "")
                            . (($this->params["customer"] != array()) ? "m.customer_id IN (:customer) AND " : "")
                            . (($this->params["product"] != array()) ? "m.product_id IN (:product) AND " : "")
                            . ("(DATE_FORMAT(o.process_month, '%b') = '$month' OR DATE_FORMAT(o.process_month, '%b') = '$month1' OR DATE_FORMAT(o.process_month, '%b') = '$month2')")
                    )
                    ->params(array(
                        ":customer" => $this->params["customer"],
                        ":network" => $this->params["network"],
                        ":group" => $this->params["group"],
                        ":product" => $this->params["product"]
                    ))
                    ->pipe(new ColumnMeta(array(
                        "expense" => array(
                            'type' => 'number',
                            "decimals" => 2,
                            "prefix" => "R",
                        ),
                        "income" => array(
                            'type' => 'number',
                            "decimals" => 2,
                            "prefix" => "R",
                        ),
                        "serial_no" => array(
                            'type' => 'number',
                        ),
                    )))
                    ->pipe(new Pivot(array(
                        "dimensions" => array(
                            "column" => "year,month",
                            "row" => "code,parent,name"
                        ),
                        "aggregates" => array(
                            "sum" => "income,expense",
                            "count" => "serial_no",
                        )
                    )))->saveTo($node2);
    $node2->pipe($this->dataStore('sales'));
}

}

-------------------------------------------------view file ----------------------------------------------

<?php

use \koolreport\pivot\widgets\PivotTable; use \koolreport\inputs\DateTimePicker; ?> <style>

.calendar.left .daterangepicker_input,
.calendar.right .daterangepicker_input {
    display: none;
}

</style> <div class="report-content">

<form method="POST">
    <?php echo csrf_field() ?>
    <div class="text-center">
        <h3>Supplier OGR Recon</h3>
        <br/>
        <div class="form-group">
            <button formaction="/reporting/supplier_ogr_recon_export_pdf/" class="btn btn-primary">Download PDF</button>
            <button formaction="/reporting/supplier_ogr_recon_export_excel/" class="btn btn-primary">Download Excel</button>
        </div>
    </div>
    <div class="row">
        <div class="col-md-3">
            From Date:
            <?php
            DateTimePicker::create(array(
                "name" => "month",
                "maxDate" => "@endDatePicker",
                "format" => "YYYY-MM",
                "themeBase" => "bs4",
            ));
            ?>
        </div>
        <div class="col-md-3">
            <?php $this->subReport("customerAjax"); ?>
        </div>
        <div class="col-md-3">
            <?php $this->subReport("productAjax"); ?>
        </div>

        <div class="form-group" style="margin-top:30px;">
            <button class="btn btn-lg btn-primary">Submit form</button>
        </div>
    </div>

</form>

</div>

<?php if (!empty($this->dataStore('sales'))) {

PivotTable::create(array(
    "dataStore" => $this->dataStore('sales'),
    'rowCollapseLevels' => array(0),
    'columnCollapseLevels' => array(0),
    'hideSubtotalRow' => true,
    'hideSubtotalColumn' => true,
    'showDataHeaders' => true,
    'columnSort' => array(
        'month' => function ($a, $b) {
            return false;
        },
    ),
));

} ?>

why my data not load every time?

David Winterburn commented on Aug 20, 2020

Please check if $this->dataStore('sales')->data() return empty result or not. If it's empty, PivotTable won't have any data to show for. Thanks!

icanstudioz app solutions commented on Aug 20, 2020

you can see in above image.. report work perfectly.. but when i refresh again then something wrong,check below image.. every refresh, sometime load report or sometime not

David Winterburn commented on Aug 20, 2020

In your report's view, Please check if $this->dataStore('sales')->data() return empty result or not.

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