I'm having trouble getting the Input & Export example working. The select works and I'm able to see the page with the searched table. When I click Export to PDF, I get a 404 Not Found error. I'm sure I have something wrong in Laravel. Any help would be appreciated.
web.php
Auth::routes();
Route::any('/order', 'OrderController@index')->name('order');
Route::any('/export', 'ExportController@index')->name('export');
OrderController.php
<?php
namespace App\Http\Controllers;
use App\Reports\Order;
class OrderController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$report = new Order;
$report->run();
return view("order",["order"=>$report]);
}
}
Order.php
<?php
namespace App\Reports;
use \koolreport\processes\CalculatedColumn;
class Order extends \koolreport\KoolReport
{
use \koolreport\laravel\Friendship;
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=xxx.xxx.xxx.xxx70;dbname=automaker",
"username"=>"user",
"password"=>"user",
"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"));
}
}
Order.view.php
<?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">
<?php echo csrf_field() ?>
<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>
ExportController.php
<?php
namespace App\Http\Controllers;
use App\Reports\Export;
class ExportController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$export = new Export;
$export ->run();
return view("export",["export"=>$export]);
}
}
export.php
<?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");
export.blade.php
@extends('layouts.app')
@section('content')
<?php
require_once "Order.php";
$report = new Order;
$report->run()->render();
?>
@endsection
OrderPdf.view.php
<?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>