Exemplo n.º 1
0
 function redistribute_sched($ctrl, $acct, $cycle, $brno, $trandate)
 {
     include 'config.php';
     $query_loanbalance = sqlanywhere_query($conn, "SELECT loans.loan_amount, loans.interest, balance.tot_cbu, balance.prin_bal,\n\t\t\t\t\t\t\t\t\t\t\t\t\tbalance.int_bal, balance.cbu_bal, balance.dcsa, balance.dcsa_bal\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM loans, balance\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE (loans.ctrl = balance.ctrl)\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND (loans.acct = balance.acct)\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND (loans.cycle = balance.cycle)\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND (loans.ctrl = '{$ctrl}')\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND (loans.acct = '{$acct}')\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND (loans.cycle = '{$cycle}')\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND (loans.brno = '{$brno}')");
     $baloansrow = sqlanywhere_num_rows($query_loanbalance);
     if ($baloansrow > 0) {
         $loanbal_row = sqlanywhere_fetch_row($query_loanbalance);
         $loan_amount = $loanbal_row[0];
         $interest = $loanbal_row[1];
         $tot_cbu = $loanbal_row[2];
         $prin_bal = $loanbal_row[3];
         $int_bal = $loanbal_row[4];
         $cbu_bal = $loanbal_row[5];
         $dcsa = $loanbal_row[6];
         $dcsa_bal = $loanbal_row[7];
         $prin_tot = $loan_amount - $prin_bal;
         $int_tot = $interest - $int_bal;
         $cbu_tot = $tot_cbu - $cbu_bal;
         $dcsa_tot = $dcsa - $dcsa_bal;
         //clean payment...
         $cleanamort_query = sqlanywhere_query($conn, "UPDATE amort SET prin_pay = '0.00', int_pay = '0.00',\n\t\t\t\t\t\t\t\t\t\t\t   cbu_pay = '0.00', amt_pay = '0.00', dcsa_pay = '0.00'\n\t\t\t\t\t\t\t\t\t\t\t   WHERE ctrl = '{$ctrl}' and acct = '{$acct}'\n\t\t\t\t\t\t\t\t\t\t\t   and cycle = '{$cycle}' ");
         sqlanywhere_free_result($cleanamort_query);
         $amort_query = sqlanywhere_query($conn, "SELECT no_pmt, prin_pay, int_pay, cbu_pay,\n\t\t\t\t\t\t\t\t\t\t  principal, interest, cbu, dcsa_pay, dcsa_orig\n\t\t\t\t\t\t\t\t\t\t  FROM amort WHERE ctrl = '{$ctrl}' and acct = '{$acct}'\n\t\t\t\t\t\t\t\t\t\t  and cycle = '{$cycle}' ");
         $amort_numrows = sqlanywhere_num_rows($amort_query);
         if ($amort_numrows > 0) {
             while ($amort_row = sqlanywhere_fetch_row($amort_query)) {
                 $tot_amount = 0.0;
                 $orig_prinpay = 0.0;
                 $orig_cbupay = 0.0;
                 $orig_intpay = 0.0;
                 $orig_dcsapay = 0.0;
                 $no_pmt = $amort_row[0];
                 $prin_pay = $amort_row[1];
                 $int_pay = $amort_row[2];
                 $cbu_pay = $amort_row[3];
                 $principal = $amort_row[4];
                 $interest = $amort_row[5];
                 $cbu = $amort_row[6];
                 $dcsa_pay = $amort_row[7];
                 $dcsa_orig = $amort_row[8];
                 //for principal pay distribution...
                 if ($prin_tot > 0) {
                     $dprin = $principal - $prin_pay;
                     if ($prin_tot >= $principal && $prin_pay != $principal) {
                         $orig_prinpay = $prin_pay + $dprin;
                         $update_amort_prin = sqlanywhere_query($conn, "UPDATE amort SET prin_pay = {$orig_prinpay}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE ctrl = '{$ctrl}' and acct = '{$acct}' and cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t and no_pmt = '{$no_pmt}'");
                         $prin_tot = $prin_tot - $dprin;
                         sqlanywhere_free_result($update_amort_prin);
                     } else {
                         if ($prin_tot < $principal && $prin_pay != $principal) {
                             $orig_prinpay = $prin_pay + $prin_tot;
                             $update_amort_prin = sqlanywhere_query($conn, "UPDATE amort SET prin_pay = {$orig_prinpay}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE ctrl = '{$ctrl}' and acct = '{$acct}' and cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand no_pmt = '{$no_pmt}'");
                             $prin_tot = $prin_tot - $prin_tot;
                             sqlanywhere_free_result($update_amort_prin);
                         }
                     }
                 }
                 //for interest payment distribution...
                 if ($int_tot > 0) {
                     $dint = $interest - $int_pay;
                     if ($int_tot >= $interest && $int_pay != $interest) {
                         $orig_intpay = $int_pay + $dint;
                         $update_amort_int = sqlanywhere_query($conn, "UPDATE amort SET int_pay = {$orig_intpay}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE ctrl = '{$ctrl}' and acct = '{$acct}' and cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t and no_pmt = '{$no_pmt}'");
                         $int_tot = $int_tot - $dint;
                         sqlanywhere_free_result($update_amort_int);
                     } else {
                         if ($int_tot < $interest && $int_pay != $interest) {
                             $orig_intpay = $int_pay + $int_tot;
                             $update_amort_int = sqlanywhere_query($conn, "UPDATE amort SET int_pay = {$orig_intpay}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE ctrl = '{$ctrl}' and acct = '{$acct}' and cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t and no_pmt = '{$no_pmt}'");
                             $int_tot = $int_tot - $int_tot;
                             sqlanywhere_free_result($update_amort_int);
                         }
                     }
                 }
                 //for cbu payment distribution...
                 if ($cbu_tot > 0) {
                     $dcbu = $cbu - $cbu_pay;
                     if ($cbu_tot >= $cbu && $cbu_pay != $cbu) {
                         $orig_cbupay = $cbu_pay + $dcbu;
                         $update_amort_cbu = sqlanywhere_query($conn, "UPDATE amort SET cbu_pay = {$orig_cbupay}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE ctrl = '{$ctrl}' and acct = '{$acct}' and cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand no_pmt = '{$no_pmt}'");
                         $cbu_tot = $cbu_tot - $dcbu;
                         sqlanywhere_free_result($update_amort_cbu);
                     } else {
                         if ($cbu_tot < $cbu && $cbu_pay != $cbu) {
                             $orig_cbupay = $cbu_pay + $cbu_tot;
                             $update_amort_cbu = sqlanywhere_query($conn, "UPDATE amort SET cbu_pay = {$orig_cbupay}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE ctrl = '{$ctrl}' and acct = '{$acct}' and cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t and no_pmt = '{$no_pmt}'");
                             $cbu_tot = $cbu_tot - $cbu_tot;
                             sqlanywhere_free_result($update_amort_cbu);
                         }
                     }
                 }
                 //for savings payment distribution...
                 if ($dcsa_tot > 0) {
                     $dsavings = $dcsa - $dcsa_pay;
                     if ($dcsa_tot >= $dcsa && $dcsa_pay != $dcsa) {
                         $orig_dcsapay = $dcsa_pay + $dsavings;
                         $update_amort_dcsa = sqlanywhere_query($conn, "UPDATE amort SET dcsa_pay = {$orig_dcsapay}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE ctrl = '{$ctrl}' and acct = '{$acct}' and cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t and no_pmt = '{$no_pmt}'");
                         $dcsa_tot = $dcsa_tot - $dsavings;
                         sqlanywhere_free_result($update_amort_dcsa);
                     } else {
                         if ($dcsa_tot < $dcsa && $dcsa_pay != $dcsa) {
                             $orig_dcsapay = $dcsa_pay + $dcsa_tot;
                             $update_amort_dcsa = sqlanywhere_query($conn, "UPDATE amort SET dcsa_pay = {$orig_dcsapay}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE ctrl = '{$ctrl}' and acct = '{$acct}' and cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand no_pmt = '{$no_pmt}'");
                             $dcsa_tot = $dcsa_tot - $dcsa_tot;
                             sqlanywhere_free_result($update_amort_dcsa);
                         }
                     }
                 }
                 //update total amount paid...
                 $tot_amount = $orig_prinpay + $orig_cbupay + $orig_intpay + $orig_dcsapay;
                 $update_amt_tot = sqlanywhere_query($conn, "UPDATE amort SET amt_pay = '{$tot_amount}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE ctrl = '{$ctrl}' AND acct = '{$acct}' AND cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t AND no_pmt = '{$no_pmt}'");
                 $update_posted1 = sqlanywhere_query($conn, "UPDATE amort SET posted = 'P'\n\t\t\t\t\t\t\t\t\t\t\t\t\t  WHERE ctrl = '{$ctrl}' AND acct = '{$acct}' AND cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t  AND principal <= '{$orig_prinpay}' AND interest <= '{$orig_intpay}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t  AND cbu <= '{$orig_cbupay}' AND dcsa <= '{$orig_dcsapay}' AND no_pmt = '{$no_pmt}'");
                 //updated by jym 2011-10-05...
                 //and amt_pay >= '$tot_amount' and no_pmt = '$no_pmt'");// and no_pmt = '$no_pmt'
                 $update_posted2 = sqlanywhere_query($conn, "UPDATE amort SET posted = 'N'\n\t\t\t\t\t\t\t\t\t\t\t\t\t  WHERE ctrl = '{$ctrl}' AND acct = '{$acct}' AND cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t  AND (principal > '{$orig_prinpay}' OR interest > '{$orig_intpay}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t   OR cbu > '{$orig_cbupay}' OR dcsa > '{$orig_dcsapay}')\n\t\t\t\t\t\t\t\t\t\t\t\t\t  AND no_pmt > '{$no_pmt}'");
                 //updated by jym 2011-10-05...
                 //and amt_pay < amount and no_pmt = '$no_pmt'");// and no_pmt = '$no_pmt'
                 $update_datepost = sqlanywhere_query($conn, "UPDATE amort SET datepaid = '{$trandate}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t  WHERE ctrl = '{$ctrl}' AND acct = '{$acct}' AND cycle = '{$cycle}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t  AND no_pmt = '{$no_pmt}' AND amt_pay <> 0");
                 //and posted = 'N'");
                 sqlanywhere_free_result($update_posted1);
                 sqlanywhere_free_result($update_posted2);
                 sqlanywhere_free_result($update_datepost);
                 sqlanywhere_free_result($update_amt_tot);
             }
         }
     }
 }
