
<?php

session_start(); 
    $u_uname = '';
    if (isset($_COOKIE['auth_token']))
    {
        $u_uname = $_COOKIE['auth_token'];
    }else{
        header("location:../login.php");
    }

include '../include/connection.php';

// Check if all required parameters are set
if (isset($_POST['projectname'], $_POST['amount'], $_POST['advance'], $_POST['clientId'], $_POST['commission'], $_POST['commStatus'])) {
    // Assign values to variables
    $projectname=$_POST['projectname'];
    $cost=$_POST['amount'];
    $advance=$_POST['advance'];
    $balance = $cost - $advance;
    $clientId = $_POST['clientId'];
    $commission=$_POST['commission'];
    $commStatus=$_POST['commStatus'];

    // SQL query
     $sql = "INSERT INTO `project`(`projectname`, `projectcost`, `balance`,`advanceamount`, `recievedPay`, `commission`, `commissionstatus`, `client_id`) 
                         VALUES ('$projectname', '$cost', '$balance' ,'$advance' ,'$advance','$commission', '$commStatus', '$clientId')";
    
    // Execute the query
    if ($link->query($sql) === TRUE) {
        header('Location:../addproject.php?status=1');
    } else {
        header('Location:../addproject.php?status=2');
       
    }
} else {
    // Handle case where parameters are missing
    echo "Error: Missing parameters";
}
?>