<?php

session_start();
if (isset($_GET['fromDate'])) {

    $typeOfExcel = $_GET['typeOfExcel'];
    $empId = $_GET['empId'];
    $fromDate = $_GET['fromDate'];
    $toDate = $_GET['toDate'];
    // $calimstatus = $_GET['calimstatus'];
    $obj = new Excel();
    $obj->fetchData($fromDate, $toDate, $empId, $typeOfExcel);
} else {
    echo "no reached";
}
class Excel
{

    function __construct()
    {
        require_once '../Classes/PHPExcel/IOFactory.php';
        require_once dirname(__FILE__).'/DB_Connect.php';
        $this->phpExcel = new PHPExcel();
        $loadExcel = PHPExcel_IOFactory::load("FTA.xlsx");
        $this->activeSheet = $loadExcel;

        $obj=new DB_conncect();
        $this->db=$obj->connectToDB();

    }

    //set individual cell value fucntion
    function setToRelatedSingleCell($rowIndex, $rowValue)
    {
        $this->activeSheet->getActiveSheet()->setCellValue($rowIndex, strval($rowValue));
    }

    //set text-color for claimStatus  fucntion
    function changeTextColor($rowIndex, $color)
    {
        $styleArray = array(
            'font'  => array(
                'color' => array('rgb' => "$color")

            )
        );
        $this->activeSheet->getActiveSheet()->getStyle("$rowIndex")->applyFromArray($styleArray);
    }

    //merging cell (fromcell -> Tocell)
    function mergeCellINExcel($rowIndex, $lastRowIndex, $colIndex)
    {
        $co_ordinate1 = $colIndex . $rowIndex;
        $co_ordinate2 = $colIndex . $lastRowIndex;
        $this->activeSheet->getActiveSheet()->mergeCells("$co_ordinate1:$co_ordinate2");
    }

