Ejemplo n.º 1
2
 /**
  * What to do when this action will be called.
  *
  * Just render the `index` view file from current controller.
  */
 public function run()
 {
     if (Yii::app()->user->isGuest) {
         $this->controller->layout = '//layouts/landing';
         $this->controller->render('landing');
     } else {
         $this->controller->layout = '//layouts/main';
         $user = Yii::app()->user->data();
         $balance = Balance::model()->findAllByAttributes(array('id_user' => $user->id));
         $transactions = Transaction::model()->findAllByAttributes(array('id_user' => $user->id), new CDbCriteria(array('order' => 'create_time DESC', 'limit' => 10)));
         $this->controller->render('home', array('transactions' => $transactions, 'balance' => $balance));
     }
 }
Ejemplo n.º 2
0
 public function actionMonthStorage()
 {
     $dates = explode('-', $_POST['dates']);
     $depId = $_POST['depId'];
     $number = cal_days_in_month(CAL_GREGORIAN, $dates[1], $dates[0]);
     $realized = array();
     $expense = new Expense();
     $expenses = array();
     $startCount = array();
     $endCount = array();
     $depRealize = new DepFaktura();
     $inexp = new Expense();
     $balance = new Balance();
     for ($i = 1; $i <= $number; $i++) {
         $tempDate = $dates[0] . "-" . $dates[1] . "-" . $i;
         $listDate[$i] = $tempDate;
         $realized[$tempDate] = $depRealize->getDepRealizesSumm($tempDate, $depId);
         $expenses[$tempDate] = $expense->getDepCost($depId, $tempDate);
         $tempBalance = $balance->getDepBalanceSumm($tempDate, $depId);
         $startCount[$tempDate] = $tempBalance[0];
         $endCount[$tempDate] = $tempBalance[1];
         $curEndCount[$tempDate] = $tempBalance[2];
     }
     $this->renderPartial('monthStorage', array('tempDate' => $listDate, 'realized' => $realized, 'expenses' => $expenses, 'startCount' => $startCount, 'endCount' => $endCount, 'curEndCount' => $curEndCount, 'depId' => $depId));
 }
Ejemplo n.º 3
0
function mostrarBalance()
{
    $objResponse = new xajaxResponse();
    $balance = new Balance();
    $resultado = $balance->mostrarBalance();
    $objResponse->addAssign("librom", "innerHTML", $resultado);
    return $objResponse;
}
 public function run()
 {
     DB::table('users')->delete();
     $user = User::create(['guid' => '7xDsRLyXEd1PgJ6Glrhs6d', 'email' => '*****@*****.**', 'name' => 'John Doe', 'password' => 'strong_pass_plz', 'secret' => 'secretsecret', 'callback_url' => 'https://url.to/send/on/btc/received', 'rpc_connection' => 'http://*****:*****@ipaddress:18332', 'blocknotify_callback_url' => 'https://url.to/send/on/btc/received']);
     $btcBalance = new Balance(['crypto_type_id' => '1']);
     // btc
     $btcBalance->user()->associate($user);
     $user->balances()->save($btcBalance);
 }
Ejemplo n.º 5
0
 public function addPointsTrade($user_id, $amount_fee, $trade_id, $wallet_init)
 {
     $logFile = 'points.log';
     Log::useDailyFiles(storage_path() . '/logs/points/' . $logFile);
     $setting = new Setting();
     $balance = new Balance();
     $wallet = wallet::where('type', 'POINTS')->first();
     $user = User::find($user_id);
     Log::info("\n" . '------------------------- Add Point Trade -----------------------------');
     Log::info("\n" . 'amount_fee ' . $amount_fee . ' . trade_id: ' . $trade_id . " -- wallet_init: " . $wallet_init);
     if (isset($wallet->id)) {
         $point_per_btc = $setting->getSetting('point_per_btc', 1);
         $percent_point_reward_trade = $setting->getSetting('percent_point_reward_trade', 0);
         $percent_point_reward_referred_trade = $setting->getSetting('percent_point_reward_referred_trade', 0);
         Log::info("\n" . 'Setting -- point_per_btc: ' . $point_per_btc . ' . percent_point_reward_trade: ' . $percent_point_reward_trade . " % -- percent_point_reward_referred_trade: " . $percent_point_reward_referred_trade . " %");
         //cong point cho $user_id
         if ($percent_point_reward_trade > 0) {
             $amount_reward = $amount_fee * $percent_point_reward_trade / 100;
             $point_reward = $amount_reward / $point_per_btc;
             Log::info("\n" . 'Add point for ' . $user->username . ' . amount_reward: ' . $amount_reward . " BTC -- point_reward: " . $point_reward . " POINTS");
             if ($point_reward > 0) {
                 $balance->addMoney($point_reward, $wallet->id, $user->id);
                 $deposit = new Deposit();
                 $deposit->user_id = $user->id;
                 $deposit->wallet_id = $wallet->id;
                 $deposit->amount = $point_reward;
                 $deposit->paid = 1;
                 $deposit->transaction_id = "Points earned from trade " . $trade_id;
                 $deposit->save();
             }
         }
         //cong point cho nguoi da gioi thieu $user_id nay neu co
         if (!empty($user->referral) && $percent_point_reward_referred_trade > 0) {
             $user_referred = User::where('username', $user->referral)->first();
             if (!empty($user_referred)) {
                 $amount_reward = $amount_fee * $percent_point_reward_referred_trade / 100;
                 $point_reward = $amount_reward / $point_per_btc;
                 Log::info("user_referred AAAAAAAAA: ", $user_referred);
                 Log::info("\n" . 'Add point for user referred: ' . $user_referred->username . ' . amount_reward: ' . $amount_reward . " BTC -- point_reward: " . $point_reward . " POINTS");
                 if ($point_reward > 0) {
                     $balance->addMoney($point_reward, $wallet->id, $user_referred->id);
                     $deposit = new Deposit();
                     $deposit->user_id = $user_referred->id;
                     $deposit->wallet_id = $wallet->id;
                     $deposit->amount = $point_reward;
                     $deposit->paid = 1;
                     $deposit->transaction_id = "Points earned from User " . $user->username . "( Trade: " . $trade_id . ")";
                     $deposit->save();
                 }
             }
         }
     } else {
         Log::info("\n" . 'No wallet POINTS');
     }
 }
Ejemplo n.º 6
0
 public function actionTest()
 {
     $start = time();
     Yii::app()->cache->flush();
     Yii::app()->db->createCommand()->truncateTable(Buy::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Sell::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Order::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Balance::model()->tableName());
     // Тест на 10 000 руб.
     Status::setParam('balance', 10000);
     Status::setParam('balance_btc', 0);
     $exs = Exchange::getAllByDt('btc_rur', '2013-12-16', '2014-01-06');
     $cnt = 0;
     foreach ($exs as $exchange) {
         $obj = new stdClass();
         $obj->dtm = $exchange['dt'];
         $obj->buy = $exchange['buy'];
         $obj->sell = $exchange['sell'];
         $cnt++;
         $bot = new Bot($obj);
         $bot->run();
     }
     $end = time();
     echo '<b>Elapsed time: ' . ($end - $start) / 60 . ' min.<br/>';
     echo '<b>Steps count: ' . $cnt . '<br/>';
 }
