<commit_before><?php
/*******************************************************************************
*
*  filename    : Reports/AdvancedDeposit.php
*  last change : 2005-03-29
*  description : Creates a PDF customized Deposit Report .
*
*  InfoCentral is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
******************************************************************************/

require "../Include/Config.php";
require "../Include/Functions.php";
require "../Include/ReportFunctions.php";
require "../Include/ReportConfig.php";

// Security
if (!$_SESSION['bFinance'] && !$_SESSION['bAdmin']) {
	Redirect("Menu.php");
	exit;
}

// Filter values
$sort = FilterInput($_POST["sort"]);
$detail_level = FilterInput($_POST["detail_level"]);
$output = FilterInput($_POST["output"]);
$sDateStart = FilterInput($_POST["DateStart"],"date");
$sDateEnd = FilterInput($_POST["DateEnd"],"date");
$iDepID = FilterInput($_POST["deposit"],"int");

if (!$sort)
	$sort = "deposit";
if (!$detail_level)
	$detail_level = "detail";
if (!$output)
	$output = "pdf"; 

// If CSVAdminOnly option is enabled and user is not admin, redirect to the menu.
if (!$_SESSION['bAdmin'] && $bCSVAdminOnly && $output != "pdf") {
	Redirect("Menu.php");
	exit;
}

// Build SQL Query
// Build SELECT SQL Portion
$sSQL = "SELECT fam_ID, fam_Name, fam_Address1, fam_Address2, fam_City, fam_State, fam_Zip, fam_Country, plg_date, plg_amount, plg_method, plg_comment, plg_depID, plg_CheckNo, fun_ID, fun_Name, dep_Date FROM pledge_plg
	LEFT JOIN family_fam ON plg_FamID=fam_ID
	INNER JOIN deposit_dep ON plg_depID = dep_ID
	LEFT JOIN donationfund_fun ON plg_fundID=fun_ID
	WHERE plg_PledgeOrPayment='Payment' ";

// Add  SQL criteria
// Report Dates OR Deposit ID
if ($iDepID > 0)
	$sSQL .= " AND plg_depID='$iDepID' ";
else {
	$today = date("Y-m-d");	
	if (!$sDateEnd && $sDateStart)
		$sDateEnd = $sDateStart;
	if (!$sDateStart && $sDateEnd)
		$sDateStart = $sDateEnd;
	if (!$sDateStart && !$sDateEnd){
		$sDateStart = $today;
		$sDateEnd = $today;
	}
	if ($sDateStart > $sDateEnd){
		$temp = $sDateStart;
		$sDateStart = $sDateEnd;
		$sDateEnd = $temp;
	}
	$sSQL .= " AND plg_date BETWEEN '$sDateStart' AND '$sDateEnd' ";
}

// Filter by Fund
if (!empty($_POST["funds"])) {
	$count = 0;
	foreach ($_POST["funds"] as $fundID) {
		$fund[$count++] = FilterInput($fundID,'int');
	}
	if ($count == 1) {
		if ($fund[0])
			$sSQL .= " AND plg_fundID='$fund[0]' ";
	} else {
		$sSQL .= " AND (plg_fundID ='$fund[0]'";
		for($i = 1; $i < $count; $i++) {
			$sSQL .= " OR plg_fundID='$fund[$i]'";
		}
		$sSQL .= ") ";
	}
}

// Filter by Family
if (!empty($_POST["family"])) {
	$count = 0;
	foreach ($_POST["family"] as $famID) {
		$fam[$count++] = FilterInput($famID,'int');
	}
	if ($count == 1) {
		if ($fam[0])
			$sSQL .= " AND plg_FamID='$fam[0]' ";
	} else {
		$sSQL .= " AND (plg_FamID='$fam[0]'";
		for($i = 1; $i < $count; $i++) {
			$sSQL .= " OR plg_FamID='$fam[$i]'";
		}
		$sSQL .= ") ";
	}
}