    //main-query function
    function fetchData($fromDate, $toDate, $empId, $typeOfExcel)
    {
        $cellValueArray = array(); //array
        $sitevistOrder = 1;
        $filename = '';
        $selectStatement = "SELECT tesf.NAME,tesf.`SITE_VISITED_ORDER`,tesf.`EMP_ID`,tesf.`SITE_VISIT_DATE`,tesf.`SITE_ID`,tesf.`DISTANCE_(KMS)`,tesf.`USER_LAT`,tesf.`USER_LNG`,tesf.`USER_LOCATION_ADDRESS`,`tesf-2`.`TOTAL_DISTANCE`,tesf.FTA,tesf.`REPORT_SUBMISSION_STATE`,tesf.`SUPPORTING_BILLS_AVAILABLE_(Y/N)`,tesf.`MODE_OF_TRANSPORT`,tesf.REMARK,tesf.`EMPLOYEE_IMAGES`,tesf.`SITE_LOG_IN`,tesf.`SITE_LOG_OUT`, sitesinfo.`SITE_NAME`, tesf.`SITE_ID_LATITUDE`,  tesf.`SITE_ID_LONGITUDE`, tesf.`SITE_ID_PROJECT`, sitesinfo.`CUSTOMER_NAME`, `tesf-2`.`ENGINEER_HOTEL_BILLS_AMOUNT`,`tesf-2`.`ENGINEER_OTHER_BILLS_AMOUNT`, `tesf-2`.`CLAIM_STATUS`, `tesf-2`.`CLAIM_DATE`, `tesf-2`.`ENGINEER_DEPUTATION_ALLOWANCE`, `tesf-2`.`ENGINEER_DA_AMOUNT`, `tesf-2`.`ENGINEER_FINAL_AMOUNT`, `tesf-2`.`TL_APPROVED_FINAL_AMOUNT`, `tesf-2`.`TL_NAME`, `tesf-2`.`TL_EMP_ID`, `tesf-2`.`TL_APPROVED_DATE`,`tesf-2`.`TL_APPROVED_HOTEL_BILLS`,`tesf-2`.`TL_APPROVED_OTHER_BILLS`,`tesf-2`.`TL_APPROVED_DEPUTATION_ALLOWANCE`, `tesf-2`.`TL_APPROVED_DA_AMOUNT`,`tesf-2`.`TL_DEDUCTED_AMOUNT`,`tesf-2`.`TL_DEDUCTED_REASON`, `tesf-2`.`FINANCE_EMP_NAME`, `tesf-2`.`FINANCE_EMP_ID`, `tesf-2`.`FINANCE_APPROVED_DATE`,`tesf-2`.`FINANCE_APPROVED_HOTEL_BILLS`,`tesf-2`.`FINANCE_APPROVED_OTHER_BILLS`,`tesf-2`.`FINANCE_APPROVED_DEPUTATION_ALLOWANCE`, `tesf-2`.`FINANCE_APPROVED_DA_AMOUNT`, `tesf-2`.`FINANCE_APPROVED_FINAL_AMOUNT`, `tesf-2`.`TOTAL_DEDUCTED_AMOUNT`, `tesf-2`.`FINANCE_DEDUCTED_REASON`,`tesf-2`.`FINANCE_DEDUCTED_AMOUNT`,`tesf-2`.`REJECT_REASON`, `tesf-2`.`TL_OR_FINANCE_REJECTED_DATE` ,`tesf-2`.`PAID_DATE` ,`tesf-2`.`PAID_BY`  FROM `tesf` LEFT JOIN `tesf-2` ON `tesf-2`.`SITE_VISIT_DATE`=tesf.`SITE_VISIT_DATE` AND `tesf-2`.`ENGINEER_EMP_ID`=tesf.`EMP_ID` AND tesf.SITE_VISITED_ORDER=? LEFT JOIN sitesinfo ON sitesinfo.`SITE_ID`=tesf.`SITE_ID` WHERE ";

        if ($typeOfExcel == BULK_EXCEL) {
            $query = $this->db->prepare($selectStatement . "tesf.`SITE_VISIT_DATE` BETWEEN ? AND ?  ORDER BY tesf.`SITE_VISIT_DATE` ASC,tesf.`EMP_ID` ASC,tesf.SITE_VISITED_ORDER ASC");
            $query->bind_param("iss", $sitevistOrder, $fromDate, $toDate);
            $filename = $fromDate . 'to' . $toDate;
        } elseif ($typeOfExcel == INDIVIDUAL_EXCEL) {
            $query = $this->db->prepare($selectStatement . "tesf.`EMP_ID`=? AND tesf.`SITE_VISIT_DATE` BETWEEN ? AND ?  ORDER BY tesf.`SITE_VISIT_DATE`,tesf.`SITE_VISITED_ORDER`ASC");
            $query->bind_param("isss", $sitevistOrder, $empId, $fromDate, $toDate);
            $filename = $empId . "from" . $fromDate . 'to' . $toDate;
        }
        $query->execute();
        $query->bind_result($tesf_name, $tesf_SiteVisitedOrder, $tesf_empid, $tesf_date, $tesf_siteID, $tesf_distance, $tesf_user_lat, $tesf_user_lng, $tesf_user_location_address, $tesf2_TotalDistance, $tesf_FTA, $tesf_report_submission_state, $tesf_SupportingBillsAvaliable, $tesf_mode_of_transport, $tesf_remark, $tesf_EmployeeImages, $tesf_logIn, $tesf_logOut, $sitesinfo_SiteName, $sitesinfo_latitude, $sitesinfo_longitude, $sitesinfo_project, $sitesinfo_CustomerName, $tesf2_engHotelBillsAmount, $tesf2_engOtherBillsAmount, $tesf2_claimstatus, $tesf2_claimdate, $tesf2_engDA, $tesf2_engDAAmount, $tesf2_engFinalAmount, $tesf2_TLApprovedFinalAmount, $tesf2_TL_Name, $tesf2_TL_ID, $tesf2_TLApproveDate, $tesf2_TLApprovedHotelBill, $tesf2_TLApprovedOtherBill, $tesf2_TLApprovedDA, $tesf2_TLApprovedDAAmount, $tesf2_TLDeductedAmount, $tesf2_TLDeductedReason, $tesf2_finance_Name, $tesf2_finance_ID, $tesf2_financeApprovedDate, $tesf2_financeApprovedHotelBill, $tesf2_financeApprovedOtherBill, $tesf2_financeApprovedDA, $tesf2_financeApprovedDAAmount, $tesf2_financeApprovedFinalAmount, $tesf2_totalDeductAmount, $tesf2_financeDeductReason, $tesf2_financeDeductAmount, $tesf2_rejectReason, $tesf2_tlOrFinanceRejectedDate, $tesf2PaidDate, $tesf2PaidBy);
        $query->store_result();

        if ($query->num_rows()) {
            while ($query->fetch()) {

                $data[0] = $tesf_empid;
                $data[1] = $tesf_name;
                $data[2] = $tesf_EmployeeImages;
                $data[3] = $tesf_date;
                $data[4] = $tesf_user_location_address;
                $data[5] = $tesf_user_lat;
                $data[6] = $tesf_user_lng;
                $data[7] = $sitesinfo_latitude;
                $data[8] = $sitesinfo_longitude;
                $data[9] = $tesf_SiteVisitedOrder;
                $data[10] = $tesf_siteID;
                $data[11] = $sitesinfo_SiteName;
                $data[12] = $sitesinfo_project;
                $data[13] = $sitesinfo_CustomerName;
                $data[14] = $tesf_report_submission_state;
                $data[15] = $tesf_mode_of_transport;
                $data[16] = $tesf_SupportingBillsAvaliable;
                $data[17] = $tesf_logIn;
                $data[18] = $tesf_logOut;
                $data[19] = $tesf_distance;
                $data[20] = $tesf2_TotalDistance;
                $data[21] = $tesf_FTA;
                $data[22] = $tesf_remark;
                $data[23] = $tesf2_claimstatus;
                $data[24] = $tesf2_claimdate;
                $data[25] = $tesf2_engDA;
                $data[26] = $tesf2_engDAAmount;
                $data[27] = $tesf2_engHotelBillsAmount;
                $data[28] = $tesf2_engOtherBillsAmount;
                $data[29] = $tesf2_engFinalAmount;
                $data[30] = $tesf2_TLApproveDate;
                $data[31] = $tesf2_TLApprovedDA;
                $data[32] = $tesf2_TLApprovedDAAmount;
                $data[33] = $tesf2_TLApprovedHotelBill;
                $data[34] = $tesf2_TLApprovedOtherBill;
                $data[35] = $tesf2_TLApprovedFinalAmount;
                $data[36] = $tesf2_TL_Name;
                $data[37] = $tesf2_TL_ID;
                $data[38] = $tesf2_TLDeductedReason;
                $data[39] = $tesf2_TLDeductedAmount;
                $data[40] = $tesf2_financeApprovedDate;
                $data[41] = $tesf2_financeApprovedDA;
                $data[42] = $tesf2_financeApprovedDAAmount;
                $data[43] = $tesf2_financeApprovedHotelBill;
                $data[44] = $tesf2_financeApprovedOtherBill;
                $data[45] = $tesf2_financeApprovedFinalAmount;
                $data[46] = $tesf2_finance_Name;
                $data[47] = $tesf2_finance_ID;
                $data[48] = $tesf2_financeDeductReason;
                $data[49] = $tesf2_financeDeductAmount;
                $data[50] = $tesf2_rejectReason;
                $data[51] = $tesf2_totalDeductAmount;
                $data[52] = $tesf2_tlOrFinanceRejectedDate;
                $data[53] = $tesf2PaidDate;
                $data[54] = $tesf2PaidBy;



                array_push($cellValueArray, $data);
            }
            $this->bindValuesToExcel($cellValueArray); //2d-array
            $this->saveExcel($filename);
        } else {
            echo "<script>
             alert('no data found');
             window.history.back();
             </script>";
          }
    }

