<?php
include 'config/koneksi.php';

$id_jasa = $_GET['id_jasa'];
$metode  = $_GET['metode'] ?? 'Transfer';
$qty     = $_GET['qty'] ?? 1;

// ambil data jasa
$q = mysqli_query($conn, "SELECT * FROM jasa WHERE id='$id_jasa'");
$j = mysqli_fetch_assoc($q);

if(!$j){
    die("Data jasa tidak ditemukan");
}

// hitung total
$total = $j['harga'] * $qty;

// simpan ke transaksi
mysqli_query($conn, "INSERT INTO transaksi 
(nama, no_hp, alamat, id_jasa, total, status, metode, nama_jasa, harga, qty)
VALUES 
('Customer', '08123456789', 'Alamat customer', '$id_jasa', '$total', 'Lunas', '$metode', '{$j['nama_jasa']}', '{$j['harga']}', '$qty')
");

$id_transaksi = mysqli_insert_id($conn);

// redirect
header("Location: invoice.php?id=$id_transaksi");
exit;