<?php include'header.php'; ?>	

<div class="app-content content">
    <div class="content-overlay"></div>
    <div class="content-wrapper">
        <div class="content-header row"></div>
        <div class="content-body">

                <div class="row">
                    <div class="col-12">
                        <div class="card">

                            <div class="card-header">
                                <h4 class="card-title mb-1">Tax Slabs</h4>
                            </div>

                            <div class="card-content">
                                <div class="card-body">

<div class="modal-info d-inline-block">
    <button type="button" class="btn btn-info" data-toggle="modal" data-target="#addPlan">Add Tax Slabs</button>

    <!-- Add Plan Modal -->
    <div class="modal fade text-left" id="addPlan" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable" role="document">
            <div class="modal-content">
                
                <div class="modal-header bg-info">
                    <h5 class="modal-title white">Add New Tax Slabs</h5>
                    <button type="button" class="close" data-dismiss="modal">
                        <i class="bx bx-x"></i>
                    </button>
                </div>

                <div class="modal-body">

<form class="form" action="" method="POST">
    <div class="form-body">
        <div class="row">
            <div class="col-md-4 mt-1">
    <div class="form-label-group position-relative has-icon-left">
        
        <select class="form-control" name="state" required>
            <option value="">Select state</option>
            <?php
$obj->sql("SELECT * FROM state ORDER BY id ASC");
$result = $obj->getResult();
foreach ($result as $row) { ?>
<option value="<?php echo $row['name'];?>"><?php echo $row['name'];?></option>
            <?php } ?>
        </select>

        <div class="form-control-position">
            <i class="bx bx-user"></i>
        </div>

        <label>State</label>
    </div>
</div>
           <div class="col-md-4 mt-1">
                <div class="form-label-group position-relative has-icon-left">
                    <input type="text" class="form-control" name="duration" placeholder="Duration" required>
                    <div class="form-control-position"><i class="bx bx-package"></i></div>
                    <label>Duration</label>
                </div>
            </div>
            <div class="col-md-4 mt-1">
                <div class="form-label-group position-relative has-icon-left">
                    <input type="decimal" class="form-control" name="amount" placeholder="amount" required>
                    <div class="form-control-position"><i class="bx bx-package"></i></div>
                    <label>Amount</label>
                </div>
            </div>
            <!-- Buttons -->
            <div class="col-md-12 d-flex justify-content-end">
                <button type="submit" class="btn btn-primary mr-1 mb-1" name="add_tax_slabs">Submit</button>
                <button type="reset" class="btn btn-light-secondary mr-1 mb-1">Reset</button> 
            </div>

        </div>
    </div>
</form>

                </div>

                <div class="modal-footer">
                    NOTE: <i>Please Enter All Detail Carefully.</i>
                </div>

            </div>
        </div>
    </div>
</div>
 

<!-- CUSTOMER LIST TABLE -->
<div class="table-responsive col-md-12 s-right mt-2">
    <table class="table table-striped">
        <thead>
            <tr>
                <th>state</th>
                <th>duration</th>
                <th>amount</th>
                <th>Action</th>
            </tr>
        </thead>

        <tbody>
