Skip to content

Commit

Permalink
modifications on sales report/snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
Emm-Anuel100 committed Apr 10, 2024
1 parent d1bf670 commit f0fd98a
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 24 deletions.
6 changes: 5 additions & 1 deletion cashier_login/cashier_login.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@
$_SESSION['cashier_id'] = $cashier_id;
$_SESSION['cashier_name'] = $cashier_name;
## Redirect to cart page
header("Location: ../cart.php");
?>
<script>
window.location.href = "../cart.php";
</script>
<?php
exit();
} else {
## Incorrect cashier ID
Expand Down
16 changes: 16 additions & 0 deletions conn.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,20 @@
die ("CONNECTION ERROR:" .$conn->connect_error);
}




// $HOST = "localhost";
// $USERNAME = "id22025454_pos_userdb";
// $PASSWORD = "Pos12345@";
// $DB = "id22025454_pos_database";

// $conn = new mysqli("$HOST","$USERNAME","$PASSWORD","$DB");

// ## if error in connection
// if ($conn->connect_error) {
// # code...
// die ("CONNECTION ERROR:" .$conn->connect_error);
// }

?>
8 changes: 8 additions & 0 deletions generate_report/generate_sales_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
(YEAR < '$end_year' OR (YEAR = '$end_year' AND MONTH < '$end_month') OR (YEAR = '$end_year' AND MONTH = '$end_month' AND DAY <= '$end_day'))");

