<?php
$Is_Arabic = Session::getUserPreferences() == 'ar';
?>
<style>
    .table thead tr >th{
        background-color: #4c0870;
        color:#fff;
        width: 20%;
    }
    .table thead tr th[class*='sorting_'] {
        color: #FFFFFF;
    }
    .bg-master-lighter {
        border:none;
        background-color:#fff;
        border-top:1px solid #ddd; 
    }
    .line-dashed{
        border-right :2px solid #4c0870;
        border-right-style: dashed;
    }
    .line-dashed-right{
        border-left :2px solid #4c0870;
        border-left-style: dashed;
    }
    .lined{
        border :2px solid #4c0870;
        border-style: dashed;
    }
    .BestSeller{
        border:2px solid #4c0870;
    }
</style>

<!--<script>
        function AddCommas(val){
                val = parseFloat(val.toString()).toString();
                while (/(\d+)(\d{3})/.test(val.toString())){
                        val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
                }
                return val.replace(/\.0$|\.00$/,"") || "0";
        }
        function FixNumber(val){
                return AddCommas(parseFloat(val+"").toFixed(2));
        }


</script>-->

<div class="container-fluid container-fixed-lg bg-white" style="<?php echo $Is_Arabic ? "height:600px" : "" ?>">
    <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-md-12">
                    <div class="col-md-4 BestSeller" style="margin-left:-10px;">
                        <h3 class="text-center bold"><?php print CommonLanguage::getMessage('product_info'); ?></h3>
                        <label class="bold"><?php print CommonLanguage::getMessage('Product'); ?> : </label> <?php echo $product['Product_Code'] . ' - ' . $product['Product_Name']; ?><br>
                        <label class="bold"><?php print CommonLanguage::getMessage('current_quantity'); ?> : </label> <script> document.write(FixNumber(<?php echo $product['Product_Quantity']; ?>))</script><br>
                        <label class="bold"><?php print CommonLanguage::getMessage('Category'); ?> : </label> <?php echo $product['Cat_Name'] . ' - ' . $product['Category_Name']; ?><br>
                        <label class="bold"><?php print CommonLanguage::getMessage('profit'); ?> : </label> <?php echo $CurrencyDefaultSymbol ?> <script> document.write(FixNumber(<?php echo $product['Profit_Item']; ?>))</script>
                    </div>
                    <div class="col-md-4 BestSeller" style="margin-left:5px;">
                        <h3 class="text-center bold"><?php print CommonLanguage::getMessage('sales_info'); ?></h3>
                        <label class="bold"><?php print CommonLanguage::getMessage('Employee'); ?> : </label> <?php echo $product['Employee_Name']; ?><br>
                        <label class="bold"><?php print CommonLanguage::getMessage('customer'); ?> : </label> <?php echo $product['Customer_Name']; ?><br>
                        <label class="bold"><?php print CommonLanguage::getMessage('Quantity'); ?> : </label> <script> document.write(FixNumber(<?php echo $product['Sold_Quantity']; ?>))</script><br>
                        <label class="bold"><?php print CommonLanguage::getMessage('Price'); ?> : </label> <?php echo $CurrencyDefaultSymbol ?> <script> document.write(FixNumber(<?php echo $product['Sold_Price']; ?>))</script>
                    </div>
                    <div class="col-md-4 BestSeller" style="margin-left:5px;">
                        <h3 class="text-center bold"><?php print CommonLanguage::getMessage('purchase_info'); ?></h3>
                        <label class="bold"><?php print CommonLanguage::getMessage('Employee'); ?> : </label> <?php echo $product['Employee_Name_Purchase']; ?><br>
                        <label class="bold"><?php print CommonLanguage::getMessage('vendor'); ?> : </label> <?php echo $product['Supplier_Name']; ?><br>
                        <label class="bold"><?php print CommonLanguage::getMessage('Quantity'); ?> : </label> <script> document.write(FixNumber(<?php echo $product['Purchased_Quantity']; ?>))</script><br>
                        <label class="bold"><?php print CommonLanguage::getMessage('Price'); ?> : </label> <?php echo $CurrencyDefaultSymbol ?> <script> document.write(FixNumber(<?php echo $product['Purchased_Price']; ?>))</script>
                    </div>
                </div>
                <br>
                <br>
                <br>
                <div class="col-md-12 lined"></div>
                <br>
                <br>
                <div class="col-md-12">
                    <div class="col-md-6 <?php echo $Is_Arabic ? "line-dashed-right" : "line-dashed" ?>">
                        <table class="table table-bordered table-responsive " id="SaledTable">
                            <thead>
                                <tr>
                                    <th class="text-center bold"> <?php print CommonLanguage::getMessage('invoice'); ?>#</th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('Date'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('sold_quantity'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('sold_price'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                for ($x = 0; $x < count($product_sales_details); $x++) {
                                    $CurItem = $product_sales_details[$x];
                                    ?>
                                    <tr>
                                        <td class="text-center"><?php echo $CurItem['Invoice_ID'] ?></td>
                                        <td class="text-center"><?php echo $CurItem['Invoice_Date'] ?></td>
                                        <td class="text-center"><script> document.write(FixNumber(<?php echo $CurItem['Sold_Quantity'] ?>))</script></td>
                                        <td class="text-center"><?php echo $CurrencyDefaultSymbol ?> <script> document.write(FixNumber(<?php echo $CurItem['Sold_Price']; ?>))</script></td>
                                    </tr>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <table class="table table-bordered table-responsive " id="PurchasedTable">
                            <thead>
                                <tr>
                                    <th class="text-center bold"><?php print CommonLanguage::getMessage('purchase'); ?> #</th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('Date'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('purchased_quantity'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('purchased_price'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                for ($x = 0; $x < count($product_purchased_details); $x++) {
                                    $CurItem = $product_purchased_details[$x];
                                    ?>
                                    <tr>
                                        <td class="text-center"><?php echo $CurItem['Purchase_ID'] ?></td>

                                        <td class="text-center"><?php echo $CurItem['Purchase_Date'] ?></td>
                                        <td class="text-center"><script> document.write(FixNumber(<?php echo $CurItem['Purchased_Quantity'] ?>))</script></td>
                                        <td class="text-center"><?php echo $CurrencyDefaultSymbol ?> <script> document.write(FixNumber(<?php echo $CurItem['Purchased_Price']; ?>))</script></td>
                                    </tr>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<nav class="navbar navbar-default bg-master-lighter sm-padding-10" role="navigation" style="<?php echo $Is_Arabic ? "dispaly:inline" : "" ?>">
    <div class="container-fluid">
        <div class="collapse navbar-collapse" id="sub-nav">
            <div class="row"> 
                <div class="col-sm-4 ">
                    <ul class="nav navbar-nav navbar-center">
                        <li><a href="#" data-toggle="tooltip" title="Print" class="PrintThisTableButton" data-currency='<?php echo $CurrencyDefaultName ?>' data-table="#tableWithSearch" data-date="<?php echo $today ?>" data-title="Items History Report  "><i class="fa fa-print"></i></a></li>
                        <li><a href="#" data-toggle="tooltip" data-placement="bottom" title="Download"><i class="fa fa-download"></i></a></li>
                    </ul>
                </div>
                <div class="col-sm-4 pull-right">
                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="#" class="p-r-10"><img width="25" height="25" alt="" class="icon-pdf" data-src-retina="<?php echo SITE_LINK; ?>img/invoice/pdf2x.png" data-src="<?php echo SITE_LINK; ?>img/invoice/pdf2x.png" src="<?php echo SITE_LINK; ?>img/invoice/pdf2x.png"></a>
                        </li>
                        <li>
                            <a href="#" class="p-r-10"><img width="25" height="25" alt="" class="icon-image" data-src-retina="<?php echo SITE_LINK; ?>img/invoice/image2x.png" data-src="<?php echo SITE_LINK; ?>img/invoice/image2x.png" src="<?php echo SITE_LINK; ?>img/invoice/image2x.png"></a>
                        </li>
                        <li>
                            <a href="#" class="p-r-10"><img width="25" height="25" alt="" class="icon-doc" data-src-retina="<?php echo SITE_LINK; ?>img/invoice/doc2x.png" data-src="<?php echo SITE_LINK; ?>img/invoice/doc2x.png" src="<?php echo SITE_LINK; ?>img/invoice/doc2x.png"></a>
                        </li>
                        <li><a href="#" class="p-r-10" onclick="$.Pages.setFullScreen(document.querySelector('html'));return false"><i class="fa fa-expand"></i></a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</nav>
<script>
    var menu;
    $(function () {
        var table = $('#SaledTable,#PurchasedTable');
//		menu = '<div class="block-area" id="custom-select">'
//			+'<div class="row">'
//			+'<div class="col-md-2 m-b-15">'
//			+'<select class="select">'
//			+'<option value="10">10</option>'
//			+'<option value="20">20</option>'
//			+'<option value="30">30</option>'   
//			+'<option value="50">50</option>'
//			+'<option value="100">100</option>'
//			+'<option value="200">200</option>'
//			+'</select>'
//			+'</div>'
//			+'</div>'
//			+'</div>'
//		var settings = {
//			//            "sDom": "<'table-responsive't><'row'<p i>>",
//			//            "sPaginationType": "bootstrap",
//			"destroy": true,
//			"scrollCollapse": true,
//			oLanguage: {
//				sLengthMenu: menu
//			},
//			"iDisplayLength": 10,
//			//           "order": [
//			//                    [0, "desc"]
//			//                ]       
//		};
//		table.dataTable(settings);
        table.dataTable();

    })
</script>
