Пример #1
0
 public function applicationUserRequest(Request $request)
 {
     $statusObject = array("applied" => array("step" => "สมัครขอทุน", "appStatus" => "Pending", "approve" => "approved", "reject" => "rejected"), "rejected" => array("step" => "สมัครขอทุน", "appStatus" => "Reject"), "approved" => array("step" => "สมัครขอทุน", "appStatus" => "Approve"), "signed_agreement" => array("step" => "ทำสัญญารับทุน", "appStatus" => "Pending", "approve" => "approved_agreement", "reject" => "rejected_agreement", "files" => array(1, 2, 22)), "rejected_agreement" => array("step" => "ทำสัญญารับทุน", "appStatus" => "Reject", "files" => array(1, 2, 22)), "approved_agreement" => array("step" => "ทำสัญญารับทุน", "appStatus" => "Approve"), "first_payment" => array("step" => "เบิกเงินงวดที่ 1", "appStatus" => "Pending", "approve" => "approved_first_payment", "reject" => "rejected_first_payment", "files" => array(3, 4, 5, 6)), "rejected_first_payment" => array("step" => "เบิกเงินงวดที่ 1", "appStatus" => "Reject", "files" => array(3, 4, 5, 6)), "approved_first_payment" => array("step" => "เบิกเงินงวดที่ 1", "appStatus" => "Approve"), "second_payment" => array("step" => "รายงานความก้าวหน้าครั้งที่ 1", "appStatus" => "Pending", "approve" => "approved_second_payment", "reject" => "rejected_second_payment", "files" => array(7, 8, 9)), "rejected_second_payment" => array("step" => "รายงานความก้าวหน้าครั้งที่ 1", "appStatus" => "Reject", "files" => array(7, 8, 9)), "approved_second_payment" => array("step" => "รายงานความก้าวหน้าครั้งที่ 1", "appStatus" => "Approve"), "second_progress_report" => array("step" => "รายงานความก้าวหน้าครั้งที่ 2", "appStatus" => "Pending", "approve" => "approved_second_progress_report", "reject" => "rejected_second_progress_report", "files" => array(10, 11)), "rejected_second_progress_report" => array("step" => "รายงานความก้าวหน้าครั้งที่ 2", "appStatus" => "Reject", "files" => array(10, 11)), "approved_second_progress_report" => array("step" => "รายงานความก้าวหน้าครั้งที่ 2", "appStatus" => "Approve"), "finalized" => array("step" => "ส่งผลงานเพื่อปิดโครงการ", "appStatus" => "Pending", "approve" => "approved_finalized", "reject" => "rejected_finalized", "files" => array(17, 18, 19, 20, 21, 23, 24)), "rejected_finalized" => array("step" => "ส่งผลงานเพื่อปิดโครงการ", "appStatus" => "Reject", "files" => array(17, 18, 19, 20, 21, 23, 24)), "approved_finalized" => array("step" => "ส่งผลงานเพื่อปิดโครงการ", "appStatus" => "Approve"), "request_extend" => array("step" => "ขอขยายเวลา", "appStatus" => "Pending", "approve" => "approved_extend", "reject" => "rejected_extend", "files" => array(14, 15, 16)), "rejected_extend" => array("step" => "ขอขยายเวลา", "appStatus" => "Reject", "files" => array(14, 15, 16)), "approved_extend" => array("step" => "ขอขยายเวลา", "appStatus" => "Approve"), "project_finished" => array("step" => "ปิดโครงการ", "appStatus" => "Pending", "approve" => "approved_project_finished", "reject" => "rejected_project_finished", "files" => array(17, 18, 19, 20, 21, 23, 24)), "rejected_project_finished" => array("step" => "ปิดโครงการ", "appStatus" => "Reject", "files" => array(17, 18, 19, 20, 21, 23, 24)), "approved_project_finished" => array("step" => "ปิดโครงการ", "appStatus" => "Approve"));
     $id = $request->get('id', null);
     $applications = DB::table('applications')->join('funds', 'applications.fund', '=', 'funds.id')->join('users', 'applications.owner', '=', 'users.id')->where('fund', $id)->select('applications.id', 'applications.status', 'funds.name as fundName', 'users.name as userName')->get();
     $fund = Fund::find($id);
     if (!$fund) {
         return redirect()->route('fund_user_request_choose');
     }
     for ($i = 0; $i < count($applications); $i++) {
         $applications[$i]->step = $statusObject[$applications[$i]->status]['step'];
         $applications[$i]->appStatus = $statusObject[$applications[$i]->status]['appStatus'];
         $applications[$i]->documents = null;
         if ($applications[$i]->appStatus != 'Approve') {
             if ($applications[$i]->appStatus == 'Pending') {
                 $applications[$i]->approve = $statusObject[$applications[$i]->status]['approve'];
                 $applications[$i]->reject = $statusObject[$applications[$i]->status]['reject'];
             }
             if ($applications[$i]->status != 'applied' && $applications[$i]->status != 'rejected') {
                 $documents = [];
                 $files = $statusObject[$applications[$i]->status]['files'];
                 for ($j = 0; $j < count($files); $j++) {
                     $upload = Upload::where('filetype', $files[$j])->where('application_id', $applications[$i]->id)->first();
                     $filetype = Filetype::find($upload->filetype);
                     array_push($documents, array("file_name" => $filetype->name, "file_path" => $upload->file_path, "file_status" => $upload->status, "upload_id" => $upload->id));
                 }
                 $applications[$i]->documents = $documents;
             }
         }
     }
     return view('admin.fund_user_request', ['applications' => $applications, 'fundName' => $fund->name]);
 }
 /**
  * Displays the view for the Admin control panel.
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function index()
 {
     if (!$this->authorize('show-admin')) {
         redirect('home');
     }
     $data = ['page_title' => 'Admin Dashboard', 'users' => User::getUser(), 'num_users' => User::getNumOfUsers(), 'roles' => Role::all(), 'num_admins' => User::getNumAdmins(), 'centers' => Fund::all()];
     return view('admin.dashboard', $data);
 }
Пример #3
0
 /**
  * Gets a multidimensional array of all of the centers
  * and the accounts that belong to each.
  *
  * @param $center_id
  * @return array
  */
 public static function getCenter($center_id = false)
 {
     $centers = [];
     if ($center_id) {
         array_push($centers, Fund::find($center_id));
     } else {
         foreach (Fund::all() as $fund) {
             array_push($centers, $fund);
         }
     }
     return $centers;
 }