Ejemplo n.º 7
0
 public static function boot()
 {
     parent::boot();
     // Setup event bindings...
     Balance::saving(function ($balance) {
         $balance->user_id = Auth::id();
         return $balance;
     });
     $user_id = Auth::id();
     $balance = Balance::where('user_id', $user_id)->orderBy('id', 'DESC')->first();
     if (count($balance) > 0) {
         $date = Carbon::createFromFormat('Y-m-d H:i:s', $balance->created_at);
         if ($date->isToday()) {
             // Deixa como está.
         } else {
             // Cria o pro=imeiro registro
             $todayAmount = DB::table('transactions')->where('created_at', '>', date("Y-m-d") . " 00:00:00")->where('created_at', '<=', date('Y-m-d H:i:s'))->where('user_id', Auth::id())->where('done', 1)->sum('amount');
             $newAmount = $balance->amount + $todayAmount;
             // Cria um novo pro dia de hoje
             $balance = Balance::create(['amount' => $newAmount, 'user_id' => $user_id]);
         }
     } else {
         // Cria o pro=imeiro registro
         $amount = DB::table('transactions')->where('created_at', '<=', date('Y-m-d H:i:s'))->where('user_id', Auth::id())->where('done', 1)->sum('amount');
         $balance = Balance::create(['amount' => $amount, 'user_id' => $user_id]);
     }
 }
Ejemplo n.º 8
0
 public function userbalancesubmitAction()
 {
     if (!$this->isValidUserBalance()) {
         $this->_forward('userbalance', null, null, array('validate' => $this->emptyField));
         return;
     }
     try {
         $array_of_params = $this->_request->getParams();
         $balanceServer = new Balance();
         $response = $balanceServer->getBalance($this->getUserFromParam($array_of_params));
         $this->_forward('userbalance', null, null, array('balance' => $response));
     } catch (Exception $e) {
         var_dump($e);
         die;
     }
 }
Ejemplo n.º 9
0
 public function testRetrieve()
 {
     self::authorizeFromEnv();
     $d = Balance::retrieve();
     $this->assertSame($d->object, "balance");
     $this->assertTrue(Util\Util::isList($d->available));
     $this->assertTrue(Util\Util::isList($d->pending));
 }
Ejemplo n.º 10
0
 public function testSendMany()
 {
     $userBalance = Balance::find(1);
     $userBalance->balance = 8900000000;
     // 89 BTC !
     $userBalance->save();
     // TODO compile some addresses
     $recipients = ['recipients' => json_encode(['mrcpH23MHKweJmzNWNbPKMxtVKMJYVpKgr' => 4500000, 'n21cjTZa59QcMBXFvoKx2WoRotBV9mErnJ' => 5500000, 'mxKRETCDzCuLVLiw9MieJb8xFi1WhkQ9wY' => 6500000])];
     $response = $this->call('POST', 'api/7xDsRLyXEd1PgJ6Glrhs6d/sendmany?password=strong_pass_plz', $recipients);
     $jsonResult = json_decode($response->getContent());
 }
Ejemplo n.º 11
0
 public function init()
 {
     try {
         $config = Zend_Registry::get('appconf');
         $storageAdapter = new Zing_Auth_Storage_Session(array('host' => $config->authorization->storage->host, 'port' => $config->authorization->storage->port));
         //$auth=new Zing_App_Auth();
         // $auth->setStorage($storageAdapter);
         $auth = Zing_Authv2::getInstance();
         if ($auth->isLogged()) {
             $identity = $auth->getIdentity();
             $this->userID = $this->uName2uID($identity['username']);
             $this->view->userID = $this->userID;
             if (!$this->checkUser($identity['username'])) {
                 echo "<p style='text-align:center'>Bạn không được phép truy cập hệ thống Ví Zing Me</p>";
                 exit;
             }
         }
         $this->loadConfig(ROOT_PATH . '/config/config.ini');
         require_once ROOT_PATH . '/util/Logger.php';
         try {
             $balance = new Balance();
             $res = $balance->getBalance($this->userID);
             if ($res->code == 0) {
                 $this->view->balance = $res->currentBalance;
             } else {
                 if ($res->code == -3) {
                     $this->view->balance = 0;
                 } else {
                     $this->view->errMsg = "fail";
                 }
             }
         } catch (Exception $e) {
         }
     } catch (Exception $e) {
         echo 'Hệ Thống Ví Zing Me đang được bảo trì. Mời bạn quay lại sau.';
         die;
     }
 }
Ejemplo n.º 12
0
 public function handle_after_destroy()
 {
     $expense_id = $this->id;
     if (!is_null($expense_id)) {
         $t = Transaction::where_expense_id($expense_id)->first();
         $transaction_id = $t->id;
         $b = Balance::where_transaction_id($transaction_id)->first();
         if (!is_null($t) && !is_null($b)) {
             $b->delete();
             $t->delete();
             $t->update_later_balance();
         }
     }
 }
