0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.117.91.170


Current Path : /var/www/html/oums/src/
Upload File :
Current File : /var/www/html/oums/src/expense_report_details_head_sum.php

<?php
include("sys_session.php");
include("sys_connect.php");
include("sys_mainphp.php");

$load_data = $_POST["load_data"];

$resp_mesg = "";
$resp_stat = "";
$resp_file = "";

if ($load_data == 'dept_data') {
    if ($type_id == 'ADMIN') {
        $mysql = "select * from masdept order by fdeptname";
    } elseif ($type_id == 'CHIEF') {
        $mysql = "select * from masdept where fdeptstat='T' and fdepthead='$empl_id' order by fdeptname";
    } else {
        $mysql = "select * from masdept where fdeptcode='$dept_id' order by fdeptname";
    }
    $myres = mysqli_query($mycon, $mysql);
    if (mysqli_num_rows($myres) > 1) {
        echo "<option value=0>--Select--</option>";
    }
    while ($row = mysqli_fetch_assoc($myres)) {
        echo "<option value='$row[fdeptcode]'>$row[fdeptname]</option>";
    }
}

if ($load_data == 'empl_data') {
    $dept_code = $_POST["dept_code"];
    if ($type_id == 'ADMIN') {
        $mysql = "select * from masempl where fdeptcode='$dept_code' and fexpnentr='T' order by femplname";
        echo "<option value=%>ALL</option>";
    } elseif ($type_id == 'CHIEF') {
        $mysql = "select * from masempl where fdeptcode='$dept_code' and fexpnentr='T' order by femplname";
        echo "<option value=%>ALL</option>";
    } else {
        $mysql = "select * from masempl where femplcode='$empl_id' and fexpnentr='T' order by femplname";
    }
    $myres = mysqli_query($mycon, $mysql);
    if (mysqli_num_rows($myres) != 0) {
        while ($row = mysqli_fetch_assoc($myres)) {
            echo "<option value='$row[femplcode]'>$row[femplname]</option>";
        }
    }
}

if ($load_data == 'head_desc') {
    $acnt_type = $_POST["acnt_type"];
    if ($acnt_type != "") {
        $mysql = "select * from mashead where facnttype like '$acnt_type' order by facnttype,fheaddesc";
        $myres = mysqli_query($mycon, $mysql);
        if (mysqli_num_rows($myres) != 0) {
            echo "<option value=%>ALL</option>";
            while ($row = mysqli_fetch_assoc($myres)) {
                echo "<option value='$row[fheaddesc]'>$row[fheaddesc] [$row[facnttype]]</option>";
            }
        }
    }
}

