function transaction()
    {
        $bulan = addslashes($_GET['m']);
        if ($bulan == "") {
            $bulan = date("F Y");
            $days_ago = date('Y-m-01');
            // hard-coded '01' for first day
            $days_now = date('Y-m-t');
        } else {
            $bulan = urldecode($bulan);
            $days_ago = date('Y-m-01', strtotime($bulan));
            // hard-coded '01' for first day
            $days_now = date('Y-m-t', strtotime($bulan));
        }
        $numberDays = cal_days_in_month(CAL_GREGORIAN, date('n', strtotime($bulan)), date('Y', strtotime($bulan)));
        $days_ago = date('Y-m-01', strtotime($bulan));
        // hard-coded '01' for first day
        $days_now = date('Y-m-01', strtotime('+1 month', strtotime($bulan)));
        $t = time();
        //get average transaction value
        //latest transaction
        //max transaction
        //min transaction
        //most buyed products
        //most viewed products
        $tt = new LL_AccStatement();
        $arrTt = $tt->getWhere("Cash_Value > 0 AND (TransactionDateTime BETWEEN '{$days_ago}' AND '{$days_now}') ORDER BY TransactionDateTime DESC");
        $value = 0;
        foreach ($arrTt as $tts) {
            $value += $tts->Cash_Value;
        }
        $atv = $value / count($arrTt);
        $arrStats['Transactions Nr.'] = $arrTt;
        //        pr($arrTt);
        //        echo $atv;
        ?>
<div class="row">
        <div class="col-md-12">
            <h1>
                Transaction Dashboard
                <small><?php 
        echo $bulan;
        ?>
</small>
            </h1>
            <ol class="breadcrumb">
                <li>
                    <?php 
        echo Lang::t('Select Timeframe');
        ?>
                </li>
                <li class="active">
                    <?php 
        $start = new DateTime('11 months ago');
        // So you don't skip February if today is day the 29th, 30th, or 31st
        $start->modify('first day of this month');
        $end = new DateTime();
        $interval = new DateInterval('P1M');
        $period = new DatePeriod($start, $interval, $end);
        ?>
                    <select id="apptimeselector_<?php 
        echo $t;
        ?>
">
                        <?php 
        foreach ($period as $dt) {
            ?>
                            <option value="<?php 
            echo urlencode($dt->format('F Y'));
            ?>
" <?php 
            if ($dt->format('F Y') == $bulan) {
                echo "selected";
            }
            ?>
>
                                <?php 
            echo $dt->format('F Y') . "<br>";
            ?>
                            </option>
                        <?php 
        }
        ?>

                    </select>
                    <script>
                        $("#apptimeselector_<?php 
        echo $t;
        ?>
").change(function(){
                            var slc = $("#apptimeselector_<?php 
        echo $t;
        ?>
").val();
                            openLw("Transaction","<?php 
        echo _SPPATH;
        ?>
BIWebTransaction/transaction?m="+slc,"fade");
                        });
                    </script>
                </li>
            </ol>
        </div>
        </div>

        <div class="row">
            <div class="col-md-4">
                <div class="small-box bg-aqua">
                    <div class="inner">
                        <h3><small style="color: white;font-weight: bold;"><?php 
        echo idr($atv);
        ?>
</small></h3>
                        <p>Average Transaction Value</p>
                    </div>
                    <div class="icon">
                        <i class="ion ion-bag"></i>
                    </div>
                    <!--                            <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>-->
                </div>
            </div>
            <div class="col-md-4">
                <div class="small-box bg-green">
                    <div class="inner">

                        <h3><small style="color: white;font-weight: bold;"><?php 
        echo idr($value);
        ?>
</small></h3>

                        <p>Total Transactions</p>
                    </div>
                    <div class="icon">
                        <i class="ion ion-stats-bars"></i>
                    </div>
                    <!--                            <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>-->
                </div>
            </div>
            <div class="col-md-4">
                <div class="small-box bg-yellow">
                    <div class="inner">


                        <h3><?php 
        echo count($arrTt);
        ?>
</h3>

                        <p>Number of Transactions</p>
                    </div>
                    <div class="icon">
                        <i class="ion ion-stats-bars"></i>
                    </div>
                    <!--                            <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>-->
                </div>
            </div>

        </div>

        <div class="row">
            <div class="col-md-12">
                <div class="box box-default">
                    <div class="box-header with-border">
                        <h3 class="box-title">Transaction Stats</h3>

                        <div class="box-tools pull-right">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                            </button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                        </div>
                    </div>
                    <div class="box-body chart-responsive">

                        <?php 
        //            $days_ago = date('Y-m-d', strtotime('-30 days', time()));
        //            $days_now =  date("Y-m-d");
        $data = self::getAppStats($arrStats, $days_ago, $days_now);
        ?>


                    </div>
                    <!-- /.box-body -->
                </div>
            </div>

        </div>

        <?php 
        //latest transactions
        $tt = new LL_AccStatement();
        $arrTtNew = $tt->getWhere("(TransactionDateTime BETWEEN '{$days_ago}' AND '{$days_now}') ORDER BY TransactionDateTime DESC LIMIT 0,10");
        ?>
        <div class="row">
            <div class="col-md-7">
                <div class="box box-info">
                    <div class="box-header with-border">
                        <h3 class="box-title">Latest Transactions</h3>

                        <div class="box-tools pull-right">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                            </button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <div class="table-responsive">
                            <table class="table no-margin">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Date</th>
                                    <th>Description</th>
                                    <th>Store</th>
                                    <th>Value</th>
                                    <th>Points</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php 
        foreach ($arrTtNew as $tt) {
            ?>
                                <tr>
                                    <td><?php 
            echo $tt->TransactionID;
            ?>
</td>
                                    <td><?php 
            echo date("d-m-Y", strtotime($tt->TransactionDateTime));
            ?>
</td>
                                    <td><?php 
            echo $tt->Description;
            ?>
</td>
                                    <td><?php 
            echo $tt->StoreName;
            ?>
</td>
                                    <td><?php 
            echo idr($tt->Cash_Value);
            ?>
</td>
                                    <td><?php 
            echo $tt->Point_Value;
            ?>
</td>
                                </tr>
                                <?php 
        }
        ?>

                                </tbody>
                            </table>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer clearfix">

                        <a href="javascript:openLw('Transaction_Detail', '<?php 
        echo _SPPATH;
        ?>
LLAccWeb/LL_TransactionDetail', 'fade');
                                activkanMenuKiri('Transaction_Detail');" class="btn btn-sm btn-default btn-flat pull-right">View All Transactions</a>
                    </div>
                    <!-- /.box-footer -->
                </div>
            </div>
            <?php 
        $arrSales = array();
        $prods = array();
        //calculate top products based on sales
        $lltt = new LL_TransactionDetail();
        foreach ($arrTt as $tt) {
            $arrProd = $lltt->getWhereFromMultipleTable("detail_trans_id = " . $tt->TransactionID . " AND VariantID = detail_varian_id ", array("LL_Article_WImage"));
            //                pr($arrProd);
            foreach ($arrProd as $prod) {
                $arrSales[$prod->VariantID] += $prod->detail_price_total;
                $prods[$prod->VariantID] = $prod;
            }
        }
        arsort($arrSales);
        //            $arrSales = array_reverse($arrSales);
        //            pr($arrSales);
        ?>
            <div class="col-md-5">
                <div class="box box-success">
                    <div class="box-header with-border">
                        <h3 class="box-title">Top Products</h3>

                        <div class="box-tools pull-right">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                            </button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <div class="table-responsive">
                            <table class="table no-margin">
                                <thead>
                                <tr>
                                    <th>ID</th>
<!--                                    <th>Picture</th>-->
                                    <th>Name</th>

                                    <th>Value</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php 
        foreach ($arrSales as $varid => $saledata) {
            if ($varid == '2887') {
                continue;
            }
            ?>
                                <tr>
                                    <td><?php 
            echo $varid;
            ?>
</td>

<!--                                    <td>--><?php 
            //=$prods[$varid]->BaseArticleImageFile;
            ?>
<!--</td>-->
                                    <td><?php 
            echo $prods[$varid]->VariantNameENG;
            ?>
</td>
                                    <td>
                                        <?php 
            echo idr($saledata);
            ?>
                                    </td>
                                </tr>
                                <?php 
        }
        ?>

                                </tbody>
                            </table>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
<!--                     /.box-body-->
                    <div class="box-footer clearfix">
<!--                        <a href="javascript::;" class="btn btn-sm btn-info btn-flat pull-left">Place New Order</a>-->
                        <a href="javascript:openLw('LL_Article', '<?php 
        echo _SPPATH;
        ?>
LLProdWeb/LL_Article_WImage', 'fade');
                                activkanMenuKiri('LL_Article');" class="btn btn-sm btn-default btn-flat pull-right">View All Articles</a>
                    </div>
                    <!-- /.box-footer -->
                </div>
            </div>
        </div>
        <style>
            ul.legend li{
                list-style: none;
                line-height: 30px;
            }
            ul.legend li div{
                float: left;
                margin-top: 10px;
                margin-right: 15px;
            }
            .legend-item{
                float: left;
                margin: 10px;
                line-height: 30px;
                margin-right: 5px;
            }
            .legend-item div{
                float: left;
                margin-top: 10px;
                margin-right: 5px;
            }
            .breadcrumb {
                padding: 8px 15px;
                margin-bottom: 20px;
                list-style: none;
                background-color: #f5f5f5;
                border-radius: 4px;
            }
            .breadcrumb {
                float: right;
                background: transparent;
                margin-top: 0;
                margin-bottom: 0;
                font-size: 12px;
                padding: 7px 5px;
                position: absolute;
                top: 15px;
                right: 10px;
                border-radius: 2px;
            }
            .users-list-name{
                white-space: nowrap;
            }
        </style>
    <?php 
    }
 public static function parseStatementwType($ST, $ll)
 {
     $vs = new VRStatement();
     $vs->response_code = (string) $ST->ARTSHeader->Response['ResponseCode'];
     //        $vs->point_total = 0;
     //        $vs->cash_total = 0;
     //        $transaction = array();
     if ($vs->response_code != 'OK') {
         return 0;
     }
     $arrStatement = $ST->CustomerBody->LineItems;
     //pr($ST);
     $num = 0;
     foreach ($arrStatement as $obj) {
         $num++;
         $type = (string) $obj->TransactionValue[0]->Type;
         /*
          * macam2 type , update 12 nov 2015
          *
          * Konsep baru, we should go by description
          *
          * ada :
          *
          * Purchase , punya 4 TransactionValue kl beli offline, krn bs tuker point, kl beli online cuman payment and earn saja
          *
          * Point Adjustment
          *
          * Catalogue Redeem
          *
          * Point Expiry
          *
          * GCT Transaction
          */
         $array = array();
         $array['TransactionID'] = (string) $obj->TransactionID;
         $array['TransactionDateTime'] = date("Y-m-d", strtotime(substr((string) $obj->TransactionDateTime, 0, 10)));
         $array['Description'] = (string) $obj->Description;
         $array['StoreName'] = (string) $obj->StoreName;
         $array['ReferenceNumber'] = (string) $obj->ReferenceNumber;
         $array['ReceiptNumber'] = (string) $obj->ReceiptNumber;
         $array['CardNumber'] = (string) $obj->CardNumber;
         if ($array['Description'] == "Purchase") {
             //cash
             $array['Cash_Value'] = (int) $obj->TransactionValue[0]->TransactionCurrencyValue;
             $array['Cash_Currency'] = (string) $obj->TransactionValue[0]->TransactionCurrency;
             $array['Cash_Type'] = (string) $obj->TransactionValue[0]->Type;
             $array['Cash_Descr'] = (string) $obj->TransactionValue[0]->TransactionCurrencyDescription;
             //points
             $array['Point_Value'] = (int) $obj->TransactionValue[1]->TransactionCurrencyValue;
             $array['Point_Currency'] = (string) $obj->TransactionValue[1]->TransactionCurrency;
             $array['Point_Type'] = (string) $obj->TransactionValue[1]->Type;
             $array['Point_Descr'] = (string) $obj->TransactionValue[1]->TransactionCurrencyDescription;
         } else {
             //cash
             $array['Cash_Value'] = 0;
             $array['Cash_Currency'] = "";
             $array['Cash_Type'] = "";
             $array['Cash_Descr'] = "";
             //not a purchase
             $array['Point_Value'] = (int) $obj->TransactionValue->TransactionCurrencyValue;
             $array['Point_Currency'] = (string) $obj->TransactionValue->TransactionCurrency;
             $array['Point_Type'] = (string) $obj->TransactionValue->Type;
             $array['Point_Descr'] = (string) $obj->TransactionValue->TransactionCurrencyDescription;
         }
         $array['Point_Balance'] = (string) $obj->TransactionBalance->BalanceCurrencyValue;
         $array['trans_acc_id'] = $ll->macc_id;
         $nn = new LL_AccStatement();
         $nn->fill($array);
         $nn->save();
         //echo "trans : ".$array['TransactionID']."<br>";
         //            $transaction[] = $array;
     }
     //pr($transaction);
     //        $vs->total_transaction = $num;
     //        $vs->transactions = $transaction;
     //        return $vs;
 }