luisruiz

Untitled

Feb 20th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. import { element } from 'protractor';
  2. import { PipeTransform, Pipe, Component, OnInit, OnDestroy } from '@angular/core';
  3. import { ActivatedRoute } from '@angular/router';
  4. import { AngularFirestore, AngularFirestoreDocument, AngularFirestoreCollection } from 'angularfire2/firestore';
  5. import { Observable } from 'rxjs/Observable';
  6. import * as _ from 'lodash';
  7. import * as moment from 'moment';
  8. import { MatSnackBar } from '@angular/material';
  9. import { EmployeeService } from '../employee.service';
  10. import { ConfigService } from '../../remuneracion/config/config.service';
  11.  
  12. import * as pdfMake from 'pdfmake/build/pdfmake';
  13. import * as pdfFonts from 'pdfmake/build/vfs_fonts';
  14.  
  15. declare var $ :any;
  16.  
  17.  
  18. export interface EmployeeBonos{
  19. id?: string;
  20. nombre?: string;
  21. valor?: number;
  22. }
  23.  
  24. export interface EmployeeDetail{
  25. id ?: any;
  26. datosPersonales ?: EmployeeDatosPersonales;
  27. }
  28.  
  29. export interface EmployeeDatosPersonales extends EmployeeDetail{
  30. nombre ?: string;
  31. }
  32.  
  33. @Pipe({name: 'keys'})
  34.  
  35.  
  36.  
  37. @Component({
  38. selector: 'fuse-employee-detail',
  39. templateUrl: './employee-detail.component.html',
  40. styleUrls: ['./employee-detail.component.scss']
  41. })
  42.  
  43.  
  44.  
  45. export class EmployeeDetailComponent implements OnInit, OnDestroy, PipeTransform {
  46.  
  47.  
  48. text: string;
  49. selectBono: any;
  50. selectNoBono: any;
  51.  
  52. private EmployeeDoc: AngularFirestoreDocument<EmployeeDetail>;
  53. private refDocumentBonosImponibles: AngularFirestoreDocument<EmployeeBonos>;
  54.  
  55.  
  56. private BonosImponiblesCollection: AngularFirestoreCollection<EmployeeBonos>;
  57. private BonosNoImponiblesCollection: AngularFirestoreCollection<any>;
  58. private AfpCollection: AngularFirestoreCollection<any>;
  59. private isapresCollection: AngularFirestoreCollection<any>;
  60.  
  61.  
  62. idEmployee: string;
  63. employee: any;
  64.  
  65. EmployeeBonosImponibles: any;
  66. EmployeeBonosNoImponibles: any;
  67.  
  68. BonosImponibles: any;
  69. BonosNoImponibles: any;
  70. AFPList: any;
  71. isapres: any;
  72.  
  73. editorContent: string = 'My Document\'s Title';
  74.  
  75. public options: Object = {
  76.  
  77. charCounterCount: true,
  78. toolbarButtons: [
  79. 'print', 'alert','insert'
  80. ],
  81. toolbarButtonsXS: ['print', 'alert','insert']
  82. }
  83.  
  84. vm = this;
  85.  
  86. constructor(
  87. private afs: AngularFirestore,
  88. private route: ActivatedRoute,
  89. public snackBar: MatSnackBar,
  90. private employeeService:EmployeeService,
  91. private configService: ConfigService) {
  92.  
  93.  
  94. this.text = '[My New HTML]';
  95.  
  96.  
  97. // Obtiene parametros de Route
  98. this.route.params.subscribe(params => {
  99. this.idEmployee = params['id'];
  100. });
  101.  
  102.  
  103. // Employee Datos
  104.  
  105. this.employeeService.getEmployeeId(this.idEmployee).subscribe(employee => {
  106.  
  107. this.employee = employee;
  108. if (employee.datosLaborales.contratoDocente){
  109.  
  110. this.employee.datosLaborales.totalHrs = (this.employee.datosLaborales.base.hrsBase || 0)
  111. + (this.employee.datosLaborales.sueldoGeneral.hrsGeneral || 0)
  112. + (this.employee.datosLaborales.sueldoPIE.hrsPIE || 0)
  113. + (this.employee.datosLaborales.sueldoSEP.hrsSEP || 0);
  114. employee.datosLaborales.SAEhrs = 6300;
  115. }
  116.  
  117. });
  118.  
  119.  
  120.  
  121. this.employeeService.getEmployeeBonoimponible().subscribe(bonosImponibles => {
  122. this.EmployeeBonosImponibles = bonosImponibles;
  123. });
  124.  
  125. this.employeeService.getEmployeeBonoNoimponible().subscribe(bonosNoImponibles => {
  126. this.EmployeeBonosNoImponibles = bonosNoImponibles;
  127. });
  128.  
  129.  
  130. // Config Datos
  131.  
  132. this.configService.resolve().then(files => {
  133.  
  134. this.BonosImponibles = files[0];
  135. this.BonosNoImponibles = files[1];
  136. this.isapres = files[3];
  137. this.AFPList = files[4];
  138.  
  139. })
  140.  
  141. }
  142.  
  143.  
  144.  
  145. transform(value, args: string[]): any {
  146. const keys = [];
  147. for ( const key of value) {
  148. keys.push({key: key, value: value[key]});
  149. }
  150. return keys;
  151. }
  152.  
  153. updateFechaIngreso($event: Date){
  154. this.employee.datosLaborales.fechaIngreso = $event;
  155. }
  156. saveEmployee(){
  157.  
  158. // TODO: mover a servicio
  159.  
  160. this.EmployeeDoc.update(this.employee);
  161.  
  162.  
  163. this.EmployeeBonosImponibles.forEach((bono: any, _id: string) => {
  164. _id = bono.id;
  165. delete bono.id;
  166. this.BonosImponiblesCollection.doc(_id).update(bono);
  167. });
  168.  
  169. this.EmployeeBonosNoImponibles.forEach((bono: any, _id: string) => {
  170. _id = bono.id;
  171. delete bono.id;
  172. this.BonosNoImponiblesCollection.doc(_id).update(bono);
  173. });
  174.  
  175. const snackBarRef = this.snackBar.open('Actualizado', 'listo' , {
  176. duration: 3000
  177. });
  178.  
  179. }
  180.  
  181. addBono(bonoSelect: any, typeBono: string){
  182.  
  183. const bono = Object.assign({}, bonoSelect);
  184.  
  185. bono.idBonoDescuento = bono.id;
  186. delete bono.id;
  187.  
  188. if (typeBono === 'imponible'){
  189. this.BonosImponiblesCollection
  190. .add(bono).then( suss => {
  191. this.selectBono = {};
  192. } ).catch(error => {
  193. console.log('error al ingresar los datos');
  194. });
  195. }
  196. if (typeBono === 'noImponible'){
  197. this.BonosNoImponiblesCollection
  198. .add(bono).then(suss => {
  199. this.selectBono = {};
  200.  
  201. }).catch(error => {
  202. console.log('error al ingresar los datos');
  203. });
  204. }
  205.  
  206. }
  207.  
  208. removeBono(_id: string, typeBono: string){
  209.  
  210. if (typeBono === 'imponible') {
  211.  
  212. this.BonosImponiblesCollection.doc(_id)
  213. .delete();
  214. }
  215.  
  216. if (typeBono === 'noImponible') {
  217. this.BonosNoImponiblesCollection.doc(_id)
  218. .delete();
  219. }
  220.  
  221. }
  222.  
  223. ngOnInit() {
  224.  
  225.  
  226.  
  227.  
  228. $.FroalaEditor.DefineIcon('insert', {NAME: 'plus'});
  229. $.FroalaEditor.RegisterCommand('insert', {
  230. title: 'Insert HTML',
  231. focus: true,
  232. undo: true,
  233. refreshAfterCallback: true,
  234. callback: function (){
  235. this.html.insert('Hola mundo');
  236. console.log(this.vm.editorContent)
  237. }
  238. });
  239.  
  240.  
  241.  
  242. $.FroalaEditor.DefineIcon('alert', {NAME: 'info'});
  243. $.FroalaEditor.RegisterCommand('alert', {
  244. title: 'Hello',
  245. focus: false,
  246. undo: false,
  247. refreshAfterCallback: false,
  248.  
  249. callback: function() {
  250. const w = window.open();
  251. w.document.write($('.report_left_inner').html());
  252. w.document.body.innerHTML = "<html><head><title></title></head><body>" + this.editorContent + "</body>";
  253. w.print();
  254. w.close();
  255.  
  256.  
  257. }
  258. });
  259.  
  260.  
  261.  
  262. }
  263.  
  264.  
  265. ngOnDestroy(){
  266. }
  267.  
  268.  
  269. }
Advertisement
Add Comment
Please, Sign In to add comment