Exemplo n.º 1
0
 /**
  * @param Organization $organization
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function organizationPage(Organization $organization)
 {
     $workers = null;
     $snapshot = Snapshot::where('organization_id', $organization->id)->orderBy('id', 'desc')->first();
     if (!is_null($snapshot)) {
         $workers = Worker::where('snapshot_id', $snapshot->id)->get();
         $workers = Worker::structure($workers);
     }
     $this->getCounters();
     return view('site.organization', ['organization' => $organization, 'snapshot' => $snapshot, 'workers' => $workers, 'fixed' => true]);
 }
Exemplo n.º 2
0
                foreach ($by as $action => $value) {
                    // Check if workers is empty.
                    if (empty($workers)) {
                        $workers = Worker::where($filter, $action, $value);
                    } else {
                        $workers = $workers->where($filter, $action, $value);
                    }
                }
            }
        } else {
            if ($logic == 'or') {
                foreach ($rule as $filter => $by) {
                    foreach ($by as $action => $value) {
                        // Check if workers is empty.
                        if (empty($workers)) {
                            $workers = Worker::where($filter, $action, $value);
                        } else {
                            $workers = $workers->orWhere($filter, $action, $value);
                        }
                    }
                }
            }
        }
        $workers = $workers->get();
    }
} else {
    $workers = Worker::all();
}
?>
@if(isset($id) && $id != '')
	<select id="{{ $id }}">
Exemplo n.º 3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Get all workers that haven't been fired.
     $workers = Worker::where('Fired', '=', false)->get();
     foreach ($workers as $worker) {
         // First let's check if it has a long term loan active.
         $currentMonth = date('Y-m');
         if ($worker->Loan > 0) {
             // Let's check if we have gotten this months loan payment.
             $loans = WorkerLoan::where('WorkerId', '=', $worker->Id)->where('Date', '>', $currentMonth . '-01')->where('Type', '=', 2)->get();
             if (count($loans) == 0) {
                 // Charge worker for loan.
                 $charge = $worker->Loan / $worker->Months;
                 $loan = WorkerLoan::create(array('Date' => date('Y-m-d'), 'Amount' => $charge, 'Processed' => false, 'State' => 2, 'Type' => 2, 'WorkerId' => $worker->Id));
                 $worker->Loan -= $charge;
                 $worker->Months--;
                 $worker->save();
             }
         }
         // Now let's check if we have gotten this month's insurance fee.
         $loans = WorkerLoan::where('WorkerId', '=', $worker->Id)->where('Date', '>', $currentMonth . '-01')->where('Type', '=', 3)->get();
         if (count($loans) == 0) {
             // Charge worker for loan.
             $charge = $worker->Insurance - $worker->Patron;
             if ($charge > 0) {
                 $loan = WorkerLoan::create(array('Date' => date('Y-m-d'), 'Amount' => $charge, 'Processed' => false, 'State' => 2, 'Type' => 3, 'WorkerId' => $worker->Id));
             }
         }
         // Get workers days.
         $days = WorkerSalary::where('SystemProcess', '=', false)->where('WorkerId', '=', $worker->Id)->get();
         // Now let's check if we need to add a bonus to the worker.
         if ($worker->BonusPercentage > 0) {
             switch ($worker->BonusSource) {
                 case 'production':
                     foreach ($days as $day) {
                         if ($day->DayType != 3 && ($day->DayType < 5 || $day->DayType == 7)) {
                             // If worker is on general production then let's get what was produced and the price of what was produced.
                             $produced = ProductionStage::where('Date', '>', $day->Date . ' 00:00:01')->get();
                             $totalProduced = 0;
                             $pIds = array();
                             foreach ($produced as $p) {
                                 // Check if we have already checked this product.
                                 if (!in_array($p->ProductionId, $pIds)) {
                                     array_push($pIds, $p->ProductionId);
                                     // Check if product is finished.
                                     $product = Production::find($p->ProductionId);
                                     if ($product->Stage == $product->maxStage()) {
                                         $finalProduct = Stock::where('Code', '=', $product->Code)->where('BranchId', '=', $product->BranchId)->first();
                                         $totalProduced += $finalProduct->Price;
                                     }
                                 }
                             }
                             $day->Bonus += $totalProduced * ($worker->BonusPercentage / 100);
                         }
                         // Add insurance Patron Value for the day.
                         // TODO: I should check how many days are in this month,
                         $day->Insurance = $worker->Patron / 30;
                         $day->save();
                     }
                     break;
                 case 'productionsingle':
                     foreach ($days as $day) {
                         if ($day->DayType != 3 && ($day->DayType < 5 || $day->DayType == 7)) {
                             // If worker is on single production then let's get what he produced and the price of what was produced.
                             $produced = ProductionStage::where('Date', '>', $day->Date . ' 00:00:01')->where('WorkerId', '=', $worker->Id)->get();
                             $totalProduced = 0;
                             $pIds = array();
                             foreach ($produced as $p) {
                                 // Check if we have already checked this product.
                                 if (!in_array($p->ProductionId, $pIds)) {
                                     array_push($pIds, $p->ProductionId);
                                     // Check if product is finished.
                                     $product = Production::find($p->ProductionId);
                                     if ($product->Stage == $product->maxStage()) {
                                         $finalProduct = Stock::where('Code', '=', $product->Code)->where('BranchId', '=', $product->BranchId)->first();
                                         $totalProduced += $finalProduct->Price;
                                     }
                                 }
                             }
                             $day->Bonus += $totalProduced * ($worker->BonusPercentage / 100);
                         }
                         // Add insurance Patron Value for the day.
                         // TODO: I should check how many days are in this month,
                         $day->Insurance = $worker->Patron / 30;
                         $day->save();
                     }
                     break;
                 case 'sales':
                     foreach ($days as $day) {
                         if ($day->DayType != 3 && ($day->DayType < 5 || $day->DayType == 7)) {
                             // If worker is on general sales then let's get all sales.
                             $sales = Sale::where('Created', '>=', $day->Date . ' 00:00:01')->where('Created', '<=', $day->Date . ' 23:59:59')->where('BranchId', '=', $worker->BranchId)->get();
                             $totalSales = 0;
                             foreach ($sales as $sale) {
                                 $totalSales += $sale->Value;
                             }
                             $day->Bonus += $totalSales * ($worker->BonusPercentage / 100);
                         }
                         // Add insurance Patron Value for the day.
                         // TODO: I should check how many days are in this month,
                         $day->Insurance = $worker->Patron / 30;
                         $day->save();
                     }
                     break;
                 case 'salessingle':
                     foreach ($days as $day) {
                         if ($day->DayType != 3 && ($day->DayType < 5 || $day->DayType == 7)) {
                             // If worker is on general sales then let's get all sales.
                             $sales = Sale::where('Created', '>=', $day->Date . ' 00:00:01')->where('Created', '<=', $day->Date . ' 23:59:59')->where('WorkerId', '=', $worker->Id)->get();
                             $totalSales = 0;
                             foreach ($sales as $sale) {
                                 $totalSales += $sale->Value;
                             }
                             $day->Bonus += $totalSales * ($worker->BonusPercentage / 100);
                         }
                         // Add insurance Patron Value for the day.
                         // TODO: I should check how many days are in this month,
                         $day->Insurance = $worker->Patron / 30;
                         $day->save();
                     }
                     break;
             }
         }
     }
     // Get all days that have not been processed and set them as being processed.
     $allDays = WorkerSalary::where('SystemProcess', '=', false)->get();
     foreach ($allDays as $day) {
         $day->SystemProcess = true;
         $day->save();
     }
 }
 public function postFilter()
 {
     $d = Worker::where('department_id', 2)->get();
     return $d;
 }
Exemplo n.º 5
0
 /**
  * Удаление организации
  * @param Organization $organization
  * @return \Illuminate\Http\RedirectResponse
  * @throws \Exception
  */
 public function delete(Organization $organization)
 {
     // удаляем подразделения
     Organization::where('parent_id', $organization->id)->delete();
     // удаляем сотрудников
     Worker::where('organization_id', $organization->id)->delete();
     Snapshot::where('organization_id', $organization->id)->delete();
     // удаляем саму организацию
     $organization->delete();
     return redirect()->route('admin::organization');
 }