    function bindValuesToExcel($cellValueArray)
    {

        $allEmpIdAndDateArray = array();
        for ($i = 0; $i < count($cellValueArray); $i++) {
            array_push($allEmpIdAndDateArray, $cellValueArray[$i][0] . "+" . $cellValueArray[$i][3]); //merging-cell-based-on ("$cellValueArray[$i][0]"--> empid) and (" $cellValueArray[$i][3])"-->date)
        }
        $this->noOfDuplicateDateCountArray = array_count_values($allEmpIdAndDateArray); // contains no fo duplicate (emp+date) count eg:{ (180291+2020-11-20)=>2 }    ie: 2 is duplicate count.


        $sno = 0;
        $rowIndex = 2;
        $duplicateDateCount = 0;
        $tempDuplicateDateCount = 0;
        for ($loopCount = 0; $loopCount < count($cellValueArray); $loopCount++) {

            $sno++;
            $rowIndex++;
            if ($duplicateDateCount == 0) {
                $duplicateDateCount = $this->getThisDateDuplicateCount($cellValueArray[$loopCount][0] . "+" . $cellValueArray[$loopCount][3]); //function call to get perticular(emp + date) count
                $tempDuplicateDateCount = $duplicateDateCount; //temp
            }

            if ($tempDuplicateDateCount == 1) {
                $this->mergedCells($rowIndex, $cellValueArray, $loopCount, false, $duplicateDateCount);
            } elseif ($tempDuplicateDateCount == $duplicateDateCount) {                                       //eg: duplicateDateCount=3  then  (duplicateDateCount--) upto duplicateDateCount= tempDuplicateDateCount if(equal){ get the duplicateDateCount}
                $this->mergedCells($rowIndex, $cellValueArray, $loopCount, true, $duplicateDateCount);
            }
            $duplicateDateCount--;


            $this->setToRelatedSingleCell("A$rowIndex", $sno); //s.no in execl

            $this->unMergedCells($rowIndex, $cellValueArray, $loopCount); // unmerged cell in excel
        }
    }
    function mergedCells($rowIndex, $rowValueArray, $loopCount, $merge, $duplicateDateCount)
    {
        if ($merge) {
            $lastRowIndex = $rowIndex + ($duplicateDateCount - 1);
            //MERGING CELL
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "B");//EMPID
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "C");//EMP NAME
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "E");//SITE-VISITED- DATE
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "V");//TOTAL DISTANCE
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "Y");//CLAIM STATUS
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "Z");//CLAIM DATE
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AA");//DEPUTATION ALL0WANCES
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AB");//DA-AMOUNT
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AC");//HOTEL BILLS
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AD");//OTHER AMOUNT
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AE");//FINAL BILLS
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AF");//TL APPROVED DATE
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AG");//TL DEPUTATION ALLOWANCES
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AH");//TL DA-AMOUNT
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AI");//APPROVED HOTEL BILLS
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AJ");//APPROVED OTHER BILLS
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AK");//APPROVED FINAL  AMOUNT
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AL");//APPROVED TL
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AM");//TL REASON
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AN");//TL-DEDUCTED REASON
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AO");//FINANCE APPROVED DATE
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AP");//FINANCE  APPROVED DA
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AQ");//FINANCE APPROVED DA-AMOUNT
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AR");//FINANCE APPROVED HOTEL BILLS
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AS");//FINANCE APPROVED OTHER BILLS
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AT");//FINANCE FINAL AMOUNT
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AU");//APPROVED FINANCE NAME AND ID
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AV");//FINANCE REASON
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AW");//FINANCE DEDUCTED AMOUNT
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AX");//PAID DATE
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AY");//PAID DA
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "AZ");//PAID DA-AMOUNT
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "BA");//PAID HOTEL BILLS
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "BB");//PAID OTHER BIILLS
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "BC");//PAID FINAL AMOUNTS
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "BD");//PAID BY
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "BE");//REJECTED DATE
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "BF");//REJECTED REASON
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "BG");//REJECTED BY
            $this->mergeCellINExcel($rowIndex, $lastRowIndex, "BH");//TOTAL DEDUCTED AMOUNT
        }
         // DIFFERENT FIELDS
        $claimStatus = $this->getClaimStatus($rowValueArray[$loopCount][23], $rowIndex, $rowValueArray, $loopCount);
        $this->setToRelatedSingleCell("Y$rowIndex", $claimStatus);

        //COMMON FILEDS
        $this->setToRelatedSingleCell("B$rowIndex", $rowValueArray[$loopCount][0]);
        $this->setToRelatedSingleCell("C$rowIndex", $rowValueArray[$loopCount][1]);//emp-name
        $this->setToRelatedSingleCell("E$rowIndex", $rowValueArray[$loopCount][3]);//site visited date
        $this->setToRelatedSingleCell("V$rowIndex", $rowValueArray[$loopCount][20]);//total distance
        $this->setToRelatedSingleCell("Z$rowIndex", $rowValueArray[$loopCount][24]);//claimdate
        $this->setToRelatedSingleCell("AA$rowIndex", $rowValueArray[$loopCount][25]);//engineer DA
        $this->setToRelatedSingleCell("AB$rowIndex", $rowValueArray[$loopCount][26]);//enginner Da- Amount
        $this->setToRelatedSingleCell("AC$rowIndex", $rowValueArray[$loopCount][27]);//engineer hotel-amount
        $this->setToRelatedSingleCell("AD$rowIndex", $rowValueArray[$loopCount][28]);//enginner other-amount
        $this->setToRelatedSingleCell("AE$rowIndex", $rowValueArray[$loopCount][29]);//engineer final amount
        $this->setToRelatedSingleCell("AM$rowIndex", $rowValueArray[$loopCount][38]); // TLdeducted reason,
        $this->setToRelatedSingleCell("AN$rowIndex", $rowValueArray[$loopCount][39]); // TL deducted amount
        $this->setToRelatedSingleCell("AV$rowIndex", $rowValueArray[$loopCount][48]); // Finance deducted reason,
        $this->setToRelatedSingleCell("AW$rowIndex", $rowValueArray[$loopCount][49]); // Finance deducted amount
        $this->setToRelatedSingleCell("BH$rowIndex", $rowValueArray[$loopCount][51]);// TOTAL DEDUCTED AMOUNT



    }
    function unMergedCells($rowIndex, $rowValueArray, $loopCount)
    {
        $selfyproof = "Yes";
        if (empty($rowValueArray[$loopCount][2])) {
            $selfyproof = "No";
        }
        $this->setToRelatedSingleCell("D$rowIndex", $selfyproof);//self image
        $this->setToRelatedSingleCell("F$rowIndex", $rowValueArray[$loopCount][4]);//user location
        $this->setToRelatedSingleCell("G$rowIndex", $rowValueArray[$loopCount][5]);//user-lat
        $this->setToRelatedSingleCell("H$rowIndex", $rowValueArray[$loopCount][6]);//user-long
        $this->setToRelatedSingleCell("I$rowIndex", $rowValueArray[$loopCount][7]);//site-lat
        $this->setToRelatedSingleCell("J$rowIndex", $rowValueArray[$loopCount][8]);//site-long
        $this->setToRelatedSingleCell("K$rowIndex", $rowValueArray[$loopCount][9]);//site no of the day
        $this->setToRelatedSingleCell("L$rowIndex", $rowValueArray[$loopCount][10]);//siteId
        $this->setToRelatedSingleCell("M$rowIndex", $rowValueArray[$loopCount][11]);//siteName
        $this->setToRelatedSingleCell("N$rowIndex", $rowValueArray[$loopCount][12]);//project
        $this->setToRelatedSingleCell("O$rowIndex", $rowValueArray[$loopCount][13]);//customer
        $this->setToRelatedSingleCell("P$rowIndex", $rowValueArray[$loopCount][14]);//report submission state
        $this->setToRelatedSingleCell("Q$rowIndex", $rowValueArray[$loopCount][15]);//mode of transport
        $this->setToRelatedSingleCell("R$rowIndex", $rowValueArray[$loopCount][16]);//supporting bills
        $this->setToRelatedSingleCell("S$rowIndex", $rowValueArray[$loopCount][17]);//site login
        $this->setToRelatedSingleCell("T$rowIndex", $rowValueArray[$loopCount][18]);//site logout
        $this->setToRelatedSingleCell("U$rowIndex", $rowValueArray[$loopCount][19]);//distance
        $this->setToRelatedSingleCell("W$rowIndex", $rowValueArray[$loopCount][21]);//fta
        $this->setToRelatedSingleCell("X$rowIndex", $rowValueArray[$loopCount][22]);//site remarks
    }

    function getClaimStatus($claimValue, $rowIndex, $rowValueArray, $loopCount)
    {
        //echo $claimValue;
        switch ($claimValue) {
            case null: //NOT AT CLAIMED
                return "NOT AT CLAIMED";
                break;
            case CLAIM_PENDING: //CLAIM-PENDING
                $this->changeTextColor("Y$rowIndex", "ffc107");
                return "CLAIM PENDING";
                break;
            case CLAIM_TL_APPROVED: //TL-APPROVED
                $this->changeTextColor("Y$rowIndex", "007bff");
                $this->setToTLApprovedCellValues($rowIndex, $rowValueArray, $loopCount);
                return "TL APPROVED";
                break;
            case CLAIM_TL_REJECTED: //TL-REJECT
                $this->changeTextColor("Y$rowIndex", "ff0000");
                $this->setToTLRejectedCellValues($rowIndex, $rowValueArray, $loopCount);
                return "REJECTED";
                break;
            case CLAIM_FINANCE_APPROVED: //FINANCE-APPROVED
                $this->changeTextColor("Y$rowIndex", "4b0082");
                $this->setToTLApprovedCellValues($rowIndex, $rowValueArray, $loopCount);
                $this->setToFinanceApprovedCellValues($rowIndex, $rowValueArray, $loopCount);
                return "FINANCE APPROVED";
                break;
            case CLAIM_FINANCE_REJECTED: //FINANCE-REJECTED
                $this->changeTextColor("Y$rowIndex", "ff0000");
                $this->setToTLApprovedCellValues($rowIndex, $rowValueArray, $loopCount);
                $this->setFinanceRejectedCellValues($rowIndex, $rowValueArray, $loopCount);
                return "REJECTED";
            case CLAIM_PAID: //FINANCE-REJECTED
                $this->changeTextColor("Y$rowIndex", "28a745");
                $this->setToTLApprovedCellValues($rowIndex, $rowValueArray, $loopCount);
                $this->setToFinanceApprovedCellValues($rowIndex, $rowValueArray, $loopCount);
                $this->setToPaidCellValues($rowIndex, $rowValueArray, $loopCount);

                return "PAID";
                break;
        }
    }

    function setToTLApprovedCellValues($rowIndex, $rowValueArray, $loopCount)
    {
        $this->setToRelatedSingleCell("AF$rowIndex", $rowValueArray[$loopCount][30]);//TL APPROVED DATE
        $this->setToRelatedSingleCell("AG$rowIndex", $rowValueArray[$loopCount][31]);//TL APPROVED DA
        $this->setToRelatedSingleCell("AH$rowIndex", $rowValueArray[$loopCount][32]);//TL APPROVED DA-AMOUNT
        $this->setToRelatedSingleCell("AI$rowIndex", $rowValueArray[$loopCount][33]);//TL HOTEL BILLS
        $this->setToRelatedSingleCell("AJ$rowIndex", $rowValueArray[$loopCount][34]);//TL OTHER BILLS
        $this->setToRelatedSingleCell("AK$rowIndex", $rowValueArray[$loopCount][35]);//TL FINAL AMOUNT
        $this->setToRelatedSingleCell("AL$rowIndex", $rowValueArray[$loopCount][36] . " " . $rowValueArray[$loopCount][37]);// APPROVED TL NAME AND ID

    }

    function setToTLRejectedCellValues($rowIndex, $rowValueArray, $loopCount)
    {

        $this->setToRelatedSingleCell("BE$rowIndex", $rowValueArray[$loopCount][52]);//REJECTED DATE
        $this->setToRelatedSingleCell("BF$rowIndex", $rowValueArray[$loopCount][50]);// REJECTED REASON
        $this->setToRelatedSingleCell("BG$rowIndex", $rowValueArray[$loopCount][36] . " " . $rowValueArray[$loopCount][37]);//REJECTED BY
    }

    function setToFinanceApprovedCellValues($rowIndex, $rowValueArray, $loopCount)
    {
        $this->setToRelatedSingleCell("AO$rowIndex", $rowValueArray[$loopCount][40]);//FINANCE APPROVED DATE
        $this->setToRelatedSingleCell("AP$rowIndex", $rowValueArray[$loopCount][41]);//FINANCE APPROVED DA
        $this->setToRelatedSingleCell("AQ$rowIndex", $rowValueArray[$loopCount][42]);//FINANCE APPROVED DA-AMOUNT
        $this->setToRelatedSingleCell("AR$rowIndex", $rowValueArray[$loopCount][43]);//FINANCE HOTEL BILLS
        $this->setToRelatedSingleCell("AS$rowIndex", $rowValueArray[$loopCount][44]);//FINANCE OTHER BILLS
        $this->setToRelatedSingleCell("AT$rowIndex", $rowValueArray[$loopCount][45]);//FINANCE FINAL AMOUNT
        $this->setToRelatedSingleCell("AU$rowIndex", $rowValueArray[$loopCount][46] . " " . $rowValueArray[$loopCount][47]);// APPROVED FINANCE NAME AND ID
    }
    function setFinanceRejectedCellValues($rowIndex, $rowValueArray, $loopCount)
    {
        $this->setToRelatedSingleCell("BE$rowIndex", $rowValueArray[$loopCount][52]);//REJECTED DATE
        $this->setToRelatedSingleCell("BF$rowIndex", $rowValueArray[$loopCount][50]);// REJECTED REASON
        $this->setToRelatedSingleCell("BG$rowIndex", $rowValueArray[$loopCount][46] . " " . $rowValueArray[$loopCount][47]);// REJECTED BY

    }
    function setToPaidCellValues($rowIndex, $rowValueArray, $loopCount){
        $this->setToRelatedSingleCell("AX$rowIndex", $rowValueArray[$loopCount][53]);//PAID APPROVED DATE
        $this->setToRelatedSingleCell("AY$rowIndex", $rowValueArray[$loopCount][41]);//PAID APPROVED DA
        $this->setToRelatedSingleCell("AZ$rowIndex", $rowValueArray[$loopCount][42]);//PAID APPROVED DA-AMOUNT
        $this->setToRelatedSingleCell("BA$rowIndex", $rowValueArray[$loopCount][43]);//PAID HOTEL BILLS
        $this->setToRelatedSingleCell("BB$rowIndex", $rowValueArray[$loopCount][44]);//PAID OTHER BILLS
        $this->setToRelatedSingleCell("BC$rowIndex", $rowValueArray[$loopCount][45]);//PAID FINAL AMOUNT
        $this->setToRelatedSingleCell("BD$rowIndex", $rowValueArray[$loopCount][54]);// PAID FINANCE NAME AND ID
    }


    function getThisDateDuplicateCount($EmployeAndDate)
    {
        return $this->noOfDuplicateDateCountArray[$EmployeAndDate]; // returns count (no.of duplicate this date contains)
    }
    function saveExcel($filename)
    {
        $file = PHPExcel_IOFactory::createWriter($this->activeSheet, 'Excel2007');
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //mime type
        header('Content-Disposition: attachment;filename=' . $filename . '.xlsx'); //tell browser what's the file name
        header('Cache-Control: max-age=0'); //no cache
        ob_end_clean();
        $file->save('php://output');
        exit();
    }
}
?>

// $obj = new Excel();
// $obj->fetchData("2020-01-01", "2020-09-22");
