Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Contracts\Validation\Validator;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Hash;
- use Illuminate\Support\Facades\Input;
- use Illuminate\Support\Facades\Redirect;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Route;
- use \Carbon\Carbon;
- use Auth;
- use App;
- use App\User;
- use App\UserLilu;
- use App\Transaction;
- use App\Product;
- use App\ProductClass;
- use App\ProductCategory;
- use App\ServiceCategory;
- use App\Booking;
- use App\Client;
- use App\Ticket;
- use App\Sale;
- use App\Business;
- use App\Staff;
- class HomeController extends Controller
- {
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct()
- {
- $this->middleware('auth');
- }
- /**
- * Show the application dashboard.
- *
- * @return \Illuminate\Http\Response
- */
- public function index(Request $request) {
- date_default_timezone_set("America/Mexico_City");
- $today = \Carbon\Carbon::now()->toDateString();
- $dayago = \Carbon\Carbon::now()->subDay(1)->toDateString();
- $twodayago = \Carbon\Carbon::now()->subDay(2)->toDateString();
- $threedayago = \Carbon\Carbon::now()->subDay(3)->toDateString();
- $fourdayago = \Carbon\Carbon::now()->subDay(4)->toDateString();
- $fivedayago = \Carbon\Carbon::now()->subDay(5)->toDateString();
- $sixdayago = \Carbon\Carbon::now()->subDay(6)->toDateString();
- $monthago = \Carbon\Carbon::now()->subMonth()->toDateString(); # YA NO ES SEMANAL ES MENSUAL
- $twomonthago = \Carbon\Carbon::now()->subMonth(2)->toDateString();
- ///HACER UN LOOP CON PARA SACAR TODOS LOS USER Y HACER GROUP BY USER_ID
- //return $users_ids;
- $all_users_ids=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->get();
- if ($request->isMethod('post')) {
- //
- $users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->whereIn('user_id',Input::get('user_ids'))->select('user_id')->get();
- $selected_users=Input::get('user_ids');
- }else{
- if(UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->count()>0){
- $users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->get();
- foreach($users as $user){
- $selected_users[]=$user->user_id;
- }
- }else{
- $selected_users[]='';
- }
- //$selected_users=$all_users_ids->pluck('user_id');
- }
- $all_users_ids=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->get();
- //$user= UserLilu::where('franchise_id',Auth::user()->franchise_id)->first();
- # CITAS REALIZADAS DEL ÚLTIMO MES
- $bookings_week = 0;
- $bookings_twomonthago = 0;
- $clients_week=0;
- $clients_twomonthago=0;
- $sales_week=0;
- $sales_twomonthago=0;
- $income_month = 0;
- $income_twomonthago = 0;
- # FOREACH RECORRIENDO TODOS LOS NEGOCIOS DE LA FRANQUICIA
- if(UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->count()>0) {
- foreach($users as $user){
- for($x=0;$x<=30;$x++)
- $bookings_week += $this->getBookingsCount($x,$user);
- # CITAS REALIZADAS DEL MES PASADO
- for($x=30;$x<=60;$x++)
- $bookings_twomonthago += $this->getBookingsCount($x,$user);
- # CLIENTES NUEVOS LA ÚLTIMA SEMANA
- $clients_week += Client::where('user_id',$user->user_id)->whereBetween( DB::raw('date(created_at)'), [$monthago, $today] )->whereNull('deleted_at')->get()->count();
- # CLIENTES NUEVOS LA SEMANA PASADA
- $clients_twomonthago += Client::where('user_id',$user->user_id)->whereBetween( DB::raw('date(created_at)'), [$twomonthago, $monthago] )->whereNull('deleted_at')->get()->count();
- # VENTAS NUEVOS LA ÚLTIMA SEMANA
- $sales_week += Ticket::where('user_id',$user->user_id)->whereBetween( DB::raw('date(created_at)'), [$monthago, $today] )->whereNull('deleted_at')->get()->count();
- # VENTAS NUEVOS LA SEMANA PASADA
- $sales_twomonthago += Ticket::where('user_id',$user->user_id)->whereBetween( DB::raw('date(created_at)'), [$twomonthago, $monthago] )->whereNull('deleted_at')->get()->count();
- # INGRESOS NUEVOS DEL ÚLTIMO MES
- for($x=0;$x<=30;$x++)
- $income_month += $this->getIncomeSubday($x,$user) + $this->getIncomeProductsSubday($x,$user);
- # INGRESOS NUEVOS DEL MES PASADO
- for($x=30;$x<=60;$x++)
- $income_twomonthago += $this->getIncomeSubday($x,$user) + $this->getIncomeProductsSubday($x,$user);
- }
- }
- # CITAS COMPLETADAS LA ÚLTIMA SEMANA
- # 1 tomamos la fecha que necesitamos y la igualamos con la que almacenamos en la bd, 2 vemos si el mes comienza con 0 si es asi lo eliminamos, despues vemos si el día comienza con 0 si es asi lo eliminamos
- $todayy = \Carbon\Carbon::now()->format('m/d/Y');
- $todayy = (substr( $todayy, 0, 1 ) === "0") ? substr($todayy,1) : $todayy;
- $todayy = (substr( explode("/",$todayy)[1], 0, 1 ) === "0") ? explode("/",$todayy)[0]."/".substr(explode("/",$todayy)[1],1)."/".explode("/",$todayy)[2] : $todayy;
- # 1 tomamos la fecha que necesitamos y la igualamos con la que almacenamos en la bd, 2 vemos si el mes comienza con 0 si es asi lo eliminamos, despues vemos si el día comienza con 0 si es asi lo eliminamos
- $dayagoo = \Carbon\Carbon::now()->subDay(1)->format('m/d/Y');
- $dayagoo = (substr( $dayagoo, 0, 1 ) === "0") ? substr($dayagoo,1) : $dayagoo;
- $dayagoo = (substr( explode("/",$dayagoo)[1], 0, 1 ) === "0") ? explode("/",$dayagoo)[0]."/".substr(explode("/",$dayagoo)[1],1)."/".explode("/",$dayagoo)[2] : $dayagoo;
- # 1 tomamos la fecha que necesitamos y la igualamos con la que almacenamos en la bd, 2 vemos si el mes comienza con 0 si es asi lo eliminamos, despues vemos si el día comienza con 0 si es asi lo eliminamos
- $twodayagoo = \Carbon\Carbon::now()->subDay(2)->format('m/d/Y');
- $twodayagoo = (substr( $twodayagoo, 0, 1 ) === "0") ? substr($twodayagoo,1) : $twodayagoo;
- $twodayagoo = (substr( explode("/",$twodayagoo)[1], 0, 1 ) === "0") ? explode("/",$twodayagoo)[0]."/".substr(explode("/",$twodayagoo)[1],1)."/".explode("/",$twodayagoo)[2] : $twodayagoo;
- # 1 tomamos la fecha que necesitamos y la igualamos con la que almacenamos en la bd, 2 vemos si el mes comienza con 0 si es asi lo eliminamos, despues vemos si el día comienza con 0 si es asi lo eliminamos
- $threedayagoo = \Carbon\Carbon::now()->subDay(3)->format('m/d/Y');
- $threedayagoo = (substr( $threedayagoo, 0, 1 ) === "0") ? substr($threedayagoo,1) : $threedayagoo;
- $threedayagoo = (substr( explode("/",$threedayagoo)[1], 0, 1 ) === "0") ? explode("/",$threedayagoo)[0]."/".substr(explode("/",$threedayagoo)[1],1)."/".explode("/",$threedayagoo)[2] : $threedayagoo;
- # 1 tomamos la fecha que necesitamos y la igualamos con la que almacenamos en la bd, 2 vemos si el mes comienza con 0 si es asi lo eliminamos, despues vemos si el día comienza con 0 si es asi lo eliminamos
- $fourdayagoo = \Carbon\Carbon::now()->subDay(4)->format('m/d/Y');
- $fourdayagoo = (substr( $fourdayagoo, 0, 1 ) === "0") ? substr($fourdayagoo,1) : $fourdayagoo;
- $fourdayagoo = (substr( explode("/",$fourdayagoo)[1], 0, 1 ) === "0") ? explode("/",$fourdayagoo)[0]."/".substr(explode("/",$fourdayagoo)[1],1)."/".explode("/",$fourdayagoo)[2] : $fourdayagoo;
- # 1 tomamos la fecha que necesitamos y la igualamos con la que almacenamos en la bd, 2 vemos si el mes comienza con 0 si es asi lo eliminamos, despues vemos si el día comienza con 0 si es asi lo eliminamos
- $fivedayagoo = \Carbon\Carbon::now()->subDay(5)->format('m/d/Y');
- $fivedayagoo = (substr( $fivedayagoo, 0, 1 ) === "0") ? substr($fivedayagoo,1) : $fivedayagoo;
- $fivedayagoo = (substr( explode("/",$fivedayagoo)[1], 0, 1 ) === "0") ? explode("/",$fivedayagoo)[0]."/".substr(explode("/",$fivedayagoo)[1],1)."/".explode("/",$fivedayagoo)[2] : $fivedayagoo;
- # 1 tomamos la fecha que necesitamos y la igualamos con la que almacenamos en la bd, 2 vemos si el mes comienza con 0 si es asi lo eliminamos, despues vemos si el día comienza con 0 si es asi lo eliminamos
- $sixdayagoo = \Carbon\Carbon::now()->subDay(6)->format('m/d/Y');
- $sixdayagoo = (substr( $sixdayagoo, 0, 1 ) === "0") ? substr($sixdayagoo,1) : $sixdayagoo;
- $sixdayagoo = (substr( explode("/",$sixdayagoo)[1], 0, 1 ) === "0") ? explode("/",$sixdayagoo)[0]."/".substr(explode("/",$sixdayagoo)[1],1)."/".explode("/",$sixdayagoo)[2] : $sixdayagoo;
- # FOREACH RECORRIENDO TODOS LOS NEGOCIOS DE LA FRANQUICIA
- $bookings_completed_today=0;
- $bookings_completed_1ago=0;
- $bookings_completed_2ago=0;
- $bookings_completed_3ago=0;
- $bookings_completed_4ago=0;
- $bookings_completed_5ago=0;
- $bookings_completed_6ago=0;
- $bookings_cancelled_today=0;
- $bookings_cancelled_1ago=0;
- $bookings_cancelled_2ago=0;
- $bookings_cancelled_3ago=0;
- $bookings_cancelled_4ago=0;
- $bookings_cancelled_5ago=0;
- $bookings_cancelled_6ago=0;
- $bookings_pending_today=0;
- $bookings_pending_1ago=0;
- $bookings_pending_2ago=0;
- $bookings_pending_3ago=0;
- $bookings_pending_4ago=0;
- $bookings_pending_5ago=0;
- $bookings_pending_6ago=0;
- if(UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->count()>0) {
- foreach ($users as $user) {
- $bookings_completed_today += Booking::where('user_id', $user->user_id)->where('status', 2)->where('end_date', 'like', '%' . $todayy . '%')->whereNull('deleted_at')->get()->count();
- $bookings_completed_1ago += Booking::where('user_id', $user->user_id)->where('status', 2)->where('end_date', 'like', '%' . $dayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_completed_2ago += Booking::where('user_id', $user->user_id)->where('status', 2)->where('end_date', 'like', '%' . $twodayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_completed_3ago += Booking::where('user_id', $user->user_id)->where('status', 2)->where('end_date', 'like', '%' . $threedayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_completed_4ago += Booking::where('user_id', $user->user_id)->where('status', 2)->where('end_date', 'like', '%' . $fourdayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_completed_5ago += Booking::where('user_id', $user->user_id)->where('status', 2)->where('end_date', 'like', '%' . $fivedayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_completed_6ago += Booking::where('user_id', $user->user_id)->where('status', 2)->where('end_date', 'like', '%' . $sixdayagoo . '%')->whereNull('deleted_at')->get()->count();
- # CITAS COMPLETADAS LA ÚLTIMA SEMANA
- $bookings_cancelled_today += Booking::where('user_id', $user->user_id)->where('status', 3)->where('end_date', 'like', '%' . $todayy . '%')->whereNull('deleted_at')->get()->count();
- $bookings_cancelled_1ago += Booking::where('user_id', $user->user_id)->where('status', 3)->where('end_date', 'like', '%' . $dayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_cancelled_2ago += Booking::where('user_id', $user->user_id)->where('status', 3)->where('end_date', 'like', '%' . $twodayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_cancelled_3ago += Booking::where('user_id', $user->user_id)->where('status', 3)->where('end_date', 'like', '%' . $threedayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_cancelled_4ago += Booking::where('user_id', $user->user_id)->where('status', 3)->where('end_date', 'like', '%' . $fourdayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_cancelled_5ago += Booking::where('user_id', $user->user_id)->where('status', 3)->where('end_date', 'like', '%' . $fivedayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_cancelled_6ago += Booking::where('user_id', $user->user_id)->where('status', 3)->where('end_date', 'like', '%' . $sixdayagoo . '%')->whereNull('deleted_at')->get()->count();
- # CITAS PENDIENTES LA ÚLTIMA SEMANA
- $bookings_pending_today += Booking::where('user_id', $user->user_id)->where('status', 1)->where('end_date', 'like', '%' . $todayy . '%')->whereNull('deleted_at')->get()->count();
- $bookings_pending_1ago += Booking::where('user_id', $user->user_id)->where('status', 1)->where('end_date', 'like', '%' . $dayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_pending_2ago += Booking::where('user_id', $user->user_id)->where('status', 1)->where('end_date', 'like', '%' . $twodayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_pending_3ago += Booking::where('user_id', $user->user_id)->where('status', 1)->where('end_date', 'like', '%' . $threedayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_pending_4ago += Booking::where('user_id', $user->user_id)->where('status', 1)->where('end_date', 'like', '%' . $fourdayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_pending_5ago += Booking::where('user_id', $user->user_id)->where('status', 1)->where('end_date', 'like', '%' . $fivedayagoo . '%')->whereNull('deleted_at')->get()->count();
- $bookings_pending_6ago += Booking::where('user_id', $user->user_id)->where('status', 1)->where('end_date', 'like', '%' . $sixdayagoo . '%')->whereNull('deleted_at')->get()->count();
- }
- }
- # CITAS PENDIENTES LA ÚLTIMA SEMANA
- #$booking = Booking::where('user_id',$user->user_id)->where('status',1)->whereDate('created_at',$today)->first();
- #$monday = Booking::where('user_id',$user->user_id)->where('status',1)->whereDate('created_at',$today)->first()->mon;
- //$user->franchise_id;
- # FOREACH RECORRIENDO TODOS LOS NEGOCIOS DE LA FRANQUICIA
- $staff_count=0;
- $test = null;
- $bookings_available_today=0;
- $bookings_available_1ago=0;
- $bookings_available_2ago=0;
- $bookings_available_3ago=0;
- $bookings_available_4ago=0;
- $bookings_available_5ago=0;
- $bookings_available_6ago=0;
- if(UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->count()>0) {
- foreach($users as $user) {
- $business = Business::where('user_id', $user->user_id)->first(); # CHECK, IT WAS 'ID' CHANGED TO 'USER_ID'
- $staff_count += Staff::where('user_id', $user->user_id)->whereNull('deleted_at')->get()->count();
- if (\Carbon\Carbon::now()->format('l') == 'Monday') {
- if ($business->mon) {
- $bookings_available_today = Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[1])) * $staff_count - $bookings_completed_today - $bookings_pending_today;
- } else {
- $bookings_available_today = 0;
- }
- }
- if (\Carbon\Carbon::now()->format('l') == 'Tuesday') {
- if ($business->tue) {
- $bookings_available_today = Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[1])) * $staff_count - $bookings_completed_today - $bookings_pending_today;
- } else {
- $bookings_available_today = 0;
- }
- }
- if (\Carbon\Carbon::now()->format('l') == 'Wednesday') {
- if ($business->wed) {
- $bookings_available_today = Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[1])) * $staff_count - $bookings_completed_today - $bookings_pending_today;
- } else {
- $bookings_available_today = 0;
- }
- }
- if (\Carbon\Carbon::now()->format('l') == 'Thursday') {
- if ($business->thu) {
- $bookings_available_today = Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[1])) * $staff_count - $bookings_completed_today - $bookings_pending_today;
- } else {
- $bookings_available_today = 0;
- }
- }
- if (\Carbon\Carbon::now()->format('l') == 'Friday') {
- if ($business->fri) {
- $bookings_available_today = Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[1])) * $staff_count - $bookings_completed_today - $bookings_pending_today;
- } else {
- $bookings_available_today = 0;
- }
- }
- if (\Carbon\Carbon::now()->format('l') == 'Sathurday') {
- if ($business->sat) {
- $bookings_available_today = Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[1])) * $staff_count - $bookings_completed_today - $bookings_pending_today;
- } else {
- $bookings_available_today = 0;
- }
- }
- if (\Carbon\Carbon::now()->format('l') == 'Sunday') {
- if ($business->sun) {
- $bookings_available_today = Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[1])) * $staff_count - $bookings_completed_today - $bookings_pending_today;
- } else {
- $bookings_available_today = 0;
- }
- }
- try {
- if (\Carbon\Carbon::now()->subDay(1)->format('l') == 'Monday') {
- if ($business->mon) {
- $bookings_available_1ago = Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[1])) * $staff_count - $bookings_completed_1ago - $bookings_pending_1ago;
- } else {
- $bookings_available_1ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_1ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(1)->format('l') == 'Tuesday') {
- if ($business->tue) {
- $bookings_available_1ago = Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[1])) * $staff_count - $bookings_completed_1ago - $bookings_pending_1ago;
- } else {
- $bookings_available_1ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_1ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(1)->format('l') == 'Wednesday') {
- if ($business->wed) {
- $bookings_available_1ago = Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[1])) * $staff_count - $bookings_completed_1ago - $bookings_pending_1ago;
- } else {
- $bookings_available_1ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_1ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(1)->format('l') == 'Thursday') {
- if ($business->thu) {
- $bookings_available_1ago = Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[1])) * $staff_count - $bookings_completed_1ago - $bookings_pending_1ago;
- } else {
- $bookings_available_1ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_1ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(1)->format('l') == 'Friday') {
- if ($business->fri) {
- $bookings_available_1ago = Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[1])) * $staff_count - $bookings_completed_1ago - $bookings_pending_1ago;
- } else {
- $bookings_available_1ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_1ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(1)->format('l') == 'Sathurday') {
- if ($business->sat) {
- $bookings_available_1ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[1])) * $staff_count - $bookings_completed_1ago - $bookings_pending_1ago;
- } else {
- $bookings_available_1ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_1ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(1)->format('l') == 'Sunday') {
- if ($business->sun) {
- $bookings_available_1ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[1])) * $staff_count - $bookings_completed_1ago - $bookings_pending_1ago;
- } else {
- $bookings_available_1ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_1ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(2)->format('l') == 'Monday') {
- if ($business->mon) {
- $bookings_available_2ago = Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[1])) * $staff_count - $bookings_completed_2ago - $bookings_pending_2ago;
- } else {
- $bookings_available_2ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_2ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(2)->format('l') == 'Tuesday') {
- if ($business->tue) {
- $bookings_available_2ago = Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[1])) * $staff_count - $bookings_completed_2ago - $bookings_pending_2ago;
- } else {
- $bookings_available_2ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_2ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(2)->format('l') == 'Wednesday') {
- if ($business->wed) {
- $bookings_available_2ago = Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[1])) * $staff_count - $bookings_completed_2ago - $bookings_pending_2ago;
- } else {
- $bookings_available_2ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_2ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(2)->format('l') == 'Thursday') {
- if ($business->thu) {
- $bookings_available_2ago = Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[1])) * $staff_count - $bookings_completed_2ago - $bookings_pending_2ago;
- } else {
- $bookings_available_2ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_2ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(2)->format('l') == 'Friday') {
- if ($business->fri) {
- $bookings_available_2ago = Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[1])) * $staff_count - $bookings_completed_2ago - $bookings_pending_2ago;
- } else {
- $bookings_available_2ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_2ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(2)->format('l') == 'Sathurday') {
- if ($business->sat) {
- $bookings_available_2ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[1])) * $staff_count - $bookings_completed_2ago - $bookings_pending_2ago;
- } else {
- $bookings_available_2ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_2ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(2)->format('l') == 'Sunday') {
- if ($business->sun) {
- $bookings_available_2ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[1])) * $staff_count - $bookings_completed_2ago - $bookings_pending_2ago;
- } else {
- $bookings_available_2ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_2ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(3)->format('l') == 'Monday') {
- if ($business->mon) {
- $bookings_available_3ago = Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[1])) * $staff_count - $bookings_completed_3ago - $bookings_pending_3ago;
- } else {
- $bookings_available_3ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_3ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(3)->format('l') == 'Tuesday') {
- if ($business->tue) {
- $bookings_available_3ago = Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[1])) * $staff_count - $bookings_completed_3ago - $bookings_pending_3ago;
- } else {
- $bookings_available_3ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_3ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(3)->format('l') == 'Wednesday') {
- if ($business->wed) {
- $bookings_available_3ago = Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[1])) * $staff_count - $bookings_completed_3ago - $bookings_pending_3ago;
- } else {
- $bookings_available_3ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_3ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(3)->format('l') == 'Thursday') {
- if ($business->thu) {
- $bookings_available_3ago = Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[1])) * $staff_count - $bookings_completed_3ago - $bookings_pending_3ago;
- } else {
- $bookings_available_3ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_3ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(3)->format('l') == 'Friday') {
- if ($business->fri) {
- $bookings_available_3ago = Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[1])) * $staff_count - $bookings_completed_3ago - $bookings_pending_3ago;
- } else {
- $bookings_available_3ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_3ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(3)->format('l') == 'Sathurday') {
- if ($business->sat) {
- $bookings_available_3ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[1])) * $staff_count - $bookings_completed_3ago - $bookings_pending_3ago;
- } else {
- $bookings_available_3ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_3ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(3)->format('l') == 'Sunday') {
- if ($business->sun) {
- $bookings_available_3ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[1])) * $staff_count - $bookings_completed_3ago - $bookings_pending_3ago;
- } else {
- $bookings_available_3ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_3ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(4)->format('l') == 'Monday') {
- if ($business->mon) {
- $bookings_available_4ago = Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[1])) * $staff_count - $bookings_completed_4ago - $bookings_pending_4ago;
- } else {
- $bookings_available_4ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_4ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(4)->format('l') == 'Tuesday') {
- if ($business->tue) {
- $bookings_available_4ago = Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[1])) * $staff_count - $bookings_completed_4ago - $bookings_pending_4ago;
- } else {
- $bookings_available_4ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_4ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(4)->format('l') == 'Wednesday') {
- if ($business->wed) {
- $bookings_available_4ago = Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[1])) * $staff_count - $bookings_completed_4ago - $bookings_pending_4ago;
- } else {
- $bookings_available_4ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_4ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(4)->format('l') == 'Thursday') {
- if ($business->thu) {
- $bookings_available_4ago = Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[1])) * $staff_count - $bookings_completed_4ago - $bookings_pending_4ago;
- } else {
- $bookings_available_4ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_4ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(4)->format('l') == 'Friday') {
- if ($business->fri) {
- $bookings_available_4ago = Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[1])) * $staff_count - $bookings_completed_4ago - $bookings_pending_4ago;
- } else {
- $bookings_available_4ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_4ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(4)->format('l') == 'Sathurday') {
- if ($business->sat) {
- $bookings_available_4ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[1])) * $staff_count - $bookings_completed_4ago - $bookings_pending_4ago;
- } else {
- $bookings_available_4ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_4ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(4)->format('l') == 'Sunday') {
- if ($business->sun) {
- $bookings_available_4ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[1])) * $staff_count - $bookings_completed_4ago - $bookings_pending_4ago;
- } else {
- $bookings_available_4ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_4ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(5)->format('l') == 'Monday') {
- if ($business->mon) {
- $bookings_available_5ago = Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[1])) * $staff_count - $bookings_completed_5ago - $bookings_pending_5ago;
- } else {
- $bookings_available_5ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_5ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(5)->format('l') == 'Tuesday') {
- if ($business->tue) {
- $bookings_available_5ago = Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[1])) * $staff_count - $bookings_completed_5ago - $bookings_pending_5ago;
- } else {
- $bookings_available_5ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_5ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(5)->format('l') == 'Wednesday') {
- if ($business->wed) {
- $bookings_available_5ago = Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[1])) * $staff_count - $bookings_completed_5ago - $bookings_pending_5ago;
- } else {
- $bookings_available_5ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_5ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(5)->format('l') == 'Thursday') {
- if ($business->thu) {
- $bookings_available_5ago = Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[1])) * $staff_count - $bookings_completed_5ago - $bookings_pending_5ago;
- } else {
- $bookings_available_5ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_5ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(5)->format('l') == 'Friday') {
- if ($business->fri) {
- $bookings_available_5ago = Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[1])) * $staff_count - $bookings_completed_5ago - $bookings_pending_5ago;
- } else {
- $bookings_available_5ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_5ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(5)->format('l') == 'Sathurday') {
- if ($business->sat) {
- $bookings_available_5ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[1])) * $staff_count - $bookings_completed_5ago - $bookings_pending_5ago;
- } else {
- $bookings_available_5ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_5ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(5)->format('l') == 'Sunday') {
- if ($business->sun) {
- $bookings_available_5ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[1])) * $staff_count - $bookings_completed_5ago - $bookings_pending_5ago;
- } else {
- $bookings_available_5ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_5ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(6)->format('l') == 'Monday') {
- if ($business->mon) {
- $bookings_available_6ago = Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->mon))[1])) * $staff_count - $bookings_completed_6ago - $bookings_pending_6ago;
- } else {
- $bookings_available_6ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_6ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(6)->format('l') == 'Tuesday') {
- if ($business->tue) {
- $bookings_available_6ago = Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->tue))[1])) * $staff_count - $bookings_completed_6ago - $bookings_pending_6ago;
- } else {
- $bookings_available_6ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_6ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(6)->format('l') == 'Wednesday') {
- if ($business->wed) {
- $bookings_available_6ago = Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->wed))[1])) * $staff_count - $bookings_completed_6ago - $bookings_pending_6ago;
- } else {
- $bookings_available_6ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_6ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(6)->format('l') == 'Thursday') {
- if ($business->thu) {
- $bookings_available_6ago = Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->thu))[1])) * $staff_count - $bookings_completed_6ago - $bookings_pending_6ago;
- } else {
- $bookings_available_6ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_6ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(6)->format('l') == 'Friday') {
- if ($business->fri) {
- $bookings_available_6ago = Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->fri))[1])) * $staff_count - $bookings_completed_6ago - $bookings_pending_6ago;
- } else {
- $bookings_available_6ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_6ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(6)->format('l') == 'Sathurday') {
- if ($business->sat) {
- $bookings_available_6ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sat))[1])) * $staff_count - $bookings_completed_6ago - $bookings_pending_6ago;
- } else {
- $bookings_available_6ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_6ago = 0;
- }
- try {
- if (\Carbon\Carbon::now()->subDay(6)->format('l') == 'Sunday') {
- if ($business->sun) {
- $bookings_available_6ago = Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[0])->diffInHours(Carbon::parse(explode('-', str_replace(' ', '', $business->sun))[1])) * $staff_count - $bookings_completed_6ago - $bookings_pending_6ago;
- } else {
- $bookings_available_6ago = 0;
- }
- }
- } catch (Exception $e) {
- $bookings_available_6ago = 0;
- }
- }
- }
- //$business = Business::where('user_id',$user->user_id)->first(); # CHECK, IT WAS 'ID' CHANGED TO 'USER_ID'
- //$staff_count = Staff::where('user_id',$user->user_id)->whereNull('deleted_at')->get()->count();
- /*
- * CICLO FOREACH USER
- */
- $income_products_today=0;
- $income_products_1ago=0;
- $income_products_2ago=0;
- $income_products_3ago=0;
- $income_products_4ago=0;
- $income_products_5ago=0;
- $income_products_6ago=0;
- $income_products_7ago=0;
- $clients_today=0;
- $clients_1ago=0;
- $clients_2ago=0;
- $clients_3ago=0;
- $clients_4ago=0;
- $clients_5ago=0;
- $clients_6ago=0;
- $clients_7ago=0;
- $ticket_today=0;
- $ticket_1ago=0;
- $ticket_2ago=0;
- $ticket_3ago=0;
- $ticket_4ago=0;
- $ticket_5ago=0;
- $ticket_6ago=0;
- $ticket_7ago=0;
- $ticketcount_today=0;
- $ticketcount_1ago=0;
- $ticketcount_2ago=0;
- $ticketcount_3ago=0;
- $ticketcount_4ago=0;
- $ticketcount_5ago=0;
- $ticketcount_6ago=0;
- $ticketcount_7ago=0;
- $income_services_today=0;
- $income_services_1ago=0;
- $income_services_2ago=0;
- $income_services_3ago=0;
- $income_services_4ago=0;
- $income_services_5ago=0;
- $income_services_6ago=0;
- $income_services_7ago=0;
- if(UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->count()>0) {
- foreach($users as $user){$income_products_today+=$this->getIncomeProductsSubday(0,$user);};
- foreach($users as $user){$income_products_1ago+=$this->getIncomeProductsSubday(1,$user);};
- foreach($users as $user){$income_products_2ago+=$this->getIncomeProductsSubday(2,$user);};
- foreach($users as $user){$income_products_3ago+=$this->getIncomeProductsSubday(3,$user);};
- foreach($users as $user){$income_products_4ago+=$this->getIncomeProductsSubday(4,$user);};
- foreach($users as $user){$income_products_5ago+=$this->getIncomeProductsSubday(5,$user);};
- foreach($users as $user){$income_products_6ago+=$this->getIncomeProductsSubday(6,$user);};
- foreach($users as $user){$income_products_7ago+=$this->getIncomeProductsSubday(7,$user);};
- foreach($users as $user){$clients_today+=$this->getIncomeClientCountSubday(0,$user);};
- foreach($users as $user){$clients_1ago+=$this->getIncomeClientCountSubday(1,$user);};
- foreach($users as $user){$clients_2ago+=$this->getIncomeClientCountSubday(2,$user);};
- foreach($users as $user){$clients_3ago+=$this->getIncomeClientCountSubday(3,$user);};
- foreach($users as $user){$clients_4ago+=$this->getIncomeClientCountSubday(4,$user);};
- foreach($users as $user){$clients_5ago+=$this->getIncomeClientCountSubday(5,$user);};
- foreach($users as $user){$clients_6ago+=$this->getIncomeClientCountSubday(6,$user);};
- foreach($users as $user){$clients_7ago+=$this->getIncomeClientCountSubday(7,$user);};
- foreach($users as $user){$ticket_today+=$this->getTicketAvSubday(0,$user);};
- foreach($users as $user){$ticket_1ago+=$this->getTicketAvSubday(1,$user);};
- foreach($users as $user){$ticket_2ago+=$this->getTicketAvSubday(2,$user);};
- foreach($users as $user){$ticket_3ago+=$this->getTicketAvSubday(3,$user);};
- foreach($users as $user){$ticket_4ago+=$this->getTicketAvSubday(4,$user);};
- foreach($users as $user){$ticket_5ago+=$this->getTicketAvSubday(5,$user);};
- foreach($users as $user){$ticket_6ago+=$this->getTicketAvSubday(6,$user);};
- foreach($users as $user){$ticket_7ago+=$this->getTicketAvSubday(7,$user);};
- foreach($users as $user){$ticketcount_today+=$this->getTicketCountSubday(0,$user);};
- foreach($users as $user){$ticketcount_1ago+=$this->getTicketCountSubday(1,$user);};
- foreach($users as $user){$ticketcount_2ago+=$this->getTicketCountSubday(2,$user);};
- foreach($users as $user){$ticketcount_3ago+=$this->getTicketCountSubday(3,$user);};
- foreach($users as $user){$ticketcount_4ago+=$this->getTicketCountSubday(4,$user);};
- foreach($users as $user){$ticketcount_5ago+=$this->getTicketCountSubday(5,$user);};
- foreach($users as $user){$ticketcount_6ago+=$this->getTicketCountSubday(6,$user);};
- foreach($users as $user){$ticketcount_7ago+=$this->getTicketCountSubday(7,$user);};
- foreach($users as $user){$income_services_today+=$this->getIncomeSubday(0,$user);};
- foreach($users as $user){$income_services_1ago+=$this->getIncomeSubday(1,$user);};
- foreach($users as $user){$income_services_2ago+=$this->getIncomeSubday(2,$user);};
- foreach($users as $user){$income_services_3ago+=$this->getIncomeSubday(3,$user);};
- foreach($users as $user){$income_services_4ago+=$this->getIncomeSubday(4,$user);};
- foreach($users as $user){$income_services_5ago+=$this->getIncomeSubday(5,$user);};
- foreach($users as $user){$income_services_6ago+=$this->getIncomeSubday(6,$user);};
- foreach($users as $user){$income_services_7ago+=$this->getIncomeSubday(7,$user);};
- }
- /*
- * END CICLO FOREACH USER
- */
- $data = [
- 'test' => $test,
- //'business' => DB::connection('mysql2')->table('business_details')->select('size')->where('user_id',$user->user_id)->first(),
- 'bookings_week' => $bookings_week,
- 'bookings_gainedlost' => abs($bookings_week - $bookings_twomonthago),
- 'bookings_ispositive' => ($bookings_week - $bookings_twomonthago >= 1) ? true : false,
- 'clients_week' => $clients_week,
- 'clients_gainedlost' => abs($clients_week - $clients_twomonthago),
- 'clients_ispositive' => ($clients_week - $clients_twomonthago >= 1) ? true : false,
- 'sales_week' => $sales_week,
- 'sales_gainedlost' => abs($sales_week - $sales_twomonthago),
- 'sales_ispositive' => ($sales_week - $sales_twomonthago >= 1) ? true : false,
- 'income_month' => $income_month,
- 'income_gainedlost' => abs($income_month - $income_twomonthago),
- 'income_ispositive' => ($income_month - $income_twomonthago >= 1) ? true : false,
- # CITAS COMPLETADAS LA ÚLTIMA SEMANA
- 'bookings_completed_today' => (isset($bookings_completed_today)) ? $bookings_completed_today : 0,
- 'bookings_completed_1ago' => (isset($bookings_completed_1ago)) ? $bookings_completed_1ago : 0,
- 'bookings_completed_2ago' => (isset($bookings_completed_2ago)) ? $bookings_completed_2ago : 0,
- 'bookings_completed_3ago' => (isset($bookings_completed_3ago)) ? $bookings_completed_3ago : 0,
- 'bookings_completed_4ago' => (isset($bookings_completed_4ago)) ? $bookings_completed_4ago : 0,
- 'bookings_completed_5ago' => (isset($bookings_completed_5ago)) ? $bookings_completed_5ago : 0,
- 'bookings_completed_6ago' => (isset($bookings_completed_6ago)) ? $bookings_completed_6ago : 0,
- # CITAS CANCELADAS LA ÚLTIMA SEMANA
- 'bookings_cancelled_today' => (isset($bookings_cancelled_today)) ? $bookings_cancelled_today : 0,
- 'bookings_cancelled_1ago' => (isset($bookings_cancelled_1ago)) ? $bookings_cancelled_1ago : 0,
- 'bookings_cancelled_2ago' => (isset($bookings_cancelled_2ago)) ? $bookings_cancelled_2ago : 0,
- 'bookings_cancelled_3ago' => (isset($bookings_cancelled_3ago)) ? $bookings_cancelled_3ago : 0,
- 'bookings_cancelled_4ago' => (isset($bookings_cancelled_4ago)) ? $bookings_cancelled_4ago : 0,
- 'bookings_cancelled_5ago' => (isset($bookings_cancelled_5ago)) ? $bookings_cancelled_5ago : 0,
- 'bookings_cancelled_6ago' => (isset($bookings_cancelled_6ago)) ? $bookings_cancelled_6ago : 0,
- # CITAS PENDIENTES LA ÚLTIMA SEMANA
- 'bookings_pending_today' => (isset($bookings_pending_today)) ? $bookings_pending_today : 0,
- 'bookings_pending_1ago' => (isset($bookings_pending_1ago)) ? $bookings_pending_1ago : 0,
- 'bookings_pending_2ago' => (isset($bookings_pending_2ago)) ? $bookings_pending_2ago : 0,
- 'bookings_pending_3ago' => (isset($bookings_pending_3ago)) ? $bookings_pending_3ago : 0,
- 'bookings_pending_4ago' => (isset($bookings_pending_4ago)) ? $bookings_pending_4ago : 0,
- 'bookings_pending_5ago' => (isset($bookings_pending_5ago)) ? $bookings_pending_5ago : 0,
- 'bookings_pending_6ago' => (isset($bookings_pending_6ago)) ? $bookings_pending_6ago : 0,
- # CITAS DISPONIBLES LA ÚLTIMA SEMANA
- 'bookings_available_today' => (isset($bookings_available_today)) ? $bookings_available_today : 0,
- 'bookings_available_1ago' => (isset($bookings_available_1ago)) ? $bookings_available_1ago : 0,
- 'bookings_available_2ago' => (isset($bookings_available_2ago)) ? $bookings_available_2ago : 0,
- 'bookings_available_3ago' => (isset($bookings_available_3ago)) ? $bookings_available_3ago : 0,
- 'bookings_available_4ago' => (isset($bookings_available_4ago)) ? $bookings_available_4ago : 0,
- 'bookings_available_5ago' => (isset($bookings_available_5ago)) ? $bookings_available_5ago : 0,
- 'bookings_available_6ago' => (isset($bookings_available_6ago)) ? $bookings_available_6ago : 0,
- # INGRESOS PRODUCTOS LA ÚLTIMA SEMANA
- 'income_products_today' => $income_products_today,
- 'income_products_1ago' => $income_products_1ago,
- 'income_products_2ago' => $income_products_2ago,
- 'income_products_3ago' => $income_products_3ago,
- 'income_products_4ago' => $income_products_4ago,
- 'income_products_5ago' => $income_products_5ago,
- 'income_products_6ago' => $income_products_6ago,
- 'income_products_7ago' => $income_products_7ago,
- # CLIENTES LA ÚLTIMA SEMANA
- 'clients_today' => $clients_today,
- 'clients_1ago' => $clients_1ago,
- 'clients_2ago' => $clients_2ago,
- 'clients_3ago' => $clients_3ago,
- 'clients_4ago' => $clients_4ago,
- 'clients_5ago' => $clients_5ago,
- 'clients_6ago' => $clients_6ago,
- 'clients_7ago' => $clients_7ago,
- # TICKETS LA ÚLTIMA SEMANA
- 'ticket_today' => $ticket_today,
- 'ticket_1ago' => $ticket_1ago,
- 'ticket_2ago' => $ticket_2ago,
- 'ticket_3ago' => $ticket_3ago,
- 'ticket_4ago' => $ticket_4ago,
- 'ticket_5ago' => $ticket_5ago,
- 'ticket_6ago' => $ticket_6ago,
- 'ticket_7ago' => $ticket_7ago,
- # contador de TICKETS LA ÚLTIMA SEMANA
- 'ticketcount_today' => $ticketcount_today,
- 'ticketcount_1ago' => $ticketcount_1ago,
- 'ticketcount_2ago' => $ticketcount_2ago,
- 'ticketcount_3ago' => $ticketcount_3ago,
- 'ticketcount_4ago' => $ticketcount_4ago,
- 'ticketcount_5ago' => $ticketcount_5ago,
- 'ticketcount_6ago' => $ticketcount_6ago,
- 'ticketcount_7ago' => $ticketcount_7ago,
- # INGRESOS SERVICIOS LA ÚLTIMA SEMANA
- 'income_services_today' => $income_services_today,
- 'income_services_1ago' => $income_services_1ago,
- 'income_services_2ago' => $income_services_2ago,
- 'income_services_3ago' => $income_services_3ago,
- 'income_services_4ago' => $income_services_4ago,
- 'income_services_5ago' => $income_services_5ago,
- 'income_services_6ago' => $income_services_6ago,
- 'income_services_7ago' => $income_services_7ago,
- #'test' => $this->getIncomeSubday(0),
- 'test' => \Carbon\Carbon::now()->subDay(0)->format('n/j/Y'),
- 'users'=>$all_users_ids,
- 'selected_users'=>$selected_users,
- ];
- #return dd($this->getTopClients());
- # SAVE LAST TIME USER WAS ACTIVE, WE ARE USING "DASHBOARD" AS THE USER LANDS HERE EVERYTIME IT LOGS IN
- //try { UserLilu::where('user_id',$user->user_id)->update([ 'last_login'=> \Carbon\Carbon::now() ]); } catch(Exception $e) { }
- /*Cookie::queue('name', 'Jose', 60);
- return response('Set cookie');*/
- /*$created = \Carbon\Carbon::parse($user->conekta_trial_endsat);
- $now = \Carbon\Carbon::now();
- $days_left = $now->diff($created)->format("%r%a");
- if($days_left >= 0 && $days_left <= 5) {
- if(!isset($_COOKIE['trial_message_lilu'])) {
- #setcookie('trial_message_lilu','0',3600*6);
- }
- }
- \Cookie::make('trial_message_lilu','0',3600*6);
- $ok = (\Cookie::get('trial_message_lilu')) ? 'Existe' : 'No existe';
- dd($ok);*/
- return view('home',$data);
- }
- public function getBookingsCount($days,$user) {
- $date = \Carbon\Carbon::now()->subDay($days)->format('n/j/Y');
- $count = Booking::where('user_id',$user->user_id)->where('start_date','like','%'.$date.'%')->where('status',2)->whereNull('deleted_at')->get()->count();
- return $count;
- }
- public function getIncomeSubday($days,$user) {
- date_default_timezone_set("America/Mexico_City");
- $date = \Carbon\Carbon::now()->subDay($days)->format('n/j/Y');
- $services = Booking::where('user_id',$user->user_id)->where('start_date','like','%'.$date.'%')->where('status',2)->whereNull('deleted_at')->get();
- $total =0;
- foreach($services as $res) {
- if($res->discount!=0)
- $total += $res->price - ($res->price * ($res->discount/100));
- else
- $total += $res->price;
- }
- return $total;
- }
- public function getIncomeProductsSubday($days,$user) {
- $date = \Carbon\Carbon::now()->subDay($days)->toDateString();
- $from_products = Sale::where('user_id',$user->user_id)
- ->where('created_at','like','%'.$date.'%')
- ->whereNull('deleted_at')
- ->get()
- ->sum('total');
- return $from_products;
- }
- public function getIncomeClientCountSubday($days,$user) {
- $date = \Carbon\Carbon::now()->subDay($days)->toDateString();
- $from_clients = Client::where('user_id',$user->user_id)
- ->where('created_at','like','%'.$date.'%')
- ->whereNull('deleted_at')
- ->count();
- return $from_clients;
- }
- public function getTicketAvSubday($days,$user) {
- $date = \Carbon\Carbon::now()->subDay($days)->toDateString();
- $from_tickets = Ticket::where('user_id',$user->user_id)
- ->where('finalized_at','like','%'.$date.'%')
- ->whereNull('deleted_at')
- ->sum('total1');
- return $from_tickets;
- }
- public function getTicketCountSubday($days,$user) {
- $date = \Carbon\Carbon::now()->subDay($days)->toDateString();
- $from_tickets = Ticket::where('user_id',$user->user_id)
- ->where('finalized_at','like','%'.$date.'%')
- ->whereNull('deleted_at')
- ->count();
- return $from_tickets;
- }
- public function clients() {
- $data = [
- 'users' => DB::connection('mysql2')->table('users')->where('role',1)->whereNull('deleted_at')->orderBy('last_login','desc')->get(),
- ];
- return view('clients',$data);
- }
- public function demo() {
- $data['demo'] = DB::connection('mysql2')->table('demo')->whereNull('deleted_at')->orderBy('created_at','asc')->get();
- return view('demo',$data);
- }
- public function promociones() {
- $data = [
- 'promos' => DB::connection('mysql2')->table('promocodes')->whereNull('deleted_at')->get(),
- ];
- return view('promociones',$data);
- }
- public function promocionesPost() {
- $name = Input::get('name');
- $code = Input::get('code');
- $price = Input::get('price');
- $stock = Input::get('stock');
- $expires = Input::get('expires');
- date_default_timezone_set("America/Mexico_City");
- $created_at = new \DateTime();
- DB::connection('mysql2')->table('promocodes')->insert([
- 'name' => $name,
- 'code' => $code,
- 'price' => $price,
- 'stock' => $stock,
- 'created_at' => $created_at,
- ]);
- return Redirect::route('promociones');
- }
- public function getDashboardTopClients() {
- if(count(Input::get('user_ids'))>0){
- $users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->whereIn('user_id',Input::get('user_ids'))->select('user_id')->get();
- foreach($users as $user){
- $selected_users[]=$user->user_id;
- }
- }else{
- $users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->get();
- foreach($users as $user){
- $selected_users[]=$user->user_id;
- }
- }
- $clients = Client::select('id','user_id','name','lastname')->whereIn('user_id',$selected_users)->whereNull('deleted_at')->get();
- $i=0;
- foreach($clients as $client) {
- $bookings = collect(Booking::select('ticket_total','ticket_total2')->where('user_id',$client->user_id)->where('client_id',$client->id)->where('status',2)->whereNull('parent_booking')->whereNull('deleted_at')->get());
- $transactions = collect(Transaction::select('ticket_total','ticket_total2')->where('user_id',$client->user_id)->where('client_id',$client->id)->whereNull('event_id')->whereNull('deleted_at')->get());
- $tickets = $bookings->merge($transactions);
- $x=0;
- foreach($tickets as $res) {
- $x += $res->ticket_total + $res->ticket_total2;
- }
- $ret[$i] = [
- 'client_id' => $client->id,
- 'client' => $client->lastname.' '.$client->name,
- 'total' => $x,
- ];
- $i++;
- }
- $collection = collect($ret)->sortByDesc('total')->take(10);
- $i=0;
- foreach($collection as $res) {
- $ok[$i] = [
- 'client' => str_limit($res['client'],20),
- 'total' => '$'.number_format((int)$res['total']),
- ];
- $i++;
- }
- return $ok;
- }
- public function getDashboardStock() {
- /*$products = Product::select('id','name','product_category','product_class','stock')->where('user_id',Auth::user()->user_id)->whereNull('deleted_at')->orderBy('stock','asc')->get()->take(10);
- $i=0;
- foreach($products as $res) {
- try {
- $category = ProductCategory::where('id',$res->product_category)->first()->name;
- } catch(Exception $e) { $category = '-';}
- try {
- $make = ProductClass::where('id',$res->product_class)->first()->name;
- } catch(Exception $e) { $make = '-';}
- $ok[$i] = [
- 'nombre' => str_limit($res->name,15),
- 'stock' => str_limit($res->stock,15),
- 'marca' => str_limit($make,15),
- 'categoria' => $category,
- ];
- $i++;
- }
- return $ok;*/
- if(count(Input::get('user_ids'))>0){
- $users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->whereIn('user_id',Input::get('user_ids'))->select('user_id')->get();
- foreach($users as $user){
- $selected_users[]=$user->user_id;
- }
- }else{
- $users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->get();
- foreach($users as $user){
- $selected_users[]=$user->user_id;
- }
- }
- $products = Product::select('id','name','product_category','product_class','stock')->whereIn('user_id',$selected_users)->whereNull('deleted_at')->orderBy('stock','asc')->get();
- $i=0;
- $return = null;
- $ok=[];
- foreach($products as $res) {
- try {
- $category = (ProductCategory::where('id',$res->product_category)->count()) ? ProductCategory::where('id',$res->product_category)->first()->name : '-';
- } catch(Exception $e) { $category = '-';}
- try {
- $make = (ProductClass::where('id',$res->product_class)->count()) ? ProductClass::where('id',$res->product_class)->first()->name : '-';
- } catch(Exception $e) { $make = '-';}
- $sales = Sale::where('product_id',$res->id)->get();
- $sum = 0;
- if($sales->count()) {
- foreach($sales as $sale) {
- $sum += $sale->total;
- }
- }
- $ok[] = [
- 'nombre' => str_limit($res->name,15),
- 'sum' => $sum,
- 'marca' => str_limit($make,15),
- 'categoria' => $category,
- ];
- $i++;
- }
- if(count($ok)){
- $collection = collect($ok)->keyBy('sum')->sortByDesc('sum')->take(10);
- $i=0;
- foreach($collection as $res) {
- $xd[] = [
- 'nombre' => $res['nombre'],
- 'sum' => '$'.number_format((int)$res['sum']),
- 'marca' => $res['marca'],
- 'categoria' => $res['categoria'],
- ];
- $i++;
- }
- return $xd;
- }else{
- $xd[0] = [
- 'nombre' => '-',
- 'sum' => '-',
- 'marca' => '-',
- 'categoria' => '-',
- ];
- return $xd;
- }
- }
- public function getDashboardServicesSold(){
- /*try{
- $topServiceCategories=Booking::join('services', 'bookings.service_id', '=', 'services.id')->select('services.service_category', DB::raw('count(*) as total'),DB::raw('sum(bookings.price*(bookings.discount/100)) as ganancias'))->where('bookings.user_id',Auth::user()->user_id)->whereNull('bookings.deleted_at')->groupBy('services.service_category')->orderBy('ganancias','DESC')->pluck('services.service_category')->take(10);
- }catch(Exception $e){
- $topServiceCategories=Booking::join('services', 'bookings.service_id', '=', 'services.id')->select('services.service_category', DB::raw('count(*) as total'),DB::raw('sum(bookings.price) as ganancias'))->where('bookings.user_id',Auth::user()->user_id)->whereNull('bookings.deleted_at')->groupBy('services.service_category')->orderBy('ganancias','DESC')->pluck('services.service_category')->take(10);
- }*/
- if(count(Input::get('user_ids'))>0){
- $users=Input::get('user_ids');
- }else{
- $users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->pluck('user_id');
- }
- //$users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->pluck('user_id');
- $topServiceCategories=Booking::join('services', 'bookings.service_id', '=', 'services.id')->when('bookings.discount'>0, function ($query){
- return $query->select('services.service_category', DB::raw('count(*) as total'),DB::raw('sum(bookings.price -(bookings.price*(bookings.discount/100))) as ganancias'));
- }, function ($query) {
- return $query->select('services.service_category', DB::raw('count(*) as total'),DB::raw('sum(bookings.price) as ganancias'));
- })->whereIn('bookings.user_id',$users)->whereNull('bookings.deleted_at')->groupBy('services.service_category')->orderBy('ganancias','DESC')->pluck('services.service_category');#->take(10);
- //$topServiceCategories=Booking::join('services', 'bookings.service_id', '=', 'services.id')->select('services.service_category', DB::raw('count(*) as total'),DB::raw('sum(bookings.price) as ganancias'))->where('bookings.user_id',Auth::user()->user_id)->whereNull('bookings.deleted_at')->groupBy('services.service_category')->orderBy('ganancias','DESC')->pluck('services.service_category')->take(10);
- $topServices_names=[];
- $a=0;
- $booking_sales_service_categories=[];
- foreach($topServiceCategories as $topServiceCategory){
- $service_category=ServiceCategory::whereIn('user_id',$users)->where('id',$topServiceCategory)->get()->first();
- $topServices_names[]=$service_category['name'];
- $booking_total_7_days=[];
- for($i=0;$i<=7;$i++){
- $day=Carbon::now()->subDay($i)->toDateString();
- $bookingsInDay=Booking::join('services', 'bookings.service_id', '=', 'services.id')->whereIn('bookings.user_id',$users)->whereNull('bookings.deleted_at')->Where('services.service_category',$topServiceCategory)->where('bookings.created_at','like','%'.$day.'%')->get();
- $totalSalesBookingInDay=0;
- foreach( $bookingsInDay as $bookingInDay){
- if ($bookingInDay->discount!=0){
- $totalSalesBookingInDay+=$bookingInDay->price -($bookingInDay->price * ($bookingInDay->discount/100));
- }else{
- $totalSalesBookingInDay+=$bookingInDay->price;
- }
- }
- $booking_total_7_days[]=$totalSalesBookingInDay;
- }
- $booking_sales_service_categories[$a]=$booking_total_7_days;
- $a++;
- }
- $otherServiceCategories=ServiceCategory::whereIn('user_id',$users)->whereNotIn('id',$topServiceCategories)->get();
- $other=0;
- $other_booking_sales_service_categories=[];
- foreach($otherServiceCategories as $otherServiceCategory){
- for($i=0;$i<=7;$i++) {
- $day = Carbon::now()->subDay($i)->toDateString();
- $other_bookingsInDay = Booking::join('services', 'bookings.service_id', '=', 'services.id')->whereIn('bookings.user_id', $users)->whereNull('bookings.deleted_at')->Where('services.service_category',$otherServiceCategory['id'])->where('bookings.created_at', 'like', '%' . $day . '%')->get();
- $other_totalSalesBookingInDay = 0;
- foreach ($other_bookingsInDay as $other_bookingInDay) {
- if ($other_bookingInDay->discount != 0) {
- $other_totalSalesBookingInDay += $other_bookingInDay->price -($other_bookingInDay->price * ($other_bookingInDay->discount / 100));
- } else {
- $other_totalSalesBookingInDay += $other_bookingInDay->price;
- }
- }
- $other_category_booking_total_7_days[] = $other_totalSalesBookingInDay;
- }
- $other_booking_sales_service_categories[$other]=$other_category_booking_total_7_days;
- $other++;
- }
- //return $other_booking_sales_service_categories;
- /*for($i=0;$i<7;$i++){
- $value = array_sum(array_column($other_booking_sales_service_categories,$i));
- return $value;
- }*/
- $one=0;
- $two=0;
- $tree=0;
- $four=0;
- $five=0;
- $six=0;
- $seven=0;
- $eight=0;
- foreach ($other_booking_sales_service_categories as $subArray) {
- $one += $subArray[0];
- $two += $subArray[1];
- $tree+= $subArray[2];
- $four+= $subArray[3];
- $five+= $subArray[4];
- $six += $subArray[5];
- $seven+= $subArray[6];
- $eight+= $subArray[7];
- /*foreach ($subArray as $id=>$value) {
- $sumArray[$id]+=$value;
- }*/
- }
- if($one+$two+$tree+$four+$five+$six+$seven+$eight > 0)
- $resultss=[$one,$two,$tree,$four,$five,$six,$seven,$eight];
- else
- $resultss=false;
- $dataBookings=['topServices_names'=>$topServices_names,'data'=>$booking_sales_service_categories,'others_data'=>$resultss];
- return $dataBookings;
- }
- public function getDashboardProductsSold() {
- /*$topProductBrands=Sale::where('sales.user_id',Auth::user()->user_id)
- ->join('products','sales.product_id','=','products.id')
- ->join('product_category','products.product_category','=','product_category.id')
- ->select('products.product_category', DB::raw('count(*) as total'),DB::raw('sum(sales.total) as ganancias'))
- ->whereNull('sales.deleted_at')
- ->groupBy('products.product_category')
- ->orderBy('ganancias','DESC')
- ->get()
- ->take(10)
- ;*/
- if(count(Input::get('user_ids'))>0){
- $users=Input::get('user_ids');
- }else{
- $users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->pluck('user_id');
- }
- //$users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->pluck('user_id');
- //$user=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->get()->first();
- $products = Product::select('id','name','product_category','product_class','stock')->whereIn('user_id',$users)->whereNull('deleted_at')->orderBy('stock','asc')->get();
- $i=0;
- $return = null;
- foreach($products as $res) {
- try {
- $category = (ProductCategory::where('id',$res->product_category)->count()) ? ProductCategory::where('id',$res->product_category)->first()->name : '-';
- } catch(Exception $e) { $category = '-';}
- try {
- $make = (ProductClass::where('id',$res->product_class)->count()) ? ProductClass::where('id',$res->product_class)->first()->name : '-';
- } catch(Exception $e) { $make = '-';}
- $sales = Sale::where('product_id',$res->id)->get();
- $sum = 0;
- if($sales->count()) {
- foreach($sales as $sale) {
- $sum += $sale->total;
- }
- }
- $ok[] = [
- 'id'=>$res->id,
- 'nombre' => str_limit($res->name,15),
- 'sum' => $sum,
- 'marca' => str_limit($make,15),
- 'categoria' => $category,
- ];
- $i++;
- }
- $collection = collect($ok)->keyBy('sum')->sortByDesc('sum');#->take(10);
- $i=0;
- $product_names=[];
- foreach($collection as $res) {
- $product_names[]=$res['nombre'];
- $xd[] = [
- 'id'=>$res['id'],
- 'nombre' => $res['nombre'],
- 'sum' => '$'.number_format((int)$res['sum']),
- 'marca' => $res['marca'],
- 'categoria' => $res['categoria'],
- ];
- $xd_ids[]=$res['id'];
- $i++;
- }
- $a=0;
- foreach($xd as $product){
- //$salesInDay=0;
- $product_day =[];
- for($i=0;$i<=7;$i++){
- $day=Carbon::now()->subDay($i)->toDateString();
- $salesInDay=Sale::whereIn('user_id',$users)->where('product_id',$product['id'])->where('created_at','like','%'.$day.'%')->whereNull('deleted_at')->get();
- $totalSalesProductInDay=0;
- foreach($salesInDay as $saleInDay){
- if($saleInDay->discount!=0){
- $totalSalesProductInDay+=$saleInDay->total * ($saleInDay->discount/100);
- }else{
- $totalSalesProductInDay+=$saleInDay->total;
- }
- }
- $product_day[]=$totalSalesProductInDay;
- }
- $products_sales[$a]=$product_day;
- $a++;
- }
- $b=0;
- $otherProducts = Product::select('id','name','product_category','product_class','stock')->whereIn('user_id',$users)->whereNotIn('id',$xd_ids)->whereNull('deleted_at')->orderBy('stock','asc')->get();
- foreach($otherProducts as $product){
- $other_product_day =[];
- for($i=0;$i<=7;$i++){
- $day=Carbon::now()->subDay($i)->toDateString();
- $other_salesInDay=Sale::whereIn('user_id',$users)->where('product_id',$product['id'])->where('created_at','like','%'.$day.'%')->whereNull('deleted_at')->get();
- $other_totalSalesProductInDay=0;
- foreach($other_salesInDay as $other_saleInDay){
- if($other_saleInDay->discount!=0){
- $other_totalSalesProductInDay+=$other_saleInDay->total * ($other_saleInDay->discount/100);
- }else{
- $other_totalSalesProductInDay+=$other_saleInDay->total;
- }
- }
- $other_product_day[]=$other_totalSalesProductInDay;
- }
- $other_products_sales[$b]=$other_product_day;
- $b++;
- }
- if(empty($other_products_sales)){
- $other_products_sales[]=0;
- };
- $sumArray = [];
- $one=0;
- $two=0;
- $tree=0;
- $four=0;
- $five=0;
- $six=0;
- $seven=0;
- $eight=0;
- foreach ($other_products_sales as $subArray) {
- $one += $subArray[0];
- $two += $subArray[1];
- $tree+= $subArray[2];
- $four+= $subArray[3];
- $five+= $subArray[4];
- $six += $subArray[5];
- $seven+= $subArray[6];
- $eight+= $subArray[7];
- }
- if($one+$two+$tree+$four+$five+$six+$seven+$eight > 0)
- $other_products_sales=[$one,$two,$tree,$four,$five,$six,$seven,$eight];
- else
- $other_products_sales=false;
- $dataProducts=['product_names'=>$product_names,'data'=>$products_sales,'others_data'=>$other_products_sales];
- return $dataProducts;
- }
- public function getDashboardGraphSchedule(){
- $morning=0;
- $midday=0;
- $noon=0;
- $afternoon=0;
- $night=0;
- if(count(Input::get('user_ids'))>0){
- $users=Input::get('user_ids');
- }else{
- $users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->pluck('user_id');
- }
- $tickets=Ticket::whereIn('user_id',$users)->whereNull('deleted_at')->get();
- foreach($tickets as $ticket){
- switch(true){
- case ($ticket->created_at->format('H:i:s')>='09:00:01')&& ($ticket->created_at->format('H:i:s')<='11:00:00'):
- $morning+=1;
- break;
- case ($ticket->created_at->format('H:i:s')>='11:00:01')&& ($ticket->created_at->format('H:i:s')<='14:00:00'):
- $midday+=1;
- break;
- case ($ticket->created_at->format('H:i:s')>='14:00:01')&& ($ticket->created_at->format('H:i:s')<='17:00:00'):
- $noon+=1;
- break;
- case ($ticket->created_at->format('H:i:s')>='17:00:01')&& ($ticket->created_at->format('H:i:s')<='20:00:00'):
- $afternoon+=1;
- break;
- case ($ticket->created_at->format('H:i:s')>='20:00:01')&& ($ticket->created_at->format('H:i:s')<='11:59:59'):
- $night+=1;
- break;
- }
- }
- $schdule_morning=[ 'name'=>'9am - 11am','y'=>$morning ];
- $schdule_midday=[ 'name'=>'11am - 2pm','y'=>$midday ];
- $schdule_noon=[ 'name'=>'2pm - 5pm','y'=>$noon ];
- $schdule_afternoon=[ 'name'=>'5pm - 8pm','y'=>$afternoon ];
- $schdule_night=[ 'name'=>'8pm+','y'=>$night ];
- $dataSchedule=[$schdule_morning,$schdule_midday,$schdule_noon,$schdule_afternoon,$schdule_night];
- return $dataSchedule;
- }
- public function getDashboardTicketDays(){
- if(count(Input::get('user_ids'))>0){
- $users=Input::get('user_ids');
- }else{
- $users=UserLilu::where('franchise_id',Auth::user()->franchise_id)->groupBy('user_id')->select('user_id')->pluck('user_id');
- }
- $business = Business::whereIn('user_id',$users)->first(); # CHECK, IT WAS 'ID' CHANGED TO 'USER_ID'
- $today = \Carbon\Carbon::now()->format('m/d/Y');
- $monthAgo=\Carbon\Carbon::now()->subMonth(1)->format('m/d/Y');
- $bookingsAgo=Booking::whereIn('user_id',$users)->where('status',2)->whereNull('deleted_at')->get();
- # SALES
- $sales=0;
- $sales_mon=0;
- $sales_tues=0;
- $sales_wed=0;
- $sales_thu=0;
- $sales_fri=0;
- $sales_satu=0;
- $sales_sun=0;
- $salesAgo=Sale::whereIn('user_id',$users)->whereNull('deleted_at')->get();
- foreach($salesAgo as $sale){
- $carbon_date= Carbon::parse($sale->created_at) ;
- switch($carbon_date->format('l')){
- case 'Monday': $sales_mon+=1; break;
- case 'Tuesday': $sales_tues+=1; break;
- case 'Wednesday': $sales_wed+=1; break;
- case 'Thursday': $sales_thu+=1; break;
- case 'Friday': $sales_fri+=1; break;
- case 'Saturday': $sales_satu+=1; break;
- case 'Sunday': $sales_sun+=1; break;
- }
- }
- # END SALES
- $mon=0;
- $tues=0;
- $wed=0;
- $thu=0;
- $fri=0;
- $satu=0;
- $sun=0;
- foreach($bookingsAgo as $booking){
- $carbon_start_date= Carbon::parse($booking->start_date) ;
- switch($carbon_start_date->format('l')){
- case 'Monday': $mon+=1; break;
- case 'Tuesday': $tues+=1; break;
- case 'Wednesday': $wed+=1; break;
- case 'Thursday': case 'Friday': $fri+=1; break;
- case 'Saturday': $satu+=1; break;
- case 'Sunday': $sun+=1; break;
- }
- }
- $services=[$mon,$tues,$wed,$thu,$fri,$satu,$sun];
- $products=[$sales_mon,$sales_tues,$sales_wed,$sales_thu,$sales_fri,$sales_satu,$sales_sun];
- $dataBooking=['services'=>$services,'products'=>$products];
- return $dataBooking;
- }
- public function user_settings(){
- return view('settings.index');
- }
- public function change_password(){
- $data = Input::only(
- 'old_password',
- 'new_password'
- );
- $rules = array(
- 'old_password' => 'required|min:4',
- 'new_password' => 'required|min:4',
- );
- $validator = \Illuminate\Support\Facades\Validator::make($data, $rules);
- if ($validator->passes()) {
- if (Hash::check(Input::get('old_password'), Auth::user()->password)) {
- Auth::user()->password=Hash::make(Input::get('new_password'));
- Auth::user()->save();
- return redirect()->back()->with('global-success', 'Contraseña guardada correctamente');
- }else{
- return redirect()->back()->with('global-error', 'La contraseña es incorrecta');
- }
- }else{
- return redirect()->back()->with('global-error', 'La contraseña debe ser de más de 3 caracteres');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement