<style>
    .table thead tr >th{
        background-color: #4c0870;

        color:#fff;
    }
    .table thead tr th[class*='sorting_'] {
        color: #FFFFFF;
    }
    .bg-master-lighter {
        border:none;
        background-color:#fff;
        border-top:1px solid #ddd; 
    }
    .btn-default{
        border: none;
        background-color: #eee;
    }
    .btn-default:hover{
        background-color:#4c0870!important;
        color:#fff;
        border: none;
    }
    .BestSeller{
        border:2px solid #4c0870;
    }
    .line-dashed{
        border :2px solid #4c0870;
        border-style: dashed;

    }





</style>
<script>

    // to remove many digits after the period
//    $(function () {
//        $(".ValSpan").each(function () {
//            $(this).html(AddCommas(parseFloat($.trim($(this).text())).toFixed(3)))
//        })
//    })
</script>

<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"> <?php print CommonLanguage::getMessage('history_report_item'); ?></div>
            <div class="panel-body">
                <div class="col-xs-12 col-md-12 PrintDiv">
                    <div class="col-xs-4 col-md-4 BestSeller" style="margin-left:-10px">
                        <h4 class="text-center bold"><?php print CommonLanguage::getMessage('best_seller_item_price'); ?></h4>
                        <label class="bold"><?php print CommonLanguage::getMessage('Item'); ?> : <?php echo $product['Best_Seller_Price_ID'] ?> </label> <br>
                        <label class="bold "><?php print CommonLanguage::getMessage('Price'); ?> : <?php echo $CurrencyDefaultSymbol ?></label><label class="bold "> <?php echo Forms::DecimalNumber ($product['Best_Seller_Price'] )?></label> 

                    </div>
                    <div class="col-xs-4 col-md-4 BestSeller" style="margin-left:5px">
                        <h4 class="text-center bold"><?php print CommonLanguage::getMessage('best_seller_item_qty'); ?></h4>
                        <label class="bold"><?php print CommonLanguage::getMessage('Item'); ?> : <?php echo $product['Best_Seller_Quantity_ID'] ?></label> <br>
                        <label class="bold "><?php print CommonLanguage::getMessage('Quantity'); ?> :</label> <label class="bold "> <?php echo $product['Best_Seller_Quantity'] ?></label>
                    </div>
                    <div class="col-xs-4 col-md-4 BestSeller" style="margin-left:5px">
                        <h4 class="text-center bold"><?php print CommonLanguage::getMessage('best_seller_item_profit'); ?></h4>
                        <label class="bold"><?php print CommonLanguage::getMessage('Item'); ?> : <?php echo $product['Best_Profit_Item'] ?></label>  <br>
                        <label class="bold "><?php print CommonLanguage::getMessage('profit'); ?> : <?php echo $CurrencyDefaultSymbol ?></label><label class="bold "> <?php echo Forms::DecimalNumber($product['Best_Profit_Price']) ?></label>
                    </div>
                </div>
                <br>

                <br>
                <br>
                <div class="col-md-12 line-dashed"></div>
                <br>
                    <div class="col-md-4 col-sm-height col-bottom sm-no-padding sm-p-b-20" style="vertical-align: top;">
                                <div  class="form-group form-group-default input-group">
                                    <label><?php print CommonLanguage::getMessage('Date'); ?></label>
                                    <input id="Purchase_Invoice_Date" name="Purchase_Invoice_Date" class="form-control" value="<?php echo ($today); ?>" />
                                    <span class="input-group-addon primary"><i class="fa fa-calendar"></i></span>
                                </div>
                </div>
                
                
                
                
                
                <p style="margin:0px auto;font-size:1.3em;text-align:center;font-weight:bold"> <?php print CommonLanguage::getMessage('Currency'); ?>: <?php echo $CurrencyDefaultSymbol ?> </p>
                <table class="table table-bordered table-responsive table-hover" id="tableWithSearch">
                    <thead>
                        <tr>
                            <th class="text-center" style="width:16%;"><?php print CommonLanguage::getMessage('barcode'); ?></th>
                            <th class="text-center" style="width:16%;"><?php print CommonLanguage::getMessage('Name'); ?></th>
                            <th class="text-center" style="width:10%;"><?php print CommonLanguage::getMessage('Type'); ?></th>
                            <th class="text-center"><?php print CommonLanguage::getMessage('sold_quantity'); ?></th>
                            <th class="text-center"><?php print CommonLanguage::getMessage('sold_price'); ?></th>
                            <th class="text-center"><?php print CommonLanguage::getMessage('purchased_quantity'); ?></th>
                            <th class="text-center"><?php print CommonLanguage::getMessage('purchased_price'); ?></th>
                            <th class="text-center"><?php print CommonLanguage::getMessage('current_quantity'); ?></th>
                            <th class="text-center"><?php print CommonLanguage::getMessage('item_profit'); ?></th>
