Ejemplo n.º 1
0
 public function store(WageRequest $request)
 {
     //        dd($request->input());
     try {
         DB::transaction(function () use($request) {
             $inputs = $request->input();
             foreach ($inputs['selected'] as $employee_id) {
                 $wage = new Wage();
                 $wage->employee_id = $employee_id;
                 $wage->employee_type = $inputs['employee'][$employee_id]['employee_type'];
                 $wage->workspace_id = $inputs['employee'][$employee_id]['workspace_id'];
                 $wage->year = date('Y');
                 $wage->month = $inputs['month'];
                 $wage->salary = $inputs['employee'][$employee_id]['salary'];
                 $wage->extra_hours = $inputs['employee'][$employee_id]['overtime'];
                 $wage->bonus = $inputs['employee'][$employee_id]['bonus'];
                 $wage->cut = $inputs['employee'][$employee_id]['cut'];
                 $wage->net = $inputs['employee'][$employee_id]['net'];
                 $wage->net = $inputs['employee'][$employee_id]['net'];
                 $wage->created_by = Auth::user()->id;
                 $wage->created_by = time();
                 $wage->save();
                 $personalAccount = PersonalAccount::where(['person_id' => $employee_id, 'person_type' => Config::get('common.person_type_employee')])->first();
                 $personalAccount->balance += $inputs['employee'][$employee_id]['net'];
                 //Add
                 $personalAccount->updated_by = Auth::user()->id;
                 $personalAccount->updated_at = time();
                 $personalAccount->save();
             }
         });
     } catch (\Exception $e) {
         Session()->flash('error_message', 'Salary cannot generate. Please Try again.');
         return Redirect::back();
     }
     Session()->flash('flash_message', 'Salary generated successfully.');
     return redirect('wages');
 }
