summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Qarz daftarcha.iml8
-rw-r--r--add_user.php50
-rw-r--r--connect_database.php14
-rw-r--r--delete_user.php15
-rw-r--r--get_users.php40
-rw-r--r--index.php117
-rw-r--r--paid.php50
7 files changed, 294 insertions, 0 deletions
diff --git a/Qarz daftarcha.iml b/Qarz daftarcha.iml
new file mode 100644
index 0000000..80cc739
--- /dev/null
+++ b/Qarz daftarcha.iml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module> \ No newline at end of file
diff --git a/add_user.php b/add_user.php
new file mode 100644
index 0000000..652de82
--- /dev/null
+++ b/add_user.php
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Qarz daftarcha</title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
+ <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>
+</head>
+<body>
+
+<div class="container mt-5">
+ <h2>Qoshish</h2>
+ <form method="post" action="">
+ <div class="form-group">
+ <label for="ism">Ism:</label>
+ <input type="text" class="form-control" id="ism" placeholder="Jahongir" name="ism" required>
+ <label for="telefon_nomer">Telefon nomer:</label>
+ <input type="number" class="form-control" id="telefon_nomer" placeholder="998907477777" name="telefon_nomer" required>
+ <label for="miqdor">Qarz:</label>
+ <input type="number" min="0" class="form-control" id="miqdor" placeholder="10000" name="miqdor" required>
+ </div>
+ <button type="submit" class="btn btn-primary">Saqlash</button>
+ </form>
+</div>
+
+<?php
+
+include "get_users.php";
+
+if (array_key_exists("ism", $_POST)) {
+ $ism = $_POST["ism"];
+ $telefon_nomer = $_POST["telefon_nomer"];
+ $miqdor = $_POST["miqdor"];
+ $sql = "INSERT INTO qarzdorlar (ism, telefon_nomer, miqdor) VALUES ('$ism', $telefon_nomer,$miqdor)";
+ $result = $conn->query($sql);
+
+ if ($result === TRUE) {
+ header("Location: index.php");
+ } else {
+ echo "Error: " . $sql . "<br>" . $conn->error;
+ }
+}
+
+?>
+
+</body>
+</html>
diff --git a/connect_database.php b/connect_database.php
new file mode 100644
index 0000000..978e6ed
--- /dev/null
+++ b/connect_database.php
@@ -0,0 +1,14 @@
+<?php
+
+$servername = "localhost";
+$username = "root";
+$password = "";
+$dbname = "qarz_daftarcha";
+
+$conn = new mysqli($servername, $username, $password, $dbname);
+
+if ($conn->connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+}
+
+?>
diff --git a/delete_user.php b/delete_user.php
new file mode 100644
index 0000000..d6623f2
--- /dev/null
+++ b/delete_user.php
@@ -0,0 +1,15 @@
+<?php
+
+include "connect_database.php";
+
+$id = $_GET["id"];
+
+$sql = "DELETE FROM qarzdorlar WHERE id = $id";
+$result = $conn->query($sql);
+
+if ($result === TRUE) {
+ header("Location: index.php");
+} else {
+ echo "Error: " . $sql . "<br>" . $conn->error;
+}
+
diff --git a/get_users.php b/get_users.php
new file mode 100644
index 0000000..32d2801
--- /dev/null
+++ b/get_users.php
@@ -0,0 +1,40 @@
+<?php
+
+include "connect_database.php";
+
+$sql;
+
+if (isset($ism) && $ism != null) {
+ $sql = "SELECT * FROM qarzdorlar WHERE ism = $ism";
+} else {
+ $sql = "SELECT * FROM qarzdorlar";
+}
+
+$result = $conn->query($sql);
+
+$users;
+$min_user;
+$max_user;
+
+$sum_duty = 0;
+$min_duty = 99999999999;
+$max_duty = 0;
+
+for ($i = 0, $j = 0; $i < $result->field_count; $i++) {
+ while ($row = $result->fetch_assoc()) {
+ $users[$j] = $row;
+ $sum_duty += $row["miqdor"];
+
+ if ($row["miqdor"] < $min_duty) {
+ $min_user = $row;
+ $min_duty = $row["miqdor"];
+ }
+ if ($row["miqdor"] > $max_duty) {
+ $max_user = $row;
+ $max_duty = $row["miqdor"];
+ }
+ $j++;
+ }
+}
+
+?>
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..1177956
--- /dev/null
+++ b/index.php
@@ -0,0 +1,117 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Qarz daftarcha</title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
+ <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>
+</head>
+<body>
+
+<div class="jumbotron text-center">
+ <h1>Qarz daftarcha</h1>
+</div>
+
+<div class="container">
+ <form action="" method="get">
+ <div class="input-group mb-3">
+ <input type="text" class="form-control" placeholder="Jahongir" id="ism" name="ism">
+ <div class="input-group-append">
+ <button class="btn btn-primary" type="submit">Kidirish</button>
+ </div>
+ </div>
+ </form>
+
+ <a href="add_user.php" class="btn btn-success mb-3">Qoshish</a>
+
+ <p>Qarzdorlar:</p>
+ <table class="table table-bordered">
+ <thead>
+ <tr>
+ <th>Ism</th>
+ <th>Telefon nomer</th>
+ <th>Vaqt</th>
+ <th>Qarz</th>
+ <th>Harakatlar</th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php
+ $ism = null;
+
+ if (isset($_GET["ism"])) {
+ $ism = "'" . $_GET["ism"] . "'";
+ }
+
+ include "get_users.php";
+
+ if (isset($users)):
+ for ($i = 0; $i < sizeof($users); $i++): ?>
+ <tr>
+ <td><?= $users[$i]["ism"] ?></td>
+ <td>+<?= $users[$i]["telefon_nomer"] ?></td>
+ <td><?= $users[$i]["vaqt"] ?></td>
+ <td><span class="badge badge-danger badge-pill"><?= $users[$i]["miqdor"] ?> so'm</span></td>
+ <td><?php if ($users[$i]["miqdor"] == 0): ?><a href='delete_user.php?id=<?= $users[$i]["id"] ?>' class="btn btn-danger mr-1">Ochirish</a><?php endif; ?><a href='paid.php?id=<?= $users[$i]["id"] ?>' class="btn btn-success">Toladi</a></td>
+ </tr>
+ <?php
+ endfor;
+ endif;
+ ?>
+ </tbody>
+ </table>
+
+ <p class="mt-5">Statistika</p>
+ <ul class="list-group">
+ <p>Jami: <?= $sum_duty ?> so'm</p>
+ <p>Eng kam qarzdor:</p>
+ <table class="table table-bordered">
+ <thead>
+ <tr>
+ <th>Ism</th>
+ <th>Telefon nomer</th>
+ <th>Vaqt</th>
+ <th>Qarz</th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php if (isset($min_user)): ?>
+ <tr>
+ <td><?= $min_user["ism"]; ?></td>
+ <td>+<?= $min_user["telefon_nomer"]; ?></td>
+ <td><?= $min_user["vaqt"] ?></td>
+ <td><span class="badge badge-danger badge-pill"><?= $min_user["miqdor"]; ?> so'm</span></td>
+ </tr>
+ <?php endif; ?>
+ </tbody>
+ </table>
+ <p>Eng ko'p qarzdor:</p>
+
+ <table class="table table-bordered">
+ <thead>
+ <tr>
+ <th>Ism</th>
+ <th>Telefon nomer</th>
+ <th>Vaqt</th>
+ <th>Qarz</th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php if (isset($max_user)): ?>
+ <tr>
+ <td><?= $max_user["ism"]; ?></td>
+ <td>+<?= $max_user["telefon_nomer"]; ?></td>
+ <td><?= $max_user["vaqt"] ?></td>
+ <td><span class="badge badge-danger badge-pill"><?= $max_user["miqdor"]; ?> so'm</span></td>
+ </tr>
+ <?php endif; ?>
+ </tbody>
+ </table>
+ </ul>
+</div>
+
+</body>
+</html>
diff --git a/paid.php b/paid.php
new file mode 100644
index 0000000..ec7e89a
--- /dev/null
+++ b/paid.php
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Qarz daftarcha</title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
+ <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>
+</head>
+<body>
+
+<div class="container mt-5">
+ <h2>Toladi</h2>
+ <form method="post" action="">
+ <div class="form-group">
+ <label for="miqdor">Pul:</label>
+ <input type="number" min="0" class="form-control" id="miqdor" placeholder="10000" name="miqdor">
+ </div>
+ <button type="submit" class="btn btn-primary">Saqlash</button>
+ </form>
+</div>
+
+<?php
+
+include "get_users.php";
+
+$id = $_GET["id"];
+$existing_money = $conn->query("SELECT miqdor FROM qarzdorlar WHERE id = $id");
+$existing_money = $existing_money->fetch_assoc()["miqdor"];
+
+if (array_key_exists("miqdor", $_POST) && $existing_money >= $_POST["miqdor"]) {
+ $miqdor = (int) $existing_money - $_POST["miqdor"];
+ $sql = "UPDATE qarzdorlar SET miqdor = $miqdor WHERE id = $id";
+ $result = $conn->query($sql);
+
+ if ($result === TRUE) {
+ header("Location: index.php");
+ } else {
+ echo "Error: " . $sql . "<br>" . $conn->error;
+ }
+} elseif (array_key_exists("miqdor", $_POST) && $existing_money <= $_POST["miqdor"]) {
+ header("Location: index.php");
+}
+
+?>
+
+</body>
+</html>