Exemplo n.º 2
0
 $pnmbr = $_GET['pnmbr'];
 $commit = 0;
 $counter = 0;
 $query_brno = sqlanywhere_query($conn, "SELECT vcBrno, vccard_number FROM names\n\t\t\t\t\t\t\t\t\t\tWHERE mobile = '{$phone}' AND pnmbr = '{$pnmbr}' AND btcard_status='1'");
 $brno_numrows = sqlanywhere_num_rows($query_brno);
 if ($brno_numrows > 0) {
     $brno_row = sqlanywhere_fetch_row($query_brno);
     $brno = $brno_row[0];
     $cardID = $brno_row[1];
     $query_card = sqlanywhere_query($conn, "SELECT vccard_expirydate\n\t\t\t\t\t\t\t\t\t\t  \t\tFROM names\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE vccard_number = '{$cardID}'\n\t\t\t\t\t\t\t\t\t\t\t\tAND btcard_status='1'\n\t\t\t\t\t\t\t\t\t\t\t\tAND vcBrno = '{$brno}'");
     $card_numrows = sqlanywhere_num_rows($query_card);
     if ($card_numrows == 0 || $card_numrows > 1) {
         //echo "ERROR|Invalid Card #";
         echo json_encode(array('success' => false, 'message' => '[1] Invalid card number'));
     } else {
         $card_row = sqlanywhere_fetch_row($query_card);
         $expiry_date = $card_row[0];
         $query = sqlanywhere_query($conn, "SELECT dptdailydatepost FROM setdailyposting \n\t\t\t\t\t\t\t\t\t\t\t\tWHERE dptdailyapptype='SA' AND brno = '{$brno}'");
         $row = sqlanywhere_fetch_array($query);
         $dateTran = $row['dptdailydatepost'];
         $date_tran = explode(" ", $dateTran);
         $trandate = $date_tran[0];
         $timepost = date("h:i:s");
         $timetrans = $trandate . " " . $timepost;
         $date_exp = explode(" ", $expiry_date);
         $date_expired = $date_exp[0];
         //select regular savings
         $selProd = sqlanywhere_query($conn, "SELECT * FROM fpdDepositProduct WHERE dpfProductDesc ='ATM SAVINGS'");
         $rowProd = sqlanywhere_fetch_array($selProd);
         $productID = $rowProd['dpfProductCode'];
         if (!($date_expired > $trandate)) {
Exemplo n.º 3
0
 public function process_deposit($phone, $depositAmount)
 {
     $commit = 0;
     $counter = 0;
     $query_brno = sqlanywhere_query($conn, "SELECT vcBrno, vccard_number FROM names\n\t\t\t\t\t\t\t\t\t\t\tWHERE mobile = '{$phone}' AND btcard_status='1'");
     $brno_numrows = sqlanywhere_num_rows($query_brno);
     if ($brno_numrows > 0) {
         $brno_row = sqlanywhere_fetch_row($query_brno);
         $brno = $brno_row[0];
         $cardID = $brno_row[1];
         $query_card = sqlanywhere_query($conn, "SELECT vccard_expirydate\n\t\t\t\t\t\t\t\t\t\t\t  \t\tFROM names\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE vccard_number = '{$cardID}'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND btcard_status='1'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND vcBrno = '{$brno}'");
         $card_numrows = sqlanywhere_num_rows($query_card);
         if ($card_numrows == 0 || $card_numrows > 1) {
             //echo "ERROR|Invalid Card #";
             echo json_encode(array('success' => false, 'message' => 'Invalid card number'));
         } else {
             $card_row = sqlanywhere_fetch_row($query_card);
             $expiry_date = $card_row[0];
             $query = sqlanywhere_query($conn, "SELECT dptdailydatepost FROM setdailyposting \n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE dptdailyapptype='SA' AND brno = '{$brno}'");
             $row = sqlanywhere_fetch_array($query);
             $dateTran = $row['dptdailydatepost'];
             $date_tran = explode(" ", $dateTran);
             $trandate = $date_tran[0];
             $timepost = date("h:i:s");
             $timetrans = $trandate . " " . $timepost;
             $date_exp = explode(" ", $expiry_date);
             $date_expired = $date_exp[0];
             //select regular savings
             $selProd = sqlanywhere_query($conn, "SELECT * FROM fpdDepositProduct WHERE dpfProductDesc ='REGULAR SAVINGS'");
             $rowProd = sqlanywhere_fetch_array($selProd);
             $productID = $rowProd['dpfProductCode'];
             if (!($date_expired > $trandate)) {
                 //echo "ERROR|Date not synch";
                 echo json_encode(array('success' => false, 'message' => 'Date not sync'));
             } else {
                 $query1 = sqlanywhere_query($conn, "SELECT ctrl, acct, vcbrno FROM names \n\t\t\t\t\t\t\t\t\t\t\t\tWHERE vccard_number = '{$cardID}' AND btcard_status='1'\n\t\t\t\t\t\t\t\t\t\t\t\tAND vcBrno = '{$brno}'");
                 $existCard = sqlanywhere_num_rows($query1);
                 if ($existCard == 1) {
                     $query = sqlanywhere_query($conn, "SELECT * FROM names  WHERE vccard_number = '{$cardID}' \n\t\t\t\t\t\t\t\t\t\t\t\t\t   AND vcBrno = '{$brno}'");
                     if (sqlanywhere_num_rows($query) == 0) {
                         //echo "ERROR|Invalid Card #";
                         echo json_encode(array('success' => false, 'message' => 'Invalid Card number'));
                         exit;
                     } else {
                         $row = sqlanywhere_fetch_array($query);
                         $card_no = $row['vccard_number'];
                         $cName = $row['names'];
                         $checkCard = sqlanywhere_query($conn, "SELECT * FROM dmmDepositAccount WHERE vccard_number = '" . $card_no . "' \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   AND  datProductCode = '{$productID}'");
                         if (sqlanywhere_num_rows($checkCard) == 0) {
                             //echo "ERROR|Invalid Prod ID";
                             echo json_encode(array('success' => false, 'message' => 'Invalid Prod ID'));
                         } else {
                             $rowStatus = sqlanywhere_fetch_array($checkCard);
                             $AccountStatus = $rowStatus['datAccountStatus'];
                             if ($AccountStatus == '01') {
                                 $query3 = sqlanywhere_query($conn, "SELECT * FROM dmmDepositAccount \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE vccard_number = '" . $card_no . "'  \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND  datProductCode = '{$productID}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND datAccountStatus = '01'");
                                 if (sqlanywhere_num_rows($query3) == 0) {
                                     //echo "ERROR|Invalid Card # & Prod ID";
                                     echo json_encode(array('success' => false, 'message' => 'Invalid Card # & Prod ID'));
                                     exit;
                                 } else {
                                     $row3 = sqlanywhere_fetch_array($query3);
                                     $availableBal = $row3['datAvailableBalance'];
                                     $outstandingBal = $row3['datOutstandingBalance'];
                                     $sequenceNo = $row3['datSequence'];
                                     $lastMovementDate = $dateTran;
                                     $lastTransactionDate = $row3['datLastMovementDate'];
                                     $t_AvailableBal = $depositAmount + $availableBal;
                                     $t_outstandingBal = $depositAmount + $outstandingBal;
                                     $res = $sequenceNo + '1';
                                     $t_sequenceNo = leading_zeros($res, 10);
                                     $query4 = sqlanywhere_query($conn, "UPDATE dmmDepositAccount \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSET datAvailableBalance = {$t_AvailableBal} ,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdatOutstandingBalance ={$t_outstandingBal}  ,                \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdatLastMovementDate = '{$lastMovementDate}' ,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdatLastTransactionDate ='{$lastTransactionDate}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdatSequence ='{$t_sequenceNo}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE vccard_number= '" . $card_no . "' \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND datProductCode ='{$productID}' \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND datAccountStatus = '01'");
                                     if (!$query4) {
                                         //echo "ERROR|Invalid Card # & Prod ID";
                                         echo json_encode(array('success' => false, 'message' => 'Invalid Card # & Prod ID'));
                                         $counter++;
                                         exit;
                                     } else {
                                         $query5 = sqlanywhere_query($conn, "SELECT * FROM dmmDepositAccount \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  WHERE vccard_number= '" . $card_no . "' \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  AND datProductCode ='{$productID}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  AND datAccountStatus = '01'");
                                         if (sqlanywhere_num_rows($query5) == 0) {
                                             //echo "ERROR|Invalid Card # & Prod ID";
                                             echo json_encode(array('success' => false, 'message' => 'Invalid Card # & Prod ID'));
                                         } else {
                                             $row5 = sqlanywhere_fetch_array($query5);
                                             $availableBal = $row5['datAvailableBalance'];
                                             $dttAppCode = $row5['datAppCode'];
                                             $dttAccountCode = $row5['datAccountCode'];
                                             $dttProductCode = $row5['datProductCode'];
                                             $dttSequence = $row5['datSequence'];
                                             $dttTransactionDate = $timetrans;
                                             $dttTransactionCode = '001';
                                             $dttTransactionSymbol = 'CSDP';
                                             $dttCashCociCode = '1';
                                             $dttDebitTransaction = 0.0;
                                             $dttCreditTransaction = $depositAmount;
                                             $dttAvailableBalance = $t_AvailableBal;
                                             $dttOutstandingBalance = $t_outstandingBal;
                                             $dttUserInitial = $user;
                                             $dttErrorCorrect = '0';
                                             $dttBranchName = $row5['datBranchCode'];
                                             $dttCheckNumber = NULL;
                                             $dttFloatDay = '0';
                                             $dttPrintPassbook = '1';
                                             $dttPrintLedger = '1';
                                             $refnum = get_controlno('REFNUM', $dttBranchName);
                                             $trrefnum = set_reference($refnum);
                                             $RefNum = explode("-", $trrefnum);
                                             $RefNum = $RefNum[1];
                                             $dttReference = $trrefnum;
                                             $dttDateIssued = $dateTran;
                                             $dttDepositAmount = $depositAmount;
                                             $dttInterestAmount = NULL;
                                             $dttTaxAmount = NULL;
                                             $dttTransno = NULL;
                                             $vcFinance = $row5['vcFinance'];
                                             $datDepositorAddress = $row5['datDepositorAddress'];
                                             $dateTransaction = $row5['datLastMovementDate'];
                                             $str = $row5['datDepositorName'];
                                             $dttDepositorName = str_replace("'", " ", $str);
                                             $query6 = sqlanywhere_query($conn, "INSERT INTO dmmDepositTransaction\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t (dttAppCode, dttAccountCode, dttProductCode,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  dttSequence, dttTransactionDate, dttTransactionCode,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  dttTransactionSymbol, dttCashCociCode,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  dttDebitTransaction,dttCreditTransaction,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  dttAvailableBalance, dttOutstandingBalance, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  dttUserInitial, dttDepositorName,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  dttErrorCorrect, dttBranchName, dttCheckNumber,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  dttFloatDay, dttPrintPassbook, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  dttPrintLedger,dttReference, dttDateIssued,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  dttDepositAmount, dttInterestAmount,        \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  dttTaxAmount, dttTransno, vcFinance)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES('{$dttAppCode}', '{$dttAccountCode}', '{$dttProductCode}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$dttSequence}', '{$dttTransactionDate}', '{$dttTransactionCode}',  \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '{$dttTransactionSymbol}', '{$dttCashCociCode}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '{$dttDebitTransaction}', '{$dttCreditTransaction}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '{$dttAvailableBalance}','{$dttOutstandingBalance}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '{$dttUserInitial}', '{$dttDepositorName}', '{$dttErrorCorrect}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '{$dttBranchName}', '{$dttCheckNumber}', {$dttFloatDay},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '{$dttPrintPassbook}', '{$dttPrintLedger}', '{$dttReference}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '{$dttDateIssued}', '{$dttDepositAmount}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '{$dttInterestAmount}','{$dttTaxAmount}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '{$dttTransno}', '{$vcFinance}')");
                                             if (!$query6) {
                                                 //echo  "ERROR|Invalid Transaction";
                                                 echo json_encode(array('success' => false, 'message' => 'Invalid Transaction'));
                                                 $counter++;
                                                 //2;
                                                 exit;
                                             } else {
                                                 //$counter++;//3
                                                 $query7 = sqlanywhere_query($conn, "SELECT * FROM  fpddepositproducttransaction\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE dtfAppCode ='{$dttAppCode}'                                   \t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND dtfTransactionCode ='{$dttTransactionCode}' \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND dtfProductCode ='{$dttProductCode}'");
                                                 if (sqlanywhere_num_rows($query7) == 0) {
                                                     //echo "ERROR|Invalid Prod ID";
                                                     echo json_encode(array('success' => false, 'message' => 'Invalid Prod ID'));
                                                 } else {
                                                     $row7 = sqlanywhere_fetch_array($query7);
                                                     $dtfGLAcctDebit = $row7['dtfGLAcctDebit'];
                                                     $dtfGLAcctCredit = $row7['dtfGLAcctCredit'];
                                                     $trdatepost = $timetrans;
                                                     $dttBranchName = $dttBranchName;
                                                     $trdebit = $dttDepositAmount;
                                                     $trcredit = 0.0;
                                                     $trparticulars = "Savings of " . $dttDepositorName;
                                                     $trno = get_trno($trdatepost, $dttBranchName);
                                                     $trtype = '1';
                                                     $trans_no = get_transno($trdatepost, $dttBranchName);
                                                     $trtime = $timetrans;
                                                     $teller = $user;
                                                     $brno = $dttBranchName;
                                                     $trname = $dttDepositorName;
                                                     $traddress = $datDepositorAddress;
                                                     $trn_seq = get_controlno('TMPTRAN', $dttBranchName);
                                                     $vcappcode = 'SA';
                                                     $vcfinance = $vcFinance;
                                                     //insert gl transaction
                                                     if ($trcredit != 0.0) {
                                                         $tracctnum = $dtfGLAcctCredit;
                                                         //echo "trcredit".$trcredit."<BR>";
                                                         //echo "dtfGLAcctDebit".$dtfGLAcctDebit."<BR>";
                                                         $query8 = sqlanywhere_query($conn, "INSERT INTO  tmptrans(trdatepost,tracctnum,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  trno, trans_no, brno,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  trn_seq, trrefnum,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  trdebit, trcredit, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  trparticulars, trtype,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  trtime, teller, trname,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  traddr, vcAppCode,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  vcFinance)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES('{$trdatepost}', '{$tracctnum}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$trno}','{$trans_no}', '{$dttBranchName}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$trn_seq}', '{$trrefnum}', '{$trdebit}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$trcredit}', '{$trparticulars}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$trtype}', '{$trtime}', '{$teller}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$trname}', '{$traddress}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$vcappcode}','{$vcfinance}')");
                                                         if (!$query8) {
                                                             $counter++;
                                                             //4
                                                         }
                                                     }
                                                     if ($trdebit == 0.0) {
                                                         $tracctnum = $dtfGLAcctDebit;
                                                         //echo "debit".$trdebit."<BR>";
                                                         //echo "dtfGLAcctCredit".$dtfGLAcctCredit."<BR>";
                                                         $query9 = sqlanywhere_query($conn, "INSERT INTO tmptrans(trdatepost,tracctnum, trno,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t trans_no, brno, trn_seq,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t trrefnum, trdebit, trcredit,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t trparticulars, trtype,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t trtime, teller, trname,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t traddr, vcAppCode, vcFinance)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES('{$trdatepost}', '{$tracctnum}', '{$trno}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$trans_no}' ,'{$dttBranchName}', '{$trn_seq}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$trrefnum}', '{$trcredit}', '{$trdebit}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$trparticulars}', '{$trtype}', '{$trtime}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$teller}', '{$trname}', '{$traddress}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   '{$vcappcode}','{$vcfinance}')");
                                                         if (!$query9) {
                                                             $counter++;
                                                         }
                                                     }
                                                     //echo "counter".$counter."<BR>";
                                                     if ($counter == 0) {
                                                         //auditrail for mtm epoy 4-12-2013
                                                         $query13 = sqlanywhere_query($conn, "SELECT stlAppType, stlWindow, stlAudType, stlAudDesc FROM setTransactionLibrary WHERE stlID = '54'");
                                                         $row2 = sqlanywhere_fetch_array($query13);
                                                         $stlAppType = $row2['stlAppType'];
                                                         $stlWindow = $row2['stlWindow'];
                                                         $stlAudType = $row2['stlAudType'];
                                                         $stlAudDesc = $row2['stlAudDesc'];
                                                         $insertLogs = sqlanywhere_query($conn, "INSERT INTO AuditTrail(auddate, audapptype, audwindowtitle, audaudittype, audkeyvalue, auduserid, \taudremarks, transType)VALUES('{$timetrans}','{$stlAppType}','{$stlWindow}','{$stlAudType}','{$user}', '{$user}', '{$stlAudDesc}', 'M')");
                                                         if (!$insertLogs) {
                                                             //echo  "ERROR|PLS TRY AGAIN!";
                                                             echo json_encode(array('success' => false, 'message' => 'Please try again!'));
                                                             exit;
                                                         }
                                                         //end
                                                         /*$selProductName = sqlanywhere_query($conn, "SELECT * FROM fpdDepositProduct 
                                                         												WHERE dpfProductCode ='$dttProductCode'");
                                                         			
                                                         		$rowselProductName =  sqlanywhere_fetch_array($selProductName);
                                                         		$dpfProductDesc = $rowselProductName['dpfProductDesc'];
                                                         							
                                                         		$card = card_hidden($cardID);
                                                         		$savingsDep = "SUCCESSFUL";*/
                                                         echo json_encode(array('success' => true, 'message' => 'Successful'));
                                                         /*if(sqlanywhere_commit($conn))
                                                         		{ 
                                                         			$selProductName = sqlanywhere_query($conn, "SELECT * FROM fpdDepositProduct 
                                                         												WHERE dpfProductCode ='$dttProductCode'");
                                                         			
                                                         			$rowselProductName =  sqlanywhere_fetch_array($selProductName);
                                                         			$dpfProductDesc = $rowselProductName['dpfProductDesc'];
                                                         								
                                                         			$card = card_hidden($cardID);
                                                         			$savingsDep = "SUCCESSFUL";
                                                         			echo json_encode(array('success' => true, 'message' => 'Successful'));
                                                         			//echo $savingsDep;
                                                         		}
                                                         		else
                                                         		{
                                                         			//echo "ERROR|PLS TRY AGAIN.";
                                                         			echo json_encode(array('success' => false, 'message' => 'Please try again!'));
                                                         		}*/
                                                     } else {
                                                         if (sqlanywhere_rollback($conn)) {
                                                             //echo "ERROR|PLS TRY AGAIN.";
                                                             echo json_encode(array('success' => false, 'message' => 'Please try again!'));
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 //echo "ERROR|Account is inactive";
                                 echo json_encode(array('success' => false, 'message' => 'Account is inactive'));
                             }
                         }
                     }
                 } else {
                     //echo "ERROR|Card # inactive.";
                     echo json_encode(array('success' => false, 'message' => 'Card # inactive'));
                 }
             }
         }
     } else {
         //echo "ERROR|NO MOBILE LINK";
         echo json_encode(array('success' => false, 'message' => 'NO MOBILE LINK'));
     }
 }