Пример #4
0
 public function fundFormFileUpload(Request $request)
 {
     $fundId = $request->get('id', 0);
     $fund = Fund::find($fundId);
     if (!$fund) {
         return redirect()->route('fund_manage');
     }
     return view('admin.fund_form_file_upload', ['fundId' => $fundId]);
 }
Пример #5
0
 /**
  * Store a newly created resource in storage.
  *
  * @param CreateFundRequest $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(CreateFundRequest $request)
 {
     $values = $request->only(['provider_id', 'name', 'website', 'investment_term', 'loans_rate', 'min_size', 'max_size', 'focus', 'status']);
     Fund::create($values);
     return response()->json(['message' => 'Fund successfully created.', 'code' => 201], 201);
 }
Пример #6
0
 public function manualnotify(Request $request)
 {
     $app_id = $request->get('appid');
     $application = Application::find($app_id);
     // die($application);
     $fund = Fund::find($application->fund);
     // print_r($applications);
     $data = array();
     $data['application'] = $application;
     $data['user'] = $application->user;
     $data['fund'] = $fund;
     Mail::queue('emails.autonotify', $data, function ($message) use($data) {
         $message->to($data['user']->email, $data['user']->name)->subject('You have uncompleted applications at nurse.tu.ac.th');
     });
     echo "success";
 }
Пример #7
0
 public function revenue(Request $request)
 {
     $data = array();
     $data['page'] = 'revenue';
     //total turnoveUserr
     $totalTurnoverINR = Order::where('payment_status', 2)->where('currency', 'INR')->sum('amount');
     $totalTurnoverUSD = Order::where('payment_status', 2)->where('currency', 'USD')->sum('amount');
     if ($totalTurnoverUSD > 0) {
         $totalTurnoverINR = $totalTurnoverINR + convert_currency('USD', 'INR', $totalTurnoverUSD);
     }
     $data['totalTurnover'] = number_format($totalTurnoverINR, 2, '.', ',');
     $totalFeeINR = Order::where('payment_status', 2)->where('currency', 'INR')->sum('txnfee');
     $totalFeeUSD = Order::where('payment_status', 2)->where('currency', 'USD')->sum('txnfee');
     if ($totalFeeUSD > 0) {
         $totalFeeINR = $totalFeeINR + convert_currency('USD', 'INR', $totalFeeUSD);
     }
     $data['totalTxnFee'] = number_format($totalFeeINR, 2, '.', ',');
     //earnings
     $totalCredit = Fund::select(array(DB::raw('sum(amount) as amount'), 'currency'))->where('txn_type', 1)->groupBy('currency')->lists('amount', 'currency');
     if (isset($totalCredit['USD']) && $totalCredit['USD'] > 0) {
         $totalCredit['INR'] = $totalCredit['INR'] + convert_currency('USD', 'INR', $totalCredit['USD']);
     }
     $totalCredit = $totalCredit['INR'];
     //refunds
     $totalDebit = Fund::select(array(DB::raw('sum(amount) as amount'), 'currency'))->where('txn_type', 0)->groupBy('currency')->lists('amount', 'currency');
     if (isset($totalDebit['USD']) && $totalDebit['USD'] > 0) {
         $totalDebit['INR'] = $totalDebit['INR'] + convert_currency('USD', 'INR', $totalDebit['USD']);
     }
     $totalDebit = $totalDebit['INR'];
     //total income
     $data['totalRevenue'] = number_format($totalCredit - $totalDebit, 2, '.', ',');
     $data['totalCredit'] = number_format($totalCredit, 2, '.', ',');
     $data['totalDebit'] = number_format($totalDebit, 2, '.', ',');
     //total income from jobs / services / contest
     $totalCreditINR = Fund::select(array(DB::raw('sum(amount) as amount'), 'source_type'))->where('txn_type', 1)->where('currency', 'INR')->groupBy('source_type')->lists('amount', 'source_type');
     $totalCreditUSD = Fund::select(array(DB::raw('sum(amount) as amount'), 'source_type'))->where('txn_type', 1)->where('currency', 'USD')->groupBy('source_type')->lists('amount', 'source_type');
     foreach ($totalCreditINR as $key => $credits) {
         $tmpInr = isset($totalCreditUSD[$key]) ? convert_currency('USD', 'INR', $totalCreditUSD[$key]) : 0.0;
         $totalCreditINR[$key] = $totalCreditINR[$key] + $tmpInr;
     }
     $startDate = date('Y-m-d', strtotime('-12 month'));
     $endDate = date('Y-m-d');
     $fundStatsUSD = Fund::select(DB::raw('sum(amount) as amount'), DB::raw('date(created_at) as date'))->where('txn_type', 1)->where('currency', 'USD')->where('created_at', '>=', $startDate)->where('created_at', '<=', $endDate)->groupBy('source_type')->groupBy('updated_at')->lists('amount', 'date');
     $fundStatsINR = Fund::select(DB::raw('sum(amount) as amount'), DB::raw('date(created_at) as date'))->where('txn_type', 1)->where('currency', 'INR')->where('created_at', '>=', $startDate)->where('created_at', '<=', $endDate)->groupBy('source_type')->groupBy('updated_at')->lists('amount', 'date');
     $debitStatsUSD = Fund::select(DB::raw('sum(amount) as amount'), DB::raw('date(created_at) as date'))->where('txn_type', 0)->where('currency', 'USD')->where('created_at', '>=', $startDate)->where('created_at', '<=', $endDate)->groupBy('source_type')->groupBy('updated_at')->lists('amount', 'date');
     $debitStatsINR = Fund::select(DB::raw('sum(amount) as amount'), DB::raw('date(created_at) as date'))->where('txn_type', 0)->where('currency', 'INR')->where('created_at', '>=', $startDate)->where('created_at', '<=', $endDate)->groupBy('source_type')->groupBy('updated_at')->lists('amount', 'date');
     $statsDataUSD = array();
     foreach ($fundStatsUSD as $date => $amount) {
         $statsDataUSD[strtotime($date)] = convert_currency('USD', 'INR', $amount);
     }
     $statsData = array();
     $maxValue = 50;
     foreach ($fundStatsINR as $date => $amount) {
         $date = strtotime($date);
         $tmp = isset($statsDataUSD[$date]) ? floatval($amount) + $statsDataUSD[$date] : floatval($amount);
         $statsData[$date] = $tmp;
         $maxValue = $tmp > $maxValue ? $tmp : $maxValue;
     }
     $statsDebitDataUSD = array();
     foreach ($debitStatsUSD as $date => $amount) {
         $statsDebitDataUSD[strtotime($date)] = convert_currency('USD', 'INR', $amount);
     }
     $statsDebitData = array();
     foreach ($debitStatsINR as $date => $amount) {
         $date = strtotime($date);
         $tmp = isset($statsDebitDataUSD[$date]) ? floatval($amount) + $statsDebitDataUSD[$date] : floatval($amount);
         $statsDebitData[$date] = $tmp;
     }
     $xtmp = array();
     for ($i = 365; $i >= 0; $i--) {
         $date = strtotime($endDate . '-' . $i . ' day');
         if (isset($statsData[$date])) {
             $xtmp[] = array('x' => $date, 'y' => $statsData[$date]);
         } else {
             $xtmp[] = array('x' => $date, 'y' => 0);
         }
         if (isset($statsDebitData[$date])) {
             $debitTmp[] = array('x' => $date, 'y' => $statsDebitData[$date]);
         } else {
             $debitTmp[] = array('x' => $date, 'y' => 0);
         }
     }
     $tmp = array();
     $tmp[] = array('key' => 'Earnings', 'values' => $xtmp, 'color' => '#2ca02c');
     $tmp[] = array('key' => 'Redunds & Chargebacks', 'values' => $debitTmp, 'color' => '#ff7f0e');
     $data['totalCreditJob'] = isset($totalCreditINR['1']) ? number_format($totalCreditINR['1'], 2, '.', ',') : 0.0;
     $data['totalCreditExtInv'] = isset($totalCreditINR['2']) ? number_format($totalCreditINR['2'], 2, '.', ',') : 0.0;
     $data['totalCreditMembership'] = isset($totalCreditINR['3']) ? number_format($totalCreditINR['3'], 2, '.', ',') : 0.0;
     $data['totalCreditFeatured'] = isset($totalCreditINR['4']) ? number_format($totalCreditINR['4'], 2, '.', ',') : 0.0;
     $data['totalCreditProposalBuy'] = isset($totalCreditINR['5']) ? number_format($totalCreditINR['5'], 2, '.', ',') : 0.0;
     $data['totalCreditTxnAdmin'] = isset($totalCreditINR['6']) ? number_format($totalCreditINR['6'], 2, '.', ',') : 0.0;
     $data['totalCreditPartialPay'] = isset($totalCreditINR['7']) ? number_format($totalCreditINR['7'], 2, '.', ',') : 0.0;
     $data['revenueData'] = $tmp;
     $data['maxValue'] = $maxValue;
     return view('backend.revenue')->with($data);
 }
Пример #8
0
 /**
  * Used to display the view of an individual center and also pass along
  * the needed variables and methods.
  *
  * @param $center_id
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function getCenterBalance($center_id)
 {
     $data = ['center_data' => Fund::getSeparateCenterAccounts($center_id), 'centers' => Fund::all()];
     return view('dashboard.center.center-view', $data);
 }
Пример #9
0
 /**
  * Gets the monthly balance of each account. If there is only a date passed,
  * it gets the sum of all accounts for that month. If only a center id
  * is passed, then it gets a whole year for that center. If both a
  * date and center id are passed, it gets that center's average
  * balance for that month. If no parameter is passed, it gets
  * the average monthly balance for the entire organization.
  *
  * @param bool $date = false
  * @param bool $center_id = false
  * @return array|string
  */
 public static function getMonthlyBalance($date = false, $center_id = false)
 {
     if ($date && $center_id) {
         $output = [];
         $balance = Balance::select('availableBalance')->where('center_id', '=', $center_id)->where('date', '<=', $date)->orderBy('date', 'dec')->first();
         $center_name = Center::find($center_id)->codeName;
         $output['center_id'] = $center_id;
         $output['center_name'] = $center_name;
         $output['balance'] = $balance;
         return $output;
     } elseif ($date && !$center_id) {
         $output = Balance::where('date', '=', $date)->sum('availableBalance');
         while ($output == 0) {
             $date = Carbon::parse($date)->subDay()->toDateString();
             $output = Balance::where('date', '=', $date)->sum('availableBalance');
         }
         return $output;
     } elseif ($center_id && !$date) {
         $date = Carbon::now();
         $centers = Fund::getSeparateCenterAccounts($center_id);
         $date_array = self::getArrayOfMonths($date->toDateString(), 12);
         $accounts_array = [];
         $counter = 0;
         $output = [];
         foreach ($centers as $center) {
             foreach ($center['accounts'] as $account) {
                 array_push($accounts_array, $account['account_name']);
                 for ($i = 0; $i < 12; $i++) {
                     $balance = Balance::select('availableBalance')->where('center_id', '=', $account['account_id'])->where('date', '=', $date_array[$i])->get();
                     if ($i < 12) {
                         $output[$counter]['this_year'][$i] = [Carbon::parse($date_array[$i])->format('M Y'), (int) $balance[0]->availableBalance];
                     } else {
                         if (empty($balance[0])) {
                             $output[$counter]['last_year'][$i - 12] = [Carbon::parse($date_array[$i])->format('M Y'), 0];
                         } else {
                             $output[$counter]['last_year'][$i - 12] = [Carbon::parse($date_array[$i])->format('M Y'), (int) $balance[0]->availableBalance];
                         }
                     }
                 }
                 $counter++;
             }
         }
         return json_encode(['output' => array_reverse($output), 'accounts' => array_reverse($accounts_array)]);
     } else {
         $date = Carbon::now();
         $current_months_array = [];
         $last_years_months_array = [];
         $current_months_balance_array = [];
         $last_years_balance_array = [];
         $date_array = self::getArrayOfMonths($date->toDateString(), 24);
         for ($i = 0; $i < count($date_array); $i++) {
             $balance = Balance::where('date', '=', $date_array[$i])->sum('availableBalance');
             if ($i < 12) {
                 array_push($current_months_array, Carbon::parse($date_array[$i])->format('M Y'));
                 array_push($current_months_balance_array, (int) $balance);
             } else {
                 array_push($last_years_months_array, Carbon::parse($date_array[$i])->format('M Y'));
                 array_push($last_years_balance_array, (int) $balance);
             }
         }
         return json_encode(['current_years_months' => array_reverse($current_months_array), 'current_years_balance' => array_reverse($current_months_balance_array), 'last_years_balance' => array_reverse($last_years_balance_array), 'last_years_months' => array_reverse($last_years_months_array)]);
     }
 }
 public function dashboard()
 {
     $researchs = Research::count();
     $funds = Fund::count();
     $translations = Translation::count();
     $users = User::count();
     return view('researchcenter.dashboard', ['researchs' => $researchs, 'funds' => $funds, 'translations' => $translations, 'users' => $users]);
 }
Пример #11
0
 public function fundDelete($id)
 {
     $fund = Fund::find($id);
     $fund->delete();
     return redirect()->route('fund_manage');
 }