Ejemplo n.º 13
0
 public function testPayment()
 {
     $userBalance = Balance::find(1);
     $userBalance->balance = 75000;
     $userBalance->save();
     $this->assertEquals(75000, $userBalance->balance);
     $response = $this->call('GET', 'api/7xDsRLyXEd1PgJ6Glrhs6d/payment?password=strong_pass_plz&to=mrcpH23MHKweJmzNWNbPKMxtVKMJYVpKgr&amount=50000&note=xxx');
     $jsonResult = json_decode($response->getContent());
     $this->assertEquals("Sent 0.0005, crypto type id: 1 to mrcpH23MHKweJmzNWNbPKMxtVKMJYVpKgr", $jsonResult->message);
     $transactionModel = Transaction::find(1);
     $this->assertEquals('151f9b43343c5cd4f2064b5ac2a722f67cc53a845d05cdf9979379fa4ed19160', $transactionModel->tx_id);
     $this->assertEquals(20080, $transactionModel->network_fee);
     // to, amount, note
     // address valid
     // user has enough balance
     //
 }
 public function states_index()
 {
     $user_id = Auth::user()->id;
     $colonia = Session::get("colonia");
     $urbanism = Urbanism::where('colony_id', '=', $colonia)->first();
     $urbanismo = $urbanism->id;
     $urb_name = $urbanism->Colony->name;
     $ano = date("Y");
     $vigencia = date("Y-m");
     $monthly_fee = MonthlyFee::where('monthly_fee.urbanism_id', '=', $urbanismo)->where(DB::raw('DATE_FORMAT(monthly_fee.since,\'%Y-%m\')'), '=', $vigencia)->orderBy('monthly_fee.created_at', 'desc')->pluck('amount');
     $monthly_all = MonthlyFee::where('monthly_fee.urbanism_id', '=', $urbanismo)->where(DB::raw('DATE_FORMAT(monthly_fee.since,\'%Y\')'), '=', $ano)->get();
     $monthly_ini = MonthlyFee::where('monthly_fee.urbanism_id', '=', $urbanismo)->where(DB::raw('DATE_FORMAT(monthly_fee.since,\'%Y\')'), '=', $ano)->orderBy('monthly_fee.created_at', 'ASC')->pluck('since');
     $mes_ini = (int) date("m", strtotime($monthly_ini));
     $months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Decem");
     $cuotas = array();
     foreach ($monthly_all as $cuota_mensual) {
         $ini = (int) date("m", strtotime($cuota_mensual->since));
         $fin = (int) date("m", strtotime($cuota_mensual->until));
         if ($cuota_mensual->until == NULL) {
             $fin = (int) date("m");
         }
         for ($i = $ini; $i <= $fin; $i++) {
             $cuotas[$months[$i - 1]] = $cuota_mensual->amount;
         }
     }
     $neighbor = Neighbors::with('NeighborProperty')->where('user_id', '=', $user_id)->get();
     foreach ($neighbor as $vecino) {
         foreach ($vecino->NeighborProperty as $property) {
             if ($property->urbanism_id == $urbanismo) {
                 $property_id = $property->id;
             }
         }
     }
     $balance = Balance::where('neighbor_property_id', '=', $property_id)->pluck('amount');
     if ($balance) {
         $saldo = $balance;
     } else {
         $saldo = 0;
     }
     $payments_states = PaymentStates::where('neighbor_property_id', '=', $property_id)->where('year', '=', $ano)->get();
     $breadcrumbs = Neighbors::with('NeighborProperty')->where('user_id', '=', $user_id)->first();
     $breadcrumbs_data = $breadcrumbs->name . " " . $breadcrumbs->last_name . " [ " . $urb_name . " ]";
     return View::make('dashboard.payments.account_states.states', ['payments' => $payments_states, 'cuotas' => $cuotas, 'months' => $months, 'saldo' => $saldo, 'prueba' => $user_id, 'mes_ini' => $mes_ini, 'sobrante' => 0, 'breadcrumbs_data' => $breadcrumbs_data]);
 }
Ejemplo n.º 15
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionTodayStorage()
 {
     $dates = date('Y:m:d');
     $depId = $_POST['depId'];
     $Products = array();
     /*$model = DepBalance::model()->with('products')->findAll('t.department_id = :depId AND t.type = :type',array(':depId'=>$depId,'type'=>1));
       foreach ($model as $val) {
           $products[$val->prod_id] = $val->getRelated('products')->name;
       }*/
     //$model = new Products();
     //$products = $model->getProdName($depId);
     $storageModel = Storage::model()->findAll();
     $balanceModel = Balance::model()->with('products')->findAll('b_date = :b_date', array(':b_date' => $dates));
     if (!empty($balanceModel)) {
         foreach ($balanceModel as $val) {
             $products[$val->prod_id] = $val->getRelated('products')->name;
             $Products[$val->prod_id] = $Products[$val->prod_id] + $val->startCount;
         }
     } else {
         foreach ($storageModel as $val) {
             $Products[$val->prod_id] = $Products[$val->prod_id] + $val->curCount;
         }
     }
     $realizedProd = Faktura::model()->with('realize.products')->findAll('date(realize_date) = :realize_date', array('realize_date' => $dates));
     foreach ($realizedProd as $value) {
         foreach ($value->getRelated('realize') as $val) {
             $Products[$val->prod_id] = $Products[$val->prod_id] + $val->count;
         }
     }
     $realizeStorageProd = DepFaktura::model()->with('realizedProd')->findAll('date(real_date) = :real_date AND fromDepId = :fromDepId', array(':real_date' => $dates, ':fromDepId' => 0));
     foreach ($realizeStorageProd as $value) {
         foreach ($value->getRelated('realizedProd') as $val) {
             $Products[$val->prod_id] = $Products[$val->prod_id] - $val->count;
         }
     }
     $expBalance = Yii::app()->db->createCommand()->select('ord.just_id,ord.count')->from('expense ex')->join('orders ord', 'ord.expense_id = ex.expense_id')->where('date(ex.order_date) = :dates AND ex.kind = :kind ', array(':dates' => $dates, ':kind' => 1))->queryAll();
     foreach ($expBalance as $val) {
         $Products[$val['just_id']] = $Products[$val['just_id']] - $val['count'];
     }
     $this->renderPartial('todayStorage', array('Products' => $Products, 'products' => $products, 'depId' => $depId));
 }
Ejemplo n.º 16
0
 public function takeMoney($amount, $wallet_id, $user_id)
 {
     $balanceCoin = Balance::where('user_id', '=', $user_id)->where('wallet_id', '=', $wallet_id)->first();
     if ($amount == 0) {
         return true;
     }
     if (isset($balanceCoin->amount)) {
         //update balance
         $old_amount = $balanceCoin->amount;
         if ($old_amount < $amount) {
             return false;
         } else {
             $new_amount = $old_amount - $amount;
             Log::info("Take Money " . $wallet_id . " -- User: "******": " . $new_amount . ' -- amount: ' . $amount);
             //echo "<br>Take New ".$wallet_id.": ".$new_amount.' -- amount: '.$amount;
             Balance::where('id', $balanceCoin->id)->update(array('amount' => $new_amount));
             return true;
         }
     } else {
         //insert balance
         return false;
     }
 }
 /**
  * @param $confirms
  * @param $transaction_model
  * @param $common_data
  * @param $btc_amount
  * @param $to_address
  * @param $satoshi_amount
  *
  * @return mixed
  */
 private function processUnknownAddress($confirms, $transaction_model = null, $common_data, $btc_amount, $to_address, $satoshi_amount)
 {
     if ($confirms > 0) {
         /* bitcoind sent 2nd callback for the transaction which is 1st confirmation
          * no need to shoot to the application, since application is updating first confirmation anyway on block-notify */
         Transaction::updateTxConfirmation($transaction_model, $common_data);
     } else {
         /* either its change address or somebody sent to some address that is not registered in db!
          * say some shit that address is unknown, and mail too! */
         MailHelper::sendEmailPlain(['email' => Config::get('mail.admin_email'), 'subject' => 'RECEIVED BITCOINS TO UNKNOWN ADDRESS', 'text' => 'RECEIVED ' . $btc_amount . ' BITCOINS TO UNKNOWN ADDRESS. Address that received it: ' . $to_address]);
         $initialUserBalance = Balance::getBalance($this->user->id, $this->crypto_type_id);
         $common_data['transaction_type'] = TX_RECEIVE;
         $common_data['note'] = TX_UNREGISTERED_ADDRESS;
         $common_data['user_balance'] = bcadd($initialUserBalance, $satoshi_amount);
         // new API user balance
         $common_data['previous_balance'] = $initialUserBalance->balance;
         // API user balance before that transaction, because user balance has not been updated yet
         $common_data['bitcoind_balance'] = bcmul($this->bitcoin_core->getbalance(), SATOSHIS_FRACTION);
         // bitcoind balance on received! that means this transaction is not included, because it has 0 conf
         // insert new transaction anyway
         Transaction::insertNewTransaction($common_data);
         Log::warning('Received payment to unregistered address');
     }
 }
