<?php include("includes/db_config.php");
if(isset($_POST['update']))
{
extract($_POST);
$id=$_POST["pt_id"];
$sql1 ="UPDATE ah_party SET party_name='$party_name',date_of_joining='$date_of_joining',email_id='$email_id',party_phone_no='$party_phone_no',billing_address='$billing_address',shipping_address='$shipping_address',gst_type='$gst_type',gst_no='$gst_no',gst_state='$gst_state',opening_balance='$opening_balance',as_of_date='$as_of_date',paying_status='$paying_status' WHERE id='$id'"; 
$res=mysqli_query($conn,$sql1) or die(mysqli_error());
}
?>
<!DOCTYPE html>
<html lang="en" dir="ltr" data-theme="light">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <?php include("includes/css.php");?>
    <style>
        .modal-body .form-label{font-weight:600;}.viewptdt .form-label{font-weight:600;}.viewptdt label{margin-top:10px;}
    </style>
</head>

<body class="preload-active aside-active aside-mobile-minimized aside-desktop-maximized">
    <div class="holder">
        <?php include("includes/sidebar.php");?>
        <div class="wrapper">
            <?php include("includes/header.php");?>
            <div class="content">
                <div class="container-fluid g-5">
                    <div class="row mt-1">
                        <div class="col-12">
                            <div class="portlet">
                                <div class="portlet-header portlet-header-bordered">
                                    <h3 class="portlet-title">All Party Details</h3>
                                </div>
                                <div class="portlet-body table-responsive">
                                    <table id="datatable-1" class="table table-bordered table-striped table-hover">
                                        <thead>
                                            <tr>
                                                <th>Party Name</th>
                                                <th style="text-center">Type</th>
                                                <th>Number</th>
                                                <th>Date</th>
                                                <th style="text-center">Balance</th>
                                                <th style="text-center">As Of Date</th>
                                                <th>
                                                    <center>Action</center>
                                                </th>
                                                <th>
                                                    <center>Balance sheet</center>
                                                </th>
                                                <th> <center>View Transaction</center> </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                         <?php $j=1; 
                                            $sql="select * from ah_party"; 
                                            $result = mysqli_query($conn, $sql); 
                                            while($res= mysqli_fetch_array($result)){ ?>
                                            <tr>
                                                <td><a href="view-all-party-transaction-details.php" style="color:#000"><?= $res['party_name'];?></a></td>
                                                <td><?= ($res['type'] == 'Purchase') ? 'Buyer' : 'Seller'; ?></td>
                                                <td><?= $res['party_phone_no'];?></td>
                                                <td><?= $res['date_of_joining'];?></td>
                                                <td>₹ <?= $res['opening_balance'];?></td>
                                                <td><?= $res['as_of_date'];?></td>
                                                <td>
                                                    <center>
                                                        <button name="view" value="View" id="<?php echo $res["id"]; ?>" class="btn btn-primary view_data"> <i class="far fa-eye"></i></button>
                                                        <button name="edit" id="<?= $res['id'];?>" class="btn btn-success edit_data"> <i class="far fa-edit"></i></button>
                                                        <a href="javascript:delete_ptype_by_ID('<?php echo $res['id'] ?>');" class="btn btn-danger shadow btn-xs sharp"><i class="fa fa-trash"></i></a>
                                                    </center>
                                                </td>
                                                 <td>
                                                    <center>
                                                       <a href="view-balance-details.php?id=<?php echo $res["id"]; ?>"><button class="btn btn-primary view_data"> <i class="far fa-eye"></i></button></a>
                                                     </center>
                                                </td> 
                                                <td> <a href="view-all-party-transaction-details.php?party_id=<?php echo $res["id"]; ?>"><button name="view" class="btn btn-primary" type="button"> <i class="fa fa-file"></i></button></a>
                                                </td>
                                            </tr>
                                          <?php } ?>

                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal fade" id="modal3" data-bs-backdrop="static">
                <div class="modal-dialog dialog-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">Edit Party Details</h5><button type="button" class="btn btn-label-danger btn-icon" data-bs-dismiss="modal"><i class="fa fa-times"></i></button>
                        </div>
                    <form class="row g-3" action="" method="post">
                        <div class="modal-body">
                        <div class="row">
                                <div class="mb-3 col-md-6">
                                    <label class="form-label">Party Name</label>
                                    <input type="text" name="party_name" id="party_name" placeholder="Enter Party Name" class="form-control">
                                </div>
                                <div class="mb-3 col-md-6">
                                    <label class="form-label">Date Of Joining</label>
                                    <input type="date" id="date_of_joining" name="date_of_joining" class="form-control">
                                </div>
                                <div class="mb-3 col-md-6">
                                    <label class="form-label">Email</label>
                                    <input type="email" id="email_id" name="email_id" class="form-control">
                                </div>
                                <div class="mb-3 col-md-6">
                                    <label class="form-label">Party Phone Number</label>
                                    <input type="tel" placeholder="Party Phone Number" id="party_phone_no" name="party_phone_no" class="form-control">
                                </div>
                                </div>
                                <div class="card">
                                    <div class="card-header">
                                        <div class="nav nav-lines card-header-lines" id="card1-tab" role="tablist">
                                            <a class="nav-item nav-link active" id="card1-address-tab" data-bs-toggle="tab" href="#card1-address" aria-selected="true" role="tab">Address</a>
                                            <a class="nav-item nav-link" id="card1-gst-tab" data-bs-toggle="tab" href="#card1-gst" aria-selected="false" role="tab" tabindex="-1">GST</a>
                                            <a class="nav-item nav-link" id="card1-opb-tab" data-bs-toggle="tab" href="#card1-opb" aria-selected="false" tabindex="-1" role="tab">Opening Balance</a>
                                        </div>
                                    </div>
                                    <div class="card-body">
                                        <div class="tab-content">
                                            <div class="tab-pane fade active show" id="card1-address" role="tabpanel" aria-labelledby="#card1-address-tab">
                                                <div class="row">
                                                    <div class="col-md-6 mb-3">
                                                        <label class="form-label">Billing Address</label>
                                                        <textarea type="text" name="billing_address" id="billing_address"  rows="4" placeholder="Billing Address" class="form-control"></textarea>
                                                    </div>
                                                    <div class="col-md-6 mb-3">
                                                        <label class="form-label">Shipping Address</label>
                                                        <textarea type="text" name="shipping_address" id="shipping_address"  rows="4" placeholder="Shipping Address" class="form-control"></textarea>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="tab-pane fade" id="card1-gst" role="tabpanel" aria-labelledby="#card1-gst-tab">
                                                <div class="row">
                                                    <div class="mb-3 col-md-6">
                                                        <label class="form-label">GST Type</label>
                                                        <select type="text" class="form-control" id="gst_type" name="gst_type">
                                                            <option value="">Select GST Type</option>
                                                            <option>Unregistered/Consumer</option>
                                                            <option>Registered Business - Regular</option>
                                                            <option>Registered Business - Composition</option>
                                                        </select>
                                                    </div>
                                                    <div class="mb-3 col-md-6">
                                                        <label class="form-label">GST Number</label>
                                                        <input type="text" placeholder="GST Number" id="gst_no" name="gst_no" class="form-control">
                                                    </div>
                                                    <div class="mb-3 col-md-6">
                                                        <label class="form-label">State</label>
                                                        <select type="text" class="form-control" id="gst_state" name="gst_state">
                                                            <option>Select State</option>
                                                            <option>Andra Pradesh</option>
                                                            <option>Telangana</option>
                                                            <option>Other</option>
                                                        </select>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="tab-pane fade" id="card1-opb" role="tabpanel" aria-labelledby="#card1-opb-tab">
                                                <div class="row">
                                                    <div class="mb-3 col-md-6">
                                                        <label class="form-label">Opening Balance</label>
                                                        <input type="text" placeholder="Opening Balance" class="form-control" name="opening_balance" id="opening_balance" >
                                                    </div>
                                                    <div class="mb-3 col-md-6">
                                                        <label class="form-label">As Of Date</label>
                                                        <input type="text" class="form-control" id="as_of_date" name="as_of_date">
                                                    </div>
                                                    <div class="mb-3 col-md-">
                                                        <div class="form-check">
                                                            <input class="form-check-input" type="radio" name="paying_status" id="" checked="checked"> <label class="form-check-label" for="flexRadioDefault2">To Pay</label>
                                                        </div>
                                                    </div>
                                                    <input type="hidden" name="pt_id" id="pt_id" />

                                                    <div class="mb-3 col-md-">
                                                        <div class="form-check"> <input class="form-check-input" type="radio" name="paying_status"> <label class="form-check-label" for="flexRadioDefault2">To Recieve</label>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <div class="modal-footer"><button type="submit" name="update" id="insert" class="btn btn-primary">Update</button></div>
                         </form>
                    </div>
                </div>
            </div>
            <div class="modal fade" id="modal2" data-bs-backdrop="static">
                <div class="modal-dialog dialog-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">View Party Details</h5><button type="button" class="btn btn-label-danger btn-icon" data-bs-dismiss="modal"><i class="fa fa-times"></i></button>
                        </div>
                        <div class="modal-body viewptdt">
                            <div class="row">
                                <div class="mb-1 col-md-12">
                                    <label class="form-label">Party Name</label>
                                    <input type="text" id="party_names" class="form-control" readonly>
                                </div>
                                <div class="mb-1 col-md-6">
                                    <label class="form-label">Date Of Joining</label>
                                    <input type="text" value="" id="date_of_joinings" class="form-control" readonly>
                                </div>
                                <div class="mb-1 col-md-6">
                                    <label class="form-label">Email</label>
                                    <input type="email" value="" id="emailids" class="form-control" readonly>
                                </div>
                                <div class="mb-1 col-md-6">
                                    <label class="form-label">Party Phone Number</label>
                                    <input type="tel" value="" id="party_phone_nos" class="form-control" readonly>
                                </div>
                                <div class="col-md-6 mb-1">
                                    <label class="form-label">Billing Address</label>
                                    <textarea id="billing_addresss" type="text" rows="1" value="Billing Address" class="form-control" readonly></textarea>
                                </div>
                                <div class="col-md-6 mb-1">
                                    <label class="form-label">Shipping Address</label>
                                    <textarea id="shipping_address" type="text" rows="1" value="Shipping Address" class="form-control" readonly></textarea>
                                </div>
                                <div class="mb-1 col-md-6">
                                    <label class="form-label">GST Type</label>
                                    <input type="tel" id="gst_types" class="form-control" readonly>
                                </div>
                                <div class="mb-1 col-md-6">
                                    <label class="form-label">GST Number</label>
                                    <input type="text" id="gst_nos" class="form-control" readonly>
                                </div>
                                <div class="mb-1 col-md-6">
                                    <label class="form-label">State</label>
                                    <input type="text" id="gst_states" class="form-control" readonly>
                                </div>
                                <div class="mb-3 col-md-6">
                                    <label class="form-label">Opening Balance</label>
                                    <input type="text" id="opening_balances" class="form-control" readonly>
                                </div>
                                <div class="mb-3 col-md-6">
                                    <label class="form-label">As Of Date</label>
                                    <input type="text" class="form-control" id="as_of_dates" readonly>
                                </div>
                                <div class="mb-3 col-md-6">
                                    <label class="form-label">Pay</label>
                                    <input type="text" class="form-control" id="paying_statuss" readonly>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include("includes/footer.php");?>
        </div>
    </div>
    <?php include("includes/js.php");?>
