PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB` get('from'); $to = $request->get('to'); $reference = \App\Reference::where('status', 0)->get(); //$income = ReferenceIncome::get(); $ref_id = $request->reference_id; $status_purpose = $request->status_purpose; if ($from || $to) { $from = date("Y-m-d", strtotime($request->from)); $to = date("Y-m-d", strtotime($request->to)); if ($ref_id == NULL && $status_purpose == NULL) { $withdraws = ReferenceWithdraw::orderBy('date', 'ASC') ->whereBetween('date', array($from, $to))->paginate(20); $total = ReferenceWithdraw::whereBetween('date', array($from, $to)) ->sum('amount'); } else if ($ref_id == NULL && $status_purpose != NULL) { $withdraws = ReferenceWithdraw::orderBy('date', 'ASC') ->where('status_purpose', $status_purpose) ->whereBetween('date', array($from, $to))->paginate(20); $total = ReferenceWithdraw::whereBetween('date', array($from, $to)) ->where('status_purpose', $status_purpose) ->sum('amount'); } else if ($ref_id != NULL && $status_purpose == NULL) { $withdraws = ReferenceWithdraw::orderBy('date', 'ASC') ->where('reference_id', $ref_id) ->whereBetween('date', array($from, $to))->paginate(20); $total = ReferenceWithdraw::whereBetween('date', array($from, $to)) ->where('reference_id', $ref_id) ->sum('amount'); } else { $withdraws = ReferenceWithdraw::orderBy('date', 'ASC') ->where('status_purpose', $status_purpose) ->where('reference_id', $ref_id) ->whereBetween('date', array($from, $to))->paginate(20); $total = ReferenceWithdraw::whereBetween('date', array($from, $to)) ->where('status_purpose', $status_purpose) ->where('reference_id', $ref_id) ->sum('amount'); } $book_com = ReferenceWithdraw::where('status_purpose', 2) ->whereBetween('date', array($from, $to)) ->sum('amount'); $ins_com = ReferenceWithdraw::where('status_purpose', 3) ->whereBetween('date', array($from, $to)) ->sum('amount'); $ek_com = ReferenceWithdraw::where('status_purpose', 1) ->whereBetween('date', array($from, $to)) ->sum('amount'); } else if ($from == NULL && $to == NULL && ($ref_id != NULL || $status_purpose != NULL)) { if ($ref_id == NULL && $status_purpose != NULL) { $withdraws = ReferenceWithdraw::orderBy('date', 'ASC') ->where('status_purpose', $status_purpose)->paginate(20); $total = ReferenceWithdraw::where('status_purpose', $status_purpose) ->sum('amount'); } else if ($ref_id != NULL && $status_purpose == NULL) { $withdraws = ReferenceWithdraw::orderBy('date', 'ASC') ->where('reference_id', $ref_id) ->paginate(20); $total = ReferenceWithdraw::where('reference_id', $ref_id) ->sum('amount'); } else { $withdraws = ReferenceWithdraw::orderBy('date', 'ASC') ->where('status_purpose', $status_purpose) ->where('reference_id', $ref_id) ->paginate(20); $total = ReferenceWithdraw::where('status_purpose', $status_purpose) ->where('reference_id', $ref_id) ->sum('amount'); } $book_com = ReferenceWithdraw::where('status_purpose', 2) ->sum('amount'); $ins_com = ReferenceWithdraw::where('status_purpose', 3) ->sum('amount'); $ek_com = ReferenceWithdraw::where('status_purpose', 1) ->sum('amount'); } else { $withdraws = ReferenceWithdraw::orderBy('date', 'ASC')->get(); $book_com = ReferenceWithdraw::where('status_purpose', 2) ->sum('amount'); $ins_com = ReferenceWithdraw::where('status_purpose', 3) ->sum('amount'); $ek_com = ReferenceWithdraw::where('status_purpose', 1) ->sum('amount'); $total = ReferenceWithdraw::sum('amount'); } $company = Company::latest()->first(); return view('withdraw.index', compact( 'withdraws', 'company', 'reference', 'from', 'to', 'status_purpose', 'ref_id', 'book_com', 'ins_com', 'ek_com', 'total' )); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function reference_details($id) { $reference = \App\Reference::with(['referenceIncomes', 'withdraws'])->where('id', $id)->first(); // dd($reference); $sale = Sale::where('reference_id', $id)->get(); $incom = \App\ReferenceIncome::where('reference_id', $id)->get(); $total_with = ReferenceWithdraw::where('reference_id', $id)->sum('amount'); $total_bal = \App\ReferenceIncome::where('reference_id', $id)->sum('amount'); $saleD = SaleDetail::get(); $count = 0; foreach ($saleD as $saleD) { if ($saleD->refference_id == $id) $count++; } $total_sale = $count; $due_amount = $total_bal - $total_with; return view('withdraw.reference_details', compact( 'reference', 'total_with', 'total_bal', 'sale', 'total_sale', 'due_amount' )); } public function witd_create($id) { $sale = Sale::where('id', $id)->first(); $mem_id = $sale->member_id; $referenceIn = ReferenceIncome::where('sell_id', $id) ->where('isDelete', 0) ->first(); $referenceIncome = ReferenceIncome::where('sell_id', $id) ->where('isDelete', 0) ->get(); $referenceIncome2 = ReferenceIncome::where('sell_id', $id) ->where('isDelete', 0) ->get(); $referenceIncome3 = ReferenceIncome::where('sell_id', $id) ->where('isDelete', 0) ->get(); $saleDetails = SaleDetail::where('sales_id', $sale->id)->first(); $plot = Plot::where('id', $sale->plot_id)->first(); $block = Block::where('id', $plot->block_id)->first(); $member = Member::where('id', $mem_id)->first(); $reference = \App\Reference::where('id', $member->reference_id)->first(); $company = Account::where('sell_id', $id)->first(); $company_amount = $company->company_log; $company_amount_in = $company->company_log; $total_income = ReferenceIncome::where('sell_id', $id)->sum('amount'); $company_add = Company::latest()->first(); $total_wid = ReferenceWithdraw::where('sell_id', $id)->sum('amount'); $book = BookingAmount::where('sales_id', $sale->id)->get(); return view('withdraw.create', compact( 'referenceIn', 'referenceIncome', 'referenceIncome2', 'referenceIncome3', 'total_income', 'total_wid', 'sale', 'plot', 'block', 'member', 'reference', 'saleDetails', 'company_amount', 'company_amount_in', 'company_add', 'book' )); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $request->validate([ 'amount' => 'required', ]); $wth = new ReferenceWithdraw(); $wth->amount = $request->amount; $wth->reference_id = $request->reference_id; $wth->member_id = $request->member_id; $wth->income_id = $request->id; $wth->sell_id = $request->sell_id; $wth->date = $request->date; //dd($wth); $in = ReferenceIncome::where('id', $wth->income_id)->first(); $total_wid = ReferenceWithdraw::where('sell_id', $request->sell_id)->sum('amount'); $to_details = Account::where('sell_id', $request->sell_id)->first(); $total_paid = $to_details->company_log; if ($in->status == 2) { if (($total_paid) - $wth->amount >= 50000) { if ($wth->amount == ($in->rest_amount)) { $company_am = $total_paid; $reff_log = $wth->amount; $acnt = Account::where('sell_id', $in->sell_id)->first(); //dd($acnt); $pre_ref = $acnt->reference_log; $acnt->company_log = $total_paid - $reff_log; $acnt->reference_log = $reff_log + $pre_ref; $in->isDelete = 1; $in->save(); $acnt->save(); $wth->status_purpose = 2; $wth->save(); $wthDate = ReferenceWithdraw::where('id', $wth->id)->first(); $dateChange = date("Y-m-d", strtotime($wthDate->created_at)); $wthDate->date = $dateChange; $wthDate->save(); $sale = SaleDetail::where('sales_id', $in->sell_id)->first(); $pre_paid = $sale->company_log; $pre_ref = $sale->refference_log; $sale->refference_log = $reff_log + $pre_ref; $sale->company_log = $pre_paid - ($sale->refference_log); $sale->save(); } else if ($wth->amount < ($in->rest_amount)) { $company_am = $total_paid; $reff_log = $wth->amount; $acnt = Account::where('sell_id', $in->sell_id)->first(); //dd($acnt); $pre_ref = $acnt->reference_log; $acnt->company_log = $total_paid - $reff_log; $acnt->reference_log = $reff_log + $pre_ref; $acnt->save(); $wth->status_purpose = 2; $wth->save(); $wthDate = ReferenceWithdraw::where('id', $wth->id)->first(); $dateChange = date("Y-m-d", strtotime($wthDate->created_at)); $wthDate->date = $dateChange; $wthDate->save(); $sale = SaleDetail::where('sales_id', $in->sell_id)->first(); $pre_paid = $sale->company_log; $pre_ref = $sale->refference_log; $sale->refference_log = $reff_log + $pre_ref; $sale->company_log = $pre_paid - ($sale->refference_log); $sale->save(); $in->rest_amount = $in->rest_amount - $wth->amount; $in->save(); } else { Toastr::error('Not sufficient amount ! :)', 'Error'); return redirect()->back(); } } else { Toastr::error('Not sufficient amount ! :)', 'Error'); return redirect()->back(); } } else if ($in->status == 3) { //dd($wth->amount); if (($total_paid) - $wth->amount >= 50000) { $inst = installment::where('id', $in->intall_id)->first(); $ins_id = $inst->id; $in = ReferenceIncome::where('intall_id', $ins_id)->first(); // dd($in->rest_amount); if ($wth->amount == ($in->rest_amount)) { $inst = installment::where('id', $in->intall_id)->first(); $pay = $inst->amount; $paid_am = $in->installment_per_amount; $inst->refference_log = $wth->amount; $ins = $inst->refference_log; $inst->company_log = $pay - $ins; $inst->save(); $acnt = Account::where('sell_id', $in->sell_id)->first(); $pre_ref = $acnt->reference_log; $acnt->company_log = $total_paid - $ins; $acnt->reference_log = $ins + $pre_ref; $acnt->save(); $sale = SaleDetail::where('sales_id', $in->sell_id)->first(); // $pre_com = $sale->company_log; $pre_reff = $sale->refference_log; $sale->refference_log = $wth->amount + $pre_ref; $sale->company_log = $pre_com - ($sale->refference_log); $sale->save(); $wth->status_purpose = 3; $wth->save(); $wthDate = ReferenceWithdraw::where('id', $wth->id)->first(); $dateChange = date("Y-m-d", strtotime($wthDate->created_at)); $wthDate->date = $dateChange; $wthDate->save(); $in->isDelete = 1; $in->save(); } else if ($wth->amount < ($in->rest_amount)) { $inst = installment::where('id', $in->intall_id)->first(); $pay = $in->rest_amount; $paid_am = $in->installment_per_amount; $inst->refference_log = $wth->amount; $ins = $inst->refference_log; $inst->company_log = $pay - $ins; $inst->save(); $acnt = Account::where('sell_id', $in->sell_id)->first(); $pre_ref = $acnt->reference_log; $acnt->company_log = $total_paid - $ins; $acnt->reference_log = $ins + $pre_ref; $acnt->save(); $sale = SaleDetail::where('sales_id', $in->sell_id)->first(); // $pre_com = $sale->company_log; $pre_reff = $sale->refference_log; $sale->refference_log = $wth->amount + $pre_ref; $sale->company_log = $pre_com - ($sale->refference_log); $sale->save(); $wth->status_purpose = 3; $wth->save(); $wthDate = ReferenceWithdraw::where('id', $wth->id)->first(); $dateChange = date("Y-m-d", strtotime($wthDate->created_at)); $wthDate->date = $dateChange; $wthDate->save(); $in->rest_amount = $in->rest_amount - $wth->amount; $in->save(); } else { Toastr::error('Not sufficient amount ! :)', 'Error'); return redirect()->back(); } } else { Toastr::error('Not sufficient amount ! :)', 'Error'); return redirect()->back(); } } else if ($in->status == 1) { if (($total_paid) - $wth->amount >= 50000) { if ($wth->amount == ($in->rest_amount)) { $paid_am = $total_paid; $pay = $in->ekkalin_per_amount; $acnt = Account::where('sell_id', $in->sell_id)->first(); $pre_ref = $acnt->reference_log; $acnt->reference_log = $wth->amount + $pre_ref; $com = $acnt->reference_log; $acnt->company_log = $paid_am - $com; //$acnt->company_log = $paid_am - ($acnt->refference_log); $acnt->save(); $sale = SaleDetail::where('sales_id', $in->sell_id)->first(); $pre_paid = $sale->company_log; $pre_ref = $sale->refference_log; $sale->refference_log = $wth->amount + $pre_ref; $sale->company_log = $pre_paid - ($sale->refference_log); $sale->save(); $wth->status_purpose = 1; $wth->save(); $wthDate = ReferenceWithdraw::where('id', $wth->id)->first(); $dateChange = date("Y-m-d", strtotime($wthDate->created_at)); $wthDate->date = $dateChange; $wthDate->save(); $in->isDelete = 1; $in->save(); } else if ($wth->amount < ($in->rest_amount)) { // $paid_am = $total_paid; $pay = $in->ekkalin_per_amount; $acnt = Account::where('sell_id', $in->sell_id)->first(); $paid_am = $acnt->company_log; $pre_ref = $acnt->reference_log; $acnt->reference_log = $wth->amount + $pre_ref; //dd($paid_am - ($acnt->refference_log)); $com = $acnt->reference_log; $acnt->company_log = $paid_am - $com; $acnt->save(); $sale = SaleDetail::where('sales_id', $in->sell_id)->first(); $pre_paid = $sale->company_log; $pre_ref = $sale->refference_log; $sale->refference_log = $wth->amount + $pre_ref; $sale->company_log = $pre_paid - ($sale->refference_log); $sale->save(); $wth->status_purpose = 1; $wth->save(); $wthDate = ReferenceWithdraw::where('id', $wth->id)->first(); $dateChange = date("Y-m-d", strtotime($wthDate->created_at)); $wthDate->date = $dateChange; $wthDate->save(); $in->rest_amount = $in->rest_amount - $wth->amount; $in->save(); } else { Toastr::error('Not sufficient amount ! :)', 'Error'); return redirect()->back(); } } else { Toastr::error('Not sufficient amount ! :)', 'Error'); return redirect()->back(); } } $ref = \App\Reference::where('id', $request->reference_id)->first(); $to = $ref->mobile; $message = "Dear" . $ref->name . ", You have withdrawn amount of " . $wth->amount . " TK"; event(new SendSMS($to, $message)); $sms = new SmsCounter(); $sms->mobile = $ref->mobile; $sms->sms = $message; $sms->total = 5000; $sms->save(); Toastr::success('Withdraw Created ! :)', 'Success'); return redirect()->route('admin.withdraw.index'); } /** * Display the specified resource. * * @param \App\ReferenceWithdraw $referenceWithdraw * @return \Illuminate\Http\Response */ public function show(ReferenceWithdraw $referenceWithdraw) { // } /** * Show the form for editing the specified resource. * * @param \App\ReferenceWithdraw $referenceWithdraw * @return \Illuminate\Http\Response */ public function edit($id) { $rwth = ReferenceWithdraw::findOrFail($id); return view('withdraw.edit', compact('rwth')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\ReferenceWithdraw $referenceWithdraw * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $rwth = ReferenceWithdraw::findOrFail($id); $rwth->amount = $request->amount; $rwth->save(); Toastr::success('Withdraw Updated ! :)', 'Success'); return redirect()->route('admin.withdraw.index'); } /** * Remove the specified resource from storage. * * @param \App\ReferenceWithdraw $referenceWithdraw * @return \Illuminate\Http\Response */ public function destroy(ReferenceWithdraw $referenceWithdraw) { if ($referenceWithdraw->delete()) { Toastr::success('Withdraw deleted successfully :)', 'Success'); return redirect()->back(); } else { Toastr::error('Something went wrong :(', 'Error'); return redirect()->back(); } } }