pahelp naman po sa system namin. ang kailangan po kase pag sinelect yung month, yung data ng month na naselect ang maeexport into excel. example kung january ang naselect, dapat data lang ng january ang maexport into excel. ang problema po eh hindi ko alam kung paano gagawin yun. eto po code ko
creditors.php
<?php
session_start();
require("../../database.php");
require_once('../../crgmclass.php');
$users = $crgm->getUsers();
$userdetails = $crgm->get_userdata();
if (isset($userdetails)) {
if ($userdetails['access'] != "crgm") {
header("Location: ../../login.php");
}
} else {
header("Location: ../../login.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Monthly Reports</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="You do not have permission to view the full content of this post. Log in or register now.">
<link rel="stylesheet" href="../crgm2024.css">
<script src="../crgm2024.js"></script>
<!-- Bootstrap JS (jQuery is required) -->
<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
<link href="You do not have permission to view the full content of this post. Log in or register now." rel="stylesheet" />
<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
</head>
<body>
<div id="container">
<button id="toggleBtn" onclick="toggleNav()">☰</button>
<img id="logo" src="../logo.png" alt="Logo">
<div id="header">
<h2 a href="">CRGM Monitoring and Management System</a></h2>
</div>
</div>
<div id="content-container" style="margin-left: 0;">
<div id="sidebar">
<a href="../crgmmain.php">Home</a>
<a href="../dashboard/dashboard.php">Dashboard</a>
<a href="../expenses/expenses.php">Expenses</a>
<a href="../purchase_request/purchase_request.php">Purchase Request</a>
<a href="#">Collections</a>
<div class="submenu">
<a href="../sales/sales.php">Sales</a>
<a href="../ar_collections/account_receivables.php">Account Receivables</a>
</div>
<a href="#">Reports</a>
<div class="submenu">
<a href="creditors.php">Monthly Creditors</a>
<a href="monthly.php">Monthly</a>
<a href="quarterly.php">Quarterly</a>
<a href="annually.php">Annually</a>
</div>
<a href="../../logout.php">Log Out</a>
</div>
<div class="container" style="margin-top: -15px; ">
<center>
<h1><strong>MONTHLY CREDITORS</strong></h1>
</center>
<br>
<div class="row">
<a href="print_pdf.php" class="btn btn-success pull-right"><span class="glyphicon glyphicon-print"></span>
PDF</a>
<a href="../reports/export_excel_creditors.php?month=1" class="btn btn-success pull-right"><span class="glyphicon glyphicon-print"></span>
Excel</a>
</div>
<br>
<select id="selectHatcheryMonth" class="form-select form-control" onchange="filterDataHatchery()">
<option disabled selected>All Months</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<table class="table table-bordered table-striped table-hover">
<thead class="table ">
<tr>
<th>Date</th>
<th>Name of Creditor</th>
<th>Particulars</th>
<th>Purpose</th>
<th>QTY/kg</th>
<th>Total</th>
</tr>
</thead>
<tbody id="monthlyDataHatchery">
<?php
// Example SQL to fetch data for a particular month and year from cash orders
// SELECT * FROM cash_order WHERE MONTH(created_at) = 11 AND YEAR(created_at) = 2023;
$query = "SELECT * FROM credit_order";
$query_run = mysqli_query($conn, $query);
if (mysqli_num_rows($query_run) > 0) {
foreach ($query_run as $data) {
?>
<tr>
<td>
<?= $data['created_at']; ?>
</td>
<td>
<?= $data['fullname']; ?>
</td>
<td>
<?= $data['product_name']; ?>
</td>
<td>
<!-- <?= $data['business_enterprise']; ?> -->
</td>
<td>
<?= $data['quantity']; ?>
</td>
<td>
<?= number_format($data['totalAmount'], 2, '.', ','); ?>
</td>
</tr>
<?php
}
} else {
// echo "<h5> No Record Found </h5>";
}
?>
</tbody>
</table>
</div>
<script>
function filterDataHatchery() {
var selectedHatcheryMonth = document.getElementById("selectHatcheryMonth").value;
$.ajax({
type: "POST",
url: "fetch_monthly_creditors_data.php", // Replace with the actual filename where you put the PHP code
data: { selectedHatcheryMonth: selectedHatcheryMonth },
success: function (response) {
$("#monthlyDataHatchery").html(response);
}
});
}
</script>
<script src="../../script.js"></script>
</body>
</html>
eto po yung kung nasaan yung export button. kung mapapansin nyo po eh may month=1 dun sa button ng excel kase di ko po alam kung pano. pag tinanggal naman po yung month=1, lahat ng data sa lahat ng month ang maeexport.
eto naman po yung code ko sa export_excel_creditors.php na nakalink sa excel button ko
<?php
require_once '../../phpspreadsheet/vendor/autoload.php'; // Adjust the path as needed
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
// Database connection
include_once '../../database.php';
$selectedMonth = isset($_GET['month']) ? intval($_GET['month']) : 0;
// Set the default month to the current month if no month is selected
if ($selectedMonth == 0) {
$selectedMonth = date('n');
}
$query = "SELECT * FROM credit_order WHERE MONTH(created_at) = $selectedMonth";
$query_run = mysqli_query($conn, $query);
// Create the SQL query with the selected month
// $query = "SELECT * FROM credit_order WHERE business_enterprise='Rice Production' AND MONTH(created_at) = $month AND YEAR(created_at) = $year";
// $query_run = mysqli_query($conn, $query);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Date');
$sheet->setCellValue('B1', 'Name of Creditor');
$sheet->setCellValue('C1', 'Particulars');
$sheet->setCellValue('D1', 'Purpose');
$sheet->setCellValue('E1', 'QTY/kg');
$sheet->setCellValue('F1', 'Total');
$row = 2;
if (mysqli_num_rows($query_run) > 0) {
foreach ($query_run as $data) {
$sheet->setCellValue('A' . $row, $data['created_at']);
$sheet->setCellValue('B' . $row, $data['fullname']);
$sheet->setCellValue('C' . $row, $data['product_name']);
$sheet->setCellValue('D' . $row, $data['business_enterprise']);
$sheet->setCellValue('E' . $row, $data['quantity']);
$sheet->setCellValue('F' . $row, number_format($data['totalAmount'], 2, '.', ','));
$row++;
}
}
$writer = new Xlsx($spreadsheet);
$filename = 'monthly_creditors_' . date('Y-m-d') . '.xlsx';
$writer->save($filename);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: max-age=0');
readfile($filename);
unlink($filename);
exit;
?>
sana po matulungan nyo ako
creditors.php
<?php
session_start();
require("../../database.php");
require_once('../../crgmclass.php');
$users = $crgm->getUsers();
$userdetails = $crgm->get_userdata();
if (isset($userdetails)) {
if ($userdetails['access'] != "crgm") {
header("Location: ../../login.php");
}
} else {
header("Location: ../../login.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Monthly Reports</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="You do not have permission to view the full content of this post. Log in or register now.">
<link rel="stylesheet" href="../crgm2024.css">
<script src="../crgm2024.js"></script>
<!-- Bootstrap JS (jQuery is required) -->
<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
<link href="You do not have permission to view the full content of this post. Log in or register now." rel="stylesheet" />
<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
</head>
<body>
<div id="container">
<button id="toggleBtn" onclick="toggleNav()">☰</button>
<img id="logo" src="../logo.png" alt="Logo">
<div id="header">
<h2 a href="">CRGM Monitoring and Management System</a></h2>
</div>
</div>
<div id="content-container" style="margin-left: 0;">
<div id="sidebar">
<a href="../crgmmain.php">Home</a>
<a href="../dashboard/dashboard.php">Dashboard</a>
<a href="../expenses/expenses.php">Expenses</a>
<a href="../purchase_request/purchase_request.php">Purchase Request</a>
<a href="#">Collections</a>
<div class="submenu">
<a href="../sales/sales.php">Sales</a>
<a href="../ar_collections/account_receivables.php">Account Receivables</a>
</div>
<a href="#">Reports</a>
<div class="submenu">
<a href="creditors.php">Monthly Creditors</a>
<a href="monthly.php">Monthly</a>
<a href="quarterly.php">Quarterly</a>
<a href="annually.php">Annually</a>
</div>
<a href="../../logout.php">Log Out</a>
</div>
<div class="container" style="margin-top: -15px; ">
<center>
<h1><strong>MONTHLY CREDITORS</strong></h1>
</center>
<br>
<div class="row">
<a href="print_pdf.php" class="btn btn-success pull-right"><span class="glyphicon glyphicon-print"></span>
PDF</a>
<a href="../reports/export_excel_creditors.php?month=1" class="btn btn-success pull-right"><span class="glyphicon glyphicon-print"></span>
Excel</a>
</div>
<br>
<select id="selectHatcheryMonth" class="form-select form-control" onchange="filterDataHatchery()">
<option disabled selected>All Months</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<table class="table table-bordered table-striped table-hover">
<thead class="table ">
<tr>
<th>Date</th>
<th>Name of Creditor</th>
<th>Particulars</th>
<th>Purpose</th>
<th>QTY/kg</th>
<th>Total</th>
</tr>
</thead>
<tbody id="monthlyDataHatchery">
<?php
// Example SQL to fetch data for a particular month and year from cash orders
// SELECT * FROM cash_order WHERE MONTH(created_at) = 11 AND YEAR(created_at) = 2023;
$query = "SELECT * FROM credit_order";
$query_run = mysqli_query($conn, $query);
if (mysqli_num_rows($query_run) > 0) {
foreach ($query_run as $data) {
?>
<tr>
<td>
<?= $data['created_at']; ?>
</td>
<td>
<?= $data['fullname']; ?>
</td>
<td>
<?= $data['product_name']; ?>
</td>
<td>
<!-- <?= $data['business_enterprise']; ?> -->
</td>
<td>
<?= $data['quantity']; ?>
</td>
<td>
<?= number_format($data['totalAmount'], 2, '.', ','); ?>
</td>
</tr>
<?php
}
} else {
// echo "<h5> No Record Found </h5>";
}
?>
</tbody>
</table>
</div>
<script>
function filterDataHatchery() {
var selectedHatcheryMonth = document.getElementById("selectHatcheryMonth").value;
$.ajax({
type: "POST",
url: "fetch_monthly_creditors_data.php", // Replace with the actual filename where you put the PHP code
data: { selectedHatcheryMonth: selectedHatcheryMonth },
success: function (response) {
$("#monthlyDataHatchery").html(response);
}
});
}
</script>
<script src="../../script.js"></script>
</body>
</html>
eto po yung kung nasaan yung export button. kung mapapansin nyo po eh may month=1 dun sa button ng excel kase di ko po alam kung pano. pag tinanggal naman po yung month=1, lahat ng data sa lahat ng month ang maeexport.
eto naman po yung code ko sa export_excel_creditors.php na nakalink sa excel button ko
<?php
require_once '../../phpspreadsheet/vendor/autoload.php'; // Adjust the path as needed
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
// Database connection
include_once '../../database.php';
$selectedMonth = isset($_GET['month']) ? intval($_GET['month']) : 0;
// Set the default month to the current month if no month is selected
if ($selectedMonth == 0) {
$selectedMonth = date('n');
}
$query = "SELECT * FROM credit_order WHERE MONTH(created_at) = $selectedMonth";
$query_run = mysqli_query($conn, $query);
// Create the SQL query with the selected month
// $query = "SELECT * FROM credit_order WHERE business_enterprise='Rice Production' AND MONTH(created_at) = $month AND YEAR(created_at) = $year";
// $query_run = mysqli_query($conn, $query);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Date');
$sheet->setCellValue('B1', 'Name of Creditor');
$sheet->setCellValue('C1', 'Particulars');
$sheet->setCellValue('D1', 'Purpose');
$sheet->setCellValue('E1', 'QTY/kg');
$sheet->setCellValue('F1', 'Total');
$row = 2;
if (mysqli_num_rows($query_run) > 0) {
foreach ($query_run as $data) {
$sheet->setCellValue('A' . $row, $data['created_at']);
$sheet->setCellValue('B' . $row, $data['fullname']);
$sheet->setCellValue('C' . $row, $data['product_name']);
$sheet->setCellValue('D' . $row, $data['business_enterprise']);
$sheet->setCellValue('E' . $row, $data['quantity']);
$sheet->setCellValue('F' . $row, number_format($data['totalAmount'], 2, '.', ','));
$row++;
}
}
$writer = new Xlsx($spreadsheet);
$filename = 'monthly_creditors_' . date('Y-m-d') . '.xlsx';
$writer->save($filename);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: max-age=0');
readfile($filename);
unlink($filename);
exit;
?>
sana po matulungan nyo ako