<?php
error_reporting(E_ERROR | E_PARSE);

include ('includes/server_connection.php');

$columns = array(
    'ce_id',
    'ce_pay_date',
    'ce_type',
    'ce_from_cust',
    'ce_paid_to',
    'ce_ref_no',
    'ce_payment_mode',
    'ce_previous_bal',
    'ce_cash_cr',
    'ce_cash_dr',
    'ce_total_amount',
    'ce_debit_for',
    'ce_remark'
);

$query = "SELECT * FROM cash_entry WHERE ";

//date range filter
if ($_POST["is_date_search"] == "yes")
{
    $query .= 'ce_pay_date BETWEEN "' . $_POST["start_date"] . '" AND "' . $_POST["end_date"] . '" AND ';
}

//common search
if (isset($_POST["search"]["value"]))
{
    $query .= '
  (ce_id LIKE "%' . $_POST["search"]["value"] . '%" 
  OR ce_pay_date LIKE "%' . $_POST["search"]["value"] . '%" 
  OR ce_type LIKE "%' . $_POST["search"]["value"] . '%" 
  OR ce_from_cust LIKE "%' . $_POST["search"]["value"] . '%"
  OR ce_paid_to LIKE "%' . $_POST["search"]["value"] . '%"
  OR ce_ref_no LIKE "%' . $_POST["search"]["value"] . '%"
  OR ce_payment_mode LIKE "%' . $_POST["search"]["value"] . '%"
  OR ce_previous_bal LIKE "%' . $_POST["search"]["value"] . '%"
  OR ce_cash_cr LIKE "%' . $_POST["search"]["value"] . '%"
  OR ce_cash_dr LIKE "%' . $_POST["search"]["value"] . '%"
  OR ce_total_amount LIKE "%' . $_POST["search"]["value"] . '%"
  OR ce_debit_for LIKE "%' . $_POST["search"]["value"] . '%"
  OR ce_remark LIKE "%' . $_POST["search"]["value"] . '%")
 ';
}
//for sorting
if (isset($_POST["order"]))
{
    $query .= 'ORDER BY ' . $columns[$_POST['order']['0']['column']] . ' ' . $_POST['order']['0']['dir'] . ' 
 ';
}
else
{
    $query .= 'ORDER BY ce_id DESC ';
}

if ($_POST["length"] != - 1)
{
    $query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}

$query4 = '';

//selecting company details
$query4 .= "SELECT * FROM company";

$statement = $connection->prepare($query4);
$statement->execute();
$result = $statement->fetchAll();
$data = array();

