public function permission_index()
 {
     $president_id = Auth::user()->id;
     $users = User::with('AssigmentRole')->with('Neighbors')->paginate(10);
     $president_urbanism = Neighbors::with('NeighborProperty')->findOrFail($president_id);
     foreach ($president_urbanism->NeighborProperty as $row) {
         $urbanism_id = $row->urbanism_id;
         $neighbors = NeighborProperty::where('urbanism_id', '=', $urbanism_id)->get();
     }
     $roles = Role::orderBy('id', 'ASC')->lists('name', 'id');
     return View::make('dashboard.admin.permission.index', ['select' => ['' => 'Seleccione'], 'neighbors' => $neighbors, 'roles' => $roles, 'users' => $users]);
 }
 public function confirm_data_fam($code)
 {
     if (!$code) {
         $error_msg = new InvalidConfirmationCodeException();
         return Redirect::action('UsersController@login')->with('error', $error_msg);
     }
     $confirm = InvitedNeighbors::where('Confirmation_code', '=', $code)->first();
     if (!$confirm) {
         $error_msg = Lang::get('confide::confide.alerts.wrong_confirmation');
         return Redirect::action('UsersController@login')->with('error', $error_msg);
     }
     if (!$confirm->confirmed) {
         $email = $confirm->email;
         $reg_user = User::where('email', '=', $email)->first();
         if ($reg_user) {
             $reg_neighbor = Neighbors::where('user_id', '=', $reg_user->id)->first();
             $property = NeighborProperty::where('neighbors_id', '=', $reg_neighbor->id)->first();
             $urbanism_id = $confirm->urbanism_id;
             $urbanism = Urbanism::findOrFail($urbanism_id);
             $urbanism_name = $urbanism->name;
             $urbanism_type = $urbanism->urbanism_type_id;
             if ($urbanism_type == 3) {
                 $catalog = BuildingCatalog::where('urbanism_id', '=', $urbanism_id)->first();
             } else {
                 $catalog = StreetCatalog::where('urbanism_id', '=', $urbanism_id)->first();
             }
             $notice_msg = Lang::get('confide::confide.alerts.confirmation_invitation');
             return View::make('dashboard.neighbors.edit_fam', ['email' => $email, 'urbanism' => $urbanism_name, 'urbanism_id' => $urbanism_id, 'code' => $code, 'urbanism_type' => $urbanism_type, 'catalog' => $catalog, 'neighbor' => $reg_neighbor, 'property' => $property, 'notice' => $notice_msg]);
         } else {
             return Redirect::action('ConfirmationController@confirm', $code);
         }
     } else {
         $notice_msg = 'Acceda a Habitaria con su usuario creado';
         return Redirect::action('UsersController@login')->with('notice', $notice_msg);
     }
 }
 public function modalEstadoCuenta()
 {
     $neighbor_property_id = Input::get('neighbor_property_id');
     $user_id = Auth::user()->id;
     $colonia = Session::get("colonia");
     $urbanism = Urbanism::where('colony_id', '=', $colonia)->first();
     $urbanismo = $urbanism->id;
     $urb_name = $urbanism->name;
     $property_id = NeighborProperty::where('urbanism_id', '=', $urbanismo)->pluck('id');
     $vigencia = date("Y-m");
     $months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Decem");
     $today = date("Y-m-d");
     $ano = date("Y");
     $selano = Payment::select(DB::raw('DATE_FORMAT(payments.created_at,\'%Y\') as y'))->groupBy(DB::raw('Year(payments.created_at)'))->orderBy(DB::raw('Year(payments.created_at)'))->get();
     $monthly_all = MonthlyFee::where('monthly_fee.urbanism_id', '=', $urbanismo)->where(DB::raw('DATE_FORMAT(monthly_fee.since,\'%Y\')'), '=', $ano)->get();
     $monthly_ini = MonthlyFee::where('monthly_fee.urbanism_id', '=', $urbanismo)->where(DB::raw('DATE_FORMAT(monthly_fee.since,\'%Y\')'), '=', $ano)->orderBy('monthly_fee.created_at', 'ASC')->pluck('since');
     $mes_ini = (int) date("m", strtotime($monthly_ini));
     $cuotas = array();
     foreach ($monthly_all as $cuota_mensual) {
         $ini = (int) date("m", strtotime($cuota_mensual->since));
         $fin = (int) date("m", strtotime($cuota_mensual->until));
         if ($cuota_mensual->until == NULL) {
             $fin = (int) date("m");
         }
         for ($i = $ini; $i <= $fin; $i++) {
             $cuotas[$months[$i - 1]] = $cuota_mensual->amount;
         }
     }
     for ($j = 0; $j <= 11; $j++) {
         if ($j + 1 < $mes_ini) {
             $saldoAnteriol[$j] = "";
             $cuataMes[$j] = "";
             $totalDebe[$j] = "";
             $pagos[$j] = "";
             $saldoTotal[$j] = "";
         } elseif ($j + 1 <= date("m")) {
             $saldoAnteriol[$j] = $saldoTotal[$j - 1];
             $cuataMes[$j] = -$cuotas[$months[$j]];
             $totalDebe[$j] = $saldoAnteriol[$j] + $cuataMes[$j];
             $neighbor_payments = PaymentStates::with('NeighborProperty')->where('neighbor_property_id', '=', $neighbor_property_id)->first();
             if ($neighbor_payments) {
                 $pagos[$j] = $neighbor_payments->{$months}[$j] == NULL ? 0 : $neighbor_payments->{$months}[$j];
             } else {
                 $pagos[$j] = 0;
             }
             $saldoTotal[$j] = $totalDebe[$j] + $pagos[$j];
         } elseif ($j + 1 > date("m")) {
             $saldoAnteriol[$j] = "";
             $cuataMes[$j] = "";
             $totalDebe[$j] = "";
             $pagos[$j] = "";
             $saldoTotal[$j] = "";
         }
     }
     $neighbor = NeighborProperty::find($neighbor_property_id);
     return View::make('dashboard.payments.neighbors.table_neigbor', compact('breadcrumbs_data', 'saldoAnteriol', 'cuataMes', 'totalDebe', 'pagos', 'saldoTotal', 'mes_ini', 'ini', 'months', 'color', 'neighbor'));
 }
 public function record_index()
 {
     $user_id = Auth::user()->id;
     $colonia = Session::get("colonia");
     $AssigmentRole = Auth::user()->AssigmentRole[0]->role_id;
     $urbanism = Urbanism::where('colony_id', '=', $colonia)->first();
     $urb_name = $urbanism->Colony->name;
     $collector = Collector::where('user_id', '=', $user_id)->where('urbanism_id', '=', $urbanism->id)->first();
     $collector_neighbor = Neighbors::where('user_id', '=', $user_id)->first();
     $collector_properties = NeighborProperty::where('neighbors_id', '=', $collector_neighbor->id)->pluck('id');
     $neighbors_payments = Payment::join('neighbors_properties', 'payments.neighbor_property_id', '=', 'neighbors_properties.id')->join('neighbors', 'neighbors_properties.neighbors_id', '=', 'neighbors.id')->join('sub_accounts', 'payments.sub_account_id', '=', 'sub_accounts.id')->select('payments.id', 'payments.created_at', 'payments.amount', 'payments.coments', 'neighbors.name', 'neighbors.last_name', 'sub_accounts.description')->where('neighbors_properties.urbanism_id', '=', $urbanism->id)->orderBy('created_at')->get();
     $breadcrumbs = Neighbors::with('NeighborProperty')->where('user_id', '=', $user_id)->first();
     $breadcrumbs_data = $breadcrumbs->name . " " . $breadcrumbs->last_name . " [" . $urb_name . "]";
     return View::make('dashboard.incomes.record.index', ['incomes' => $neighbors_payments, 'breadcrumbs_data' => $breadcrumbs_data, 'AssigmentRole' => $AssigmentRole, 'total' => 0]);
 }
 public function reg_familiar()
 {
     $user_id = Auth::user()->id;
     $colonia = Session::get("colonia");
     $urbanism = Urbanism::where('colony_id', '=', $colonia)->first();
     $urbanism_type = $urbanism->urbanism_type_id;
     $attendant = Neighbors::where('user_id', '=', $user_id)->first();
     if ($urbanism_type == 3) {
         $catalog = BuildingCatalog::where('urbanism_id', '=', $urbanism->id)->orderBy('id', 'ASC')->lists('description', 'id');
         $select = '¿Piso donde vive?';
         $select_name = 'name_floor';
     } else {
         $catalog = StreetCatalog::where('urbanism_id', '=', $urbanism->id)->orderBy('id', 'ASC')->lists('name', 'id');
         $select = '¿Calle donde vive?';
         $select_name = 'name_street';
     }
     $neighbor_properties = NeighborProperty::where('neighbors_id', '=', $attendant->id)->first();
     $breadcrumbs = Neighbors::where('user_id', '=', $user_id)->first();
     $breadcrumbs_data = $breadcrumbs->name . " " . $breadcrumbs->last_name . " [ " . $urbanism->name . " ]";
     return View::make('dashboard.colonies.config.reg_familiar', ['usuario' => $breadcrumbs_data, 'urbanism' => $urbanism->name, 'urbanism_id' => $urbanism->id, 'urbanism_type' => $urbanism_type, 'catalog' => $catalog, 'select_name' => $select_name, 'select' => ['' => $select], 'neighbor_properties' => $neighbor_properties, '']);
 }
 public function reportStatus()
 {
     $user_id = Auth::user()->id;
     $colonia = Session::get("colonia");
     $urbanism = Urbanism::where('colony_id', '=', $colonia)->first();
     $urbanismo = $urbanism->id;
     $urb_name = $urbanism->name;
     $property_id = NeighborProperty::where('urbanism_id', '=', $urbanismo)->pluck('id');
     $vigencia = date("Y-m");
     $months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Decem");
     $today = date("Y-m-d");
     $ano = date("Y");
     $selano = Payment::select(DB::raw('DATE_FORMAT(payments.created_at,\'%Y\') as y'))->groupBy(DB::raw('Year(payments.created_at)'))->orderBy(DB::raw('Year(payments.created_at)'))->get();
     $monthly_all = MonthlyFee::where('monthly_fee.urbanism_id', '=', $urbanismo)->where(DB::raw('DATE_FORMAT(monthly_fee.since,\'%Y\')'), '=', $ano)->get();
     $monthly_ini = MonthlyFee::where('monthly_fee.urbanism_id', '=', $urbanismo)->where(DB::raw('DATE_FORMAT(monthly_fee.since,\'%Y\')'), '=', $ano)->orderBy('monthly_fee.created_at', 'ASC')->pluck('since');
     $mes_ini = (int) date("m", strtotime($monthly_ini));
     $cuotas = array();
     foreach ($monthly_all as $cuota_mensual) {
         $ini = (int) date("m", strtotime($cuota_mensual->since));
         $fin = (int) date("m", strtotime($cuota_mensual->until));
         if ($cuota_mensual->until == NULL) {
             $fin = (int) date("m");
         }
         for ($i = $ini; $i <= $fin; $i++) {
             $cuotas[$months[$i - 1]] = $cuota_mensual->amount;
         }
     }
     $neighbors = NeighborProperty::with('Neighbors')->where('urbanism_id', '=', $urbanismo)->get();
     $breadcrumbs = Neighbors::select('neighbors.name as name_ne', 'neighbors.last_name', 'urbanisms.name as name_ur ')->join('neighbors_properties', 'neighbors.id', '=', 'neighbors_properties.neighbors_id')->join('urbanisms', 'neighbors_properties.urbanism_id', '=', 'urbanisms.id')->where('neighbors.user_id', '=', self::getUserId())->first();
     $breadcrumbs_data = $breadcrumbs->name_ne . " " . $breadcrumbs->last_name . " [" . $breadcrumbs->name_ur . "]";
     $data = ['mes_ini' => $mes_ini, 'months' => $months, 'cuotas' => $cuotas, 'selano' => $selano, 'urbanism' => $urbanismo, 'breadcrumbs_data' => $breadcrumbs_data, 'neighbors' => $neighbors, 'ini' => $ini, 'fin' => $fin, 'ano' => $ano, 'breadcrumbs_data' => $breadcrumbs_data];
     $pdf = PDF::loadView('dashboard.reports.status.pdf', $data);
     return $pdf->download('reporte_Estato_cuanta_general.pdf');
 }
 public function store_update_fam()
 {
     $post = Input::All();
     $email = Input::get('email');
     $user_id = User::where('email', '=', $email)->pluck('id');
     $neighbor_add = Neighbors::where('user_id', '=', $user_id)->first();
     $neighbor_pro = NeighborProperty::where('neighbors_id', '=', $neighbor_add->id)->first();
     $user = UserNeighbors::findOrFail($user_id);
     $user->password = Hash::make(Input::get('password'));
     $user->update(['id']);
     $last_user_add = $user->id;
     $neighbor = Neighbors::findOrFail($neighbor_add->id);
     $neighbor->name = Input::get('firstname');
     $neighbor->last_name = Input::get('lastname');
     $neighbor->phone = Input::get('phone');
     $neighbor->update(['id']);
     $confirm = InvitedNeighbors::where('Confirmation_code', '=', Input::get('code'))->first();
     $confirm->confirmed = true;
     $confirm->update(['id']);
     $urbanismNeigh = $neighbor_pro->urbanism_id;
     $colonies = Colony::select('colonies.id')->join('urbanisms', 'urbanisms.colony_id', '=', 'colonies.id')->join('neighbors_properties', 'urbanisms.id', '=', 'neighbors_properties.urbanism_id')->where('neighbors_properties.urbanism_id', '=', $urbanismNeigh)->first();
     $user_auth = User::where('id', '=', $last_user_add)->first();
     Auth::login($user_auth);
     if (Auth::check()) {
         Session::put('colonia', $colonies->id);
         return Redirect::action('HomeController@index');
     } else {
         return Redirect::action('UsersController@login');
     }
 }