<?php include("includes/db_config.php"); ?>
<!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;}.mt-35{margin-top:35px!important}.viewptdt .form-label{font-weight:600;}.viewptdt label{margin-top:10px;}.portlet-titles{padding: 15px 20px;font-size: 20px;border-radius: 10px;}.portlet-titles-icon{font-size: 40px;text-align: center}.srchdt label{font-weight: 600;font-size: 14px;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">
                                    <div class="col-md-12">
                                        <h3 class="portlet-title">PROFIT ON SALE INVOICES</h3>
                                    </div>
                                    
                                 </div>
                                <div class="row srchdt"> 
                                     <div class="col-md-2 col-12 col-xs-12" style="margin-left:15px;">
                                         <label><b>From</b></label>
                                       <input type="date" id="from_date" class="form-control">
                                    </div>
                                    <div class="col-md-2 col-12 col-xs-12">
                                        <label><b>To</b></label>
                                       <input type="date" id="to_date" class="form-control">
                                    </div>
                                    <div class="col-md-2 col-12 col-xs-12"> 
                                       <input type="submit" class="btn btn-success btn-lg mt-35" value="Submit">
                                    </div>
                                    </div>  
                                   <div class="portlet-body table-responsive">
                                    <table id="datatable-1" class="table table-bordered table-striped table-hover">
                                        <thead>
                                             <tr>
                                                <th>#</th>
                                                <th>Date</th>
                                                <th>Invoice No</th>
                                                <th>Party</th>
                                                <th>Total Sale Amount</th>
                                                <th>Profit(+)/Loss(-)</th>
                                                 <th> <center>Details</center></th>
                                            </tr>
                                        </thead>
                                        <tbody id="report_data"> 
                                            <!-- <tr>
                                                <td>1.</td>
                                                <td>06-03-2025</td>
                                                <td>1</td>
                                                <td>Raj Kumar</td>
                                                <td>₹ 1200.00</td>
                                                <td><font style="color:green">₹ 1200.00</font></td>
                                                 <td>
                                                    <center> 
                                                       <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#static">Show</button> 
                                                    </center>
                                                </td>
                                            </tr>  -->
                                         </tbody>
                                        <tfoot>
                                        <!-- <tr>
                                            <th colspan="2"><b>Summary</b></th>
                                            <th colspan="2"><b>Total Sale Amount : ₹ 1200.00</b></th>
                                            <th colspan="3"><b>Total Profit(+)/Loss(-) : <font style="color:green">₹ 1200.00</font></b></th>
                                            </tr> -->
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>       
            <div class="modal fade" id="static" data-bs-backdrop="static"> 
                <div class="modal-dialog dialog-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">Invoice: -Raj Kumar</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">
                                <table id="datatable-1" class="table table-bordered table-striped table-hover">
                                        <thead><tr><th colspan="2">Cost Calculations</th></tr> </thead>
                                        <tbody> 
                                           <tr>
                                                <td>Sale Amount</td>
                                                <td>₹ 1200.00</td> 
                                            </tr>
                                            <tr>
                                                <td>Total Cost</td>
                                                <td>₹ 0.00</td> 
                                            </tr> 
                                            <tr>
                                                <td>Tax Payable</td>
                                                <td>₹ 0.00</td> 
                                            </tr> 
                                            <tr>
                                                <td>TDS Receiable</td>
                                                <td>₹ 0.00</td> 
                                            </tr> 
                                            <tr>
                                                <td>Profit (Sale Amount - Total Cost - Tax Payable -  TDS Receiable)</td>
                                                <td>₹ 1200.00</td> 
                                            </tr>
                                            <tr>
                                                <td>Profit (Excluding Additional Charges)</td>
                                                <td>₹ 1200.00</td> 
                                            </tr> 
                                         </tbody>
                                </table>
                            </div> 
                        </form>
                    </div>
                </div>
            </div>
          
            <?php include("includes/footer.php");?>
        </div>
    </div>
    <?php include("includes/js.php");?>
<script type="text/javascript">
      function delete_ptype_by_ID(id) {
        if (confirm('Do You Want to Deleting This \nContinue anyway?')) {
            window.location.href = 'delete_purchase.php?id=' + id;
        }
    }
    </script>
    <script>
        $(document).ready(function(){
            // Fetch all data on page load
            fetchData();

            // Fetch filtered data when clicking Search
            $("#search").click(function(){
                var from_date = $("#from_date").val();
                var to_date = $("#to_date").val();
                fetchData(from_date, to_date);
            });

            function fetchData(from_date = '', to_date = '') {
                $.ajax({
                    url: "fetch_profit_report.php",
                    type: "POST",
                    data: {from_date: from_date, to_date: to_date},
                    success: function(response){
                        $("#report_data").html(response);
                    }
                });
            }
        });
        </script>
</body>
</html>