Ejemplo n.º 18
0
 public function actionToday()
 {
     $dates = date('Y-m-d');
     $startProducts = array();
     $inProducts = array();
     $outProducts = array();
     $inOutProducts = array();
     $endProducts = array();
     $prodModel = Products::model()->findAll();
     //Приход
     $fakturaProd = Faktura::model()->with('realize.products')->findAll('date(realize_date) = :realize_date', array('realize_date' => $dates));
     foreach ($fakturaProd as $value) {
         foreach ($value->getRelated('realize') as $key => $val) {
             $inProducts[$val->getRelated('products')->product_id] = $inProducts[$val->getRelated('products')->product_id] + $val->count;
         }
     }
     //Расход
     $Depfaktura = DepFaktura::model()->with('realizedProd')->findAll('date(real_date) = :real_date', array(':real_date' => $dates));
     foreach ($Depfaktura as $value) {
         foreach ($value->getRelated('realizedProd') as $val) {
             $outProducts[$val->prod_id] = $outProducts[$val->prod_id] + $val->count;
         }
     }
     $expense = Expense::model()->with('order.products')->findAll('date(order_date) = :dates AND t.kind = :kind', array(':kind' => 1, ':dates' => $dates));
     foreach ($expense as $value) {
         foreach ($value->getRelated('order') as $val) {
             $inOutProducts[$val->just_id] = $inOutProducts[$val->just_id] + $val->count;
         }
     }
     $curProd = Balance::model()->with('products')->findAll('b_date = :dates', array(':dates' => $dates), array('order' => 'products.name'));
     foreach ($curProd as $value) {
         $endProducts[$value->prod_id] = $endProducts[$value->prod_id] + $value->startCount + $inProducts[$value->prod_id] - $outProducts[$value->prod_id] - $inOutProducts[$value->prod_id];
     }
     $this->render('today', array('prodModel' => $prodModel, 'model' => $curProd, 'inProducts' => $inProducts, 'outProducts' => $outProducts, 'inOutProducts' => $inOutProducts, 'endProducts' => $endProducts));
 }
Ejemplo n.º 19
0
 public function addProd($id)
 {
     if ($this->checkProd($id) != true) {
         $max_date = Balance::model()->find(array('select' => 'MAX(b_date) as b_date'));
         $model = new Balance();
         $model->b_date = $max_date->b_date;
         $model->prod_id = $id;
         $model->startCount = 0;
         $model->endCount = 0;
         $model->save();
     }
 }
Ejemplo n.º 20
0
 public function balanceAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     $data = $this->_getParam("data");
     $agentID = $this->_getParam("appID");
     $result = 0;
     try {
         $balance = new Balance();
         $parser = $balance->zingUnSignature($agentID, $data, 1);
         /*if($parser[0]!=$agentID){
           echo '0';
           return;
           }
           */
         $res = $balance->getBalance($parser[0]);
         if ($res->code == 0) {
             $result = $res->currentBalance;
         } else {
             if ($res->code == -3) {
                 $result = 0;
             } else {
                 $result = 0;
             }
         }
     } catch (Exception $e) {
     }
     echo $result;
 }
Ejemplo n.º 21
0
 public function doCancel()
 {
     if (Auth::guest()) {
         echo json_encode(array('status' => 'error', 'message' => Lang::get('messages.login_to_buy')));
         exit;
     }
     $logFile = 'trades.log';
     Log::useDailyFiles(storage_path() . '/logs/trades/' . $logFile);
     Log::info('------------------------- Do Cancel -----------------------------');
     $user = Confide::user();
     $balance = new Balance();
     $order_id = $_POST['order_id'];
     $orders = Order::find($order_id);
     if ($orders->user_id == $user->id && in_array($orders->status, $orders->getStatusActive())) {
         //this condition use to avoid case a user cancel order of other user
         //message_socket for update data not f5
         $message_socket['market_id'] = $orders->market_id;
         $message_socket_temp = array('id' => $orders->id, 'amount' => $orders->from_value, 'total' => $orders->to_value, 'action' => "update", 'price' => $orders->price);
         //refund money for user
         //get info market
         $market_default = Market::find($orders->market_id);
         $wallet_from = $market_default->wallet_from;
         $wallet_to = $market_default->wallet_to;
         $wallet = new Wallet();
         $from = $wallet->getType($wallet_from);
         $to = $wallet->getType($wallet_to);
         $value_refund = 0;
         $type_money_refund = '';
         if ($orders->type == 'buy') {
             //if buy: refund to_value to to_type_money (eg. Market BTC-> USD => refund to USD wallet)
             $value_refund = $orders->to_value;
             $type_money_refund = $wallet_to;
             $coin_code = $to;
             $message_socket['order_b'] = $message_socket_temp;
             $message_socket['order_b']['type'] = 'buy';
         } else {
             //if sell: refund from_value to from_type_money (eg. Market BTC-> USD => refund to BTC wallet)
             $value_refund = $orders->from_value;
             $type_money_refund = $wallet_from;
             $coin_code = $from;
             $message_socket['order_s'] = $message_socket_temp;
             $message_socket['order_s']['type'] = 'sell';
         }
         $balance->addMoney($value_refund, $type_money_refund, $user->id);
         //delete order
         $orders->delete();
         echo json_encode(array('status' => 'success', 'message_socket' => $message_socket, 'message' => Lang::get('messages.cancel_successfull', array('value' => $value_refund, 'coin' => strtoupper($coin_code)))));
         exit;
     } else {
         echo json_encode(array('status' => 'error', 'message' => Lang::get('messages.not_your_order')));
         exit;
     }
 }
