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 @@

-
- - -
" name="DepositSlipSubmit"> - " name="DepositSlipCancel" onclick="javascript:document.location=' 0) { echo $linkBack; } else {echo "Menu.php"; } ?>';"> - " name="DepositSlipGeneratePDF" onclick="javascript:document.location='Reports/PrintDeposit.php?BankSlip=';"> + " name="DepositSlipGeneratePDF" onclick="javascript:document.location='Reports/PrintDeposit.php?BankSlip=dep_Type == 'Bank')?>';"> " name="DepositSlipGeneratePDF" onclick="javascript:document.location='FinancialReports.php';"> dep_Type and !$thisDeposit->dep_Closed) { + if ($thisDeposit->dep_Type == "eGive") { echo ""; } else { echo ""; } ?> - - + dep_Type == 'BankDraft' || $thisDeposit->dep_Type == 'CreditCard') { ?> " name="DepositSlipLoadAuthorized"> " name="DepositSlipRunTransactions">
- - - - - "; - if ($sDepositType == "BankDraft") - $selectBankDraft = "Checked "; - elseif ($sDepositType == "CreditCard") - $selectCreditCard = "Checked "; - elseif ($sDepositType == "eGive") - $selecteGive = "Checked "; - else - $selectOther = "Checked "; - echo ""; - } else { - echo ""; - } - ?> - + + - + - - -
".gettext("Deposit Type:")."".gettext("Bank")."   "; - echo "".gettext("Credit Card")."   "; - echo "".gettext("Bank Draft")."   "; - echo "".gettext("eGive")."
> + dep_Closed) echo " checked";?>> dep_Type == 'BankDraft' || $thisDeposit->dep_Type == 'CreditCard') { echo "

" . gettext("Important note: failed transactions will be deleted permanantly when the deposit slip is closed.") . "

"; } ?>

-\$$deposit_total - TOTAL AMOUNT   (Items: $totalItems)
"; - if ($totalCash) - echo "\$$totalCash - Total Cash   (Items: $totalCashItems)
"; - if ($totalChecks) - echo "\$$totalChecks - Total Checks   (Items: $totalCheckItems)
"; + echo "".$thisDeposit->dep_Total." - TOTAL AMOUNT   (Items: $thisDeposit->countTotal)
"; + if ($thisDeposit->totalCash) + echo "".$thisDeposit->totalCash." - Total Cash   (Items: $thisDeposit->countCash)
"; + if ($thisDeposit->totalChecks) + echo "".$thisDeposit->totalChecks." - Total Checks   (Items: $thisDeposit->countCheck)
"; echo "
"; ?> @@ -310,9 +153,7 @@
- +
@@ -376,7 +217,7 @@ { width: 'auto', title:'Fund', - data:'plg_fundID', + data:'fun_Name', }, { width: 'auto', @@ -401,13 +242,13 @@ title:'Comment', data:'plg_comment', }, + if ($thisDeposit->dep_Type == 'BankDraft' || $thisDeposit->dep_Type == 'CreditCard') {?>, ,{ width: 'auto', title:'Cleared', data:'plg_aut_Cleared', } + if ($thisDeposit->dep_Type == 'BankDraft' || $thisDeposit->dep_Type == 'CreditCard') { ?> ,{ width: 'auto', title:'Details', diff --git a/churchinfo/Include/Config.php b/churchinfo/Include/Config.php index e5909c2070..4c94a3bd44 100644 --- a/churchinfo/Include/Config.php +++ b/churchinfo/Include/Config.php @@ -55,7 +55,7 @@ // Turn on all error reporting -#error_reporting(-1); +error_reporting(-1); // Report all errors except E_NOTICE diff --git a/churchinfo/service/FinancialService.php b/churchinfo/service/FinancialService.php index 639053f100..5c1cb49d76 100644 --- a/churchinfo/service/FinancialService.php +++ b/churchinfo/service/FinancialService.php @@ -1,7 +1,8 @@ baseURL = $_SESSION['sURLPath']; $this->personService = new PersonService(); $this->familyService = new FamilyService(); } - function processAuthorizeNet() + + function processAuthorizeNet() { $donation = new AuthorizeNetAIM; $donation->amount = "$plg_amount"; @@ -507,7 +510,7 @@ function deleteDeposit($id) function getDeposits($id=null) { - $sSQL = "SELECT dep_ID, dep_Date, dep_Comment, dep_Closed, dep_Type FROM deposit_dep"; + $sSQL = "SELECT * FROM deposit_dep"; if ($id) { $sSQL.=" WHERE dep_ID = ".$id; @@ -517,17 +520,24 @@ function getDeposits($id=null) while ($aRow = mysql_fetch_array($rsDep)) { extract ($aRow); - $values['dep_ID']=$dep_ID; - $values['dep_Date']=$dep_Date; - $values['dep_Comment']=$dep_Comment; - $values['dep_Closed']=$dep_Closed; - $values['dep_Type']=$dep_Type; - $values['dep_Total']=$this->getDepositTotal($dep_ID); + $values= new StdClass(); + $values->dep_ID=$dep_ID; + $values->dep_Date=$dep_Date; + $values->dep_Comment=$dep_Comment; + $values->dep_Closed=$dep_Closed; + $values->dep_Type=$dep_Type; + $values->dep_EnteredBy = $dep_EnteredBy; + $values->totalCash=$this->getDepositTotal($dep_ID,'CASH'); + $values->totalChecks=$this->getDepositTotal($dep_ID,'CHECK'); + $values->dep_Total=$this->getDepositTotal($dep_ID); + $values->countCash=$this->getDepositCount($dep_ID,'CASH'); + $values->countCheck=$this->getDepositCount($dep_ID,'CHECK'); + $values->countTotal=$this->getDepositCount($dep_ID); array_push($return,$values); } return $return; } - + function createDeposit($depositType, $depositComment, $depositDate) { $sSQL = "INSERT INTO deposit_dep (dep_Date, dep_Comment, dep_EnteredBy, dep_Type) @@ -540,15 +550,34 @@ function createDeposit($depositType, $depositComment, $depositDate) return $this->getDeposits($iDepositSlipID); } - function getDepositTotal($id) + function getDepositTotal($id,$type=null) { + $sqlClause = ''; + if ($type) + { + $sqlClause = "AND plg_method = '".$type."'"; + } // Get deposit total - $sSQL = "SELECT SUM(plg_amount) AS deposit_total FROM pledge_plg WHERE plg_depID = '$id' AND plg_PledgeOrPayment = 'Payment'"; + $sSQL = "SELECT SUM(plg_amount) AS deposit_total FROM pledge_plg WHERE plg_depID = '$id' AND plg_PledgeOrPayment = 'Payment' ".$sqlClause; $rsDepositTotal = RunQuery($sSQL); list ($deposit_total) = mysql_fetch_row($rsDepositTotal); return $deposit_total; } + function getDepositCount($id,$type=null) + { + $sqlClause = ''; + if ($type) + { + $sqlClause = "AND plg_method = '".$type."'"; + } + // Get deposit total + $sSQL = "SELECT COUNT(plg_amount) AS deposit_count FROM pledge_plg WHERE plg_depID = '$id' AND plg_PledgeOrPayment = 'Payment' ".$sqlClause; + $rsDepositTotal = RunQuery($sSQL); + list ($deposit_count) = mysql_fetch_row($rsDepositTotal); + return $deposit_count; + } + function getDepositJSON($deposits) { if ($deposits) @@ -577,7 +606,12 @@ function getPaymentJSON($payments) function getPayments($depID) { - $sSQL = "SELECT * from pledge_plg"; + $sSQL = "SELECT * from pledge_plg + INNER JOIN + donationfund_fun + ON + pledge_plg.plg_fundID = donationfund_fun.fun_ID"; + if ($depID) { $sSQL.=" WHERE plg_depID = ".$depID; @@ -601,6 +635,7 @@ function getPayments($depID) $values['plg_EditedBy']=$plg_EditedBy; $values['plg_PledgeOrPayment']=$plg_PledgeOrPayment; $values['plg_fundID']=$plg_fundID; + $values['fun_Name'] = $fun_Name; $values['plg_depID']=$plg_depID; $values['plg_CheckNo']=$plg_CheckNo; $values['plg_Problem']=$plg_Problem; @@ -738,7 +773,7 @@ private function validateFund($payment) } - + function validateChecks($payment) { //validate that the payment options are valid