Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @extends('principal')
- @section('contenido')
- @if(Auth::check())
- @if (Auth::user()->idrol == 1)
- <template v-if="menu==0">
- <dashboard></dashboard>
- </template>
- <template v-if="menu==1">
- <categoria></categoria>
- </template>
- <template v-if="menu==2">
- <articulo></articulo>
- </template>
- <template v-if="menu==3">
- <ingreso></ingreso>
- </template>
- <template v-if="menu==4">
- <proveedor></proveedor>
- </template>
- <template v-if="menu==5">
- <venta></venta>
- </template>
- <template v-if="menu==6">
- <cliente></cliente>
- </template>
- <template v-if="menu==7">
- <user></user>
- </template>
- <template v-if="menu==8">
- <rol></rol>
- </template>
- <template v-if="menu==9">
- <consultaingreso></consultaingreso>
- </template>
- <template v-if="menu==10">
- <consultaventa></consultaventa>
- </template>
- <template v-if="menu==11">
- <h1>Ayuda</h1>
- </template>
- <template v-if="menu==12">
- <h1>Acerca de</h1>
- </template>
- @elseif (Auth::user()->idrol == 2)
- <template v-if="menu==0">
- <dashboard></dashboard>
- </template>
- <template v-if="menu==5">
- <venta></venta>
- </template>
- <template v-if="menu==6">
- <cliente></cliente>
- </template>
- <template v-if="menu==10">
- <consultaventa></consultaventa>
- </template>
- <template v-if="menu==11">
- <h1>Ayuda</h1>
- </template>
- <template v-if="menu==12">
- <h1>Acerca de</h1>
- </template>
- @elseif (Auth::user()->idrol == 3)
- <template v-if="menu==0">
- <dashboard></dashboard>
- </template>
- <template v-if="menu==1">
- <categoria></categoria>
- </template>
- <template v-if="menu==2">
- <articulo></articulo>
- </template>
- <template v-if="menu==3">
- <ingreso></ingreso>
- </template>
- <template v-if="menu==4">
- <proveedor></proveedor>
- </template>
- <template v-if="menu==9">
- <consultaingreso></consultaingreso>
- </template>
- <template v-if="menu==11">
- <h1>Ayuda</h1>
- </template>
- <template v-if="menu==12">
- <h1>Acerca de</h1>
- </template>
- @else
- @endif
- @endif
- @endsection
- <template>
- <main class="main">
- <!-- Breadcrumb -->
- <ol class="breadcrumb">
- <li class="breadcrumb-item"><a href="/">Escritorio</a></li>
- </ol>
- <div class="container-fluid">
- <div class="card">
- <div class="card-header">
- </div>
- <div class="car-body">
- <div class="row">
- <div class="col-md-6">
- <div class="card card-chart">
- <div class="card-header">
- <h4>Ingresos</h4>
- </div>
- <div class="card-content">
- <div class="ct-chart">
- <canvas id="ingresos">
- </canvas>
- </div>
- </div>
- <div class="card-footer">
- <p>Compras de los últimos meses.</p>
- </div>
- </div>
- </div>
- <div class="col-md-6">
- <div class="card card-chart">
- <div class="card-header">
- <h4>Ventas</h4>
- </div>
- <div class="card-content">
- <div class="ct-chart">
- <canvas id="ventas">
- </canvas>
- </div>
- </div>
- <div class="card-footer">
- <p>Ventas de los últimos meses.</p>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </main>
- </template>
- <script>
- export default {
- data (){
- return {
- varIngreso:null,
- charIngreso:null,
- ingresos:[],
- varTotalIngreso:[],
- varMesIngreso:[],
- varVenta:null,
- charVenta:null,
- ventas:[],
- varTotalVenta:[],
- varMesVenta:[],
- }
- },
- methods : {
- getIngresos(){
- let me=this;
- var url= '/dashboard';
- axios.get(url).then(function (response) {
- var respuesta= response.data;
- me.ingresos = respuesta.ingresos;
- //cargamos los datos del chart
- me.loadIngresos();
- })
- .catch(function (error) {
- console.log(error);
- });
- },
- getVentas(){
- let me=this;
- var url= '/dashboard';
- axios.get(url).then(function (response) {
- var respuesta= response.data;
- me.ventas = respuesta.ventas;
- //cargamos los datos del chart
- me.loadVentas();
- })
- .catch(function (error) {
- console.log(error);
- });
- },
- loadIngresos(){
- let me=this;
- me.ingresos.map(function(x){
- me.varMesIngreso.push(x.mes);
- me.varTotalIngreso.push(x.total);
- });
- me.varIngreso=document.getElementById('ingresos').getContext('2d');
- me.charIngreso = new Chart(me.varIngreso, {
- type: 'bar',
- data: {
- labels: me.varMesIngreso,
- datasets: [{
- label: 'Ingresos',
- data: me.varTotalIngreso,
- backgroundColor: 'rgba(255, 99, 132, 0.2)',
- borderColor: 'rgba(255, 99, 132, 0.2)',
- borderWidth: 1
- }]
- },
- options: {
- scales: {
- yAxes: [{
- ticks: {
- beginAtZero:true
- }
- }]
- }
- }
- });
- },
- loadVentas(){
- let me=this;
- me.ventas.map(function(x){
- me.varMesVenta.push(x.mes);
- me.varTotalVenta.push(x.total);
- });
- me.varVenta=document.getElementById('ventas').getContext('2d');
- me.charVenta = new Chart(me.varVenta, {
- type: 'bar',
- data: {
- labels: me.varMesVenta,
- datasets: [{
- label: 'Ventas',
- data: me.varTotalVenta,
- backgroundColor: 'rgba(54, 162, 235, 0.2)',
- borderColor: 'rgba(54, 162, 235, 0.2)',
- borderWidth: 1
- }]
- },
- options: {
- scales: {
- yAxes: [{
- ticks: {
- beginAtZero:true
- }
- }]
- }
- }
- });
- }
- },
- mounted() {
- this.getIngresos();
- this.getVentas();
- }
- }
- </script>
- require('./bootstrap');
- window.$ = window.jQuery = require('jquery');
- window.Vue = require('vue');
- /**
- * Next, we will create a fresh Vue application instance and attach it to
- * the page. Then, you may begin adding components to this application
- * or customize the JavaScript scaffolding to fit your unique needs.
- */
- Vue.component('categoria', require('./components/Categoria.vue'));
- Vue.component('articulo', require('./components/Articulo.vue'));
- Vue.component('cliente', require('./components/Cliente.vue'));
- Vue.component('proveedor', require('./components/Proveedor.vue'));
- Vue.component('rol', require('./components/Rol.vue'));
- Vue.component('user', require('./components/User.vue'));
- Vue.component('ingreso', require('./components/Ingreso.vue'));
- Vue.component('venta', require('./components/Venta.vue'));
- Vue.component('dashboard', require('./components/Dashboard.vue'));
- Vue.component('consultaingreso', require('./components/ConsultaIngreso.vue'));
- Vue.component('consultaventa', require('./components/ConsultaVenta.vue'));
- Vue.component('notification', require('./components/Notification.vue'));
- const app = new Vue({
- el: '#app',
- data :{
- menu : 0,
- notifications: []
- },
- created() {
- let me = this;
- axios.post('notification/get').then(function(response) {
- //console.log(response.data);
- me.notifications=response.data;
- }).catch(function(error) {
- console.log(error);
- });
- var userId = $('meta[name="userId"]').attr('content');
- Echo.private('App.User.' + userId).notification((notification) => {
- me.notifications.unshift(notification);
- });
- }
- });
- <?php
- namespace AppHttpControllers;
- use IlluminateSupportFacadesDB;
- use IlluminateHttpRequest;
- class DashboardController extends Controller
- {
- public function __invoke(Request $request)
- {
- $anio=date('Y');
- $ingresos=DB::table('ingresos as i')
- ->select(DB::raw('MONTH(i.fecha_hora) as mes'),
- DB::raw('YEAR(i.fecha_hora) as anio'),
- DB::raw('SUM(i.total) as total'))
- ->whereYear('i.fecha_hora',$anio)
- ->groupBy(DB::raw('MONTH(i.fecha_hora)'),DB::raw('YEAR(i.fecha_hora)'))
- ->get();
- $ventas=DB::table('ventas as v')
- ->select(DB::raw('MONTH(v.fecha_hora) as mes'),
- DB::raw('YEAR(v.fecha_hora) as anio'),
- DB::raw('SUM(v.total) as total'))
- ->whereYear('v.fecha_hora',$anio)
- ->groupBy(DB::raw('MONTH(v.fecha_hora)'),DB::raw('YEAR(v.fecha_hora)'))
- ->get();
- return ['ingresos'=>$ingresos,'ventas'=>$ventas,'anio'=>$anio];
- }
- }
- Route::group(['middleware'=>['auth']],function(){
- Route::post('/logout', 'AuthLoginController@logout')->name('logout');
- Route::get('/dashboard', 'DashboardController');
- });
Add Comment
Please, Sign In to add comment