/** * Store a newly created resource in storage. * * @return Response */ public function store() { $uId = \Input::get('user_id'); $date = \Input::get('date'); $check = \Payment::where('emp_id', '=', $uId)->where('pay_date', '=', $date)->first(); if ($check) { echo '{"error":"already exits"}'; return; } else { $earn = \Input::get('earned'); $deduction = \Input::get('deducted'); $net = \Input::get('net'); $description = \Input::except('earned', 'deducted', 'net', 'date', 'date_of_salary', '_token', 'user_id'); $description = json_encode($description); $insert = \Payment::insertGetId(array('emp_id' => $uId, 'earning_amount' => $earn, 'deducting_amount' => $deduction, 'total_amount' => $net, 'pay_date' => $date, 'description' => $description)); if ($insert) { $ids = array('uId' => $uId, 'date' => $date, 'eId' => $insert); $msg = array('success' => json_encode($ids)); echo json_encode($msg); return; } else { echo '{"error":"already exits"}'; return; } } }
public function report() { //add security to avoid stealing of information $user = Auth::user(); $club = $user->Clubs()->FirstOrFail(); $type = Input::get('expType'); $from = date('Ymd', strtotime(Input::get('expFrom'))); $to = date('Ymd', strtotime(Input::get('expTo'))); $payments = Payment::where('club_id', '=', $club->id)->with('player')->whereBetween('created_at', array($from, $to))->get(); $param = array('transaction_type' => 'cc', 'action_type' => 'refund,sale', 'condition' => 'pendingsettlement,complete,failed', 'club' => $club->id, 'start_date' => $from . '000000', 'end_date' => $to . '235959'); $payment = new Payment(); $transactions = $payment->ask($param); //return $transactions; //return json_decode(json_encode($transactions->transaction),true); // return View::make('export.lacrosse.accounting.all') // ->with('payments', $transactions->transaction); //return json_decode(json_encode($transactions->transaction),true); Excel::create('transactions', function ($excel) use($transactions) { $excel->sheet('Sheetname', function ($sheet) use($transactions) { $sheet->setOrientation('landscape'); // first row styling and writing content $sheet->loadView('export.lacrosse.accounting.all')->with('payments', $transactions->transaction); }); })->download('xlsx'); }
/** * Use this method to check if the agent can proceed with credit * * returns true */ public static function canProceedWithCredit($currentAmount) { $payments = Payment::where('user_id', Auth::id())->sum('amount'); $totalCredit = self::totalCreditFromAllBookings(); $creditLimit = self::getCreditLimit(Auth::id()); $creditLeft = $totalCredit + $currentAmount - $payments; return $creditLimit >= $creditLeft; }
/** * Display a listing of the resource. * GET /account * * @return Response */ public function index() { $user = Auth::user(); $title = 'League Together - Club'; $payment = Payment::where('user_id', $user->id)->with('items')->get(); $coachCount = count($user->teams()->get()); return View::make('app.account.index')->with('page_title', $title)->with('payment', $payment)->with('coachCount', $coachCount)->withUser($user); }
public function get_info($id) { $trans = Payment::where('transaction_id', '=', $id)->first(); if (empty($trans)) { return View::make('msg.error')->with('error', 'This transaction does not exist'); } $settings = IniHandle::readini(); return View::make('page.admin.transaction.info')->with('trans', $trans)->with('currency', $settings['ppcurrency'])->with('transactions', Payment::where('user_id', '=', $trans->user_id)->order_by('date', 'DESC')->take(15)->get()); }
/** * Show the form for creating a new resource. * GET /payments/create * * @return Response */ public function create($id) { $invoices = Invoice::with('invoicedetail')->find($id); $paymenttypes = Paymenttype::all(); $total = $invoices->invoicedetail->rent + $invoices->invoicedetail->water + $invoices->invoicedetail->electricity + $invoices->invoicedetail->security; $houseid = $invoices->houseID; $balance = Payment::where('houseID', $houseid)->sum('balance'); return View::make('backend.code.payment.create', compact('invoices', 'invoicedetail', 'total', 'balance')); }
public function index() { $user = Auth::user(); $club = $user->Clubs()->FirstOrFail(); $payment = Payment::where('club_id', '=', $club->id)->get(); $sales = new Payment(); $title = 'League Together - Club'; return View::make('app.club.index')->with('page_title', $title)->with('club', $club)->with('payments', $payment)->with('sales', $sales)->withUser($user); }
public function post_process() { Log::write('PayPal', 'Trying to process IPN'); Bundle::start('paypal-ipn'); $listener = new IpnListener(); // $listener->use_sandbox = true; try { $listener->requirePostMethod(); $verified = $listener->processIpn(); } catch (Exception $e) { Log::info($e->getMessage()); } if ($verified) { Log::write('PayPal', 'IPN payment looks verified'); $data = Input::get(); $settings = IniHandle::readini(); if (!in_array($data['payment_status'], array('Completed', 'COMPLETED', 'completed'))) { Log::write('PayPal', 'payment not completed'); return View::make('msg.error')->with('error', 'PayPal: payment not completed'); } if (strtolower($data['receiver_email']) != strtolower($settings['ppemail'])) { Log::write('PayPal', 'receive email not same as set in settings. Settings: ' . $settings['ppemail'] . ' ||| PayPal email: ' . $data['receiver_email']); return View::make('msg.error')->with('error', 'PayPal: receive email not same as set in settings'); } if (Payment::where('transaction_id', '=', $data['txn_id'])->count() != 0) { Log::write('PayPal', 'transaction ID already exists'); return View::make('msg.error')->with('error', 'PayPal: transaction ID already exists'); } if (strtolower($data['mc_currency']) != strtolower($settings['ppcurrency'])) { Log::write('PayPal', 'Currencies do not match'); return View::make('msg.error')->with('error', 'PayPal: currencies do not match'); } Log::write('PayPal', 'Got past all PLAN controller checks now going into CUSTOM'); if (strtolower($data['custom']) == 'plan') { $result = Payment::verifyPlan($data); if (!$result) { return $result; } } elseif (strtolower($data['custom']) == 'blacklist_skype' || strtolower($data['custom']) == 'blacklist_ip') { $result = Payment::verifyBlacklist($data); if (!$result) { return $result; } } else { Log::write('PayPal', 'Custom not found, can\'t verify anything'); return View::make('msg.error')->with('error', 'Fraudulent payment?'); } Log::write('PayPal', 'Now trying to add Payment info to DB'); $payment = Payment::create(array('user_id' => $data['option_selection1'], 'token' => $data['ipn_track_id'], 'date' => date('Y-m-d H:i:s', time()), 'ack' => $data['payment_status'], 'transaction_id' => $data['txn_id'], 'amount' => $data['mc_gross'], 'paypal_fee' => $data['mc_fee'], 'status' => $data['payment_status'], 'description' => $data['custom'])); Log::write('PayPal', 'Successful payment, DB id: ' . $payment->id); } else { Log::write('PayPal', 'IPN listener returns false on check'); } return 'handled'; }
public static function VeryPayment() { if ($user = Sentry::getUser()) { $dt = Carbon::now(); $payment = Payment::where('user_id', $user->id)->first(); $plan = Plan::find($payment->plan_id); $create = Carbon::parse($payment->created_at); if ($create->addDays($plan->time) > $dt) { return true; } else { return false; } } }
/** * Execute the console command. * * @return mixed */ public function fire() { $from = Carbon::now()->subDay()->hour(0)->minute(0)->second(0); $to = Carbon::now()->subDay()->hour(23)->minute(59)->second(59); $payments = Payment::whereBetween('created_at', array($from, $to))->sum('total'); $payments2 = Payment::whereBetween('created_at', array($from, $to))->sum('service_fee'); $payments3 = Payment::whereBetween('created_at', array($from, $to))->sum('subtotal'); $payments4 = Payment::where('created_at', '>=', Carbon::now()->startOfMonth())->sum('total'); //return Log::info($yesterday); //return Log::info($payments); $data = array('payments' => $payments, 'fees' => $payments2, 'subtotal' => $payments3, 'month' => $payments4); $mail = Mail::send('emails.notification.report.daily', $data, function ($message) { $message->to('*****@*****.**', 'Jay Clayton')->cc('*****@*****.**', 'Brooks Carter')->bcc('*****@*****.**', 'Jay Clayton')->subject("Daily Volume Summary"); }); }
public function getPaymentsList() { $data = Input::all(); // dd($data); if (Input::get('search')) { $validator = Validator::make($data, array('from_date' => 'required|date', 'to_date' => 'required|date')); if ($validator->fails()) { return Redirect::back()->with($validator->errors()); } $from = Input::get('from_date'); $to = Input::get('to_date'); $payments = Payment::where('payment_date_time', '>=', $from)->where('payment_date_time', '<=', $to)->get(); // dd($payments); } else { $payments = Payment::all(); } return View::make('payments.index', compact('payments', 'from', 'to')); }
public function postGenerateReport() { //verify the user input and create account $validator = Validator::make(Input::all(), array('Start_Date' => 'required', 'End_Date' => 'required')); if ($validator->fails()) { return Redirect::route('payment-get')->withErrors($validator)->withInput(); } else { $startdate = date("Y-m-d", strtotime(Input::get('Start_Date'))); $enddate = date("Y-m-d", strtotime(Input::get('End_Date'))); if ($startdate <= $enddate) { $payments = Payment::where('withdrawal_date', '>=', $startdate)->where('withdrawal_date', '<=', $enddate)->get(); View::share('startdate', $startdate); View::share('enddate', $enddate); View::share('payments', $payments); return View::make('members.paymentreportfeedback'); } else { return Redirect::route('reports-get')->withInput()->with('global', 'Failed, Please Enter The Correct Date Formats'); } } }
public function indexthn() { $date = \Carbon\Carbon::now(); $menu = Menu::where('tipe', Sentry::getUser()->last_name)->get(); $jenjang = Sentry::getUser()->last_name; $thn = Input::get('tahun'); $spay = Payment::where('user_id', Sentry::getUser()->id)->where(DB::raw('year'), '=', date('Y'))->where('verifikasi', '1')->first(); if ($jenjang === 'SMA') { $runpas = Contest::where('nocontest', 'Lari 50m pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $runpis = Contest::where('nocontest', 'Lari 50m pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $ljpas = Contest::where('nocontest', 'Lompat Jauh pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $ljpis = Contest::where('nocontest', 'Lompat Jauh pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $tppas = Contest::where('nocontest', 'Tolak Peluru pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $tppis = Contest::where('nocontest', 'Tolak Peluru pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $ltpas = Contest::where('nocontest', 'Lompat Tinggi pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $ltpis = Contest::where('nocontest', 'Lompat Tinggi pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); return View::make('contests.index', compact('contests'))->withTitle('Lomba')->with('menu', $menu)->with('runpas', $runpas)->with('runpis', $runpis)->with('ljpas', $ljpas)->with('ljpis', $ljpis)->with('tppas', $tppas)->with('tppis', $tppis)->with('ltpas', $ltpas)->with('ltpis', $ltpis)->with('thn', $thn)->with('spay', $spay); } elseif ($jenjang === 'SMP') { $runpas = Contest::where('nocontest', 'Lari 60m pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $runpis = Contest::where('nocontest', 'Lari 60m pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $ljpas = Contest::where('nocontest', 'Lompat Jauh pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $ljpis = Contest::where('nocontest', 'Lompat Jauh pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $tppas = Contest::where('nocontest', 'Tolak Peluru pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $tppis = Contest::where('nocontest', 'Tolak Peluru pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $ltpas = Contest::where('nocontest', 'Lompat Tinggi pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $ltpis = Contest::where('nocontest', 'Lompat Tinggi pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); return View::make('contests.index', compact('contests'))->withTitle('Lomba')->with('menu', $menu)->with('runpas', $runpas)->with('runpis', $runpis)->with('ljpas', $ljpas)->with('ljpis', $ljpis)->with('tppas', $tppas)->with('tppis', $tppis)->with('ltpas', $ltpas)->with('ltpis', $ltpis)->with('thn', $thn)->with('spay', $spay); } elseif ($jenjang == 'SD') { $runpas = Contest::where('nocontest', 'Lari 50m pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $runpis = Contest::where('nocontest', 'Lari 50m pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $ljpas = Contest::where('nocontest', 'Lompat Jauh pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $ljpis = Contest::where('nocontest', 'Lompat Jauh pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $lbpas = Contest::where('nocontest', 'Lempar Bola pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $lbpis = Contest::where('nocontest', 'Lempar Bola pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $lespa = Contest::where('nocontest', 'Lari Estafet pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); $lespi = Contest::where('nocontest', 'Lari Estafet pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', $thn)->get(); return View::make('contests.index', compact('contests'))->withTitle('Lomba')->with('menu', $menu)->with('runpas', $runpas)->with('runpis', $runpis)->with('ljpas', $ljpas)->with('ljpis', $ljpis)->with('lbpas', $lbpas)->with('lbpis', $lbpis)->with('lespa', $lespa)->with('lespi', $lespi)->with('thn', $thn)->with('spay', $spay); } }
public function validation($code) { $now = new DateTime(); $now->setTimezone(new DateTimeZone('America/Chicago')); $discount = Discount::where('name', '=', $code)->First(); if (!$discount) { //retrived data save from API - See API documentation $data = array('success' => false, 'error' => "Discount code not available."); return $data; } else { $used = $discount->limit - count(Payment::where('promo', '=', $code)->get()); if ($discount->start <= $now->format('Y-m-d') && $discount->end >= $now->format('Y-m-d') && $used > 0) { //allow only one discount at a single time Session::forget('discount'); Session::flash('discount', array('percent' => $discount->percent, 'id' => $discount->id)); //retrived data save from API - See API documentation $data = array('success' => true, 'now' => $now->format('Y-m-d'), 'start' => $discount->start, 'end' => $discount->end); return $data; } else { $data = array('success' => false, 'error' => "Discount code not active or past validation day"); return $data; } } }
public function add_request() { Log::info('add request from admin panel.'); $owner_id = Request::segment(3); $owner = Owner::find($owner_id); $services = ProviderType::where('is_visible', '=', 1)->get(); $total_services = ProviderType::where('is_visible', '=', 1)->count(); // Payment options allowed $payment_options = array(); $payments = Payment::where('owner_id', $owner_id)->count(); if ($payments) { $payment_options['stored_cards'] = 1; } else { $payment_options['stored_cards'] = 0; } $codsett = Settings::where('key', 'cod')->first(); if ($codsett->value == 1) { $payment_options['cod'] = 1; } else { $payment_options['cod'] = 0; } $paypalsett = Settings::where('key', 'paypal')->first(); if ($paypalsett->value == 1) { $payment_options['paypal'] = 1; } else { $payment_options['paypal'] = 0; } Log::info('payment_options = ' . print_r($payment_options, true)); // Promo code allowed $promosett = Settings::where('key', 'promo_code')->first(); if ($promosett->value == 1) { $promo_allow = 1; } else { $promo_allow = 0; } $settdestination = Settings::where('key', 'get_destination')->first(); $settdestination = $settdestination->value; $title = ucwords("Add" . trans('customize.Request')); /* 'Add Request' */ return View::make('add_request')->with('owner', $owner)->with('services', $services)->with('total_services', $total_services)->with('payment_option', $payment_options)->with('settdestination', $settdestination)->with('title', $title)->with('page', 'walks'); }
public function postSave() { $in = Input::get(); //print_r($in); /* current_trx:3IseB cc_amount: cc_number: cc_expiry: dc_amount: dc_number: payable_amount:632500 cash_amount: cash_change: */ $trx = Payment::where('sessionId', $in['current_trx'])->first(); //print_r($trx); if ($trx) { } else { $trx = new Payment(); $trx->sessionId = $in['current_trx']; $trx->createdDate = new MongoDate(); $trx->sessionStatus = 'open'; } $trx->by_name = $in['by_name']; $trx->by_gender = $in['by_gender']; $trx->by_address = $in['by_address']; $trx->cc_amount = $in['cc_amount']; $trx->cc_number = $in['cc_number']; $trx->cc_expiry = $in['cc_expiry']; $trx->dc_amount = $in['dc_amount']; $trx->dc_number = $in['dc_number']; $trx->payable_amount = $in['payable_amount']; $trx->cash_amount = $in['cash_amount']; $trx->cash_change = $in['cash_change']; $trx->lastUpdate = new MongoDate(); $trx->save(); return Response::json(array('result' => 'OK')); }
public function deleteUserPayment() { $user_id = $this->user_id; $id = Request::segment(4); Payment::where('user_id', $user_id)->where('id', $id)->delete(); $message = "Your card is successfully removed"; $type = "success"; return Redirect::to('/user')->with('message', $message)->with('type', $type); }
public function payment_options_allowed() { $token = Input::get('token'); $owner_id = Input::get('id'); $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id), array('token' => 'required', 'owner_id' => 'required|integer')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) { // check for token validity if (is_token_active($owner_data->token_expiry)) { // Payment options allowed $payment_options = array(); $payments = Payment::where('owner_id', $owner_id)->count(); if ($payments) { $payment_options['stored_cards'] = 1; } else { $payment_options['stored_cards'] = 0; } $codsett = Settings::where('key', 'cod')->first(); if ($codsett->value == 1) { $payment_options['cod'] = 1; } else { $payment_options['cod'] = 0; } $paypalsett = Settings::where('key', 'paypal')->first(); if ($paypalsett->value == 1) { $payment_options['paypal'] = 1; } else { $payment_options['paypal'] = 0; } Log::info('payment_options = ' . print_r($payment_options, true)); /* SEND REFERRAL & PROMO INFO */ $settings = Settings::where('key', 'referral_code_activation')->first(); $referral_code_activation = $settings->value; if ($referral_code_activation) { $referral_code_activation_txt = "referral on"; } else { $referral_code_activation_txt = "referral off"; } $settings = Settings::where('key', 'promotional_code_activation')->first(); $promotional_code_activation = $settings->value; if ($promotional_code_activation) { $promotional_code_activation_txt = "promo on"; } else { $promotional_code_activation_txt = "promo off"; } /* SEND REFERRAL & PROMO INFO */ // Promo code allowed /* $promosett = Settings::where('key', 'promo_code')->first(); */ if ($promotional_code_activation == 1) { $promo_allow = 1; } else { $promo_allow = 0; } $response_array = array('success' => true, 'payment_options' => $payment_options, 'promo_allow' => $promo_allow, 'is_referral_active' => $referral_code_activation, 'is_referral_active_txt' => $referral_code_activation_txt, 'is_promo_active' => $promotional_code_activation, 'is_promo_active_txt' => $promotional_code_activation_txt); } else { /* $var = Keywords::where('id', 2)->first(); $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID not Found', 'error_code' => 410); */ $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.User') . ' ID not Found', 'error_code' => 410); } } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } $response = Response::json($response_array, $response_code); return $response; }
public function showSubscription() { if (Auth::check()) { $user = Auth::user(); if ($user->level == 2) { $data['title'] = $this->layout->title = 'Subskrypcja'; $data['user'] = $user; $data['subscription'] = Subscription::where('user_id', '=', $user->id); $data['payments'] = Payment::where('user_id', '=', $user->id)->orderBy('created_at', 'desc'); $this->layout->content = View::make('user.subscription', $data); } else { return Redirect::to('/konto/pro/')->with('alert', array('type' => 'error', 'content' => 'Nie wolno! Tylko dla użytkowników Pro!')); } } }
public function payments() { return Payment::where('user_id', '=', $this->id)->get(); }
public function deleteUserPayment() { $owner_id = Session::get('user_id'); $id = Request::segment(4); Payment::where('owner_id', $owner_id)->where('id', $id)->delete(); $message = "Your card is successfully removed"; $type = "success"; return Redirect::to('/user/payments')->with('message', $message)->with('type', $type); }
public function doRefund($id) { $user = Auth::user(); $club = $user->clubs()->FirstOrFail(); $uuid = Uuid::generate(); $payment = Payment::where('club_id', '=', $club->id)->where('transaction', '=', $id)->FirstOrFail(); $user_parent = User::find($payment->user_id); $uuid = Uuid::generate(); if ($payment->event_type) { $participant = Participant::Find($payment->items->first()->participant_id); $event = Evento::find($participant->event->id); } else { $participant = Member::Find($payment->items->first()->member_id); $event = Team::find($participant->team->id); } $player = Player::Find($participant->player->id); //$amount = $payment->getOriginal('subtotal'); $amount = Input::get('amount'); if ($amount > $payment->getOriginal('subtotal')) { return Redirect::action('AccountingController@refund', $payment->transaction)->with('error', "You cannot refund more than " . $payment->getOriginal('subtotal')); } if ($amount <= 0 || $amount == '') { return Redirect::action('AccountingController@refund', $payment->transaction)->with('error', "Amount must be more than 0"); } if ($amount > 0) { $param = array('transactionid' => $payment->transaction, 'club' => $club->id, 'amount' => number_format($amount, 2, ".", "")); $transaction = $payment->refund($param); if ($transaction->response == 3 || $transaction->response == 2) { return Response::json($transaction); return Redirect::action('AccountingController@transaction', $payment->transaction)->with('error', $transaction->responsetext); } else { $payment1 = new Payment(); $payment1->id = $uuid; $payment1->customer = $user_parent->profile->customer_vault; $payment1->transaction = $transaction->transactionid; $payment1->subtotal = -$transaction->total; $payment1->total = -$transaction->total; $payment1->club_id = $club->id; $payment1->user_id = $user_parent->id; $payment1->player_id = $player->id; $payment1->type = $transaction->type; $sale = new Item(); $sale->description = $event->name . " ({$transaction->type})"; $sale->quantity = 1; $sale->price = -$transaction->total; $sale->payment_id = $uuid; if ($payment->event_type) { $payment1->event_type = $event->type_id; } else { $payment1->event_type = NULL; } $payment1->save(); $sale->save(); $data = array('club' => $club, 'transaction' => $transaction, 'user' => $user, 'contact' => $user_parent); //send notification for refund confirmation $mail = Mail::send('emails.receipt.refund', $data, function ($message) use($user, $club, $user_parent) { $message->to($user_parent->email)->subject("Refund Confirmation | " . $club->name); foreach ($club->users()->get() as $value) { $message->bcc($value->email, $club->name); } }); } //end of transaction result } //end of amount test return Redirect::action('AccountingController@transaction', $payment->transaction); }
public function createReport() { $to = Input::get('to'); $from = Input::get('from'); if ($from == null || $to == null) { $todayFrom = date('Y-m-d', strtotime('-30 day')) . ' 00:00:00'; $todayTo = date('Y-m-d') . ' 23:59:59'; } else { $todayFrom = $from . ' 00:00:00'; $todayTo = $to . ' 23:59:59'; } $results = []; try { $trips = DailyTrips::where('departure_date_time', '>', $todayFrom)->where('departure_date_time', '<', $todayTo)->orderBy('departure_date_time')->get(); $totalTripCount = count($trips); $totalTripCost = 0; $totalTripDistance = 0; $totalTripTime = 0; foreach ($trips as $trip) { $totalTripCost += $trip->trip_cost; $totalTripDistance += $trip->arrival_km - $trip->departure_km; $totalTripTime += strtotime($trip->arrival_date_time) - strtotime($trip->departure_date_time); } $totalTripTime = date('H:i:s', $totalTripTime); $totalFuel = FuelFillUp::where('date_and_time', '>', $todayFrom)->where('date_and_time', '<', $todayTo)->orderBy('date_and_time')->get(); $totalFuelCost = 0; $totalFuelAmount = 0; foreach ($totalFuel as $Fuel) { $totalFuelCost += $Fuel->cost; $totalFuelAmount += $Fuel->amount; } $totalPayments = 0; $totalOther = 0; $payments = Payment::where('created_at', '>', $todayFrom)->where('created_at', '<', $todayTo)->orderBy('created_at')->get(); foreach ($payments as $payment) { $totalPayments += $payment->amount; $totalOther += $payment->other; } $report = ['totalTripCounts' => $totalTripCount, 'totalTripCost' => $totalTripCost, 'totalTripkm' => $totalTripDistance, 'totalTripTime' => $totalTripTime, 'totalFuelCost' => round($totalFuelCost, 2), 'totalFuelAmount' => round($totalFuelAmount, 2), 'totalPayments' => $totalPayments, 'totalOther' => $totalOther]; array_push($results, $report); /* $queries = DB::getQueryLog(); $last_query = end($queries); */ } catch (Exception $ex) { \Log::error(__METHOD__ . ' | error :' . print_r($ex, 1)); } //\Log::info(__METHOD__.' | =====> $results : '.print_r($results,1 )); return json_encode($results); }
public function get_request() { $request_id = Input::get('request_id'); $token = Input::get('token'); $owner_id = Input::get('id'); $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'owner_id' => $owner_id), array('request_id' => 'required|integer', 'token' => 'required', 'owner_id' => 'required|integer')); /* $var = Keywords::where('id', 2)->first(); */ if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) { // check for token validity if (is_token_active($owner_data->token_expiry) || $is_admin) { /* SEND REFERRAL & PROMO INFO */ $settings = Settings::where('key', 'referral_code_activation')->first(); $referral_code_activation = $settings->value; if ($referral_code_activation) { $referral_code_activation_txt = "referral on"; } else { $referral_code_activation_txt = "referral off"; } $settings = Settings::where('key', 'promotional_code_activation')->first(); $promotional_code_activation = $settings->value; if ($promotional_code_activation) { $promotional_code_activation_txt = "promo on"; } else { $promotional_code_activation_txt = "promo off"; } /* SEND REFERRAL & PROMO INFO */ // Do necessary operations if ($request = Requests::find($request_id)) { if ($request->owner_id == $owner_data->id) { if ($request->current_walker != 0) { if ($request->confirmed_walker != 0) { $walker = Walker::where('id', $request->confirmed_walker)->first(); $walker_data = array(); $walker_data['unique_id'] = 1; $walker_data['id'] = $walker->id; $walker_data['first_name'] = $walker->first_name; $walker_data['last_name'] = $walker->last_name; $walker_data['phone'] = $walker->phone; $walker_data['bio'] = $walker->bio; $walker_data['picture'] = $walker->picture; $walker_data['latitude'] = $walker->latitude; $walker_data['longitude'] = $walker->longitude; if ($request->D_latitude != NULL) { $walker_data['d_latitude'] = $request->D_latitude; $walker_data['d_longitude'] = $request->D_longitude; } $walker_data['type'] = $walker->type; $walker_data['rating'] = $walker->rate; $walker_data['num_rating'] = $walker->rate_count; $walker_data['car_model'] = $walker->car_model; $walker_data['car_number'] = $walker->car_number; $walker_data['bearing'] = $walker->bearing; /* $walker_data['rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->avg('rating') ? : 0; $walker_data['num_rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->count(); */ $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; if ($unit == 0) { $unit_set = 'kms'; } elseif ($unit == 1) { $unit_set = 'miles'; } $requestserv = RequestServices::where('request_id', $request->id)->first(); $bill = array(); $request_typ = ProviderType::where('id', '=', $requestserv->type)->first(); /* $currency_selected = Keywords::find(5); $cur_symb = $currency_selected->keyword; */ $cur_symb = Config::get('app.generic_keywords.Currency'); if ($request->is_completed == 1) { $bill['unit'] = $unit_set; $bill['payment_mode'] = $request->payment_mode; $bill['distance'] = (string) $request->distance; $bill['time'] = $request->time; if ($requestserv->base_price != 0) { $bill['base_distance'] = $request_typ->base_distance; $bill['base_price'] = currency_converted($requestserv->base_price); $bill['distance_cost'] = currency_converted($requestserv->distance_cost); $bill['time_cost'] = currency_converted($requestserv->time_cost); } else { /* $setbase_price = Settings::where('key', 'base_price')->first(); $bill['base_price'] = currency_converted($setbase_price->value); $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first(); $bill['distance_cost'] = currency_converted($setdistance_price->value); $settime_price = Settings::where('key', 'price_per_unit_time')->first(); $bill['time_cost'] = currency_converted($settime_price->value); */ $bill['base_distance'] = $request_typ->base_distance; $bill['base_price'] = currency_converted($request_typ->base_price); $bill['distance_cost'] = currency_converted($request_typ->price_per_unit_distance); $bill['time_cost'] = currency_converted($request_typ->price_per_unit_time); } if ($request->payment_mode == 2) { $bill['walker']['email'] = $walker->email; $bill['walker']['amount'] = currency_converted($request->transfer_amount); $admins = Admin::first(); $bill['admin']['email'] = $admins->username; $bill['admin']['amount'] = currency_converted($request->total - $request->transfer_amount); } $bill['currency'] = $cur_symb; /* $bill['total'] = currency_converted($request->total); */ $bill['main_total'] = currency_converted($request->total); $bill['total'] = currency_converted($request->total - $request->ledger_payment - $request->promo_payment); $bill['referral_bonus'] = currency_converted($request->ledger_payment); $bill['promo_bonus'] = currency_converted($request->promo_payment); // $bill['payment_type'] = $owner_data->cash_or_card; $bill['payment_type'] = ""; $bill['is_paid'] = $request->is_paid; $discount = 0; if ($request->promo_code != "") { if ($request->promo_code != "") { $promo_code = PromoCodes::where('id', $request->promo_code)->first(); if ($promo_code) { $promo_value = $promo_code->value; $promo_type = $promo_code->type; if ($promo_type == 1) { // Percent Discount $discount = $request->total * $promo_value / 100; } elseif ($promo_type == 2) { // Absolute Discount $discount = $promo_value; } } } } $bill['promo_discount'] = currency_converted($discount); $bill['actual_total'] = currency_converted($request->total + $request->ledger_payment + $discount); } $cards = ""; /* $cards['none'] = ""; */ $dif_card = 0; $cardlist = Payment::where('owner_id', $owner_id)->where('is_default', 1)->first(); /* $cardlist = Payment::where('id', $owner_data->default_card_id)->first(); */ if (count($cardlist) >= 1) { $cards = array(); $default = $cardlist->is_default; if ($default == 1) { $dif_card = $cardlist->id; $cards['is_default_text'] = "default"; } else { $cards['is_default_text'] = "not_default"; } $cards['card_id'] = $cardlist->id; $cards['owner_id'] = $cardlist->owner_id; $cards['customer_id'] = $cardlist->customer_id; $cards['last_four'] = $cardlist->last_four; $cards['card_token'] = $cardlist->card_token; $cards['card_type'] = $cardlist->card_type; $cards['is_default'] = $default; } $code_data = Ledger::where('owner_id', '=', $owner_data->id)->first(); $owner = array(); $owner['owner_lat'] = $owner_data->latitude; $owner['owner_long'] = $owner_data->longitude; $owner['owner_dist_lat'] = $request->D_latitude; $owner['owner_dist_long'] = $request->D_longitude; $owner['payment_type'] = $request->payment_mode; $owner['default_card'] = $dif_card; $owner['dest_latitude'] = $request->D_latitude; $owner['dest_longitude'] = $request->D_longitude; $owner['referral_code'] = $code_data->referral_code; $owner['is_referee'] = $owner_data->is_referee; $owner['promo_count'] = $owner_data->promo_count; $charge = array(); $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; if ($unit == 0) { $unit_set = 'kms'; } elseif ($unit == 1) { $unit_set = 'miles'; } $charge['unit'] = $unit_set; if ($requestserv->base_price != 0) { $charge['base_distance'] = $request_typ->base_distance; $charge['base_price'] = currency_converted($requestserv->base_price); $charge['distance_price'] = currency_converted($requestserv->distance_cost); $charge['price_per_unit_time'] = currency_converted($requestserv->time_cost); } else { /* $setbase_price = Settings::where('key', 'base_price')->first(); $charge['base_price'] = currency_converted($setbase_price->value); $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first(); $charge['distance_price'] = currency_converted($setdistance_price->value); $settime_price = Settings::where('key', 'price_per_unit_time')->first(); $charge['price_per_unit_time'] = currency_converted($settime_price->value); */ $charge['base_distance'] = $request_typ->base_distance; $charge['base_price'] = currency_converted($request_typ->base_price); $charge['distance_price'] = currency_converted($request_typ->price_per_unit_distance); $charge['price_per_unit_time'] = currency_converted($request_typ->price_per_unit_time); } $charge['total'] = currency_converted($request->total); $charge['is_paid'] = $request->is_paid; $loc1 = WalkLocation::where('request_id', $request->id)->first(); $loc2 = WalkLocation::where('request_id', $request->id)->orderBy('id', 'desc')->first(); if ($loc1) { $time1 = strtotime($loc2->created_at); $time2 = strtotime($loc1->created_at); $difference = intval(($time1 - $time2) / 60); } else { $difference = 0; } $difference = $request->time; /* $rserv = RequestServices::where('request_id', $request_id)->get(); $typs = array(); $typi = array(); $typp = array(); $total_price = 0; foreach ($rserv as $typ) { $typ1 = ProviderType::where('id', $typ->type)->first(); $typ_price = ProviderServices::where('provider_id', $request->confirmed_walker)->where('type', $typ->type)->first(); if ($typ_price->base_price > 0) { $typp1 = 0.00; $typp1 = $typ_price->base_price; } elseif ($typ_price->price_per_unit_distance > 0) { $typp1 = 0.00; foreach ($rserv as $key) { $typp1 = $typp1 + $key->distance_cost; } } else { $typp1 = 0.00; } $typs['name'] = $typ1->name; $typs['price'] = currency_converted($typp1); $total_price = $total_price + $typp1; array_push($typi, $typs); } $bill['type'] = $typi;*/ $rserv = RequestServices::where('request_id', $request_id)->get(); $typs = array(); $typi = array(); $typp = array(); $total_price = 0; foreach ($rserv as $typ) { $typ1 = ProviderType::where('id', $typ->type)->first(); $typ_price = ProviderServices::where('provider_id', $request->confirmed_walker)->where('type', $typ->type)->first(); $typp1 = 0.0; if (isset($typ_price->base_price)) { if ($typ_price->base_price > 0) { $typp1 = 0.0; $typp1 = $typ_price->base_price; } elseif ($typ_price->price_per_unit_distance > 0) { $typp1 = 0.0; foreach ($rserv as $key) { $typp1 = $typp1 + $key->distance_cost; } } else { $typp1 = 0.0; } } $typs['name'] = $typ1->name; $typs['price'] = currency_converted($typp1); $total_price = $total_price + $typp1; array_push($typi, $typs); } $bill['type'] = $typi; $response_array = array('success' => true, 'unique_id' => 1, 'status' => $request->status, 'is_referral_active' => $referral_code_activation, 'is_referral_active_txt' => $referral_code_activation_txt, 'is_promo_active' => $promotional_code_activation, 'is_promo_active_txt' => $promotional_code_activation_txt, 'confirmed_walker' => $request->confirmed_walker, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_walker_rated' => $request->is_walker_rated, 'is_cancelled' => $request->is_cancelled, 'dest_latitude' => $request->D_latitude, 'dest_longitude' => $request->D_longitude, 'promo_id' => $request->promo_id, 'promo_code' => $request->promo_code, 'walker' => $walker_data, 'time' => $difference, 'bill' => $bill, 'owner' => $owner, 'card_details' => $cards, 'charge_details' => $charge); $user_timezone = $walker->timezone; $default_timezone = Config::get('app.timezone'); $accepted_time = get_user_time($default_timezone, $user_timezone, $request->request_start_time); $time = DB::table('walk_location')->where('request_id', $request_id)->min('created_at'); $end_time = get_user_time($default_timezone, $user_timezone, $time); $response_array['accepted_time'] = $accepted_time; if ($request->is_started == 1) { $response_array['start_time'] = DB::table('walk_location')->where('request_id', $request_id)->min('created_at'); $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; $response_array['distance'] = DB::table('walk_location')->where('request_id', $request_id)->max('distance'); $response_array['distance'] = (string) convert($response_array['distance'], $unit); if ($unit == 0) { $unit_set = 'kms'; } elseif ($unit == 1) { $unit_set = 'miles'; } $response_array['unit'] = $unit_set; } if ($request->is_completed == 1) { $response_array['end_time'] = $end_time; } } else { if ($request->current_walker != 0) { $walker = Walker::find($request->current_walker); $walker_data = array(); $walker_data['unique_id'] = 1; $walker_data['id'] = $walker->id; $walker_data['first_name'] = $walker->first_name; $walker_data['last_name'] = $walker->last_name; $walker_data['phone'] = $walker->phone; $walker_data['bio'] = $walker->bio; $walker_data['picture'] = $walker->picture; $walker_data['latitude'] = $walker->latitude; $walker_data['longitude'] = $walker->longitude; $walker_data['type'] = $walker->type; $walker_data['car_model'] = $walker->car_model; $walker_data['car_number'] = $walker->car_number; $walker_data['bearing'] = $walker->bearing; // $walker_data['payment_type'] = $request->cash_or_card; $walker_data['rating'] = $walker->rate; $walker_data['num_rating'] = $walker->rate_count; } $cards = ""; /* $cards['none'] = ""; */ $dif_card = 0; $cardlist = Payment::where('owner_id', $owner_id)->where('is_default', 1)->first(); /* $cardlist = Payment::where('id', $owner_data->default_card_id)->first(); */ if (count($cardlist) >= 1) { $cards = array(); $default = $cardlist->is_default; if ($default == 1) { $dif_card = $cardlist->id; $cards['is_default_text'] = "default"; } else { $cards['is_default_text'] = "not_default"; } $cards['card_id'] = $cardlist->id; $cards['owner_id'] = $cardlist->owner_id; $cards['customer_id'] = $cardlist->customer_id; $cards['last_four'] = $cardlist->last_four; $cards['card_token'] = $cardlist->card_token; $cards['card_type'] = $cardlist->card_type; $cards['is_default'] = $default; } $code_data = Ledger::where('owner_id', '=', $owner_data->id)->first(); $owner = array(); $owner['owner_lat'] = $owner_data->latitude; $owner['owner_long'] = $owner_data->longitude; $owner['owner_dist_lat'] = $request->D_latitude; $owner['owner_dist_long'] = $request->D_longitude; //$owner['payment_type'] = $owner_data->cash_or_card; $owner['payment_type'] = ""; $owner['default_card'] = $dif_card; $owner['dest_latitude'] = $request->D_latitude; $owner['dest_longitude'] = $request->D_longitude; $owner['referral_code'] = $code_data->referral_code; $owner['is_referee'] = $owner_data->is_referee; $owner['promo_count'] = $owner_data->promo_count; /* $driver = Keywords::where('id', 1)->first(); */ $requestserv = RequestServices::where('request_id', $request->id)->first(); $charge = array(); $request_typ = ProviderType::where('id', '=', $requestserv->type)->first(); $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; if ($unit == 0) { $unit_set = 'kms'; } elseif ($unit == 1) { $unit_set = 'miles'; } $charge['unit'] = $unit_set; if ($requestserv->base_price != 0) { $charge['base_distance'] = $request_typ->base_distance; $charge['base_price'] = currency_converted($requestserv->base_price); $charge['distance_price'] = currency_converted($requestserv->distance_cost); $charge['price_per_unit_time'] = currency_converted($requestserv->time_cost); } else { /* $setbase_price = Settings::where('key', 'base_price')->first(); $charge['base_price'] = currency_converted($setbase_price->value); $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first(); $charge['distance_price'] = currency_converted($setdistance_price->value); $settime_price = Settings::where('key', 'price_per_unit_time')->first(); $charge['price_per_unit_time'] = currency_converted($settime_price->value); */ $charge['base_distance'] = $request_typ->base_distance; $charge['base_price'] = currency_converted($request_typ->base_price); $charge['distance_price'] = currency_converted($request_typ->price_per_unit_distance); $charge['price_per_unit_time'] = currency_converted($request_typ->price_per_unit_time); } $charge['total'] = currency_converted($request->total); $charge['is_paid'] = $request->is_paid; $response_array = array('success' => true, 'unique_id' => 1, 'status' => $request->status, 'is_referral_active' => $referral_code_activation, 'is_referral_active_txt' => $referral_code_activation_txt, 'is_promo_active' => $promotional_code_activation, 'is_promo_active_txt' => $promotional_code_activation_txt, 'confirmed_walker' => 0, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_walker_rated' => $request->is_walker_rated, 'is_cancelled' => $request->is_cancelled, 'dest_latitude' => $request->D_latitude, 'dest_longitude' => $request->D_longitude, 'promo_id' => $request->promo_id, 'promo_code' => $request->promo_code, 'walker' => $walker_data, 'bill' => "", 'owner' => $owner, 'card_details' => $cards, 'charge_details' => $charge, 'confirmed_walker' => 0, 'error_code' => 484, 'error' => 'Searching for ' . Config::get('app.generic_keywords.Provider') . 's.'); } } else { /* $driver = Keywords::where('id', 1)->first(); */ if ($request->current_walker != 0) { $walker = Walker::find($request->current_walker); $walker_data = array(); $walker_data['unique_id'] = 1; $walker_data['id'] = $walker->id; $walker_data['first_name'] = $walker->first_name; $walker_data['last_name'] = $walker->last_name; $walker_data['phone'] = $walker->phone; $walker_data['bio'] = $walker->bio; $walker_data['picture'] = $walker->picture; $walker_data['latitude'] = $walker->latitude; $walker_data['longitude'] = $walker->longitude; $walker_data['type'] = $walker->type; $walker_data['car_model'] = $walker->car_model; $walker_data['car_number'] = $walker->car_number; $walker_data['bearing'] = $walker->bearing; $walker_data['payment_type'] = $request->cash_or_card; $walker_data['rating'] = $walker->rate; $walker_data['num_rating'] = $walker->rate_count; } $cards = ""; /* $cards['none'] = ""; */ $dif_card = 0; $cardlist = Payment::where('owner_id', $owner_id)->where('is_default', 1)->first(); /* $cardlist = Payment::where('id', $owner_data->default_card_id)->first(); */ if (count($cardlist) >= 1) { $cards = array(); $default = $cardlist->is_default; if ($default == 1) { $dif_card = $cardlist->id; $cards['is_default_text'] = "default"; } else { $cards['is_default_text'] = "not_default"; } $cards['card_id'] = $cardlist->id; $cards['owner_id'] = $cardlist->owner_id; $cards['customer_id'] = $cardlist->customer_id; $cards['last_four'] = $cardlist->last_four; $cards['card_token'] = $cardlist->card_token; $cards['card_type'] = $cardlist->card_type; $cards['is_default'] = $default; } $code_data = Ledger::where('owner_id', '=', $owner_data->id)->first(); $owner = array(); $owner['owner_lat'] = $owner_data->latitude; $owner['owner_long'] = $owner_data->longitude; $owner['owner_dist_lat'] = $request->D_latitude; $owner['owner_dist_long'] = $request->D_longitude; // $owner['payment_type'] = $owner_data->cash_or_card; $owner['payment_type'] = ""; $owner['default_card'] = $dif_card; $owner['dest_latitude'] = $request->D_latitude; $owner['dest_longitude'] = $request->D_longitude; $owner['referral_code'] = $code_data->referral_code; $owner['is_referee'] = $owner_data->is_referee; $owner['promo_count'] = $owner_data->promo_count; /* $driver = Keywords::where('id', 1)->first(); */ $requestserv = RequestServices::where('request_id', $request->id)->first(); $charge = array(); $request_typ = ProviderType::where('id', '=', $requestserv->type)->first(); $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; if ($unit == 0) { $unit_set = 'kms'; } elseif ($unit == 1) { $unit_set = 'miles'; } $charge['unit'] = $unit_set; if ($requestserv->base_price != 0) { $charge['base_distance'] = $request_typ->base_distance; $charge['base_price'] = currency_converted($requestserv->base_price); $charge['distance_price'] = currency_converted($requestserv->distance_cost); $charge['price_per_unit_time'] = currency_converted($requestserv->time_cost); } else { /* $setbase_price = Settings::where('key', 'base_price')->first(); $charge['base_price'] = currency_converted($setbase_price->value); $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first(); $charge['distance_price'] = currency_converted($setdistance_price->value); $settime_price = Settings::where('key', 'price_per_unit_time')->first(); $charge['price_per_unit_time'] = currency_converted($settime_price->value); */ $charge['base_distance'] = $request_typ->base_distance; $charge['base_price'] = currency_converted($request_typ->base_price); $charge['distance_price'] = currency_converted($request_typ->price_per_unit_distance); $charge['price_per_unit_time'] = currency_converted($request_typ->price_per_unit_time); } $charge['total'] = currency_converted($request->total); $charge['is_paid'] = $request->is_paid; $response_array = array('success' => true, 'unique_id' => 1, 'status' => $request->status, 'is_referral_active' => $referral_code_activation, 'is_referral_active_txt' => $referral_code_activation_txt, 'is_promo_active' => $promotional_code_activation, 'is_promo_active_txt' => $promotional_code_activation_txt, 'confirmed_walker' => 0, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_walker_rated' => $request->is_walker_rated, 'is_cancelled' => $request->is_cancelled, 'dest_latitude' => $request->D_latitude, 'dest_longitude' => $request->D_longitude, 'promo_id' => $request->promo_id, 'promo_code' => $request->promo_code, 'walker' => "", 'bill' => "", 'owner' => $owner, 'card_details' => $cards, 'charge_details' => $charge, 'current_walker' => 0, 'error_code' => 483, 'error' => 'No ' . Config::get('app.generic_keywords.Provider') . 's are available currently. Please try after sometime.'); } $response_code = 200; } else { /* $response_array = array('success' => false, 'error' => 'Request ID doesnot matches with ' . $var->keyword . ' ID', 'error_code' => 407); */ $response_array = array('success' => false, 'error' => 'Request ID doesnot matches with ' . Config::get('app.generic_keywords.User') . ' ID', 'error_code' => 407); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Request ID Not Found', 'error_code' => 408); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { /* $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID not Found', 'error_code' => 410); */ $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.User') . ' ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } $response = Response::json($response_array, $response_code); return $response; }
public function providerTripChangeState() { $date = date("Y-m-d H:i:s"); $time_limit = date("Y-m-d H:i:s", strtotime($date) - 3 * 60 * 60); $walker_id = Session::get('walker_id'); $state = $request_id = Request::segment(4); $current_request = Requests::where('confirmed_walker', $walker_id)->where('is_cancelled', 0)->where('is_dog_rated', 0)->where('created_at', '>', $time_limit)->orderBy('created_at', 'desc')->where(function ($query) { $query->where('status', 0)->orWhere(function ($query_inner) { $query_inner->where('status', 1)->where('is_dog_rated', 0); }); })->first(); if ($current_request && $state) { if ($state == 2) { $current_request->is_walker_started = 1; $owner = Owner::find($current_request->owner_id); $walker = Walker::find($walker_id); $location = get_location($owner->latitude, $owner->longitude); $latitude = $location['lat']; $longitude = $location['long']; $angle = get_angle($walker->latitude, $walker->longitude, $latitude, $longitude); $walker->old_latitude = $walker->latitude; $walker->old_longitude = $walker->longitude; $walker->latitude = $latitude; $walker->longitude = $longitude; $walker->bearing = $angle; $walker->save(); $walk_location = new WalkLocation(); $walk_location->request_id = $current_request->id; $walk_location->latitude = $latitude; $walk_location->longitude = $longitude; $walk_location->distance = 0; $walk_location->save(); } if ($state == 3) { $current_request->is_walker_arrived = 1; } if ($state == 4) { $current_request->is_started = 1; } if ($state == 6) { $rating = 0; if (Input::has('rating')) { $rating = Input::get('rating'); } $current_request->is_dog_rated = 1; $current_request->save(); $review_dog = new DogReview(); $review_dog->walker_id = $current_request->confirmed_walker; $review_dog->comment = Input::get('review'); $review_dog->rating = $rating; $review_dog->owner_id = $current_request->owner_id; $review_dog->request_id = $current_request->id; $review_dog->save(); if ($rating) { if ($owner = Owner::find($current_request->owner_id)) { $old_rate = $owner->rate; $old_rate_count = $owner->rate_count; $new_rate_counter = $owner->rate_count + 1; $new_rate = ($owner->rate * $owner->rate_count + $rating) / $new_rate_counter; $owner->rate_count = $new_rate_counter; $owner->rate = $new_rate; $owner->save(); } } $message = "You has successfully rated the owner."; $type = "success"; return Redirect::to('/provider/trips')->with('message', $message)->with('type', $type); } if ($state == 5) { $request_services = RequestServices::where('request_id', $current_request->id)->first(); $request_typ = ProviderType::where('id', '=', $request_services->req_typ)->first(); $address = urlencode(Input::get('address')); $end_address = json_decode(file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address={$address}"), TRUE); $end_location = $end_address['results'][0]['geometry']; $latitude = $end_location['location']['lat']; $longitude = $end_location['location']['lng']; $location = get_location($latitude, $longitude); $latitude = $location['lat']; $longitude = $location['long']; $request_id = $current_request->id; $walk_location_last = WalkLocation::where('request_id', $request_id)->orderBy('created_at', 'desc')->first(); if ($walk_location_last) { $distance_old = $walk_location_last->distance; $distance_new = distanceGeoPoints($walk_location_last->latitude, $walk_location_last->longitude, $latitude, $longitude); $distance = $distance_old + $distance_new; $settings = Settings::where('key', 'default_distance_unit')->first(); //$unit = $settings->value; $distance = $distance; } else { $distance = 0; } $walker = Walker::find($walker_id); $angle = get_angle($walker->latitude, $walker->longitude, $latitude, $longitude); $walker->old_latitude = $walker->latitude; $walker->old_longitude = $walker->longitude; $walker->latitude = $latitude; $walker->longitude = $longitude; $walker->bearing = $angle; $walker->save(); $walk_location = new WalkLocation(); $walk_location->request_id = $request_id; $walk_location->latitude = $latitude; $walk_location->longitude = $longitude; $walk_location->distance = $distance; $walk_location->save(); Walker::where('id', '=', $walker_id)->update(array('is_available' => 1)); // Calculate Rerquest Stats $time = 0; $time_query = "SELECT TIMESTAMPDIFF(SECOND,MIN(created_at),MAX(created_at)) as diff\n\t\t\t\tFROM walk_location where request_id = {$current_request->id}\n\t\t\t\tGROUP BY request_id limit 1 "; $time_data = DB::select(DB::raw($time_query)); foreach ($time_data as $time_diff) { $time = $time_diff->diff; } $time = $time / 60; /* TIME CALCULATION REDIRECTED */ $time = 0; /* TIME CALCULATION REDIRECTED END */ $walker_data = Walker::find($current_request->confirmed_walker); $provider_type = ProviderServices::where('type', $walker_data->type)->where('provider_id', $walker_id)->first(); if ($provider_type == NULL) { /* $settings = Settings::where('key', 'price_per_unit_distance')->first(); $price_per_unit_distance = $settings->value; $settings = Settings::where('key', 'price_per_unit_time')->first(); $price_per_unit_time = $settings->value; $settings = Settings::where('key', 'base_price')->first(); $base_price = $settings->value; */ $setbase_distance = $request_typ->base_distance; $base_price = $request_typ->base_price; $price_per_unit_distance = $request_typ->price_per_unit_distance; $price_per_unit_time = $request_typ->price_per_unit_time; } else { // $setbase_distance = $request_typ->base_distance; $setbase_distance = ""; $provider_type = ProviderServices::where('type', $walker_data->type)->where('provider_id', $walker_id)->first(); $base_price = $provider_type->base_price; $price_per_unit_distance = $provider_type->price_per_unit_distance; $price_per_unit_time = $provider_type->price_per_unit_time; } $settings = Settings::where('key', 'default_charging_method_for_users')->first(); $pricing_type = $settings->value; $settings = Settings::where('key', 'default_distance_unit')->first(); //$unit = $settings->value; $distance = convert($distance); if ($pricing_type == 1) { if ($distance <= $setbase_distance) { $distance_cost = 0; } else { $distance_cost = $price_per_unit_distance * ($distance - $setbase_distance); } $time_cost = $price_per_unit_time * $time; $total = $base_price + $distance_cost + $time_cost; } else { $distance_cost = 0; $time_cost = 0; $total = $base_price; } $current_request->is_completed = 1; $current_request->distance = $distance; $current_request->time = $time; $request_services->base_price = $base_price; $request_services->distance_cost = $distance_cost; $request_services->time_cost = $time_cost; $request_services->total = $total; $current_request->total = $total; $request_services->save(); // charge client // charge client $ledger = Ledger::where('owner_id', $current_request->owner_id)->first(); if ($ledger) { $balance = $ledger->amount_earned - $ledger->amount_spent; if ($balance > 0) { if ($total > $balance) { $ledger_temp = Ledger::find($ledger->id); $ledger_temp->amount_spent = $ledger_temp->amount_spent + $balance; $ledger_temp->save(); $total = $total - $balance; } else { $ledger_temp = Ledger::find($ledger->id); $ledger_temp->amount_spent = $ledger_temp->amount_spent + $total; $ledger_temp->save(); $total = 0; } } } $promo_discount = 0; if ($pcode = PromoCodes::where('id', $current_request->promo_code)->where('type', 1)->first()) { $discount = $pcode->value / 100; $promo_discount = $total * $discount; $total = $total - $promo_discount; if ($total < 0) { $total = 0; } } $current_request->total = $total; $current_request->save(); $cod_sett = Settings::where('key', 'cod')->first(); $allow_cod = $cod_sett->value; if ($current_request->payment_mode == 1 and $allow_cod == 1) { // Pay by Cash $current_request->is_paid = 1; Log::info('allow_cod'); } elseif ($current_request->payment_mode == 2) { // paypal Log::info('paypal payment'); } else { Log::info('normal payment. Stored cards'); // stored cards if ($total == 0) { $current_request->is_paid = 1; } else { $payment_data = Payment::where('owner_id', $current_request->owner_id)->where('is_default', 1)->first(); if (!$payment_data) { $payment_data = Payment::where('owner_id', $current_request->owner_id)->first(); } if ($payment_data) { $customer_id = $payment_data->customer_id; $setransfer = Settings::where('key', 'transfer')->first(); $transfer_allow = $setransfer->value; if (Config::get('app.default_payment') == 'stripe') { //dd($customer_id); Stripe::setApiKey(Config::get('app.stripe_secret_key')); try { $charge = Stripe_Charge::create(array("amount" => ceil($total * 100), "currency" => "usd", "customer" => $customer_id)); Log::info($charge); } catch (Stripe_InvalidRequestError $e) { // Invalid parameters were supplied to Stripe's API $ownr = Owner::find($current_request->owner_id); $ownr->debt = $total; $ownr->save(); $message = array('error' => $e->getMessage()); $type = "success"; Log::info($message); return Redirect::to('/provider/tripinprogress')->with('message', $message)->with('type', $type); } $current_request->is_paid = 1; $settng = Settings::where('key', 'service_fee')->first(); $settng_mode = Settings::where('key', 'payment_mode')->first(); if ($settng_mode->value == 2 and $transfer_allow == 1) { $transfer = Stripe_Transfer::create(array("amount" => ($total - $settng->value * $total / 100) * 100, "currency" => "usd", "recipient" => $walker_data->merchant_id)); $current_request->transfer_amount = $total - $settng->value * $total / 100; } } else { try { Braintree_Configuration::environment(Config::get('app.braintree_environment')); Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id')); Braintree_Configuration::publicKey(Config::get('app.braintree_public_key')); Braintree_Configuration::privateKey(Config::get('app.braintree_private_key')); if ($settng_mode->value == 2 and $transfer_allow == 1) { $sevisett = Settings::where('key', 'service_fee')->first(); $service_fee = $sevisett->value * $total / 100; $result = Braintree_Transaction::sale(array('amount' => $total - $service_fee, 'paymentMethodNonce' => $customer_id, 'merchantAccountId' => $walker_data->merchant_id, 'options' => array('submitForSettlement' => true, 'holdInEscrow' => true), 'serviceFeeAmount' => $service_fee)); } else { $result = Braintree_Transaction::sale(array('amount' => $total, 'paymentMethodNonce' => $customer_id)); } if ($result->success) { $request->is_paid = 1; } else { $request->is_paid = 0; } } catch (Exception $e) { $message = "Something went wrong in the payment. Please try again."; $type = "success"; return Redirect::to('/provider/tripinprogress')->with('message', $message)->with('type', $type); } } $current_request->card_payment = $total; $current_request->ledger_payment = $current_request->total - $total; } } } $current_request->save(); } $current_request->save(); } return Redirect::to('/provider/tripinprogress'); }
public function pre_payment() { if (Request::isMethod('post')) { $request_id = Input::get('request_id'); $token = Input::get('token'); $walker_id = Input::get('id'); $time = Input::get('time'); $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'walker_id' => $walker_id, 'time' => $time), array('request_id' => 'required|integer', 'token' => 'required', 'walker_id' => 'required|integer', 'time' => 'required')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($walker_data = $this->getWalkerData($walker_id, $token, $is_admin)) { // check for token validity if (is_token_active($walker_data->token_expiry) || $is_admin) { // Do necessary operations if ($request = Requests::find($request_id)) { if ($request->confirmed_walker == $walker_id) { $request_service = RequestServices::find($request_id); $request_typ = ProviderType::where('id', '=', $request_service->type)->first(); if (!$walker_data->type) { /* $settings = Settings::where('key', 'price_per_unit_distance')->first(); $price_per_unit_distance = $settings->value; $settings = Settings::where('key', 'price_per_unit_time')->first(); $price_per_unit_time = $settings->value; $settings = Settings::where('key', 'base_price')->first(); $base_price = $settings->value; */ $price_per_unit_distance = $request_typ->price_per_unit_distance; $price_per_unit_time = $request_typ->price_per_unit_time; $base_price = $request_typ->base_price; } else { $provider_type = ProviderServices::find($walker_data->type); $base_price = $provider_type->base_price; $price_per_unit_distance = $provider_type->price_per_unit_distance; $price_per_unit_time = $provider_type->price_per_unit_time; } $settings = Settings::where('key', 'default_charging_method_for_users')->first(); $pricing_type = $settings->value; $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; if ($pricing_type == 1) { $distance_cost = $price_per_unit_distance; $time_cost = $price_per_unit_time; $total = $base_price + $distance_cost + $time_cost; } else { $distance_cost = 0; $time_cost = 0; $total = $base_price; } Log::info('req'); $request_service = RequestServices::find($request_id); $request_service->base_price = $base_price; $request_service->distance_cost = $distance_cost; $request_service->time_cost = $time_cost; $request_service->total = $total; $request_service->save(); $request->distance = $distance_cost; $request->time = $time_cost; $request->total = $total; Log::info('in '); // charge client $ledger = Ledger::where('owner_id', $request->owner_id)->first(); if ($ledger) { $balance = $ledger->amount_earned - $ledger->amount_spent; if ($balance > 0) { if ($total > $balance) { $ledger_temp = Ledger::find($ledger->id); $ledger_temp->amount_spent = $ledger_temp->amount_spent + $balance; $ledger_temp->save(); $total = $total - $balance; } else { $ledger_temp = Ledger::find($ledger->id); $ledger_temp->amount_spent = $ledger_temp->amount_spent + $total; $ledger_temp->save(); $total = 0; } } } Log::info('out'); if ($total == 0) { $request->is_paid = 1; } else { $payment_data = Payment::where('owner_id', $request->owner_id)->where('is_default', 1)->first(); if (!$payment_data) { $payment_data = Payment::where('owner_id', $request->owner_id)->first(); } if ($payment_data) { $customer_id = $payment_data->customer_id; try { if (Config::get('app.default_payment') == 'stripe') { Stripe::setApiKey(Config::get('app.stripe_secret_key')); try { Stripe_Charge::create(array("amount" => floor($total) * 100, "currency" => "usd", "customer" => $customer_id)); } catch (Stripe_InvalidRequestError $e) { // Invalid parameters were supplied to Stripe's API $ownr = Owner::find($request->owner_id); $ownr->debt = $total; $ownr->save(); $response_array = array('error' => $e->getMessage()); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } $request->is_paid = 1; $setting = Settings::where('key', 'paypal')->first(); $settng1 = Settings::where('key', 'service_fee')->first(); if ($setting->value == 2 && $walker_data->merchant_id != NULL) { // dd($amount$request->transfer_amount); $transfer = Stripe_Transfer::create(array("amount" => ($total - $settng1->value) * 100, "currency" => "usd", "recipient" => $walker_data->merchant_id)); } } else { $amount = $total; Braintree_Configuration::environment(Config::get('app.braintree_environment')); Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id')); Braintree_Configuration::publicKey(Config::get('app.braintree_public_key')); Braintree_Configuration::privateKey(Config::get('app.braintree_private_key')); $card_id = $payment_data->card_token; $setting = Settings::where('key', 'paypal')->first(); $settng1 = Settings::where('key', 'service_fee')->first(); if ($setting->value == 2 && $walker_data->merchant_id != NULL) { // escrow $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id)); } else { $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id)); } Log::info('result = ' . print_r($result, true)); if ($result->success) { $request->is_paid = 1; } else { $request->is_paid = 0; } } } catch (Exception $e) { $response_array = array('success' => false, 'error' => $e, 'error_code' => 405); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } } } $request->card_payment = $total; $request->ledger_payment = $request->total - $total; $request->save(); Log::info('Request = ' . print_r($request, true)); if ($request->is_paid == 1) { $owner = Owner::find($request->owner_id); $settings = Settings::where('key', 'sms_request_unanswered')->first(); $pattern = $settings->value; $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern); $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%user_mobile%', $owner->phone, $pattern); sms_notification(1, 'admin', $pattern); } $walker = Walker::find($walker_id); $walker->is_available = 1; $walker->save(); // Send Notification $walker = Walker::find($request->confirmed_walker); $walker_data = array(); $walker_data['first_name'] = $walker->first_name; $walker_data['last_name'] = $walker->last_name; $walker_data['phone'] = $walker->phone; $walker_data['bio'] = $walker->bio; $walker_data['picture'] = $walker->picture; $walker_data['type'] = $walker->type; $walker_data['rating'] = $walker->rate; $walker_data['num_rating'] = $walker->rate_count; $walker_data['car_model'] = $walker->car_model; $walker_data['car_number'] = $walker->car_number; /* $walker_data['rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->avg('rating') ? : 0; $walker_data['num_rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->count(); */ $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; if ($unit == 0) { $unit_set = 'kms'; } elseif ($unit == 1) { $unit_set = 'miles'; } $bill = array(); if ($request->is_paid == 1) { $bill['distance'] = (string) convert($request->distance, $unit); $bill['unit'] = $unit_set; $bill['time'] = $request->time; $bill['base_price'] = currency_converted($base_price); $bill['distance_cost'] = currency_converted($distance_cost); $bill['time_cost'] = currency_converted($time_cost); $bill['total'] = currency_converted($request->total); $bill['is_paid'] = $request->is_paid; } $response_array = array('success' => true, 'request_id' => $request_id, 'status' => $request->status, 'confirmed_walker' => $request->confirmed_walker, 'walker' => $walker_data, 'bill' => $bill); $title = "Payment Has Made"; $message = $response_array; send_notifications($walker->id, "walker", $title, $message); $settings = Settings::where('key', 'email_notification')->first(); $condition = $settings->value; if ($condition == 1) { /* $settings = Settings::where('key', 'payment_made_client')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%amount%', $request->total, $pattern); $subject = "Payment Charged"; email_notification($walker->id, 'walker', $pattern, $subject); */ $settings = Settings::where('key', 'admin_email_address')->first(); $admin_email = $settings->value; $pattern = array('admin_eamil' => $admin_email, 'name' => ucwords($walker->first_name . " " . $walker->last_name), 'amount' => $total, 'req_id' => $request_id, 'web_url' => web_url()); $subject = "Payment Done With " . $request_id . ""; email_notification($walker->id, 'walker', $pattern, $subject, 'pre_payment', null); } // Send SMS $owner = Owner::find($request->owner_id); $settings = Settings::where('key', 'sms_when_provider_completes_job')->first(); $pattern = $settings->value; $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern); $pattern = str_replace('%driver%', $walker->first_name . " " . $walker->last_name, $pattern); $pattern = str_replace('%driver_mobile%', $walker->phone, $pattern); $pattern = str_replace('%amount%', $request->total, $pattern); sms_notification($request->owner_id, 'owner', $pattern); $email_data = array(); $email_data['name'] = $owner->first_name; $email_data['emailType'] = 'user'; $email_data['base_price'] = $bill['base_price']; $email_data['distance'] = $bill['distance']; $email_data['time'] = $bill['time']; $email_data['unit'] = $bill['unit']; $email_data['total'] = $bill['total']; if ($bill['payment_mode']) { $email_data['payment_mode'] = $bill['payment_mode']; } else { $email_data['payment_mode'] = '---'; } /* $subject = "Invoice Generated"; send_email($request->owner_id, 'owner', $email_data, $subject, 'invoice'); $subject = "Invoice Generated"; $email_data['emailType'] = 'walker'; send_email($request->confirmed_walker, 'walker', $email_data, $subject, 'invoice'); */ if ($request->is_paid == 1) { // send email /* $settings = Settings::where('key', 'email_payment_charged')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%url%', web_url() . "/admin/request/" . $request->id, $pattern); $subject = "Payment Charged"; email_notification(1, 'admin', $pattern, $subject); */ $settings = Settings::where('key', 'admin_email_address')->first(); $admin_email = $settings->value; $pattern = array('admin_eamil' => $admin_email, 'name' => 'Administrator', 'amount' => $total, 'req_id' => $request_id, 'web_url' => web_url()); $subject = "Payment Done With " . $request_id . ""; email_notification(1, 'admin', $pattern, $subject, 'pay_charged', null); } $response_array = array('success' => true, 'base_fare' => currency_converted($base_price), 'distance_cost' => currency_converted($distance_cost), 'time_cost' => currency_converted($time_cost), 'total' => currency_converted($total), 'is_paid' => $request->is_paid); $response_code = 200; } else { /* $var = Keywords::where('id', 1)->first(); $response_array = array('success' => false, 'error' => 'Service ID doesnot matches with ' . $var->keyword . ' ID', 'error_code' => 407); */ $response_array = array('success' => false, 'error' => 'Service ID doesnot matches with ' . Config::get('app.generic_keywords.Provider') . ' ID', 'error_code' => 407); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Service ID Not Found', 'error_code' => 408); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { /* $var = Keywords::where('id', 1)->first(); $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID not Found', 'error_code' => 410); */ $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.Provider') . ' ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } } $response = Response::json($response_array, $response_code); return $response; }
public function paymentGet() { if (isset($_GET)) { $amount = HsbcPayment::null2unknown($_GET["vpc_Amount"]); $locale = HsbcPayment::null2unknown($_GET["vpc_Locale"]); $batchNo = HsbcPayment::null2unknown($_GET["vpc_BatchNo"]); $command = HsbcPayment::null2unknown($_GET["vpc_Command"]); $message = HsbcPayment::null2unknown($_GET["vpc_Message"]); $version = HsbcPayment::null2unknown($_GET["vpc_Version"]); $cardType = HsbcPayment::null2unknown($_GET["vpc_Card"]); $orderInfo = HsbcPayment::null2unknown($_GET["vpc_OrderInfo"]); $receiptNo = HsbcPayment::null2unknown($_GET["vpc_ReceiptNo"]); $merchantID = HsbcPayment::null2unknown($_GET["vpc_Merchant"]); $authorizeID = HsbcPayment::null2unknown($_GET["vpc_AuthorizeId"]); $merchTxnRef = HsbcPayment::null2unknown($_GET["vpc_MerchTxnRef"]); $transactionNo = HsbcPayment::null2unknown($_GET["vpc_TransactionNo"]); $acqResponseCode = HsbcPayment::null2unknown($_GET["vpc_AcqResponseCode"]); $txnResponseCode = HsbcPayment::null2unknown($_GET["vpc_TxnResponseCode"]); $verType = array_key_exists("vpc_VerType", $_GET) ? $_GET["vpc_VerType"] : "No Value Returned"; $verStatus = array_key_exists("vpc_VerStatus", $_GET) ? $_GET["vpc_VerStatus"] : "No Value Returned"; $token = array_key_exists("vpc_VerToken", $_GET) ? $_GET["vpc_VerToken"] : "No Value Returned"; $verSecurLevel = array_key_exists("vpc_VerSecurityLevel", $_GET) ? $_GET["vpc_VerSecurityLevel"] : "No Value Returned"; $enrolled = array_key_exists("vpc_3DSenrolled", $_GET) ? $_GET["vpc_3DSenrolled"] : "No Value Returned"; $xid = array_key_exists("vpc_3DSXID", $_GET) ? $_GET["vpc_3DSXID"] : "No Value Returned"; $acqECI = array_key_exists("vpc_3DSECI", $_GET) ? $_GET["vpc_3DSECI"] : "No Value Returned"; $authStatus = array_key_exists("vpc_3DSstatus", $_GET) ? $_GET["vpc_3DSstatus"] : "No Value Returned"; $payment_info = HsbcPayment::where('HSBC_payment_id', $merchTxnRef); if ($payment_info) { $qsi_res_code = HsbcPayment::getResponseDescription($txnResponseCode); $pay = array(); $pay = array('paid_amount' => $amount / 100, 'vpc_txn_res_code' => $txnResponseCode, 'qsi_res_code' => $qsi_res_code, 'vpc_message' => $message, 'vpc_receipt_number' => $receiptNo, 'vpc_txn_no' => $transactionNo, 'vpc_acq_res_code' => $acqResponseCode, 'vpc_bank_auth_id' => $authorizeID, 'vpc_batch_no' => $batchNo, 'card_type' => $cardType, 'vpc_merchant' => $merchantID, 'vpc_command' => $command, 'vpc_version' => $version, 'vpc_Locale' => $locale, 'vpc_OrderInfo' => $orderInfo); $HSBC_payments = DB::table('hsbc_payments')->where('HSBC_payment_id', $merchTxnRef)->update($pay); if (substr_count($orderInfo, 'A') != 0) { if ($txnResponseCode == 0) { $mybooking = 0; $payment = DB::table('payments')->where('HSBC_payment_id', $merchTxnRef)->update(array('my_booking' => $mybooking)); $booking = Booking::where('payment_reference_number', $orderInfo)->first(); $this->sendBookingEmails($booking); } } if (substr_count($orderInfo, 'B') != 0) { if ($txnResponseCode == 0) { $mybooking = 0; $payment = DB::table('payments')->where('HSBC_payment_id', $merchTxnRef)->update(array('my_booking' => $mybooking)); $booking = Booking::where('payment_reference_number', $orderInfo)->first(); $this->sendBookingEmails($booking); } } if (substr_count($orderInfo, 'O') != 0) { if ($txnResponseCode == 0) { $mybooking = 0; $payment = DB::table('payments')->where('HSBC_payment_id', $merchTxnRef)->update(array('my_booking' => $mybooking)); $booking = Booking::where('payment_reference_number', $orderInfo)->first(); $payment = Payment::where('reference_number', $orderInfo)->first(); //dd($booking->email); // Mail::send('emails/online-payment', array( // 'payment' => $payment, // 'booking' => $booking // ), function ($message) use ($booking) { // $message->subject('Online Payment Receipt : ' . $booking->reference_number) // ->from('*****@*****.**', 'SriLankaHotels.Travel') // ->bcc('*****@*****.**') // ->to('*****@*****.**'); // }); Mail::send('emails/online-payment', array('booking' => $booking, 'payment' => $payment), function ($message) use($booking, $payment) { $message->subject('Payment : ' . $payment->reference_number)->from('*****@*****.**', 'SriLankaHotels.Travel')->to($booking->email, $booking->booking_name)->bcc('*****@*****.**', 'Admin'); }); Session::flash('global', 'Thank you for paying online. </br> We have emailed you the online payment invoice'); // return View::make('pages.message'); } Session::flash('global', 'Sorry Your Payment was unsuccessful!'); // return View::make('pages.message'); } if (substr_count($orderInfo, 'AP') != 0) { if ($txnResponseCode == 0) { $mybooking = 0; $payment = DB::table('payments')->where('HSBC_payment_id', $merchTxnRef)->update(array('my_booking' => $mybooking)); $booking = Booking::where('payment_reference_number', $orderInfo)->first(); $this->sendBookingEmails($booking); } } $url = "http://srilankahotels.travel/message"; header("Location: {$url}"); exit; } else { die("An error occurred. Please contact administrator"); } } else { header("Location:index.php"); exit; } }
public function get_cards() { $token = Input::get('token'); $owner_id = Input::get('id'); $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id), array('token' => 'required', 'owner_id' => 'required|integer')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) { // check for token validity if (is_token_active($owner_data->token_expiry) || $is_admin) { // Do necessary operations $payment_data = Payment::where('owner_id', $owner_id)->get(); $payments = array(); foreach ($payment_data as $data) { $data['id'] = $data->id; $data['customer_id'] = $data->customer_id; $data['last_four'] = $data->last_four; array_push($payments, $data); } $response_array = array('success' => true, 'payments' => $payments); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } $response = Response::json($response_array, $response_code); return $response; }
public function request_walk_completed() { if (Request::isMethod('post')) { $request_id = Input::get('request_id'); $token = Input::get('token'); $walker_id = Input::get('id'); $latitude = Input::get('latitude'); $longitude = Input::get('longitude'); $distance = Input::get('distance'); $time = Input::get('time'); $walker = Walker::find($walker_id); $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'walker_id' => $walker_id, 'latitude' => $latitude, 'longitude' => $longitude, 'distance' => $distance, 'time' => $time), array('request_id' => 'required|integer', 'token' => 'required', 'walker_id' => 'required|integer', 'latitude' => 'required', 'longitude' => 'required', 'distance' => 'required', 'time' => 'required')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($walker_data = $this->getWalkerData($walker_id, $token, $is_admin)) { // check for token validity if (is_token_active($walker_data->token_expiry) || $is_admin) { // Do necessary operations if ($request = Requests::find($request_id)) { if ($request->confirmed_walker == $walker_id) { if ($request->is_started == 1) { $settings = Settings::where('key', 'default_charging_method_for_users')->first(); $pricing_type = $settings->value; $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; $distance = convert($distance, $unit); $pt = ProviderServices::where('provider_id', $walker_id)->get(); foreach ($pt as $key) { $reqserv = RequestServices::where('request_id', $request_id)->where('type', $key->type)->first(); $base_price = $key->base_price; $price_per_unit_distance = $key->price_per_unit_distance * $distance; $price_per_unit_time = $key->price_per_unit_time * $time; $reqserv->base_price = $base_price; $reqserv->distance_cost = $price_per_unit_distance; $reqserv->time_cost = $price_per_unit_time; $reqserv->total = $base_price + $price_per_unit_distance + $price_per_unit_time; $reqserv->save(); } $rs = RequestServices::where('request_id', $request_id)->get(); $total = 0; foreach ($rs as $key) { Log::info('total = ' . print_r($key->total, true)); $total = $total + $key->total; } $request->is_completed = 1; $request->distance = $distance; $request->time = $time; $request->total = $total; // charge client $ledger = Ledger::where('owner_id', $request->owner_id)->first(); if ($ledger) { $balance = $ledger->amount_earned - $ledger->amount_spent; if ($balance > 0) { if ($total > $balance) { $ledger_temp = Ledger::find($ledger->id); $ledger_temp->amount_spent = $ledger_temp->amount_spent + $balance; $ledger_temp->save(); $total = $total - $balance; } else { $ledger_temp = Ledger::find($ledger->id); $ledger_temp->amount_spent = $ledger_temp->amount_spent + $total; $ledger_temp->save(); $total = 0; } } } if ($total == 0) { $request->is_paid = 1; } else { $payment_data = Payment::where('owner_id', $request->owner_id)->first(); if ($payment_data) { $customer_id = $payment_data->customer_id; try { if (Config::get('app.default_payment') == 'stripe') { $am = round($total) * 100; $sett = Settings::where('key', 'service_fee')->first(); $serviceFee = $sett->value * 100; $amount = $am - $serviceFee; Stripe::setApiKey(Config::get('app.stripe_secret_key')); Stripe_Charge::create(array("amount" => $am, "currency" => "usd", "customer" => $customer_id)); if ($walker->merchant_id != NULL) { $transfer = Stripe_Transfer::create(array("amount" => $amount, "currency" => "usd", "recipient" => $walker->merchant_id, "statement_descriptor" => "UberFoxX")); Log::info('transfer = ' . print_r($transfer, true)); } $request->is_paid = 1; } else { $am = round($total, 2); $sett = Settings::where('key', 'service_fee')->first(); $serviceFee = $sett->value; $amount = $am - $serviceFee; Braintree_Configuration::environment(Config::get('app.braintree_environment')); Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id')); Braintree_Configuration::publicKey(Config::get('app.braintree_public_key')); Braintree_Configuration::privateKey(Config::get('app.braintree_private_key')); $card_id = $payment_data->card_token; if ($walker->merchant_id == NULL) { $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id)); } else { $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id, 'merchantAccountId' => $walker->merchant_id, 'serviceFeeAmount' => $serviceFee)); } Log::info('result = ' . print_r($result, true)); if ($result->success) { $request->is_paid = 1; } else { $request->is_paid = 0; } } } catch (Exception $e) { $response_array = array('success' => false, 'error' => $e, 'error_code' => 405); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } } } $request->card_payment = $total; $request->ledger_payment = $request->total - $total; $request->save(); if ($request->is_paid == 1) { $owner = Owner::find($request->owner_id); $settings = Settings::where('key', 'sms_request_unanswered')->first(); $pattern = $settings->value; $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern); $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%user_mobile%', $owner->phone, $pattern); sms_notification(1, 'admin', $pattern); } $walker = Walker::find($walker_id); $walker->is_available = 1; $walker->save(); $walk_location = new WalkLocation(); $walk_location->latitude = $latitude; $walk_location->longitude = $longitude; $walk_location->request_id = $request_id; $walk_location->save(); // Send Notification $walker = Walker::find($request->confirmed_walker); $walker_data = array(); $walker_data['first_name'] = $walker->first_name; $walker_data['last_name'] = $walker->last_name; $walker_data['phone'] = $walker->phone; $walker_data['bio'] = $walker->bio; $walker_data['picture'] = $walker->picture; $walker_data['latitude'] = $walker->latitude; $walker_data['longitude'] = $walker->longitude; $walker_data['type'] = $walker->type; $walker_data['rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->avg('rating') ?: 0; $walker_data['num_rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->count(); $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; $bill = array(); if ($request->is_completed == 1) { $bill['distance'] = convert($request->distance, $unit); $bill['time'] = $request->time; $bill['base_price'] = $request->base_price; $bill['distance_cost'] = $request->distance_cost; $bill['time_cost'] = $request->time_cost; $bill['total'] = $request->total; $bill['is_paid'] = $request->is_paid; } $response_array = array('success' => true, 'request_id' => $request_id, 'status' => $request->status, 'confirmed_walker' => $request->confirmed_walker, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_walker_rated' => $request->is_walker_rated, 'walker' => $walker_data, 'bill' => $bill); $title = "Trip Completed"; $message = $response_array; send_notifications($request->owner_id, "owner", $title, $message); // Send SMS $owner = Owner::find($request->owner_id); $settings = Settings::where('key', 'sms_when_provider_completes_job')->first(); $pattern = $settings->value; $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern); $pattern = str_replace('%driver%', $walker->first_name . " " . $walker->last_name, $pattern); $pattern = str_replace('%driver_mobile%', $walker->phone, $pattern); $pattern = str_replace('%damount%', $request->total, $pattern); sms_notification($request->owner_id, 'owner', $pattern); // send email $settings = Settings::where('key', 'email_request_finished')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $request->id, $pattern); $subject = "Request Completed"; email_notification(1, 'admin', $pattern, $subject); $settings = Settings::where('key', 'email_invoice_generated_user')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%amount%', $request->total, $pattern); $subject = "Invoice Generated"; email_notification($request->owner_id, 'owner', $pattern, $subject); $settings = Settings::where('key', 'email_invoice_generated_provider')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%amount%', $request->total, $pattern); $subject = "Invoice Generated"; email_notification($request->confirmed_walker, 'walker', $pattern, $subject); if ($request->is_paid == 1) { // send email $settings = Settings::where('key', 'email_payment_charged')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $request->id, $pattern); $subject = "Payment Charged"; email_notification(1, 'admin', $pattern, $subject); } $response_array = array('success' => true, 'total' => $total, 'is_paid' => $request->is_paid); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Walk not yet started', 'error_code' => 413); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Walk ID doesnot matches with Walker ID', 'error_code' => 407); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Walk ID Not Found', 'error_code' => 408); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { $response_array = array('success' => false, 'error' => 'Walker ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } } $response = Response::json($response_array, $response_code); return $response; }
public function invoice() { $jenjang = Sentry::getUser()->last_name; $cost = Setting::first(); $school = School::where('user_id', Sentry::getUser()->id)->first(); $payment = Payment::where('user_id', Sentry::getUser()->id)->where(DB::raw('year'), '=', date('Y'))->first(); if ($jenjang === 'SMA') { $runpas = Contest::where('nocontest', 'Lari 100m pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $runpis = Contest::where('nocontest', 'Lari 100m pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $ljpas = Contest::where('nocontest', 'Lompat Jauh pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $ljpis = Contest::where('nocontest', 'Lompat Jauh pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $tppas = Contest::where('nocontest', 'Tolak Peluru pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $tppis = Contest::where('nocontest', 'Tolak Peluru pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $ltpas = Contest::where('nocontest', 'Lompat Tinggi pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $ltpis = Contest::where('nocontest', 'Lompat Tinggi pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $sertatl = Contest::where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->whereNotNull('nodada')->where('sertifikat', 1)->count(); $sertoff = Officer::where('user_id', Sentry::getUser()->id)->where(DB::raw('YEAR(created_at)'), '=', date('Y'))->where('sertifikat', 1)->count(); $book = Docbook::where('user_id', Sentry::getUser()->id)->where(DB::raw('YEAR(created_at)'), '=', date('Y'))->where('docbook', 1)->count(); $jrunpas = $runpas * $cost->moneyreg; $jrunpis = $runpis * $cost->moneyreg; $jljpas = $ljpas * $cost->moneyreg; $jljpis = $ljpis * $cost->moneyreg; $jtppas = $tppas * $cost->moneyreg; $jtppis = $tppis * $cost->moneyreg; $jltpas = $ltpas * $cost->moneyreg; $jltpis = $ltpis * $cost->moneyreg; $jsertatl = $sertatl * $cost->moneysertatl; $jsertoff = $sertoff * $cost->moneysertoff; $jbook = $book * $cost->moneydocbook; $jtotal = $jrunpas + $jrunpis + $jljpas + $jljpis + $jtppas + $jtppis + $jltpas + $jltpis + $jsertatl + $jsertoff + $jbook; return View::make('costs.invoice2')->with('runpas', $runpas)->with('runpis', $runpis)->with('ljpas', $ljpas)->with('ljpis', $ljpis)->with('tppas', $tppas)->with('tppis', $tppis)->with('ltpas', $ltpas)->with('ltpis', $ltpis)->with('sertatl', $sertatl)->with('sertoff', $sertoff)->with('book', $book)->with('jrunpas', $jrunpas)->with('jrunpis', $jrunpis)->with('jljpas', $jljpas)->with('jljpis', $jljpis)->with('jtppas', $jtppas)->with('jtppis', $jtppis)->with('jltpas', $jltpas)->with('jltpis', $jltpis)->with('jsertatl', $jsertatl)->with('jsertoff', $jsertoff)->with('jbook', $jbook)->with('jtotal', $jtotal)->with('cost', $cost)->with('school', $school)->with('payment', $payment); } elseif ($jenjang === 'SMP') { $runpas = Contest::where('nocontest', 'Lari 60m pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $runpis = Contest::where('nocontest', 'Lari 60m pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $ljpas = Contest::where('nocontest', 'Lompat Jauh pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $ljpis = Contest::where('nocontest', 'Lompat Jauh pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $tppas = Contest::where('nocontest', 'Tolak Peluru pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $tppis = Contest::where('nocontest', 'Tolak Peluru pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $ltpas = Contest::where('nocontest', 'Lompat Tinggi pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $ltpis = Contest::where('nocontest', 'Lompat Tinggi pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $sertatl = Contest::where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->whereNotNull('nodada')->where('sertifikat', 1)->count(); $sertoff = Officer::where('user_id', Sentry::getUser()->id)->where(DB::raw('YEAR(created_at)'), '=', date('Y'))->where('sertifikat', 1)->count(); $book = Docbook::where('user_id', Sentry::getUser()->id)->where(DB::raw('YEAR(created_at)'), '=', date('Y'))->where('docbook', 1)->count(); $jrunpas = $runpas * $cost->moneyreg; $jrunpis = $runpis * $cost->moneyreg; $jljpas = $ljpas * $cost->moneyreg; $jljpis = $ljpis * $cost->moneyreg; $jtppas = $tppas * $cost->moneyreg; $jtppis = $tppis * $cost->moneyreg; $jltpas = $ltpas * $cost->moneyreg; $jltpis = $ltpis * $cost->moneyreg; $jsertatl = $sertatl * $cost->moneysertatl; $jsertoff = $sertoff * $cost->moneysertoff; $jbook = $book * $cost->moneydocbook; $jtotal = $jrunpas + $jrunpis + $jljpas + $jljpis + $jtppas + $jtppis + $jltpas + $jltpis + $jsertatl + $jsertoff + $jbook; return View::make('costs.invoice2')->with('runpas', $runpas)->with('runpis', $runpis)->with('ljpas', $ljpas)->with('ljpis', $ljpis)->with('tppas', $tppas)->with('tppis', $tppis)->with('ltpas', $ltpas)->with('ltpis', $ltpis)->with('sertatl', $sertatl)->with('sertoff', $sertoff)->with('book', $book)->with('jrunpas', $jrunpas)->with('jrunpis', $jrunpis)->with('jljpas', $jljpas)->with('jljpis', $jljpis)->with('jtppas', $jtppas)->with('jtppis', $jtppis)->with('jltpas', $jltpas)->with('jltpis', $jltpis)->with('jsertatl', $jsertatl)->with('jsertoff', $jsertoff)->with('jbook', $jbook)->with('jtotal', $jtotal)->with('cost', $cost)->with('school', $school)->with('payment', $payment); } elseif ($jenjang === 'SD') { $runpas = Contest::where('nocontest', 'Lari 50m pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $runpis = Contest::where('nocontest', 'Lari 50m pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $ljpas = Contest::where('nocontest', 'Lompat Jauh pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $ljpis = Contest::where('nocontest', 'Lompat Jauh pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $lbpas = Contest::where('nocontest', 'Lempar Bola pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $lbpis = Contest::where('nocontest', 'Lempar Bola pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $lespa = Contest::where('nocontest', 'Lari Estafet pa')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $lespi = Contest::where('nocontest', 'Lari Estafet pi')->where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->count(); $sertatl = Contest::where('user_id', Sentry::getUser()->id)->where(DB::raw('tahun'), '=', date('Y'))->where('verifikasi', 1)->whereNotNull('nodada')->where('sertifikat', 1)->count(); $sertoff = Officer::where('user_id', Sentry::getUser()->id)->where(DB::raw('YEAR(created_at)'), '=', date('Y'))->where('sertifikat', 1)->count(); $book = Docbook::where('user_id', Sentry::getUser()->id)->where(DB::raw('YEAR(created_at)'), '=', date('Y'))->where('docbook', 1)->count(); $jrunpas = $runpas * $cost->moneyreg; $jrunpis = $runpis * $cost->moneyreg; $jljpas = $ljpas * $cost->moneyreg; $jljpis = $ljpis * $cost->moneyreg; $jlbpas = $lbpas * $cost->moneyreg; $jlbpis = $lbpis * $cost->moneyreg; if ($lespa % 8 == 0) { $lespa = $lespa / 8; $jlespa = $lespa * $cost->moneyregest; } else { $lespa = 0; $jlespa = $lespa * $cost->moneyregest; } if ($lespi % 8 == 0) { $lespi = $lespi / 8; $jlespi = $lespi * $cost->moneyregest; } else { $lespi = 0; $jlespi = $lespi * $cost->moneyregest; } $jsertatl = $sertatl * $cost->moneysertatl; $jsertoff = $sertoff * $cost->moneysertoff; $jbook = $book * $cost->moneydocbook; $jtotal = $jrunpas + $jrunpis + $jljpas + $jljpis + $jlbpas + $jlbpis + $jlespa + $jlespi + $jsertatl + $jsertoff + $jbook; return View::make('costs.invoice2')->with('runpas', $runpas)->with('runpis', $runpis)->with('ljpas', $ljpas)->with('ljpis', $ljpis)->with('lbpas', $lbpas)->with('lbpis', $lbpis)->with('lespa', $lespa)->with('lespi', $lespi)->with('sertatl', $sertatl)->with('sertoff', $sertoff)->with('book', $book)->with('jrunpas', $jrunpas)->with('jrunpis', $jrunpis)->with('jljpas', $jljpas)->with('jljpis', $jljpis)->with('jlbpas', $jlbpas)->with('jlbpis', $jlbpis)->with('jlespa', $jlespa)->with('jlespi', $jlespi)->with('jsertatl', $jsertatl)->with('jsertoff', $jsertoff)->with('jbook', $jbook)->with('jtotal', $jtotal)->with('cost', $cost)->with('school', $school)->with('payment', $payment); } }