File: /home/mckernan/public_html/iJournal/includes/fixed/report.php
<?php
// fixed asset report
// init database name
$database = DB_PREFIX;
// process request
if ($sid != '')
{
// sid check
require "includes/session/sidck.php";
// fetch database name / open db
$dbn = '';
if ( isset($_POST['db']) ) $dbn = $_POST['db'];
if ( isset($_GET['db']) ) $dbn = $_GET['db'];
if ($dbn == '') die();
$database .= $dbn;
require "includes/db.php";
// get params
$year = getvar($db, 'yr', 'string');
// fetch client name
$client = '';
$query = "SELECT cli_sortname FROM client";
if ($result = $db->query($query))
{
$row = $result->fetch_assoc();
$client = $row['cli_sortname'];
}
// fetch assets
$data = array();
$total = 0.00;
$query = "SELECT fa_id, fa_date, fa_caption, fa_mos, fa_cost, fa_financed, fa_monthly FROM fixed_assets
WHERE fa_per IN (SELECT per_id FROM periods WHERE per_yr = '" . $year . "')
ORDER BY fa_date ASC";
if ($result = $db->query($query))
{
if ($db->affected_rows > 0)
{
while ($row = $result->fetch_assoc())
{
$date = date('M j, Y', strtotime($row['fa_date']));
$data[] = array(
'caption' => $row['fa_caption'],
'date' => $date,
'months' => $row['fa_mos'],
'cost' => $row['fa_cost'],
'financed' => $row['fa_financed']
);
$total += $row['fa_cost'];
}
}
}
$ct = count($data);
require "ReportClass.php";
$pdf = new PDF($client, $year);
$pdf->AliasNbPages();
$pdf->SetDrawColor(150, 150, 150);
$pdf->SetFillColor(242, 242, 242);
$pdf->SetFont('Arial', '', '9');
$pdf->AddPage();
$fill = false;
if ($ct > 0)
{
foreach ($data as $d)
{
$pdf->SetX(30);
$pdf->Cell(76, 5, $d['caption'], 1, 0, 'L', $fill);
$pdf->Cell(22, 5, $d['date'], 1, 0, 'L', $fill);
$pdf->Cell(14, 5, $d['months'], 1, 0, 'R', $fill);
$pdf->Cell(25, 5, number_format($d['cost'], 2), 1, 0, 'R', $fill);
$pdf->Cell(25, 5, number_format($d['financed'], 2), 1, 1, 'R', $fill);
$fill = !$fill;
}
$pdf->SetFont('Arial', 'B', '9');
$pdf->SetFillColor(230, 230, 230);
$pdf->SetX(30);
$pdf->Cell(80, 5, $ct . ' New Assets: ', 'LBT', 0, 'R', true);
$pdf->Cell(18, 5, '', 'BT', 0, 'T', true);
$pdf->Cell(14, 5, '', 'RBT', 0, 'R', true);
$pdf->Cell(25, 5, number_format($total, 2), 'LBRT', 0, 'R', true);
$pdf->Cell(25, 5, '', 'LRBT', 1, 'R', true);
}
else
{
$pdf->SetFont('Arial', 'I', '9');
$pdf->Ln(6);
$pdf->SetX(40);
$pdf->Cell(166, 5, '[ No new Fixed Assets found ]', 0, 0, "C");
}
$pdf->Output();
}
?>