Esempio n. 1
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();
     }
 }
Esempio n. 2
0
 /**
  * Function that gets order Information.
  *
  * @return Response
  */
 public function addReturn()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('code' => 'required', 'worker' => 'required'));
     if ($validator->fails()) {
         return response()->json(['error' => 'El codigo del ataud es necesario!']);
     }
     // 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 Item in question.
     $item = Production::find(Input::get('code'));
     if (!$item) {
         return response()->json(['error' => 'No existe un ataud con este codigo!']);
     }
     // Make sure item has finished production.
     $maxStage = $item->maxStage();
     if ($item->Stage <= $maxStage) {
         return response()->json(['error' => 'Este ataud no ha salido del proceso de produccion!']);
     }
     // Verify that worker exists and is of correct branch.
     $worker = Worker::find(Input::get('worker'));
     if (!$worker) {
         return response()->json(['error' => 'Este trabajador no existe']);
     }
     if ($worker->BranchId != 2) {
         return response()->json(['error' => 'Este trabajador no es parte de la sucursal correcta!']);
     }
     // Set item as being repaired.
     $item->Stage = 0;
     $item->save();
     // Create Repair Stage for item.
     $itemStage = ProductionStage::create(array('ProductionId' => $item->Id, 'Stage' => 0, 'WorkerId' => $worker->Id, 'Materials' => '{}', 'Date' => date('Y-m-d')));
     // Return information.
     $response['success'] = 'Devolucion hecha exitosamente!';
     return response()->json($response);
 }
Esempio n. 3
0
 /**
  * Function that sets record of specified item as finished.
  *
  * @return Response
  */
 public function finishItemProduction()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('code' => 'required', 'productCode' => 'required|integer'));
     if ($validator->fails()) {
         return response()->json(['error' => 'All fields are required!']);
     }
     // 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 Item in production.
     $item = Production::find(Input::get('productCode'));
     if (!$item) {
         return response()->json(['error' => 'No existe un ataud con este codigo!']);
     }
     // Make sure that item is still in production.
     $maxStage = $item->maxStage();
     if ($item->Stage > $maxStage) {
         return response()->json(['error' => 'Este ataud ya no esta en produccion!']);
     }
     // Now check that item is ready to move to final stage.
     if ($item->Stage != $maxStage && $item->Stage != 0) {
         return response()->json(['error' => 'Este ataud no esta listo para completarse!']);
     }
     // Check that we aren't repairing.
     if ($item->Stage != 0) {
         $itemStage = $item->currentStage();
         // Get current worker of current stage.
         $worker = Worker::find($itemStage->WorkerId);
         // Check that he is working today.
         $salary = $worker->getDateSalary(date('Y-m-d'));
         if (!$salary) {
             return response()->json(['error' => "El trabajador asignado para la etapa {$item->Stage} no sido agregado a asistencia de hoy!"]);
         }
         // Get the value of the bono.
         $expense = $item->currentExpense();
         $salary->Bonus += $expense->Bonus;
         $salary->save();
     }
     // Now update the stage of item.
     $item->Stage = $maxStage + 1;
     $item->save();
     // Now add it to the stock.
     $stock = Stock::where('Code', '=', $item->Code)->where('BranchId', '=', 2)->first();
     // Calculate the cost of it.
     $stages = $item->stages();
     $cost = 0;
     foreach ($stages as $stage) {
         $materials = json_decode($stage->Materials, true);
         foreach ($materials as $material => $quantity) {
             $stockMaterial = Stock::where('Code', '=', $material)->where('BranchId', '=', 2)->first();
             $cost += $stockMaterial->AverageCost * $quantity;
         }
     }
     $expenses = $item->expenses();
     foreach ($expenses as $expense) {
         $cost += $expense->Bonus;
     }
     $stock->AverageCost = ($stock->AverageCost * $stock->Quantity + $cost) / $stock->Quantity + 1;
     $stock->Cost = $cost;
     $stock->Quantity++;
     $stock->save();
     // Inform user.
     return response()->json(['success' => 'Ataud completado exitosamente!']);
 }
Esempio n. 4
0
<?php

use App\User;
use App\Worker;
use App\Branch;
use App\UserLevel;
use App\Notification;
use App\StorageRequest;
use App\Production;
use App\ProductionStage;
use App\Stock;
$currentNotification = Notification::find($notification);
$currentNotification->Seen = true;
$currentNotification->save();
$permissions = json_decode(UserLevel::find(Auth::user()->UserLevel)->Permissions);
$production = Production::find($pId);
$stage = ProductionStage::where('ProductionId', '=', $pId)->where('Stage', '=', $stage)->first();
$worker = Worker::find($stage->WorkerId);
$product = Stock::where('Code', '=', $production->Code)->where('BranchId', '=', $worker->BranchId)->first();
?>
<!DOCTYPE html>
<html lang="es">
    <head>
        <title>Eirene Systema Administrativo</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta charset="UTF-8">
        <meta name="csrf-token" content="{{{ Session::token() }}}">
        <link href="{{ URL::to('/') }}/css/bootstrap.min.css" rel="stylesheet">
        <link href="{{ URL::to('/') }}/css/bootstrap-responsive.min.css" rel="stylesheet">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600"
Esempio n. 5
0
 /**
  * Function that gets the item information with specified code.
  *
  * @return Response
  */
 public function loadStageMaterials()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('code' => 'required', 'stage' => 'required'));
     if ($validator->fails()) {
         return response()->json(['error' => 'El codigo es necesario!']);
     }
     // 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 Product.
     $item = Production::find(Input::get('code'));
     // Check if it exists.
     if (!$item) {
         return response()->json(['error' => 'No existe un ataud con este codigo!']);
     }
     // Get the product information.
     $expense = $item->currentExpense();
     $stage = $item->currentStage();
     $maxStage = $item->maxStage();
     // Make all relevant checks.
     if ($item->Stage > $maxStage) {
         return response()->json(['error' => 'Este ataud ya ha sido terminado!']);
     }
     // If item is under repairs return.
     if ($item->Stage == 0) {
         return response()->json(['error' => 'No hay materiales definidos para reparaciones!']);
     }
     // If this item has a grip fuse materials.
     $usedMaterials = json_decode($expense->Materials, true);
     if ($item->Grip) {
         $gripMaterials = json_decode($expense->GripMaterial, true);
         $found = false;
         foreach ($gripMaterials as $gripMaterial => $gripQuantity) {
             foreach ($usedMaterials as $material => $quantity) {
                 // If the material is already in the used Materials just add extra quantity.
                 if ($material == $gripMaterial) {
                     $found = true;
                     $quantity += $gripQuantity;
                 }
             }
             // If the grip material isn't in used Materials add it.
             $usedMaterials[$gripMaterial] = $gripQuantity;
         }
     }
     // Now add product description to used materials.
     foreach ($usedMaterials as $material => $quantity) {
         $stock = Stock::where('Code', '=', $material)->where('BranchId', '=', 2)->get()->first();
         $usedMaterials[$material] = $stock->Description;
     }
     // Prepare information.
     $response = array('materials' => $usedMaterials);
     // Return suggestions.
     return response()->json($response);
 }