Ejemplo n.º 22
0
 public function index($market_id = '')
 {
     $setting = new Setting();
     $wallet = new Wallet();
     $m = Market::where('active', 1)->orderBy('id')->first();
     if ($market_id == '') {
         $market_id = $setting->getSetting('default_market', $m->id);
     }
     Session::put('market_id', $market_id);
     $market_default = Market::find($market_id);
     if (!isset($market_default->active) || $market_default->active == 0) {
         //$setting->setSetting('default_market',$m->id);
         return Redirect::to('market/' . $m->id);
     }
     $wallet_from = $market_default->wallet_from;
     $wallet_to = $market_default->wallet_to;
     $from = strtoupper($wallet->getType($wallet_from));
     $to = strtoupper($wallet->getType($wallet_to));
     //get limit amount
     $limit_day = WalletTimeLimitTrade::select('limit_amount')->where('wallet_id', $wallet_to)->where('time_limit', 'per day')->first();
     if (isset($limit_day)) {
         $data['limit_day'] = $limit_day->limit_amount;
     } else {
         $data['limit_day'] = 1000;
     }
     $limit_week = WalletTimeLimitTrade::select('limit_amount')->where('wallet_id', $wallet_to)->where('time_limit', 'per week')->first();
     if (isset($limit_week)) {
         $data['limit_week'] = $limit_week->limit_amount;
     } else {
         $data['limit_week'] = 1000;
     }
     //get amount : day
     $user = Confide::user();
     if (isset($user)) {
         $uid = $user->id;
         $select = "SELECT sum(t.to_value) as sumamount from orders t, market m where m.id=t.market_id and m.wallet_to=" . $wallet_to . " and t.user_id=" . $uid . " and t.created_at='" . date("Y-m-d") . "'";
         $selectsum = DB::select($select);
         $sumamount = $selectsum[0]->sumamount;
         $data['amount_sum_day'] = $sumamount;
     }
     if (!isset($data['amount_sum_day'])) {
         $data['amount_sum_day'] = 0;
     }
     //echo 'aaaaaaaaaaa:'; print_r($data['amount_sum_day']);
     //get name of wallet
     $wallet1 = Wallet::where('id', $wallet_from)->first();
     $wallet2 = Wallet::where('id', $wallet_to)->first();
     $data['market_from'] = $wallet1->name;
     $data['market_to'] = $wallet2->name;
     $data['coinmain'] = $from;
     $data['coinsecond'] = $to;
     //get balance
     $balance = new Balance();
     $data['balance_coinmain'] = sprintf('%.8f', $balance->getBalance($wallet_from, 0));
     $data['balance_coinsecond'] = sprintf('%.8f', $balance->getBalance($wallet_to, 0));
     //get Sell Lowest
     $data['sell_lowest'] = sprintf('%.8f', 0);
     $data['buy_highest'] = sprintf('%.8f', 0);
     $order = new Order();
     $sell_lowest = $order->getSellLowest($market_id);
     $buy_highest = $order->getBuyHighest($market_id);
     if (isset($sell_lowest->price)) {
         $data['sell_lowest'] = sprintf('%.8f', $sell_lowest->price);
     }
     if (isset($buy_highest->price)) {
         $data['buy_highest'] = sprintf('%.8f', $buy_highest->price);
     }
     //fee_buy, fee_sell
     $fee_trade = new FeeTrade();
     $fee = $fee_trade->getFeeTrade($market_id);
     $data['fee_buy'] = $fee['fee_buy'];
     $data['fee_sell'] = $fee['fee_sell'];
     //get list orders
     $num_transaction_display = $setting->getSetting('num_transaction_display', 0);
     $list_sell_orders = $order->getOrders($market_id, 'sell', $num_transaction_display);
     $list_buy_orders = $order->getOrders($market_id, 'buy', $num_transaction_display);
     $data['sell_orders'] = $list_sell_orders;
     $data['buy_orders'] = $list_buy_orders;
     //get all history
     $trade_history = Trade::where('market_id', '=', $market_id)->orderBy('created_at', 'desc')->take($num_transaction_display)->get();
     $data['trade_history'] = $trade_history;
     $data['market_id'] = $market_id;
     $current_orders_user = $order->getCurrentOrdersUser($market_id);
     if ($current_orders_user) {
         $data['current_orders_user'] = $current_orders_user;
     }
     $trade = new Trade();
     $datachart = $trade->getDatasChart($market_id, '6 hour');
     $news = Post::where('type', 'news')->take(5)->orderby('created_at', 'desc')->get();
     $data['news'] = $news;
     //price
     $data_price = $trade->getBlockPrice($market_id);
     $data["get_prices"] = $data_price['get_prices'];
     $data['lastest_price'] = $data_price['lastest_price'];
     //limit trade amount
     $limit_trade = WalletLimitTrade::where('wallet_id', $wallet_from)->first();
     if ($limit_trade) {
         $data['limit_trade'] = $limit_trade->toArray();
     } else {
         $data['limit_trade'] = array('min_amount' => 0.0001, 'max_amount' => 1000);
     }
     //get data for block statistic
     $btc_wallet = Wallet::where('type', 'BTC')->first();
     $ltc_wallet = Wallet::where('type', 'LTC')->first();
     $btc_markets = array();
     $ltc_markets = array();
     //btc market on sidebar left
     $all_market_btc = array();
     if (isset($btc_wallet->id)) {
         $btc_markets = Market::leftJoin('wallets', 'market.wallet_from', '=', 'wallets.id')->select('market.*', 'wallets.name', 'wallets.type')->where('wallet_to', $btc_wallet->id)->orderby('wallets.type')->get();
         $btc_datainfo = array();
         foreach ($btc_markets as $value) {
             $all_market_btc[] = $value->id;
             $btc_datainfo[$value->id] = Trade::where('market_id', $value->id)->orderby('created_at', 'desc')->take(2)->get()->toArray();
             //      	$total_btc = DB::table('trade_history')->select(DB::raw('SUM( amount * price ) AS total'))
             //                  ->where('market_id', '=', $value->id)->first();
             //              //echo "<pre>total_btc: "; print_r($total_btc); echo "</pre>";
             //              //echo "<pre>getQueryLog: ".dd(DB::getQueryLog())."</pre>";
             // if(isset($total_btc->total))
             // 	$ltc_datainfo[$value->id]['total'] = $total_btc->total;
             $select = "SELECT SUM( amount * price ) AS total FROM trade_history Where `market_id`='" . $value->id . "' GROUP BY market_id";
             $total_btc = DB::select($select);
             if (isset($total_btc[0])) {
                 $btc_datainfo[$value->id]['total'] = $total_btc[0]->total;
             } else {
                 $btc_datainfo[$value->id]['total'] = 0;
             }
         }
         $data['btc_datainfo'] = $btc_datainfo;
     }
     //ltc market on sidebar left
     $all_market_ltc = array();
     if (isset($ltc_wallet->id)) {
         $ltc_markets = Market::leftJoin('wallets', 'market.wallet_from', '=', 'wallets.id')->select('market.*', 'wallets.name', 'wallets.type')->where('wallet_to', $ltc_wallet->id)->orderby('wallets.type')->get();
         $ltc_datainfo = array();
         foreach ($ltc_markets as $value) {
             $all_market_ltc[] = $value->id;
             $ltc_datainfo[$value->id] = Trade::where('market_id', $value->id)->orderby('created_at', 'desc')->take(2)->get()->toArray();
             // $total_ltc = DB::table('trade_history')->select(DB::raw('SUM( amount * price ) AS total'))
             //                  ->where('market_id', '=', $value->id)->first();
             // if(isset($total_ltc->total))
             // 	$ltc_datainfo[$value->id]['total'] = $total_ltc->total;
             $select = "SELECT SUM( amount * price ) AS total FROM trade_history Where `market_id`='" . $value->id . "' GROUP BY market_id";
             $total_ltc = DB::select($select);
             if (isset($total_ltc[0])) {
                 $ltc_datainfo[$value->id]['total'] = $total_ltc[0]->total;
             } else {
                 $ltc_datainfo[$value->id]['total'] = 0;
             }
         }
         $data['ltc_datainfo'] = $ltc_datainfo;
     }
     $data['btc_markets'] = $btc_markets;
     $data['ltc_markets'] = $ltc_markets;
     $date = date("Y-m-d H:i:s", strtotime(" -24 hour"));
     //echo "+24 hours: ".$date;
     if (!empty($all_market_btc)) {
         $data['statistic_btc'] = DB::table('trade_history')->select(DB::raw('COUNT(*) as number_trade,SUM( amount * price ) AS total'))->where('created_at', '>=', $date)->whereIn('market_id', $all_market_btc)->first();
     }
     if (!empty($all_market_ltc)) {
         $data['statistic_ltc'] = DB::table('trade_history')->select(DB::raw('COUNT(*) as number_trade,SUM( amount * price ) AS total'))->where('created_at', '>=', $date)->whereIn('market_id', $all_market_ltc)->first();
     }
     $data['wallets'] = Wallet::orderby('type')->get();
     return View::make('home', $data);
 }
