/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(TransactionRequest $request, $num) { $transaction = new Transaction(['nomenclator_id' => $request['nomenclator_id'], 'tipo' => $request['tipo'], 'monto' => $request['monto']]); $transaction->account_id = $num; $transaction->save(); Session::flash('message', 'Registro realizado correctamente'); return redirect()->action('AccountController@index'); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $transaction = new Transaction(); $transaction->item_name = $request->get('item_name'); $transaction->quantity = $request->get('quantity'); $transaction->price = $request->get('price'); $transaction->save(); return redirect('/transaction')->withSuccess("Transaction added {$transaction->item_name}"); }
public function receiveToken(Request $request) { $token = (string) $request->input('token'); $transaction = new Transaction(); $transaction->associated_name = $request->has('associated_name') ? $request->input('associated_name') : ''; $transaction->contains_please = $request->has('contains_please') ? $request->input('contains_please') : 0; $transaction->charge(100, ['source' => $token]); $transaction->save(); return response()->json(['status' => 'success']); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $transaction = new Transaction(); $transaction->name = $request->input("name"); $transaction->date = $request->input("date"); $transaction->category_id = $request->input("category_id"); $transaction->amount = $request->input("amount"); $transaction->capital_id = $request->input("capital_id"); $transaction->save(); return redirect()->route('transactions.index')->with('message', 'Item created successfully.'); }
/** * Handle the event. * * @param SubscriptionSucceeded $event * @return void */ public function handle(SubscriptionSucceeded $event) { // Get subscription id $query = Subscription::where('paymill_subscription_id', $event->subscription['id'])->first(); $transaction = new Transaction(); $transaction->paymill_transaction_id = $event->transaction['id']; $transaction->user_id = $event->userId; $transaction->subscription_id = $query->id; $transaction->amount = $event->transaction['amount']; $transaction->status = $event->transaction['status']; $transaction->response_code = $event->transaction['response_code']; $transaction->save(); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $this->validate($request, ['name' => 'required', 'description' => 'required', 'sla' => 'required']); $t = new Transaction(); $t->name = $request->name; $t->description = $request->description; $t->sla = $request->sla; $t->TransactionCount = 1; $t->save(); //$input = $request->all(); //Transaction::create($input); Session::flash('flash_message', 'Transaction successfully added!'); return redirect()->back(); }
public function postIndex(Request $request) { if ($request->has('name', 'amount')) { if ($request->get('name') == '' || $request->get('amount') == '') { return Response::make('You need to fill all fields', 400); } $transaction = new Transaction(); $transaction->customer_id = $request->get('customer_id'); $transaction->name = $request->get('name'); $transaction->amount = $request->get('amount'); $transaction->save(); return $transaction; } else { return Response::make('You need to fill all fields', 400); } }
/** * Handle the event. * * @param SubscriptionFailed $event * @return void */ public function handle(SubscriptionFailed $event) { // Stop event propagation if subscription does not exists if (!$event->userId) { return false; } // Get subscription id $subscriptionQuery = Subscription::where('paymill_subscription_id', $event->subscription['id'])->first(); $transaction = new Transaction(); $transaction->paymill_transaction_id = $event->transaction['id']; $transaction->subscription_id = $subscriptionQuery->id; $transaction->user_id = $event->userId; $transaction->amount = $event->transaction['amount']; $transaction->status = $event->transaction['status']; $transaction->response_code = $event->transaction['response_code']; $transaction->save(); }
/** * @param $id * @return \Illuminate\Http\RedirectResponse */ public function checkin($id) { $lastTransaction = Transaction::findLatest($id); if (!$lastTransaction->get()->isEmpty() && $lastTransaction->in_or_out == 'OUT') { $transaction = new Transaction(); $transaction->in_or_out = 'IN'; $transaction->transaction_id = $this->generateTransactionId($transaction->in_or_out); $transaction->due_date = NULL; $transaction->equipment_id = $id; $transaction->username = Auth::id(); // temporary $transaction->person_id = $lastTransaction->person_id; // temporary $transaction->save(); $this->generateReceiptEmail($transaction); return redirect()->route('inventory.index'); } else { return redirect()->route('inventory.index'); } }
public function store_transaction(Request $request) { $money = $request->money; $note = $request->note; $type = $request->type; if ($money == null || $type == null) { Session::flash('message', '<strong class="red-text">Bạn cần nhập số tiền và chọn loại giao dịch</strong>'); return redirect('manage/spendmoney'); } $current_money = $this->user->money; if ($type == 2) { if ($current_money < $money) { Session::flash('message', '<strong class="red-text">Bạn không thể chi nhiều hơn số tiền mình có</strong>'); } else { Session::flash('message', '<strong class="blue-text">Bạn đã chi ' . currency_vnd_format($money) . '</strong>'); $this->user->money = $current_money - $money; $this->user->save(); $transaction = new Transaction(); $transaction->money = $money; $transaction->note = $note; $transaction->type = $type; $transaction->status = 1; $transaction->sender_id = $this->user->id; $transaction->sender_money = $current_money; $transaction->save(); } } else { Session::flash('message', '<strong class="green-text">Bạn đã thêm ' . currency_vnd_format($money) . '</strong>'); $this->user->money = $current_money + $money; $this->user->save(); $transaction = new Transaction(); $transaction->money = $money; $transaction->note = $note; $transaction->type = $type; $transaction->status = 1; $transaction->sender_id = $this->user->id; $transaction->sender_money = $current_money; $transaction->save(); } return redirect('manage/spendmoney'); }
public function get_money(Request $request) { if ($request->register_id == null || $request->money == null || $request->code == null) { return $this->responseBadRequest('Not enough parameters!'); } $register_id = $request->register_id; $money = str_replace(array('.', ','), '', $request->money); $code = $request->code; $register = Register::find($register_id); if ($register->status == 1) { return $this->responseBadRequest('Học viên này đã đóng tiền rồi'); } $register->money = $money; $register->paid_time = format_time_to_mysql(time()); $register->note = $request->note; $register->staff_id = $this->user->id; $regis_by_code = Register::where('code', $code)->first(); if ($regis_by_code != null) { return $this->responseBadRequest('code is already existed'); } else { $register->code = $code; $register->status = 1; $register->save(); $transaction = new Transaction(); $transaction->money = $money; $transaction->sender_id = $this->user->id; $transaction->receiver_id = $register->id; $transaction->sender_money = $this->user->money; $transaction->note = "Học viên " . $register->user->name . " - Lớp " . $register->studyClass->name; $transaction->status = 1; $transaction->type = 1; $transaction->save(); DB::insert(DB::raw("\n insert into attendances(`register_id`,`checker_id`,class_lesson_id)\n (select registers.id,-1,class_lesson.id\n from class_lesson\n join registers on registers.class_id = class_lesson.class_id\n where registers.id = {$register->id}\n )\n ")); $current_money = $this->user->money; $this->user->money = $current_money + $money; $this->user->save(); send_mail_confirm_receive_studeny_money($register, ["*****@*****.**", "*****@*****.**"]); } $return_data = array('data' => ['money' => $register->money, 'code' => $register->code, 'paid_time' => format_date_full_option($register->paid_time)], 'message' => "success"); return $this->respond($return_data); }
public function withdraw(Request $request) { app('db')->transaction(function () use($request, &$response) { $user = $request->user(); $amount = bcmul('1', $request->input('amount')); // truncate extra decimals $u = app('db')->table('users')->where('id', $request->user()->id)->lockForUpdate(); $balance = $u->first()->balance; if ($amount <= 0) { return $response = redirect()->back()->withErrors("You can't withdraw 0"); } if (bccomp($amount, bcadd(TX_FEE, 1.0E-8)) < 0) { return $response = redirect()->back()->withErrors("Amount is too small for TX fee of " . TX_FEE); } if (bccomp($balance, bcsub($amount, TX_FEE)) >= 0) { // change balance atomically app('db')->table('users')->where('id', $user->id)->decrement('balance', $amount); $user->save(); // We do NOT talk to Litecoin directly as that can introduce race conditions. // Store the withdrawal in the DB with 'pending' $t = new Transaction(); $t->user_id = $user->id; $t->type = 'withdrawal'; $t->address = $request->input('address'); $t->amount = bcsub($amount, TX_FEE); // tx fee $t->status = 'confirm'; $t->confirmation_key = rand_str(); $t->save(); Mail::send('emails.confirm_withdraw', ['user' => $user, 'transaction' => $t], function ($m) use($user) { $m->from(env('FROM_EMAIL'), env('FROM_NAME')); $m->to($user->email, $user->name)->subject('Confirm LitecoinPledge Withdrawal'); }); $response = redirect()->back()->with('status', 'Withdrawal was successful. Please check your emails to verify it.'); } else { $response = redirect()->back()->withErrors('Not enough balance to withdraw'); } }); return $response; }
public function postPayment() { $user = $this->auth->user(); $member_id = Input::get("member_id"); $amount = floatval(Input::get("amount")); $service = Input::get("service"); $transaction = new Transaction(); $member = Member::where("member_id", "=", $member_id)->get()->first(); if ($member_id && $amount && $member) { //record changes to member database $member = Member::where("member_id", "=", $member_id)->get()->first(); $member->balance -= abs($amount); $member->save(); //save transaction $transaction->member_id = $member_id; $transaction->amount = abs($amount) * -1; $transaction->service = $service; $transaction->balance = $member->balance; $transaction->save(); return Redirect::to('/members/view?id=' . $member_id); } else { $message = trans("locale.member_not_found"); return view('/transaction/add_transaction')->with("message", $message); } }
public function store_send_money(Request $request) { $this->user->status = 2; $this->user->save(); $transaction = new Transaction(); $transaction->status = 0; $transaction->sender_id = $this->user->id; $transaction->receiver_id = $request->receiver_id; $transaction->receiver_money = User::find($request->receiver_id)->money; $transaction->money = $this->user->money; $transaction->save(); $notification = new Notification(); $notification->product_id = $transaction->id; $notification->actor_id = $this->user->id; $notification->receiver_id = $request->receiver_id; $notification->type = 3; $notification->save(); $data = array("message" => $notification->actor->name . " vừa chuyển tiền cho bạn và đang chờ bạn xác nhận", "link" => "", 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id); $publish_data = array("event" => "notification", "data" => $data); Redis::publish('colorme-channel', json_encode($publish_data)); $publish_data = array("event" => "notification", "data" => ["notification" => $this->notificationTransformer->transform($notification)]); Redis::publish('colorme-channel', json_encode($publish_data)); return redirect('manage/sendmoney'); }
private function setReceiveSalePayment() { $sales[0] = Sale::where('invoice_id', '=', Input::get('invoice_id'))->get(); $saleTransaction = new Transaction(); $saleTransaction->account_category_id = Input::get('account_category_id'); $saleTransaction->account_name_id = Input::get('account_name_id'); $saleTransaction->amount = Input::get('amount'); $saleTransaction->remarks = Input::get('remarks'); $saleTransaction->type = "Receive"; $saleTransaction->user_id = Session::get('user_id'); $saleTransaction->payment_method = Input::get('payment_method'); $saleTransaction->cheque_no = Input::get('cheque_no'); $saleTransaction->invoice_id = Input::get('invoice_id'); $totalAmount = 0; $totalPrice = 0; $saleDetails = SAleDetail::where('invoice_id', '=', $saleTransaction->invoice_id)->get(); $transactions = Transaction::where('invoice_id', '=', $saleTransaction->invoice_id)->get(); foreach ($saleDetails as $saleDetail) { $totalPrice = $totalPrice + $saleDetail->price * $saleDetail->quantity; } foreach ($transactions as $transaction) { $totalAmount = $totalAmount + $transaction->amount; } $sale = Sale::find($sales[0][0]['id']); if ($totalAmount == $totalPrice) { $sale->status = "Completed"; } else { $sale->status = "Partial"; } $accountPayment = NameOfAccount::find(Input::get('account_name_id')); $accountPayment->opening_balance = $accountPayment->opening_balance + Input::get('amount'); $saleTransaction->branch_id = Input::get('branch_id'); $saleTransaction->save(); $sale->save(); $accountPayment->save(); Session::flash('message', 'Sales Due has been Successfully Received.'); }
private function setPurchasePayment() { $accountPayment = NameOfAccount::find(Input::get('account_name_id')); if ($accountPayment->opening_balance >= Input::get('amount')) { $purchases[0] = PurchaseInvoice::where('invoice_id', '=', Input::get('invoice_id'))->get(); $purchaseTransaction = new Transaction(); $purchaseTransaction->account_category_id = Input::get('account_category_id'); $purchaseTransaction->account_name_id = Input::get('account_name_id'); $purchaseTransaction->amount = Input::get('amount'); $purchaseTransaction->remarks = Input::get('remarks'); $purchaseTransaction->user_id = Session::get('user_id'); $purchaseTransaction->type = "Payment"; $purchaseTransaction->payment_method = Input::get('payment_method'); $purchaseTransaction->invoice_id = Input::get('invoice_id'); $purchaseTransaction->cheque_no = Input::get('cheque_no'); $totalAmount = 0; $totalPrice = 0; $purchaseDetails = PurchaseInvoiceDetail::where('detail_invoice_id', '=', $purchaseTransaction->invoice_id)->get(); $transactions = Transaction::where('invoice_id', '=', $purchaseTransaction->invoice_id)->get(); foreach ($purchaseDetails as $purchaseDetail) { $totalPrice = $totalPrice + $purchaseDetail->price * $purchaseDetail->quantity; } foreach ($transactions as $transaction) { $totalAmount = $totalAmount + $transaction->amount; } $purchaseInvoice = PurchaseInvoice::find($purchases[0][0]['id']); if ($totalAmount == $totalPrice) { $purchaseInvoice->status = "Completed"; } else { $purchaseInvoice->status = "Partial"; } $purchaseInvoice->save(); $purchaseTransaction->save(); $accountPayment->opening_balance = $accountPayment->opening_balance - Input::get('amount'); $accountPayment->save(); Session::flash('message', 'Payment has been Successfully Cleared.'); } else { Session::flash('message', 'You dont have Enough Balance'); } }
public function postIndex() { $user = Auth::user(); $id = Input::get('payment'); /* *There is an invisible field called form that tells what form was submitted * */ if (Input::get('form') == 'trans') { $monthNum = substr(Input::get('date'), 0, 2); $month = date('M', mktime(0, 0, 0, $monthNum, 10)); $year = substr(Input::get('date'), -4); $transaction = new Transaction(); $transaction->userID = $user->id; $transaction->date = Input::get('date'); $transaction->amount = Input::get('amount'); $transaction->typeID = Input::get('type'); $transaction->note = Input::get('note'); $transaction->year = $year; $transaction->month = $month; if ($id == 'cash') { $month = Month::where('userID', $user->id)->where('name', $month)->where('year', date("Y"))->first(); $month->cash -= Input::get('amount'); $month->save(); $transaction->accountID = 0; } else { $transaction->accountID = $id; $account = Account::find($id); //add for credit subtract for bank if ($account->accountType == 'c') { $account->balance += Input::get('amount'); } else { $account->balance -= Input::get('amount'); } $account->save(); } $transaction->save(); return redirect('options')->with('message', 'Transaction added successfully.'); } else { if (Input::get('form') == 'type') { $type = new Type(); $type->userID = $user->id; $type->name = Input::get('name'); $type->save(); return redirect('options')->with('message', 'Category added successfully.'); } else { if (Input::get('form') == 'payment') { $monthNum = substr(Input::get('date'), 0, 2); $month = date('M', mktime(0, 0, 0, $monthNum, 10)); $year = substr(Input::get('date'), -4); $amount = Input::get('amount'); $bankID = Input::get('bank'); $ccID = Input::get('payment'); $note = Input::get('note'); $date = Input::get('date'); if ($ccID == 'cash') { $month2 = Month::where('userID', $user->id)->where('name', $month)->first(); $month2->cash = $month2->cash + $amount; $month2->save(); if ($bankID == 'cash') { $month2 = Month::where('userID', $user->id)->where('name', $month)->first(); $month2->cash = $month2->cash - $amount; $month2->save(); } else { $bank = Account::find($bankID); $bank->balance = $bank->balance - $amount; $bank->save(); } $transfer = new Transfer(); $transfer->userID = $user->id; $transfer->creditAccountID = $bankID; $transfer->debitAccountID = 0; $transfer->amount = $amount; $transfer->note = $note; $transfer->date = $date; $transfer->year = $year; $transfer->month = $month; $transfer->save(); } else { $cc = Account::find($ccID); if ($bankID == 'cash') { $month2 = Month::where('userID', $user->id)->where('name', $month)->first(); $month2->cash = $month2->cash - $amount; $month2->save(); } else { $bank = Account::find($bankID); $bank->balance = $bank->balance - $amount; $bank->save(); } if ($cc->accountType == 'b') { //transfer $cc->balance = $cc->balance + $amount; $transfer = new Transfer(); $transfer->userID = $user->id; $transfer->creditAccountID = $bankID; $transfer->debitAccountID = $ccID; $transfer->amount = $amount; $transfer->note = $note; $transfer->date = $date; $transfer->year = $year; $transfer->month = $month; $transfer->save(); } else { //payment $cc->balance = $cc->balance - $amount; $payment = new Payment(); $payment->userID = $user->id; $payment->creditAccountID = $bankID; $payment->debitAccountID = $ccID; $payment->amount = $amount; $payment->note = $note; $payment->date = $date; $payment->year = $year; $payment->month = $month; $payment->save(); } $cc->save(); } return redirect('options')->with('message', 'Payment saved successfully.'); } else { if (Input::get('form') == 'cc') { $cc = new Account(); $cc->userID = $user->id; $cc->name = Input::get('name'); $cc->balance = Input::get('balance'); $cc->creditLimit = Input::get('limit'); $cc->statementDay = Input::get('date'); $cc->accountType = 'c'; $cc->save(); return redirect('options')->with('message', 'Credit Card added successfully.'); } else { if (Input::get('form') == 'bank') { $bank = new Account(); $bank->userID = $user->id; $bank->name = Input::get('name'); $bank->balance = Input::get('balance'); $bank->accountType = 'b'; $bank->save(); return redirect('options')->with('message', 'Bank Account added successfully.'); } else { if (Input::get('form') == 'income') { $date = Input::get('date'); $monthNum = substr($date, 0, 2); $month = date('M', mktime(0, 0, 0, $monthNum, 10)); $amount = Input::get('amount'); $bankID = Input::get('bank'); $year = substr(Input::get('date'), -4); $income = new Income(); $income->userID = $user->id; $income->month = $month; $income->amount = $amount; $income->note = Input::get('note'); $income->date = $date; $income->year = $year; if ($bankID == "cash") { $income->accountID = 0; $month = Month::where('userID', $user->id)->where('name', $month)->first(); $month->cash = $month->cash + $amount; $month->save(); } else { $income->accountID = $bankID; $bank = Account::find($bankID); $bank->balance = $bank->balance + $amount; $bank->save(); } $income->save(); return redirect('options')->with('message', 'Income added successfully.'); } } } } } } }
public function postSaveSalesReturn() { $ruless = array('party_id' => 'required', 'cus_ref_no' => 'required', 'branch_id' => 'required', 'product_type' => 'required', 'product_id' => 'required', 'quantity' => 'required', 'return_amount' => 'required', 'consignment_name' => 'required'); $validate = Validator::make(Input::all(), $ruless); if ($validate->fails()) { return Redirect::to('salesreturn/create')->withErrors($validate); } else { $salesreturn = new SalesReturn(); $this->setSalesReturnData($salesreturn); //automatically reduce sales payment starts $return_amount = Input::get('return_amount'); $remaining_amount = $return_amount; //var_dump($remaining_amount); $partyId = Input::get('party_id'); if ($remaining_amount > 0) { $invoiceId = Sale::where('party_id', '=', $partyId)->get(); foreach ($invoiceId as $invid) { $price = SAleDetail::where('invoice_id', '=', $invid->invoice_id)->get(); $detailsPrice = 0; foreach ($price as $prc) { $detailsPrice = $detailsPrice + $prc->price * $prc->quantity; } var_dump($detailsPrice); $amount = Transaction::where('invoice_id', '=', $invid->invoice_id)->where('type', '=', 'Receive')->get(); $paid = 0; foreach ($amount as $amnt) { $paid = $paid + $amnt->amount; } $difference = $detailsPrice - $paid; if ($difference > 0) { echo 'greater than 0 difference'; if ($remaining_amount <= $difference) { $transaction = new Transaction(); $transaction->invoice_id = $invid->invoice_id; $transaction->amount = $remaining_amount; $transaction->type = 'Receive'; $transaction->payment_method = 'Sales Return'; $transaction->account_category_id = 7; $transaction->remarks = 'Sales Return'; $transaction->account_name_id = 8; $transaction->user_id = Session::get('user_id'); $transaction->cheque_no = ''; $branch = SAleDetail::where('invoice_id', '=', $invid->invoice_id)->first(); $transaction->branch_id = $branch->branch_id; $transaction->save(); $remaining_amount = 0; } elseif ($remaining_amount > $difference) { $toBePaid = $remaining_amount - $difference; $transaction = new Transaction(); $transaction->invoice_id = $invid->invoice_id; $transaction->amount = $difference; $transaction->type = 'Receive'; $transaction->payment_method = 'Sales Return'; $transaction->account_category_id = 7; $transaction->remarks = 'Sales Return'; $transaction->account_name_id = 8; $transaction->user_id = Session::get('user_id'); $transaction->cheque_no = ''; $branch = SAleDetail::where('invoice_id', '=', $invid->invoice_id)->first(); $transaction->branch_id = $branch->branch_id; $transaction->save(); $remaining_amount = $toBePaid; } } } } /*if($remaining_amount>0) { echo "How come its possible! Consult with DEVELOPERS!!!"; }*/ //automatically reduce sales payment ends return Redirect::to('salesreturn/create'); } }
private function setPurchasePayment() { $accountPayment = NameOfAccount::find(Input::get('account_name_id')); if ($accountPayment->opening_balance >= Input::get('amount')) { $expense[0] = Expense::where('invoice_id', '=', Input::get('invoice_id'))->get(); $expenseTransaction = new Transaction(); $expenseTransaction->branch_id = Input::get('branch_id'); $expenseTransaction->account_category_id = Input::get('account_category_id'); $expenseTransaction->account_name_id = Input::get('account_name_id'); $expenseTransaction->amount = Input::get('amount'); $expenseTransaction->remarks = Input::get('remarks'); $expenseTransaction->type = "Expense"; $expenseTransaction->user_id = Session::get('user_id'); $expenseTransaction->payment_method = Input::get('payment_method'); $expenseTransaction->invoice_id = Input::get('invoice_id'); $expenseTransaction->cheque_no = Input::get('cheque_no'); $expenseTransaction->save(); $totalAmount = 0; $transactions = Transaction::where('invoice_id', '=', $expenseTransaction->invoice_id)->get(); foreach ($transactions as $transaction) { $totalAmount = $totalAmount + $transaction->amount; } $expense = Expense::find($expense[0][0]['id']); if ($totalAmount == $expense->amount) { $expense->status = "Completed"; } else { $expense->status = "Partial"; } $expense->save(); $accountPayment->opening_balance = $accountPayment->opening_balance - Input::get('amount'); $accountPayment->save(); Session::flash('message', 'Expense has been Successfully Cleared.'); } else { Session::flash('message', 'You dont have Enough Balance'); } }
/** * Check if we can complete a transaction (has it got enough confirms), * if so, set to complete and increment the users balance * @param $t * @param $tran * @return bool */ function completeTransaction($t, Transaction $tran) { if ($t['confirmations'] > 0) { if ($tran->user_id > 0) { $u = $tran->user; DB::table('users')->where('id', $u->id)->increment('balance', $t['amount']); $this->info("Incremented user '{$u->username}' balance by {$tran->amount}"); } else { if ($tran->project_id > 0) { $p = $tran->project; DB::table('projects')->where('id', $p->id)->increment('project_balance', $t['amount']); DB::table('projects')->where('id', $p->id)->increment('total_pledged', $t['amount']); $this->info("Incremented project '{$p->id}' balance by {$tran->amount}"); // track anonymous pledges $pledge = new Pledge(); $pledge->amount = $t['amount']; $pledge->user_id = 0; $pledge->type = "anon"; $pledge->project_id = $p->id; $pledge->save(); } else { return false; } } $tran->confirmations = $t['confirmations']; $tran->status = 'complete'; } $tran->save(); return true; }
public function postSaveReceiveAll() { $transactionId = 0; $ruless = array('party_id' => 'required', 'branch_id' => 'required', 'account_category_id' => 'required', 'account_name_id' => 'required', 'payment_method' => 'required', 'amount' => 'required'); $validate = Validator::make(Input::all(), $ruless); if ($validate->fails()) { var_dump($validate); die; return Redirect::to('sales/index/')->withErrors($validate); } else { //$this->setReceiveSalePaymentAll(); //return Redirect::to('sales/index'); //$salesreturn = new SalesReturn(); //$this->setSalesReturnData($salesreturn); //automatically reduce sales payment starts $return_amount = Input::get('amount'); $remaining_amount = $return_amount; //var_dump($remaining_amount); $partyId = Input::get('party_id'); if ($remaining_amount > 0) { $invoiceId = PurchaseInvoice::where('party_id', '=', $partyId)->get(); foreach ($invoiceId as $invid) { $detailsPrice = 0; $paid = 0; $saleDetails = PurchaseInvoiceDetail::where('detail_invoice_id', '=', $invid->invoice_id)->get(); $transactions = Transaction::where('invoice_id', '=', $invid->invoice_id)->where('payment_method', '=', 'Check')->where('type', '=', 'Payment')->where('cheque_status', '=', 1)->get(); foreach ($saleDetails as $saleDetail) { $detailsPrice = $detailsPrice + $saleDetail->price * $saleDetail->quantity; } foreach ($transactions as $transaction) { $paid = $paid + $transaction->amount; } $transactions2 = Transaction::where('invoice_id', '=', $invid->invoice_id)->where('type', '=', 'Payment')->where('payment_method', '!=', 'Check')->get(); foreach ($transactions2 as $transaction) { $paid = $paid + $transaction->amount; } $difference = $detailsPrice - $paid; //echo $difference; die(); if ($difference > 0) { //echo 'greater than 0 difference'; if ($remaining_amount <= $difference) { if ($remaining_amount > 0) { $sale = PurchaseInvoice::find($invid->id); if ($remaining_amount < $difference) { $sale->status = "Partial"; } elseif ($remaining_amount == $difference) { $sale->status = "Completed"; } $transaction = new Transaction(); $transaction->invoice_id = $invid->invoice_id; $transaction->amount = $remaining_amount; $transaction->type = 'Payment'; $transaction->payment_method = Input::get('payment_method'); $transaction->account_category_id = Input::get('account_category_id'); $transaction->remarks = Input::get('remarks'); $transaction->account_name_id = Input::get('account_name_id'); $transaction->user_id = Session::get('user_id'); $transaction->cheque_no = Input::get('cheque_no'); $branch = PurchaseInvoiceDetail::where('detail_invoice_id', '=', $invid->invoice_id)->first(); $transaction->branch_id = $branch->branch_id; $transaction->cheque_date = Input::get('cheque_date'); $transaction->cheque_bank = Input::get('cheque_bank'); if ($transaction->payment_method != "Check") { $accountPayment = NameOfAccount::find(Input::get('account_name_id')); $accountPayment->opening_balance = $accountPayment->opening_balance - $remaining_amount; $accountPayment->save(); } $transaction->save(); $transactionId = $transaction->id; $remaining_amount = 0; } } elseif ($remaining_amount > $difference) { if ($remaining_amount > 0) { $sale = PurchaseInvoice::find($invid->id); $sale->status = "Completed"; $toBePaid = $remaining_amount - $difference; $transaction = new Transaction(); $transaction->invoice_id = $invid->invoice_id; $transaction->amount = $difference; $transaction->type = 'Payment'; $transaction->payment_method = Input::get('payment_method'); $transaction->account_category_id = Input::get('account_category_id'); $transaction->remarks = Input::get('remarks'); $transaction->account_name_id = Input::get('account_name_id'); $transaction->user_id = Session::get('user_id'); $transaction->cheque_no = Input::get('cheque_no'); $branch = PurchaseInvoiceDetail::where('detail_invoice_id', '=', $invid->invoice_id)->first(); $transaction->branch_id = $branch->branch_id; $transaction->cheque_date = Input::get('cheque_date'); $transaction->cheque_bank = Input::get('cheque_bank'); if ($transaction->payment_method != "Check") { $accountPayment = NameOfAccount::find(Input::get('account_name_id')); $accountPayment->opening_balance = $accountPayment->opening_balance - $difference; $accountPayment->save(); } $transaction->save(); $transactionId = $transaction->id; $remaining_amount = $toBePaid; } } $sale->save(); } } } /*if($remaining_amount>0) { echo "How come its possible! Consult with DEVELOPERS!!!"; }*/ //automatically reduce sales payment ends return Redirect::to('purchases/voucher/' . $transactionId); } }
public function check(Requests\EventSelectionRequest $request) { $doc_type = $request->get('doc_type'); $doc_num = $request->get('doc_num'); $gender = $request->get('gender'); $dob = Carbon::parse($request->get('dob')); $race = Race::find($request->get('race_id')); $event = Event::find($request->get('event_id')); $payment = Payment::find($request->get('payment_id')); if (!($code = Code::where('code', $request->get('code'))->first())) { $code = Code::makeDummy(); } if (!($gateway = Gateway::find($request->get('gateway_id')))) { $gateway = Gateway::makeDummy(); } if (!($coupon = Coupon::where('coupon', $request->get('coupon'))->first())) { $coupon = Coupon::makeDummy(); } if ($race->locality_enabled == true) { $locality = $code->getLocality(); $mask = $event->mask; $event = Event::where([['race_id', $race->id], ['locality', $locality], ['mask', $mask]])->first(); } if (!$event) { $age_group = getAgeGroup($race, $dob); $event = Event::find($age_group->event_id); } else { $age_group = getAgeGroup($race, $dob, $event); } //==== ALL MODELS AVAILABLE ====// // CHECK RUNNER AGE if ($error = checkRunnerAge($event, $age_group)) { return redirect($race->prefix . '/error')->with('age', $error); } // CHECK RUNNER GENDER if ($error = checkRunnerGender($event, $gender)) { return redirect($race->prefix . '/error')->with('gender', $error); } // CHECK RUNNER DOC if ($error = checkRunnerDoc($race, $doc_num)) { return redirect($race->prefix . '/error')->with('doc', $error); } // CHECK CODE if ($error = checkCode($payment, $event, $code, $request->get('code'))) { return redirect($race->prefix . '/error')->with('code', $error); } // CHECK COUPON if ($error = checkCoupon($coupon, $request->get('coupon'))) { return redirect($race->prefix . '/error')->with('coupon', $error); } // POPULATE TICKET if ($event->free_event == false) { if ($payment->id == 1) { $rate = $event->getCurrentRate(); $transaction = new Transaction(); $transaction->gateway_id = $gateway->id; $transaction->event_id = $event->id; $transaction->price = $rate->price; $transaction->coupon = $coupon->coupon; $transaction->discount = $coupon->calculateDiscount($transaction->price); $transaction->amount = $transaction->price - $transaction->discount; $transaction->save(); $ticket = $transaction->id; } else { $ticket = $code->code; $transaction = Transaction::makeDummy(); } } else { $ticket = $doc_num; $transaction = Transaction::makeDummy(); } $type = $request->get('type'); return redirect($race->prefix . '/runner')->with(['doc_type' => $doc_type, 'doc_num' => $doc_num, 'gender' => $gender, 'dob' => $dob, 'race_id' => $race->id, 'event_id' => $event->id, 'age_group_id' => $age_group->id, 'payment_id' => $payment->id, 'ticket' => $ticket, 'gateway_id' => $gateway->id, 'transaction_id' => $transaction->id, 'code_id' => $code->id, 'coupon_id' => $coupon->id, 'type' => $type]); }
public function postCheckout() { $tos = Cart::tos(); $total = Cart::total(); $input = array('order_date' => date('Y-m-d H:i:s'), 'total_tax' => $tos, 'total_purchase' => $total, 'order_status' => 'pending', 'name' => Input::get('name'), 'email' => Input::get('email'), 'no_tel' => Input::get('no_tel'), 'address' => Input::get('address'), 'city' => Input::get('city'), 'poskod' => Input::get('poskod'), 'state' => Input::get('state')); $order = Order::create($input); $formid = str_random(); $cart_content = Cart::content(); foreach ($cart_content as $cart) { $transaction = new Transaction(); $transaction->product_id = $cart->id; $transaction->form_id = $formid; $transaction->qty = $cart->qty; $transaction->total_price = $cart->subtotal; $transaction->order_id = $order->id; $transaction->gambar_id = $cart->options->img_id; $transaction->color = $cart->options->color; $transaction->size = $cart->options->size; $transaction->category_id = $cart->options->cat; $transaction->save(); } $ttr = Transaction::where('order_id', '=', $order->id); Cart::destroy(); Session::forget('values'); return redirect('store/thankyou/'); }
public function postSaveSalesReturn() { $ruless = array('party_id' => 'required'); $validate = Validator::make(Input::all(), $ruless); if ($validate->fails()) { return json_encode($validate); } else { $salesreturn = new SalesReturnInvoice(); $this->setSalesReturnData($salesreturn); $salesReturnDetails = new SalesReturnDetail(); $salesReturnDetails->product_type = Input::get('product_type'); $salesReturnDetails->product_id = Input::get('product_id'); $salesReturnDetails->quantity = Input::get('quantity'); $salesReturnDetails->unit_price = Input::get('unit_price'); $salesReturnDetails->return_amount = $salesReturnDetails->quantity * $salesReturnDetails->unit_price - $salesReturnDetails->quantity * $salesReturnDetails->unit_price * ((double) Input::get('discount_percentage') / 100); $salesReturnDetails->consignment_name = Input::get('consignment_name'); $salesReturnDetails->invoice_id = Input::get('invoice_id'); $salesReturnDetails->save(); //automatically reduce sales payment starts $unit_price = Input::get('unit_price'); $remaining_amount = $salesReturnDetails->return_amount; //var_dump($remaining_amount); $partyId = Input::get('party_id'); if ($remaining_amount > 0) { $invoiceId = Sale::where('party_id', '=', $partyId)->where('is_sale', '=', 1)->get(); foreach ($invoiceId as $invid) { $price = SAleDetail::where('invoice_id', '=', $invid->invoice_id)->get(); $detailsPrice = 0; foreach ($price as $prc) { $detailsPrice = $detailsPrice + $prc->price * $prc->quantity; } //var_dump($detailsPrice); $amount = Transaction::where('invoice_id', '=', $invid->invoice_id)->where('type', '=', 'Receive')->get(); $paid = 0; foreach ($amount as $amnt) { $paid = $paid + $amnt->amount; } $difference = $detailsPrice - $paid; if ($difference > 0) { //echo 'greater than 0 difference'; if ($remaining_amount <= $difference) { if ($remaining_amount > 0) { $sale = Sale::find($invid->id); if ($remaining_amount < $difference) { $sale->status = "Partial"; } elseif ($remaining_amount == $difference) { $sale->status = "Completed"; } $transaction = new Transaction(); $transaction->invoice_id = $invid->invoice_id; $transaction->amount = $remaining_amount; $transaction->type = 'Receive'; $transaction->payment_method = 'Sales Return'; $transaction->account_category_id = 7; $transaction->remarks = Input::get('invoice_id'); $transaction->account_name_id = 8; $transaction->user_id = Session::get('user_id'); $transaction->cheque_no = ''; $branch = SAleDetail::where('invoice_id', '=', $invid->invoice_id)->first(); $transaction->branch_id = $branch->branch_id; $transaction->save(); $remaining_amount = 0; } } elseif ($remaining_amount > $difference) { if ($remaining_amount > 0) { $sale = Sale::find($invid->id); $sale->status = "Completed"; $toBePaid = $remaining_amount - $difference; $transaction = new Transaction(); $transaction->invoice_id = $invid->invoice_id; $transaction->amount = $difference; $transaction->type = 'Receive'; $transaction->payment_method = 'Sales Return'; $transaction->account_category_id = 7; $transaction->remarks = Input::get('invoice_id'); $transaction->account_name_id = 8; $transaction->user_id = Session::get('user_id'); $transaction->cheque_no = ''; $branch = SAleDetail::where('invoice_id', '=', $invid->invoice_id)->first(); $transaction->branch_id = $branch->branch_id; $transaction->save(); $remaining_amount = $toBePaid; } } $sale->save(); } } } /*if($remaining_amount>0) { echo "How come its possible! Consult with DEVELOPERS!!!"; }*/ //automatically reduce sales payment ends return $this->saleReturnDetailConvertToArray($salesReturnDetails); } }
public function create_transaction($domain, Request $request) { if ($this->user->status == 2) { return $this->responseBadRequest('Nhân viên này đang chuyển tiền.'); } else { $this->user->status = 2; $this->user->save(); $transaction = new Transaction(); $transaction->status = 0; $transaction->sender_id = $this->user->id; $transaction->receiver_id = $request->receiver_id; $transaction->receiver_money = User::find($request->receiver_id)->money; $transaction->money = $this->user->money; $transaction->save(); $notification = new Notification(); $notification->product_id = $transaction->id; $notification->actor_id = $this->user->id; $notification->receiver_id = $request->receiver_id; $notification->type = 3; $notification->save(); $data = array("message" => $notification->actor->name . " vừa chuyển tiền cho bạn và đang chờ bạn xác nhận.", "link" => "", 'transaction' => ['id' => $transaction->id, 'sender' => $transaction->sender->name, 'receiver' => $transaction->receiver->name, 'status' => transaction_status_raw($transaction->status), 'money' => $transaction->money], 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id); $publish_data = array("event" => "notification", "data" => $data); Redis::publish('colorme-channel', json_encode($publish_data)); $publish_data = array("event" => "notification", "data" => ["notification" => $this->notificationTransformer->transform($notification)]); Redis::publish('colorme-channel', json_encode($publish_data)); return $this->respond(['transaction' => ['sender' => $transaction->sender->name, 'receiver' => $transaction->receiver->name, 'status' => transaction_status_raw($transaction->status), 'money' => $transaction->money]]); } }
public function store(Request $request) { $validator = Validator::make($request->all(), ['firstname' => 'required', 'lastname' => 'required', 'street' => 'required', 'email' => 'required|email|max:255', 'city' => 'required', 'state' => 'required', 'city' => 'required', 'postcode' => 'required', 'phone' => 'required', 'shipping' => 'required']); if ($validator->fails()) { return Redirect::to('cart/billing')->withErrors($validator)->withInput(); } else { $count = Transaction::all()->count(); $formid = 'hr' . '-' . date('m') . date('Y') . '-' . ($count + 1); $cart_content = Cart::content(); $get_subtotal = Cart::total(); $get_shipping = Input::get('shipping'); #save user $user = new User(); $user->name = Input::get('firstname') . ' ' . Input::get('lastname'); $user->email = Input::get('email'); $user->save(); $user_id = $user->id; #save group $group = array('id_user' => $user_id, 'id_group' => 3); User::set_group($group); #save profile $profile = new profile(); $profile->id_user = $user_id; $profile->firstname = Input::get('firstname'); $profile->lastname = Input::get('lastname'); $profile->country = Input::get('country'); $profile->street = Input::get('street'); $profile->optionals = Input::get('optionals'); $profile->email = Input::get('email'); $profile->city = Input::get('city'); $profile->state = Input::get('state'); $profile->postcode = Input::get('postcode'); $profile->phone = Input::get('phone'); $profile->note = Input::get('note'); $profile->save(); $profile_id = $profile->id; #save transaction $transaction = new Transaction(); $transaction->date = date('Y-m-d'); $transaction->code = $formid; $transaction->subtotal = $get_subtotal; $transaction->shipping = $get_shipping; $transaction->total = $get_subtotal + $get_shipping; $transaction->subsribe = 0; $transaction->id_user = $user_id; $transaction->save(); $transaction_id = $transaction->id; #save order #show all data in cart foreach ($cart_content as $cart) { $data = array('id_transaction' => $transaction_id, 'id_product' => $cart->id, 'qty' => $cart->qty, 'subtotal' => $cart->subtotal); Transaction::insert_order($data); } #save transaction subsribe #save order #show all data in cart // start count total and price foreach ($cart_content as $cart) { $qty = 0; $price_total = 0; if ($cart->options->subs > 0) { $qty += $cart->qty; $price_total += $cart->subtotal; // shipping calculate if ($qty == 1) { $shipping = 5; } else { $shipping = 2 * ($qty - 1) + 5; } $subsribe = new Transaction(); $subsribe->date = date('Y-m-d'); $subsribe->code = $formid . '-' . $cart->options->subs; $subsribe->subtotal = $price_total; $subsribe->shipping = $shipping; $subsribe->total = $price_total + $shipping; $subsribe->subsribe = $cart->options->subs; $subsribe->id_user = $user_id; $subsribe->subsribe_status = 'active'; $subsribe->save(); $subsribe_id = $subsribe->id; $data = array('id_transaction' => $subsribe_id, 'id_product' => $cart->id, 'qty' => $cart->qty, 'subtotal' => $cart->subtotal); Transaction::insert_order($data); } } // $transac = new Transac(); // $transac->send_order($transaction_id); Cart::destroy(); return redirect('cart/finish/' . $transaction_id)->with('message', 'You have done successfully'); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // validate request $this->validate($request, ['date' => 'required|date_format:d/m/Y', 'type' => 'required|in:WITHDRAWAL,DEPOSIT', 'account_id' => 'required|integer|min:1', 'payee_id' => 'required|integer|min:0', 'category_id' => 'required|integer|min:0', 'amount' => 'required|numeric|min:0.01', 'comment' => 'max:255']); // check if account exists $account = User::find(Auth::user()->id)->accounts->find($request->account_id); if ($account === null) { // stuff to pass into view $title = "Error"; $errmsg = "The account does not exist."; return view('errors.error', compact('errmsg', 'title', 'heading')); } // get the amount and balance $balance = $account->balance * 100; $amount = round($request->amount * 100, 2); // check if payee exists if ($request->payee_id != 0) { $payee = User::find(Auth::user()->id)->payees->find($request->payee_id); if ($payee === null) { // stuff to pass into view $title = "Error"; $errmsg = "The payee does not exist."; return view('errors.error', compact('errmsg', 'title', 'heading')); } } // check if category exists if ($request->category_id != 0) { $category = User::find(Auth::user()->id)->categories->find($request->category_id); if ($category === null) { // stuff to pass into view $title = "Error"; $errmsg = "The category does not exist."; return view('errors.error', compact('errmsg', 'title', 'heading')); } } // start new transaction DB::transaction(function () use($request, $balance, $amount) { // create new transaction record $transaction = new Transaction(); // format date $date = date('Y-m-d', strtotime(str_replace('/', '-', $request->date))); // set the values $transaction->user_id = Auth::user()->id; $transaction->type = $request->type; $transaction->date = $date; $transaction->account_id = $request->account_id; if ($request->payee_id != 0) { $transaction->payee_id = $request->payee_id; } if ($request->category_id != 0) { $transaction->category_id = $request->category_id; } $transaction->amount = round($request->amount, 2); $transaction->comment = $request->comment; // save the transaction $transaction->save(); // get the account record $account = User::find(Auth::user()->id)->accounts->find($request->account_id); // update the values if (strcasecmp($request->type, "WITHDRAWAL") == 0) { $account->balance = round(($balance - $amount) / 100, 2); } else { if (strcasecmp($request->type, "DEPOSIT") == 0) { $account->balance = round(($balance + $amount) / 100, 2); } } // update the balance $account->save(); }); // flash message session()->flash('flash_message', 'Transaction created successfully.'); // redirect to transactions list return redirect()->route('accounts.show', $request->account_id); }
/** * Save transaction * * @param int $typeId * @param string $text * @param $userId * @param $amount */ protected function _saveTransation($status_id = 1, $user_id, $amount, $campaign_id = null, $payment_id = null, $recommendation_id = null) { /** * Save transaction */ $transaction = new Transaction(); $transaction->transactionstatus_id = $status_id; $transaction->user_id = $user_id; $transaction->amount = $amount; $transaction->campaign_id = $campaign_id; $transaction->payment_id = $payment_id; $transaction->recommendation_id = $recommendation_id; $transaction->save(); /** * Update user wallet */ $user = User::find($user_id); $user->wallet = $user->wallet + $amount; $user->save(); }