/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $loan = Loan::find($id); $loan->name = $request->name; $loan->minimum_amount = $request->minimum_amount; $loan->maximum_amount = $request->maximum_amount; $loan->min_return_time = $request->min_return_time; $loan->max_return_time = $request->max_return_time; $loan->profit_percent = $request->profit_percent; $loan->comments = $request->comments; $loan->collateral = $request->collateral; $loan->created_by = 1; if (!$loan->save()) { return "failed"; } else { return "success"; } }
/** * View employees with loan * * @param int $id * @return Response */ public function deleteLoan($id, $loanId) { Labor::where('employee_no', $id)->first()->LoanMonths()->where('loan_id', $loanId)->delete(); Loan::find($loanId)->delete(); flash()->success('Successfully deleted.'); return redirect('employees/' . $id . '/edit'); }
public function filterAjaxAttendance() { $summary = []; $filterComplete = 'false'; $skip = intval(\Input::get('skip')); $take = intval(\Input::get('take')); $viewDeleted = \Input::get('view_deleted'); $dateFrom = \Input::get('date_from'); $dateTo = \Input::get('date_to'); $employee_no = \Input::get('employee_no'); $site = \Input::get('site_list'); $trade = \Input::get('trade_list'); $dateFromCarbon = Carbon::parse($dateFrom); $dateToCarbon = Carbon::parse($dateTo); $sites = Site::where('id', '>', 1)->get()->lists('code', 'id')->toArray(); $monthFrom = $dateFromCarbon->format('n'); $monthTo = $dateToCarbon->format('n'); $yearFrom = $dateFromCarbon->format('Y'); $yearTo = $dateToCarbon->format('Y'); $dFrom = Carbon::parse($dateFrom); $dTo = Carbon::parse($dateTo); $total_days = 0; //dd($dTo->format('n-Y')); if ($dateFromCarbon->format('n-Y') != $dTo->format('n-Y')) { do { $total_days += $this->daysCount(intval($dFrom->format('n')), intval($dFrom->format('Y'))); $dFrom->addMonth(); } while ($dFrom->format('n-Y') != $dTo->format('n-Y')); $total_days += $this->daysCount(intval($dTo->format('n')), intval($dTo->format('Y'))); } else { $total_days += $this->daysCount(intval($dTo->format('n')), intval($dTo->format('Y'))); } $showAbsent = \Input::get('view_absent') == 1 ? true : false; $labors = Labor::where('deleted', 'false')->orderBy('employee_no')->skip($skip)->take($take)->get(); //if deleted employees included if ($viewDeleted) { $labors = Labor::orderBy('employee_no')->skip($skip)->take($take)->get(); } //if filter by employee number if (!empty($employee_no) && empty($site) && empty($trade)) { $labors = Labor::where('employee_no', $employee_no)->where('deleted', 'false')->orderBy('employee_no')->skip($skip)->take($take)->get(); if ($viewDeleted) { $labors = Labor::where('employee_no', $employee_no)->orderBy('employee_no')->skip($skip)->take($take)->get(); } } elseif (empty($employee_no) && !empty($site) && empty($trade)) { $labors = Labor::where('deleted', 'false')->where('site_id', $site[0]); if ($viewDeleted) { $labors = Labor::where('site_id', $site[0]); } if (count($site) > 1) { foreach ($site as $s) { $labors = $labors->orWhere('site_id', $s); } } $labors = $labors->orderBy('employee_no')->skip($skip)->take($take)->get(); } elseif (empty($employee_no) && empty($site) && !empty($trade)) { $labors = Labor::where('deleted', 'false')->where('trade_id', $trade[0]); if ($viewDeleted) { $labors = Labor::where('trade_id', $trade[0]); } if (count($trade) > 1) { foreach ($trade as $t) { $labors = $labors->orWhere('trade_id', $t); } } $labors = $labors->orderBy('employee_no')->skip($skip)->take($take)->get(); } elseif (!empty($employee_no) && !empty($site) && empty($trade)) { $labors = Labor::where('deleted', 'false')->where('employee_no', $employee_no); if ($viewDeleted) { $labors = Labor::where('employee_no', $employee_no); } $labors = $labors->where(function ($query) use($site) { foreach ($site as $s) { $query->orWhere('site_id', $s); } }); $labors = $labors->orderBy('employee_no')->skip($skip)->take($take)->get(); } elseif (!empty($employee_no) && empty($site) && !empty($trade)) { $labors = Labor::where('deleted', 'false')->where('employee_no', $employee_no); if ($viewDeleted) { $labors = Labor::where('employee_no', $employee_no); } $labors = $labors->where(function ($query) use($trade) { foreach ($trade as $t) { $query->orWhere('trade_id', $t); } }); $labors = $labors->orderBy('employee_no')->skip($skip)->take($take)->get(); } elseif (empty($employee_no) && !empty($site) && !empty($trade)) { $labors = Labor::where('deleted', 'false'); if ($viewDeleted) { $labors = Labor::all(); } $labors = $labors->where(function ($query) use($site) { foreach ($site as $s) { $query->orWhere('site_id', $s); } }); $labors = $labors->where(function ($query) use($trade) { foreach ($trade as $t) { $query->orWhere('trade_id', $t); } }); $labors = $labors->orderBy('employee_no')->skip($skip)->take($take)->get(); } elseif (!empty($employee_no) && !empty($site) && !empty($trade)) { $labors = Labor::where('deleted', 'false')->where('employee_no', $employee_no); if ($viewDeleted) { $labors = Labor::where('employee_no', $employee_no); } $labors = $labors->where(function ($query) use($site) { foreach ($site as $s) { $query->orWhere('site_id', $s); } }); $labors = $labors->where(function ($query) use($trade) { foreach ($trade as $t) { $query->orWhere('trade_id', $t); } }); $labors = $labors->orderBy('employee_no')->skip($skip)->take($take)->get(); } $filterComplete = empty($labors->toArray()) ? 'true' : 'false'; $labor_att = []; $total = []; $salary = []; $trades = []; foreach ($labors as $labor) { $att_count = 0; $ot_count = 0.0; $bot_count = 0.0; $deduction = 0; //$loanEntry = $labor->loanMonths()->where('deduction_month',Carbon::now()->format('Ym'))->first(); foreach ($labor->loanMonths()->get() as $loanMonth) { if ($loanMonth->deduction_date->format('Ym') == Carbon::now()->format('Ym')) { $deduction = intval(Loan::find($loanMonth->loan_id)->deduction); } } $trades[] = $labor->trade->name; for ($dateFromCarbon; $dateFromCarbon <= $dateToCarbon; $dateFromCarbon->addDay()) { $att_entry = $labor->attendance()->where('att_date', $dateFromCarbon->format('Y-m-d H:i:s'))->first(); if (!is_null($att_entry)) { if ($showAbsent && $att_entry->pivot->attended == '1') { $labor_att[$labor->employee_no]['attended'][$dateFromCarbon->format('Y-m-d')] = '—'; } else { $labor_att[$labor->employee_no]['attended'][$dateFromCarbon->format('Y-m-d')] = $att_entry->pivot->attended; $att_count += intval($labor_att[$labor->employee_no]['attended'][$dateFromCarbon->format('Y-m-d')]); } } else { $labor_att[$labor->employee_no]['attended'][$dateFromCarbon->format('Y-m-d')] = '—'; } if (!is_null($att_entry) && $att_entry->pivot->attended == '1') { if ($showAbsent) { $labor_att[$labor->employee_no]['ot'][$dateFromCarbon->format('Y-m-d')] = '—'; $labor_att[$labor->employee_no]['bot'][$dateFromCarbon->format('Y-m-d')] = '—'; $labor_att[$labor->employee_no]['site'][$dateFromCarbon->format('Y-m-d')] = '—'; } else { $labor_att[$labor->employee_no]['ot'][$dateFromCarbon->format('Y-m-d')] = $att_entry->pivot->ot; $labor_att[$labor->employee_no]['bot'][$dateFromCarbon->format('Y-m-d')] = $att_entry->pivot->bot; $labor_att[$labor->employee_no]['site'][$dateFromCarbon->format('Y-m-d')] = $att_entry->pivot->site; $ot_count += floatval($att_entry->pivot->ot); $bot_count += intval($att_entry->pivot->bot); } } elseif (!is_null($att_entry) && $att_entry->pivot->attended == '0') { if ($showAbsent) { $labor_att[$labor->employee_no]['attended'][$dateFromCarbon->format('Y-m-d')] = $att_entry->pivot->attended; $labor_att[$labor->employee_no]['ot'][$dateFromCarbon->format('Y-m-d')] = $att_entry->pivot->ot; $labor_att[$labor->employee_no]['bot'][$dateFromCarbon->format('Y-m-d')] = $att_entry->pivot->bot; $labor_att[$labor->employee_no]['site'][$dateFromCarbon->format('Y-m-d')] = $att_entry->pivot->site; } else { $labor_att[$labor->employee_no]['attended'][$dateFromCarbon->format('Y-m-d')] = '—'; $labor_att[$labor->employee_no]['ot'][$dateFromCarbon->format('Y-m-d')] = '—'; $labor_att[$labor->employee_no]['bot'][$dateFromCarbon->format('Y-m-d')] = '—'; $labor_att[$labor->employee_no]['site'][$dateFromCarbon->format('Y-m-d')] = '—'; } } elseif (is_null($att_entry)) { $labor_att[$labor->employee_no]['attended'][$dateFromCarbon->format('Y-m-d')] = '—'; $labor_att[$labor->employee_no]['ot'][$dateFromCarbon->format('Y-m-d')] = '—'; $labor_att[$labor->employee_no]['bot'][$dateFromCarbon->format('Y-m-d')] = '—'; $labor_att[$labor->employee_no]['site'][$dateFromCarbon->format('Y-m-d')] = '—'; } $total[$labor->employee_no]['attended'] = round($att_count, 2); $total[$labor->employee_no]['ot'] = $ot_count; $total[$labor->employee_no]['bot'] = $bot_count; //------total salary computation $basic_salary = intval($labor->basic_salary); $allowance = intval($labor->allowance); $gross = intval($labor->basic_salary) + intval($labor->allowance); $salary[$labor->employee_no]['attended'] = round($gross / $total_days * $att_count, 2); $salary[$labor->employee_no]['ot'] = round($basic_salary / $total_days / 8 * 1.25 * $ot_count, 2); $salary[$labor->employee_no]['bot'] = round($basic_salary / $total_days / 8 * 1.25 * $bot_count, 2); $salary[$labor->employee_no]['total'] = $salary[$labor->employee_no]['attended'] + $salary[$labor->employee_no]['ot'] + $salary[$labor->employee_no]['bot'] - $deduction; } $dateFromCarbon = Carbon::parse($dateFrom); } /* $summary = []; if(\Input::get('summary')){ $summary['total_days'] = $total_days; if(!empty($site)){ $sites = Site::all()->lists('name')->toArray(); foreach($sites as $site){ $labors->where } } else{ } } */ $response = ['summary' => $summary, 'trade' => $trades, 'salary' => $salary, 'total' => $total, 'labor_att' => $labor_att, 'labor' => $labors, 'dateFrom' => $dateFromCarbon->format('Y-m-d'), 'dateTo' => $dateToCarbon->format('Y-m-d'), 'filterComplete' => $filterComplete]; echo json_encode($response); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $loan = Loan::find($id); return view('admin.loan.create', compact($loan)); }