<!-- Page Content -->
<div class="page-content">
    <!-- Page Header -->
    <div class="page-header position-relative">
        <div class="header-title">
            <h1>
               Products Count Report
            </h1>
        </div>
        <!--Header Buttons-->
        <div class="header-buttons">
            <a class="sidebar-toggler" href="#">
                <i class="fa fa-arrows-h"></i>
            </a>
            <a class="refresh" id="refresh-toggler" href="">
                <i class="glyphicon glyphicon-refresh"></i>
            </a>
            <a class="fullscreen" id="fullscreen-toggler" href="#">
                <i class="glyphicon glyphicon-fullscreen"></i>
            </a>
        </div>
        <!--Header Buttons End-->
    </div>
    <!-- /Page Header -->
    <!-- Page Body -->
    <div class="page-body" id="resources">
      <div class="well">
          
          
          <div id="searchdiv" style="margin-bottom: 10px;">
            <form name="frmsearch" id="frmsearch" method="post">
                <div class="row">
                    <div class='col-md-4 searchfieldslist'>
                        <select class="form-control" name="customerid" id="customerid">
                            <option value=''>Select Customer</option>
                            <?php
                            if($customerslist){
                                foreach($customerslist as $customersrec){
                            ?>
                                <option value='<?php echo $customersrec->ID; ?>' <?php if(isset($_POST["customerid"]) && $_POST["customerid"]==$customersrec->ID) echo "selected"; ?>><?php echo $customersrec->NAME; ?></option>
                            <?php
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <div class='col-md-2 searchfieldslist'>
                        <script> $( function() { $( '#datefrom' ).datepicker({ format: 'yyyy-mm-dd' }); }); </script>
                        <input type='text' name='datefrom' id='datefrom' value='<?php if(isset($_POST["datefrom"])) echo $_POST["datefrom"]; else echo date("Y-m-d",strtotime("-1 month")); ?>' readonly placeholder='Select from date' class='form-control' />
                    </div>
                    <div class='col-md-2 searchfieldslist'>
                        <script> $( function() { $( '#dateto' ).datepicker({ format: 'yyyy-mm-dd' }); }); </script>
                        <input type='text' name='dateto' id='dateto' value='<?php if(isset($_POST["dateto"])) echo $_POST["dateto"]; else echo date('Y-m-d'); ?>' readonly placeholder='Select to date' class='form-control' />
                    </div>
                    <div class='col-md-3 searchfieldslist'>
                        <button type="submit" class="btn btn-primary" name="allsearch"><span class="fa fa-search"></span>Search</button>
                    </div>
                    <div class='col-md-12' style="margin-top: 12px;text-align: right;">
                        <a class="btn btn-success" name="allsearch" onclick="exportexcelpdf()"><span class="fa fa-file-excel-o"></span>Excel</a>
                    </div>
                </div>
            </form>
        </div>
          
          <div class="row" style="overflow: auto;">
              <?php
              if($_POST){
              ?>
            <table class="table table-striped table-hover table-bordered editable">
                <tr style="font-weight: bold;">
                    <td>Date</td>
                    <?php
                    if($productstotallist){
                        $i=0;
                        foreach($productstotallist as $productstotallistrec){
                    ?>
                            <td><?php echo $productstotallistrec->NAME; ?></td>
                    <?php
                        $prarray[$i]    =   $productstotallistrec->ID;
                        $prpricearray[$i]    =   $productstotallistrec->PRICE;
                        $i++;
                        }
                    }
                    ?>
                </tr>
                    <?php
                    while (strtotime($date) <= strtotime($end_date)) {
                    ?>
                        <tr><td><div style="width: 100px;"><?php echo $date; ?></div></td>
                            <?php                          
                            if(isset($prarray) && $prarray){
                                foreach($prarray as $prarrayData){
                                    $count=0;
                                    //  Check date and product id to get the product count of that day
                                    if($productcount){
                                        foreach($productcount as $productcountrec){
                                            if($productcountrec->ID==$prarrayData && $productcountrec->RECIEPTDATE==$date)
                                                $count=$productcountrec->CNT;
                                        }
                                    }
                            ?>
                                <td>
                                <?php
                                    echo $count;
                                ?>
                                </td>
                            <?php
                                }
                            }
                            ?>
                        </tr>
                    <?php
                        $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
                    }
                    ?>
                        <tr style="font-weight: bold;">
                            <td>Quantity</td>
                            <?php                          
                            if(isset($prarray) && $prarray){
                                $j=0;
                                foreach($prarray as $prarrayData){
                                    $totcount=0;
                                    if($producttotalcount){
                                        foreach($producttotalcount as $producttotalcountrec){
                                            if($producttotalcountrec->ID==$prarrayData) {
                                                $totcount=$totcount+$producttotalcountrec->CNT;
                                            }
                                        }
                                    }
                            ?>
                            <td><div><?php echo $totcount; ?></div></td>
                            <?php
                                $j++;
                                }
                            }
                            ?>
                        </tr>
                        <tr style="font-weight: bold;">
                            <td>Price</td>
                            <?php                          
                            if(isset($prarray) && $prarray){
                                $j=0;
                                $grandtotal=0;
                                foreach($prarray as $prarrayData){
                                    $totprice=0;
                                    if($producttotalcount){
                                        foreach($producttotalcount as $producttotalcountrec){
                                            if($producttotalcountrec->ID==$prarrayData) {
                                                $totprice=$totprice+$producttotalcountrec->TOTALPRICE;
                                            }
                                        }
                                    }
                                    $grandtotal=$grandtotal+$totprice;
                            ?>
                            <td><div><?php echo $this->formatslist->formatCurrencywithHash($totprice); ?></div></td>
                            <?php
                                $j++;
                                }
                            }
                            ?>
                        </tr>
                        <tr>
                            <td>Sub Total</td>
                            <td colspan="<?php echo $j; ?>" style="font-weight: bold;">
                                <div>
                                <?php
                                $taxamount  =   $grandtotal*.05;
                                $subtotal   =   $grandtotal-$taxamount;
                                echo $this->formatslist->formatCurrencywithHash($subtotal);
                                ?>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>Tax Amount</td>
                            <td colspan="<?php echo $j; ?>" style="font-weight: bold;">
                                <div><?php echo $this->formatslist->formatCurrencywithHash($taxamount); ?></div>
                            </td>
                        </tr>
                        <tr>
                            <td>Total Amount</td>
                            <td colspan="<?php echo $j; ?>" style="font-weight: bold;">
                                <div><?php echo $this->formatslist->formatCurrencywithHash($grandtotal); ?></div>
                            </td>
                        </tr>
            </table>
              <?php
              }
              ?>
        </div>
</div>
</div>
<!-- /Page Body -->
</div>
<!-- /Page Content -->

</div>
<!-- /Page Container -->
<!-- Main Container -->

</div>
<script type="text/javascript">
    function exportexcelpdf() {
        var customerid  =   $("#customerid").val();
        var datefrom  =   $("#datefrom").val();
        var dateto  =   $("#dateto").val();
        window.location.href = "<?php echo base_url(); ?>reports/productcountreport/exportreportexcelandpdf/?customerid="+customerid+"&datefrom="+datefrom+"&dateto="+dateto+"&j="+<?php echo ($j=='')?0:$j; ?>;
    }
</script>