<script type="text/javascript">
  $(document).ready(function() {
        $(document).on('click', '.view_data', function() {
            var pt_id = $(this).attr("id");
            $.ajax({
                url: "view_party.php",
                method: "POST",
                data: { pt_id: pt_id
                },
                dataType: "json",
                success: function(data) {
                    console.log(data);
                    $('#party_names').val(data.party_name);
                    $('#date_of_joinings').val(data.date_of_joining);
                    $('#emailids').val(data.email_id);
                    $('#party_phone_nos').val(data.party_phone_no);
                    $('#billing_addresss').val(data.billing_address);
                    $('#shipping_address').val(data.shipping_address);
                    $('#gst_types').val(data.gst_type);
                    $('#gst_nos').val(data.gst_no);
                    $('#gst_states').val(data.gst_state);
                    $('#opening_balances').val(data.opening_balance);
                    $('#as_of_dates').val(data.as_of_date);
                    $('#paying_statuss').val(data.paying_status);
                   // $('#insert').val("Update");
                    $('#modal2').modal('show');
                }
            });
        });
    });   
 $(document).ready(function() {
        $(document).on('click', '.edit_data', function() {
            var pt_id = $(this).attr("id");
            $.ajax({
                url: "edit_party.php",
                method: "POST",
                data: { pt_id: pt_id},
                dataType: "json",
                success: function(data) {
                    console.log(data);
                   $('#party_name').val(data.party_name);
                    $('#date_of_joining').val(data.date_of_joining);
                    $('#emailid').val(data.email_id);
                    $('#party_phone_no').val(data.party_phone_no);
                    $('#billing_address').val(data.billing_address);
                    $('#shipping_address').val(data.shipping_address);
                    $('#gst_type').val(data.gst_type);
                    $('#gst_no').val(data.gst_no);
                    $('#gst_state').val(data.gst_state);
                    $('#opening_balance').val(data.opening_balance);
                    $('#as_of_date').val(data.as_of_date);
                    $('#pt_id').val(data.id);
                     $('#insert').val("Update");
                    $('#modal3').modal('show');
                }
            });
        });
    });   
     function delete_ptype_by_ID(id) {
        if (confirm('Do You Want to Deleting This \nContinue anyway?')) {
            window.location.href = 'delete_party.php?id=' + id;
        }
    }
</script>    
</body>

</html>