if (mysqli_num_rows($result_sales) > 0) {
$total_naira = 0; ## Initialize total naira
while ($row = mysqli_fetch_assoc($result_sales)) {
$total_naira += $row['total_naira']; ## Add current row's total_naira to total_naira
}

echo "<h4 class='report-title'>Total Revenue: <b style='color: rgb(172, 172, 247)'> ₦ " . number_format($total_naira, 2) . "</b></h4><br/><br/>";

$output = "<h5 class='report-title'>Sales Report from $start_date to $end_date</h5><br/><br/>";
$output .= "<table>
<tr>
Expand All @@ -48,6 +55,7 @@
<th>Date</th>
</tr>";
$i = 1;
mysqli_data_seek($result_sales, 0); ## Reset the result pointer to start from the beginning
while ($row = mysqli_fetch_assoc($result_sales)) {
$output .= "<tr>";
$output .= "<td>" . $i . "</td>";
Expand Down
5 changes: 3 additions & 2 deletions iamadmin/admin_home.php
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,6 @@ function exportSalesReport(format) {


<?php

## adding of distributor starts here
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["distributor_name"]) && isset($_POST["distributor_address"]) && isset($_POST["distributor_reg_no"])) {
## initialise vars...
Expand Down Expand Up @@ -1493,7 +1492,9 @@ function exportSalesReport(format) {

if ($result_insert_udo) {
echo '
<script>alert("Product quantity updated and UDO record inserted successfully.!")</script>
<script>alert("Product quantity updated and UDO record inserted successfully!");
window.location.href = "./admin_home.php";
</script>
';
} else {
echo "Error inserting UDO list: " . mysqli_error($conn);
Expand Down
7 changes: 6 additions & 1 deletion iamadmin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@
## Password is correct, set session variables and redirect to dashboard
$_SESSION['admin_id'] = $id;
$_SESSION['admin_username'] = $db_username;
header("Location: ./admin_home.php");
## redirect to admin home page
?>
<script>
window.location.href = "./admin_home.php";
</script>
<?php
exit();
} else {
echo('
Expand Down
6 changes: 0 additions & 6 deletions receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,15 @@
margin-bottom: 5px;
text-transform: uppercase;
}

.address {
font-size: 10px;
line-height: 14px;
}

.trans-id {
font-size: 10px;
margin-top: 5px;
margin-bottom: 5px;
}

.header, .items {
display: flex;
justify-content: space-between;
Expand All @@ -106,17 +103,14 @@
margin-bottom: 3px;
font-size: 10px;
}

.header div:nth-child(1) {
width: 30px; /* Width for quantity column */
text-align: left;
}

.header div:nth-child(2) {
width: 140px; /* Width for description column */
text-align: left;
}

.header div:nth-child(3),
.items div:nth-child(3),
.items div:nth-child(4) {
Expand Down
26 changes: 21 additions & 5 deletions sales_report_export/export_csv.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
## Require connection file
require_once('../conn.php');

$start_year = $_GET['start_year'];
Expand All @@ -12,11 +13,23 @@
(YEAR > '$start_year' OR (YEAR = '$start_year' AND MONTH > '$start_month') OR (YEAR = '$start_year' AND MONTH = '$start_month' AND DAY >= '$start_day')) AND
(YEAR < '$end_year' OR (YEAR = '$end_year' AND MONTH < '$end_month') OR (YEAR = '$end_year' AND MONTH = '$end_month' AND DAY <= '$end_day'))");

if (mysqli_num_rows($result_sales) > 0) {
if (mysqli_num_rows($result_sales) > 0) {
## Initialize an array to store the fetched data
$sales_data = [];

## Calculate total revenue
$total_naira = 0;

## Fetch data and store it in the array
while ($row = mysqli_fetch_assoc($result_sales)) {
$sales_data[] = $row;
$total_naira += $row['total_naira'];
}

## Set headers for CSV file download
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="sales_report.csv"');

## Open file handle to write CSV data
$output = fopen('php://output', 'w');

Expand All @@ -25,7 +38,7 @@

## Fetch and write data rows to CSV file
$i = 1;
while ($row = mysqli_fetch_assoc($result_sales)) {
foreach ($sales_data as $row) {
## Format data for CSV
$csv_data = array(
$i++,
Expand All @@ -41,9 +54,12 @@
fputcsv($output, $csv_data);
}

## Add row for total revenue
fputcsv($output, array('Total Revenue', '', '', '', "" . number_format($total_naira, 2), '', ''));

## Close file handle
fclose($output);
} else {
} else {
echo "No sales data found." . '<br/><br/> <a href="../iamadmin/admin_home.php">go back</a>';
}
}
?>
15 changes: 14 additions & 1 deletion sales_report_export/export_pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,27 @@
(YEAR < '$end_year' OR (YEAR = '$end_year' AND MONTH < '$end_month') OR (YEAR = '$end_year' AND MONTH = '$end_month' AND DAY <= '$end_day'))");

if (mysqli_num_rows($result_sales) > 0) {
## Calculate total revenue
$total_naira = 0;
while ($row = mysqli_fetch_assoc($result_sales)) {
$total_naira += $row['total_naira'];
}

$pdf = new FPDF('P', 'mm', array(380, 340));
$pdf->AddPage();

## Title
$pdf->SetFont('Arial', 'B', 18); ## Set font size to 18px with bold
$pdf->Cell(0, 10, 'Sales Report', 0, 1, 'C');

## Subtitle with start and end dates
$pdf->SetFont('Arial', 'B', 12); ## Set font size to 12px with bold
$pdf->Cell(0, 10, 'From: ' . $start_year . '-' . $start_month . '-' . $start_day . ' To: ' . $end_year . '-' . $end_month . '-' . $end_day, 0, 1, 'C');

## Display total revenue as a title at the center of the page
$pdf->SetFont('Arial', 'B', 15); ## Set font size to 15px with bold
$pdf->Cell(0, 10, 'Total Revenue: ₦' . number_format($total_naira, 2), 0, 1, 'C');

$pdf->Ln(10);
$pdf->SetFont('Arial', '', 12); ## Set font size to 12px without bold
$pdf->Cell(40, 10, 'S/N', 1);
Expand All @@ -37,6 +49,7 @@
$pdf->Ln();

$i = 1;
mysqli_data_seek($result_sales, 0); ## Reset result pointer
while ($row = mysqli_fetch_assoc($result_sales)) {
$pdf->Cell(40, 10, $i++, 1);

Expand Down
20 changes: 16 additions & 4 deletions sales_snapshot_export/export_csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
$num_rows = mysqli_num_rows($result_infor);

if ($num_rows > 0) {
## Set CSV headers
## Initialize total naira
$total_naira = 0;

## Set filename with date
$filename = "sales_snapshot_$year-$month-$day.csv";

## Set CSV headers with filename
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="sales_snapshot.csv"');
header("Content-Disposition: attachment; filename=\"$filename\"");

## Open file handle for output
$output = fopen('php://output', 'w');
Expand All @@ -36,11 +42,17 @@
$row['payment_mode'],
$row["cashier"]
));

## Sum up total naira
$total_naira += $row['total_naira'];
}

## Add row for total naira
fputcsv($output, array('', '', 'Total Naira: ₦' . number_format($total_naira, 2), '', '', ''));

## Close file handle
fclose($output);
} else {
echo "No data found." . '<br/><br/> <a href="../iamadmin/admin_home.php">go back</a>';
echo "No data found." . '<br/><br/> <a href="../iamadmin/admin_home.php">go back</a>';
}
?>
?>
25 changes: 21 additions & 4 deletions sales_snapshot_export/export_pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
$num_rows = mysqli_num_rows($result_infor);

if ($num_rows > 0) {
## Initialize total naira
$total_naira = 0;

## Create new PDF instance
$pdf = new FPDF('P', 'mm', array(350, 330));
$pdf->AddPage();
Expand All @@ -32,7 +35,7 @@
## Add table header
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(40, 10, 'S/N', 1);
$pdf->Cell(80, 10, 'Product Info', 1); // Increase width for product_info
$pdf->Cell(80, 10, 'Product Info', 1); ## Increase width for product_info
$pdf->Cell(40, 10, 'Sub-total', 1);
$pdf->Cell(40, 10, 'Transaction ID', 1);
$pdf->Cell(40, 10, 'Payment Mode', 1);
Expand Down Expand Up @@ -68,11 +71,25 @@
$pdf->Cell(40, 10, $row['cashier'], 1); ## Cashier

$pdf->Ln(); ## Move to the next row

## Add total naira
$total_naira += $row['total_naira'];
}

## Output PDF
$pdf->Output('sales_snapshot.pdf', 'I'); ## 'I' for inline view
} else {
## Add space before displaying total naira
$pdf->Ln(10);

## Add Total Revenue at the bottom of page
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(0, 10, 'Total Revenue: ₦' . number_format($total_naira, 2), 0, 1, 'C');
$pdf->Ln(10);

## Set filename with date
$filename = "sales_snapshot_$year-$month-$day.pdf";

## Output PDF with filename
$pdf->Output($filename, 'I'); ## 'I' for inline view
} else {
echo "No data found." . '<br/><br/> <a href="../iamadmin/admin_home.php">go back</a>';
}
?>

0 comments on commit f0fd98a

Please sign in to comment.