<?php


function success_update() {
    echo "<h1>Records Edit Successfully Please Wait.</h1>";
    echo'<script>location.replace("")</script>';	    
}
	


if (isset($_POST['edit_services'])) { 
    $id     = $_POST['id'];
    $name= $_POST['name'];
    $detail  = $_POST['detail'];
     $status    = $_POST['status'];

    $obj->update('services', [
        'name' => $name, 
        'detail' => $detail,
        'status' => $status
    ], "id='$id'");

    if ($obj->getResult()) {
        success_update();
    }
}
if (isset($_POST['edit_tax_slabs'])) { 
    $id     = $_POST['id'];
    $sate= $_POST['state'];
    $duration  = $_POST['duration'];
     $amount   = $_POST['amount'];

    $obj->update('tax_slabs', [
        'state' => $sate, 
        'duration' => $duration,
        'amount' => $amount
    ], "id='$id'");

    if ($obj->getResult()) {
        success_update();
    }
}
if (isset($_POST['edit_category'])) { 
    $id     = $_POST['id'];
    $name= $_POST['name'];
    $obj->update('category', [
        'name' => $name, 
    ], "id='$id'");

    if ($obj->getResult()) {
        success_update();
    }
}
if (isset($_POST['edit_sub_category'])) { 
    $id     = $_POST['id'];
     $category= $_POST['category'];
    $name= $_POST['name'];
    $obj->update('sub_category', [
        'category' => $category, 
        'name' => $name, 
    ], "id='$id'");

    if ($obj->getResult()) {
        success_update();
    }
}
if (isset($_POST['edit_employee'])) { 
    $id     = $_POST['id'];
     $name= $_POST['name'];
    $number= $_POST['number'];
     $password= $_POST['password'];
    $status= $_POST['status'];
    $role= $_POST['role'];
    $obj->update('employee', [
        
        'name' => $name, 
        'number' => $number,
        'password' => $password,
        'status' => $status,
        'role' => $role,
    ], "id='$id'");

    if ($obj->getResult()) {
        success_update();
    }
}
if (isset($_POST['edit_payments'])) { 
    $id     = $_POST['id'];
    $status= $_POST['status'];
    $obj->update('payments', [
        'status' => $status, 
    ], "id='$id'");

    if ($obj->getResult()) {
        success_update();
    }
}
if (isset($_POST['edit_bank_details'])) {

    $id             = $_POST['id'];
    $bank_name      = $_POST['bank_name'];
    $account_number = $_POST['account_number'];
    $ifsc_code      = $_POST['ifsc_code'];
    $upi_id         = $_POST['upi_id'];

    $data = [
        'bank_name'      => $bank_name,
        'account_number' => $account_number,
        'ifsc_code'      => $ifsc_code,
        'upi_id'         => $upi_id
    ];

    // QR upload check
    if (!empty($_FILES['qr_code']['name'])) {

        $qr = $_FILES['qr_code'];
        $filename = time() . '_' . $qr['name'];

        $targetDir  = "../assets/qrcode/";
        $targetfile = $targetDir . $filename;

        if (move_uploaded_file($qr['tmp_name'], $targetfile)) {
            $data['qr_code'] = $filename;
        }
    }

    $obj->update('bank_details', $data, "id='$id'");

    if ($obj->getResult()) {
        success_update();
    }
}
?>