/** * Show the form for creating a new resource. * * @param int $id * @return \Illuminate\Http\Response */ public function createSalesman($id) { $userId = Auth::user()->id; $moduleUser = ModuleAssigment::where(["salesman_id" => $userId, "status" => 1])->first(); if (!is_object($moduleUser)) { return back()->withErrors(['Usted no tiene modulo asignado, por lo tanto no puede vender']); } else { if (Auth::user()->role_id == config('constants.salesman') && Auth::user()->module && Auth::user()->module->openModule == 0) { return back()->withErrors(['Usted no ha abierto su caja, por lo tanto no puede vender']); } } //Buscar y enviar info de evento con $id $event = Event::find($id); $presentations = Presentation::where('event_id', $id)->where('cancelled', 0)->where('starts_at', '>', strtotime(Carbon::now()))->get(); $slots_array = array(); foreach ($presentations as $pres) { $slots = DB::table('slot_presentation')->where('presentation_id', $pres->id)->where('status', config('constants.seat_available'))->lists('slot_id', 'slot_id'); $slots_array[$pres->id] = $slots; } $presentations = $presentations->lists('starts_at', 'id'); foreach ($presentations as $key => $pres) { $presentations[$key] = date("Y-m-d H:i", $pres); } $presentations = $presentations->toArray(); $zones = Zone::where('event_id', $id)->lists('name', 'id'); $exchangeRate = ExchangeRate::where('status', config('constants.active'))->first(); return view('internal.salesman.buy', compact('event', 'presentations', 'zones', 'slots_array', 'exchangeRate')); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create($ticket_id) { $ticket = Ticket::findOrFail($ticket_id); if ($ticket == null) { Session::flash('message', 'Este ticket no existe'); Session::flash('alert-class', 'alert-danger'); return redirect('salesman/devolutions'); } if ($ticket->cancelled) { Session::flash('message', 'El ticket fue cancelado'); Session::flash('alert-class', 'alert-danger'); return redirect('salesman/devolutions'); } $presentation = $ticket->presentation()->first(); if (!$presentation->cancelled) { Session::flash('message', 'La presentación no fue cancelado'); Session::flash('alert-class', 'alert-danger'); return redirect('salesman/devolutions'); } $cancelPresentation = CancelPresentation::where("presentation_id", $ticket->presentation_id)->first(); if (!$cancelPresentation->authorized) { Session::flash('message', 'El ticket no esta autorizado para ser devuelto'); Session::flash('alert-class', 'alert-danger'); return redirect('salesman/devolutions'); } $today = strtotime(date("Y-m-d")); $date_refund = strtotime($cancelPresentation->date_refund); $date_refund_last = $date_refund + $cancelPresentation->duration * 86400; if ($today < $date_refund) { Session::flash('message', 'El ticket aun no se puede devolver. Autorizado para devolución a partir de ' . $cancelPresentation->date_refund); Session::flash('alert-class', 'alert-danger'); return redirect('salesman/devolutions'); } if ($today > $date_refund_last) { Session::flash('message', 'El ticket no puede ser devuelto, tiempo de devolución agotado'); Session::flash('alert-class', 'alert-danger'); return redirect('salesman/devolutions'); } $modulesAuth = $cancelPresentation->modules; $userId = Auth::user()->id; $moduleUser = ModuleAssigment::where(["salesman_id" => $userId, "status" => 1])->first(); if (!is_object($moduleUser)) { Session::flash('message', 'Usted no tiene modulo asignado, por lo tanto no puede devolver'); Session::flash('alert-class', 'alert-danger'); return redirect('salesman/devolutions'); } $isAuthorized = 0; foreach ($modulesAuth as $obj) { if ($obj->id == $moduleUser->module_id) { $isAuthorized = 1; break; } } return view('internal.salesman.devolution.new', ["ticket" => $ticket, "authorizedModule" => $modulesAuth, "isAuthorized" => $isAuthorized]); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // $moduleassigment = ModuleAssigment::where('module_id', $id)->where('status', 1)->get(); if ($moduleassigment->count() == 0) { $module = Module::find($id); $module->delete(); $business = Business::all()->first(); $business->exchange_active = NULL; $business->save(); } else { return back()->withErrors(['Debe primero desasociar el vendedor del punto de venta']); } return redirect('admin/modules'); }
public function assistanceExcel(Request $request) { if ($request['ty_report'] == 1) { $salesmans = User::where('role_id', 2)->get(); $date_at = $request['date_at']; $auxSalesman = []; foreach ($salesmans as $salesman) { if (date_format(date_create($salesman->created_at), "Y-m-d") <= date_format(date_create($date_at), "Y-m-d")) { array_push($auxSalesman, $salesman); } } $salesmans = $auxSalesman; $assiInformation = []; foreach ($salesmans as $salesman) { $assistances = Attendance::where('salesman_id', $salesman->id)->where('datetimestart', 'LIKE', '%' . date_format(date_create($date_at), "Y-m-d") . '%')->get(); if (count($assistances) == 0) { $aux = ModuleAssigment::where('dateAssigments', '<', date_format(date_create(date("Y-m-d", strtotime($date_at) + 86400)), "Y-m-d"))->where('salesman_id', $salesman->id)->get()->last(); if (count($aux) == 0) { array_push($assiInformation, array($salesman->name, $salesman->lastname, "-", "-", "No Asistió", "No Asistió", "No tiene Módulo")); } else { $module = Module::find($aux->module_id); if ($aux->dateMoveAssigments == null) { array_push($assiInformation, array($salesman->name, $salesman->lastname, "-", "-", "No Asistió", "No Asistió", $module->name)); } else { if (date_format(date_create($aux->dateMoveAssigments), "Y-m-d") < $date_at) { array_push($assiInformation, array($salesman->name, $salesman->lastname, "-", "-", "No Asistió", "No Asistió", "No tiene Módulo")); } else { array_push($assiInformation, array($salesman->name, $salesman->lastname, "-", "-", "No Asistió", "No Asistió", $module->name)); } } } } else { foreach ($assistances as $assistance) { $aux = ModuleAssigment::where('dateAssigments', '<', date_format(date_create(date("Y-m-d", strtotime($date_at) + 86400)), "Y-m-d"))->where('salesman_id', $salesman->id)->get()->last(); if (count($aux) == 0) { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "-", "-", "No tiene Módulo")); } else { $module = Module::find($aux->module_id); if ($aux->dateMoveAssigments == null || date_format(date_create($aux->dateMoveAssigments), "Y-m-d") >= $date_at) { $openHour = date_format(date_create($module->starTime), "H:i:s"); if ($openHour >= date_format(date_create($assistance->datetimestart), "H:i:s")) { if ($assistance->datetimeend == null) { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), "-", "Llegó Puntual", "Sigue Trabajando", $module->name)); } else { $endHour = date_format(date_create($module->endTime), "H:i:s"); if ($endHour <= date_format(date_create($assistance->datetimeend), "H:i:s")) { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "Llegó Puntual", "Salio Puntual", $module->name)); } else { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "Llego Puntual", "Salió Temprano", $module->name)); } } } else { if ($assistance->datetimeend == null) { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), "-", "Llegó Tarde", "Sigue Trabajando", $module->name)); } else { $endHour = date_format(date_create($module->endTime), "H:i:s"); if ($endHour <= date_format(date_create($assistance->datetimeend), "H:i:s")) { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "Llegó Tarde", "Salió Puntual", $module->name)); } else { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "Llegó Tarde", "Salió Temprano", $module->name)); } } } } else { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "-", "-", "No tiene Módulo")); } } } } //} } return view('internal.admin.reports.assistance', compact('assiInformation', 'date_at')); } elseif ($request['ty_report'] == 2) { $input = $request->all(); $salesmans = User::where('role_id', 2)->get(); $date_at = $request['date_at']; $auxSalesman = []; foreach ($salesmans as $salesman) { if (date_format(date_create($salesman->created_at), "Y-m-d") <= date_format(date_create($date_at), "Y-m-d")) { array_push($auxSalesman, $salesman); } } $salesmans = $auxSalesman; $assiInformation = []; foreach ($salesmans as $salesman) { $assistances = Attendance::where('salesman_id', $salesman->id)->where('datetimestart', 'LIKE', '%' . date_format(date_create($date_at), "Y-m-d") . '%')->get(); if (count($assistances) == 0) { $aux = ModuleAssigment::where('dateAssigments', '<', date_format(date_create(date("Y-m-d", strtotime($date_at) + 86400)), "Y-m-d"))->where('salesman_id', $salesman->id)->get()->last(); if (count($aux) == 0) { array_push($assiInformation, array($salesman->name, $salesman->lastname, "-", "-", "No Asistió", "No Asistió", "No tiene Módulo")); } else { $module = Module::find($aux->module_id); if ($aux->dateMoveAssigments == null) { array_push($assiInformation, array($salesman->name, $salesman->lastname, "-", "-", "No Asistió", "No Asistió", $module->name)); } else { if (date_format(date_create($aux->dateMoveAssigments), "Y-m-d") < $date_at) { array_push($assiInformation, array($salesman->name, $salesman->lastname, "-", "-", "No Asistió", "No Asistió", "No tiene Módulo")); } else { array_push($assiInformation, array($salesman->name, $salesman->lastname, "-", "-", "No Asistió", "No Asistió", $module->name)); } } } } else { foreach ($assistances as $assistance) { $aux = ModuleAssigment::where('dateAssigments', '<', date_format(date_create(date("Y-m-d", strtotime($date_at) + 86400)), "Y-m-d"))->where('salesman_id', $salesman->id)->get()->last(); if (count($aux) == 0) { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "-", "-", "No tiene Módulo")); } else { $module = Module::find($aux->module_id); if ($aux->dateMoveAssigments == null || date_format(date_create($aux->dateMoveAssigments), "Y-m-d") >= $date_at) { $openHour = date_format(date_create($module->starTime), "H:i:s"); if ($openHour >= date_format(date_create($assistance->datetimestart), "H:i:s")) { if ($assistance->datetimeend == null) { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), "-", "Llegó Puntual", "Sigue Trabajando", $module->name)); } else { $endHour = date_format(date_create($module->endTime), "H:i:s"); if ($endHour <= date_format(date_create($assistance->datetimeend), "H:i:s")) { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "Llegó Puntual", "Salio Puntual", $module->name)); } else { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "Llego Puntual", "Salió Temprano", $module->name)); } } } else { if ($assistance->datetimeend == null) { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), "-", "Llegó Tarde", "Sigue Trabajando", $module->name)); } else { $endHour = date_format(date_create($module->endTime), "H:i:s"); if ($endHour <= date_format(date_create($assistance->datetimeend), "H:i:s")) { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "Llegó Tarde", "Salió Puntual", $module->name)); } else { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "Llegó Tarde", "Salió Temprano", $module->name)); } } } } else { array_push($assiInformation, array($salesman->name, $salesman->lastname, date_format(date_create($assistance->datetimestart), "H:i:s"), date_format(date_create($assistance->datetimeend), "H:i:s"), "-", "-", "No tiene Módulo")); } } } } //} } if ($input['type'] == 1) { Excel::create('Reporte de asistencia de vendedores starkticket', function ($excel) use($assiInformation, $date_at) { $excel->sheet('Reporte de ventas', function ($sheet) use($assiInformation, $date_at) { $sheet->mergeCells('A1:G2'); $sheet->setCellValue('A1', "Reporte de asistencia de vendedores"); $sheet->cells('A1:G1', function ($cells) { $cells->setAlignment('center'); $cells->setValignment('center'); $cells->setFontSize(30); }); $sheet->mergeCells('A3:G3'); if (date_format(date_create($date_at), "d/m/Y") == date_format(date_create(new Carbon()), "d/m/Y")) { $sheet->setCellValue('A3', 'Fecha del día ' . date_format(date_create($date_at), "d/m/Y") . ' a las ' . date_format(date_create(new Carbon()), "H:i")); } else { $sheet->setCellValue('A3', 'Fecha del día ' . date_format(date_create($date_at), "d/m/Y")); } $sheet->cells('A3:G3', function ($cells) { $cells->setAlignment('center'); $cells->setValignment('center'); $cells->setFontSize(14); }); $cantidad = count($assiInformation) + 4; $sheet->setBorder('A4:G' . $cantidad, 'thin'); $sheet->setCellValue('A4', "Nombres del Vendedor"); $sheet->setCellValue('B4', "Apellidos del Vendedor"); $sheet->setCellValue('C4', "Hora de Entrada"); $sheet->setCellValue('D4', "Hora de Salida"); $sheet->setCellValue('E4', "Situación de Entrada"); $sheet->setCellValue('F4', "Situación de Salida"); $sheet->setCellValue('G4', "Punto de Venta"); //$cells->setAlignment('center'); $sheet->cells('A4:G4', function ($cells) { $cells->setFontWeight('bold'); $cells->setBackground('#008000'); $cells->setFontColor('#FFFFFF'); $cells->setAlignment('center'); $cells->setValignment('center'); }); $sheet->cells('A4:G500', function ($cells) { $cells->setAlignment('center'); $cells->setValignment('center'); }); $sheet->setWidth(array('A' => '30', 'B' => '30', 'C' => '30', 'D' => '30', 'E' => '30', 'F' => '30', 'G' => '30')); $sheet->setHeight(array('1' => '20')); $data = $assiInformation; $sheet->fromArray($data, true, 'A5', true, false); }); })->download('xlsx'); } else { Excel::create('Reporte de ventas starkticket', function ($excel) use($assiInformation, $date_at) { $excel->sheet('Reporte de ventas', function ($sheet) use($assiInformation, $date_at) { $sheet->mergeCells('A1:G2'); $sheet->setCellValue('A1', "Reporte de asistencia de vendedores"); $sheet->cells('A1:G1', function ($cells) { $cells->setAlignment('center'); $cells->setValignment('center'); $cells->setFontSize(30); }); $sheet->mergeCells('A3:G3'); if (date_format(date_create($date_at), "d/m/Y") == date_format(date_create(new Carbon()), "d/m/Y")) { $sheet->setCellValue('A3', 'Fecha del día ' . date_format(date_create($date_at), "d/m/Y") . ' a las ' . date_format(date_create(new Carbon()), "H:i")); } else { $sheet->setCellValue('A3', 'Fecha del día ' . date_format(date_create($date_at), "d/m/Y")); } $sheet->cells('A3:G3', function ($cells) { $cells->setAlignment('center'); $cells->setValignment('center'); $cells->setFontSize(14); }); $cantidad = count($assiInformation) + 4; $sheet->setBorder('A4:G' . $cantidad, 'thin'); $sheet->setCellValue('A4', "Nombres del Vendedor"); $sheet->setCellValue('B4', "Apellidos del Vendedor"); $sheet->setCellValue('C4', "Hora de Entrada"); $sheet->setCellValue('D4', "Hora de Salida"); $sheet->setCellValue('E4', "Situación de Entrada"); $sheet->setCellValue('F4', "Situación de Salida"); $sheet->setCellValue('G4', "Total"); //$cells->setAlignment('center'); $sheet->cells('A4:G4', function ($cells) { $cells->setFontWeight('bold'); $cells->setBackground('#008000'); $cells->setFontColor('#FFFFFF'); $cells->setAlignment('center'); $cells->setValignment('center'); }); $sheet->cells('A4:G500', function ($cells) { $cells->setAlignment('center'); $cells->setValignment('center'); }); $sheet->setWidth(array('A' => '30', 'B' => '30', 'C' => '30', 'D' => '30', 'E' => '30', 'F' => '30', 'G' => '30')); $sheet->setHeight(array('1' => '20')); $data = $assiInformation; $sheet->fromArray($data, true, 'A5', true, false); }); })->export('pdf'); } } }
public function destroySalesman($id) { $moduleassigment = ModuleAssigment::where('salesman_id', $id)->where('status', 1)->get(); if ($moduleassigment->count() == 0) { $user = User::find($id); $user->delete(); } else { return back()->withErrors(['Debe primero desasociar el vendedor del punto de venta']); } return redirect('admin/salesman'); }