// Filter by Payment Method
if (!empty($_POST["method"])) {
	$count = 0;
	foreach ($_POST["method"] as $MethodItem) {
		$aMethod[$count++] = FilterInput($MethodItem);
	}
	if ($count == 1) {
		if ($aMethod[0])
			$sSQL .= " AND plg_method='$aMethod[0]' ";
	} else {
		$sSQL .= " AND (plg_method='$aMethod[0]' ";
		for($i = 1; $i < $count; $i++) {
			$sSQL .= " OR plg_method='$aMethod[$i]'";
		}
		$sSQL .= ") ";
	}
}

// Add SQL ORDER
if ($sort == "deposit")
	$sSQL .= " ORDER BY plg_depID, fun_Name, fam_Name, fam_ID";
elseif ($sort == "fund")
	$sSQL .= " ORDER BY fun_Name, fam_Name, fam_ID, plg_depID ";
elseif ($sort == "family")
	$sSQL .= " ORDER BY fam_Name, fam_ID, fun_Name, plg_depID";

//Execute SQL Statement
$rsReport = RunQuery($sSQL);

// Exit if no rows returned
$iCountRows = mysql_num_rows($rsReport);
if ($iCountRows < 1){
	header("Location: ../FinancialReports.php?ReturnMessage=NoRows&ReportType=Advanced%20Deposit%20Report"); 
}

// Create PDF Report -- PDF
// ***************************

