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 store(WageRequest $request)
 {
     try {
         DB::transaction(function () use($request) {
             //                dd($request->input());
             $inputs = $request->input();
             $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();
             foreach ($inputs['selected'] as $key => $employee_id) {
                 $wage = new Wage();
                 $wage->employee_id = $employee_id;
                 $wage->employee_type = Config::get('common.employee_type.Daily Worker');
                 $wage->workspace_id = $inputs['employee'][$employee_id]['workspace_id'];
                 $wage->payment_date = strtotime($inputs['payment_date']);
                 $wage->wage = $inputs['employee'][$employee_id]['wage'];
                 $wage->paid = $inputs['employee'][$employee_id]['pay_now'];
                 $wage->due = $due = $inputs['employee'][$employee_id]['wage'] - $inputs['employee'][$employee_id]['pay_now'];
                 $wage->created_by = $user->id;
                 $wage->created_at = $time;
                 $wage->save();
                 if ($inputs['employee'][$employee_id]['pay_now']) {
                     $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 11000, 'balance_type' => $balance_type, 'year' => $year])->first();
                     $workspaceLedger->balance -= $inputs['employee'][$employee_id]['pay_now'];
                     //Sub Cash
                     $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 = 11000;
                     $generalJournal->workspace_id = $user->workspace_id;
                     $generalJournal->amount = $inputs['employee'][$employee_id]['pay_now'];
                     $generalJournal->dr_cr_indicator = Config::get('common.debit_credit_indicator.credit');
                     $generalJournal->created_by = $user->id;
                     $generalJournal->created_at = $time;
                     $generalJournal->save();
                     $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 29992, 'balance_type' => $balance_type, 'year' => $year])->first();
                     $workspaceLedger->balance += $inputs['employee'][$employee_id]['pay_now'];
                     //add Wage Expense
                     $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 = 29992;
                     $generalJournal->workspace_id = $user->workspace_id;
                     $generalJournal->amount = $inputs['employee'][$employee_id]['pay_now'];
                     $generalJournal->dr_cr_indicator = Config::get('common.debit_credit_indicator.debit');
                     $generalJournal->created_by = $user->id;
                     $generalJournal->created_at = $time;
                     $generalJournal->save();
                 }
                 if ($due > 0) {
                     $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', '=', $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();
                 }
             }
         });
     } catch (\Exception $e) {
         dd($e);
         Session()->flash('error_message', 'Wage payment can not successfully. Please Try again.');
         return Redirect::back();
     }
     Session()->flash('flash_message', 'Successfully paid.');
     return redirect('daily_wage_payment');
 }