Basic report design

Using Report Manager from PHP

This is a sample provided by Rahul Tamrakar (rahultamrakar@yahoo.com)

// calling report through any script (PHP,ASP,JSP) basically we need

1. full path of the web server
2. path of the report manager
3. Parameters -> Report name , alias name & rest of the parameter
depend on report

// creating a dynamic link to view report , passing parameter to report
// if you click this link yiu will see the actual report

<a href="http://192.168.0.227/cgi-bin/repwebexe.bin/execute.pdf?reportname=%2Fr
ptsalesorder&aliasname=SALES+ORDER& ParamSONO=$outSO"> View Report
</a>

File SalesOrder_Search.php

<?php
$ROOT_PATH = "../";
$PAGE_NAME = "SalesOrder_Search";

include($ROOT_PATH."Common/Config.inc");

page_open(array(
"sess" => "MIS_Session",
"auth" => "MIS_Auth",
"perm" => "MIS_Perm",
"user" => "MIS_User" ));

// Dynamic Permission
// eval("\$perm->permissions = ".LoadPermission($PAGE_NAME).";");
// eval("\$perm->check(\"".PagePermission($gDB

$db = new DB_MPOS;

$t = new Template("./", "keep");
$t->set_file(array("form" => $PAGE_NAME.".shtml"));
$t->set_block("form", "ITEMS", "ITEMS_List");

// Have a Default Empty List
$t->set_var("ITEMS_List", "");

if($Search=="Search") {
// Check to make sure that required files are in
$Msg = "";
$ErrorFlag = 0;

if(empty($inSTARTDATE) == false && verify_date($inSTARTDATE) == "") {
// Invalid Date
$Msg = PrepareErrorMsg($Msg, "<B>Start Date</B> is invliad");
$ErrorFlag = 1;
}
if(empty($inENDDATE) == false && verify_date($inENDDATE) == "") {
// Invalid Date
$Msg = PrepareErrorMsg($Msg, "<B>End Date</B> is invliad");
$ErrorFlag = 1;
}

if($ErrorFlag == 0) {
// No Error


$SQL_Extra = "";
if($inLOCATION != 0) {
$SQL_Extra = "WHERE location_code = '$inLOCATION' ";
}
if(!empty($inTERMINAL)) {
if(empty($SQL_Extra)) {
$SQL_Extra = "WHERE terminal = '$inTERMINAL' ";
} else {
$SQL_Extra = $SQL_Extra . " AND terminal = '$inTERMINAL' ";
}
}
if(!empty($inSO)) {
if(empty($SQL_Extra)) {
$SQL_Extra = "WHERE sales_order_no LIKE '$inSO%' ";
} else {
$SQL_Extra = $SQL_Extra . " AND sales_order_no LIKE '$inSO%' ";
}
}
if(!empty($inSTARTDATE)) {
$PERIOD_START = format_date($inSTARTDATE). " 00:00:00";
if(empty($SQL_Extra)) {
$SQL_Extra = "WHERE date_in >= '$PERIOD_START' ";
} else {
$SQL_Extra = $SQL_Extra . " AND date_in >= '$PERIOD_START' ";
}
}
if(!empty($inENDDATE)) {
$PERIOD_END = format_date($inENDDATE). " 23:59:59";
if(empty($SQL_Extra)) {
$SQL_Extra = "WHERE date_in <= '$PERIOD_END' ";
} else {
$SQL_Extra = $SQL_Extra . " AND date_in <= '$PERIOD_END' ";
}
}
if(!empty($inSESSION)) {
if(empty($SQL_Extra)) {
$SQL_Extra = "WHERE session_id = '$inSESSION' ";
} else {
$SQL_Extra = $SQL_Extra . " AND session_id = '$inSESSION' ";
}
}

$Query = "SELECT * FROM sales_order_master " . $SQL_Extra."ORDER BY
location_code, terminal, sales_order_no DESC";
$db->query($Query);

// Display Content in List
while($db->next_record()){
$MasterIndex = $db->f("master_index");
$outSO = $db->f("sales_order_no");

$outACTIONS =


// calling report through php basically we need

// 1. full path of the web server
// 2. path of the report manager
// 3. Parameters -> Repoprt name , alias name & rest of the parameter depend on ur report


// creating a dynamic link to c report , passing parameter to report
// if u click this link u will c the actule report


htmlLink("View",$gMAIN_PATH."cgi-bin/repwebexe.bin/execute.pdf?reportname=%2Frptsalesorder&aliasname=SALES+ORDER&ParamSONO=$outSO");

$outLOCATION = $db->f("location_code");
$outTERMINAL = $db->f("terminal");
$outSESSION = $db->f("session_id");
$outDATE = substr(format_datetime($db->f("date_in")),0,10);
$outSTATUS = $db->f("status");

$t->set_var(array(
"ACTIONS" => $outACTIONS,
"SO" => $outSO,
"LOCATION" => $outLOCATION,
"TERMINAL" => $outTERMINAL,
"SESSION_ID" => $outSESSION,
"DATE" => $outDATE,
"STATUS" => $outSTATUS));

$t->parse("ITEMS_List", "ITEMS", true);
}
}
}