Ejemplo n.º 2
0
 public function update($id, Request $request)
 {
     //        dd($request->input());
     try {
         DB::transaction(function () use($id, $request) {
             $user = Auth::user();
             $time = time();
             $date = strtotime(date('d-m-Y'));
             $balance_type = Config::get('common.balance_type_intermediate');
             $year = CommonHelper::get_current_financial_year();
             $wage = Wage::find($id);
             $clone = clone $wage;
             $wage->wage = $request->wage;
             $wage->paid = $request->paid;
             $wage->due = $request->wage - $request->paid;
             $wage->updated_by = $user->id;
             $wage->updated_at = $time;
             $wage->update();
             if ($clone->paid && !$request->paid) {
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 11000, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance += $clone->paid;
                 //Add Cash
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = GeneralJournal::where('transaction_type', '=', Config::get('common.transaction_type.wage_payment'))->where('reference_id', '=', $id)->where('year', '=', $year)->where('account_code', '=', 11000)->where('workspace_id', '=', $user->workspace_id)->first();
                 $generalJournal->delete();
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 29992, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance -= $clone->paid;
                 //sub Wage Expense
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = GeneralJournal::where('transaction_type', '=', Config::get('common.transaction_type.wage_payment'))->where('reference_id', '=', $id)->where('year', '=', $year)->where('account_code', '=', 29992)->where('workspace_id', '=', $user->workspace_id)->first();
                 $workspaceLedger->delete();
             } elseif (!$clone->paid && $request->paid) {
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 11000, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance -= $request->paid;
                 //Sub Cash
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = GeneralJournal::where('transaction_type', '=', Config::get('common.transaction_type.wage_payment'))->where('reference_id', '=', $id)->where('year', '=', $year)->where('account_code', '=', 11000)->where('workspace_id', '=', $user->workspace_id)->first();
                 $generalJournal->amount += $request->paid;
                 $generalJournal->updated_by = $user->id;
                 $generalJournal->updated_at = $time;
                 $generalJournal->update();
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 29992, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance += $request->paid;
                 //sub Wage Expense
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = GeneralJournal::where('transaction_type', '=', Config::get('common.transaction_type.wage_payment'))->where('reference_id', '=', $id)->where('year', '=', $year)->where('account_code', '=', 29992)->where('workspace_id', '=', $user->workspace_id)->first();
                 $generalJournal->amount += $request->paid;
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
             } elseif ($clone->paid > $request->paid) {
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 11000, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance += $clone->paid - $request->paid;
                 //Add Cash
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = GeneralJournal::where('transaction_type', '=', Config::get('common.transaction_type.wage_payment'))->where('reference_id', '=', $id)->where('year', '=', $year)->where('account_code', '=', 11000)->where('workspace_id', '=', $user->workspace_id)->first();
                 $generalJournal->amount -= $clone->paid - $request->paid;
                 $generalJournal->updated_by = $user->id;
                 $generalJournal->updated_at = $time;
                 $generalJournal->update();
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 29992, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance -= $clone->paid - $request->paid;
                 //sub Wage Expense
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = GeneralJournal::where('transaction_type', '=', Config::get('common.transaction_type.wage_payment'))->where('reference_id', '=', $id)->where('year', '=', $year)->where('account_code', '=', 29992)->where('workspace_id', '=', $user->workspace_id)->first();
                 $generalJournal->amount -= $clone->paid - $request->paid;
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
             } elseif ($clone->paid < $request->paid) {
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 11000, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance -= $request->paid - $clone->paid;
                 //Sub Cash
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = GeneralJournal::where('transaction_type', '=', Config::get('common.transaction_type.wage_payment'))->where('reference_id', '=', $id)->where('year', '=', $year)->where('account_code', '=', 11000)->where('workspace_id', '=', $user->workspace_id)->first();
                 $generalJournal->amount += $request->paid - $clone->paid;
                 $generalJournal->updated_by = $user->id;
                 $generalJournal->updated_at = $time;
                 $generalJournal->update();
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 29992, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance += $request->paid - $clone->paid;
                 //sub Wage Expense
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = GeneralJournal::where('transaction_type', '=', Config::get('common.transaction_type.wage_payment'))->where('reference_id', '=', $id)->where('year', '=', $year)->where('account_code', '=', 29992)->where('workspace_id', '=', $user->workspace_id)->first();
                 $generalJournal->amount += $request->paid - $clone->paid;
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
             }
             $due = $request->wage - $request->paid;
             if (!$clone->due && $due) {
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 43000, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance += $due;
                 //Add wage payable
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = new GeneralJournal();
                 $generalJournal->date = $date;
                 $generalJournal->transaction_type = Config::get('common.transaction_type.wage_payment');
                 $generalJournal->reference_id = $wage->id;
                 $generalJournal->year = $year;
                 $generalJournal->account_code = 43000;
                 $generalJournal->workspace_id = $user->workspace_id;
                 $generalJournal->amount = $due;
                 $generalJournal->dr_cr_indicator = Config::get('common.debit_credit_indicator.credit');
                 $generalJournal->created_by = $user->id;
                 $generalJournal->created_at = $time;
                 $generalJournal->save();
                 $personal = PersonalAccount::where('person_id', '=', $clone->employee_id)->where('person_type', '=', Config::get('common.person_type_employee'))->first();
                 $personal->balance += $due;
                 $personal->updated_by = $user->id;
                 $personal->updated_at = $time;
                 $personal->update();
             } elseif ($clone->due && !$due) {
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 43000, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance -= $clone->due;
                 //sub wage payable
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = GeneralJournal::where('transaction_type', '=', Config::get('common.transaction_type.wage_payment'))->where('reference_id', '=', $id)->where('year', '=', $year)->where('account_code', '=', 43000)->where('workspace_id', '=', $user->workspace_id)->first();
                 $workspaceLedger->delete();
                 $personal = PersonalAccount::where('person_id', '=', $clone->employee_id)->where('person_type', '=', Config::get('common.person_type_employee'))->first();
                 $personal->balance -= $clone->due - $due;
                 $personal->updated_by = $user->id;
                 $personal->updated_at = $time;
                 $personal->update();
             } elseif ($clone->due > $due) {
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 43000, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance -= $clone->due - $due;
                 //sub wage payable
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = GeneralJournal::where('transaction_type', '=', Config::get('common.transaction_type.wage_payment'))->where('reference_id', '=', $id)->where('year', '=', $year)->where('account_code', '=', 43000)->where('workspace_id', '=', $user->workspace_id)->first();
                 $generalJournal->amount -= $clone->due - $due;
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $personal = PersonalAccount::where('person_id', '=', $clone->employee_id)->where('person_type', '=', Config::get('common.person_type_employee'))->first();
                 $personal->balance -= $clone->due - $due;
                 $personal->updated_by = $user->id;
                 $personal->updated_at = $time;
                 $personal->update();
             } elseif ($clone->due < $due) {
                 $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 43000, 'balance_type' => $balance_type, 'year' => $year])->first();
                 $workspaceLedger->balance += $due - $clone->due;
                 //Add wage payable
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $generalJournal = GeneralJournal::where('transaction_type', '=', Config::get('common.transaction_type.wage_payment'))->where('reference_id', '=', $id)->where('year', '=', $year)->where('account_code', '=', 43000)->where('workspace_id', '=', $user->workspace_id)->first();
                 $generalJournal->amount += $due - $clone->due;
                 $workspaceLedger->updated_by = $user->id;
                 $workspaceLedger->updated_at = $time;
                 $workspaceLedger->update();
                 $personal = PersonalAccount::where('person_id', '=', $clone->employee_id)->where('person_type', '=', Config::get('common.person_type_employee'))->first();
                 $personal->balance += $due - $clone->due;
                 $personal->updated_by = $user->id;
                 $personal->updated_at = $time;
                 $personal->update();
             }
         });
     } catch (\Exception $e) {
         dd($e);
         Session()->flash('error_message', 'Wage payment update can not successfully. Please Try again.');
         return Redirect::back();
     }
     Session()->flash('flash_message', 'Successfully Updated.');
     return redirect('daily_wage_payment');
 }
Ejemplo n.º 3
0
 public function getDailyWorkerList(Request $request)
 {
     $current_date = strtotime($request->payment_date);
     $payments = Wage::where('employee_type', '=', Config::get('common.employee_type.Daily Worker'))->where('payment_date', '=', $current_date)->get(['employee_id'])->toArray();
     $emp = array_values(array_column($payments, 'employee_id'));
     $employees = Employee::where('employee_type', '=', Config::get('common.employee_type.Daily Worker'))->whereNotIn('id', $emp)->with('designation')->get();
     $ajaxView = view('payrolls.dailyWagePayment.ajaxView')->with(compact('employees'))->render();
     return response()->json($ajaxView);
 }