Guest User

Untitled

a guest
Jan 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.15 KB | None | 0 0
  1. @extends('principal')
  2. @section('contenido')
  3.  
  4. @if(Auth::check())
  5. @if (Auth::user()->idrol == 1)
  6. <template v-if="menu==0">
  7. <dashboard></dashboard>
  8. </template>
  9.  
  10. <template v-if="menu==1">
  11. <categoria></categoria>
  12. </template>
  13.  
  14. <template v-if="menu==2">
  15. <articulo></articulo>
  16. </template>
  17.  
  18. <template v-if="menu==3">
  19. <ingreso></ingreso>
  20. </template>
  21.  
  22. <template v-if="menu==4">
  23. <proveedor></proveedor>
  24. </template>
  25.  
  26. <template v-if="menu==5">
  27. <venta></venta>
  28. </template>
  29.  
  30. <template v-if="menu==6">
  31. <cliente></cliente>
  32. </template>
  33.  
  34. <template v-if="menu==7">
  35. <user></user>
  36. </template>
  37.  
  38. <template v-if="menu==8">
  39. <rol></rol>
  40. </template>
  41.  
  42. <template v-if="menu==9">
  43. <consultaingreso></consultaingreso>
  44. </template>
  45.  
  46. <template v-if="menu==10">
  47. <consultaventa></consultaventa>
  48. </template>
  49.  
  50. <template v-if="menu==11">
  51. <h1>Ayuda</h1>
  52. </template>
  53.  
  54. <template v-if="menu==12">
  55. <h1>Acerca de</h1>
  56. </template>
  57. @elseif (Auth::user()->idrol == 2)
  58. <template v-if="menu==0">
  59. <dashboard></dashboard>
  60. </template>
  61. <template v-if="menu==5">
  62. <venta></venta>
  63. </template>
  64.  
  65. <template v-if="menu==6">
  66. <cliente></cliente>
  67. </template>
  68. <template v-if="menu==10">
  69. <consultaventa></consultaventa>
  70. </template>
  71.  
  72. <template v-if="menu==11">
  73. <h1>Ayuda</h1>
  74. </template>
  75.  
  76. <template v-if="menu==12">
  77. <h1>Acerca de</h1>
  78. </template>
  79. @elseif (Auth::user()->idrol == 3)
  80. <template v-if="menu==0">
  81. <dashboard></dashboard>
  82. </template>
  83. <template v-if="menu==1">
  84. <categoria></categoria>
  85. </template>
  86.  
  87. <template v-if="menu==2">
  88. <articulo></articulo>
  89. </template>
  90.  
  91. <template v-if="menu==3">
  92. <ingreso></ingreso>
  93. </template>
  94.  
  95. <template v-if="menu==4">
  96. <proveedor></proveedor>
  97. </template>
  98. <template v-if="menu==9">
  99. <consultaingreso></consultaingreso>
  100. </template>
  101. <template v-if="menu==11">
  102. <h1>Ayuda</h1>
  103. </template>
  104.  
  105. <template v-if="menu==12">
  106. <h1>Acerca de</h1>
  107. </template>
  108. @else
  109.  
  110. @endif
  111.  
  112. @endif
  113.  
  114.  
  115. @endsection
  116.  
  117. <template>
  118. <main class="main">
  119. <!-- Breadcrumb -->
  120. <ol class="breadcrumb">
  121. <li class="breadcrumb-item"><a href="/">Escritorio</a></li>
  122. </ol>
  123. <div class="container-fluid">
  124. <div class="card">
  125. <div class="card-header">
  126.  
  127. </div>
  128. <div class="car-body">
  129. <div class="row">
  130. <div class="col-md-6">
  131. <div class="card card-chart">
  132. <div class="card-header">
  133. <h4>Ingresos</h4>
  134. </div>
  135. <div class="card-content">
  136. <div class="ct-chart">
  137. <canvas id="ingresos">
  138. </canvas>
  139. </div>
  140. </div>
  141. <div class="card-footer">
  142. <p>Compras de los últimos meses.</p>
  143. </div>
  144. </div>
  145. </div>
  146. <div class="col-md-6">
  147. <div class="card card-chart">
  148. <div class="card-header">
  149. <h4>Ventas</h4>
  150. </div>
  151. <div class="card-content">
  152. <div class="ct-chart">
  153. <canvas id="ventas">
  154. </canvas>
  155. </div>
  156. </div>
  157. <div class="card-footer">
  158. <p>Ventas de los últimos meses.</p>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166.  
  167. </main>
  168. </template>
  169. <script>
  170. export default {
  171. data (){
  172. return {
  173. varIngreso:null,
  174. charIngreso:null,
  175. ingresos:[],
  176. varTotalIngreso:[],
  177. varMesIngreso:[],
  178.  
  179. varVenta:null,
  180. charVenta:null,
  181. ventas:[],
  182. varTotalVenta:[],
  183. varMesVenta:[],
  184. }
  185. },
  186. methods : {
  187. getIngresos(){
  188. let me=this;
  189. var url= '/dashboard';
  190. axios.get(url).then(function (response) {
  191. var respuesta= response.data;
  192. me.ingresos = respuesta.ingresos;
  193. //cargamos los datos del chart
  194. me.loadIngresos();
  195. })
  196. .catch(function (error) {
  197. console.log(error);
  198. });
  199. },
  200. getVentas(){
  201. let me=this;
  202. var url= '/dashboard';
  203. axios.get(url).then(function (response) {
  204. var respuesta= response.data;
  205. me.ventas = respuesta.ventas;
  206. //cargamos los datos del chart
  207. me.loadVentas();
  208. })
  209. .catch(function (error) {
  210. console.log(error);
  211. });
  212. },
  213. loadIngresos(){
  214. let me=this;
  215. me.ingresos.map(function(x){
  216. me.varMesIngreso.push(x.mes);
  217. me.varTotalIngreso.push(x.total);
  218. });
  219. me.varIngreso=document.getElementById('ingresos').getContext('2d');
  220.  
  221. me.charIngreso = new Chart(me.varIngreso, {
  222. type: 'bar',
  223. data: {
  224. labels: me.varMesIngreso,
  225. datasets: [{
  226. label: 'Ingresos',
  227. data: me.varTotalIngreso,
  228. backgroundColor: 'rgba(255, 99, 132, 0.2)',
  229. borderColor: 'rgba(255, 99, 132, 0.2)',
  230. borderWidth: 1
  231. }]
  232. },
  233. options: {
  234. scales: {
  235. yAxes: [{
  236. ticks: {
  237. beginAtZero:true
  238. }
  239. }]
  240. }
  241. }
  242. });
  243. },
  244. loadVentas(){
  245. let me=this;
  246. me.ventas.map(function(x){
  247. me.varMesVenta.push(x.mes);
  248. me.varTotalVenta.push(x.total);
  249. });
  250. me.varVenta=document.getElementById('ventas').getContext('2d');
  251.  
  252. me.charVenta = new Chart(me.varVenta, {
  253. type: 'bar',
  254. data: {
  255. labels: me.varMesVenta,
  256. datasets: [{
  257. label: 'Ventas',
  258. data: me.varTotalVenta,
  259. backgroundColor: 'rgba(54, 162, 235, 0.2)',
  260. borderColor: 'rgba(54, 162, 235, 0.2)',
  261. borderWidth: 1
  262. }]
  263. },
  264. options: {
  265. scales: {
  266. yAxes: [{
  267. ticks: {
  268. beginAtZero:true
  269. }
  270. }]
  271. }
  272. }
  273. });
  274. }
  275. },
  276. mounted() {
  277. this.getIngresos();
  278. this.getVentas();
  279. }
  280. }
  281. </script>
  282.  
  283. require('./bootstrap');
  284.  
  285. window.$ = window.jQuery = require('jquery');
  286.  
  287. window.Vue = require('vue');
  288.  
  289. /**
  290. * Next, we will create a fresh Vue application instance and attach it to
  291. * the page. Then, you may begin adding components to this application
  292. * or customize the JavaScript scaffolding to fit your unique needs.
  293. */
  294.  
  295. Vue.component('categoria', require('./components/Categoria.vue'));
  296. Vue.component('articulo', require('./components/Articulo.vue'));
  297. Vue.component('cliente', require('./components/Cliente.vue'));
  298. Vue.component('proveedor', require('./components/Proveedor.vue'));
  299. Vue.component('rol', require('./components/Rol.vue'));
  300. Vue.component('user', require('./components/User.vue'));
  301. Vue.component('ingreso', require('./components/Ingreso.vue'));
  302. Vue.component('venta', require('./components/Venta.vue'));
  303. Vue.component('dashboard', require('./components/Dashboard.vue'));
  304. Vue.component('consultaingreso', require('./components/ConsultaIngreso.vue'));
  305. Vue.component('consultaventa', require('./components/ConsultaVenta.vue'));
  306. Vue.component('notification', require('./components/Notification.vue'));
  307.  
  308. const app = new Vue({
  309. el: '#app',
  310. data :{
  311. menu : 0,
  312. notifications: []
  313. },
  314. created() {
  315. let me = this;
  316. axios.post('notification/get').then(function(response) {
  317. //console.log(response.data);
  318. me.notifications=response.data;
  319. }).catch(function(error) {
  320. console.log(error);
  321. });
  322.  
  323. var userId = $('meta[name="userId"]').attr('content');
  324.  
  325. Echo.private('App.User.' + userId).notification((notification) => {
  326. me.notifications.unshift(notification);
  327. });
  328.  
  329. }
  330. });
  331.  
  332. <?php
  333.  
  334. namespace AppHttpControllers;
  335. use IlluminateSupportFacadesDB;
  336.  
  337. use IlluminateHttpRequest;
  338.  
  339. class DashboardController extends Controller
  340. {
  341. public function __invoke(Request $request)
  342. {
  343. $anio=date('Y');
  344. $ingresos=DB::table('ingresos as i')
  345. ->select(DB::raw('MONTH(i.fecha_hora) as mes'),
  346. DB::raw('YEAR(i.fecha_hora) as anio'),
  347. DB::raw('SUM(i.total) as total'))
  348. ->whereYear('i.fecha_hora',$anio)
  349. ->groupBy(DB::raw('MONTH(i.fecha_hora)'),DB::raw('YEAR(i.fecha_hora)'))
  350. ->get();
  351.  
  352. $ventas=DB::table('ventas as v')
  353. ->select(DB::raw('MONTH(v.fecha_hora) as mes'),
  354. DB::raw('YEAR(v.fecha_hora) as anio'),
  355. DB::raw('SUM(v.total) as total'))
  356. ->whereYear('v.fecha_hora',$anio)
  357. ->groupBy(DB::raw('MONTH(v.fecha_hora)'),DB::raw('YEAR(v.fecha_hora)'))
  358. ->get();
  359.  
  360. return ['ingresos'=>$ingresos,'ventas'=>$ventas,'anio'=>$anio];
  361.  
  362. }
  363. }
  364.  
  365. Route::group(['middleware'=>['auth']],function(){
  366.  
  367. Route::post('/logout', 'AuthLoginController@logout')->name('logout');
  368. Route::get('/dashboard', 'DashboardController');
  369. });
Add Comment
Please, Sign In to add comment