gitea init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../../includes/init.php'; // ბაზასთან კავშირი
|
||||
require_once __DIR__ . '/../models/client.php'; // Client მოდელის ჩასმა
|
||||
|
||||
Client::setDb($pdo); // აქ ვუკავშირებთ PDO ობიექტს მოდელს
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// ყველა მონაცემის შეგროვება ერთი მასივში
|
||||
$data = [
|
||||
'first_name' => trim($_POST['first_name'] ?? ''),
|
||||
'last_name' => trim($_POST['last_name'] ?? ''),
|
||||
'company_name' => trim($_POST['company'] ?? null),
|
||||
'vat_number' => trim($_POST['vat_number'] ?? null),
|
||||
'email' => trim($_POST['email'] ?? ''),
|
||||
'password' => password_hash($_POST['password'], PASSWORD_BCRYPT),
|
||||
'address1' => trim($_POST['address1'] ?? null),
|
||||
'address2' => trim($_POST['address2'] ?? null),
|
||||
'city' => trim($_POST['city'] ?? null),
|
||||
'state' => trim($_POST['state'] ?? null),
|
||||
'postcode' => trim($_POST['postcode'] ?? null),
|
||||
'country' => trim($_POST['country'] ?? null),
|
||||
'phone' => trim($_POST['phone'] ?? null),
|
||||
'payment_method' => trim($_POST['payment_method'] ?? null),
|
||||
'billing_contact' => trim($_POST['billing_contact'] ?? null),
|
||||
'currency' => trim($_POST['currency'] ?? 'USD'),
|
||||
'language' => trim($_POST['language'] ?? 'default'),
|
||||
'status' => trim($_POST['status'] ?? 'active'),
|
||||
'client_group' => trim($_POST['client_group'] ?? 'none'),
|
||||
'admin_notes' => trim($_POST['admin_notes'] ?? null),
|
||||
];
|
||||
|
||||
// მონაცემის დამატება მოდელიდან
|
||||
Client::create($data);
|
||||
|
||||
header("Location: dashboard.php?module=clients&action=list");
|
||||
exit;
|
||||
}
|
||||
// view-ის ჩატვირთვა
|
||||
require_once __DIR__ . '/../views/clients_add.php';
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../../includes/init.php';
|
||||
require_once __DIR__ . '/../models/client.php';
|
||||
|
||||
Client::setDb($pdo); // ვუთითებთ PDO ობიექტს
|
||||
|
||||
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
|
||||
$id = (int)$_GET['id'];
|
||||
|
||||
// გადავცემთ ID-ს მოდელს წასაშლელად
|
||||
Client::delete($id);
|
||||
}
|
||||
|
||||
header("Location: dashboard.php?module=clients&action=list");
|
||||
exit;
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../../includes/init.php';
|
||||
require_once __DIR__ . '/../models/client.php';
|
||||
|
||||
// შემოწმება GET id-ზე
|
||||
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||
header("Location: dashboard.php?module=clients&action=list");
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = (int)$_GET['id'];
|
||||
|
||||
// მომხმარებლის წამოღება
|
||||
Client::setDb($pdo);
|
||||
$client = Client::find($id);
|
||||
|
||||
if (!$client) {
|
||||
echo "კლიენტი ვერ მოიძებნა.";
|
||||
exit;
|
||||
}
|
||||
|
||||
// თუ შენახვის ფორმა გამოიგზავნა
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$data = [
|
||||
'first_name' => trim($_POST['first_name'] ?? ''),
|
||||
'last_name' => trim($_POST['last_name'] ?? ''),
|
||||
'company_name' => trim($_POST['company'] ?? null),
|
||||
'email' => trim($_POST['email'] ?? ''),
|
||||
'phone' => trim($_POST['phone'] ?? null),
|
||||
'status' => trim($_POST['status'] ?? 'active'),
|
||||
'client_group' => trim($_POST['client_group'] ?? 'none'),
|
||||
'admin_notes' => trim($_POST['admin_notes'] ?? null),
|
||||
];
|
||||
|
||||
Client::update($id, $data);
|
||||
header("Location: dashboard.php?module=clients&action=profile&id=$id");
|
||||
exit;
|
||||
}
|
||||
|
||||
// view-ის ჩატვირთვა
|
||||
require_once __DIR__ . '/../views/clients_edit.php';
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../../includes/init.php';
|
||||
require_once __DIR__ . '/../models/client.php';
|
||||
|
||||
Client::setDb($pdo);
|
||||
$clients = Client::all(); // მოდელიდან იღებ ყველა კლიენტს
|
||||
|
||||
include __DIR__ . '/../views/clients_list.php'; // აჩვენე View
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../../includes/init.php';
|
||||
|
||||
// ID გადმოწოდებულია URL-იდან
|
||||
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||
header("Location: clients_list.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = (int)$_GET['id'];
|
||||
$stmt = $pdo->prepare("SELECT * FROM clients WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$client = $stmt->fetch();
|
||||
|
||||
if (!$client) {
|
||||
echo "კლიენტი ვერ მოიძებნა.";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Ჩვენ ვიღებთ კლიენტის ID-ს
|
||||
$client_id = $_GET['id'];
|
||||
|
||||
// ყველა ინვოისი ამ მომხმარებლისთვის
|
||||
$stmt = $pdo->prepare("SELECT status, total_amount FROM invoices WHERE client_id = ?");
|
||||
$stmt->execute([$client_id]);
|
||||
$invoices = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// ინიციალიზაცია
|
||||
$paid = $draft = $unpaid_due = $cancelled = $refunded = 0;
|
||||
|
||||
// გამოთვლა
|
||||
foreach ($invoices as $inv) {
|
||||
$amount = (float)$inv['total_amount'];
|
||||
switch ($inv['status']) {
|
||||
case 'გადახდილი':
|
||||
$paid += $amount;
|
||||
break;
|
||||
case 'დრაფტი':
|
||||
$draft += $amount;
|
||||
break;
|
||||
case 'გადაუხდელი':
|
||||
case 'გადასახდელი':
|
||||
$unpaid_due += $amount;
|
||||
break;
|
||||
case 'გაუქმებული':
|
||||
$cancelled += $amount;
|
||||
break;
|
||||
case 'დაბრუნებული':
|
||||
$refunded += $amount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$gross_revenue = $paid + $unpaid_due + $draft;
|
||||
$net_income = $paid;
|
||||
$credit_balance = 0.00; // შეგიძლია დაამატო ცალკე ცხრილიდან
|
||||
|
||||
|
||||
|
||||
$client_id = $_GET['id'];
|
||||
|
||||
// სერვისების მიღება
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT p.name AS product_name, ii.amount, ii.description, i.issue_date
|
||||
FROM invoice_items ii
|
||||
JOIN invoices i ON ii.invoice_id = i.id
|
||||
JOIN products p ON ii.product_id = p.id
|
||||
WHERE i.client_id = ?
|
||||
ORDER BY i.issue_date DESC
|
||||
");
|
||||
$stmt->execute([$client_id]);
|
||||
$services = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
|
||||
require_once __DIR__ . '/../views/client_profile.php';
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user