
<?php
    $doctors = $db->selectAll('doctor','where base_id='.$userData['base_id'])   ;
    $product_finished=$db->getProductData('and type= '.PRODUCT_TYPE_FINISHED);
    $product_gift=$db->getProductData('and type= '.PRODUCT_TYPE_GIFT_ITEM);
    $hours=[];
    $minuet =[] ;
    for($i=0;$i<60;$i++){
        $title = ($i<10)?'0'.$i:strval($i);  
        $minuet[$title]  = $title;
    }
    for($i=0;$i<24;$i++){
        $title = ($i<10)?'0'.$i:strval($i);  
        $hours[$title]  = $title;
    }

?>
<script type="text/javascript">
    <?=  'var product_details={finished:'.json_encode($product_finished).',gift:'.json_encode($product_gift).'};'?>
    $(document).on('change','#finished-product-id',function(){
        product_details_load('finished');
    });
    $(document).on('change','#gift-product-id',function(){
        product_details_load('gift');
    }); 

</script>
<section class="mb-4" id="sale_area">
    <div class="card">
        <div class="card-header text-center py-3"> 
            <h5 class="mb-0 text-center">
                <strong>Doctor visit</strong>
            </h5>
        </div>
        <div class="card-body">

            <?php
                include 'visit_date_time_input.php';
            ?>
        
            <?php $general->inputBoxSelect($doctors,'Doctor','doctor-id','id','name',haveSelect:'Select doctor');?> 

            <?php $general->inputBoxText('prescription','Prescription');?>
            <?php $general->inputBoxTextArea('note','Note');?>
            <hr/> 
            <h4>Finished product</h4>
            <?php $general->inputBoxSelect($product_finished,'Product','finished-product-id','id','t');?>
            <div class="form-group row">
                <label for="qty" class="col-md-4 col-form-label">Quantity</label>
                <div class="col-md-8">
                    <div class="input-group qty-input-group">
                        <input class="form-control amount_td" value="" placeholder="Quantity" id="finished-quantity" type="text">
                        <div class="input-group-append">
                            <span class="input-group-text" id="finished-unit">--</span>
                        </div>
                    </div>
                </div>
            </div>
            <hr/>
            <div>
                <button class="form-control btn btn-info" onclick="visit_card_add('finished')">Add to cart</button>
            </div>

            <div class="table-responsive">
                <table class="table table-striped" id="reportTable">
                    <thead>
                        <tr>
                            <th  style="width: 2%;">#</th>
                            <th>Product</th>
                            <th>Unit</th>

                            <th class="amount_td">Qty</th>
                            <th style="width: 2%;" class="amount_td">X</th>
                        </tr>
                    </thead>
                    <tbody id="finished-product">

                    </tbody>

                </table>
            </div>
            <h4>Gift product</h4>
            <?php $general->inputBoxSelect($product_gift,'Product','gift-product-id','id','t');?>
            <div class="form-group row">
                <label for="qty" class="col-md-4 col-form-label">Quantity</label>
                <div class="col-md-8">
                    <div class="input-group qty-input-group">
                        <input class="form-control amount_td" value="" placeholder="Quantity" id="gift-quantity" type="text">
                        <div class="input-group-append">
                            <span class="input-group-text" id="gift-unit">--</span>
                        </div>
                    </div>
                </div>
            </div>
            <hr/>
            <div>
                <button class="form-control btn btn-info" onclick="visit_card_add('gift')">Add to cart</button>
            </div>

            <div class="table-responsive">
                <table class="table table-striped" id="reportTable">
                    <thead>
                        <tr>
                            <th  style="width: 2%;">#</th>
                            <th>Product</th>
                            <th>Unit</th>

                            <th class="amount_td">Qty</th>
                            <th style="width: 2%;" class="amount_td">X</th>
                        </tr>
                    </thead>
                    <tbody id="gift-product">

                    </tbody>

                </table>
            </div>
            <div><button  onclick="doctor_visit()" class="mt-1 btn-lg btn-success pull-right doctor_visit">SUBMIT</button></div>
        </div>
    </div>
</section>
<div style="display: none;">
    <table>
        <tbody>
            <tr id="card-product">
                <td class="autoSerial"></td>
                <td>
                    <input type="hidden" class="product-id" value="">
                    <span class="product-title"></span>
                </td>
                <td class="unit"></td>
                <td class="qty amount_td"></td>
                <td class="amount_td"><button class="btn btn-danger remove">X</button></td>
            </tr>
        </tbody>
    </table>
</div>