<commit_before><?php
/*******************************************************************************
 *
 *  filename    : DepositSlipEditor.php
 *  last change : 2004-6-12
 *  website     : http://www.infocentral.org
 *  copyright   : Copyright 2001, 2002, 2003 <NAME>, <NAME>, <NAME>
 *
 *  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.
 *
 ******************************************************************************/

//Include the function library
require "Include/Config.php";
require "Include/Functions.php";

$linkBack = FilterInput($_GET["linkBack"]);
$iDepositSlipID = FilterInput($_GET["DepositSlipID"]);
$sDepositType = FilterInput($_GET["DepositType"]);

// Security: User must have finance permission to use this form
if (!$_SESSION['bFinance'])
{
	Redirect("Menu.php");
	exit;
}

if ($iDepositSlipID) {
	// Get the current deposit slip
	$sSQL = "SELECT * from deposit_dep WHERE dep_ID = " . $iDepositSlipID;
	$rsDeposit = RunQuery($sSQL);
	extract(mysql_fetch_array($rsDeposit));
}

//Set the page title
if (! $iDepositSlipID)
	$sPageTitle = $dep_Type . " " . gettext("Deposit Slip Number: TBD");
else
	$sPageTitle = $dep_Type . " " . gettext("Deposit Slip Number: ") . $iDepositSlipID;

