<?php include("includes/db_config.php");
if(isset($_POST['update']))
{ extract($_POST);
$id=$_POST["pt_id"];
$sql1 ="UPDATE ah_sales_payment_in SET receipt_no='$receipt_no',date='$pdate',customer_id='$customer_id',contact_no='$phone_no',received_amonut='$received_amonut',total_amount='$total_amount',balance='$balance',cheque_no='$cheque_no',desp='$desp',bank_name='$bank_name',transaction_id='$transaction_id',opening_balance='$opening_balance',as_on='$as_on' WHERE id='$id'"; 
$res=mysqli_query($conn,$sql1) or die(mysqli_error());
 if($res){
    
   }
} ?>
<!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">
                        <div class="col-12">
                            <div class="portlet">
                               <div class="portlet-header portlet-header-bordered row">
                                     <div class="col-md-10">
                                        <h3 class="portlet-title">Payment Out</h3>
                                    </div>
                                     <div class="col-md-2"><a href="add-payment-out.php"> <button class="btn btn-success btn-md">Add Give Payment</button> </a>
                                    </div>                                    
                                </div>
                                <div class="portlet-body row">
                                     <div class="col-md-2 mt-2">
                                    <label>Type</label>
                                    <select class="form-control">
                                        <option value="">Select Type</option>
                                        <option value="">Today</option>
                                        <option value="">This Week</option>
                                        <option value="">This Month</option>
                                        <option value="">This Quarter</option>
                                        <option value="">This Year</option>
                                        <option value="">Custom</option>
                                    </select>
                                </div> 
                                <div class="col-md-3 mt-2">
                                    <label>Payment-Out</label>
                                    <select class="form-control">
                                        <option value="">Select Payment-In</option>
                                        <option value="">All Transactions</option>
                                        <option value="">Purchase</option>
                                        <option value="">Expense</option>
                                        <option value="">Sale</option>
                                        <option value="">Party To Party(Paid)</option>
                                        <option value="">Party To Party(Recieved)</option>
                                        <option value="">Payment-In</option>
                                        <option value="">Payment-Out</option>
                                        <option value="">Credit Note</option>
                                        <option value="">Debit Note</option>
                                        <option value="">Sale Order</option>
                                        <option value="">Purchase Order</option>
                                        <option value="">Estimate</option>
                                        <option value="">Delivery Challan</option>
                                        <option value="">Sale FA</option>
                                        <option value="">Purchase FA</option>
                                    </select>
                                </div> 
                                <div class="col-md-3 mt-2">
                                    <label>Party Name</label>
                                    <select class="form-control">
                                        <option value="">Select Party Name</option>
                                       <?php $sqlct=mysqli_query($conn,"select * from ah_vendor");
                                        while($resct= mysqli_fetch_array($sqlct)){ ?>
                                        <option value="<?= $resct['id'];?>"><?= $resct['party_name'];?></option>
                                        <?php } ?>
                                    </select>
                                </div> 
                                <div class="col-md-2 mt-2">
                                    <label>Payment Type</label>
                                    <select class="form-control">
                                        <option value="">Select Type</option>
                                        <option value="">All </option>
                                        <option value="">Cash</option>
                                        <option value="">Cheque No.</option>
                                        <option value="">Bank A/c</option>
                                    </select>
                                </div> 
                                <div class="col-md-2 mt-2"> 
                                    <label class="">From Date</label>
                                    <input type="date" placeholder="" class="form-control">
                                </div>
                                <div class="col-md-2 mt-2"> 
                                    <label class="">To Date</label>
                                    <input type="date" placeholder="" class="form-control">
                                </div>
                                <div class="col-md-2 mt-2"> 
                                     <input type="button" value="Find" class="btn btn-success btn-lg" style="margin-top:30px;">
                                </div>
                                </div>
                                <div class="portlet-body mt-3 table-responsive">
                                     <table id="datatable-1" class="table table-bordered table-striped table-hover">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th>Reciept No.</th>
                                                <th>Date</th>
                                                <th>Party Name</th>
                                                <th>Payment Type</th> 
                                                <th style="text-center">Total</th>
                                                <th style="text-center">Received</th>
                                                 <th style="text-center">Balance</th>
                                                <th>
                                                    <center>Action</center>
                                                </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        <?php $i=1;
                                        $sqlsl=mysqli_query($conn,"select * from ah_purchase_payment_out");
                                         while($resl= mysqli_fetch_array($sqlsl)){
                                         $cid=$resl['customer_id'];
                                         $sqlpt=mysqli_query($conn,"SELECT * from ah_vendor where id='".$cid."'");
                                         $restpy=mysqli_fetch_array($sqlpt); ?>
                                            <tr>
                                                <td><?php echo $i; $i++; ?>.</td>
                                                <td><?= $resl['receipt_no'];?></td>
                                                <td><?= $resl['receipt_date'];?></td>
                                                <td><?= $restpy['party_name'];?></td>
                                                <td><?= $resl['payment_type'];?></td>
                                                <td>₹ <?= $resl['total_amount'];?></td>
                                                <td>₹ <?= $resl['received_amonut'];?></td>
                                                <td>₹ <?= $resl['balance'];?></td>
                                                 <td>
                                                    <center> <button class="btn btn-success view_data" name="view" value="View" id="<?php echo $res["id"]; ?>"> <i class="far fa-eye"></i></button>
                                                        <button class="btn btn-primary edit_data" name="edit" id="<?= $res['id'];?>" > <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>
                                            </tr>
                                         <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="modaledit" data-bs-backdrop="static">
                <div class="modal-dialog dialog-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">Edit Payment-In 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="g-3" action="" method="post">
                            <div class="row modal-body">
                                <div class="mb-3 col-md-6">
                                <label class="form-label">Receipt No.</label>
                                <input type="text" placeholder="Enter Receipt No." id="receipt_no" id="receipt_no" class="form-control">
                            </div>
                         <div class="mb-3 col-md-6">
                                <label class="form-label">Date</label>
                                <input type="text" id="pdate" name="pdate" placeholder="Choose Date"  class="form-control">
                            </div>
                            <div class="mb-3 col-md-6">
                                <label class="form-label">Customer Name</label>
                                  <select class="form-control" name="customer_id" id="customer_id">
                                    <option value="">Select Customer Name</option>
                                    <?php $sqlct=mysqli_query($conn,"select * from ah_party");
                                    while($resct= mysqli_fetch_array($sqlct)){ ?>
                                    <option value="<?= $resct['id'];?>"><?= $resct['party_name'];?></option>
                                    <?php } ?>
                                 </select>
                            </div>
                            <div class="mb-3 col-md-6">
                                <label class="form-label">Recieved Amount(Rs.)</label>
                                <input type="text" placeholder="Enter Amount" name="received_amount" id="received_amount" class="form-control" >
                            </div>
                            <div class="mb-3 col-md-6">
                                <label class="form-label">Total Amount(Rs.)</label>
                                <input type="text" value="" id="total_amt" name="total_amt" class="form-control">
                            </div>
                            <div class="mb-3 col-md-12">
                                <label class="form-label">Description</label>
                                <input type="text" placeholder="Description" class="form-control" id="desp" name="desp">
                            </div>
                            <div class="mb-3 col-md-6">
                                <label class="form-label">Payment Type</label>
                                <select class="form-control" name="payment_type" id="payment_type">
                                    <option value="cash">Cash</option>
                                    <option value="cheque-no">Cheque No.</option>
                                    <option value="bank-ac">Bank A/c</option>
                                </select>
                            </div>     
                            <div class="mb-3 col-md-6">
                                <label class="form-label">Bank Name</label>
                                <input type="text" placeholder="" id="bank_name" name="bank_name" class="form-control">
                            </div>
                            
                            <div class="mb-3 col-md-6">
                                <label class="form-label">Opening Balance</label>
                                <input type="text" placeholder="" id="opening_balance" name="opening_balance" class="form-control">
                            </div> 
                            <div class="mb-3 col-md-6">
                                <label class="form-label"> As On</label>
                                <input type="text" value="None" name="as_on" id="as_on" class="form-control">
                                <input type="hidden" name="pt_id" id="pt_id"  class="form-control">
                            </div> 
                            <div class="mb-3 col-md-6">
                                <label class="form-label">Reference No.</label>
                                <input type="text" placeholder="Enter Reference No." id="transaction_id" name="cheque_no"  class="form-control">
                            </div> 
                            <div class="mb-3 col-md-6">
                                <label class="form-label">Images</label>
                                <input type="file" placeholder="" name="image"  class="form-control">
                            </div>  
                            </div>
                            <div class="modal-footer"><button class="btn btn-primary" type="submit" name="update">Update</button></div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="modal fade" id="modalview" data-bs-backdrop="static">
                <div class="modal-dialog dialog-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">View Payment-In 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 table-responsive">
                             <table class="table table-bordered">
                                <thead></thead>
                                <tbody>
                                    <tr>
                                        <td><strong>Receipt No.:</strong></td>
                                        <td>101</td> 
                                        <td><strong>Date:</strong></td>
                                        <td>20-09-2024</td>
                                    </tr>
                                    <tr>
                                        <td><strong>Customer Name:</strong></td>
                                        <td></td> 
                                        <td><strong>Phone No.:</strong></td>
                                        <td></td>
                                    </tr> 
                                    <tr>
                                        <td><strong>Recieved Amount(Rs.):</strong></td>
                                        <td>Rs.</td> 
                                        <td><strong>Total Amount(Rs.):</strong></td>
                                        <td>Rs.</td>
                                    </tr>
                                    <tr>
                                        <td><strong>Description:</strong></td>
                                        <td colspan="3"> </td>  
                                    </tr> 
                                    <tr>
                                        <td><strong>Payment Type:</strong></td>
                                        <td>Cash</td> 
                                        <td><strong>Cheque No.:</strong></td>
                                        <td></td>
                                    </tr>   <!--  
                                    <tr>
                                        <td><strong>Bank Name:</strong></td>
                                        <td> </td> 
                                        <td><strong>Transaction-Id No.:</strong></td>
                                        <td></td>
                                    </tr> -->    
                                    <tr>
                                        <td><strong>Opening Balance:</strong></td>
                                        <td> </td> 
                                        <td><strong>As On:</strong></td>
                                        <td></td>
                                    </tr>      
                                    <tr>
                                        <td><strong>Images:</strong></td>
                                        <td colspan="3">  <img src="" style="width:60px;">  <img src="" style="width:60px;"></td>
                                    </tr>  
                                </tbody>
                            </table>
                        </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 tm_id = $(this).attr("id");
            $.ajax({
                url: "view_item.php",
                method: "POST",
                data: { tm_id: tm_id
                },
                dataType: "json",
                success: function(data) {
                    console.log(data);
                    $('#item_name').val(data.item_name);
                    $('#item_hsn').val(data.item_hsn);
                    $('#item_code').val(data.item_code);
                    $('#tax_type').val(data.tax_type);
                    $('#disc_sale').val(data.disc_sale);
                    $('#disc_type').val(data.disc_type);
                    $('#wholesale_price').val(data.wholesale_price);
                    $('#wtax').val(data.wtax);
                    $('#min_wqty').val(data.min_wqty);
                    $('#purchase_price').val(data.purchase_price);
                    $('#ptax').val(data.ptax);
                    $('#tax_rate').val(data.tax_rate);
                    $('#sale_price').val(data.sale_price);
                    $('#opening_stock').val(data.opening_stock);
                    $('#at_price_unit').val(data.at_price_unit);
                    $('#item_date').val(data.item_date);
                    $('#min_stock_quatity').val(data.min_stock_quatity);
                    $('#item_location').val(data.item_location);
                    // $('#insert').val("Update");
                    $('#modal2').modal('show');
                }
            });
        });
    });   
 $(document).ready(function() {
        $(document).on('click', '.edit_data', function() {
            var pt_id = $(this).attr("id");
            $.ajax({
                url: "edit_paymtout.php",
                method: "POST",
                data: { pt_id: pt_id},
                dataType: "json",
                success: function(data) {
                    console.log(data);
                   $('#receipt_no').val(data.receipt_no);
                    $('#pdate').val(data.receipt_date);
                    $('#customer_id').val(data.customer_id);
                    $('#received_amount').val(data.received_amount);
                    $('#total_amt').val(data.total_amount);
                    $('#desp').val(data.desp);
                    $('#balance').val(data.balance);
                    $('#cheque_no').val(data.cheque_no);
                    $('#bank_name').val(data.bank_name);
                    $('#transaction_id').val(data.transaction_id);
                    $('#opening_balance').val(data.opening_balance);
                    $('#as_on').val(data.as_on);
                    $('#pt_id').val(data.id);
                    $('#insert').val("Update");
                    $('#modaledit').modal('show');
                }
            });
        });
    });   
     function delete_ptype_by_ID(id) {
        if (confirm('Do You Want to Deleting This \nContinue anyway?')) {
            window.location.href = 'delete_paymout.php?id=' + id;
        }
    }
</script>    
</body>

</html>