// $filtered_rows = $statement->rowCount();
foreach ($result as $row)
{
    $companyname1 = $row['name'];
    $companyname = str_replace('&amp;', '&', $companyname1);

    $statement = $connection->prepare($query);
    $statement->execute();
    $result = $statement->fetchAll();
    $data = array();
    $filtered_rows = $statement->rowCount();
    foreach ($result as $row)
    {

        $sub_array = array();

        $totalamount = '';

        //previous balance and total amount calculation
        $query = mysql_query("SELECT * from cash_entry order by ce_id");

        $pb = $row['ce_previous_bal'];
        $state = $row['cancel_status'];

        if ($row['ce_id'] == "1")
        {
            $pb_debit = $row['ce_previous_bal'];
            // $pb_debit= number_format($pb_debit1,2,'.','');
            $pb_credit = $row['ce_previous_bal'];
            // $pb_credit= number_format($pb_credit1,2,'.','');
            $totalamount = $row['ce_total_amount'];
            // $totalamount= number_format($totalamount1,2,'.','');
            
        }

        if (($row['ce_id'] != "1"))
        {
            $id = $row['ce_id'] - 1;
            $totalamount = $row['ce_previous_bal'];
            $selectpb = mysql_query("SELECT * from cash_entry where ce_id='$id' and cancel_status=1 order by ce_id");
            $pbselected = mysql_fetch_array($selectpb);
            $final = $totalamount;
            $credit = $row['ce_cash_cr'];
            $debit = $row['ce_cash_dr'];

            $pb_debit = $final;
            $pb_credit = $final;

            if (($credit != "") && ($row['cancel_status'] == '1'))
            {
                $totalamount = $final + $credit;
                // $totalamount= number_format($totalamount1,2,'.','');
                
            }
            else if (($debit != "") && ($row['cancel_status'] == '1'))
            {
                $totalamount = $final - $debit;
                // $totalamount= number_format($totalamount1,2,'.','');
                
            }
        }
        else
        {
            $pb = $row['ce_previous_bal'];
            $credit = $row['ce_cash_cr'];
            $debit = $row['ce_cash_dr'];
            $pb_debit = $pb;
            $pb_credit = $pb;
            if ($credit != "")
            {
                $totalamount = $pb + $credit;
                // $totalamount= number_format($totalamount1,2,'.','');
                
            }
            else if ($debit != "")
            {
                $totalamount = $pb - $debit;
                // echo $totalamount;
                // $totalamount= number_format($totalamount1,2,'.','');
                
            }
        }

        $id = $row['ce_id'];
        $id1 = $row['ce_id'] - 1;

        $lclCEId = $row['ce_id'];
        $lclId = $row['ce_pay_id'];
        $lclAdvPayId = $row['ce_adv_pay_id'];
        $lclAdvRecId = $row['ce_adv_rec_id'];
        $lclRecId = $row['ce_rec_id'];
        $lclType = $row['ce_type'];
        $status = $row['cancel_status'];
        $crAmt = $row['ce_cash_cr'];
        $drAmt = $row['ce_cash_dr'];
        $lclPBlance = $row["ce_previous_bal"];
        $lclTotalBalance = $row["ce_total_amount"];

        $lclstatus = '';
        if ($lclId != '' and $status == 0)
        {
            $lclstatus = "Changed to NonCash";
        }
        else if ($lclRecId != '' and $status == 0)
        {
            $lclstatus = "Changed to NonCash";
        }
        else if ($lclAdvPayId != '' and $status == 0)
        {
            $lclstatus = "Changed to NonCash";
        }
        else if ($lclAdvRecId != '' and $status == 0)
        {
            $lclstatus = "Changed to NonCash";
        }
        else if ($lclId == '' and $status == 0 and $lclRecId == '')
        {
            $lclstatus = "Cancelled";
        }

        // if cash_entry status == 1 (registered)
        if ($status == '1')
        {
            //fetching details for credit direct from cash entry
            if (($lclId == '') && ($lclRecId == '') && ($lclType == 'Debit') && ($lclAdvPayId == '') && ($lclAdvRecId == ''))
            {

                $sub_array[] = '<span style="font-size: 10px;font-weight: 400;">' . $row['ce_id'] . '</span>';
                $sub_array[] = '<span style="font-size: 10px;font-weight: 400;color:black" >
					<a style="font-weight: 600;" href="cash_entry_view.php?cid=' . $row['ce_id'] . '" >' . $row['ce_id'] . '</a><br> 
					[' . date('d-m-Y', strtotime($row["ce_pay_date"])) . ']</span>';

                if ($row['ce_id'] == 1)
                {
                    $sub_array[] = '<span style="font-weight: 600;font-size: 10px; color: blue;">' . "Cash In-hand" . '</span>';
                }
                else
                {
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . "Direct" . '</span>';
                }
                $sub_array[] = '<span style="color: green; font-weight: 800; font-size: 11px;">' . $row["ce_type"] . '</span>';

                $ce_from_cust1 = str_replace('&amp;', '&', $row["ce_from_cust"]);
                $ce_from_cust = str_replace('&amp;', '&', $ce_from_cust1);
                if ($row['ce_bank_name'] != '' && $row['ce_account_no'] != '' || $row['ce_from_cust'] != '')
                {
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $ce_from_cust . '<br>[' . $row["ce_bank_name"] . ']' . '<br>[ ' . $row["ce_account_no"] . ' ]</span>';
                    // $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">'.$ce_from_cust.'</span>';
                    
                }
                else
                {
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $ce_from_cust . '</span>';
                }
                $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $row["ce_paid_to"] . '</span>';
                if ($row['ce_ref_no'] != '')
                {
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $row["ce_payment_mode"] . '<br>Ref No: [' . $row["ce_ref_no"] . ']</span>';
                }
                else
                {
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $row["ce_payment_mode"] . '</span>';
                }

                if ($row['ce_id'] == "1")
                {
                    $sub_array[] = '<span style="text-align: right;font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . $row["ce_previous_bal"] . '</span>';
                }
                else
                {
                    $sub_array[] = '<span style="text-align: right;font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_debit, 2) . '</span>';
                }
                if ($row["ce_cash_cr"] != '')
                {
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($row["ce_cash_cr"], 2) . '</span>';
                }
                else
                {
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">&nbsp;' . number_format($row["ce_cash_cr"], 2) . '</span>';

                }

                $sub_array[] = '';
                $sub_array[] = '<span style="text-align: right;font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($row["ce_total_amount"], 2) . '</span>';
                $sub_array[] = '<span style="text-align: right;font-weight: 400;font-size: 10px;">' . $row["ce_debit_for"] . '</span>';
                $sub_array[] = '<button  onclick="return openModal(' . $row['ce_id'] . ')" style="font-size:10px;color:black;">View</button>';
                $sub_array[] = $row["ce_cash_cr"]; //cr
                $sub_array[] = $row["ce_cash_dr"]; //dr
                $sub_array[] = $lclstatus;
            } //direct credit close
            //fetching details for Debit direct from cash entry
            else if (($lclId == '') && ($lclRecId == '') && ($lclType == 'Credit') && ($lclAdvPayId == '') && ($lclAdvRecId == ''))
            {

                $sub_array[] = '<span style="font-size: 10px;font-weight: 400;">' . $row['ce_id'] . '</span>';
                $sub_array[] = '<span style="font-size: 10px;font-weight: 400;color:black" ><a style="font-weight: 600;" href="cash_entry_view.php?cid=' . $row["ce_id"] . '" >' . $row["ce_id"] . '</a>' . '<br>[' . $row["ce_pay_date"] . ']</span>';
                $sub_array[] = '<span style="font-size: 10px;font-weight: 400;">' . "Direct" . '</span>';
                $sub_array[] = '<span style="color: red; font-weight: 800; font-size: 11px;">' . $row["ce_type"] . '</span>';

                $ce_from_cust = str_replace('&amp;', '&', $row["ce_from_cust"]);
                $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $ce_from_cust . '</span>';

                $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $row["ce_paid_to"] . '</span>';
                $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $row["ce_payment_mode"] . '</span>';

                $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_credit, 2) . '</span>';
                $sub_array[] = '';
                if ($row["ce_cash_dr"] != '')
                {
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($row["ce_cash_dr"], 2) . '</span>';
                }
                else
                {
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">&nbsp;' . number_format($row["ce_cash_dr"], 2) . '</span>';

                }
                $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($row["ce_total_amount"], 2) . '</span>';
                $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $row["ce_debit_for"] . '</span>';
                // $sub_array[] = '<a href="cash_entry_remark.php?cid='.$row["ce_id"].'" >View</a>';
                // $sub_array[] = '<span style="text-align: right;font-weight: 400;font-size: 10px;"><a class="openModalLink" href="cash_entry_remark.php?cid='.$row["ce_id"].'">
                //                  <span>View</span></span>';
                $sub_array[] = '<button  onclick="return openModal(' . $row['ce_id'] . ')" style="font-size:10px;color:black;">View</button>';

                $sub_array[] = $row["ce_cash_cr"];
                $sub_array[] = $row["ce_cash_dr"];
                $sub_array[] = $lclstatus;

            } //direct debit close
            //connection
            // include('includes/config.php');
            //fetching details for payable
            if (($lclId != '') && ($lclRecId == '') && ($lclAdvPayId == '') && ($lclAdvRecId == ''))
            {

                $querypayable = mysql_query("select * from payable_history where id = '$lclId' and paymentmode = 'Cash'");
                while ($rowpayable = mysql_fetch_array($querypayable))
                {

                    $payableid = $rowpayable['id'];
                    $lclSupplier = $rowpayable['supplier'];
                    $lclEffAmt = $rowpayable['eff_amt'];
                    $lclPaymentDate = $rowpayable['paymentdate'];
                    $lclRemark = $rowpayable['remark'];

                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $row['ce_id'] . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;text-align: center;"><a style="font-weight: 600;" href="cash_entry_payable_view.php?cid=' . $lclCEId . '" >' . $lclCEId . '</a>' . '<br>[ ' . $lclPaymentDate . ' ]</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . "Payable" . '</span>';
                    $sub_array[] = '<span style="font-weight: 800; font-size: 11px;color: red;">' . "Credit" . '</span>';
                    $sub_array[] = $companyname;

                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $lclSupplier . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . "Cash" . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_credit, 2) . '</span>';
                    $sub_array[] = "";
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($lclEffAmt, 2) . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($totalamount, 2) . '</span>';
                    $sub_array[] = "";
                    // $sub_array[] = '<a href="cash_entry_payable_remark.php?cid='.$payableid.'" >View</a>';
                    // $sub_array[] = '<span style="text-align: right;font-weight: 400;font-size: 10px;"><a class="openModalLink" href="cash_entry_payable_remark.php?cid='.$payableid.'">
                    //                  <span>View</span></span>';
                    $sub_array[] = '<button  onclick="return openModalPayable(' . $payableid . ')" style="font-size:10px;color:black;">View</button>';

                    $sub_array[] = ""; //dr
                    $sub_array[] = $lclEffAmt; //cr
                    $sub_array[] = $lclstatus; //status
                    
                }
            } //paybale close
            //fectching details from Advance payable if payment mode==cash
            else if (($lclAdvPayId != '') && ($lclId == '') && ($lclAdvRecId == '') && ($lclRecId == ''))
            {
                $querypayableAdv = mysql_query("select * from payable_advance  where adv_id = '$lclAdvPayId' and paymentmode = 'Cash'");
                while ($rowpayableAdv = mysql_fetch_array($querypayableAdv))
                {

                    $payableAdvid = $rowpayableAdv['adv_id'];
                    $lclSupplier = $rowpayableAdv['supplier'];
                    $lclAdvAmt = $rowpayableAdv['adv_amt'];
                    $lclPaymentDate = $rowpayableAdv['paymentdate'];
                    $lclRemark = $rowpayableAdv['remark'];

                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $row['ce_id'] . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;text-align: center;"><a style="font-weight: 600;" href="cash_entry_payable_view.php?cid=' . $lclCEId . '" >' . $lclCEId . '</a>' . '<br>[ ' . $lclPaymentDate . ' ]</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . "Payable Advance" . '</span>';
                    $sub_array[] = '<span style="font-weight: 800; font-size: 11px;color: red;">' . "Credit" . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $companyname . '</span>';

                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $lclSupplier . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . "Cash" . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_credit, 2) . '</span>';
                    $sub_array[] = "";
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($lclAdvAmt, 2) . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($totalamount, 2) . '</span>';
                    $sub_array[] = "";
                    $sub_array[] = '<button  onclick="return openModalPayableAdv(' . $payableAdvid . ')" style="font-size:10px;color:black;">View</button>';
                    $sub_array[] = ""; //dr
                    $sub_array[] = $lclAdvAmt; //cr
                    $sub_array[] = $lclstatus; //status
                    
                }
            } //payable advance close
            //fetching details for Receivable if payment mode==cash
            else if (($lclRecId != '') && ($lclId == '') && ($lclAdvPayId == '') && ($lclAdvRecId == ''))
            {

                $queryRec = mysql_query("SELECT * FROM receivable_history where id = '$lclRecId' and payment_mode = 'Cash'");
                while ($rowRec = mysql_fetch_array($queryRec))
                {

                    $recid = $rowRec['id'];
                    $lclCustomer = $rowRec['customername'];
                    $lclEffAmt = $rowRec['eff_amt'];
                    $lclPaymentDate = $rowRec['paymentdate'];
                    $lclRemark = $rowRec['remark'];

                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $row['ce_id'] . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;text-align: center;"><a style="font-weight: 600;" href="cash_entry_receivable_view.php?cid=' . $lclCEId . '" >' . $lclCEId . '</a>' . '<br>[ ' . $lclPaymentDate . ' ]</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . "Receivable" . '</span>';
                    $sub_array[] = '<span  style="font-weight: 800; font-size: 11px;color: green">' . "Debit" . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $lclCustomer . '</span>';

                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $companyname . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . "Cash" . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_debit, 2) . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($lclEffAmt, 2) . '</span>';
                    $sub_array[] = "";

                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($totalamount, 2) . '</span>';
                    $sub_array[] = "";
                    $sub_array[] = '<button  onclick="return openModalReceivable(' . $recid . ')" style="font-size:10px;color:black;">View</button>';

                    $sub_array[] = $lclEffAmt; //dr
                    $sub_array[] = ""; //cr
                    $sub_array[] = $lclstatus; //status
                    
                }
            } //receivable close
            

            //fetching details for Receivable Adavance if payment mode==cash
            else if (($lclAdvRecId != '') && ($lclId == '') && ($lclAdvPayId == '') && ($lclRecId == ''))
            {

                $queryRecAdv = mysql_query("SELECT * FROM receivable_advance where adv_id = '$lclAdvRecId' and payment_mode = 'Cash'");
                while ($rowRecAdv = mysql_fetch_array($queryRecAdv))
                {

                    $recAdvid = $rowRecAdv['adv_id'];
                    $lclCustomer = $rowRecAdv['customername'];
                    $lclEffAmt = $rowRecAdv['adv_amt'];
                    $lclPaymentDate = $rowRecAdv['paymentdate'];
                    $lclRemark = $rowRecAdv['remark'];

                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $row['ce_id'] . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;text-align: center;"><a style="font-weight: 600;" href="cash_entry_receivable_view.php?cid=' . $lclCEId . '" >' . $lclCEId . '</a>' . '<br>[ ' . $lclPaymentDate . ' ]</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . "Receivable Advance" . '</span>';
                    $sub_array[] = '<span  style="font-weight: 800; font-size: 11px;color: green">' . "Debit" . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $lclCustomer . '</span>';

                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . $companyname . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;">' . "Cash" . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_debit, 2) . '</span>';
                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($lclEffAmt, 2) . '</span>';
                    $sub_array[] = "";

                    $sub_array[] = '<span style="font-weight: 400;font-size: 10px;"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($totalamount, 2) . '</span>';
                    $sub_array[] = "";
                    $sub_array[] = '<button  onclick="return openModalReceivableAdv(' . $recAdvid . ')" style="font-size:10px;color:black;">View</button>';

                    $sub_array[] = $lclEffAmt; //dr
                    $sub_array[] = ""; //cr
                    $sub_array[] = $lclstatus; //status
                    
                }
            } //receivable adavance close
            

            
        } //status id condition
        else
        {
            //fetching cash entry details if entry has been cancelled for credit
            if (($lclId == '') && ($lclRecId == '') && ($lclType == 'Debit') && ($lclAdvPayId == '') && ($lclAdvRecId == ''))
            {

                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row['ce_id'] . '</span>';
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled"><a style="font-weight: 600;" href="cash_entry_view.php?cid=' . $row['ce_id'] . '" >' . $row['ce_id'] . '</a><br> [' . $row['ce_pay_date'] . ']</span>';
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . "Direct" . '</span>';
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row["ce_type"] . '</span>';
                $ce_from_cust = str_replace('&amp;', '&', $row["ce_from_cust"]);

                if ($row["ce_from_cust"] != '' || $row['ce_bank_name'] != '' && $row['ce_account_no'] != '')
                {
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $ce_from_cust . ' <br>[' . $row["ce_bank_name"] . ']' . '<br>[ ' . $row["ce_account_no"] . ' ]</span>';
                }
                else
                {
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $ce_from_cust . '</span>';
                }

                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row["ce_paid_to"] . '</span>';
                if ($row['ce_ref_no'] != '')
                {
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row["ce_payment_mode"] . '<br>[' . $row["ce_ref_no"] . ']</span>';

                }
                else
                {
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row["ce_payment_mode"] . '</span>';

                }
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_credit, 2) . '</span>';
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($row["ce_cash_cr"], 2) . '</span>';
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . number_format($row["ce_cash_dr"], 2) . '</span>';
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($totalamount, 2) . '</span>';
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row["ce_debit_for"] . '</span>';

                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red;" data-toggle="tooltip" title="This Cash Entry has been Cancelled"><button  onclick="return openModal(' . $row['ce_id'] . ')" style="font-size:10px;color:black;">View</button></span>';

                $sub_array[] = ''; //cr
                $sub_array[] = ''; //dr
                $sub_array[] = $lclstatus; //status
                
            }

            //cash entry details if entry is cancelled and it is for debit
            else if (($lclId == '') && ($lclRecId == '') && ($lclType == 'Credit') && ($lclAdvPayId == '') && ($lclAdvRecId == ''))
            {
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red;" data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row['ce_id'] . '</span>';
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red;" data-toggle="tooltip" title="This Cash Entry has been Cancelled"><a href="cash_entry_view.php?cid=' . $row["ce_id"] . '" >' . $row["ce_id"] . '</a>' . '<br>[ ' . $row["ce_pay_date"] . ' ]</span>';
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . "Direct" . '</span>';

                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row["ce_type"] . '</span>';

                $ce_from_cust = str_replace('&amp;', '&', $row["ce_from_cust"]);
                if ($row["ce_from_cust"] != '')
                {

                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $ce_from_cust . ' </span>';

                }
                else
                {
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $ce_from_cust . '</span>';

                }

                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row["ce_paid_to"] . '</span>';

                if ($row['ce_ref_no'] != '')
                {
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row["ce_payment_mode"] . '<br>[ ' . $row["ce_ref_no"] . ' ]</span>';
                }
                else
                {
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row["ce_payment_mode"] . '</span>';
                }

                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_debit, 2) . '</span>';

                $sub_array[] = $row["ce_cash_cr"];
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($row["ce_cash_dr"], 2) . '</span>';
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($totalamount, 2) . '</span>';
                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Cash Entry has been Cancelled">' . $row["ce_debit_for"] . '</span>';

                $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red;" data-toggle="tooltip" title="This Cash Entry has been Cancelled"><button  onclick="return openModal(' . $row['ce_id'] . ')" style="font-size:10px;color:black;">View</button></span>';

                $sub_array[] = ''; //cr
                $sub_array[] = ''; //dr
                $sub_array[] = $lclstatus; //status
                
            }

            //connection
            // include('includes/config.php');
            

            //fetching details for payable if payment mode is changed to non cash
            if (($lclId != '') && ($lclRecId == '') && ($lclAdvPayId == '') && ($lclAdvRecId == ''))
            {

                $querypayable = mysql_query("SELECT * from payable_history where id = '$lclId' and paymentmode != 'Cash'");
                while ($rowpayable = mysql_fetch_array($querypayable))
                {

                    $payableid = $rowpayable['id'];
                    $lclSupplier = $rowpayable['supplier'];
                    $lclEffAmt = $rowpayable['eff_amt'];
                    $lclPaymentDate = $rowpayable['paymentdate'];
                    $lclRemark = $rowpayable['remark'];

                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $row['ce_id'] . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><a href="cash_entry_payable_view.php?cid=' . $lclCEId . '" >' . $lclCEId . '</a>' . '<br>[ ' . $lclPaymentDate . ' ]</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Payable" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Credit" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $companyname . '</span>';

                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $lclSupplier . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Cash" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_debit, 2) . '</span>';
                    $sub_array[] = "";
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($lclEffAmt, 2) . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($totalamount, 2) . '</span>';
                    $sub_array[] = "";
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red;" data-toggle="tooltip" title="This Entry has Changed to NonCash"><button  onclick="return openModalPayable(' . $payableid . ')" style="font-size:10px;color:black;">View</button></span>';

                    $sub_array[] = ''; //cr
                    $sub_array[] = ""; //dr
                    $sub_array[] = $lclstatus; //status
                    
                }
            }

            //fectching details from Advance payable if payment mode!=cash
            else if (($lclAdvPayId != '') && ($lclId == '') && ($lclRecId == '') && ($lclAdvRecId == ''))
            {
                $querypayableAdv = mysql_query("select * from payable_advance  where adv_id = '$lclAdvPayId' and paymentmode != 'Cash'");
                while ($rowpayableAdv = mysql_fetch_array($querypayableAdv))
                {

                    $payableAdvid = $rowpayableAdv['id'];
                    $lclSupplier = $rowpayableAdv['supplier'];
                    $lclAdvAmt = $rowpayableAdv['adv_amt'];
                    $lclPaymentDate = $rowpayableAdv['paymentdate'];
                    $lclRemark = $rowpayableAdv['remark'];

                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $row['ce_id'] . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><a href="cash_entry_payable_view.php?cid=' . $lclCEId . '" >' . $lclCEId . '</a>' . '<br>[ ' . $lclPaymentDate . ' ]</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Payable Advance" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Credit" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $companyname . '</span>';

                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $lclSupplier . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Cash" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_debit, 2) . '</span>';
                    $sub_array[] = "";
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($lclAdvAmt, 2) . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($totalamount, 2) . '</span>';
                    $sub_array[] = "";
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red;" data-toggle="tooltip" title="This Entry has Changed to NonCash"><button  onclick="return openModalPayableAdv(' . $payableAdvid . ')" style="font-size:10px;color:black;">View</button></span>';

                    $sub_array[] = '';
                    $sub_array[] = "";
                    $sub_array[] = $lclstatus;
                }
            }

            //fectching details from Receivable if payment mode!=cash
            else if (($lclRecId != '') && ($lclId == '') && ($lclAdvPayId == '') && ($lclAdvRecId == ''))
            {
                $queryRec = mysql_query("SELECT * FROM receivable_history where id = '$lclRecId' and payment_mode != 'Cash'");
                while ($rowRec = mysql_fetch_array($queryRec))
                {

                    $recid = $rowRec['id'];
                    $lclCustomer = $rowRec['customername'];
                    $lclEffAmt = $rowRec['eff_amt'];
                    $lclPaymentDate = $rowRec['paymentdate'];
                    $lclRemark = $rowRec['remark'];

                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $row['ce_id'] . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><a href="cash_entry_receivable_view.php?cid=' . $lclCEId . '" >' . $lclCEId . '</a>' . '<br>[ ' . $lclPaymentDate . ' ]</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Receivable" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Debit" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $lclCustomer . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $companyname . '</span>';

                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Cash" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_credit, 2) . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($lclEffAmt, 2) . '</span>';
                    $sub_array[] = "";

                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($totalamount, 2) . '</span>';
                    $sub_array[] = "";
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red;" data-toggle="tooltip" title="This Entry has Changed to NonCash"><button  onclick="return openModalReceivable(' . $recid . ')" style="font-size:10px;color:black;">View</button></span>';

                    $sub_array[] = "";
                    $sub_array[] = '';
                    $sub_array[] = $lclstatus;
                }
            }

            //fectching details from Receivable Adavance  if payment mode!=cash
            else if (($lclAdvRecId != '') && ($lclId == '') && ($lclAdvPayId == '') && ($lclRecId == ''))
            {
                $queryRecAdv = mysql_query("SELECT * FROM receivable_advance where adv_id = '$lclAdvRecId' and payment_mode != 'Cash'");
                while ($rowRecAdv = mysql_fetch_array($queryRecAdv))
                {

                    $recAdvid = $rowRecAdv['adv_id'];
                    $lclCustomer = $rowRecAdv['customername'];
                    $lclEffAmt = $rowRecAdv['adv_amt'];
                    $lclPaymentDate = $rowRecAdv['paymentdate'];
                    $lclRemark = $rowRecAdv['remark'];

                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $row['ce_id'] . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><a href="cash_entry_receivable_view.php?cid=' . $lclCEId . '" >' . $lclCEId . '</a>' . '<br>[ ' . $lclPaymentDate . ' ]</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Receivable Adavance" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Debit" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $lclCustomer . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . $companyname . '</span>';

                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash">' . "Cash" . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($pb_credit, 2) . '</span>';
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($lclEffAmt, 2) . '</span>';
                    $sub_array[] = "";

                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red " data-toggle="tooltip" title="This Entry has Changed to NonCash"><span style="font-family:sans-serif; font-size: 10px;">&#8377</span>&nbsp;' . number_format($totalamount, 2) . '</span>';
                    $sub_array[] = "";
                    $sub_array[] = '<span style="text-align: center; font-weight: 400; font-size: 10px; text-decoration: line-through;text-decoration-color:red;" data-toggle="tooltip" title="This Entry has Changed to NonCash"><button  onclick="return openModalReceivableAdv(' . $recAdvid . ')" style="font-size:10px;color:black;">View</button></span>';

                    $sub_array[] = "";
                    $sub_array[] = '';
                    $sub_array[] = $lclstatus;
                }
            }

        }

        $data[] = $sub_array;
    }
}

function get_all_data()
{
    $query = "SELECT * FROM cash_entry";
    $result = mysql_query($query);
    return mysql_num_rows($result);
}

$output = array(
    "draw" => intval($_POST["draw"]) ,
    "recordsTotal" => get_all_data() ,
    "recordsFiltered" => get_all_data() ,
    "data" => $data
);
echo json_encode($output);

// require( 'vendor/DataTables/server-side/scripts/ssp.class.php' );
// echo json_encode(
//     SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
// );

?>