Ejemplo n.º 23
0
 public static function add($currency, $desc, $summ)
 {
     $last = Balance::model()->find(array('condition' => 'currency = "' . $currency . '"', 'order' => 'id desc'));
     $last_balance = 0;
     if ($last) {
         $last_balance = $last->balance;
     }
     $bot = Bot::get_Instance();
     $b = new Balance();
     $b->dtm = $bot->current_exchange->dtm;
     $b->description = $desc;
     $b->summ = $summ;
     $b->balance = $last_balance + $summ;
     $b->currency = $currency;
     $b->save() || die(print_r($b->errors, true));
     return $last;
 }
<?php

require_once "generarBalanceGeneral.php";
$balance = new Balance();
$balance->mostrarBalance();
Ejemplo n.º 25
0
 /**
  * Show the form for editing the specified resource.
  *    
  * @return Response
  */
 public function edit()
 {
     $balance = Balance::orderBy('id', 'desc')->first();
     if (!$balance) {
         $balance = new Balance();
         $balance->amount = '0';
     }
     $balance->save();
     return View::make('transactions.panels.balance')->with('balance');
 }
 public function charges_store()
 {
     $user_id = Auth::user()->id;
     $colonia = Session::get("colonia");
     $urbanism = Urbanism::where('colony_id', '=', $colonia)->first();
     $collector = Collector::where('user_id', '=', $user_id)->where('urbanism_id', '=', $urbanism->id)->first();
     $ano = date("Y");
     $neighbor = Input::get('valorid');
     $amount = Input::get('amount');
     $income_charge = new Payment();
     $income_charge->neighbor_property_id = $neighbor;
     $income_charge->collector_id = $collector->id;
     $income_charge->amount = $amount;
     $income_charge->sub_account_id = Input::get('sub_account_id');
     $income_charge->coments = Input::get('coments');
     $income_charge->deposit = null;
     $income_charge->debt = null;
     $income_charge->status_id = 1;
     $income_charge->updated_at = date('Y') . '-01-01 ' . date('H:i:s');
     if ($income_charge->save()) {
         $neighbor_payments = $income_charge;
         $payment_state = PaymentStates::where('neighbor_property_id', '=', $neighbor)->where('year', '=', $ano)->orderBy('created_at', 'desc')->first();
         $months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
         $monthly_all = MonthlyFee::where('monthly_fee.urbanism_id', '=', $collector->urbanism_id)->where(DB::raw('DATE_FORMAT(monthly_fee.since,\'%Y\')'), '=', $ano)->get();
         $monthly_ini = MonthlyFee::where('monthly_fee.urbanism_id', '=', $collector->urbanism_id)->where(DB::raw('DATE_FORMAT(monthly_fee.since,\'%Y\')'), '=', $ano)->orderBy('monthly_fee.created_at', 'ASC')->pluck('since');
         $mes_ini = (int) date("m", strtotime($monthly_ini));
         $cuotas = array();
         foreach ($monthly_all as $cuota_mensual) {
             $ini = (int) date("m", strtotime($cuota_mensual->since));
             $fin = (int) date("m", strtotime($cuota_mensual->until));
             if ($cuota_mensual->until == NULL) {
                 $fin = (int) date("m");
             }
             for ($i = $ini; $i <= $fin; $i++) {
                 $cuotas[$months[$i - 1]] = $cuota_mensual->amount;
             }
         }
         $acumulado = $amount;
         //para guardar el monto
         $ValorInicial = $amount;
         //para guardar el valor inicial del monto ingresado
         $ValorResto = 0;
         //para comparar con el valor inicial
         $balance = Balance::where('neighbor_property_id', '=', $neighbor)->pluck('amount');
         $balance_saldo = Balance::where('neighbor_property_id', '=', $neighbor)->first();
         if ($balance) {
             $saldo = $balance;
             if ($saldo > $amount) {
                 $saldo = $saldo - $amount;
                 $amount = 0;
                 $balance_saldo->amount = $saldo;
                 $balance_saldo->update(['id']);
             } else {
                 if ($saldo < $amount) {
                     $saldo = $amount - $saldo;
                     $amount = $saldo;
                     $balance_saldo->delete(['id']);
                 } else {
                     $saldo = 0;
                     $amount = 0;
                     $balance_saldo->delete(['id']);
                 }
             }
         } else {
             $saldo = 0;
         }
         //Si el usuario no ha realizado ningún pago, se llena la tabla Payment_States por primera vez
         if (!$payment_state) {
             $TotalCuotas = 0;
             $payment_state_detail = new PaymentStates();
             $payment_state_detail->neighbor_property_id = $neighbor_payments->neighbor_property_id;
             $payment_state_detail->year = date('Y', strtotime($neighbor_payments->created_at));
             //Ciclo hasta el mes actual
             for ($i = $mes_ini - 1; $i < date('m'); $i++) {
                 if (date('m') != $i + 1) {
                     if ($amount > $cuotas[$months[$i]]) {
                         $payment_state_detail->{$months}[$i] = $cuotas[$months[$i]];
                         $amount = $amount - $cuotas[$months[$i]];
                     } else {
                         if ($amount < $cuotas[$months[$i]] && $amount != 0) {
                             $payment_state_detail->{$months}[$i] = $amount;
                             $amount = 0;
                         } else {
                             $payment_state_detail->{$months}[$i] = $cuotas[$months[$i]];
                             $amount = 0;
                         }
                     }
                 } else {
                     //si es el mes actual
                     // for: suma todas las cuotas de cada mes, las q se deben
                     for ($j = $mes_ini - 1; $j < date('m'); $j++) {
                         if ($payment_state_detail->{$months}[$j] == null) {
                             $TotalCuotas = $TotalCuotas + $cuotas[$months[$j]];
                         } elseif ($payment_state_detail->{$months}[$j] < $cuotas[$months[$j]] && $payment_state_detail->{$months}[$j] > 0) {
                             $resto_mes = $cuotas[$months[$j]] - $payment_state_detail->{$months}[$j];
                             $TotalCuotas = $TotalCuotas + $resto_mes;
                         }
                     }
                     if ($TotalCuotas > $amount) {
                         $TotalCuotas = $TotalCuotas - $amount;
                         $payment_state_detail->{$months}[$i] = "-" . $TotalCuotas;
                     } elseif ($TotalCuotas < $amount) {
                         $TotalCuotas = $amount - $TotalCuotas;
                         $payment_state_detail->{$months}[$i] = $cuotas[$months[$i]] + $TotalCuotas;
                         $amount = $TotalCuotas;
                     } elseif ($TotalCuotas == $amount) {
                         //si la cuota es igual al monto que esta pagando
                         $payment_state_detail->{$months}[$i] = $cuotas[$months[$i]];
                         $amount = 0;
                     }
                 }
             }
             //fin del ciclo
             $payment_state_detail->accumulated = $acumulado;
             //Se guardan los datos en Payment_States
             $payment_state_detail->save();
         } else {
             //si ya tiene registros en payment_state
             $fondo = $payment_state->accumulated + $amount;
             $valorResto = 0;
             $abono = 0;
             for ($i = $mes_ini - 1; $i < date('m'); $i++) {
                 if (date('m') != $i + 1) {
                     if ($payment_state->{$months}[$i]) {
                         if ($payment_state->{$months}[$i] != $cuotas[$months[$i]] && $payment_state->{$months}[$i] > 0) {
                             $valorResto = $ValorResto + $payment_state->{$months}[$i];
                             $amount = $amount + $valorResto;
                             if ($amount > $cuotas[$months[$i]]) {
                                 $payment_state->{$months}[$i] = $cuotas[$months[$i]];
                                 $amount = $amount - $cuotas[$months[$i]];
                             } else {
                                 $payment_state->{$months}[$i] = $amount;
                                 $amount = 0;
                             }
                         }
                     } else {
                         if ($amount > $cuotas[$months[$i]]) {
                             $payment_state->{$months}[$i] = $cuotas[$months[$i]];
                             $amount = $amount - $cuotas[$months[$i]];
                         } else {
                             if ($amount < $cuotas[$months[$i]]) {
                                 $payment_state->{$months}[$i] = $amount;
                                 $amount = 0;
                             } else {
                                 $payment_state->{$months}[$i] = $cuotas[$months[$i]];
                                 $amount = 0;
                             }
                         }
                     }
                 } else {
                     //si es el mes actual
                     if ($payment_state->{$months}[$i] < 0) {
                         $deuda = -1 * $payment_state->{$months}[$i];
                         $deuda = $amount - $deuda;
                         if ($deuda < 0) {
                             $payment_state->{$months}[$i] = $deuda;
                         } else {
                             if ($deuda == 0) {
                                 $payment_state->{$months}[$i] = $cuotas[$months[$i]];
                             } else {
                                 $payment_state->{$months}[$i] = $deuda + $cuotas[$months[$i]];
                             }
                         }
                     } else {
                         $abono = $payment_state->{$months}[$i] + $amount;
                         $payment_state->{$months}[$i] = $abono;
                     }
                 }
             }
             $payment_state->accumulated = $fondo;
             $payment_state->update(['id']);
         }
         //---envio por email de recibo al pagador---
         $mensaje = null;
         $monto = Input::get('amount');
         $infoCobrador = Neighbors::with('NeighborProperty')->where('user_id', '=', $user_id)->first();
         $infoPagador = NeighborProperty::where('id', '=', $neighbor)->first();
         $email = UserNeighbors::where('id', '=', $infoPagador->Neighbors->user_id)->pluck('email');
         $tipoUrb = $infoPagador->Urbanism->UrbanismType->id;
         if ($tipoUrb == 3) {
             $Domicilio = "Piso " . $infoPagador->Building->description . ' - Apartamento ' . $infoPagador->num_house_or_apartment;
         } else {
             $Domicilio = "Calle " . $infoPagador->Street->name . ' - Casa ' . $infoPagador->num_house_or_apartment;
         }
         $Colony = Urbanism::with('Colony.City')->where('id', '=', $infoPagador->Urbanism->id)->first();
         $state = DB::table('states')->where('id', $Colony->Colony->City->state_id)->first();
         $dias = array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado");
         $meses = array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
         $fecha = $dias[date('w')] . " " . date('d') . " de " . $meses[date('n') - 1] . " del " . date('Y');
         $pay_states = PaymentStates::where('neighbor_property_id', '=', $neighbor)->where('year', '=', $ano)->get();
         $data = array('Cobrador' => $infoCobrador->name . " " . $infoCobrador->last_name, 'Nombre' => $infoPagador->Neighbors->name . " " . $infoPagador->Neighbors->last_name, 'Domicilio' => $Domicilio, 'monto' => $monto, 'Fecha' => $fecha, 'colonia' => $Colony->Colony->name, 'urbanismo' => $infoPagador->Urbanism->name, 'estado' => $state->name, 'ciudad' => $Colony->Colony->City->name, 'payments' => $pay_states, 'months' => $months, 'cuotas' => $cuotas, 'mes_ini' => $mes_ini);
         try {
             Mail::send('emails.Recibo', $data, function ($message) use($email) {
                 $message->to($email);
                 $message->subject('Recibo de pago');
             });
         } catch (Exception $exc) {
             Mail::send('emails.Recibo', $data, function ($message) use($email) {
                 $message->to($email);
                 $message->subject('Recibo de pago');
             });
         }
         // ---/fin de envio por email de recibo al pagador/----
         //se agrego el logs
         Event::fire('logs', 'hizo un Cobro al Domicilio ' . $Domicilio . ' de un Monto de' . $monto);
         //fin logs
         return Redirect::action('IncomesController@charges_index')->with('error', false)->with('msg', 'Cobro ingresado con éxito.')->with('class', 'info');
     } else {
         return Redirect::back()->with('error', true)->with('msg', '¡Algo salió mal! Contacte con administrador.')->with('class', 'danger');
     }
 }
