$row = 5;
    $oldDate = "";
    $srow = 5;
    $erow = 5;
    if($itemOBJ ->rowCount() > 0){   
        foreach($itemRES as $prow){    
            if($prow['incDate'] != $oldDate){ 
                if($row != 5) {
                    $srow = $row - 1;
                    $erow = $row;

                    //echo $colGrand . $row, "=SUM(T".$srow.":T". $erow .")";

                    $spreadsheet->getActiveSheet()->setCellValue($colGrand . $row, "=SUM(T".$srow.":T". $erow .")"); 
                    //$spreadsheet->getActiveSheet()->getStyle($colGrand . $row)->getNumberFormat()->setFormatCode('#,##0.00');  
                }

                $row++;
                $dateTime = new DateTime($oldDate);
                $formattedDate = $dateTime->format('M d, Y');
                $spreadsheet->getActiveSheet()->setCellValue('A'. $row, $formattedDate); 
                $oldDate = $prow['incDate'];
            }   
            
            $spreadsheet->getActiveSheet()->setCellValue('B'. $row, $prow['itemName']); 
            $spreadsheet->getActiveSheet()->setCellValue('C'. $row, $prow['sck']); 
            $spreadsheet->getActiveSheet()->setCellValue('D'. $row, $prow['weight']); 
            $spreadsheet->getActiveSheet()->setCellValue('E'. $row, $prow['ded']); 
            $spreadsheet->getActiveSheet()->setCellValue('F'. $row, $prow['net']); 
            $spreadsheet->getActiveSheet()->setCellValue('G'. $row, $prow['priceKG']);

            $range = 'C' . $row . ':G' . $row;
            $spreadsheet->getActiveSheet()->getStyle($range)->getNumberFormat()->setFormatCode('#,##0.00');
               
            if (in_array($prow['itemName'], $item)) {
                $val = array_search($prow['itemName'], $item); // Get the index of the item
                $col = numberToColumnLetter($cell[$val]); 
                $spreadsheet->getActiveSheet()->setCellValue($col . $row, $prow['totalAmt']);  
            } elseif ($prow['itemName'] == "LOAN ADVANCES") {
                $col = numberToColumnLetter($advances);  
                $spreadsheet->getActiveSheet()->setCellValue($col . $row, $prow['totalAmt']); 
            } else {
                $col = numberToColumnLetter($general); 
                $spreadsheet->getActiveSheet()->setCellValue($col . $row, $prow['totalAmt']); 
            }
              
            $colTotal = numberToColumnLetter($total); 
            $sum = numberToColumnLetter($total - 1);
            
            //$spreadsheet->getActiveSheet()->setCellValue($colTotal . $row, "=SUM(H".$row.":". $sum. $row.")"); 

            //$spreadsheet->getActiveSheet()->setCellValue($colTotal . $row, $prow['totalAmt']); 
            $spreadsheet->getActiveSheet()->setCellValue("T" . $row, 0); 
            $colGrand = numberToColumnLetter($grand); 

            // $spreadsheet->getActiveSheet()->getStyle($col . $row)->getNumberFormat()->setFormatCode('#,##0.00'); 
            // $spreadsheet->getActiveSheet()->getStyle($colTotal . $row)->getNumberFormat()->setFormatCode('#,##0.00');   
            
            $row++;
        }
    }   