//Is this the second pass?
if (isset($_POST["DepositSlipSubmit"]))
{
	//Get all the variables from the request object and assign them locally
	$dDate = FilterInput($_POST["Date"]);
	$sComment = FilterInput($_POST["Comment"]);
	$bClosed = FilterInput($_POST["Closed"]);
	if (! $bClosed)
		$bClosed = 0;

	//Initialize the error flag
	$bErrorFlag = false;

	// Validate Date
	if (strlen($dDate) > 0)
	{
		list($iYear, $iMonth, $iDay) = sscanf($dDate,"%04d-%02d-%02d");
		if ( !checkdate($iMonth,$iDay,$iYear) )
		{
			$sDateError = "<span style=\"color: red; \">" . gettext("Not a valid Date") . "</span>";
			$bErrorFlag = true;
		}
	}

	//If no errors, then let's update...
	if (!$bErrorFlag)
	{
		// New deposit slip
		if (! $iDepositSlipID)
		{
			$sSQL = "INSERT INTO deposit_dep (dep_Date, dep_Comment, dep_EnteredBy, dep_Closed, dep_Type) 
			VALUES ('" . $dDate . "','" . $sComment . "'," . $_SESSION['iUserID'] . "," . $bClosed . ",'" . $sDepositType . "')";
			$bGetKeyBack = True;

		// Existing record (update)
		} else {
			$sSQL = "UPDATE deposit_dep SET dep_Date = '" . $dDate . "', dep_Comment = '" . $sComment . "', dep_EnteredBy = ". $_SESSION['iUserID'] . ", dep_Closed = " . $bClosed . " WHERE dep_ID = " . $iDepositSlipID . ";";
			$bGetKeyBack = false;
		}

		//Execute the SQL
		RunQuery($sSQL);

		// If this is a new deposit slip, get the key back
		if ($bGetKeyBack)
		{
			$sSQL = "SELECT MAX(dep_ID) AS iDepositSlipID FROM deposit_dep";
			$rsDepositSlipID = RunQuery($sSQL);
			extract(mysql_fetch_array($rsDepositSlipID));
			$_SESSION['iCurrentDeposit'] = $iDepositSlipID;
		}

		if (isset($_POST["DepositSlipSubmit"]))
		{
			if ($linkBack != "") {
				Redirect($linkBack);
			} else {
				//Send to the view of this DepositSlip
				Redirect("DepositSlipEditor.php?linkBack=" . $linkBack . "&DepositSlipID=" . $iDepositSlipID);
			}
		}
	}
} else if (isset($_POST["DepositSlipLoadAuthorized"])) {

	// Create all the payment records that have been authorized

	//Get all the variables from the request object and assign them locally
	$dDate = FilterInput($_POST["Date"]);
	$sComment = FilterInput($_POST["Comment"]);
	$bClosed = FilterInput($_POST["Closed"]);
	if (! $bClosed)
		$bClosed = 0;

	// Create any transactions that are authorized as of today
	if ($dep_Type == "CreditCard") {
		$enableStr = "fam_enableCreditCard=1";
		$dateStr = "fam_creditCardDate";
	} else {
		$enableStr = "fam_enableBankDraft=1";
		$dateStr = "fam_bankDraftDate";
	}

	// Compute the current fiscal year ID
	$yearNow = date ("Y");
	$monthNow = date ("m");
	$FYID = $yearNow - 1995;
	if ($monthNow > 3)
		$FYID += 1;

	// Get all the families with authorized automatic transactions
	$sSQL = "SELECT * FROM family_fam WHERE " . $enableStr . " AND " . $dateStr . "<='" . date('Y-m-d') . "'";

	$rsAuthorizedFamilies = RunQuery($sSQL);

	while ($aFam =mysql_fetch_array($rsAuthorizedFamilies))
	{
		extract($aFam);
		if ($dep_Type == "CreditCard") {
			$interval = $fam_creditCardInterval;
			$amount = $fam_creditCardAmount;
			$method = "CREDITCARD";
			$fund = $fam_creditCardFund;
			$authDate = $fam_creditCardDate;
			$scanString = $fam_scanCredit;
		} else {
			$interval = $fam_bankDraftInterval;
			$amount = $fam_bankDraftAmount;
			$method = "BANKDRAFT";
			$fund = $fam_bankDraftFund;
			$authDate = $fam_bankDraftDate;
			$scanString = $fam_scanCheck;
		}
		if ($amount > 0.00) {
			$sSQL = "INSERT INTO pledge_plg (plg_FamID, 
														plg_FYID, 
														plg_date, 
														plg_amount, 
														plg_method, 
														plg_DateLastEdited, 
														plg_EditedBy, 
														plg_PledgeOrPayment, 
														plg_fundID, 
														plg_depID,
														plg_scanString)
											VALUES (" .
														$fam_ID . "," .
														$FYID . "," .
														"'" . date ("Y-m-d") . "'," .
														$amount . "," .
														"'" . $method . "'," .
														"'" . date ("Y-m-d") . "'," .
														$_SESSION['iUserID'] . "," .
														"'Payment'," .
														$fund . "," .
														$dep_ID . "," .
														"'" . $scanString . "')";
			RunQuery ($sSQL);

			// Push the authorized transaction date forward by the interval
			$sSQL = "UPDATE family_fam SET " . $dateStr . "=DATE_ADD('" . $authDate . "', INTERVAL " . $interval . " MONTH) WHERE fam_ID = " . $fam_ID;
			RunQuery ($sSQL);
		}
	}
} else {

	//FirstPass
	//Are we editing or adding?
	if ($iDepositSlipID)
	{
		//Editing....
		//Get all the data on this record
																		
		$sSQL = "SELECT * FROM deposit_dep WHERE dep_ID = " . $iDepositSlipID;
		$rsDepositSlip = RunQuery($sSQL);
		extract(mysql_fetch_array($rsDepositSlip));

		$dDate = $dep_Date;
		$sComment = $dep_Comment;
		$bClosed = $dep_Closed;
	}
	else
	{
		//Adding....
		//Set defaults
	}
}

if ($iDepositSlipID) {
	//Get the payments for this deposit slip
	$sSQL = "SELECT plg_plgID, plg_date, plg_amount, plg_CheckNo, plg_method, plg_comment, 
	         a.fam_Name AS FamilyName, b.fun_Name as fundName
			 FROM pledge_plg 
			 LEFT JOIN family_fam a ON plg_FamID = a.fam_ID
			 LEFT JOIN donationfund_fun b ON plg_fundID = b.fun_ID
			 WHERE plg_depID = " . $iDepositSlipID . " ORDER BY pledge_plg.plg_date";
	$rsPledges = RunQuery($sSQL);
} else {
	$rsPledges = 0;
}

require "Include/Header.php";

?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?linkBack=" . $linkBack . "&DepositSlipID=".$iDepositSlipID . "&DepositType=".$sDepositType?>" name="DepositSlipEditor">

