<!DOCTYPE html>
<html>
<head>
    <?= View::make('base.head'); ?>
    <title></title>
</head>
<body>
    <?= View::make('base.header'); ?>	        
    <?= View::make('base.messages',array("errors"=>$errors)); ?>
    <div class="conteudo">
        <h2>Produtos</h2><br><br>

        <table id="dados" class="display compact" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th style="width: 500px">Produto</th>
                    <th>Código</th>                    
                    <th>Grupo</th>
                    <th style="width: 110px">Preço</th>
                    <th style="width: 150px">Custo</th>
                    <th>Local2</th>
                    <th>Local3</th>
                    <th>Ativo</th>
                    <th>Novo</th>
                    <th style="width: 130px">Ação</th>
                </tr>
            </thead>		
            <tbody>
            <?php  foreach($list as $ls){ ?>
                <tr>
                    <td title="<?php echo $ls['name']; ?>"><?php echo str_limit($ls['name'],60); ?></td>
                    <td><?php echo $ls['code']; ?></td>                    
                    <td><?php echo $ls['product_group']; ?></td>
                    <td><?php echo OrderSysUtils::ftn($ls['price'], 4); ?></td>
                    <td><?php echo OrderSysUtils::ftn($ls['cost'], 4); ?></td>
                    <td><?php echo OrderSysUtils::ftn($ls['local2'], 4); ?></td>
                    <td><?php echo OrderSysUtils::ftn($ls['local3'], 4); ?></td>
                    <td><?php echo $ls['active'] ? 'Sim' : 'Não'; ?></td>
                    <td><?php echo empty($ls['updated_by_user_at']) ? 'S' : 'N'; ?></td>
                    <td><a href="/app/product/show/<?= $ls['id'];?>" target="_blank">Editar</a> | 
                        <a href='javascript:openProductAnalysisView(<?= $ls['id'];?>)'>Analisar</a> </td>
                </tr>
            <?php } ?>
            </tbody>
        </table>
    </div>
</body>
<script type="text/javascript">
        $(document).ready(function() {
            $('#dados').dataTable( {
                "pagingType": "full_numbers",
                "iDisplayLength": 100,
                "language": {
                    "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Portuguese.json"
                }
            });
        });
        
        function openProductAnalysisView(productId) {
            openInNewTab('<?php echo action('ProductAnalysisController@getProductAnalysisView'); ?>?productId=' + productId);
        }
</script>
</html>

