function getBalance()
    {
        $app_id = AppAccount::getAppID();
        $app = AppAccount::getActiveAppObject();
        $limit = addslashes($_GET['lmt']);
        if ($limit < 30 || $limit == "") {
            $limit = 30;
        }
        ?>

        <div class="row">
            <div class="col-md-12 ">
                <div class="bg-green" style="padding: 10px; text-align: center;">
                <h1>Current Balance : <b><?php 
        echo $app->app_pulsa;
        ?>
</b> <i class="fa fa-mail-forward"></i> </h1>
                </div>
            </div>
        </div>
        <?php 
        //get transactions
        $apptrans = new AppPulsa();
        $arrB = $apptrans->getWhere("pulsa_app_id = '{$app_id}' ORDER BY pulsa_date DESC LIMIT 0,{$limit} ");
        $arrB = array_reverse($arrB);
        //        pr($arrB);
        ?>
        <div class="row">
        <div class="col-md-12" style="margin-top: 30px;">
        <h1><i class="fa fa-mail-forward"></i> Balance Statement <small>Last <?php 
        echo $limit;
        ?>
 Transactions</small></h1>
            <ol class="breadcrumb">
                <li>
                    <?php 
        echo Lang::t('Select Nr. of Transactions');
        ?>
                </li>
                <li class="active">

                    <select id="nrtransaction">
                        <option  value="30">30</option>
                        <option <?php 
        if ($limit == 60) {
            echo "selected";
        }
        ?>
 value="60">60</option>
                        <option <?php 
        if ($limit == 100) {
            echo "selected";
        }
        ?>
 value="100">100</option>
                        <option <?php 
        if ($limit == 500) {
            echo "selected";
        }
        ?>
 value="500">500</option>
                        <option <?php 
        if ($limit == 1000) {
            echo "selected";
        }
        ?>
 value="1000">1000</option>
                    </select>

                </li>
            </ol>
    <script>
        $('#nrtransaction').change(function(){
           var slc =  $('#nrtransaction').val();
            openLw('Balance','<?php 
        echo _SPPATH;
        ?>
AppBalance/getBalance?lmt='+slc,'fade');
        });
    </script>
        <div class="table-responsive" >
            <table class="table table-bordered" style="background-color: white;">
                <thead>
                <tr>
                    <th>
                        Date
                    </th>
                    <th>
                        Description
                    </th>
                    <th>
                        Debit
                    </th>
                    <th>
                        Credit
                    </th>
                    <th>
                        Balance
                    </th>

                </tr>

                </thead>
                <tbody>
                <?php 
        foreach ($arrB as $bb) {
            ?>
                <tr>
                    <td><?php 
            echo indonesian_date($bb->pulsa_date);
            ?>
</td>
                    <td>
                        <?php 
            if ($bb->pulsa_action == "debit") {
                ?>
                            Used in campaign. <a style="cursor: pointer;" id="camp_id_<?php 
                echo $bb->pulsa_camp_id;
                ?>
" >view campaign</a>
                            <script>
                                $('#camp_id_<?php 
                echo $bb->pulsa_camp_id;
                ?>
').click(function(){
//                                    var slc =  $('#nrtransaction').val();
                                    openLw('campView','<?php 
                echo _SPPATH;
                ?>
AppBalance/campView?camp_id=<?php 
                echo $bb->pulsa_camp_id;
                ?>
','fade');
                                });
                            </script>
                        <?php 
            } else {
                ?>
                                Topped-up
                            <?php 
            }
            ?>
                    </td>
                    <td class="duit">
                        <?php 
            if ($bb->pulsa_action == "debit") {
                echo $bb->pulsa_jumlah;
            }
            ?>
                    </td>
                    <td class="duit">
                        <?php 
            if ($bb->pulsa_action == "credit") {
                echo $bb->pulsa_jumlah;
            }
            ?>
                    </td>
                    <td class="duit">
                        <b><?php 
            echo $bb->pulsa_new;
            ?>
</b>
                    </td>

                </tr>
                    <?php 
        }
        ?>
                </tbody>
            </table>
        </div>
        </div>
        </div>
        <style>
            table.table td.duit{
                text-align: right;
            }
            .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;
            }
        </style>
        <?php 
    }
 static function processGCM($arrhasil, $app_id, $psn, $array_ids, $app, $isTest = 0)
 {
     $json['status_code'] = 1;
     $json['status_message'] = "Success";
     $json['result'] = $arrhasil;
     foreach ($arrhasil as $numw => $hasil) {
         //simpan hasil
         $gcm = new GCMResult();
         $gcm->multicast_id = $hasil->multicast_id;
         $gcm->success = $hasil->success;
         $gcm->failure = $hasil->failure;
         $gcm->results = serialize($hasil->results);
         $gcm->canonical_ids = $hasil->canonical_ids;
         $gcm->camp_id = $psn->camp_id;
         $gcm->gcm_date = leap_mysqldate();
         $gcm->gcm_test = $isTest;
         $gcm->app_id = $app_id;
         $gcm->client_camp_id = $psn->camp_client_id;
         $gcm->client_id = $app->app_client_id;
         $gcm->save();
         if (!$isTest) {
             //kurangin pulsa ...
             $old = $app->app_pulsa;
             $app->app_pulsa = $app->app_pulsa - $hasil->success;
             $app->load = 1;
             $app->save();
             //save transactions
             $tt = new AppPulsa();
             $tt->pulsa_acc_id = Account::getMyID();
             $tt->pulsa_action = "debit";
             $tt->pulsa_app_id = $app_id;
             $tt->pulsa_date = leap_mysqldate();
             $tt->pulsa_jumlah = $hasil->success;
             $tt->pulsa_new = $app->app_pulsa;
             $tt->pulsa_old = $old;
             $tt->pulsa_camp_id = $psn->camp_id;
             $tt->save();
             //
         }
         //            echo "ID : ".$hasil->multicast_id."<br>";
         //            echo "Success : ".$hasil->success."<br>";
         //            echo "Failure : ".$hasil->failure."<br>";
         //            echo "<a target='_blank' href='"._SPPATH."PushNotResults/res?id={$psn->camp_id}&token=".IMBAuth::createOAuth()."' class='btn btn primary'>Complete Results</a><br><br>";
         $page = 999 * $numw;
         foreach ($hasil->results as $num => $res) {
             if (isset($res->error)) {
                 //error
                 $status = 0;
                 $log_text = $res->error;
                 //delete device_id from table
                 $dv = new DeviceModel();
                 global $db;
                 //repaired using update
                 $q = "UPDATE  {$dv->table_name} SET dev_not_send = 1 WHERE device_id = '" . $array_ids[$page + $num] . "'";
                 if ($_GET['test']) {
                     echo "<br>query : " . $q . "<br>";
                     echo "delete succ :" . $db->query($q, 0);
                     echo "<br>";
                 }
             } else {
                 //success
                 $status = 1;
                 $log_text = $res->message_id;
             }
             // repaired macc id cannot get
             PushLogger::savelog($psn->camp_id, $array_ids[$num], $app->app_client_id, $status, $log_text, $hasil->multicast_id, $app_id, $psn->camp_client_id);
         }
     }
     $psn->camp_status = 1;
     $psn->camp_send_date = leap_mysqldate();
     $psn->load = 1;
     $psn->save();
     return $json;
 }
 function addpulsatrans()
 {
     $app_id = addslashes($_POST['app_id']);
     $jml = addslashes($_POST['jml']);
     if ($jml < 1) {
         die("jumlah nol");
     }
     if ($app_id == "" || $app_id < 1) {
         die("app id nol");
     }
     $app = new AppAccount();
     $app->getByID($app_id);
     $add = new AppPulsa();
     $add->pulsa_acc_id = Account::getMyID();
     $add->pulsa_action = 'credit';
     $add->pulsa_jumlah = $jml;
     $add->pulsa_app_id = $app_id;
     $add->pulsa_old = $app->app_pulsa;
     $add->pulsa_new = $app->app_pulsa + $jml;
     $add->pulsa_date = leap_mysqldate();
     $add->pulsa_camp_id = 0;
     $s1 = $add->save();
     if ($s1) {
         $app->app_pulsa = $add->pulsa_new;
         $app->load = 1;
         $s2 = $app->save();
         if ($s2) {
             die("Saved");
         } else {
             die("Error on adding pulsa to AppAcc");
         }
     } else {
         die("Error on adding pulsa to AppPulsa");
     }
 }