if ($load_data == 'view_rept') {
    $dept_code = $_POST['dept_code'];
    $empl_code = $_POST['empl_code'];
    $acnt_type = $_POST['acnt_type'];
    $head_desc = $_POST['head_desc'];
    $expn_dat1 = $_POST['expn_dat1'];
    $expn_dat2 = $_POST['expn_dat2'];
    $rept_type = $_POST['rept_type'];


    $header_dept_name = get_dept_name($dept_code);
    $header_empl_name = get_empl_name($empl_code);

    //EXPENSE LIST
    if ($rept_type == 0) {
        require("fpdf/fpdf.php");
        $line_no = 0;
        $pdf = new FPDF('L', 'mm', 'A4');
        $pdf->AddPage();
        $pdf->SetMargins(10, 10);

        $pdf->SetFont('Arial', 'B', 10);
        $pdf->Cell(0, 7, "EXPENSE STATEMENT (DAYWISE)", 0, 1, "C");
        $line_no++;
        $pdf->Cell(0, 7, "{$header_dept_name}", 0, 1, "C");
        $line_no++;
        $pdf->Cell(0, 7, "Employee: {$header_empl_name}, Expense Date: {$expn_dat1} to {$expn_dat2}", 0, 1, "C");
        $line_no++;

        $pdf->SetFont('Arial', 'B', 9);
        $pdf->Cell(10, 7, "Sl No", 1, 0, "C");
        $pdf->Cell(25, 7, "Date", 1, 0, "C");
        $pdf->Cell(70, 7, "Description", 1, 0, "C");
        $pdf->Cell(25, 7, "Receipt", 1, 0, "C");
        $pdf->Cell(25, 7, "Payment", 1, 0, "C");
        $pdf->Cell(25, 7, "Balance", 1, 0, "C");
        $pdf->Cell(100, 7, "Remarks", 1, 0, "C");
        $pdf->ln();
        $line_no++;

        $pdf->SetFont('Arial', '', 9);

        $totl_recp = 0;
        $totl_payt = 0;
        $totl_baln = 0;
        $rang_recp = 0;
        $rang_payt = 0;
        $i = 1;

        //Prev. receipt and payments--------------
        $mysqlx = "select sum(case when facnttype='receipt' then fexpnamnt end) as fexpnrecp,sum(case when facnttype='payment' then fexpnamnt end) as fexpnpayt 
            from expenses where fdeptcode='$dept_code' and femplcode like '$empl_code' and fexpndate < str_to_date('$expn_dat1','%d/%m/%Y') 
            and facnttype like '$acnt_type' and fheaddesc like '$head_desc'";

        $myresx = mysqli_query($mycon, $mysqlx);
        while ($rowx = mysqli_fetch_assoc($myresx)) {
            $totl_recp = $rowx['fexpnrecp'];
            $totl_payt = $rowx['fexpnpayt'];
        }
        $totl_baln = $totl_recp - $totl_payt;

        $totl_recp = number_format((float)$totl_recp, 2, '.', '');
        $totl_payt = number_format((float)$totl_payt, 2, '.', '');
        $totl_baln = number_format((float)$totl_baln, 2, '.', '');

        $pdf->Cell(10, 7, "{$i}", 1, 0, "C");
        $pdf->Cell(25, 7, "-", 1, 0, "C");
        $pdf->Cell(70, 7, "BALANCE BEFORE {$expn_dat1}", 1, 0, "L");
        $pdf->Cell(25, 7, "{$totl_recp}", 1, 0, "R");
        $pdf->Cell(25, 7, "{$totl_payt}", 1, 0, "R");
        $pdf->Cell(25, 7, "{$totl_baln}", 1, 0, "R");
        $pdf->Cell(100, 7, "", 1, 0, "L");
        $pdf->ln();
        $line_no++;
        $i++;

        //Amount for the range given
        $mysql1 = "select fexpndate, facnttype, fheaddesc, sum(fexpnamnt) as famntexpn, fexpnremk from expenses where fdeptcode='$dept_code' and femplcode like '$empl_code' and fexpndate between str_to_date('$expn_dat1','%d/%m/%Y') and str_to_date('$expn_dat2','%d/%m/%Y') and facnttype like '$acnt_type' and fheaddesc like '$head_desc' group by fexpndate,facnttype,fheaddesc,fexpnremk order by fexpndate,facnttype desc,fheaddesc,fexpnremk";
        $myres1 = mysqli_query($mycon, $mysql1);

        while ($row1 = mysqli_fetch_assoc($myres1)) {
            if ($line_no == 0 || $line_no % 25 == 0) {
                $pdf->SetFont('Arial', 'B', 10);
                $pdf->Cell(0, 7, "EXPENSE STATEMENT (DAYWISE)", 0, 1, "C");
                $line_no++;
                $pdf->Cell(0, 7, "{$header_dept_name}", 0, 1, "C");
                $line_no++;
                $pdf->Cell(0, 7, "Employee: {$header_empl_name}, Expense Date: {$expn_dat1} to {$expn_dat2}", 0, 1, "C");
                $line_no++;

                $pdf->SetFont('Arial', 'B', 9);
                $pdf->Cell(10, 7, "Sl No", 1, 0, "C");
                $pdf->Cell(25, 7, "Date", 1, 0, "C");
                $pdf->Cell(70, 7, "Description", 1, 0, "C");
                $pdf->Cell(25, 7, "Receipt", 1, 0, "C");
                $pdf->Cell(25, 7, "Payment", 1, 0, "C");
                $pdf->Cell(25, 7, "Balance", 1, 0, "C");
                $pdf->Cell(100, 7, "Remarks", 1, 0, "C");
                $pdf->ln();
                $line_no++;
            }
            $pdf->SetFont('Arial', '', 9);
            $expn_date = date("d/m/Y", strtotime($row1['fexpndate']));
            $acnt_type = $row1['facnttype'];
            $head_desc = $row1['fheaddesc'];
            $expn_amnt = $row1['famntexpn'];
            $expn_remk = $row1['fexpnremk'];

            if (strtolower($acnt_type) == 'receipt') {
                $totl_recp = $totl_recp + $expn_amnt;
                $rang_recp = $rang_recp + $expn_amnt;
                $totl_baln = $totl_baln + $expn_amnt;
            }

            if (strtolower($acnt_type) == 'payment') {
                $totl_payt = $totl_payt + $expn_amnt;
                $rang_payt = $rang_payt + $expn_amnt;
                $totl_baln = $totl_baln - $expn_amnt;
            }

            $totl_recp = number_format((float)$totl_recp, 2, '.', '');
            $totl_payt = number_format((float)$totl_payt, 2, '.', '');
            $totl_baln = number_format((float)$totl_baln, 2, '.', '');


            $pdf->Cell(10, 7, "{$i}", 1, 0, "C");
            $pdf->Cell(25, 7, "{$expn_date}", 1, 0, "C");
            $pdf->Cell(70, 7, "{$head_desc}", 1, 0, "L");
            if (strtolower($acnt_type) == "receipt") {
                $pdf->Cell(25, 7, "{$expn_amnt}", 1, 0, "R");
                $pdf->Cell(25, 7, "0.00", 1, 0, "R");
            } elseif (strtolower($acnt_type) == "payment") {
                $pdf->Cell(25, 7, "0.00", 1, 0, "R");
                $pdf->Cell(25, 7, "{$expn_amnt}", 1, 0, "R");
            }

            $pdf->Cell(25, 7, "{$totl_baln}", 1, 0, "R");
            $pdf->Cell(100, 7, "{$expn_remk}", 1, 0, "L");
            $pdf->ln();
            $line_no++;
            $i++;
        }

        $rang_recp = number_format((float)$rang_recp, 2, '.', '');
        $rang_payt = number_format((float)$rang_payt, 2, '.', '');

        $rang_baln = $rang_recp - $rang_payt;
        $rang_baln = number_format((float)$rang_baln, 2, '.', '');

        $pdf->Cell(105, 7, "Total from {$expn_dat1} to {$expn_dat2}", 1, 0, "C");
        $pdf->Cell(25, 7, "{$rang_recp}", 1, 0, "R");
        $pdf->Cell(25, 7, "{$rang_payt}", 1, 0, "R");
        $pdf->Cell(25, 7, "{$rang_baln}", 1, 0, "R");
        $pdf->Cell(100, 7, "", 1, 0, "C");
        $pdf->ln();
        $line_no++;

        $pdf->Cell(105, 7, "Grand Total", 1, 0, "C");
        $pdf->Cell(25, 7, "{$totl_recp}", 1, 0, "R");
        $pdf->Cell(25, 7, "{$totl_payt}", 1, 0, "R");
        $pdf->Cell(25, 7, "{$totl_baln}", 1, 0, "R");
        $pdf->Cell(100, 7, "", 1, 0, "C");
        $pdf->ln();
        $line_no++;
        $resp_file = 'reports/expense_list.pdf';
        $pdf->output($resp_file, 'F');
    }

    //EXPENSE DETAILS
    if ($rept_type == 1) {
        require("fpdf/fpdf.php");
        $line_no = 1;
        $pdf = new FPDF('L', 'mm', 'A4');
        $pdf->AliasNbPages();
        $pdf->AddPage();
        $pdf->SetMargins(10, 10);


        $mysql1 = "select fexpndate, femplcode, facnttype, fheaddesc, fexpnamnt, fexpnremk, fexpnstat from expenses where fdeptcode='$dept_code' and femplcode like '$empl_code' and fexpndate between str_to_date('$expn_dat1','%d/%m/%Y') and str_to_date('$expn_dat2','%d/%m/%Y') and facnttype like '$acnt_type' and fheaddesc like '$head_desc' group by fexpndate, fdeptcode, femplcode, facnttype,fheaddesc,fexpnremk";
        $myres1 = mysqli_query($mycon, $mysql1);
        $mycnt = mysqli_num_rows($myres1);
        if ($mycnt == 0) {
            $resp_mesg = "No records found!";
        }

        $i = 1;
        $expn_date = "";
        $totl_recp = 0;
        $totl_payt = 0;
        $recp_amnt = 0;
        $days_recp = 0;
        $payt_amnt = 0;
        $days_payt = 0;

        while ($row1 = mysqli_fetch_assoc($myres1)) {
            if ($line_no == 1 || $line_no % 26 == 0) {
                $line_no = 1;
                $pdf->SetFont('Arial', 'B', 10);
                $pdf->Cell(0, 7, "EXPENSE DETAILS (DAYWISE)", 0, 1, "C");
                $line_no++;
                $pdf->Cell(0, 7, "{$header_dept_name}", 0, 1, "C");
                $line_no++;
                $pdf->Cell(0, 7, "Employee: {$header_empl_name}, Expense Date: {$expn_dat1} to {$expn_dat2}", 0, 1, "C");
                $line_no++;

                $pdf->SetFont('Arial', 'B', 9);
                $pdf->Cell(10, 7, "Sl No", 1, 0, "C");
                $pdf->Cell(25, 7, "Date", 1, 0, "C");
                $pdf->Cell(50, 7, "Empl Name", 1, 0, "C");
                $pdf->Cell(60, 7, "Description", 1, 0, "C");
                $pdf->Cell(25, 7, "Receipt", 1, 0, "C");
                $pdf->Cell(25, 7, "Payment", 1, 0, "C");
                $pdf->Cell(80, 7, "Remarks", 1, 0, "C");
                $pdf->ln();
                $line_no++;
            }

            if ($expn_date != date('d/m/Y', strtotime($row1['fexpndate'])) && $expn_date != '') {
                $pdf->SetFont('Arial', 'B', 9);
                $pdf->Cell(145, 7, "{$expn_date} Total", 1, 0, "R");
                $pdf->Cell(25, 7, "{$days_recp}", 1, 0, "R");
                $pdf->Cell(25, 7, "{$days_payt}", 1, 0, "R");
                $pdf->Cell(80, 7, "", 1, 0, "C");
                $pdf->ln();
                $line_no++;
                $pdf->ln();
                $line_no++;

                $days_recp = 0;
                $days_payt = 0;
                $i = 1;
            }

            if ($line_no == 1 || $line_no % 26 == 0) {
                $line_no = 1;
                $pdf->SetFont('Arial', 'B', 10);
                $pdf->Cell(0, 7, "EXPENSE DETAILS (DAYWISE)", 0, 1, "C");
                $line_no++;
                $pdf->Cell(0, 7, "{$header_dept_name}", 0, 1, "C");
                $line_no++;
                $pdf->Cell(0, 7, "Employee: {$header_empl_name}, Expense Date: {$expn_dat1} to {$expn_dat2}", 0, 1, "C");
                $line_no++;

                $pdf->SetFont('Arial', 'B', 9);
                $pdf->Cell(10, 7, "Sl No", 1, 0, "C");
                $pdf->Cell(25, 7, "Date", 1, 0, "C");
                $pdf->Cell(50, 7, "Empl Name", 1, 0, "C");
                $pdf->Cell(60, 7, "Description", 1, 0, "C");
                $pdf->Cell(25, 7, "Receipt", 1, 0, "C");
                $pdf->Cell(25, 7, "Payment", 1, 0, "C");
                $pdf->Cell(80, 7, "Remarks", 1, 0, "C");
                $pdf->ln();
                $line_no++;
            }

            $recp_amnt = 0;
            $payt_amnt = 0;

            $expn_date = date('d/m/Y', strtotime($row1['fexpndate']));
            $empl_code = $row1['femplcode'];
            $gempl_name = "";
            $acnt_type = $row1['facnttype'];
            $head_desc = $row1['fheaddesc'];
            $expn_remk = $row1['fexpnremk'];

            if ($acnt_type == 'RECEIPT') {
                $recp_amnt = $row1['fexpnamnt'];
                $days_recp = $days_recp + $recp_amnt;
                $totl_recp = $totl_recp + $recp_amnt;
            }

            if ($acnt_type == 'PAYMENT') {
                $payt_amnt = $row1['fexpnamnt'];
                $days_payt = $days_payt + $payt_amnt;
                $totl_payt = $totl_payt + $payt_amnt;
            }

            $recp_amnt = number_format((float)$recp_amnt, 2, '.', '');
            $payt_amnt = number_format((float)$payt_amnt, 2, '.', '');

            $totl_recp = number_format((float)$totl_recp, 2, '.', '');
            $totl_payt = number_format((float)$totl_payt, 2, '.', '');

            $days_recp = number_format((float)$days_recp, 2, '.', '');
            $days_payt = number_format((float)$days_payt, 2, '.', '');

            $empl_name = get_empl_name($empl_code);
            $pdf->SetFont('Arial', '', 9);
            $pdf->Cell(10, 7, "{$i}", 1, 0, "C");
            $pdf->Cell(25, 7, "{$expn_date}", 1, 0, "C");
            $pdf->Cell(50, 7, "{$empl_name}", 1, 0, "L");
            $pdf->Cell(60, 7, "{$head_desc}", 1, 0, "L");
            $pdf->Cell(25, 7, "{$recp_amnt}", 1, 0, "R");
            $pdf->Cell(25, 7, "{$payt_amnt}", 1, 0, "R");
            $pdf->Cell(80, 7, "{$expn_remk}", 1, 0, "L");
            $pdf->ln();
            $line_no++;
            $i++;
        }

        $totl_amnt = $totl_payt + $totl_recp;
        $totl_amnt = number_format((float)$totl_amnt, 2, '.', '');

        $pdf->SetFont('Arial', 'B', 9);
        $pdf->Cell(145, 7, "{$expn_date} Total", 1, 0, "R");
        $pdf->Cell(25, 7, "{$days_recp}", 1, 0, "R");
        $pdf->Cell(25, 7, "{$days_payt}", 1, 0, "R");
        $pdf->Cell(80, 7, "", 1, 0, "C");
        $pdf->ln();
        $line_no++;
        $pdf->ln();
        $line_no++;

        $pdf->Cell(145, 7, "Grand Total", 1, 0, "R");
        $pdf->Cell(25, 7, "{$totl_recp}", 1, 0, "R");
        $pdf->Cell(25, 7, "{$totl_payt}", 1, 0, "R");
        $pdf->Cell(80, 7, "", 1, 0, "C");
        $pdf->ln();
        $line_no++;
        $resp_file = 'reports/expense_details.pdf';
        $pdf->output($resp_file, 'F');
    }

    //Monthwise report -----------------------------------------				
    if ($rept_type == 2) {
        require("fpdf/fpdf.php");
        $line_no = 0;
        $pdf = new FPDF('P', 'mm', 'A4');
        $pdf->AddPage();
        $pdf->SetMargins(10, 10);

        $pdf->SetFont('Arial', 'B', 10);
        $pdf->Cell(0, 7, "EXPENSE SUMMARY (MONTHWISE)", 0, 1, "C");
        $line_no++;
        $pdf->Cell(0, 7, "{$header_dept_name}", 0, 1, "C");
        $line_no++;
        $pdf->Cell(0, 7, "Employee: {$header_empl_name}, Expense Date: {$expn_dat1} to {$expn_dat2}", 0, 1, "C");
        $line_no++;

        $pdf->SetFont('Arial', 'B', 9);
        $pdf->Cell(10, 7, "Sl No", 1, 0, "C");
        $pdf->Cell(30, 7, "Month", 1, 0, "C");
        $pdf->Cell(30, 7, "Receipt", 1, 0, "C");
        $pdf->Cell(30, 7, "Payment", 1, 0, "C");
        $pdf->Cell(30, 7, "Balance", 1, 0, "C");
        $pdf->Cell(50, 7, "Remarks", 1, 0, "C");
        $pdf->ln();
        $line_no++;

        $pdf->SetFont('Arial', '', 9);

        $mysql1 = "select fexpndate,facnttype, sum(case when facnttype='receipt' then fexpnamnt end) as fexpnrecp,sum(case when facnttype='payment' then fexpnamnt end) as fexpnpayt from expenses where fdeptcode='$dept_code' and femplcode like '$empl_code' and fexpndate <= str_to_date('$expn_dat2','%d/%m/%Y') and facnttype like '$acnt_type' group by left(fexpndate,7)";

        $myres1 = mysqli_query($mycon, $mysql1);

        $i = 1;
        $expn_mnth = "";
        $curr_baln = 0;
        $expn_recp = 0;
        $expn_payt = 0;
        $totl_recp = 0;
        $totl_payt = 0;

        while ($row1 = mysqli_fetch_assoc($myres1)) {
            $expn_mnth = date('F Y', strtotime(substr($row1['fexpndate'], 0, 7)));
            $acnt_type = $row1['facnttype'];
            $expn_recp = $row1['fexpnrecp'];
            $expn_payt = $row1['fexpnpayt'];
            $expn_recp = number_format((float)$expn_recp, 2, '.', '');
            $expn_payt = number_format((float)$expn_payt, 2, '.', '');

            $totl_recp = $totl_recp + $expn_recp;
            $totl_payt = $totl_payt + $expn_payt;
            $curr_baln = $curr_baln + ($expn_recp - $expn_payt);

            $totl_recp = number_format((float)$totl_recp, 2, '.', '');
            $totl_payt = number_format((float)$totl_payt, 2, '.', '');
            $curr_baln = number_format((float)$curr_baln, 2, '.', '');

            $pdf->Cell(10, 7, "{$i}", 1, 0, "C");
            $pdf->Cell(30, 7, "{$expn_mnth}", 1, 0, "L");
            $pdf->Cell(30, 7, "{$expn_recp}", 1, 0, "R");
            $pdf->Cell(30, 7, "{$expn_payt}", 1, 0, "R");
            $pdf->Cell(30, 7, "{$curr_baln}", 1, 0, "R");
            $pdf->Cell(50, 7, "", 1, 0, "C");
            $pdf->ln();
            $line_no++;
            $i++;
        }

        $totl_amnt = $totl_payt + $totl_recp;
        $totl_amnt = number_format((float)$totl_amnt, 2, '.', '');
        $curr_baln = number_format((float)$curr_baln, 2, '.', '');

        $pdf->Cell(40, 7, "Grand Total", 1, 0, "C");
        $pdf->Cell(30, 7, "{$totl_recp}", 1, 0, "R");
        $pdf->Cell(30, 7, "{$totl_payt}", 1, 0, "R");
        $pdf->Cell(30, 7, "{$curr_baln}", 1, 0, "R");
        $pdf->Cell(50, 7, "", 1, 0, "C");
        $pdf->ln();
        $line_no++;

        $resp_file = 'reports/expense_summary_month.pdf';
        $pdf->output($resp_file, 'F');
    }

    if ($rept_type == 3) {
        require("fpdf/fpdf.php");
        $line_no = 0;
        $pdf = new FPDF('P', 'mm', 'A4');
        $pdf->AddPage();
        $pdf->SetMargins(10, 10);

        $pdf->SetFont('Arial', 'B', 10);
        $pdf->Cell(0, 7, "EXPENSE STATEMENT SUMMARY", 0, 1, "C");
        $line_no++;

        $pdf->SetFont('Arial', 'B', 9);
        $pdf->Cell(10, 7, "Sl No", 1, 0, "C");
        $pdf->Cell(80, 7, "Client", 1, 0, "C");
        $pdf->Cell(25, 7, "Receipt", 1, 0, "C");
        $pdf->Cell(25, 7, "Payment", 1, 0, "C");
        $pdf->Cell(25, 7, "Balance", 1, 0, "C");
        $pdf->Cell(25, 7, "Remarks", 1, 0, "C");
        $pdf->ln();
        $line_no++;

        $pdf->SetFont('Arial', '', 9);

        $mysql1 = "select fdeptcode, fexpndate, sum(case when facnttype='receipt' then fexpnamnt end) as fexpnrecp,sum(case when facnttype='payment' then fexpnamnt end) as fexpnpayt from expenses where fdeptcode like '$dept_code' and facnttype like '$acnt_type' and fheaddesc like '$head_desc' and fdeptcode<>'ADMN' group by fdeptcode";

        $myres1 = mysqli_query($mycon, $mysql1);

        $i = 1;
        $dept_code = "";
        $expn_recp = 0;
        $expn_payt = 0;
        $dept_baln = 0;
        $curr_baln = 0;
        $totl_recp = 0;
        $totl_payt = 0;

        while ($row1 = mysqli_fetch_assoc($myres1)) {

            $dept_code = $row1['fdeptcode'];
            $expn_recp = $row1['fexpnrecp'];
            $expn_payt = $row1['fexpnpayt'];
            $expn_recp = number_format((float)$expn_recp, 2, '.', '');
            $expn_payt = number_format((float)$expn_payt, 2, '.', '');

            $totl_recp = $totl_recp + $expn_recp;
            $totl_payt = $totl_payt + $expn_payt;
            $totl_baln = $expn_recp - $expn_payt;
            $curr_baln = $curr_baln + ($expn_recp - $expn_payt);

            $totl_recp = number_format((float)$totl_recp, 2, '.', '');
            $totl_payt = number_format((float)$totl_payt, 2, '.', '');
            $totl_baln = number_format((float)$totl_baln, 2, '.', '');
            $curr_baln = number_format((float)$curr_baln, 2, '.', '');

            $dept_name = get_dept_name($dept_code);

            $pdf->Cell(10, 7, "{$i}", 1, 0, "C");
            $pdf->Cell(80, 7, "{$dept_name}", 1, 0, "L");
            $pdf->Cell(25, 7, "{$expn_recp}", 1, 0, "R");
            $pdf->Cell(25, 7, "{$expn_payt}", 1, 0, "R");
            $pdf->Cell(25, 7, "{$curr_baln}", 1, 0, "R");
            $pdf->Cell(25, 7, "", 1, 0, "C");
            $pdf->ln();
            $line_no++;
            $i++;
        }

        $totl_amnt = $totl_payt + $totl_recp;
        $totl_amnt = number_format((float)$totl_amnt, 2, '.', '');
        $curr_baln = number_format((float)$curr_baln, 2, '.', '');

        $pdf->Cell(90, 7, "Grand Total", 1, 0, "C");
        $pdf->Cell(25, 7, "{$totl_recp}", 1, 0, "R");
        $pdf->Cell(25, 7, "{$totl_payt}", 1, 0, "R");
        $pdf->Cell(25, 7, "{$curr_baln}", 1, 0, "R");
        $pdf->Cell(25, 7, "", 1, 0, "C");
        $pdf->ln();
        $line_no++;

        $resp_file = 'reports/expense_summary_total.pdf';
        $pdf->output($resp_file, 'F');
    }
    echo json_encode(array("mesg" => $resp_mesg, "stat" => $resp_stat, "file" => $resp_file));
}