public function requestCashOut()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idResto = Generic::mustCheck($_GET['id_restaurant'], "No ID Restaurant Found");
     $amount = Generic::mustCheck($_GET['amount'], "No Amount Found");
     if ($amount == "0") {
         Generic::errorMsg("Zero Amount not Allowed");
     }
     $bankAcc = new RestoBankAccModel();
     $arrBank = $bankAcc->getWhere("id_restaurant='{$idResto}'");
     if (count($arrBank) <= 0) {
         Generic::errorMsg("You Have Not Set Your Cash Out Account");
     }
     $req = new MasterCashOutRequestModel();
     $arrReq = $req->getWhere("id_restaurant='{$idResto}' AND status='0'");
     if (count($arrReq) > 0) {
         Generic::errorMsg("You Already Request Cash Out");
     }
     $resto = new MasterRestaurantModel();
     $resto->getByID($idResto);
     $cashOut = new MasterCashOutRequestModel();
     $cashOut->id_restaurant = $idResto;
     $cashOut->datetime_request = leap_mysqldate();
     $cashOut->amount = $amount;
     $cashOut->status = 0;
     $idNewRequest = $cashOut->save();
     $tr = new MasterRestoTransactionModel();
     $tr->id_request = $idNewRequest;
     $tr->id_restaurant = $idResto;
     $tr->gross_amount = (double) $amount * -1;
     $tr->net_amount = (double) $amount * -1;
     $tr->approved = "0";
     $tr->type_transaction = "2";
     $tr->datetime_transaction = leap_mysqldate();
     $tr->mr_fee = 0;
     $tr->credit_card_fee = 0;
     $tr->other_fee = 0;
     $tr->bank_disc = 0;
     $tr->save();
     $json['status_code'] = 1;
     $json['results']['messages'] = "success";
     echo json_encode($json);
     die;
 }
 public function getCurrentCredits()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idResto = Generic::mustCheck($_GET['id_restaurant'], "No ID Restaurant Found");
     global $db;
     $rt = new MasterRestoTransactionModel();
     $q = "SELECT IFNULL(SUM(gross_amount),0) AS gross_amount,IFNULL(SUM(net_amount),0) AS net_amount FROM {$rt->table_name} WHERE id_restaurant='{$idResto}' AND approved='1'";
     $arrTrans = $db->query($q, 2);
     $result['gross_amount'] = (double) $arrTrans[0]->gross_amount;
     $result['net_amount'] = (double) $arrTrans[0]->net_amount;
     $r = new MasterCashOutRequestModel();
     $arr = $r->getWhere("id_restaurant= '{$idResto}' AND status='0'");
     $result['has_pending_request'] = count($arr) <= 0 ? false : true;
     $result['pending_amount'] = count($arr) <= 0 ? (double) 0 : (double) $arr[0]->amount;
     $json['status_code'] = 1;
     $json['results'] = $result;
     echo json_encode($json);
     die;
 }