Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97274f3635 |
18
assets/css/custom.css
Normal file
18
assets/css/custom.css
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
body {
|
||||
font-family: 'Inter', sans-serif;
|
||||
background-color: #F8F9FA;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.header-gradient {
|
||||
background: linear-gradient(90deg, #0d6efd 0%, #0d6efd 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
font-weight: 500;
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
// Generated by setup_mariadb_project.sh — edit as needed.
|
||||
define('DB_HOST', '127.0.0.1');
|
||||
define('DB_NAME', 'app_35786');
|
||||
define('DB_NAME', 'dbmaster');
|
||||
define('DB_USER', 'app_35786');
|
||||
define('DB_PASS', '4caf095d-493c-43bd-bfec-762cae9c6aab');
|
||||
|
||||
|
||||
10
footer.php
Normal file
10
footer.php
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
</main>
|
||||
|
||||
<footer class="container mt-4 text-center text-muted">
|
||||
<p>© <?php echo date("Y"); ?> vipanalisa. Built with Flatlogic. | <a href="public.php" target="_blank">View Public Report</a></p>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
45
header.php
Normal file
45
header.php
Normal file
@ -0,0 +1,45 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>vipanalisa</title>
|
||||
<meta name="description" content="Built with Flatlogic Generator">
|
||||
<meta name="keywords" content="sales analysis, php mysql, data analytics, sales dashboard, business intelligence, data visualization, flatlogic">
|
||||
<meta property="og:title" content="vipanalisa">
|
||||
<meta property="og:description" content="Built with Flatlogic Generator">
|
||||
<meta property="og:image" content="">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark header-gradient shadow-sm mb-4">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">vipanalisa</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?php echo (basename($_SERVER['PHP_SELF']) == 'index.php') ? 'active' : ''; ?>" href="index.php">Analisa per Merk</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?php echo (basename($_SERVER['PHP_SELF']) == 'sales_analysis.php') ? 'active' : ''; ?>" href="sales_analysis.php">Analisa per Sales</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?php echo (basename($_SERVER['PHP_SELF']) == 'import.php') ? 'active' : ''; ?>" href="import.php">Import Data</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
124
import.php
Normal file
124
import.php
Normal file
@ -0,0 +1,124 @@
|
||||
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
$error_message = null;
|
||||
$import_summary = null;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) {
|
||||
if ($_FILES['csv_file']['error'] == UPLOAD_ERR_OK && is_uploaded_file($_FILES['csv_file']['tmp_name'])) {
|
||||
$file = $_FILES['csv_file']['tmp_name'];
|
||||
|
||||
$pdo = db();
|
||||
$pdo->beginTransaction();
|
||||
|
||||
$success_count = 0;
|
||||
$error_count = 0;
|
||||
$errors = [];
|
||||
|
||||
try {
|
||||
$handle = fopen($file, "r");
|
||||
$header = fgetcsv($handle, 1000, ","); // Read header row
|
||||
|
||||
// Prepare statement for checking duplicates
|
||||
$check_stmt = $pdo->prepare("SELECT COUNT(*) FROM tabelmaster WHERE NO_FAKTUR = ? AND NAMA_SALES = ? AND TANGGAL = ?");
|
||||
|
||||
// Prepare statement for insertion
|
||||
$insert_stmt = $pdo->prepare("INSERT INTO tabelmaster (NAMA_SALES, TANGGAL, NO_FAKTUR, MERK, OUTLET, PRODUK, QTY, HARGA, BULAN, TAHUN, PERIODE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
$row_number = 1;
|
||||
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
|
||||
$row_number++;
|
||||
if (count($data) !== 11) {
|
||||
$errors[] = "Row {$row_number}: Invalid column count.";
|
||||
$error_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Assign variables from CSV data
|
||||
list($nama_sales, $tanggal, $no_faktur, $merk, $outlet, $produk, $qty, $harga, $bulan, $tahun, $periode) = $data;
|
||||
|
||||
// Basic Validation
|
||||
$check_stmt->execute([$no_faktur, $nama_sales, $tanggal]);
|
||||
if ($check_stmt->fetchColumn() > 0) {
|
||||
$errors[] = "Row {$row_number}: Duplicate record found for NO_FAKTUR {$no_faktur}, NAMA_SALES {$nama_sales}, TANGGAL {$tanggal}.";
|
||||
$error_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Data Normalization
|
||||
$harga_numeric = str_replace(['Rp', '.', ','], '', $harga);
|
||||
|
||||
// Insert data
|
||||
$insert_stmt->execute([
|
||||
$nama_sales, $tanggal, $no_faktur, $merk, $outlet, $produk,
|
||||
(int)$qty, $harga_numeric, (int)$bulan, (int)$tahun, $periode
|
||||
]);
|
||||
|
||||
$success_count++;
|
||||
}
|
||||
fclose($handle);
|
||||
|
||||
$pdo->commit();
|
||||
$import_summary = ['success' => $success_count, 'errors' => $error_count, 'error_details' => $errors];
|
||||
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
$error_message = "An error occurred during import: " . $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$error_message = "File upload failed. Please try again.";
|
||||
}
|
||||
}
|
||||
|
||||
require_once 'header.php';
|
||||
?>
|
||||
|
||||
<main class="container">
|
||||
<?php if (isset($error_message)): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo htmlspecialchars($error_message); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (isset($import_summary)): ?>
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">Import Summary</div>
|
||||
<div class="card-body">
|
||||
<p class="text-success">Successfully imported <strong><?php echo $import_summary['success']; ?></strong> records.</p>
|
||||
<p class="text-danger">Failed to import <strong><?php echo $import_summary['errors']; ?></strong> records.</p>
|
||||
<?php if (!empty($import_summary['error_details'])): ?>
|
||||
<hr>
|
||||
<h5>Error Details:</h5>
|
||||
<ul class="list-group">
|
||||
<?php foreach ($import_summary['error_details'] as $error): ?>
|
||||
<li class="list-group-item list-group-item-danger">- <?php echo htmlspecialchars($error); ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Import Data from CSV
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="import.php" enctype="multipart/form-data">
|
||||
<div class="mb-3">
|
||||
<label for="csv_file" class="form-label">Select CSV File</label>
|
||||
<input class="form-control" type="file" id="csv_file" name="csv_file" accept=".csv" required>
|
||||
</div>
|
||||
<div class="alert alert-info">
|
||||
<strong>CSV Format:</strong> The file must have 11 columns in the following order: <br>
|
||||
<code>NAMA_SALES, TANGGAL, NO_FAKTUR, MERK, OUTLET, PRODUK, QTY, HARGA, BULAN, TAHUN, PERIODE</code>
|
||||
<br>The first row should be the header and will be skipped.
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Upload and Import</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php require_once 'footer.php'; ?>
|
||||
435
index.php
435
index.php
@ -1,150 +1,291 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
require_once 'db/config.php';
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$error_message = null;
|
||||
$records = [];
|
||||
$total_pages = 1;
|
||||
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||
$limit = 20; // Records per page for raw data table
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
// Get distinct values for filters
|
||||
$sales_options_stmt = $pdo->query('SELECT DISTINCT NAMA_SALES FROM tabelmaster WHERE NAMA_SALES IS NOT NULL AND NAMA_SALES != "" ORDER BY NAMA_SALES');
|
||||
$sales_options = $sales_options_stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
$periode_options_stmt = $pdo->query('SELECT DISTINCT PERIODE FROM tabelmaster WHERE PERIODE IS NOT NULL AND PERIODE != "" ORDER BY PERIODE DESC');
|
||||
$periode_options = $periode_options_stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
// Handle form submission for analysis
|
||||
$analysis_results = [];
|
||||
$chart_labels_json = '[]';
|
||||
$chart_data_json = '[]';
|
||||
$selected_sales = $_POST['nama_sales'] ?? 'all';
|
||||
$selected_periode = $_POST['periode'] ?? 'all';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['run_analysis'])) {
|
||||
$sql = "
|
||||
SELECT
|
||||
MERK,
|
||||
SUM(QTY) as total_qty,
|
||||
SUM(QTY * CAST(REPLACE(HARGA, ",", "") AS DECIMAL(15,2))) as total_omzet,
|
||||
AVG(CAST(REPLACE(HARGA, ",", "") AS DECIMAL(15,2))) as avg_price,
|
||||
COUNT(DISTINCT NO_FAKTUR) as transactions_count
|
||||
FROM
|
||||
tabelmaster
|
||||
WHERE 1=1";
|
||||
|
||||
$params = [];
|
||||
if ($selected_sales !== 'all') {
|
||||
$sql .= ' AND NAMA_SALES = :nama_sales';
|
||||
$params[':nama_sales'] = $selected_sales;
|
||||
}
|
||||
if ($selected_periode !== 'all') {
|
||||
$sql .= ' AND PERIODE = :periode';
|
||||
$params[':periode'] = $selected_periode;
|
||||
}
|
||||
|
||||
$sql .= ' GROUP BY MERK HAVING SUM(QTY) > 0 ORDER BY total_omzet DESC';
|
||||
|
||||
$analysis_stmt = $pdo->prepare($sql);
|
||||
$analysis_stmt->execute($params);
|
||||
$analysis_results = $analysis_stmt->fetchAll();
|
||||
|
||||
if (!empty($analysis_results)) {
|
||||
$chart_labels = [];
|
||||
$chart_data = [];
|
||||
foreach ($analysis_results as $row) {
|
||||
$chart_labels[] = $row['MERK'];
|
||||
$chart_data[] = $row['total_omzet'];
|
||||
}
|
||||
$chart_labels_json = json_encode($chart_labels);
|
||||
$chart_data_json = json_encode($chart_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get total records for raw data pagination
|
||||
$total_stmt = $pdo->query('SELECT COUNT(*) FROM tabelmaster');
|
||||
$total_records = $total_stmt->fetchColumn();
|
||||
$total_pages = ceil($total_records / $limit);
|
||||
|
||||
// Fetch records for the current page of raw data
|
||||
$stmt = $pdo->prepare('SELECT * FROM tabelmaster ORDER BY TANGGAL DESC, NO_FAKTUR DESC LIMIT :limit OFFSET :offset');
|
||||
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$records = $stmt->fetchAll();
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$error_message = "Database error: " . $e->getMessage();
|
||||
}
|
||||
|
||||
require_once 'header.php';
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<main class="container">
|
||||
<?php if (isset($error_message)): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo htmlspecialchars($error_message); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Analysis Form -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
Analisa Penjualan per Merk
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="index.php#analysis-results">
|
||||
<div class="row g-3 align-items-end">
|
||||
<div class="col-md-5">
|
||||
<label for="nama_sales" class="form-label">Nama Sales</label>
|
||||
<select name="nama_sales" id="nama_sales" class="form-select">
|
||||
<option value="all">Semua Sales</option>
|
||||
<?php foreach ($sales_options as $sales): ?>
|
||||
<option value="<?php echo htmlspecialchars($sales); ?>" <?php echo ($selected_sales === $sales) ? 'selected' : ''; ?> >
|
||||
<?php echo htmlspecialchars($sales); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<label for="periode" class="form-label">Periode</label>
|
||||
<select name="periode" id="periode" class="form-select">
|
||||
<option value="all">Semua Periode</option>
|
||||
<?php foreach ($periode_options as $periode): ?>
|
||||
<option value="<?php echo htmlspecialchars($periode); ?>" <?php echo ($selected_periode === $periode) ? 'selected' : ''; ?> >
|
||||
<?php echo htmlspecialchars($periode); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="submit" name="run_analysis" class="btn btn-primary w-100">Jalankan</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Analysis Results -->
|
||||
<?php if (!empty($analysis_results)): ?>
|
||||
<div class="card mb-4" id="analysis-results">
|
||||
<div class="card-header">
|
||||
Hasil Analisa
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Merk</th>
|
||||
<th>Total Kuantitas</th>
|
||||
<th>Total Omzet</th>
|
||||
<th>Harga Rata-rata</th>
|
||||
<th>Jumlah Transaksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($analysis_results as $row): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($row['MERK']); ?></td>
|
||||
<td><?php echo number_format($row['total_qty']); ?></td>
|
||||
<td>Rp <?php echo number_format($row['total_omzet'], 2, ",", "."); ?></td>
|
||||
<td>Rp <?php echo number_format($row['avg_price'], 2, ",", "."); ?></td>
|
||||
<td><?php echo number_format($row['transactions_count']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<canvas id="merkChart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['run_analysis'])): ?>
|
||||
<div class="card mb-4" id="analysis-results">
|
||||
<div class="card-header">
|
||||
Hasil Analisa
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-info">Tidak ada data yang cocok dengan filter yang dipilih.</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<!-- Raw Data Table -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Data Master
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (empty($records)): ?>
|
||||
<div class="alert alert-info" role="alert">
|
||||
No records found in the 'tabelmaster'. You can start by importing your data.
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Nama Sales</th>
|
||||
<th>Tanggal</th>
|
||||
<th>No Faktur</th>
|
||||
<th>Merk</th>
|
||||
<th>Outlet</th>
|
||||
<th>Produk</th>
|
||||
<th>Qty</th>
|
||||
<th>Harga</th>
|
||||
<th>Bulan</th>
|
||||
<th>Tahun</th>
|
||||
<th>Periode</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($records as $row): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($row['NAMA_SALES']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['TANGGAL']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['NO_FAKTUR']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['MERK']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['OUTLET']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['PRODUK']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['QTY']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['HARGA']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['BULAN']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['TAHUN']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['PERIODE']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination justify-content-center">
|
||||
<li class="page-item <?php echo ($page <= 1) ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $page - 1; ">Previous</a>
|
||||
</li>
|
||||
<li class="page-item <?php echo ($page >= $total_pages) ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $page + 1; ">Next</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
if (typeof Chart !== 'undefined' && <?php echo !empty($analysis_results) ? 'true' : 'false'; ?>) {
|
||||
const ctx = document.getElementById('merkChart');
|
||||
new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: <?php echo $chart_labels_json; ?>,
|
||||
datasets: [{
|
||||
label: 'Total Omzet',
|
||||
data: <?php echo $chart_data_json; ?>,
|
||||
backgroundColor: 'rgba(13, 110, 253, 0.5)',
|
||||
borderColor: 'rgba(13, 110, 253, 1)',
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
callback: function(value, index, values) {
|
||||
return 'Rp ' + new Intl.NumberFormat('id-ID').format(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
label: function(context) {
|
||||
let label = context.dataset.label || '';
|
||||
if (label) {
|
||||
label += ': ';
|
||||
}
|
||||
if (context.parsed.y !== null) {
|
||||
label += 'Rp ' + new Intl.NumberFormat('id-ID').format(context.parsed.y);
|
||||
}
|
||||
return label;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php require_once 'footer.php'; ?>
|
||||
188
public.php
Normal file
188
public.php
Normal file
@ -0,0 +1,188 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
$error_message = null;
|
||||
$top_brands = [];
|
||||
$sales_by_period = [];
|
||||
$chart_labels_json = '[]';
|
||||
$chart_data_json = '[]';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
// Query 1: Top 5 Brands by Sales
|
||||
$top_brands_stmt = $pdo->query('
|
||||
SELECT
|
||||
MERK,
|
||||
SUM(QTY * CAST(REPLACE(HARGA, ",", "") AS DECIMAL(15,2))) as total_omzet
|
||||
FROM
|
||||
tabelmaster
|
||||
GROUP BY
|
||||
MERK
|
||||
ORDER BY
|
||||
total_omzet DESC
|
||||
LIMIT 5
|
||||
');
|
||||
$top_brands = $top_brands_stmt->fetchAll();
|
||||
|
||||
// Query 2: Sales per Period for Trend Chart
|
||||
$sales_by_period_stmt = $pdo->query('
|
||||
SELECT
|
||||
PERIODE,
|
||||
SUM(QTY * CAST(REPLACE(HARGA, ",", "") AS DECIMAL(15,2))) as total_omzet
|
||||
FROM
|
||||
tabelmaster
|
||||
WHERE PERIODE IS NOT NULL AND PERIODE != ""
|
||||
GROUP BY
|
||||
PERIODE
|
||||
ORDER BY
|
||||
PERIODE ASC
|
||||
');
|
||||
$sales_by_period = $sales_by_period_stmt->fetchAll();
|
||||
|
||||
if (!empty($sales_by_period)) {
|
||||
$chart_labels = [];
|
||||
$chart_data = [];
|
||||
foreach ($sales_by_period as $row) {
|
||||
$chart_labels[] = $row['PERIODE'];
|
||||
$chart_data[] = $row['total_omzet'];
|
||||
}
|
||||
$chart_labels_json = json_encode($chart_labels);
|
||||
$chart_data_json = json_encode($chart_data);
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$error_message = "Database error: " . $e->getMessage();
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Ringkasan Penjualan - vipanalisa</title>
|
||||
<meta name="description" content="Ringkasan laporan penjualan publik.">
|
||||
<meta name="keywords" content="laporan penjualan, ringkasan, sales report, public dashboard">
|
||||
<meta property="og:title" content="Ringkasan Penjualan - vipanalisa">
|
||||
<meta property="og:description" content="Ringkasan laporan penjualan publik.">
|
||||
<meta property="og:image" content="">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="header-gradient p-3 shadow-sm mb-4">
|
||||
<div class="container">
|
||||
<h1 class="navbar-brand mb-0 h1">Ringkasan Penjualan Publik</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="container">
|
||||
<?php if (isset($error_message)): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo htmlspecialchars($error_message); ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="row">
|
||||
<!-- Top 5 Brands -->
|
||||
<div class="col-lg-4 mb-4">
|
||||
<div class="card h-100">
|
||||
<div class="card-header">
|
||||
Top 5 Merk Terlaris
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (empty($top_brands)): ?>
|
||||
<p class="text-muted">Data tidak tersedia.</p>
|
||||
<?php else: ?>
|
||||
<ul class="list-group list-group-flush">
|
||||
<?php foreach ($top_brands as $brand): ?>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<?php echo htmlspecialchars($brand['MERK']); ?>
|
||||
<span class="badge bg-primary rounded-pill">Rp <?php echo number_format($brand['total_omzet'], 0, ",", "."); ?></span>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sales Trend -->
|
||||
<div class="col-lg-8 mb-4">
|
||||
<div class="card h-100">
|
||||
<div class="card-header">
|
||||
Tren Penjualan per Periode
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (empty($sales_by_period)): ?>
|
||||
<p class="text-muted">Data tren tidak tersedia.</p>
|
||||
<?php else: ?>
|
||||
<canvas id="salesTrendChart"></canvas>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</main>
|
||||
|
||||
<footer class="container mt-4 text-center text-muted">
|
||||
<p>© <?php echo date("Y"); ?> vipanalisa. Built with Flatlogic.</p>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
if (typeof Chart !== 'undefined' && <?php echo !empty($sales_by_period) ? 'true' : 'false'; ?>) {
|
||||
const ctx = document.getElementById('salesTrendChart');
|
||||
new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: <?php echo $chart_labels_json; ?>,
|
||||
datasets: [{
|
||||
label: 'Total Omzet',
|
||||
data: <?php echo $chart_data_json; ?>,
|
||||
fill: false,
|
||||
borderColor: 'rgba(13, 110, 253, 1)',
|
||||
tension: 0.1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
callback: function(value, index, values) {
|
||||
return 'Rp ' + new Intl.NumberFormat('id-ID').format(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
label: function(context) {
|
||||
let label = context.dataset.label || '';
|
||||
if (label) {
|
||||
label += ': ';
|
||||
}
|
||||
if (context.parsed.y !== null) {
|
||||
label += 'Rp ' + new Intl.NumberFormat('id-ID').format(context.parsed.y);
|
||||
}
|
||||
return label;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
181
sales_analysis.php
Normal file
181
sales_analysis.php
Normal file
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
$error_message = null;
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
// Get distinct values for filters
|
||||
$periode_options_stmt = $pdo->query('SELECT DISTINCT PERIODE FROM tabelmaster WHERE PERIODE IS NOT NULL AND PERIODE != \'\' ORDER BY PERIODE DESC');
|
||||
$periode_options = $periode_options_stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
// Handle form submission for analysis
|
||||
$analysis_results = [];
|
||||
$chart_labels_json = '[]';
|
||||
$chart_data_json = '[]';
|
||||
$selected_periode = $_POST['periode'] ?? 'all';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['run_analysis'])) {
|
||||
$sql = "\n SELECT\n NAMA_SALES,\n SUM(QTY) as total_qty,\n SUM(QTY * CAST(REPLACE(HARGA, ',', '') AS DECIMAL(15,2))) as total_omzet,\n AVG(CAST(REPLACE(HARGA, ',', '') AS DECIMAL(15,2))) as avg_price,\n COUNT(DISTINCT NO_FAKTUR) as transactions_count\n FROM\n tabelmaster\n WHERE 1=1";
|
||||
|
||||
$params = [];
|
||||
if ($selected_periode !== 'all') {
|
||||
$sql .= ' AND PERIODE = :periode';
|
||||
$params[':periode'] = $selected_periode;
|
||||
}
|
||||
|
||||
$sql .= ' GROUP BY NAMA_SALES HAVING SUM(QTY) > 0 ORDER BY total_omzet DESC';
|
||||
|
||||
$analysis_stmt = $pdo->prepare($sql);
|
||||
$analysis_stmt->execute($params);
|
||||
$analysis_results = $analysis_stmt->fetchAll();
|
||||
|
||||
if (!empty($analysis_results)) {
|
||||
$chart_labels = [];
|
||||
$chart_data = [];
|
||||
foreach ($analysis_results as $row) {
|
||||
$chart_labels[] = $row['NAMA_SALES'];
|
||||
$chart_data[] = $row['total_omzet'];
|
||||
}
|
||||
$chart_labels_json = json_encode($chart_labels);
|
||||
$chart_data_json = json_encode($chart_data);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$error_message = "Database error: " . $e->getMessage();
|
||||
}
|
||||
|
||||
require_once 'header.php';
|
||||
?>
|
||||
|
||||
<main class="container">
|
||||
<?php if (isset($error_message)): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo htmlspecialchars($error_message); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Analysis Form -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
Analisa Penjualan per Sales
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="sales_analysis.php#analysis-results">
|
||||
<div class="row g-3 align-items-end">
|
||||
<div class="col-md-10">
|
||||
<label for="periode" class="form-label">Periode</label>
|
||||
<select name="periode" id="periode" class="form-select">
|
||||
<option value="all">Semua Periode</option>
|
||||
<?php foreach ($periode_options as $periode): ?>
|
||||
<option value="<?php echo htmlspecialchars($periode); ?>" <?php echo ($selected_periode === $periode) ? 'selected' : ''; ?> >
|
||||
<?php echo htmlspecialchars($periode); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="submit" name="run_analysis" class="btn btn-primary w-100">Jalankan</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Analysis Results -->
|
||||
<?php if (!empty($analysis_results)): ?>
|
||||
<div class="card mb-4" id="analysis-results">
|
||||
<div class="card-header">
|
||||
Hasil Analisa
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Nama Sales</th>
|
||||
<th>Total Kuantitas</th>
|
||||
<th>Total Omzet</th>
|
||||
<th>Harga Rata-rata</th>
|
||||
<th>Jumlah Transaksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($analysis_results as $row): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($row['NAMA_SALES']); ?></td>
|
||||
<td><?php echo number_format($row['total_qty']); ?></td>
|
||||
<td>Rp <?php echo number_format($row['total_omzet'], 2, ",", "."); ?></td>
|
||||
<td>Rp <?php echo number_format($row['avg_price'], 2, ",", "."); ?></td>
|
||||
<td><?php echo number_format($row['transactions_count']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<canvas id="salesChart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['run_analysis'])): ?>
|
||||
<div class="card mb-4" id="analysis-results">
|
||||
<div class="card-header">
|
||||
Hasil Analisa
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-info">Tidak ada data yang cocok dengan filter yang dipilih.</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<script>
|
||||
if (typeof Chart !== 'undefined' && <?php echo !empty($analysis_results) ? 'true' : 'false'; ?>) {
|
||||
const ctx = document.getElementById('salesChart');
|
||||
new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: <?php echo $chart_labels_json; ?>,
|
||||
datasets: [{
|
||||
label: 'Total Omzet',
|
||||
data: <?php echo $chart_data_json; ?>,
|
||||
backgroundColor: 'rgba(13, 110, 253, 0.5)',
|
||||
borderColor: 'rgba(13, 110, 253, 1)',
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
callback: function(value, index, values) {
|
||||
return 'Rp ' + new Intl.NumberFormat('id-ID').format(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
label: function(context) {
|
||||
let label = context.dataset.label || '';
|
||||
if (label) {
|
||||
label += ': ';
|
||||
}
|
||||
if (context.parsed.y !== null) {
|
||||
label += 'Rp ' + new Intl.NumberFormat('id-ID').format(context.parsed.y);
|
||||
}
|
||||
return label;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php require_once 'footer.php'; ?>
|
||||
Loading…
x
Reference in New Issue
Block a user