File: /home/cafsindia/hrms_allyindian_com/application_bk/controllers/Twentyfour_q_quarterly - Copy.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
require('./application/libraries/PHPSpreadsheet/autoload.php');
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class Twentyfour_q_quarterly extends Action_controller{
public function __construct(){
parent::__construct('twentyfour_q_quarterly');
$this->load->helper('dompdf');
$this->load->library('action_controller');
}// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
$data['key'] = $this->generateKey();
$this->load->view("$this->control_name/manage",$data);
}
public function check_exist($month_type){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Url Expired.. Please refresh the page and try again....','table_data' => ""));
exit(0);
}
$financial_info = $this->get_financial_year();
$fin_set_id = $financial_info[0]->prime_financial_setting_id;
$start_date = $financial_info[0]->start_date;
$end_date = $financial_info[0]->end_date;
$currentYear = date('Y',strtotime($start_date));
$startMonth = $month_type;
$months = [];
for ($i = 0; $i < 3; $i++) {
$month = $startMonth + $i;
$year = $currentYear;
if ($month < 4) {
$year += 1;
}
$monthName = sprintf('%02d', $month) . '-' . $year;
$months[] = $monthName;
}
$month_list = implode('","',$months ?? []);
//check all the 3 months has data
$challan_qry = 'SELECT COUNT(DISTINCT c.process_month) AS month FROM cw_challan_entry c inner join cw_bank on cw_bank.prime_bank_id = c.bank_name WHERE process_month in ("'.$month_list.'") and c.trans_status=1';
$challan_data = $this->db->query("CALL sp_a_run ('SELECT','$challan_qry')");
$challan_rslt = $challan_data->result_array();
$challan_data->next_result();
foreach($challan_rslt as $val){
$month = $val['month'];
}
//Get Sum of Tax Details
$tax_sum_qry ='select sum(cw_transactions.monthly_tds)as monthly_tds,ROUND(SUM(monthly_tds / 104 * 100),0) AS tds_amt from cw_transactions where cw_transactions.trans_status=1 and cw_transactions.process_month in ("'.$month_list.'")';
$tax_sum_data = $this->db->query("CALL sp_a_run ('SELECT','$tax_sum_qry')");
$tax_sum_rslt = $tax_sum_data->result();
$tax_sum_data->next_result();
$tds_amt = $tax_sum_rslt[0]->tds_amt;
//Get Sum of Challan Details
$challan_sum_qry ='select ROUND(sum(tds_amt),0) as challan_amt FROM cw_challan_entry where cw_challan_entry.trans_status=1 and cw_challan_entry.process_month in ("'.$month_list.'")';
$challan_sum_data = $this->db->query("CALL sp_a_run ('SELECT','$challan_sum_qry')");
$challan_sum_rslt = $challan_sum_data->result();
$challan_sum_data->next_result();
$challan_amt = $challan_sum_rslt[0]->challan_amt;
if(!$challan_sum_rslt){
echo json_encode(array('success' => FALSE, 'message' => "No Records Found.!"));
}else
if($challan_amt !== $tds_amt){
echo json_encode(array('success' => FALSE, 'message' => "Challan Amount and TDS Amount are not equal.!($challan_amt != $tds_amt)"));
}else{
echo json_encode(array('success' => TRUE, 'message' => "Generated Successfully..!"));
}
}
public function generate_excel($month_type,$suppress_tax){
$financial_info = $this->get_financial_year();
$fin_set_id = $financial_info[0]->prime_financial_setting_id;
$start_date = $financial_info[0]->start_date;
$end_date = $financial_info[0]->end_date;
$currentYear = date('Y',strtotime($start_date));
$startMonth = $month_type;
$condition = '';
if((int)$suppress_tax === 1){
$condition .= ' AND ch.tot_tax_ded>0 ';
}else if((int)$suppress_tax === 0){
$condition .= '';
}
$months = [];
for ($i = 0; $i < 3; $i++) {
$month = $startMonth + $i;
$year = $currentYear;
if ($month < 4) {
$year += 1;
}
$monthName = sprintf('%02d', $month) . '-' . $year;
$months[] = $monthName;
}
$month_list = implode('","',$months ?? []);
$emp_name_qry = ' SELECT emp_name,c.pan as pan,c.gstin as tan,c.company_name as c_name,c.address as address,c.city AS city,CONCAT(YEAR(f.start_date), "-", YEAR(f.end_date)) AS fin_year,CONCAT(YEAR(f.end_date),"-",YEAR(f.end_date)+1) AS assess_year FROM cw_financial_setting AS f JOIN cw_employees AS e JOIN cw_company_information AS c ON f.incharge_employee = e.employee_code AND c.prime_company_information_id = f.tan_no';
$emp_name_data = $this->db->query("CALL sp_a_run ('SELECT','$emp_name_qry')");
$emp_name_rslt = $emp_name_data->result_array();
$emp_name_data->next_result();
foreach($emp_name_rslt as $val){
$name = $val['emp_name'];
$pan = $val['pan'];
$tan = $val['tan'];
$com_name = $val['c_name'];
$address = $val['address'];
$city = $val['city'];
$fin_year = $val['fin_year'];
$assess_year = $val['assess_year'];
}
$challan_foot_arr = array(1=>"5. Details of salary paid and tax deducted thereon from the Employees ",2=>"Enclose Annexures ,I,II and III",3=>"",4=>"I $name,hereby certify that all the pariculars furnished above are correct and complete.",9=>"Place:",11=>"Date:",13=>"Notes:",14=>"(1) Indicate the type of deductor Government / Others",15=>"(2) Government deductors to give particulars of transfer vouchers; other deductors to give particulars of challan no. regarding deposit into bank.",16=>"(3) Column is relevant only for Government deductors",17=>"(4) Salary includes wages, annuity, pension, gratuity, fees, commission, bonus, repayment of amount deposited",18=>"under the Additional Emoluments (Compulsory Deposit) Act, 1974 or profits in lieu of or in addition to salary or wages,",19=>"including payments made at or in connection with termination of employment advance of salary or any other sums chargeable to income tax under the head 'Salaries'.",20=>"(5) Where an employer deducts from the emoluments paid to an employee or pays on his behalf any",21=>"contributions of that employee to any approved superannuation fund, all such deductions or payments should be included in the statements.",22=>"(6) record on every page totals of each of the columns ");
//Challan wise Data START
$challan_qry = 'SELECT c.tds_amt,c.surcharge_amt,c.edu_cess," " as interest,"" as others,tot_tax_dep,cheque_no,bsr_code,
DATE_FORMAT(c.tax_dep_date, "%d-%m-%Y") as tax_dep_date ,challan_no,IF(book_entry = 1,"Yes","No") as book_entry FROM cw_challan_entry c inner join cw_bank on cw_bank.prime_bank_id = c.bank_name WHERE process_month in ("'.$month_list.'")';
$challan_data = $this->db->query("CALL sp_a_run ('SELECT','$challan_qry')");
$challan_rslt = $challan_data->result();
$challan_data->next_result();
//Challan wise Data END
if($challan_rslt){
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify('./excel_write/24Q_Quarterly.xlsx');
$excel2 = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$excel2 = $excel2->load('./excel_write/24Q_Quarterly.xlsx');//default excel template
//Company Info - START
$excel_sheet = $excel2->setActiveSheetIndex(0);
$excel2->setActiveSheetIndex(0)->setTitle("Company Info");
$excel2->getActiveSheet()->setCellValue("B"."7", "$tan");
$excel2->getActiveSheet()->setCellValue("B"."9", "$pan");
$excel2->getActiveSheet()->setCellValue("B"."11", "$fin_year");
$excel2->getActiveSheet()->setCellValue("B"."14", "$com_name");
$excel2->getActiveSheet()->setCellValue("B"."20", "$address");
$excel2->getActiveSheet()->setCellValue("B"."21", "$city");
$excel2->getActiveSheet()->setCellValue("E"."7", "$assess_year");
//Company Info - END
//Challan Entry - START
$excel_sheet = $excel2->setActiveSheetIndex(1);
$excel2->setActiveSheetIndex(1)->setTitle("Challan Entry");
$high_column = $excel_sheet->getHighestColumn();
$hign_col_num = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($high_column);
$col_arr = array();
for($i=0; $i<$hign_col_num; $i++){
$letter = $this->getNameFromNumber($i);
$col_arr[$i] = $letter;
}
$j = 4;
foreach ($challan_rslt as $key => $row_data){
$x=1;
foreach($row_data as $key => $row_value){
$col_name = $col_arr[$x];
$excel2->getActiveSheet()->getCell("A".$j)->setValue( $j-3).";";
$excel2->getActiveSheet()->getCell($col_name.$j)->setValue("$row_value").";";
$x++;
}
$j++;
}
foreach($challan_foot_arr as $key => $val){
$row = $j+$key;
$excel2->getActiveSheet()->setCellValue("A".$row, $val);
if($key === 3){
$excel2->getActiveSheet()->setCellValue("D".$row, "VERIFICATION");
$excel2->getActiveSheet()->getStyle("D".$row)->getFont()->setBold(true);
}
if($key === 9){
$excel2->getActiveSheet()->setCellValue("E".$row, "Signature of Person responsible for deducting tax at source");
}else
if($key === 11){
$excel2->getActiveSheet()->setCellValue("E".$row, "Name and designation of Person responsible for deducting tax at source");
}
if ($key === 1 || $key === 2 ) {
$excel2->getActiveSheet()->getStyle("A".$row)->getFont()->setBold(true);
}
}
//Challan Entry - END
//Quarter wise Data START
$z = 2;
foreach ($months as $key => $month_val){
$sal_end_date = date("t-m-Y",strtotime("25-".$month_val));
$sheet1_qry = 'SELECT ch.emp_code,e.pan_number,e.emp_name,ch.payment_date,ch.taxable_amt,ch.tds,ch.surcharge_amt,ch.edu_cess,ch.tot_tax_ded,ch.tot_tax_dep,ch.ded_date,DATE_FORMAT(ch.deposit_date, "%d-%m-%Y") as deposit_date FROM cw_challan_entry_line ch INNER JOIN cw_employees e ON e.employee_code = ch.emp_code WHERE ch.process_month = "'.$month_val.'" and e.trans_status = 1 '.$condition.' ';
//Quarter wise Data END
$sheet1_data = $this->db->query("CALL sp_a_run ('SELECT', '$sheet1_qry')");
$sheet1_rslt = $sheet1_data->result_array();
$sheet1_data->next_result();
//Employee Data Entry - START
$excel_sheet = $excel2->setActiveSheetIndex($z);
$excel2->setActiveSheetIndex($z)->setTitle($month_val);
$high_column = $excel_sheet->getHighestColumn();
$hign_col_num = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($high_column);
$col_arr = array();
for($i=0; $i<$hign_col_num; $i++){
$letter = $this->getNameFromNumber($i);
$col_arr[$i] = $letter;
}
$j = 4;
foreach ($sheet1_rslt as $key => $row_data){
$x=1;
foreach($row_data as $key => $row_value){
$col_name = $col_arr[$x];
$excel2->getActiveSheet()->getCell("A".$j)->setValue($j-3).";";
$excel2->getActiveSheet()->getCell($col_name.$j)->setValue("$row_value").";";
$excel2->getActiveSheet()->getCell("E".$j)->setValue($sal_end_date).";";
$excel2->getActiveSheet()->getCell("L".$j)->setValue($sal_end_date).";";
$x++;
}
$j++;
}
//Challan Entry - END
$z++;
}
$excel2->setActiveSheetIndex(0);
$quarter_map = ['04' => 'Q1','07' => 'Q2','10' => 'Q3','01' => 'Q4'];
$quarter_label = isset($quarter_map[$month_type])? $quarter_map[$month_type]: 'QX';
$filename = "24Q_Quarterly_" . $quarter_label . "_" . date('Ymd_His') . ".xls";
$dir = FCPATH . "upload_files/24q/";
if(!is_dir($dir)){
mkdir($dir, 0777, true);
}
$file_path = "upload_files/24q/" . $filename;
$objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($excel2, "Xls");
$objWriter->save(FCPATH . $file_path);
$files = [];
$files[] = ['quarter_month' => $quarter_label,'file_type' => 'xls','file_name' => $filename,'file_path' => base_url($file_path)];
// FVU PACKAGE OF ZIP
$fvu_file = $this->generate_fvu_package($month_type, $months, $condition);
if($fvu_file){
$files[] = $fvu_file;
}
$table_html = $this->create_table($files);
echo json_encode(['success' => true,'message' => '24Q file generated successfully','table_data' => $table_html]);
exit;
}
}
//GET EXCEL COLUMNS FOR NUMBERS
public function getNameFromNumber($num){
$numeric = $num % 26;
$letter = chr(65 + $numeric);
$num2 = intval($num / 26);
if($num2 > 0){
return $this->getNameFromNumber($num2 - 1) . $letter;
}else{
return $letter;
}
}
// CREATE TABLE ON SHOW FRONT _ARN 02-01-2026
public function create_table($files){
$td = '';
foreach($files as $f){
$td .= "<td>
<a class='btn btn-success btn-sm' href='{$f['file_path']}' target='_blank'>
<i class='fa fa-download'></i> Download
</a>
</td>";
}
return "<div class='table-responsive'>
<table class='table table-bordered table-striped nowrap' id='table_info' style='width:100%'>
<thead>
<tr>
<th style='width:80px'>Quarter</th>
<th style='width:80px'>File Type</th>
<th>File Name</th>
<th style='width:140px'>Download 24Q</th>
<th style='width:140px'>Download FVU</th>
</tr>
</thead>
<tbody><tr>
<td>{$files[0]['quarter_month']}</td>
<td>{$files[0]['file_type']}</td>
<td>{$files[0]['file_name']}</td>
$td
</tr>
</tbody>
</table>
</div>";
}
// =============== GENERATE FVU ZIP PACKAGE MAIN FUNCTION =====================
public function generate_fvu_package($month_type, $months, $condition){
$quarter_map = ['04'=>'Q1','07'=>'Q2','10'=>'Q3','01'=>'Q4'];
$quarter = $quarter_map[$month_type] ?? 'QX';
$base_dir = FCPATH . "upload_files/24q/fvu/{$quarter}/";
if(!is_dir($base_dir)){
mkdir($base_dir, 0777, true);
}
$company_info = $this->get_24q_company_info();
$company_info = $company_info[0];
$employee_data = $this->get_24q_employee_data($months, $condition);
if(!$employee_data){
return false;
}
list($record_count, $total_tds) = $this->build_form24q_txt($base_dir, $company_info, $quarter, $employee_data);
$this->build_form24q_fuv($base_dir);
$this->build_form24q_fvu_log($base_dir, $company_info, $quarter, $record_count, $total_tds);
$this->build_form24q_html($base_dir, $company_info, $quarter, $employee_data, $record_count, $total_tds);
$this->build_challan_csi($base_dir, $company_info, $employee_data);
$pdf_filename = $this->build_form24q_pdf($base_dir, $company_info, $quarter, $employee_data, $record_count, $total_tds);
$zip_name = "24Q_FVU_" . $quarter . "_" . date('Ymd_His') . ".zip";
$this->zip_all_files($base_dir, $zip_name);
return ['quarter_month' => $quarter,'file_type' => 'FVU','file_name' => $zip_name,'file_path' => base_url("upload_files/24q/fvu/{$quarter}/{$zip_name}")];
}
// ======================= COMPANY INFORMATION ===========================
public function get_24q_company_info(){
$qry = "SELECT e.emp_name,c.pan,c.gstin AS tan,c.company_name,c.address,c.city,CONCAT(YEAR(f.start_date), '-', YEAR(f.end_date)) AS fin_year FROM cw_financial_setting f JOIN cw_employees e ON e.employee_code = f.incharge_employee
JOIN cw_company_information c ON c.prime_company_information_id = f.tan_no where f.set_as_default_financial_year = 1 and f.trans_status = 1";
$data = $this->db->query($qry);
$rslt = $data->result_array();
$data->next_result();
return $rslt;
}
// ================================= GET EMPLOYEE DATA =====================
public function get_24q_employee_data($months, $condition){
$data = [];
foreach($months as $month){
$qry = "SELECT ch.emp_code,e.emp_name,e.pan_number,ch.taxable_amt,ch.tds,ch.challan_no,ch.deposit_date,b.bsr_code,ch.cheque_no FROM cw_challan_entry_line ch JOIN cw_employees e ON e.employee_code = ch.emp_code JOIN cw_bank b ON b.prime_bank_id = ch.bank_name WHERE ch.process_month = '$month' AND e.trans_status = 1 $condition";
$qry_info = $this->db->query($qry);
$rows = $qry_info->result_array();
$qry_info->next_result();
$data = array_merge($data, $rows);
}
return $data;
}
public function build_form24q_txt($dir, $company, $quarter, $employees){
$lines = [];
$lines[] = "H|24Q|{$company['fin_year']}|{$quarter}|{$company['tan']}|{$company['pan']}|{$company['company_name']}";
$total_tds = 0;
$count = 0;
foreach($employees as $e){
$count++;
$total_tds += $e['tds'];
$date = date('dmY', strtotime($e['deposit_date']));
$lines[] = "D|{$e['emp_code']}|{$e['emp_name']}|{$e['pan_number']}|{$e['taxable_amt']}|{$e['tds']}|{$e['challan_no']}|{$date}";
}
$lines[] = "F|{$count}|{$total_tds}";
file_put_contents($dir . 'form24q.txt', implode(PHP_EOL, $lines));
return [$count, $total_tds];
}
public function build_form24q_fuv($dir){
$txt = file_get_contents($dir . 'form24q.txt');
file_put_contents($dir . 'form24q.fuv', "FVU|SIMULATED\n" . $txt);
}
public function build_form24q_fvu_log($dir, $company, $quarter, $count, $total){
$log = "FVU VALIDATION LOG\n";
$log .= "TAN: {$company['tan']}\n";
$log .= "Quarter: {$quarter}\n";
$log .= "Employees: {$count}\n";
$log .= "Total TDS Amount: {$total}\n";
file_put_contents($dir . 'form24q.fvu.log', $log);
}
public function build_form24q_html($dir, $company, $quarter, $employees, $count, $total){
$rows = '';
foreach ($employees as $e){
$rows .= "
<tr>
<td>{$e['emp_code']}</td>
<td>{$e['emp_name']}</td>
<td>{$e['pan_number']}</td>
<td align='right'>".number_format($e['taxable_amt'],2)."</td>
<td align='right'>".number_format($e['tds'],2)."</td>
</tr>";
}
$html = "
<html><head><style>
body{font-family:Arial;font-size:13px}
table{border-collapse:collapse;width:100%}
th,td{border:1px solid #555;padding:6px}
th{background:#eee}
.text-right{text-align:right}
.text-center{text-align:center}
.page-break{page-break-after:always}
.signature{margin-top:40px}
.footer{font-size:8pt;margin-top:30px;text-align:center}
</style></head><body>
<h3>Form 24Q Summary</h3>
<table>
<tr><td>TAN</td><td>{$company['tan']}</td></tr>
<tr><td>Company</td><td>{$company['company_name']}</td></tr>
<tr><td>Financial Year</td><td>{$company['fin_year']}</td></tr>
<tr><td>Quarter</td><td>{$quarter}</td></tr>
<tr><td>No. of Employees</td><td>{$count}</td></tr>
<tr><td>Total TDS</td><td>".number_format($total,2)."</td></tr>
</table>
<h4>Employee Details</h4>
<table>
<tr><th>Emp Code</th><th>Name</th><th>PAN</th><th>Income</th><th>TDS</th></tr>
{$rows}
</table>
</body></html>";
file_put_contents($dir . 'form24q.html', $html);
}
public function build_challan_csi($dir, $company, $employees){
$lines[] = "# CSI FILE";
foreach ($employees as $e){
$date = date('dmY', strtotime($e['deposit_date']));
$lines[] = "{$company['tan']}|{$e['bsr_code']}|{$e['challan_no']}|{$date}|{$e['tds']}";
}
file_put_contents($dir . 'challan.csi', implode(PHP_EOL, $lines));
}
public function build_form24q_pdf($dir, $company, $quarter, $employees, $count, $total) {
$html = '<!DOCTYPE html>
<html>
<head>
<title>Form 24Q - ' . $quarter . ' ' . $company['fin_year'] . '</title>
<style>
body { font-family: Arial, sans-serif; font-size: 10pt; }
.header { text-align: center; margin-bottom: 20px; }
.company-name { font-size: 14pt; font-weight: bold; }
.form-title { font-size: 12pt; font-weight: bold; text-decoration: underline; margin: 10px 0; }
.section { margin: 15px 0; }
.section-title { font-weight: bold; margin: 10px 0; }
table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 9pt; }
th, td { border: 1px solid #000; padding: 5px; text-align: left; }
th { background-color: #f2f2f2; text-align: center; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.page-break { page-break-after: always; }
.signature { margin-top: 40px; }
.footer { font-size: 8pt; margin-top: 30px; text-align: center; }
</style>
</head>
<body>
<div class="header">
<div class="company-name">' . htmlspecialchars($company['company_name']) . '</div>
<div>' . htmlspecialchars($company['address']) . ', ' . htmlspecialchars($company['city']) . '</div>
<div class="form-title">FORM NO. 24Q</div>
<div>Quarter: ' . $quarter . ' | Financial Year: ' . $company['fin_year'] . '</div>
<div>TAN: ' . htmlspecialchars($company['tan']) . ' | PAN: ' . htmlspecialchars($company['pan']) . '</div>
</div>
<div class="section">
<div class="section-title">Summary</div>
<table>
<tr>
<td width="70%">Total Number of Employees</td>
<td class="text-right">' . $count . '</td>
</tr>
<tr>
<td>Total TDS Amount</td>
<td class="text-right">' . number_format($total, 2) . '</td>
</tr>
</table>
</div>
<div class="section">
<div class="section-title">Employee Details</div>
<table>
<thead>
<tr>
<th width="10%">Emp Code</th>
<th width="30%">Employee Name</th>
<th width="15%">PAN</th>
<th width="20%" class="text-right">Taxable Amount</th>
<th width="15%" class="text-right">TDS</th>
<th width="10%">Challan No</th>
</tr>
</thead>
<tbody>';
foreach ($employees as $emp) {
$html .= '<tr>
<td>' . htmlspecialchars($emp['emp_code']) . '</td>
<td>' . htmlspecialchars($emp['emp_name']) . '</td>
<td>' . htmlspecialchars($emp['pan_number']) . '</td>
<td class="text-right">' . number_format($emp['taxable_amt'], 2) . '</td>
<td class="text-right">' . number_format($emp['tds'], 2) . '</td>
<td>' . htmlspecialchars($emp['challan_no']) . '</td>
</tr>';
}
$html .= ' </tbody>
</table>
</div>
<div class="signature">
<div style="float: right; width: 200px; text-align: center;">
<div style="border-top: 1px solid #000; width: 150px; margin: 0 auto; padding-top: 5px;">
Authorized Signatory
</div>
</div>
<div style="clear: both;"></div>
</div>
<div class="footer">
Generated on: ' . date('d-M-Y H:i:s') . ' | ' . $company['company_name'] . ' | Page {PAGENO}
</div>
</body>
</html>';
// Generate PDF filename using the required format: 27A_DELD11360G_24Q_Q2_202526.pdf
$fin_year = $company['fin_year'] ?? ''; // Handle null case
$financial_year = str_replace('-', '', $fin_year);
$pdf_filename = $company['pan'] . '_24Q_' . $quarter . '_' . $financial_year . '.pdf';
$pdf_path = $dir . $pdf_filename;
// Generate PDF using common_generate_pdf from parent Action_controller
$this->common_generate_pdf(
addslashes($html), // HTML content
$dir, // Output directory
$pdf_filename, // Output filename
'portrait', // Page orientation
'A4', // Paper size
'0', // PDF password protection (0 = no password)
'' // Password (empty if no password)
);
return $pdf_filename;
}
public function zip_all_files($dir, $zip_name){
$zip = new ZipArchive();
$zip_path = $dir . $zip_name;
if($zip->open($zip_path, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE){
return false;
}
foreach(glob($dir . "*") as $file){
if(!is_file($file)){
continue;
}
if(pathinfo($file, PATHINFO_EXTENSION) === 'zip'){
continue;
}
$zip->addFile($file, basename($file));
}
$zip->close();
/* ===== DELETE INDIVIDUAL FILES ===== */
foreach(glob($dir . "*") as $file){
if(!is_file($file)){
continue;
}
if(basename($file) === $zip_name){
continue;
}
unlink($file);
}
return true;
}
}
?>