<?php if ($permissions->hasPermission('HistoryReportForItemDetails')) { ?>
                                <th class="text-center  no-print"><?php print CommonLanguage::getMessage('Action'); ?></th>
                        <?php } ?>
                        </tr>
                    </thead>
                    <tbody>
<?php
for ($i = 0; $i < count($product) - 6; $i++) {
    $CurItem = $product[$i];
    ?>
                            <tr>
                                <td class="text-center"><?php echo $CurItem['Bar_Code'] ?></td>
                                <td class="text-center"><?php echo $CurItem['Name'] ?></td>
                                <td class="text-center"><?php echo $CurItem['Category_Name'] ?></td>
                                <td class="text-center ValSpan bold"><strong><?php echo $CurItem['Sold_Quantity'] ?></strong></td>
                                <td class="text-center "> <?php echo Forms::DecimalNumber($CurItem['Sold_Price']) ?></td>
                                <td class="text-center ValSpan" ><?php echo $CurItem['Purchased_Quantity'] ?></td>
                                <td class="text-center "> <?php echo Forms::DecimalNumber($CurItem['Purchased_Price']) ?></td>
                                <td class="text-center ValSpan"><?php echo $CurItem['Current_Quantity'] ?></td>
                                <td class="text-center  bold"><strong> <?php echo Forms::DecimalNumber($CurItem['Profit_Item']) ?></strong></td>
                                <?php if ($permissions->hasPermission('HistoryReportForItemDetails')) { ?>
                                    <td class="text-center no-print"> <div class='btn-group'>
                                            <a style="opacity: 1;" href="<?php echo SITE_LINK; ?>Inventory/HistoryReportForItemsDetails/<?php echo $CurItem['ID']; ?>"> <button type='button' class='btn btn-default'><i class='fa fa-eye'> <?php print CommonLanguage::getMessage('view') ?></i></button></a>
                                        </div>
                                    </td>
    <?php } ?>
                            </tr>
<?php } ?>
                    </tbody>
                </table>
            </div>
        </div>






    </div>

</div>

<script>
      var title = <?php echo json_encode(CommonLanguage::getMessage('history_report_item')); ?>;
$(function() {
    
    $("#Purchase_Invoice_Date").datepicker({autoclose: true}).on("changeDate", function (e) {
          
      getReportList()
        });
    
    $('#tableWithSearch').dataTable()
    
    
    
})
       function getReportList(){
    
        var CurrentDate = { freq:$("#Purchase_Invoice_Date").val()}  ;
       
            $('#tableWithSearch').DataTable().destroy();
            $("#tableWithSearch tbody").empty();
            $.ajax({
                url:"InventoryAjax/HistoryReportForItem",
                data:CurrentDate,
                dataType: 'json',
                complete:function(v1,v2){
                    if(v2 == "success"){
                        var Data  = (v1.responseJSON);
                        var l = (Object.keys(Data).length);
                        for(var i=0;i<l-6;i++){
                            var TR  = "<tr>"
                            
                            TR += "<td class=' v-align-middle text-center bold'>"+Data[i]["Bar_Code"]+"</td>"
                            TR += "<td class=' v-align-middle text-center'>"+Data[i]["Name"]+"</td>"
                            TR += "<td class=' v-align-middle text-center'>"+Data[i]["Category_Name"]+"</td>"
                            TR += "<td class=' v-align-middle text-center'>"+Data[i]["Sold_Quantity"]+"</td>"
                            TR += "<td class=' v-align-middle text-center ValSpan'>"+addCommas(Data[i]["Sold_Price"])+"</td>"
                            TR += "<td class=' v-align-middle text-center'>"+Data[i]["Purchased_Quantity"]+"</td>"
                            TR += "<td class=' v-align-middle text-center ValSpan'>"+addCommas(Data[i]["Purchased_Price"])+"</td>"
                            TR += "<td class=' v-align-middle text-center'>"+Data[i]["Current_Quantity"]+"</td>"
                            TR += "<td class=' v-align-middle text-center ValSpan'>"+addCommas(Data[i]["Profit_Item"])+"</td>"
                            TR += "<td class=' v-align-middle text-center'><div class='btn-group'><a style='opacity:1'href='<?php echo SITE_LINK; ?>Inventory/HistoryReportForItemsDetails/"+Data[i]["ID"]+"'> <button type='button' class='btn btn-default'><i class='fa fa-eye'> <?php print CommonLanguage::getMessage('view') ?></i></button></a></div></td>"
                            TR += "</tr>"


                            TR = $(TR)
                            $("#tableWithSearch").append(TR)


                        }
                    }
                    RebuildTable()
                }
            })
    
    }
    
      function RebuildTable(){
        $('#tableWithSearch').dataTable();
     
    }
    
 
    
    
    
</script>





