<?php
include("../leadsnew/branch_connection.php");

if(isset($_POST['ptd_submit'])){

    $ptd_id             = isset($_POST['ptd_id']) ? intval($_POST['ptd_id']) : 0;
    $marketing_order_id = $_POST['marketing_order_id'];
    $company_name       = $_POST['company_name'];
    $customer_name      = $_POST['customer_name'];
    $category_id        = $_POST['category_id'];
    $assigned_to        = $_POST['assigned_to'];
    $man_hours          = $_POST['man_hours'];
    $segment            = $_POST['segment'];
    $order_date         = $_POST['order_date'];
    $delivery_date      = $_POST['delivery_date'];
    $status             = $_POST['status'];
$work_type = $_POST['work_type'];
$so_no  = $_POST['so_no'];
$sr_no  = $_POST['sr_no'];
$srs_no = $_POST['srs_no'];
$bdo    = $_POST['bdo'];

    if($ptd_id > 0){
        // UPDATE existing record
        $sql = mysqli_query($conn, "
            UPDATE ptd_details SET
 assigned_to = '$assigned_to',
 man_hours  = '$man_hours',
 segment    = '$segment',
 work_type  = '$work_type',
 so_no      = '$so_no',
 sr_no      = '$sr_no',
 srs_no     = '$srs_no',
 bdo        = '$bdo'
WHERE id = '$ptd_id'

        ");
        $msg = "Updated Successfully";
    } else {
        // INSERT new record
       $sql = mysqli_query($conn, "
INSERT INTO ptd_details
(
 marketing_order_id, company_name, customer_name, category_id,
 assigned_to, man_hours, segment, work_type,
 so_no, sr_no, srs_no, bdo,
 order_date, delivery_date, status
)
VALUES
(
 '$marketing_order_id', '$company_name', '$customer_name', '$category_id',
 '$assigned_to', '$man_hours', '$segment', '$work_type',
 '$so_no', '$sr_no', '$srs_no', '$bdo',
 '$order_date', '$delivery_date', '$status'
)
");

        $msg = "Added Successfully";
    }

    if($sql){
$last_id = ($ptd_id > 0) ? $ptd_id : mysqli_insert_id($conn);
header("Location: ptd.php?ptd_id=$last_id&success_msg=" . urlencode($msg));
exit;
    } else {
        die(mysqli_error($conn));
    }
}
?>
