Here's the code for the input window that pops up first:
<?php
session_start();
require_once('../../config.db.php');
require_once('../../config.inc.php');
require_once("Functions/corp.functions.php");
$action = (isset($_POST['action'])) ? ($_POST['action']) : ($_GET['action']);
$link = mysql_connect($myDbConfig->server,$myDbConfig->user,$myDbConfig->pass) or die(mysql_error());
mysql_select_db($myDbConfig->db) or die(mysql_error());
switch ($action){
case 'form':
getForm();
break;
default:
break;
}
mysql_close($link);
exit(0);
function getForm(){
$userID = $_SESSION['UserID'];
$reportNo = $_GET['repID'];
?>
// Add the additional 'advanced' VTypes
Ext.apply(Ext.form.VTypes, {
dateRange: function(val, field) {
var date = field.parseDate(val);
// We need to force the picker to update values to recaluate the disabled dates display
var dispUpd = function(picker) {
var ad = picker.activeDate;
picker.activeDate = null;
picker.update(ad);
};
if (field.startDateField) {
var sd = Ext.getCmp(field.startDateField);
sd.maxValue = date;
if (sd.menu && sd.menu.picker) {
sd.menu.picker.maxDate = date;
dispUpd(sd.menu.picker);
}
} else if (field.endDateField) {
var ed = Ext.getCmp(field.endDateField);
ed.minValue = date;
if (ed.menu && ed.menu.picker) {
ed.menu.picker.minDate = date;
dispUpd(ed.menu.picker);
}
}
/* Always return true since we're only using this vtype to set the min/max allowed values
(these are tested for after the vtype test) */
return true;
}});
var itemsForm = getForm();
function getForm(){
var date = new Date();
var sdate = new Date();
var edate = new Date();
// set start date to first day of month and end date to last day
// PHP will handle previous month of Jan (Dec of 'previous year')
sdate.setMonth(sdate.getMonth()-1,1);
edate.setMonth(edate.getMonth(),0);
var startDate = new Ext.form.DateField({
fieldLabel: 'Start Date',
format: 'm/d/Y',
name: 'start',
id: 'startDate',
endDateField: 'endDate',
hiddenName: 'start',
allowBlank: false,
vtype: 'dateRange',
maxValue: date,
value: sdate
});
var endDate = new Ext.form.DateField({
fieldLabel: 'End Date',
format: 'm/d/Y',
name: 'end',
vtype: 'dateRange',
id: 'endDate',
startDateField: 'startDate',
hiddenName: 'end',
allowBlank: false,
maxValue: date,
value: edate
});
var vHuman = new Ext.form.Checkbox({
boxLabel: 'DMs',
checked: true,
value: isHuman
});
var vHouse = new Ext.form.Checkbox({
boxLabel: 'House',
checked: false,
value: isHouse
});
var itemsForm = new Ext.form.FormPanel({
border: false,
height: 230,
id: 'itemsform',
method:'POST',
url:'reports/scheduler/newreport.php',
baseParams: {userid: <?php echo $userID; ?>, reportid: <?php echo $reportNo; ?>},
items:[startDate, endDate, vHuman, vHouse]
});
return itemsForm;
}
<?php
}
?>and the code that actually runs the sql query and gets the data (yes, i know I haven't done anything with the checkbox data yet in sql... need this solved first)<?php
require_once('c:/htdocs/corp/config.inc.php');
require_once('c:/htdocs/corp/config.db.php');
require_once("Functions/corp.functions.php");
require_once("Logger/class.Logger.php");
require_once("Reports/class.ReportInstance.php");
//$cfg['LOGGER_LEVEL'] = LOGGER_DEBUG; //all levels logged
//$cfg['LOGGER_LEVEL'] = LOGGER_INFO; //loggs levels info,notice,warning,error,critical
//$cfg['LOGGER_LEVEL'] = LOGGER_NOTICE; //loggs levels notice,warning,error,critical
//$cfg['LOGGER_LEVEL'] = LOGGER_WARNING; //loggs levels warning,error,critical
//$cfg['LOGGER_LEVEL'] = LOGGER_ERROR; //loggs levels error,critical
$cfg['LOGGER_LEVEL'] = LOGGER_CRITICAL; //loggs levels critical
define('THIS_FILE','SalesDMGPReport.php');
define('LOG_FILE','CORP');
try{
$conString = "mysql://".$myDbConfig->user."@".$myDbConfig->server."/".$myDbConfig->db."?password=".$myDbConfig->pass."&logname=CORP";
Logger::register('CORP',$conString);
}catch(Exception $e){
throw new Exception($e->getMessage());
}
try{
$log = Logger::getInstance(LOG_FILE);
}catch(Exception $e){
throw new Exception($e->getMessage());
}
$log->logMessage('Parsing arguments....',LOGGER_DEBUG,THIS_FILE);
$riID = $argv[1];
if(!isset($riID)){
$log->logMessage("Missing required arguments",LOGGER_CRITICAL,THIS_FILE);
throw new Exception("Invalid arguments");
exit(0);
}else{
$log->logMessage('Retrieved argument '.$riID,LOGGER_DEBUG,THIS_FILE);
}
$log->logMessage("Connecting to the ".$myDbConfig->db." database",LOGGER_DEBUG,THIS_FILE);
$link = @mysql_connect($myDbConfig->server,$myDbConfig->user,$myDbConfig->pass);
mysql_select_db($myDbConfig->db);
$log->logMessage("Creating report instance using ID - ".$riID,LOGGER_DEBUG,THIS_FILE);
$riObject = new ReportInstance($riID,$log,THIS_FILE);
$userID = $riObject->getSubmittingUser();
$log->logMessage("Retrieving Criteria from the ReportInstanceObject",LOGGER_DEBUG,THIS_FILE);
$log->logMessage(print_r($riObject,true),LOGGER_DEBUG,THIS_FILE);
$sdate = date('Y-m-d',strtotime($riObject->criteria['start']->getValue()));
$edate = date('Y-m-d',strtotime($riObject->criteria['end']->getValue()));
$vhuman = $riObject->criteria['vHuman']->getValue();
$vhouse = $riObject->criteria['vHouse']->getValue();
$log->logMessage("Retrieving results",LOGGER_DEBUG,THIS_FILE);
echo $vhuman;
echo $vhouse;
$data = reportFunc($sdate,$edate,$vhuman,$vhouse,$log);
writeFile($log,$data,$riID.'_1_1.json');
$note = "For ".$sdate." to ".$edate;
$riObject->setNote($note);
$riObject->setStatus('C');
exit(1);
/********************************************************************************************************************************
************************* FUNCTION(S) ************************************************************************************
*********************************************************************************************************************************/
function reportFunc($sdate,$edate,$vhuman,$vhouse,$log){
$log->logMessage("date range { $sdate - $edate }",LOGGER_DEBUG,THIS_FILE);
$arr=array();
$sql ="SELECT h.DistrictManager, ROUND(SUM(l.ShipQuantity * l.Price), 2) AS Sales, ROUND(SUM(l.ShipQuantity * l.Cost), 2) AS CostOfGoods, ";
$sql .=" ROUND(((SUM(l.Price * l.ShipQuantity) - SUM(l.ShipQuantity * l.Cost)) / SUM(l.Price * l.ShipQuantity)) * 100, 2) AS GPP, ";
$sql .=" ROUND(SUM(l.Price * l.ShipQuantity) - SUM(l.ShipQuantity * l.Cost), 2) AS GPD, ROUND(AVG(CommissionRate), 2) as AvgComm";
$sql .=" FROM invoices_saleshead h INNER JOIN invoices_salesline l ";
$sql .=" ON h.InvoiceNumber = l.InvoiceNumber";
$sql .=" WHERE (l.InvoiceDate >= '$sdate') AND (l.InvoiceDate <= '$edate')";
$sql .=" AND (l.ShipQuantity != 0) AND (l.Price != 0)";
$sql .=" GROUP BY h.DistrictManager ORDER BY h.DistrictManager";
//
//echo $sql;
$rs = mysql_query($sql) or die(mysql_error());
while($obj=mysql_fetch_object($rs)){
$arr[]=$obj;
}
return json_encode($arr);
}
?>PLEASE help me.... this is for work, I'm tired, I've looked through many resources.... I feel stupid..lolAlso- the date parameters work fine.
Note to John, WingedPanther, Jaan, or Orjan- I made this post originally in Java forum, please erase it... thanks.


Sign In
Create Account


Back to top