<table cellpadding="3" align="center">

	<tr>
		<td align="center">
			<input type="submit" class="icButton" value="<?php echo gettext("Save"); ?>" name="DepositSlipSubmit">
			<input type="button" class="icButton" value="<?php echo gettext("Cancel"); ?>" name="DepositSlipCancel" onclick="javascript:document.location='<?php if (strlen($linkBack) > 0) { echo $linkBack; } else {echo "Menu.php"; } ?>';">

			<?php if ($dep_Type == 'Bank') { ?>
			<input type="button" class="icButton" value="<?php echo gettext("Generate PDF"); ?>" name="DepositSlipGeneratePDF" onclick="javascript:document.location='Reports/PrintDeposit.php';">
			<?php } ?>

			<?php if ($dep_Type == 'BankDraft' || $dep_Type == 'CreditCard') { ?>
			<input type="submit" class="icButton" value="<?php echo gettext("Load Authorized Transactions"); ?>" name="DepositSlipLoadAuthorized">
			<?php } ?>

		</td>
	</tr>

	<tr>
		<td>
		<table cellpadding="3">
			<tr>
				<td class="LabelColumn"><?php addToolTip("Format: YYYY-MM-DD<br>or enter the date by clicking on the calendar icon to the right."); ?><?php echo gettext("Date:"); ?></td>
				<td class="TextColumn"><input type="text" name="Date" value="<?php echo $dDate; ?>" maxlength="10" id="sel1" size="11">&nbsp;<input type="image" onclick="return showCalendar('sel1', 'y-mm-dd');" src="Images/calendar.gif"> <span class="SmallText"><?php echo gettext("[format: YYYY-MM-DD]"); ?></span><font color="red"><?php echo $sDateError ?></font></td>
			</tr>

			<tr>
				<td class="LabelColumn"><?php echo gettext("Comment:"); ?></td>
				<td class="TextColumn"><input type="text" name="Comment" id="Comment" value="<?php echo $sComment; ?>"></td>
			</tr>

			<tr>
				<td class="LabelColumn"><?php echo gettext("Closed:"); ?></td>
				<td class="TextColumn"><input type="checkbox" name="Closed" value="1" <?php if ($bClosed) echo " checked";?>><?php echo gettext("Close deposit slip (remember to press Save)"); ?>
			</tr>

		</table>
		</td>
	</form><commit_msg>Added stuff to process the transactions through ECHO<commit_after><?php
/*******************************************************************************
 *
 *  filename    : DepositSlipEditor.php
 *  last change : 2004-6-12
 *  website     : http://www.infocentral.org
 *  copyright   : Copyright 2001, 2002, 2003 <NAME>, <NAME>, <NAME>
 *
 *  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.
 *
 ******************************************************************************/

//Include the function library
require "Include/Config.php";
require "Include/Functions.php";

require "Include/MICRFunctions.php";

$linkBack = FilterInput($_GET["linkBack"]);
$iDepositSlipID = FilterInput($_GET["DepositSlipID"]);
$sDepositType = FilterInput($_GET["DepositType"]);

// Security: User must have finance permission to use this form
if (!$_SESSION['bFinance'])
{
	Redirect("Menu.php");
	exit;
}

if ($iDepositSlipID) {
	// Get the current deposit slip
	$sSQL = "SELECT * from deposit_dep WHERE dep_ID = " . $iDepositSlipID;
	$rsDeposit = RunQuery($sSQL);
	extract(mysql_fetch_array($rsDeposit));
}

//Set the page title
if (! $iDepositSlipID)
	$sPageTitle = $dep_Type . " " . gettext("Deposit Slip Number: TBD");
else
	$sPageTitle = $dep_Type . " " . gettext("Deposit Slip Number: ") . $iDepositSlipID;