Exemplo n.º 6
0
 /**
  * Редактирование названия отдела/подотдела
  * @param Request $request
  */
 public function updateDepartment(Request $request)
 {
     $this->validate($request, ['snapshot' => 'required|numeric', 'field' => 'in:department,subDepartment', 'name' => 'required', 'newName' => 'required']);
     $field = $request->get('field');
     Worker::where('snapshot_id', $request->get('snapshot'))->where($field, $request->get('name'))->update([$field => $request->get('newName')]);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $moneyPerMonth = DB::select('CALL department_money_per_month_statistic(?)', array($id));
     $packagesCountStatistic = DB::select('CALL sended_received_stats(?)', array($id));
     $best5Clients = DB::select('CALL best_5_clients(?)', array($id));
     $bestWorker = Worker::where('department_id', $id)->orderBy('packages_count', 'desc')->take(1)->get();
     $monthsSet = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
     $values = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
     foreach ($moneyPerMonth as $stat) {
         $values[array_search($stat->month, $monthsSet)] = $stat->value;
     }
     #return json_encode($months);
     $dept = Department::find($id);
     $workers = $dept->workers();
     $objMoney = json_encode($values);
     $obMonth = json_encode($monthsSet);
     $params = ['department' => $dept, 'workers' => $workers, 'months' => $obMonth, 'money' => $objMoney, 'category' => 4, 'packagesStatistic' => array_shift($packagesCountStatistic), 'moneyPerMonth' => $moneyPerMonth, 'bestWorkers' => $bestWorker, 'bestClients' => $best5Clients, 'category' => 1];
     return View::make('department.detail', $params);
 }