if ($output == "pdf") {

	// Set up bottom border value
	$bottom_border = 250;
	$summaryIntervalY = 4;
	$page = 1;
	
	class PDF_TaxReport extends ChurchInfoReport {

		// Constructor
		function PDF_TaxReport() {
			parent::FPDF("P", "mm", $this->paperFormat);
			$this->SetFont("Times",'',10);
			$this->SetMargins(20,15);
			$this->Open();
			$this->SetAutoPageBreak(false);
		}
		
		function PrintRightJustified ($x, $y, $str) {
			$iLen = strlen ($str);
			$nMoveBy = 2 * $iLen;
			$this->SetXY ($x - $nMoveBy, $y);
			$this->Write (8, $str);
		}

		function StartFirstPage () {
			global $sDateStart, $sDateEnd, $sort, $iDepID;
			$this->AddPage();
			$curY = 20;
			$curX = 60;
			$this->SetFont('Times','B', 14);
			$this->WriteAt ($curX, $curY, $this->sChurchName . " Deposit Report");
			$curY += 2 * $this->incrementY;
			$this->SetFont('Times','B', 10);
			$curX = $this->leftX;
			$this->WriteAt ($curX, $curY, "Data sorted by " . ucwords($sort));
			$curY += $this->incrementY;
			if (!$iDepID) {
				$this->WriteAt ($curX, $curY, "Dates: $sDateStart through $sDateEnd");
				$curY += $this->incrementY;
			}
			if ($iDepID || $_POST['family'][0] || $_POST['funds'][0] || $_POST['method'][0]){
				$heading = "Filtered by ";
				if ($iDepID)
					$heading .= "Deposit #$iDepID, ";
				if ($_POST['family'][0])
					$heading .= "Selected Families, ";
				if ($_POST['funds'][0])
					$heading .= "Selected Funds, ";
				if ($_POST['method'][0])
					$heading .= "Selected Payment Methods, ";
				$heading = substr($heading,0,-2);
			} else {
				$heading = "Showing all records for report dates.";
			}
			$this->WriteAt ($curX, $curY, $heading);
			$curY += 2 * $this->incrementY;
			$this->SetFont("Times",'',10);
			return ($curY);
		}
		
		function PageBreak ($page) {
			// Finish footer of previous page if neccessary and add new page
			global $curY, $bottom_border, $detail_level;
			if ($curY > $bottom_border){
				$this->FinishPage($page);
				$page++;<commit_msg>Process "Apply Report Dates to: (Deposit or Payment Dates)" option.<commit_after><?php
/*******************************************************************************
*
*  filename    : Reports/AdvancedDeposit.php
*  last change : 2005-03-29
*  description : Creates a PDF customized Deposit Report .
*
*  InfoCentral is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
******************************************************************************/

require "../Include/Config.php";
require "../Include/Functions.php";
require "../Include/ReportFunctions.php";
require "../Include/ReportConfig.php";

// Security
if (!$_SESSION['bFinance'] && !$_SESSION['bAdmin']) {
	Redirect("Menu.php");
	exit;
}

// Filter values
$sort = FilterInput($_POST["sort"]);
$detail_level = FilterInput($_POST["detail_level"]);
$datetype = FilterInput($_POST["datetype"]);
$output = FilterInput($_POST["output"]);
$sDateStart = FilterInput($_POST["DateStart"],"date");
$sDateEnd = FilterInput($_POST["DateEnd"],"date");
$iDepID = FilterInput($_POST["deposit"],"int");

if (!$sort)
	$sort = "deposit";
if (!$detail_level)
	$detail_level = "detail";
if (!$output)
	$output = "pdf"; 

// If CSVAdminOnly option is enabled and user is not admin, redirect to the menu.
if (!$_SESSION['bAdmin'] && $bCSVAdminOnly && $output != "pdf") {
	Redirect("Menu.php");
	exit;
}

// Build SQL Query
// Build SELECT SQL Portion
$sSQL = "SELECT fam_ID, fam_Name, fam_Address1, fam_Address2, fam_City, fam_State, fam_Zip, fam_Country, plg_date, plg_amount, plg_method, plg_comment, plg_depID, plg_CheckNo, fun_ID, fun_Name, dep_Date FROM pledge_plg
	LEFT JOIN family_fam ON plg_FamID=fam_ID
	INNER JOIN deposit_dep ON plg_depID = dep_ID
	LEFT JOIN donationfund_fun ON plg_fundID=fun_ID
	WHERE plg_PledgeOrPayment='Payment' ";

// Add  SQL criteria
// Report Dates OR Deposit ID
if ($iDepID > 0)
	$sSQL .= " AND plg_depID='$iDepID' ";
else {
	$today = date("Y-m-d");	
	if (!$sDateEnd && $sDateStart)
		$sDateEnd = $sDateStart;
	if (!$sDateStart && $sDateEnd)
		$sDateStart = $sDateEnd;
	if (!$sDateStart && !$sDateEnd){
		$sDateStart = $today;
		$sDateEnd = $today;
	}
	if ($sDateStart > $sDateEnd){
		$temp = $sDateStart;
		$sDateStart = $sDateEnd;
		$sDateEnd = $temp;
	}
	if ($datetype == "Payment")
		$sSQL .= " AND plg_date BETWEEN '$sDateStart' AND '$sDateEnd' ";
	else
		$sSQL .= " AND dep_Date BETWEEN '$sDateStart' AND '$sDateEnd' ";
}

// Filter by Fund
if (!empty($_POST["funds"])) {
	$count = 0;
	foreach ($_POST["funds"] as $fundID) {
		$fund[$count++] = FilterInput($fundID,'int');
	}
	if ($count == 1) {
		if ($fund[0])
			$sSQL .= " AND plg_fundID='$fund[0]' ";
	} else {
		$sSQL .= " AND (plg_fundID ='$fund[0]'";
		for($i = 1; $i < $count; $i++) {
			$sSQL .= " OR plg_fundID='$fund[$i]'";
		}
		$sSQL .= ") ";
	}
}

// Filter by Family
if (!empty($_POST["family"])) {
	$count = 0;
	foreach ($_POST["family"] as $famID) {
		$fam[$count++] = FilterInput($famID,'int');
	}
	if ($count == 1) {
		if ($fam[0])
			$sSQL .= " AND plg_FamID='$fam[0]' ";
	} else {
		$sSQL .= " AND (plg_FamID='$fam[0]'";
		for($i = 1; $i < $count; $i++) {
			$sSQL .= " OR plg_FamID='$fam[$i]'";
		}
		$sSQL .= ") ";
	}
}

// Filter by Payment Method
if (!empty($_POST["method"])) {
	$count = 0;
	foreach ($_POST["method"] as $MethodItem) {
		$aMethod[$count++] = FilterInput($MethodItem);
	}
	if ($count == 1) {
		if ($aMethod[0])
			$sSQL .= " AND plg_method='$aMethod[0]' ";
	} else {
		$sSQL .= " AND (plg_method='$aMethod[0]' ";
		for($i = 1; $i < $count; $i++) {
			$sSQL .= " OR plg_method='$aMethod[$i]'";
		}
		$sSQL .= ") ";
	}
}

// Add SQL ORDER
if ($sort == "deposit")
	$sSQL .= " ORDER BY plg_depID, fun_Name, fam_Name, fam_ID";
elseif ($sort == "fund")
	$sSQL .= " ORDER BY fun_Name, fam_Name, fam_ID, plg_depID ";
elseif ($sort == "family")
	$sSQL .= " ORDER BY fam_Name, fam_ID, fun_Name, plg_depID";

//Execute SQL Statement
$rsReport = RunQuery($sSQL);

// Exit if no rows returned
$iCountRows = mysql_num_rows($rsReport);
if ($iCountRows < 1){
	header("Location: ../FinancialReports.php?ReturnMessage=NoRows&ReportType=Advanced%20Deposit%20Report"); 
}

// Create PDF Report -- PDF
// ***************************

if ($output == "pdf") {

	// Set up bottom border value
	$bottom_border = 250;
	$summaryIntervalY = 4;
	$page = 1;
	
	class PDF_TaxReport extends ChurchInfoReport {

		// Constructor
		function PDF_TaxReport() {
			parent::FPDF("P", "mm", $this->paperFormat);
			$this->SetFont("Times",'',10);
			$this->SetMargins(20,15);
			$this->Open();
			$this->SetAutoPageBreak(false);
		}
		
		function PrintRightJustified ($x, $y, $str) {
			$iLen = strlen ($str);
			$nMoveBy = 2 * $iLen;
			$this->SetXY ($x - $nMoveBy, $y);
			$this->Write (8, $str);
		}

		function StartFirstPage () {
			global $sDateStart, $sDateEnd, $sort, $iDepID, $datetype;
			$this->AddPage();
			$curY = 20;
			$curX = 60;
			$this->SetFont('Times','B', 14);
			$this->WriteAt ($curX, $curY, $this->sChurchName . " Deposit Report");
			$curY += 2 * $this->incrementY;
			$this->SetFont('Times','B', 10);
			$curX = $this->leftX;
			$this->WriteAt ($curX, $curY, "Data sorted by " . ucwords($sort));
			$curY += $this->incrementY;
			if (!$iDepID) {
				$this->WriteAt ($curX, $curY, "$datetype Dates: $sDateStart through $sDateEnd");
				$curY += $this->incrementY;
			}
			if ($iDepID || $_POST['family'][0] || $_POST['funds'][0] || $_POST['method'][0]){
				$heading = "Filtered by ";
				if ($iDepID)
					$heading .= "Deposit #$iDepID, ";
				if ($_POST['family'][0])
					$heading .= "Selected Families, ";
				if ($_POST['funds'][0])
					$heading .= "Selected Funds, ";
				if ($_POST['method'][0])
					$heading .= "Selected Payment Methods, ";
				$heading = substr($heading,0,-2);
			} else {
				$heading = "Showing all records for report dates.";
			}
			$this->WriteAt ($curX, $curY, $heading);
			$curY += 2 * $this->incrementY;
			$this->SetFont("Times",'',10);
			return ($curY);
		}
		
		function PageBreak ($page) {
			// Finish footer of previous page if neccessary and add new page
			global $curY, $bottom_border, $detail_level;
			if ($curY > $bottom_border){
				$this->FinishPage($page);
				$page++;
{'fraction_non_alphanumeric': 0.22437075509388735, 'fraction_numerical': 0.010866959648421893, 'mean_word_length': 4.106487148102815, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3504091', 'n_tokens_mistral': 5165, 'n_tokens_neox': 4649, 'n_words': 1089}