//Is this the second pass?
if (isset($_POST["DepositSlipSubmit"]))
{
	//Get all the variables from the request object and assign them locally
	$dDate = FilterInput($_POST["Date"]);
	$sComment = FilterInput($_POST["Comment"]);
	$bClosed = FilterInput($_POST["Closed"]);
	if (! $bClosed)
		$bClosed = 0;

	//Initialize the error flag
	$bErrorFlag = false;

	// Validate Date
	if (strlen($dDate) > 0)
	{
		list($iYear, $iMonth, $iDay) = sscanf($dDate,"%04d-%02d-%02d");
		if ( !checkdate($iMonth,$iDay,$iYear) )
		{
			$sDateError = "<span style=\"color: red; \">" . gettext("Not a valid Date") . "</span>";
			$bErrorFlag = true;
		}
	}

	//If no errors, then let's update...
	if (!$bErrorFlag)
	{
		// New deposit slip
		if (! $iDepositSlipID)
		{
			$sSQL = "INSERT INTO deposit_dep (dep_Date, dep_Comment, dep_EnteredBy, dep_Closed, dep_Type) 
			VALUES ('" . $dDate . "','" . $sComment . "'," . $_SESSION['iUserID'] . "," . $bClosed . ",'" . $sDepositType . "')";
			$bGetKeyBack = True;

		// Existing record (update)
		} else {
			$sSQL = "UPDATE deposit_dep SET dep_Date = '" . $dDate . "', dep_Comment = '" . $sComment . "', dep_EnteredBy = ". $_SESSION['iUserID'] . ", dep_Closed = " . $bClosed . " WHERE dep_ID = " . $iDepositSlipID . ";";
			$bGetKeyBack = false;
		}

		//Execute the SQL
		RunQuery($sSQL);

		// If this is a new deposit slip, get the key back
		if ($bGetKeyBack)
		{
			$sSQL = "SELECT MAX(dep_ID) AS iDepositSlipID FROM deposit_dep";
			$rsDepositSlipID = RunQuery($sSQL);
			extract(mysql_fetch_array($rsDepositSlipID));
			$_SESSION['iCurrentDeposit'] = $iDepositSlipID;
		}

		if (isset($_POST["DepositSlipSubmit"]))
		{
			if ($linkBack != "") {
				Redirect($linkBack);
			} else {
				//Send to the view of this DepositSlip
				Redirect("DepositSlipEditor.php?linkBack=" . $linkBack . "&DepositSlipID=" . $iDepositSlipID);
			}
		}
	}
} else if (isset($_POST["DepositSlipLoadAuthorized"])) {

	// Create all the payment records that have been authorized

	//Get all the variables from the request object and assign them locally
	$dDate = FilterInput($_POST["Date"]);
	$sComment = FilterInput($_POST["Comment"]);
	$bClosed = FilterInput($_POST["Closed"]);
	if (! $bClosed)
		$bClosed = 0;

	// Create any transactions that are authorized as of today
	if ($dep_Type == "CreditCard") {
		$enableStr = "fam_enableCreditCard=1";
		$dateStr = "fam_creditCardDate";
	} else {
		$enableStr = "fam_enableBankDraft=1";
		$dateStr = "fam_bankDraftDate";
	}

	// Compute the current fiscal year ID
	$yearNow = date ("Y");
	$monthNow = date ("m");
	$FYID = $yearNow - 1995;
	if ($monthNow > 3)
		$FYID += 1;

	// Get all the families with authorized automatic transactions
	$sSQL = "SELECT * FROM family_fam WHERE " . $enableStr . " AND " . $dateStr . "<='" . date('Y-m-d') . "'";

	$rsAuthorizedFamilies = RunQuery($sSQL);

	while ($aFam =mysql_fetch_array($rsAuthorizedFamilies))
	{
		extract($aFam);
		if ($dep_Type == "CreditCard") {
			$interval = $fam_creditCardInterval;
			$amount = $fam_creditCardAmount;
			$method = "CREDITCARD";
			$fund = $fam_creditCardFund;
			$authDate = $fam_creditCardDate;
			$scanString = $fam_scanCredit;
		} else {
			$interval = $fam_bankDraftInterval;
			$amount = $fam_bankDraftAmount;
			$method = "BANKDRAFT";
			$fund = $fam_bankDraftFund;
			$authDate = $fam_bankDraftDate;
			$scanString = $fam_scanCheck;
		}
		if ($amount > 0.00) {
			$sSQL = "INSERT INTO pledge_plg (plg_FamID, 
														plg_FYID, 
														plg_date, 
														plg_amount, 
														plg_method, 
														plg_DateLastEdited, 
														plg_EditedBy, 
														plg_PledgeOrPayment, 
														plg_fundID, 
														plg_depID,
														plg_scanString)
											VALUES (" .
														$fam_ID . "," .
														$FYID . "," .
														"'" . date ("Y-m-d") . "'," .
														$amount . "," .
														"'" . $method . "'," .
														"'" . date ("Y-m-d") . "'," .
														$_SESSION['iUserID'] . "," .
														"'Payment'," .
														$fund . "," .
														$dep_ID . "," .
														"'" . $scanString . "')";
			RunQuery ($sSQL);

			// Push the authorized transaction date forward by the interval
			$sSQL = "UPDATE family_fam SET " . $dateStr . "=DATE_ADD('" . $authDate . "', INTERVAL " . $interval . " MONTH) WHERE fam_ID = " . $fam_ID;
			RunQuery ($sSQL);
		}
	}
} else if (isset($_POST["DepositSlipRunTransactions"])) {

	// Process all the transactions

	//Get the payments for this deposit slip
	$sSQL = "SELECT plg_amount, 
	                plg_scanString, 
						 a.fam_Address1 AS address1,
						 a.fam_Address2 AS address2,
						 a.fam_City AS city,
						 a.fam_State AS state,
						 a.fam_Zip AS zip,
						 a.fam_Country AS country,
						 a.fam_HomePhone AS phone,
						 a.fam_Email AS email
			 FROM pledge_plg 
			 LEFT JOIN family_fam a ON plg_FamID = a.fam_ID
			 LEFT JOIN donationfund_fun b ON plg_fundID = b.fun_ID
			 WHERE plg_depID = " . $iDepositSlipID . " ORDER BY pledge_plg.plg_date";
	$rsTransactions = RunQuery($sSQL);

	include ("Include/echophp.class");
	include ("Include/EchoConfig.inc"); // Specific account information is in here

	// Instantiate the MICR class
	$micrObj = new MICRReader();

	$echoPHP = new EchoPHP;

	while ($aTransaction =mysql_fetch_array($rsTransactions))
	{
		extract($aTransaction);

		$echoPHP->set_EchoServer("https://wwws.echo-inc.com/scripts/INR200.EXE");
		$echoPHP->set_merchant_echo_id ($EchoAccount);
		$echoPHP->set_merchant_pin ($EchoPin);

		$echoPHP->set_grand_total($plg_amount);

		$echoPHP->set_billing_phone($phone);
		$echoPHP->set_billing_address1($address1);
		$echoPHP->set_billing_city($city);
		$echoPHP->set_billing_state($state);
		$echoPHP->set_billing_zip($zip);
		$echoPHP->set_billing_country($country);
	//	$echoPHP->set_billing_fax("503-123-4569");
		$echoPHP->set_billing_email($email);

		$echoPHP->set_billing_ip_address($REMOTE_ADDR);

		$echoPHP->set_order_type("S");

		if ($dep_Type == "CreditCard") {
			$posLastName = strpos ($plg_scanString, "^") + 1;
			$posFirstName = strpos ($plg_scanString, "/", $posLastName) + 1;
			$posDateMonth = strpos ($plg_scanString, "^", $posFirstName) + 1;
			$posDateYear = $posDateMonth + 2;

			$creditCardNumber = substr ($plg_scanString, 2, 4) . " " .
									  substr ($plg_scanString, 6, 4) . " " .
									  substr ($plg_scanString, 10, 4) . " " .
									  substr ($plg_scanString, 14, 4);
			$creditCardExpYear = substr ($plg_scanString, $posDateMonth, 2);
			$creditCardExpMonth = substr ($plg_scanString, $posDateYear, 2);
			$firstName = substr ($plg_scanString, $posFirstName, $posDateMonth - $posFirstName - 1);
			$lastName = substr ($plg_scanString, $posLastName, $posFirstName - $posLastName - 1);

			$echoPHP->set_billing_first_name($firstName);
			$echoPHP->set_billing_last_name($lastName);
			$echoPHP->set_cc_number($creditCardNumber);
			$echoPHP->set_ccexp_month($creditCardExpMonth);
			$echoPHP->set_ccexp_year($creditCardExpYear);

			$echoPHP->set_transaction_type("EV");

			// $echoPHP->set_cnp_security(3333);  // The three-digit MasterCard (CVC2) or VISA (CVV2) or the four-digit Discover (CID) 
			// or AMEX card-not-present security code.

		} else {
			// check payment info if supplied...
			$echoPHP->set_ec_bank_name(""); // **
			$echoPHP->set_ec_first_name("First"); // **
			$echoPHP->set_ec_last_name("Last"); // **
			$echoPHP->set_ec_address1($address1);
			$echoPHP->set_ec_city($city);
			$echoPHP->set_ec_state($state);
			$echoPHP->set_ec_zip($zip);
			$echoPHP->set_ec_rt($micrObj->FindRoute ($plg_scanString));
			$echoPHP->set_ec_account($micrObj->FindAccount ($plg_scanString));
			$echoPHP->set_ec_serial_number(1); // ** check number
			$echoPHP->set_ec_payee($EchoPayee);
			//$echoPHP->set_ec_id_state("");
			//$echoPHP->set_ec_id_number("");
			//$echoPHP->set_ec_id_type("");

			$echoPHP->set_transaction_type("DD");
		}

		$echoPHP->set_debug("T");  // set to T to turn on debugging

		$echoPHP->set_counter("1");
		print("You are using the " . $echoPHP->get_version() . "<hr>");

		if (!($echoPHP->Submit()))  {
			if ($echoPHP->decline_code == "1013") {
				echo "<b>Transaction Declined: Decline code 1013</b><br><br>The merchant account ";
				echo "could not login to the ECHOnline server (maybe your ";
				echo "PIN is incorrect?), or transaction_type or order_type was found to be invalid. To ensure your ECHO-ID and PIN are correct, you should be able ";
				echo "to login to the <a href=\"https://wwws.echo-inc.com/login.asp\">ECHO Merchant Center</a>. ";
				echo "If you can't, please contact <i>ECHO</i> Customer Service at 1-800-262-3246, ext. 1 and ";
				echo "they will help you resolve the problem.";
				echo "<br><br><b>ECHO Response:</b><br>";
			}
			echo "</body></html>";
		} else  {
			// At this point, your transaction was successful.  You can insert your results into your database, etc.
			// You do not need to parse <ECHOTYPE3>, we do this for you and put the results into variables.
			print("<b>Congratulations!</b> Your transaction was successful.  The results of your transaction ");
			print("have been stored in these variables for you ");
			print("(see <a href=https://wwws.echo-inc.com/ISPGuide-Interface.asp>Response Protocol</a> for return information):");
			print("<br>\$echoPHP->authorization<br>\$echoPHP->order_number<br>\$echoPHP->reference<br>\$echoPHP->status<br>");
			print("\$echoPHP->avs_result<br>\$echoPHP->security_result<br>\$echoPHP->mac<br>\$echoPHP->decline_code<br>");
			print("\$echoPHP->tran_date<br>\$echoPHP->merchant_name<br>\$echoPHP->version<br><br>\$echoPHP->EchoResponse");
			print("<br>\$echoPHP->echotype1<br>\$echoPHP->echotype2<br>\$echoPHP->echotype3<br><br>I am printing the ");
			print("\$echoPHP->EchoResponse variable here: <br>");
		}

		// This prints the ECHO response.  You always get back <ECHOTYPE1>, <ECHOTYPE2>, and <ECHOTYPE3> tags.
		// View the page source to see all three <ECHOTYPE3> results.
		print($echoPHP->EchoResponse . "<br>");
    
		echo "<hr>Printing all properties of PHP class for debugging purposes..<br>";
		echo "If you set debug to T, you will get back more information in EchoResponse<br>";
		echo "<pre>"; 
		var_dump($echoPHP); 
		echo "</pre>";    
	}

} else {

	//FirstPass
	//Are we editing or adding?
	if ($iDepositSlipID)
	{
		//Editing....
		//Get all the data on this record
																		
		$sSQL = "SELECT * FROM deposit_dep WHERE dep_ID = " . $iDepositSlipID;
		$rsDepositSlip = RunQuery($sSQL);
		extract(mysql_fetch_array($rsDepositSlip));

		$dDate = $dep_Date;
		$sComment = $dep_Comment;
		$bClosed = $dep_Closed;
	}
	else
	{
		//Adding....
		//Set defaults
	}
}