Exemplo n.º 8
0
<?php

use App\Branch;
use App\User;
use App\Worker;
use App\WorkerPayment;
// Get all the payments.
$payments = array();
// Get the worker's branch Id.
$worker = Worker::where('Cedula', '=', $worker)->first();
if ($worker != null) {
    $branchId = $worker->BranchId;
    $payments = WorkerPayment::where('WorkerId', '=', $worker->Id)->get();
}
?>
@foreach($payments as $payment)
	<tr id='payment-{{ $payment->Id }}'><td>{{ $payment->Date }}</td><td>{{ $payment->WorkedDays }}</td><td>{{ $payment->VacationDays }}</td><td>{{ $payment->TotalBasic }}</td><td>{{ $payment->TotalBonus }}</td><td>{{ $payment->TotalAguinaldo }}</td><td>{{ $payment->TotalLoan }}</td><td>{{ $payment->TotalInsurance }}</td></tr>
@endforeach
Exemplo n.º 9
0
 /**
  * This function reloads the salary of the current staff member.
  */
 public function reloadSalary()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('staffId' => 'required'));
     if ($validator->fails()) {
         return response()->json(['error' => 'La identificacion es necesaria!']);
     }
     // Check that user is part of authorized staff.
     if (Auth::user()->Type != 1) {
         // If they are unauthorized no point in returning anything.
         return response()->json(array());
     }
     // Get the worker of given Id.
     $response = array();
     $worker = Worker::where('Cedula', '=', Input::get('staffId'))->first();
     if ($worker) {
         // Store the worker's general information.
         $response['totalInsurance'] = $worker->Insurance;
         // Now get the worker's salary.
         $days = $worker->salary;
         // Store information in response array.
         $response['totalSalary'] = 0;
         $response['salary'] = array();
         foreach ($days as $day) {
             $response['totalSalary'] += $day->Basic + $day->Bono;
             array_push($response['salary'], array('date' => $day->Date, 'basic' => $day->Basic, 'bono' => $day->Bonus));
         }
         // Now get the worker's loans.
         $loans = $worker->loans;
         // Store information in response array.
         $response['totalLoans'] = 0;
         $response['loans'] = array();
         foreach ($loans as $loan) {
             // If loan has been approved deduct from salary.
             if ($loan->State == 2) {
                 $response['totalLoans'] += $loan->Amount;
             }
             // Define the loan state.
             $state = 'Solicitado';
             switch ($loan->State) {
                 // State 1 not necessary.
                 case 2:
                     $state = 'Aprobado';
                     break;
                 case 3:
                     $state = 'Rechazado';
                     break;
             }
             array_push($response['loans'], array('date' => $loan->Date, 'loan' => $loan->Amount, 'state' => $state));
         }
         // Calculate how much worker will earn.
         $response['totalEarned'] = $response['totalSalary'] - $response['totalLoans'] - $response['totalInsurance'];
         // Return response.
         return response()->json($response);
     } else {
         return response()->json(['error' => 'Trabajador inexistente']);
     }
 }
