<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
       <table class="pull-right">
       <td style="padding-right:10px">  <p><?php echo $entry_confirm; ?></p></td>
        <td style="padding-right:10px">

        <form  method="post" id="form_user" >
   <select name="user" id="user" onclick="$('#user').selected;" class="form-control">
       <?php foreach ($users as $user) { ?>
        <option  <?php if ($username==$user['username'])echo 'selected' ?> value="<?php echo $user['user_id']; ?>"><?php echo $user['username'];?>
        </option>
        <?php } ?>
   </select>
  </form></td>
           <td> <div class="pull-right">
                   <?php foreach ($today as $todays) { ?>
                       <?php if(date('Y-m-d')!=$todays['booking_date'] OR $modify!=false){
                           if($services){ ?>

                           <button type="button" data-toggle="tooltip" title="<?php echo $button_allConfirm; ?>" class="btn btn-checked" onclick="$('#form-product').submit(); confirm_product(0);"><i class="fa fa-check-circle-o"></i></button><?php  break;}
                           break;} ?>
                   <?php } ?>
               </div></td>
         <td>
             <button  id="report"   onclick="report();"  class="btn btn-primary"><i class="fa fa-print"></i></button>
             <a href="<?php echo $back; ?>" data-toggle="tooltip" title="<?php echo $button_back; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a>
         </td>

       </table>
      <h1><?php echo $heading_title; ?></h1>
      <ul class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
        <?php } ?>
      </ul>
    </div>
  </div>
  <div class="container-fluid">
 <?php if ($error_warning) { ?>
    <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>
    <?php if ($success) { ?>
    <div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $success; ?>
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-list"></i> <?php echo $text_list; ?></h3>
      </div>
        <div class="panel-body">
        <table  class="table well" >
            <form name="form-report" action="<?php echo $action;?>" method="post">
            <tr>

                    <td>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <input type="text" name="date" value="<?php echo $booking_date;?>" placeholder="Дата поступления" data-date-format="YYYY-MM-DD" id="input-date-available" class="form-control">
                                <span class="input-group-btn">
                    <button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
                    </span></div>
                        </div>
                    </td>
                    <td>
                        <select name="status"   style="background: #f56b6b;" class="form-control" >
                            <?php foreach ($all_status as $status){ ?>
                                <option  <?php if($status['id']==$product_status_id ){ echo 'selected';}?> value="<?php echo $status['id'];?>"><?php echo $status['name'];?></option>
                            <?php } ?>

                        </select>
                    </td>
                    <td>
                        <select name="report_id" class="form-control" >
                            <?php foreach ($report as $item) {?>
                                <option <?php if($report_id==$item['id']){ echo 'selected';}?> value="<?php echo $item['id']; ?>"><?php echo $item['name']; ?></option>
                            <?php }?>

                        </select>
                    </td>
                    <td>
                        <button type="submit" class="btn btn-primary pull-right"><i class="fa fa-filter">Фильтр</i></button>
                    </td>


            </tr>
            </form>
        </table>
        </div>
    </div>
      <div class="panel-body">
        <form  method="post" enctype="multipart/form-data" id="form-product">
          <div class="table-responsive">
            <table class="table table-bordered table-hover">
              <thead>
                <tr>
                 <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
                  <td class="text-left"><?php if ($sort == 'firstname') { ?>
                    <a href="<?php echo $sort_firstname; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_name; ?></a>
                    <?php } else { ?>
                    <a href="<?php echo $sort_firstname; ?>"><?php echo $column_name; ?></a>
                    <?php } ?></td>
                     <td class="text-left"><?php if ($sort == 'customer_group_id') { ?>
                    <a href="<?php echo $sort_customer_group_id; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_customer_group_id; ?></a>
                    <?php } else { ?>
                    <a href="<?php echo $sort_customer_group_id; ?>"><?php echo $column_customer_group_id; ?></a>
                    <?php } ?></td>
                    <td class="text-left"><?php if ($sort == 'product') { ?>
                    <a href="<?php echo $sort_product; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_product; ?></a>
                    <?php } else { ?>
                    <a href="<?php echo $sort_product; ?>"><?php echo $column_product; ?></a>
                    <?php } ?></td>
                    <td class="text-right"><?php echo $column_option; ?></td>
                    <td class="text-right"><?php echo $column_quantity; ?></td>
                    <td class="text-right"><?php echo $column_total; ?></td>
                    <td class="text-right" style="width:118px"><?php echo $column_action; ?></td>
                </tr>
              </thead>
              <tbody>
                <?php if ($today) { ?>
                <?php foreach ($today as $todays) { ?>
                <tr data-order-product-id="<?php echo $todays['order_product_id'];?>">
                    <td class="text-center">
                    <?php if (in_array($todays['order_product_id'], $selected)) { ?>
                    <input type="checkbox" name="selected[]" value="<?php echo $todays['order_product_id']; ?>" checked="checked" class='grop_execute'/>
                    <?php } else { ?>
                    <input type="checkbox" name="selected[]" value="<?php echo $todays['order_product_id']; ?>" class='grop_execute'/>
                    <?php } ?></td>
                    <td class="text-left"><?php echo $todays['firstname']." ". $todays['lastname']; ?></td>
                    <td class="text-right"><?php echo $todays['customer_group_id'];?></td>
                    <td class="text-right"><?php echo $todays['product'];?></td>
                    <td class="text-right"><?php echo $todays['options'];?></td>
                    <td class="text-right"><?php echo $todays['quantity'];?></td>
                    <td class="text-right"><?php echo $todays['total'];?></td>
                    <td class="text-right" style="width: 150px;">
                        <a href="<?php echo $todays['link_order']; ?>" data-toggle="tooltip" title="Редактировать" class="btn btn-primary"><i class="fa fa-pencil"></i></a>
                        <?php if($todays['product_status_id']==0){?>
                    <?php if(date('Y-m-d')==$todays['booking_date'] AND $modify==true){ ?>
                    <a onclick="delete_product(<?php echo $todays['order_product_id']; ?>);" data-toggle="tooltip" title="<?php echo $button_delete; ?>" class="btn btn-danger"><i class="fa fa-trash-o"></i></a>
                    <a onclick="confirm_product(<?php echo $todays['order_product_id']; ?> );" data-toggle="tooltip" title="<?php echo $button_confirm; ?>" class="btn btn-checked"><i class="fa fa-check-circle-o"></i></a>
                    </td>
                    <?php } elseif($services!=0){ ?>
                    <a onclick="confirm_product(<?php echo $todays['order_product_id']; ?> );" data-toggle="tooltip" title="<?php echo $button_confirm; ?>" class="btn btn-checked"><i class="fa fa-check-circle-o"></i></a>
                    <?php  }?>
                            </tr>
                <?php } ?>
                <?php } ?>
                <?php } else { ?>
                <tr>
                  <td class="text-center" colspan="8"><?php echo $text_no_results; ?></td>
                </tr>
                <?php } ?>
              </tbody>
            </table>
          </div>
        </form>
      </div>
    </div>
  </div>
<?php echo $footer; ?>
<style>
    .table.well td{
        min-width: 200px;
    }
</style>
<script>
    function report() {

        var url='<?php echo $catalog_admin; ?>index.php?route=sale/today/report&token=<?php echo $token; ?>&category_id=<?php echo $category_id; ?>&date=<?php echo $date; ?>&report_id=<?php echo $report_id;?>&status_id=<?php echo $product_status_id; ?>&sort=<?php echo $sort; ?>&order=<?php echo $order;?>';

        window.open(url, '_blank');

    }
    function delete_product(order_product_id){
        var user_confirm='<?php echo $user_confirm; ?>';
         $.ajax({
            type: "POST",
            url: '<?php echo $catalog; ?>index.php?route=api/order/deleteProduct',
            data:{ 'user': $('#user').val(), 'order_product_id':order_product_id, 'user_confirm':user_confirm},
            dataType: 'json',
            success: function(json) {
                location=location;
            }
        });
    }

    function confirm_product(order_product_id){
        if (order_product_id==0){
            if(!$(".grop_execute:checked").parents('tr').attr('data-order-product-id')){
               return;
            }
            var list;
             list='0,';
            $(".grop_execute:checked").parents('tr').each(function(){
                list += $(this).attr('data-order-product-id') + ',';
            });
        }else{
            list=order_product_id;
        }
        var user_confirm='<?php echo $user_confirm; ?>';
        $.ajax({
            type: "POST",
            url: '<?php echo $catalog; ?>index.php?route=api/order/confirm',
            data:{ 'user': $('#user').val(), 'order_product_id':list, 'user_confirm':user_confirm},
            dataType: 'json',
            success: function(json) {
                location=location;
            }
        });
    }
    $('.date').datetimepicker({
        pickTime: false
    });

    $('.time').datetimepicker({
        pickDate: false
    });

    $('.datetime').datetimepicker({
        pickDate: true,
        pickTime: true
    });
</script>