Ejemplo n.º 27
0
 public function doTransfer()
 {
     $trade_key = Input::get('trade_key');
     $amount = Input::get('amount');
     $wallet_id = Input::get('wallet_id');
     $password = Input::get('password');
     $wallet = Wallet::find($wallet_id);
     $balance = new Balance();
     $user = Confide::user();
     if (Hash::check($password, $user->password)) {
         $user_receive = User::where('trade_key', $trade_key)->first();
         $amount_balance = $balance->getBalance($wallet->id);
         if (!isset($user_receive->username)) {
             return Redirect::to('user/transfer-coin/' . $wallet->id)->with('error', 'Sorry. The trade key not exist!');
         } elseif ($user_receive->id == $user->id) {
             return Redirect::to('user/transfer-coin/' . $wallet->id)->with('error', 'Sorry. You can not referrer to yourself!');
         } elseif ($amount_balance < $amount) {
             return Redirect::to('user/transfer-coin/' . $wallet->id)->with('error', 'Amount should be less than or equal to your balance.');
         } else {
             if ($balance->takeMoney($amount, $wallet->id, $user->id)) {
                 $balance->addMoney($amount, $wallet->id, $user_receive->id);
                 $transfer_his = new Transfer();
                 $transfer_his->sender = $user->id;
                 $transfer_his->receiver = $user_receive->id;
                 $transfer_his->wallet_id = $wallet->id;
                 $transfer_his->amount = $amount;
                 $transfer_his->save();
                 return Redirect::to('user/transfer-coin/' . $wallet->id)->with('success', 'You sent to user "' . $user_receive->username . '" ' . $amount . ' ' . $wallet->getType($wallet->id) . '.');
             }
         }
     } else {
         return Redirect::to('user/transfer-coin/' . $wallet->id)->with('error', "Password invalid.");
     }
 }