Exemplo n.º 10
0
 public function staffPayAguinaldo()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('formData' => 'required', 'worker' => 'required'));
     if ($validator->fails()) {
         return response()->json(['error' => 'Informacion incompleta!']);
     }
     // Check that user is part of authorized staff.
     if (Auth::user()->Type != 1) {
         // If they are unauthorized no point in returning anything.
         return response()->json(array());
     }
     // Get the worker.
     $worker = Worker::where('Cedula', '=', Input::get('worker'))->first();
     $branchId = $worker->BranchId;
     $user = User::where('TypeId', '=', $worker->Id)->where('Type', '=', 1)->first();
     // Now get the cashbox.
     $cashbox = Cashbox::where('BranchId', '=', $branchId)->where('Close', '=', null)->where('UserId', '=', Auth::user()->Id)->first();
     if ($cashbox == null && Input::get('formData')['ppsPaymentSource'] == 1) {
         $response['state'] = 'Error';
         $response['error'] = 'No hay una caja abierta de la cual retirar los fondos!';
         return response()->json($response);
     }
     // Get the salary of the worker and his loans.
     $salaries = WorkerSalary::where('WorkerId', '=', $worker->Id)->where('AguinaldoPaid', '=', false)->get();
     $loans = WorkerLoan::where('WorkerId', '=', $worker->Id)->where('Processed', '=', false)->get();
     $totalAguinaldo = 0;
     $totalLoan = 0;
     $workedDays = 0;
     foreach ($salaries as $salary) {
         if ($salary->DayType != 3 || $salary->DayType != 5) {
             $totalAguinaldo += $worker->Basic * 0.2465;
             $workedDays++;
         }
         $salary->AguinaldoPaid = true;
         $salary->save();
     }
     foreach ($loans as $loan) {
         $totalLoan += $loan->Amount;
         $loan->Processed = true;
         $loan->save();
     }
     // Create workerpayment.
     $payment = WorkerPayment::create(array('WorkerId' => $worker->Id, 'Date' => date('Y-m-d'), 'WorkedDays' => $workedDays, 'VacationDays' => $worker->Vacation, 'TotalBasic' => 0, 'TotalBonus' => 0, 'TotalLoan' => $totalLoan, 'TotalInsurance' => 0, 'TotalAguinaldo' => $totalAguinaldo));
     if (Input::get('formData')['ppaPaymentSource'] == 1) {
         $transaction = CashboxTransaction::create(array('CashboxId' => $cashbox->Id, 'DateTime' => date('Y-m-d H:i:s'), 'Type' => 3, 'Amount' => $totalAguinaldo - $totalLoan, 'Reason' => 'Pago aguinaldo de ' . $worker->Name));
     } else {
         if (Input::get('formData')['ppsPaymentSource'] == 2) {
             // TODO: Add Bank Account transaction information.
         }
     }
     $worker->save();
     $response['state'] = 'Success';
     $response['paymentInfo'] = $payment;
     $response['worker'] = $worker;
     return response()->json($response);
 }
Exemplo n.º 11
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     return Worker::where('id', $id)->delete();
 }
Exemplo n.º 12
0
 /**
  * @param Worker $worker
  * @return mixed
  */
 public function workerPage(Worker $worker)
 {
     $this->getCounters();
     $sameWorkers = Worker::where('fio', $worker->fio)->where('id', '<>', $worker->id)->with('organization')->get();
     return view('site.worker', compact('worker', 'sameWorkers'));
 }