diff --git a/churchinfo/DepositSlipEditor.php b/churchinfo/DepositSlipEditor.php index a9d88aeca5..29f29ace5f 100644 --- a/churchinfo/DepositSlipEditor.php +++ b/churchinfo/DepositSlipEditor.php @@ -17,152 +17,56 @@ require "Include/Config.php"; require "Include/Functions.php"; require "service/FinancialService.php"; -require "Include/MICRFunctions.php"; - $financialService = new FinancialService(); $linkBack = ""; $iDepositSlipID = 0; -$dep_Type = ""; $sDateError = ""; -$sDepositType = ""; -$sComment = ""; -$bClosed = false; +$thisDeposit = ""; -if (array_key_exists ("linkBack", $_GET)) - $linkBack = FilterInput($_GET["linkBack"]); if (array_key_exists ("DepositSlipID", $_GET)) $iDepositSlipID = FilterInput($_GET["DepositSlipID"], 'int'); 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 current deposit slip - $_SESSION['iCurrentDeposit'] = $iDepositSlipID; - - // Set the session variable for default payment type so the new payment form will come up correctly - if ($dep_Type == "Bank") + + $thisDeposit = $financialService->GetDeposits($iDepositSlipID)[0]; + // Set the session variable for default payment type so the new payment form will come up correctly + if ($thisDeposit->dep_Type == "Bank") $_SESSION['idefaultPaymentMethod'] = "CHECK"; - else if ($dep_Type == "CreditCard") + else if ($thisDeposit->dep_Type == "CreditCard") $_SESSION['idefaultPaymentMethod'] = "CREDITCARD"; - else if ($dep_Type == "BankDraft") + else if ($thisDeposit->dep_Type == "BankDraft") $_SESSION['idefaultPaymentMethod'] = "BANKDRAFT"; - else if ($dep_Type == "eGive") + else if ($thisDeposit->dep_Type == "eGive") $_SESSION['idefaultPaymentMethod'] = "EGIVE"; // Security: User must have finance permission or be the one who created this deposit - if (! ($_SESSION['bFinance'] || $_SESSION['iUserID']==$dep_EnteredBy)) { + if (! ($_SESSION['bFinance'] || $_SESSION['iUserID']==$thisDeposit->dep_EnteredBy)) { Redirect("Menu.php"); exit; } } +else +{ + Redirect("Menu.php"); +} //Set the page title -if (! $iDepositSlipID) - $sPageTitle = $dep_Type . " " . gettext("Deposit Slip Number: TBD"); -else - $sPageTitle = $dep_Type . " " . gettext("Deposit Slip Number: ") . $iDepositSlipID; +$sPageTitle = $thisDeposit->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 = false; - if (array_key_exists ("Closed", $_POST)) - $bClosed = FilterInput($_POST["Closed"]); - $sDepositType = FilterInput($_POST["DepositType"]); - - 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 = "" . gettext("Not a valid Date") . ""; - $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; - - if ($bClosed && ($dep_Type=='CreditCard' || $dep_Type == 'BankDraft')) { - // Delete any failed transactions on this deposit slip now that it is closing - $q = "DELETE FROM pledge_plg WHERE plg_depID = " . $iDepositSlipID . " AND plg_PledgeOrPayment=\"Payment\" AND plg_aut_Cleared=0" ; - RunQuery($q); - } - } - - //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"])) +if (isset($_POST["DepositSlipLoadAuthorized"])) { $financialService->loadAuthorized($iDepositSlipID); } else if (isset($_POST["DepositSlipRunTransactions"])) { $financialService->runTransactions($iDepositSlipID); -} -else -{ - //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; - $sDepositType = $dep_Type; - } - $_SESSION['iCurrentDeposit'] = $iDepositSlipID; // Probably redundant - $sSQL = "UPDATE user_usr SET usr_currentDeposit = '$iDepositSlipID' WHERE usr_per_id = \"".$_SESSION['iUserID']."\""; - $rsUpdate = RunQuery($sSQL); - +$_SESSION['iCurrentDeposit'] = $iDepositSlipID; // Probably redundant +$sSQL = "UPDATE user_usr SET usr_currentDeposit = '$iDepositSlipID' WHERE usr_per_id = \"".$_SESSION['iUserID']."\""; +$rsUpdate = RunQuery($sSQL); require "Include/Header.php"; ?> @@ -180,122 +84,61 @@