$t->set_var(array(
"MSG" => DisplayMsg($Msg, $ErrorFlag),
"inLOCATION" => htmlComboDB("inLOCATION", "DB_MRETAIL",
"SELECT * FROM def_outlets",
"name", "location_code", $inLOCATION),
"inTERMINAL" => htmlText("inTERMINAL", $inTERMINAL, 10, 10),
"inSO" => htmlText("inSO", $inSO, 10, 10),
"inSESSION" => htmlText("inSESSION", $inSESSION, 10, 10),
"inORDER" => htmlText("inORDER", $inORDER, 10,10),
"inSTARTDATE" => htmlText("inSTARTDATE",$inSTARTDATE, 10, 10).
"<A NAME=\"calposition1\" ID=\"calposition1\"></A>",
"Scalendar" => GenerateCalendar("Calendar", "DateSelector",
"document.forms[0].inSTARTDATE"),
"inENDDATE" => htmlText("inENDDATE", $inENDDATE, 10, 10),
"Ecalendar" => GenerateCalendar("Calendar", "DateSelector2",
"document.forms[0].inENDDATE"),
"HEADER_EXTRA" => GenerateCalendarHeader($ROOT_PATH."Common/"),
"FORM_ACTION" => $PAGE_NAME.".php" ));

$t->pparse("output", array("form"));

page_close();
?>

File SalesOrder_Search.shtml

<html>
<head>
<title>Sales Order Search</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../Common/mPOS.css" rel="stylesheet" type="text/css">
</head>
{HEADER_EXTRA}
<body>
<form action="{FORM_ACTION}" method="post" name="{FORM_NAME}" id="{FORM_NAME}">
<table width="480" border="1" bordercolor="#000000">
<tr>
<td class="DialogTitle">MPOS Sales Order : Search</td>
</tr>
<tr>
<td><table width="100%" border="0" bgcolor="#CCCCCC">
<tr>
<td colspan="2" class="FieldsHeader">{MSG}</td>
</tr>
<tr>
<td class="FieldsHeader">Location No</td>
<td class="Fields">{inLOCATION}</td>
</tr>
<tr>
<td class="FieldsHeader">Terminal No</td>
<td class="Fields">{inTERMINAL}</td>
</tr>
<tr>
<td class="FieldsHeader">Sales Order No</td>
<td class="Fields">{inSO}</td>
</tr>
<tr>
<td class="FieldsHeader">Start Date</td>
<td class="Fields">{inSTARTDATE}{Scalendar}</td>
</tr>
<tr>
<td class="FieldsHeader">End Date</td>
<td class="Fields">{inENDDATE}{Ecalendar}</td>
</tr>
<tr>
<td class="FieldsHeader">Session ID</td>
<td class="Fields">{inSESSION}</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="right">
<input name="Search" type="submit" id="Search" value="Search">
</div></td>
</tr>
</table></td>
</tr>
</table>
<p>&nbsp;</p>
<table width="580" border="1" cellpadding="1" cellspacing="0">
<tr>
<td bgcolor="#000000">
<table width="100%" border="0" cellpadding="1" cellspacing="1">
<tr class="ResultsHeader">
<td>Actions</td>
<td>Sales Order No</td>
<td>Location</td>
<td>Terminal</td>
<td>Session ID</td>
<td>Date</td>
<td>Status</td>
</tr>
<!-- BEGIN ITEMS -->
<tr class="Results">
<td>{ACTIONS}</td>
<td>{SO}</td>
<td>{LOCATION}</td>
<td>{TERMINAL}</td>
<td>{SESSION_ID}</td>
<td>{DATE}</td>
<td>{STATUS}</td>
</tr>
<!-- END ITEMS -->
</table></td>
</tr>
</table>
</form>
</body>
</html>