<?php
require_once "../config/db.php";

$customer_id = $_POST['customer_id'] ?? '';
$service_name = trim($_POST['service_name'] ?? '');
$type = $_POST['type'] ?? '';
$amount = $_POST['amount'] ?? 0;
$cost = $_POST['cost'] ?? 0;
$start_date = $_POST['start_date'] ?? null;
$renewal_date = $_POST['renewal_date'] ?? null;

if(empty($customer_id) || empty($service_name)){
    die("Missing required fields");
}

$stmt = $conn->prepare("
INSERT INTO services 
(customer_id, service_name, type, amount, cost, start_date, renewal_date)
VALUES (?, ?, ?, ?, ?, ?, ?)
");

$stmt->bind_param(
    "issddss",
    $customer_id,
    $service_name,
    $type,
    $amount,
    $cost,
    $start_date,
    $renewal_date
);

$stmt->execute();

header("Location: ../pages/add_service.php?success=1");
exit;