if ($iDepositSlipID) {
	//Get the payments for this deposit slip
	$sSQL = "SELECT plg_plgID, plg_date, plg_amount, plg_CheckNo, plg_method, plg_comment, 
	         a.fam_Name AS FamilyName, b.fun_Name as fundName
			 FROM pledge_plg 
			 LEFT JOIN family_fam a ON plg_FamID = a.fam_ID
			 LEFT JOIN donationfund_fun b ON plg_fundID = b.fun_ID
			 WHERE plg_depID = " . $iDepositSlipID . " ORDER BY pledge_plg.plg_date";
	$rsPledges = RunQuery($sSQL);
} else {
	$rsPledges = 0;
}

require "Include/Header.php";

?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?linkBack=" . $linkBack . "&DepositSlipID=".$iDepositSlipID . "&DepositType=".$sDepositType?>" name="DepositSlipEditor">

<table cellpadding="3" align="center">

	<tr>
		<td align="center">
			<input type="submit" class="icButton" value="<?php echo gettext("Save"); ?>" name="DepositSlipSubmit">
			<input type="button" class="icButton" value="<?php echo gettext("Cancel"); ?>" name="DepositSlipCancel" onclick="javascript:document.location='<?php if (strlen($linkBack) > 0) { echo $linkBack; } else {echo "Menu.php"; } ?>';">

			<?php if ($dep_Type == 'Bank') { ?>
			<input type="button" class="icButton" value="<?php echo gettext("Generate PDF"); ?>" name="DepositSlipGeneratePDF" onclick="javascript:document.location='Reports/PrintDeposit.php';">
			<?php } ?>

			<?php if ($dep_Type == 'BankDraft' || $dep_Type == 'CreditCard') { ?>
			<input type="submit" class="icButton" value="<?php echo gettext("Load Authorized Transactions"); ?>" name="DepositSlipLoadAuthorized">
			<input type="submit" class="icButton" value="<?php echo gettext("Run Transactions"); ?>" name="DepositSlipRunTransactions">
			<?php } ?>

		</td>
	</tr>

	<tr>
		<td>
		<table cellpadding="3">
			<tr>
				<td class="LabelColumn"><?php addToolTip("Format: YYYY-MM-DD<br>or enter the date by clicking on the calendar icon to the right."); ?><?php echo gettext("Date:"); ?></td>
				<td class="TextColumn"><input type="text" name="Date" value="<?php echo $dDate; ?>" maxlength="10" id="sel1" size="11">&nbsp;<input type="image" onclick="return showCalendar('sel1', 'y-mm-dd');" src="Images/calendar.gif"> <span class="SmallText"><?php echo gettext("[format: YYYY-MM-DD]"); ?></span><font color="red"><?php echo $sDateError ?></font></td>
			</tr>

			<tr>
				<td class="LabelColumn"><?php echo gettext("Comment:"); ?></td>
				<td class="TextColumn"><input type="text" name="Comment" id="Comment" value="<?php echo $sComment; ?>"></td>
			</tr>

			<tr>
				<td class="LabelColumn"><?php echo gettext("Closed:"); ?></td>
				<td class="TextColumn"><input type="checkbox" name="Closed" value="1" <?php if ($bClosed) echo " checked";?>><?php echo gettext("Close deposit slip (remember to press Save)"); ?>
			</tr>

		</table>
		</td>
	</form>
{'fraction_non_alphanumeric': 0.18020611674385614, 'fraction_numerical': 0.007385154587557892, 'mean_word_length': 3.651271104211139, 'pattern_counts': {'":': 0, '<': 193, '<?xml version=': 0, '>': 259, 'https://': 3, 'lorem ipsum': 0, 'www.': 5, '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': '7464514', 'n_tokens_mistral': 9911, 'n_tokens_neox': 8356, 'n_words': 1884}