Ejemplo n.º 28
0
 public function actionOrders()
 {
     if ($_SERVER['HTTP_HOST'] !== 'btcbot.loc') {
         return;
     }
     $btc_rur = Exchange::updatePrices('btc_rur');
     $bot = new Bot($btc_rur);
     $info = $bot->api->getInfo();
     if ($info) {
         $bot->setBalance($info['funds']['rur']);
         $bot->setBalanceBtc($info['funds']['btc']);
         Status::setParam('balance', $info['funds']['rur']);
         Status::setParam('balance_btc', $info['funds']['btc']);
         Balance::actualize('rur', $bot->balance);
         Balance::actualize('btc', $bot->balance_btc);
     }
     $bot->checkOrders();
 }
Ejemplo n.º 29
0
<?php

$cnt = 1;
$expense = new Expense();
$depRealize = new DepFaktura();
$sumCostPrice = 0;
$sumPrice = 0;
$beforeSumCostPrice = 0;
$beforeSumPrice = 0;
$balance = new Balance();
$sumRealized = 0;
$sumInRealized = 0;
$sumInExp = 0;
$startCount = 0;
$endCount = 0;
$curEndCount = 0;
$sumFaktCost = 0;
?>
    <style>
        td,th{
            font-size: 12px;
        }
        .green{
            color: green;
        }
        .red{
            color: red;
        }
        .rait{
            padding: 0 8px!important;
        }
Ejemplo n.º 30
0
 public function blocknotifyUpdateDeposit($wallet_type = '')
 {
     $blockhash = isset($_GET['trxhash']) ? $_GET['trxhash'] : 0;
     $logFile = 'laravel_' . $wallet_type . '.log';
     Log::useDailyFiles(storage_path() . '/logs/callbackdeposits/' . $logFile);
     Log::info("*******New Blocknotify Update Deposit: " . $blockhash . " -- wallet_type: " . $wallet_type);
     Log::info("\n" . "-- wallet_type: " . $wallet_type);
     if ($wallet_type != '') {
         $wallet = Wallet::where('type', strtoupper($wallet_type))->first();
         $wallet->connectJsonRPCclient($wallet->wallet_username, $wallet->wallet_password, $wallet->wallet_ip, $wallet->port);
         $limit_confirmations = empty($wallet->limit_confirmations) || $wallet->limit_confirmations <= 0 ? 3 : $wallet->limit_confirmations;
         $listtrans = $wallet->getListTransactions();
         @Log::info("\n" . 'Result listtrans: ', $listtrans);
         $balance = new Balance();
         foreach ($listtrans as $key => $value) {
             try {
                 $transaction_id = $value['txid'];
                 $trans = $wallet->getTransaction($transaction_id);
                 if ($trans != null) {
                     $account = $trans["details"][0]["account"];
                     $category = $trans["details"][0]["category"];
                     $confirms = $trans["confirmations"];
                     //send,receive
                     $address_ = $trans["details"][0]["address"];
                     $amount = $trans["amount"];
                     Log::info("\n" . "transaction: ", $trans);
                     Log::info("\n" . "------Account: " . $account . " -- category:" . $category . " --address: " . $address_);
                     //mail("*****@*****.**", 'Deposit Cron: ', var_export($trans, true));
                     $deposit = Deposit::where('transaction_id', $transaction_id)->first();
                     $user = User::where('username', $account)->first();
                     if (isset($deposit->transaction_id)) {
                         if ($deposit->paid == 0) {
                             if ($category == "receive" && $confirms >= $limit_confirmations && isset($user->id)) {
                                 Deposit::where('id', $deposit->id)->update(array('paid' => 1, 'confirmations' => $confirms));
                                 $balance->addMoney($amount, $wallet->id, $user->id);
                                 $message .= "<br>" . $amount . " " . $wallet->type . " was credited to your account";
                                 Log::info("\n" . $amount . " " . $wallet->type . " was credited to your account");
                             }
                         } else {
                             Deposit::where('id', $deposit->id)->update(array('confirmations' => $confirms));
                             Log::info("\n" . $amount . " " . $wallet->type . " was already credited to your account. contact support if you need further assistance.");
                         }
                     } else {
                         if ($category == "receive" && isset($user->id)) {
                             if ($confirms >= $limit_confirmations) {
                                 Deposit::insert(array('user_id' => $user->id, 'wallet_id' => $wallet->id, 'transaction_id' => $transaction_id, 'amount' => $amount, 'paid' => 1, 'confirmations' => $confirms, 'address' => $address_, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')));
                                 $balance->addMoney($amount, $wallet->id, $user->id);
                                 Log::info("\n" . $amount . " " . $wallet->type . " was credited to your account");
                             } else {
                                 Deposit::insert(array('user_id' => $user->id, 'wallet_id' => $wallet->id, 'transaction_id' => $transaction_id, 'amount' => $amount, 'paid' => 0, 'confirmations' => $confirms, 'address' => $address_, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')));
                                 Log::info("\n" . "This Deposit is unconfirmed. Current confirmations:" . $confirms . ". Required : 3.");
                             }
                         } else {
                             Log::info("\n" . "transaction is not a deposit or account is invalid.");
                         }
                     }
                 } else {
                     Log::info("\n" . "We can't find any information about this deposit. contact support.");
                 }
                 //trans
             } catch (Exception $e) {
                 Log::info('Caught exception: ' . $e->getMessage() . "\n");
             }
         }
     } else {
         Log::info('------------------- Error: not param wallet_type from _GET');
     }
     Log::info("*******Stop New Blocknotify Update Deposit*************");
 }