From 97ae4ba490fe69d6d7fe64e61cbedfa63de19510 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 22 Mar 2026 17:51:27 +0000 Subject: [PATCH] update reciept --- api/ai_report.php | 22 +- api/pharmacy.php | 16 +- db/migrations/20260322_add_image_to_drugs.sql | 1 + includes/actions.php | 15 +- includes/pages/drugs.php | 106 ++++- includes/pages/pharmacy_pos.php | 73 ++-- includes/pages/settings.php | 308 ++++++++++----- lang.php | 328 ++++++++++------ mail/config.php | 79 ++-- print_pharmacy_receipt.php | 365 +++++++++++------- 10 files changed, 873 insertions(+), 440 deletions(-) create mode 100644 db/migrations/20260322_add_image_to_drugs.sql diff --git a/api/ai_report.php b/api/ai_report.php index 98be7ff..8f41026 100644 --- a/api/ai_report.php +++ b/api/ai_report.php @@ -5,15 +5,29 @@ require_once __DIR__ . '/../ai/LocalAIApi.php'; // Get JSON input $input = json_decode(file_get_contents('php://input'), true); -$target = $input['target'] ?? 'treatment_plan'; // symptoms, diagnosis, treatment_plan +$target = $input['target'] ?? 'treatment_plan'; // symptoms, diagnosis, treatment_plan, translate $symptoms = $input['symptoms'] ?? ''; $diagnosis = $input['diagnosis'] ?? ''; -$currentValue = $input['current_value'] ?? ''; // For expanding symptoms +$currentValue = $input['current_value'] ?? ''; // For expanding symptoms or translation text $systemPrompt = 'You are a professional medical assistant.'; $userPrompt = ""; switch ($target) { + case 'translate': + $text = $input['text'] ?? ''; + $from = $input['from'] ?? 'English'; + $to = $input['to'] ?? 'Arabic'; + + if (empty($text)) { + echo json_encode(['success' => false, 'error' => 'No text provided for translation.']); + exit; + } + + $systemPrompt = "You are a professional translator specializing in medical terminology."; + $userPrompt = "Translate the following text from $from to $to. Return only the translated text without any explanations or extra characters.\n\nText: $text"; + break; + case 'symptoms': if (empty($currentValue)) { $userPrompt = "Generate a list of common clinical symptoms for a general checkup in a professional medical format (HTML lists)."; @@ -57,10 +71,10 @@ try { if (!empty($response['success'])) { $text = LocalAIApi::extractText($response); - echo json_encode(['success' => true, 'report' => $text]); + echo json_encode(['success' => true, 'report' => trim($text)]); } else { echo json_encode(['success' => false, 'error' => $response['error'] ?? 'AI generation failed.']); } } catch (Exception $e) { echo json_encode(['success' => false, 'error' => $e->getMessage()]); -} \ No newline at end of file +} diff --git a/api/pharmacy.php b/api/pharmacy.php index 2cdd874..1443ba6 100644 --- a/api/pharmacy.php +++ b/api/pharmacy.php @@ -192,6 +192,14 @@ try { if (empty($input['items'])) throw new Exception("No items in sale"); + // Check Settings + $allow_negative = false; + try { + $settingStmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'allow_negative_stock'"); + $settingStmt->execute(); + $allow_negative = (bool)$settingStmt->fetchColumn(); + } catch (Exception $e) { /* ignore */ } + $pdo->beginTransaction(); try { @@ -235,7 +243,13 @@ try { } if ($qty_remaining > 0) { - throw new Exception("Insufficient stock for drug ID: $drug_id"); + if ($allow_negative) { + // Record sale for remaining quantity without batch + $item_stmt = $pdo->prepare("INSERT INTO pharmacy_sale_items (sale_id, drug_id, batch_id, quantity, unit_price, total_price) VALUES (?, ?, ?, ?, ?, ?)"); + $item_stmt->execute([$sale_id, $drug_id, null, $qty_remaining, $unit_price, $qty_remaining * $unit_price]); + } else { + throw new Exception("Insufficient stock for drug ID: $drug_id"); + } } } diff --git a/db/migrations/20260322_add_image_to_drugs.sql b/db/migrations/20260322_add_image_to_drugs.sql new file mode 100644 index 0000000..03c7a1a --- /dev/null +++ b/db/migrations/20260322_add_image_to_drugs.sql @@ -0,0 +1 @@ +ALTER TABLE drugs ADD COLUMN image VARCHAR(255) NULL; diff --git a/includes/actions.php b/includes/actions.php index 3ee6bbd..f7f0679 100644 --- a/includes/actions.php +++ b/includes/actions.php @@ -804,10 +804,11 @@ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') $price = $_POST['price'] ?? 0; $expiry_date = $_POST['expiry_date'] ?: null; $supplier_id = $_POST['supplier_id'] ?: null; + $image = upload_file($_FILES['image'] ?? [], 0, "assets/uploads/drugs/"); if ($name_en && $name_ar) { - $stmt = $db->prepare("INSERT INTO drugs (name_en, name_ar, group_id, description_en, description_ar, default_dosage, default_instructions, price, expiry_date, supplier_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); - $stmt->execute([$name_en, $name_ar, $group_id, $desc_en, $desc_ar, $dosage, $instructions, $price, $expiry_date, $supplier_id]); + $stmt = $db->prepare("INSERT INTO drugs (name_en, name_ar, group_id, description_en, description_ar, default_dosage, default_instructions, price, expiry_date, supplier_id, image) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$name_en, $name_ar, $group_id, $desc_en, $desc_ar, $dosage, $instructions, $price, $expiry_date, $supplier_id, $image]); $_SESSION['flash_message'] = __('add_drug') . ' ' . __('successfully'); $redirect = true; } @@ -823,10 +824,16 @@ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') $price = $_POST['price'] ?? 0; $expiry_date = $_POST['expiry_date'] ?: null; $supplier_id = $_POST['supplier_id'] ?: null; + $image = upload_file($_FILES['image'] ?? [], 0, "assets/uploads/drugs/"); if ($id && $name_en && $name_ar) { - $stmt = $db->prepare("UPDATE drugs SET name_en = ?, name_ar = ?, group_id = ?, description_en = ?, description_ar = ?, default_dosage = ?, default_instructions = ?, price = ?, expiry_date = ?, supplier_id = ? WHERE id = ?"); - $stmt->execute([$name_en, $name_ar, $group_id, $desc_en, $desc_ar, $dosage, $instructions, $price, $expiry_date, $supplier_id, $id]); + if ($image) { + $stmt = $db->prepare("UPDATE drugs SET name_en = ?, name_ar = ?, group_id = ?, description_en = ?, description_ar = ?, default_dosage = ?, default_instructions = ?, price = ?, expiry_date = ?, supplier_id = ?, image = ? WHERE id = ?"); + $stmt->execute([$name_en, $name_ar, $group_id, $desc_en, $desc_ar, $dosage, $instructions, $price, $expiry_date, $supplier_id, $image, $id]); + } else { + $stmt = $db->prepare("UPDATE drugs SET name_en = ?, name_ar = ?, group_id = ?, description_en = ?, description_ar = ?, default_dosage = ?, default_instructions = ?, price = ?, expiry_date = ?, supplier_id = ? WHERE id = ?"); + $stmt->execute([$name_en, $name_ar, $group_id, $desc_en, $desc_ar, $dosage, $instructions, $price, $expiry_date, $supplier_id, $id]); + } $_SESSION['flash_message'] = __('edit_drug') . ' ' . __('successfully'); $redirect = true; } diff --git a/includes/pages/drugs.php b/includes/pages/drugs.php index 26a449b..6da2066 100644 --- a/includes/pages/drugs.php +++ b/includes/pages/drugs.php @@ -57,7 +57,7 @@ if (isset($_GET['ajax_search'])) { if (empty($drugs)): ?> - + @@ -67,10 +67,16 @@ if (isset($_GET['ajax_search'])) { -
-
- + + + +
+
+ + + +
@@ -205,6 +211,7 @@ if (isset($_GET['ajax_search'])) { # + @@ -216,7 +223,7 @@ if (isset($_GET['ajax_search'])) { - + @@ -226,10 +233,16 @@ if (isset($_GET['ajax_search'])) { -
-
- + + + +
+
+ + + +
@@ -337,18 +350,28 @@ if (isset($_GET['ajax_search'])) {
-
+