Commit 47bc57f50a176ecc6848dfff9b8c523da933f229

Authored by Eric Fernandez
1 parent 7febaeb82a
Exists in master

agrego llamadas a los modal

varios
Showing 1 changed file with 101 additions and 39 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearNotaPedido') 1 angular.module('focaCrearNotaPedido')
2 .controller('notaPedidoCtrl', 2 .controller('notaPedidoCtrl',
3 [ 3 [
4 '$scope', 4 '$scope',
5 '$uibModal', 5 '$uibModal',
6 'crearNotaPedidoService', 6 'crearNotaPedidoService',
7 function ($scope, $uibModal, crearNotaPedidoService) { 7 function ($scope, $uibModal, crearNotaPedidoService) {
8 $scope.notaPedido = {}; 8 $scope.notaPedido = {};
9 $scope.articulosTabla = [];
10 var idLista;
9 var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); 11 var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
10 var domiciliosCliente = [ 12 $scope.domiciliosCliente = crearNotaPedidoService.getDomicilios(1);
11 { 13 crearNotaPedidoService.getPrecioCondicion().then(
12 dom: 'sanjuan', 14 function (res) {
13 id: 3 15 $scope.precioCondiciones = res.data;
14 },
15 {
16 dom: 'mendoza',
17 id: 2
18 } 16 }
19 ] 17 );
20 if (notaPedidoTemp != undefined) { 18 if (notaPedidoTemp != undefined) {
21 notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); 19 notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga);
22 $scope.notaPedido = notaPedidoTemp; 20 $scope.notaPedido = notaPedidoTemp;
23 $scope.notaPedido.domicilio = domiciliosCliente; 21 $scope.notaPedido.flete = ($scope.notaPedido.flete).toString();
22 $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString();
23 $scope.notaPedido.precioCondicion = 2;
24
24 } else { 25 } else {
25 $scope.notaPedido.fechaCarga = new Date(); 26 $scope.notaPedido.fechaCarga = new Date();
26 27 $scope.notaPedido.domicilio = [{ id: 0 }]
27 $scope.notaPedido.domicilio = domiciliosCliente; 28 $scope.notaPedido.bomba = '1';
29 $scope.notaPedido.flete = '1';
28 } 30 }
29 $scope.precioCondiciones = [
30 { nombre: 'Precio y condicion 1' },
31 { nombre: 'Precio y condicion 2' },
32 { nombre: 'Precio y condicion 3' }
33 ]
34 $scope.articulosTabla = [
35 {
36 codigo: '1',
37 item: 1,
38 nombre: 'naftaaskdahsñodaskdjhañslkdjahslñkjdhalskjdhaksjdhkasjhasddddddddddddddddddddddddddddddddddddddddddddddddd',
39 precio: '14,50',
40 costoUnitario: '14',
41 cantidad: 1,
42 subtotal: '19,22'
43 }
44 ]
45 $scope.notaPedido.bomba = '1';
46 $scope.notaPedido.flete = '1';
47 $scope.addNewDom = function () { 31 $scope.addNewDom = function () {
48 $scope.notaPedido.domicilio.push({ 'id': 0 }); 32 $scope.notaPedido.domicilio.push({ 'id': 0 });
49 } 33 }
50 $scope.removeNewChoice = function (choice) { 34 $scope.removeNewChoice = function (choice) {
51 if ($scope.notaPedido.domicilio.length > 1) { 35 if ($scope.notaPedido.domicilio.length > 1) {
52 $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(c => c.$$hashKey == choice.$$hashKey), 1) 36 $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(c => c.$$hashKey == choice.$$hashKey), 1)
53 } 37 }
54 } 38 }
55 $scope.crearNotaPedido = function () { 39 $scope.crearNotaPedido = function () {
56 var notaPedido = { 40 var notaPedido = {
57 idNotaPedido: 0, 41 idNotaPedido: 0,
58 precioCondicion: $scope.notaPedido.precioCondicion, 42 precioCondicion: $scope.notaPedido.precioCondicion,
59 fechaCarga: $scope.notaPedido.clientefechaCarga, 43 fechaCarga: $scope.notaPedido.fechaCarga,
60 vendedor: $scope.notaPedido.vendedor, 44 vendedor: $scope.notaPedido.vendedor,
61 cliente: $scope.notaPedido.cliente, 45 cliente: $scope.notaPedido.cliente,
62 producto: $scope.notaPedido.producto, 46 producto: $scope.notaPedido.producto,
63 bomba: $scope.notaPedido.bomba, 47 bomba: $scope.notaPedido.bomba,
64 petrolera: $scope.notaPedido.petrolera, 48 petrolera: $scope.notaPedido.petrolera,
65 domicilio: $scope.notaPedido.domicilio, 49 domicilio: $scope.notaPedido.domicilio,
66 kilometros: $scope.notaPedido.kilometros, 50 kilometros: $scope.notaPedido.kilometros,
67 jurisdiccionIIBB: $scope.notaPedido.jurisdiccion, 51 jurisdiccionIIBB: $scope.notaPedido.jurisdiccionIIBB,
68 costoFinanciacion: $scope.notaPedido.costoFinanciacion, 52 costoFinanciacion: $scope.notaPedido.costoFinanciacion,
69 flete: $scope.notaPedido.flete, 53 flete: $scope.notaPedido.flete,
70 costoUnitarioKmFlete: $scope.costoUnitarioKmFlete 54 costoUnitarioKmFlete: $scope.notaPedido.costoUnitarioKmFlete,
55 articulosTabla: $scope.articulosTabla
71 } 56 }
72 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 57 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
73 function (res) { 58 function (res) {
74 alert('Nota pedido creada') 59 alert('Nota pedido creada')
75 } 60 }
76 ) 61 )
77 } 62 }
78 $scope.siguienteTab = function () { 63 $scope.siguienteTab = function () {
79 $scope.active = 1; 64 $scope.active = 1;
80 } 65 }
81 $scope.seleccionarArticulo = function () { 66 $scope.seleccionarArticulo = function () {
82 var modalIntance = $uibModal.open( 67 if(idLista==undefined){
68 alert('primero seleccione una lista de precio y condicion');
69 return;
70 }
71 var modalInstance = $uibModal.open(
83 { 72 {
84 ariaLabelledBy: 'Busqueda de Productos', 73 ariaLabelledBy: 'Busqueda de Productos',
85 templateUrl: 'modal-busqueda-productos.html', 74 templateUrl: 'modal-busqueda-productos.html',
86 controller: 'modalBusquedaProductosCtrl', 75 controller: 'modalBusquedaProductosCtrl',
87 size: 'md' 76 resolve: {idLista: function() {return idLista}},
77 size: 'lg'
88 } 78 }
89 ) 79 )
90 modalInstance.result.then( 80 modalInstance.result.then(
91 function (producto) { 81 function (producto) {
92 console.info(producto); 82 var newArt =
93 // variable producto tiene el producto seleccionado en el modal 83 {
84 codigo: producto.FiltroSectorCodigo,
85 item: $scope.articulosTabla.length + 1,
86 nombre: producto.descripcion,
87 precio: producto.precio,
88 costoUnitario: producto.costo,
89 cantidad: 1
90 }
91 $scope.articulosTabla.unshift(newArt);
94 }, function () { 92 }, function () {
95 // funcion ejecutada cuando se cancela el modal 93 // funcion ejecutada cuando se cancela el modal
96 } 94 }
97 ); 95 );
98 } 96 }
97 $scope.seleccionarVendedor = function () {
98 var modalInstance = $uibModal.open(
99 {
100 ariaLabelledBy: 'Busqueda de Vendedores',
101 templateUrl: 'modal-vendedores.html',
102 controller: 'modalVendedoresCtrl',
103 size: 'lg'
104 }
105 )
106 modalInstance.result.then(
107 function (vendedor) {
108 $scope.notaPedido.vendedor = vendedor.NomVen;
109 }, function () {
110
111 }
112 );
113 }
114 $scope.seleccionarPetrolera = function() {
115 var modalInstance = $uibModal.open(
116 {
117 ariaLabelledBy: 'Busqueda de Petrolera',
118 templateUrl: 'modal-petroleras.html',
119 controller: 'modalPetrolerasCtrl',
120 size: 'lg'
121 }
122 )
123 modalInstance.result.then(
124 function (petrolera) {
125 $scope.notaPedido.petrolera = petrolera.NOM;
126 }, function () {
127
128 }
129 );
130 }
131 $scope.seleccionarCliente = function() {
132 var modalInstance = $uibModal.open(
133 {
134 ariaLabelledBy: 'Busqueda de Cliente',
135 templateUrl: 'foca-busqueda-cliente-modal.html',
136 controller: 'focaBusquedaClienteModalController',
137 size: 'lg'
138 }
139 )
140 modalInstance.result.then(
141 function (cliente) {
142 $scope.notaPedido.cliente = cliente.nom;
143 }, function () {
144
145 }
146 );
147 }
99 $scope.obtenerDomicilios = function (id) { 148 $scope.obtenerDomicilios = function (id) {
100 crearNotaPedidoService.getDomicilios(id).then( 149 crearNotaPedidoService.getDomicilios(id).then(
101 function (res) { 150 function (res) {
102 $scope.notaPedido.domicilio = res.data; 151 $scope.notaPedido.domicilio = res.data;
103 } 152 }
104 ) 153 )
105 } 154 }
155 $scope.getSubTotal = function(item) {
156 var subTotal=0;
157 var array = $scope.articulosTabla.filter(a=>a.item<=item);
158 for(var i = 0; i< array.length; i++) {
159 subTotal+=array[i].precio*array[i].cantidad
160 }
161 return subTotal.toFixed(2);
162 }
163 $scope.cargarArticulos = function() {
164 idLista=$scope.notaPedido.precioCondicion;