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


<div class="content-wrapper">
        <section class="content-header">
            <h1>Price Update</h1>
            <ol class="breadcrumb">
                <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Price Update</li>            
            </ol>
        </section>


        <div class="col-lg-12 alerts">
            <div id="custom-alerts" style="display:none;">
                <div class="alert alert-dismissable">
                    <div class="custom-msg"></div>
                </div>
            </div>
            
            <?php if ($error)  { ?>
            <div class="alert alert-danger alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-ban"></i> Error</h4>
                <?= $error; ?>
            </div>
            
            <?php $error=0;} if ($warning) { ?>
            <div class="alert alert-warning alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-warning"></i> Warning</h4>
                <?= $warning; ?>
            </div>
            
            <?php  $warning=0;} if ($message) { ?>
            <div class="alert alert-success alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4>    <i class="icon fa fa-check"></i> Success</h4>
                <?= $message; ?>
            </div>
            <?php $message=0; } ?>
            
        </div>
        <div class="clearfix"></div>







<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary" style="box-shadow: rgba(0, 0, 0, 0.16) 0px 3px 6px, rgba(0, 0, 0, 0.23) 0px 3px 6px;">
                
                <div class="box-body">
                    
                    
                    
                    <div class="col-lg-12" id="content-div">

                        <form id="form_details" autocomplete="off">
                                                                 
                        <div class="row">
                            
                            
                            
                            <?php foreach($price_results as $today){ ?>
                
                <input type="hidden" name="ids[]" value="<?=$today['id']?>">
                                    <div class="row" style="margin-top: 5px;">
                                        
                                        <div class="col-lg-3">
                                            <div class="form-group" style="">
                                                <label for="product_ids">Product Name</label> 
                                                <select name="product_ids[]" id="product_ids" class="form-control select2" style="width: 100%;">
                                                    <?php $statement = $pdo->prepare("SELECT * FROM `tbl_ids_products` WHERE status=1 and id=?");
                                                        $statement->execute(array($today['product_id']));
                                                        $resultss = $statement->fetchAll(PDO::FETCH_ASSOC); 
                                                        foreach ($resultss as $ress) { ?>
                                                            <option value="<?=$ress['id']?>"><?=$ress['name']?></option>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        <div class="col-lg-3">
                                            <div class="form-group" style="">
                                                <label for="purity_ids">Karat</label> 
                                                <select name="purity_ids[]" id="purity_ids" class="form-control select2" style="width: 100%;">
                                                    <?php $statement = $pdo->prepare("SELECT * FROM `tbl_ids_purity` WHERE status=1 and id=?");
                                                        $statement->execute(array($today['purity_id']));
                                                        $resultss = $statement->fetchAll(PDO::FETCH_ASSOC); 
                                                        foreach ($resultss as $ress) { ?>
                                                            <option value="<?=$ress['id']?>"><?=$ress['name']?></option>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="col-lg-3">
                                            <div class="form-group">
                                                <label for="amount">Today Price <i class="fa fa-inr"></i></label> 
                                                <input type="text" name="amount[]" class="form-control" id="amount" value="<?=$today['amount']?>" placeholder="Today Price" required style="width: 100%;">
                                            </div>
                                        </div>
                                        
                                    </div>
                                    
                <?php } ?>
                      
                            
                            
                            
                            
                        </div>
                        
                        
                        

                        <div class="form-group" style="text-align:center;">
                            <input type="submit"  id="submit" value="Price Update" class="btn btn-success" />
                        </div>
                        
                    </form>

                    </div>
                    
                    
                    
                    
                    
                    
                    
                    
                    
<div class="container" id="loading-div" style="display: none; margin-top: 20px; margin-bottom: 20px;">
        <center> <img src="img/loading.gif" style="width: 250px;"><br><b class="blinking">Processing Please Wait...</b></center>
</div>
                    
                    
                    
                    
                    <div class="container" id="success-div" style="display: none; margin-top: 40px; margin-bottom: 40px;">
                        <center><b class="blinking" style="font-size:22px;">Today Price Updated Successfully...</b><br>
                            <img src="img/success.gif" style="width: 250px;">
                            <br><br>
                            <a href="price-update.php"><button class="btn btn-warning"><i class="fa fa-plus"></i> Reset Form</button></a>
                            &nbsp;&nbsp;
                            <a href="index.php"><button class="btn btn-success"><i class="fa fa-list"></i> Back to Dashboard</button></a>
                        </center>
                    </div>
                    
                    
                    
                    
                    
                    
                        <!--<div class="form-group" style="text-align:center;">
                            <a href="customers-add.php"><button class="btn btn-primary" ><i class="fa fa-refresh"></i> Reset Form</button></a>
                            <a href="customers.php"><button class="btn btn-warning" ><i class="fa fa-chevron-left"></i> Back to List</button></a>
                        </div>-->
                         
                         
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
</section>


<?php include "footer.php"; ?>
<!--<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>-->
<style>
/*.select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: rgb(228, 228, 228);
    box-sizing: border-box;
    display: inline-block;
    margin-left: 5px;
    margin-top: 5px;
    position: relative;
    max-width: 100%;
    text-overflow: ellipsis;
    vertical-align: bottom;
    white-space-collapse: collapse;
    text-wrap: nowrap;
    border-width: 1px;
    border-style: solid;
    border-color: rgb(170, 170, 170);
    border-image: initial;
    border-radius: 4px;
    padding: 0px 10px 0px 20px;
    overflow: hidden;
    color: black;
    font-weight: 800;
}
.select2-container--default .select2-selection--multiple {
    background-color: white;
    border: 1px solid #aaa;
    border-radius: 4px;
    cursor: text;
    height: 100px;
    padding-bottom: 5px;
    padding-right: 5px;
    position: relative;
}*/
</style>

<script>
$(document).ready(function() {
   $('#form_details').on('submit', function(e){
                e.preventDefault();
                // $('#loading-div').show();
                $('#content-div').hide();
                $("#submit").prop('disabled', true);
                var formData = new FormData(this);
                formData.append('type', 'update_price');
                            $.ajax({
                            url: 'apis/update_price.php',
                            type: 'post',
                            dataType: 'json',
                            data: formData,
                            cache: false,
                            contentType: false,
                            processData: false,
                            enctype: 'multipart/form-data',
                            success: function (response) {
                                console.log(response);
                                if(response['status']==200){
                                     /*alert(response['message']);*/
                                     toastr.success(response['message']);
                                     $("#submit").prop('disabled', false);
                                     setTimeout(function(){window.location.href="index.php"},2000);
                                    //  $('#success-div').show();
                                    //  $('#loading-div').hide();
                                    
                                    
                                }else{
                                   toastr.error(response['message']);
                                    $("#submit").prop('disabled', false);
                                    $('#loading-div').hide();
                                    $('#content-div').show();
                                }
                            }
                        });
   });
});
</script>