<?php
$obj->sql("SELECT * FROM tax_slabs ORDER BY id DESC");
$result = $obj->getResult();
foreach ($result as $row) { ?>
    <tr>
        <td><?php echo $row['state']; ?></td>
        <td><?php echo $row['duration']; ?></td>
        <td><?php echo $row['amount']; ?></td>
        <td>
            <button type="button" title="Edit" data-toggle="modal" data-target="#edit<?php echo $row['id']; ?>" class="btn btn-icon rounded-circle btn-light-success mr-1"><i class="bx bxs-pencil"></i></button>
            	<div class="modal fade text-left" id="edit<?php echo $row['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel110" style="display: none;" aria-hidden="true">
            		<div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable" role="document">
            			<div class="modal-content">
            				<div class="modal-header bg-info">
            					<h5 class="modal-title white" id="myModalLabel110">Edit</h5>
            					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
            						<i class="bx bx-x"></i>
            					</button>
            				</div>
            				<div class="modal-body">									
                                <form class="form" action="" method="POST">
                                    <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
                                    <div class="form-body">
                                        <div class="row">
                                <div class="col-md-4 mt-1">
    <div class="form-label-group position-relative has-icon-left">
        
        <select class="form-control" name="state" required>
            <option value="">Select State</option>

            <?php
            $selected_state = $row['state']; // current state id for edit

            $obj->sql("SELECT * FROM state ORDER BY id ASC");
            $result1 = $obj->getResult();

            foreach ($result1 as $row1) { 
            ?>
                <option value="<?php echo $row1['name']; ?>"
                    <?php if($selected_state == $row1['name']){ echo 'selected'; } ?>>
                    
                    <?php echo $row1['name']; ?> 
                </option>
            <?php } ?>

        </select>

        <div class="form-control-position">
            <i class="bx bx-user"></i>
        </div>

        <label>State</label>
    </div>
</div>
                                           
                                             <div class="col-md-4 mt-1">
                                                <div class="form-label-group position-relative has-icon-left">
                                                    <input type="text" class="form-control" name="duration" placeholder="Duration" value="<?php echo $row['duration']; ?>" required>
                                                    <div class="form-control-position"><i class="bx bx-package"></i></div>
                                                    <label>Duration</label>
                                                </div>
                                            </div>
                                               <div class="col-md-4 mt-1">
                                                <div class="form-label-group position-relative has-icon-left">
                                                    <input type="decimal" class="form-control" name="amount" placeholder="Amount" value="<?php echo $row['amount']; ?>" required>
                                                    <div class="form-control-position"><i class="bx bx-package"></i></div>
                                                    <label>Amount</label>
                                                </div>
                                            </div>
                                            <div class="col-md-12 d-flex justify-content-end">
                                                <button type="submit" class="btn btn-primary mr-1 mb-1" name="edit_tax_slabs">Submit</button>
                                                <button type="reset" class="btn btn-light-secondary mr-1 mb-1">Reset</button>
                                            </div>
                                
                                        </div>
                                    </div>
                                </form>
            
                            </div>
            				<div class="modal-footer">
            					NOTE: <i>Fill Details Carefully.</i>
            				</div>
            			</div>
            		</div>
            	</div>              

            <button type="button" title="Delete" data-toggle="modal" data-target="#delete<?php echo $row['id']; ?>" 
            class="btn btn-icon rounded-circle btn-light-danger mr-1">
                <i class="bx bxs-trash"></i>
            </button>
            <div class="modal fade text-left" id="delete<?php echo $row['id']; ?>" tabindex="-1" role="dialog">
                <div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable">
                    <div class="modal-content">
                        <div class="modal-header bg-danger">
                            <h5 class="modal-title white">Delete</h5>
                            <button type="button" class="close" data-dismiss="modal"><i class="bx bx-x"></i></button>
                        </div>
            
                        <div class="modal-body">
                            <form class="form" action="" method="POST">
                                <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
                                <input type="hidden" name="table" value="tax_slabs">
            
                                <div class="d-flex justify-content-end">
                                    <button type="submit" class="btn btn-danger mr-1 mb-1" name="delete">Delete</button>
                                    <button type="reset" class="btn btn-light-secondary mr-1 mb-1">Reset</button>
                                </div>
                            </form>
                        </div>
            
                        <div class="modal-footer">
                            NOTE: <i>This action cannot be undone.</i>
                        </div>
                    </div>
                </div>
            </div>
        </td>
    </tr>
<?php } ?>
        </tbody>
    </table>
</div>

                        </div><!-- card-content -->
                    </div><!-- card -->
                </div>
            </div>
        </section>

    </div>
</div>
</div>
</div>

<div class="sidenav-overlay"></div>

<?php include'footer.php'; ?>
