Customer Orders

This report shows you how to use Inputs package and Export package in combination. On the report load, it will show list of customers in select box for you to select. After an customer is selected and List Orders button is clicked, the report will return list of orders from that customer. This list of customer can be exported to PDF to download.

<?php
require_once "Order.php";
$report = new Order;
$report->run()->render();
<?php
require_once "Order.php";
$report = new Order;
$report->run()
->export('OrderPdf')
->pdf(array(
    "format"=>"A4",
    "orientation"=>"portrait",
    //"zoom"=>2,
    "margin"=>"1in"
))
->toBrowser("orders.pdf");
<?php
require_once "../../../../koolreport/autoload.php";

use \koolreport\processes\CalculatedColumn;

class Order extends \koolreport\KoolReport
{
    use \koolreport\inputs\Bindable;

    use \koolreport\inputs\POSTBinding;
    use \koolreport\export\Exportable;


    function defaultParamValues()
    {
        return array(
            "customerNumber"=>0,
        );
    }

    function bindParamsToInputs()
    {
        return array(
            "customerNumber",
        );
    }

    function settings()
    {
        return array(
            "dataSources"=>array(
                "automaker"=>array(
                    "connectionString"=>"mysql:host=localhost;dbname=automaker",
                    "username"=>"root",
                    "password"=>"",
                    "charset"=>"utf8"
                ),
            )
        );
    }

    function setup()
    {

        $this->src('automaker')
        ->query("
            SELECT *
            FROM customers
            ORDER BY customerName
        ")
        ->pipe($this->dataStore("customers"));

        $this->src('automaker')
        ->query("
            SELECT products.productName,orderdetails.priceEach,orderdetails.quantityOrdered
            FROM orders
            JOIN orderdetails
            ON
                orders.orderNumber = orderdetails.orderNumber
            JOIN products
            ON
                products.productCode = orderdetails.productCode
            WHERE customerNumber = :customerNumber
        ")->params(array(
            ":customerNumber"=>$this->params["customerNumber"]
        ))
        ->pipe(new CalculatedColumn(array(
            "amount"=>"{priceEach}*{quantityOrdered}"
        )))
        ->pipe($this->dataStore("orders"));
    }
}
<?php
    use \koolreport\inputs\Select;
    use \koolreport\widgets\koolphp\Table;

    $customerName = "";
    $this->dataStore("customers")->popStart();
    while($row = $this->dataStore("customers")->pop())
    {
        if($row["customerNumber"]==$this->params["customerNumber"])
        {
            $customerName =$row["customerName"];
        }
    }
?>
<div class="report-content">
    <form method="post">
        <div class="text-center">
            <h1>Customer Orders</h1>
            <div class="row form-group">
                <div class="col-md-6 offset-md-3">
                    <?php
                    Select::create(array(
                        "name"=>"customerNumber",
                        "dataStore"=>$this->dataStore("customers"),
                        "dataBind"=>array(
                            "text"=>"customerName",
                            "value"=>"customerNumber",
                        ),
                        "attributes"=>array(
                            "class"=>"form-control"
                        )
                    ));
                    ?>
                </div>
            </div>
            <div class="form-group">
                <button class="btn btn-primary">Look up</button>
            </div>
        </div>
    </form>
    <?php
        if($this->dataStore("orders")->countData()>0)
        {
        ?>
            <?php
            Table::create(array(
                "dataStore"=>$this->dataStore("orders"),
                "columns"=>array(
                    "productName"=>array(
                        "label"=>"Product",
                    ),
                    "priceEach"=>array(
                        "label"=>"Price",
                        "prefix"=>"$",
                    ),
                    "quantityOrdered"=>array(
                        "label"=>"Quantity"
                    ),
                    "amount"=>array(
                        "label"=>"Total",
                        "prefix"=>"$",
                    )
                ),
                "class"=>array(
                    "table"=>"table table-striped"
                )
            ));
            ?>
            <div class="text-center">
                <form method="post" action="export.php">
                    <input type="hidden" value="<?php echo $this->params["customerNumber"]; ?>" name="customerNumber" />
                    <button class="btn btn-primary">Export to PDF</button>
                </form>
            </div>
        <?php
        }
    ?>
</div>
<?php
    use \koolreport\widgets\koolphp\Table;
    $this->dataStore("customers")->popStart();
    $customerName = "";
    while($row = $this->dataStore("customers")->pop())
    {
        if($row["customerNumber"]==$this->params["customerNumber"])
        {
            $customerName =$row["customerName"];
        }
    }
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Order details of customer</title>
        <link rel="stylesheet" href="../../../assets/bs3/bootstrap.min.css" />
        <link rel="stylesheet" href="../../../assets/bs3/bootstrap-theme.min.css" />
    </head>
    <body>
        <div class="container box-container">
                <div class="text-center">
                    <h1><?php echo $customerName; ?></h1>
                </div>
            <hr/>
            <?php
                if($this->dataStore("orders")->countData()>0)
                {
                ?>
                    <?php
                    Table::create(array(
                        "dataStore"=>$this->dataStore("orders"),
                        "columns"=>array(
                            "productName"=>array(
                                "label"=>"Product",
                            ),
                            "priceEach"=>array(
                                "label"=>"Price",
                                "prefix"=>"$",
                            ),
                            "quantityOrdered"=>array(
                                "label"=>"Quantity"
                            ),
                            "amount"=>array(
                                "label"=>"Total",
                                "prefix"=>"$",
                            )
                        ),
                        "class"=>array(
                            "table"=>"table table-striped"
                        )
                    ));
                    ?>
                <?php
                }
            ?>
        </div>
    </body>
</html>

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport