Commit 31c01a8a666d1829fcaee58c32428528ca7b5097
Exists in
master
Merge branch 'master' into 'master'
Master (pmarco) See merge request modulos-npm/foca-crear-nota-pedido!94
Showing
1 changed file
Show diff stats
src/js/controller.js
1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
2 | [ | 2 | [ |
3 | '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService', | 3 | '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService', |
4 | 'focaModalService', 'notaPedidoBusinessService', '$rootScope', 'focaSeguimientoService', | 4 | 'focaModalService', 'notaPedidoBusinessService', '$rootScope', 'focaSeguimientoService', |
5 | function( | 5 | function( |
6 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, | 6 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, |
7 | notaPedidoBusinessService, $rootScope, focaSeguimientoService | 7 | notaPedidoBusinessService, $rootScope, focaSeguimientoService |
8 | ) { | 8 | ) { |
9 | $scope.botonera = [ | 9 | $scope.botonera = [ |
10 | {texto: 'Vendedor', accion: function() { | 10 | {texto: 'Vendedor', accion: function() { |
11 | validarNotaRemitada($scope.seleccionarVendedor);}}, | 11 | validarNotaRemitada($scope.seleccionarVendedor);}}, |
12 | {texto: 'Cliente', accion: function() { | 12 | {texto: 'Cliente', accion: function() { |
13 | validarNotaRemitada($scope.seleccionarCliente);}}, | 13 | validarNotaRemitada($scope.seleccionarCliente);}}, |
14 | {texto: 'Proveedor', accion: function() { | 14 | {texto: 'Proveedor', accion: function() { |
15 | validarNotaRemitada($scope.seleccionarProveedor);}}, | 15 | validarNotaRemitada($scope.seleccionarProveedor);}}, |
16 | {texto: 'Moneda', accion: function() { | 16 | {texto: 'Moneda', accion: function() { |
17 | validarNotaRemitada($scope.abrirModalMoneda);}}, | 17 | validarNotaRemitada($scope.abrirModalMoneda);}}, |
18 | {texto: 'Precios y condiciones', accion: function() { | 18 | {texto: 'Precios y condiciones', accion: function() { |
19 | validarNotaRemitada($scope.abrirModalListaPrecio);}}, | 19 | validarNotaRemitada($scope.abrirModalListaPrecio);}}, |
20 | {texto: 'Flete', accion: function() { | 20 | {texto: 'Flete', accion: function() { |
21 | validarNotaRemitada($scope.abrirModalFlete);}}, | 21 | validarNotaRemitada($scope.abrirModalFlete);}}, |
22 | {texto: '', accion: function() {}}, | 22 | {texto: '', accion: function() {}}, |
23 | {texto: '', accion: function() {}} | 23 | {texto: '', accion: function() {}} |
24 | ]; | 24 | ]; |
25 | 25 | ||
26 | $scope.datepickerAbierto = false; | 26 | $scope.datepickerAbierto = false; |
27 | 27 | ||
28 | $scope.show = false; | 28 | $scope.show = false; |
29 | $scope.cargando = true; | 29 | $scope.cargando = true; |
30 | $scope.dateOptions = { | 30 | $scope.dateOptions = { |
31 | maxDate: new Date(), | 31 | maxDate: new Date(), |
32 | minDate: new Date(2010, 0, 1) | 32 | minDate: new Date(2010, 0, 1) |
33 | }; | 33 | }; |
34 | 34 | ||
35 | $scope.notaPedido = { | 35 | $scope.notaPedido = { |
36 | id: 0, | 36 | id: 0, |
37 | vendedor: {}, | 37 | vendedor: {}, |
38 | cliente: {}, | 38 | cliente: {}, |
39 | proveedor: {}, | 39 | proveedor: {}, |
40 | domicilio: {dom: ''}, | 40 | domicilio: {dom: ''}, |
41 | moneda: {}, | 41 | moneda: {}, |
42 | cotizacion: {} | 42 | cotizacion: {} |
43 | }; | 43 | }; |
44 | var monedaPorDefecto; | 44 | var monedaPorDefecto; |
45 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 45 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
46 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | 46 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { |
47 | monedaPorDefecto = res.data[0]; | 47 | monedaPorDefecto = res.data[0]; |
48 | addCabecera('Moneda:', monedaPorDefecto.DETALLE); | 48 | addCabecera('Moneda:', monedaPorDefecto.DETALLE); |
49 | addCabecera('Fecha cotizacion:', | 49 | addCabecera('Fecha cotizacion:', |
50 | new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); | 50 | new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); |
51 | addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].VENDEDOR); | 51 | addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].VENDEDOR); |
52 | $scope.notaPedido.moneda = monedaPorDefecto; | 52 | $scope.notaPedido.moneda = monedaPorDefecto; |
53 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; | 53 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; |
54 | }); | 54 | }); |
55 | 55 | ||
56 | $scope.cabecera = []; | 56 | $scope.cabecera = []; |
57 | $scope.showCabecera = true; | 57 | $scope.showCabecera = true; |
58 | 58 | ||
59 | $scope.now = new Date(); | 59 | $scope.now = new Date(); |
60 | $scope.puntoVenta = '0000'; | 60 | $scope.puntoVenta = '0000'; |
61 | $scope.comprobante = '00000000'; | 61 | $scope.comprobante = '00000000'; |
62 | $scope.articulosTabla = []; | 62 | $scope.articulosTabla = []; |
63 | $scope.idLista = undefined; | 63 | $scope.idLista = undefined; |
64 | //La pantalla solo se usa para cargar pedidos | 64 | //La pantalla solo se usa para cargar pedidos |
65 | //var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); | 65 | //var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); |
66 | 66 | ||
67 | crearNotaPedidoService.getPrecioCondicion().then( | 67 | crearNotaPedidoService.getPrecioCondicion().then( |
68 | function(res) { | 68 | function(res) { |
69 | $scope.precioCondiciones = res.data; | 69 | $scope.precioCondiciones = res.data; |
70 | } | 70 | } |
71 | ); | 71 | ); |
72 | 72 | ||
73 | crearNotaPedidoService.getNumeroNotaPedido().then( | 73 | crearNotaPedidoService.getNumeroNotaPedido().then( |
74 | function(res) { | 74 | function(res) { |
75 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 75 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
76 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 76 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
77 | }, | 77 | }, |
78 | function(err) { | 78 | function(err) { |
79 | focaModalService.alert('La terminal no esta configurada correctamente'); | 79 | focaModalService.alert('La terminal no esta configurada correctamente'); |
80 | console.info(err); | 80 | console.info(err); |
81 | } | 81 | } |
82 | ); | 82 | ); |
83 | //La pantalla solo se usa para cargar pedidos | 83 | //La pantalla solo se usa para cargar pedidos |
84 | // if (notaPedidoTemp !== undefined) { | 84 | // if (notaPedidoTemp !== undefined) { |
85 | // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); | 85 | // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); |
86 | // $scope.notaPedido = notaPedidoTemp; | 86 | // $scope.notaPedido = notaPedidoTemp; |
87 | // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); | 87 | // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); |
88 | // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); | 88 | // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); |
89 | // $scope.idLista = $scope.notaPedido.precioCondicion; | 89 | // $scope.idLista = $scope.notaPedido.precioCondicion; |
90 | // crearNotaPedidoService | 90 | // crearNotaPedidoService |
91 | // .getArticulosByIdNotaPedido($scope.notaPedido.id).then( | 91 | // .getArticulosByIdNotaPedido($scope.notaPedido.id).then( |
92 | // function(res) { | 92 | // function(res) { |
93 | // $scope.articulosTabla = res.data; | 93 | // $scope.articulosTabla = res.data; |
94 | // } | 94 | // } |
95 | // ); | 95 | // ); |
96 | //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO | 96 | //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO |
97 | //(NO REQUERIDO EN ESTA VERSION) | 97 | //(NO REQUERIDO EN ESTA VERSION) |
98 | // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( | 98 | // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( |
99 | // function(res) { | 99 | // function(res) { |
100 | // $scope.notaPedido.domicilio = res.data; | 100 | // $scope.notaPedido.domicilio = res.data; |
101 | // } | 101 | // } |
102 | // ); | 102 | // ); |
103 | // } else { | 103 | // } else { |
104 | // $scope.notaPedido.fechaCarga = new Date(); | 104 | // $scope.notaPedido.fechaCarga = new Date(); |
105 | // $scope.notaPedido.bomba = '0'; | 105 | // $scope.notaPedido.bomba = '0'; |
106 | // $scope.notaPedido.flete = '0'; | 106 | // $scope.notaPedido.flete = '0'; |
107 | // $scope.idLista = undefined; | 107 | // $scope.idLista = undefined; |
108 | // } | 108 | // } |
109 | //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO | 109 | //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO |
110 | // $scope.addNewDom = function() { | 110 | // $scope.addNewDom = function() { |
111 | // $scope.notaPedido.domicilio.push({ 'id': 0 }); | 111 | // $scope.notaPedido.domicilio.push({ 'id': 0 }); |
112 | // }; | 112 | // }; |
113 | // $scope.removeNewChoice = function(choice) { | 113 | // $scope.removeNewChoice = function(choice) { |
114 | // if ($scope.notaPedido.domicilio.length > 1) { | 114 | // if ($scope.notaPedido.domicilio.length > 1) { |
115 | // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( | 115 | // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( |
116 | // function(c) { | 116 | // function(c) { |
117 | // return c.$$hashKey === choice.$$hashKey; | 117 | // return c.$$hashKey === choice.$$hashKey; |
118 | // } | 118 | // } |
119 | // ), 1); | 119 | // ), 1); |
120 | // } | 120 | // } |
121 | // }; | 121 | // }; |
122 | 122 | ||
123 | $scope.crearNotaPedido = function() { | 123 | $scope.crearNotaPedido = function() { |
124 | if(!$scope.notaPedido.vendedor.CodVen) { | 124 | if(!$scope.notaPedido.vendedor.CodVen) { |
125 | focaModalService.alert('Ingrese Vendedor'); | 125 | focaModalService.alert('Ingrese Vendedor'); |
126 | return; | 126 | return; |
127 | } else if(!$scope.notaPedido.cliente.COD) { | 127 | } else if(!$scope.notaPedido.cliente.COD) { |
128 | focaModalService.alert('Ingrese Cliente'); | 128 | focaModalService.alert('Ingrese Cliente'); |
129 | return; | 129 | return; |
130 | } else if(!$scope.notaPedido.proveedor.COD) { | 130 | } else if(!$scope.notaPedido.proveedor.COD) { |
131 | focaModalService.alert('Ingrese Proveedor'); | 131 | focaModalService.alert('Ingrese Proveedor'); |
132 | return; | 132 | return; |
133 | } else if(!$scope.notaPedido.moneda.ID) { | 133 | } else if(!$scope.notaPedido.moneda.ID) { |
134 | focaModalService.alert('Ingrese Moneda'); | 134 | focaModalService.alert('Ingrese Moneda'); |
135 | return; | 135 | return; |
136 | } else if(!$scope.notaPedido.cotizacion.ID) { | 136 | } else if(!$scope.notaPedido.cotizacion.ID) { |
137 | focaModalService.alert('Ingrese Cotización'); | 137 | focaModalService.alert('Ingrese Cotización'); |
138 | return; | 138 | return; |
139 | } else if(!$scope.plazosPagos) { | 139 | } else if(!$scope.plazosPagos) { |
140 | focaModalService.alert('Ingrese Precios y Condiciones'); | 140 | focaModalService.alert('Ingrese Precios y Condiciones'); |
141 | return; | 141 | return; |
142 | } else if( | 142 | } else if( |
143 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 143 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
144 | { | 144 | { |
145 | focaModalService.alert('Ingrese Flete'); | 145 | focaModalService.alert('Ingrese Flete'); |
146 | return; | 146 | return; |
147 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 147 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
148 | focaModalService.alert('Ingrese Domicilio'); | 148 | focaModalService.alert('Ingrese Domicilio'); |
149 | return; | 149 | return; |
150 | } else if($scope.articulosTabla.length === 0) { | 150 | } else if($scope.articulosTabla.length === 0) { |
151 | focaModalService.alert('Debe cargar al menos un articulo'); | 151 | focaModalService.alert('Debe cargar al menos un articulo'); |
152 | return; | 152 | return; |
153 | } | 153 | } |
154 | var date = new Date(); | ||
155 | var notaPedido = { | 154 | var notaPedido = { |
156 | id: $scope.notaPedido.id, | 155 | id: $scope.notaPedido.id, |
157 | fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) | 156 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), |
158 | .toISOString().slice(0, 19).replace('T', ' '), | ||
159 | idVendedor: $scope.notaPedido.vendedor.CodVen, | 157 | idVendedor: $scope.notaPedido.vendedor.CodVen, |
160 | idCliente: $scope.notaPedido.cliente.COD, | 158 | idCliente: $scope.notaPedido.cliente.COD, |
161 | nombreCliente: $scope.notaPedido.cliente.NOM, | 159 | nombreCliente: $scope.notaPedido.cliente.NOM, |
162 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 160 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
163 | idProveedor: $scope.notaPedido.proveedor.COD, | 161 | idProveedor: $scope.notaPedido.proveedor.COD, |
164 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID | 162 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID |
165 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 163 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
166 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 164 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
167 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 165 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
168 | flete: $scope.notaPedido.flete, | 166 | flete: $scope.notaPedido.flete, |
169 | fob: $scope.notaPedido.fob, | 167 | fob: $scope.notaPedido.fob, |
170 | bomba: $scope.notaPedido.bomba, | 168 | bomba: $scope.notaPedido.bomba, |
171 | kilometros: $scope.notaPedido.kilometros, | 169 | kilometros: $scope.notaPedido.kilometros, |
172 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 170 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
173 | estado: 0, | 171 | estado: 0, |
174 | total: $scope.getTotal() | 172 | total: $scope.getTotal() |
175 | }; | 173 | }; |
176 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 174 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
177 | function(data) { | 175 | function(data) { |
178 | // Al guardar los datos de la nota de pedido logueamos la | 176 | // Al guardar los datos de la nota de pedido logueamos la |
179 | // actividad para su seguimiento. | 177 | // actividad para su seguimiento. |
180 | focaSeguimientoService.guardarPosicion( | 178 | focaSeguimientoService.guardarPosicion( |
181 | $scope.notaPedido.vendedor.CodVen, | 179 | $scope.notaPedido.vendedor.CodVen, |
182 | 'Nota de pedido', | 180 | 'Nota de pedido', |
183 | 'Nº: ' + $filter('comprobante')([ | 181 | 'Nº: ' + $filter('comprobante')([ |
184 | $scope.puntoVenta, | 182 | $scope.puntoVenta, |
185 | $scope.comprobante | 183 | $scope.comprobante |
186 | ]) + '<br/>' + | 184 | ]) + '<br/>' + |
187 | 'Vendedor: ' + $scope.notaPedido.vendedor.NomVen + '<br/>' + | 185 | 'Vendedor: ' + $scope.notaPedido.vendedor.NomVen + '<br/>' + |
188 | 'Total: ' + $filter('currency')($scope.getTotal()) | 186 | 'Total: ' + $filter('currency')($scope.getTotal()) |
189 | ); | 187 | ); |
190 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, | 188 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, |
191 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 189 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
192 | var plazos = $scope.plazosPagos; | 190 | var plazos = $scope.plazosPagos; |
193 | 191 | ||
194 | for(var j = 0; j < plazos.length; j++) { | 192 | for(var j = 0; j < plazos.length; j++) { |
195 | var json = { | 193 | var json = { |
196 | idPedido: data.data.id, | 194 | idPedido: data.data.id, |
197 | dias: plazos[j].dias | 195 | dias: plazos[j].dias |
198 | }; | 196 | }; |
199 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); | 197 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); |
200 | } | 198 | } |
201 | notaPedidoBusinessService.addEstado(data.data.id, | 199 | notaPedidoBusinessService.addEstado(data.data.id, |
202 | $scope.notaPedido.vendedor.CodVen); | 200 | $scope.notaPedido.vendedor.CodVen); |
203 | 201 | ||
204 | focaModalService.alert('Nota pedido creada'); | 202 | focaModalService.alert('Nota pedido creada'); |
205 | $scope.cabecera = []; | 203 | $scope.cabecera = []; |
206 | addCabecera('Moneda:', $scope.notaPedido.moneda.detalle); | 204 | addCabecera('Moneda:', $scope.notaPedido.moneda.detalle); |
207 | addCabecera( | 205 | addCabecera( |
208 | 'Fecha cotizacion:', | 206 | 'Fecha cotizacion:', |
209 | $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') | 207 | $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') |
210 | ); | 208 | ); |
211 | addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.VENDEDOR); | 209 | addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.VENDEDOR); |
212 | crearNotaPedidoService.getNumeroNotaPedido().then( | 210 | crearNotaPedidoService.getNumeroNotaPedido().then( |
213 | function(res) { | 211 | function(res) { |
214 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 212 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
215 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 213 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
216 | }, | 214 | }, |
217 | function(err) { | 215 | function(err) { |
218 | focaModalService.alert( | 216 | focaModalService.alert( |
219 | 'La terminal no esta configurada correctamente'); | 217 | 'La terminal no esta configurada correctamente'); |
220 | console.info(err); | 218 | console.info(err); |
221 | } | 219 | } |
222 | ); | 220 | ); |
223 | $scope.notaPedido.vendedor = {}; | 221 | $scope.notaPedido.vendedor = {}; |
224 | $scope.notaPedido.cliente = {}; | 222 | $scope.notaPedido.cliente = {}; |
225 | $scope.notaPedido.proveedor = {}; | 223 | $scope.notaPedido.proveedor = {}; |
226 | $scope.notaPedido.domicilio = {}; | 224 | $scope.notaPedido.domicilio = {}; |
227 | $scope.notaPedido.flete = null; | 225 | $scope.notaPedido.flete = null; |
228 | $scope.notaPedido.fob = null; | 226 | $scope.notaPedido.fob = null; |
229 | $scope.notaPedido.bomba = null; | 227 | $scope.notaPedido.bomba = null; |
230 | $scope.notaPedido.kilometros = null; | 228 | $scope.notaPedido.kilometros = null; |
231 | $scope.articulosTabla = []; | 229 | $scope.articulosTabla = []; |
232 | }, | 230 | }, |
233 | function(error) { | 231 | function(error) { |
234 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 232 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
235 | console.info(error); | 233 | console.info(error); |
236 | } | 234 | } |
237 | ); | 235 | ); |
238 | }; | 236 | }; |
239 | 237 | ||
240 | $scope.seleccionarNotaPedido = function() { | 238 | $scope.seleccionarNotaPedido = function() { |
241 | var modalInstance = $uibModal.open( | 239 | var modalInstance = $uibModal.open( |
242 | { | 240 | { |
243 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 241 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
244 | templateUrl: 'foca-modal-nota-pedido.html', | 242 | templateUrl: 'foca-modal-nota-pedido.html', |
245 | controller: 'focaModalNotaPedidoController', | 243 | controller: 'focaModalNotaPedidoController', |
246 | size: 'lg', | 244 | size: 'lg', |
247 | resolve: {usadoPor: function(){return 'notaPedido';}} | 245 | resolve: {usadoPor: function(){return 'notaPedido';}} |
248 | } | 246 | } |
249 | ); | 247 | ); |
250 | modalInstance.result.then( | 248 | modalInstance.result.then( |
251 | function(notaPedido) { | 249 | function(notaPedido) { |
250 | $scope.now = new Date(notaPedido.fechaCarga); | ||
252 | //añado cabeceras | 251 | //añado cabeceras |
253 | $scope.notaPedido.id = notaPedido.id; | 252 | $scope.notaPedido.id = notaPedido.id; |
254 | removeCabecera('Moneda:'); | 253 | removeCabecera('Moneda:'); |
255 | removeCabecera('Fecha cotizacion:'); | 254 | removeCabecera('Fecha cotizacion:'); |
256 | removeCabecera('Cotizacion:'); | 255 | removeCabecera('Cotizacion:'); |
257 | var cabeceras = [ | 256 | var cabeceras = [ |
258 | { | 257 | { |
259 | label: 'Moneda:', | 258 | label: 'Moneda:', |
260 | valor: notaPedido.cotizacion[0].moneda[0].DETALLE | 259 | valor: notaPedido.cotizacion[0].moneda[0].DETALLE |
261 | }, | 260 | }, |
262 | { | 261 | { |
263 | label: 'Fecha cotizacion:', | 262 | label: 'Fecha cotizacion:', |
264 | valor: $filter('date')(notaPedido.cotizacion[0].FECHA, | 263 | valor: $filter('date')(notaPedido.cotizacion[0].FECHA, |
265 | 'dd/MM/yyyy') | 264 | 'dd/MM/yyyy') |
266 | }, | 265 | }, |
267 | { | 266 | { |
268 | label: 'Cotizacion:', | 267 | label: 'Cotizacion:', |
269 | valor: notaPedido.cotizacion[0].VENDEDOR | 268 | valor: notaPedido.cotizacion[0].VENDEDOR |
270 | }, | 269 | }, |
271 | { | 270 | { |
272 | label: 'Cliente:', | 271 | label: 'Cliente:', |
273 | valor: notaPedido.cliente[0].NOM | 272 | valor: notaPedido.cliente[0].NOM |
274 | }, | 273 | }, |
275 | { | 274 | { |
276 | label: 'Domicilio:', | 275 | label: 'Domicilio:', |
277 | valor: notaPedido.domicilioStamp | 276 | valor: notaPedido.domicilioStamp |
278 | }, | 277 | }, |
279 | { | 278 | { |
280 | label: 'Vendedor:', | 279 | label: 'Vendedor:', |
281 | valor: notaPedido.vendedor[0].NomVen | 280 | valor: notaPedido.vendedor[0].NomVen |
282 | }, | 281 | }, |
283 | { | 282 | { |
284 | label: 'Proveedor:', | 283 | label: 'Proveedor:', |
285 | valor: notaPedido.proveedor[0].NOM | 284 | valor: notaPedido.proveedor[0].NOM |
286 | }, | 285 | }, |
287 | { | 286 | { |
288 | label: 'Flete:', | 287 | label: 'Flete:', |
289 | valor: notaPedido.flete === 1 ? 'Si' : 'No' | 288 | valor: notaPedido.flete === 1 ? 'Si' : 'No' |
290 | }, | 289 | }, |
291 | { | 290 | { |
292 | label: 'FOB:', | 291 | label: 'FOB:', |
293 | valor: notaPedido.fob === 1 ? 'Si' : 'No' | 292 | valor: notaPedido.fob === 1 ? 'Si' : 'No' |
294 | }, | 293 | }, |
295 | { | 294 | { |
296 | label: 'Precio condicion:', | 295 | label: 'Precio condicion:', |
297 | valor: valorPrecioCondicion() | 296 | valor: valorPrecioCondicion() |
298 | } | 297 | } |
299 | ]; | 298 | ]; |
300 | //TODO MOSTRAR PLAZOS | 299 | //TODO MOSTRAR PLAZOS |
301 | function valorPrecioCondicion() { | 300 | function valorPrecioCondicion() { |
302 | if(notaPedido.idPrecioCondicion > 0) { | 301 | if(notaPedido.idPrecioCondicion > 0) { |
303 | return notaPedido.precioCondicion[0].nombre; | 302 | return notaPedido.precioCondicion[0].nombre; |
304 | } else { | 303 | } else { |
305 | return 'Ingreso Manual'; | 304 | return 'Ingreso Manual'; |
306 | } | 305 | } |
307 | } | 306 | } |
308 | 307 | ||
309 | if(notaPedido.flete === 1) { | 308 | if(notaPedido.flete === 1) { |
310 | var cabeceraBomba = { | 309 | var cabeceraBomba = { |
311 | label: 'Bomba', | 310 | label: 'Bomba', |
312 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 311 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
313 | }; | 312 | }; |
314 | if(notaPedido.kilometros) { | 313 | if(notaPedido.kilometros) { |
315 | var cabeceraKilometros = { | 314 | var cabeceraKilometros = { |
316 | label: 'Kilometros', | 315 | label: 'Kilometros', |
317 | valor: notaPedido.kilometros | 316 | valor: notaPedido.kilometros |
318 | }; | 317 | }; |
319 | cabeceras.push(cabeceraKilometros); | 318 | cabeceras.push(cabeceraKilometros); |
320 | } | 319 | } |
321 | cabeceras.push(cabeceraBomba); | 320 | cabeceras.push(cabeceraBomba); |
322 | } | 321 | } |
323 | $scope.articulosTabla = notaPedido.articulosNotaPedido; | 322 | $scope.articulosTabla = notaPedido.articulosNotaPedido; |
324 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, | 323 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, |
325 | notaPedido.cotizacion[0].VENDEDOR); | 324 | notaPedido.cotizacion[0].VENDEDOR); |
326 | if(notaPedido.precioCondicion.length > 0) { | 325 | if(notaPedido.precioCondicion.length > 0) { |
327 | $scope.idLista = notaPedido.precioCondicion[0].idListaPrecio; | 326 | $scope.idLista = notaPedido.precioCondicion[0].idListaPrecio; |
328 | } else { | 327 | } else { |
329 | $scope.idLista = -1; | 328 | $scope.idLista = -1; |
330 | } | 329 | } |
331 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); | 330 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); |
332 | $scope.notaPedido = notaPedido; | 331 | $scope.notaPedido = notaPedido; |
333 | $scope.notaPedido.vendedor = notaPedido.vendedor[0]; | 332 | $scope.notaPedido.vendedor = notaPedido.vendedor[0]; |
334 | $scope.notaPedido.cliente = notaPedido.cliente[0]; | 333 | $scope.notaPedido.cliente = notaPedido.cliente[0]; |
335 | $scope.notaPedido.proveedor = notaPedido.proveedor[0]; | 334 | $scope.notaPedido.proveedor = notaPedido.proveedor[0]; |
336 | $scope.notaPedido.moneda = notaPedido.cotizacion[0].moneda[0]; | 335 | $scope.notaPedido.moneda = notaPedido.cotizacion[0].moneda[0]; |
337 | $scope.notaPedido.cotizacion = notaPedido.cotizacion[0]; | 336 | $scope.notaPedido.cotizacion = notaPedido.cotizacion[0]; |
338 | $scope.plazosPagos = notaPedido.plazoPago; | 337 | $scope.plazosPagos = notaPedido.plazoPago; |
339 | addArrayCabecera(cabeceras); | 338 | addArrayCabecera(cabeceras); |
340 | 339 | ||
341 | }, function() { | 340 | }, function() { |
342 | // funcion ejecutada cuando se cancela el modal | 341 | // funcion ejecutada cuando se cancela el modal |
343 | } | 342 | } |
344 | ); | 343 | ); |
345 | }; | 344 | }; |
346 | 345 | ||
347 | $scope.seleccionarArticulo = function() { | 346 | $scope.seleccionarArticulo = function() { |
348 | if ($scope.idLista === undefined) { | 347 | if ($scope.idLista === undefined) { |
349 | focaModalService.alert( | 348 | focaModalService.alert( |
350 | 'Primero seleccione una lista de precio y condicion'); | 349 | 'Primero seleccione una lista de precio y condicion'); |
351 | return; | 350 | return; |
352 | } | 351 | } |
353 | var modalInstance = $uibModal.open( | 352 | var modalInstance = $uibModal.open( |
354 | { | 353 | { |
355 | ariaLabelledBy: 'Busqueda de Productos', | 354 | ariaLabelledBy: 'Busqueda de Productos', |
356 | templateUrl: 'modal-busqueda-productos.html', | 355 | templateUrl: 'modal-busqueda-productos.html', |
357 | controller: 'modalBusquedaProductosCtrl', | 356 | controller: 'modalBusquedaProductosCtrl', |
358 | resolve: { | 357 | resolve: { |
359 | parametroProducto: { | 358 | parametroProducto: { |
360 | idLista: $scope.idLista, | 359 | idLista: $scope.idLista, |
361 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 360 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
362 | simbolo: $scope.notaPedido.moneda.SIMBOLO | 361 | simbolo: $scope.notaPedido.moneda.SIMBOLO |
363 | } | 362 | } |
364 | }, | 363 | }, |
365 | size: 'lg' | 364 | size: 'lg' |
366 | } | 365 | } |
367 | ); | 366 | ); |
368 | modalInstance.result.then( | 367 | modalInstance.result.then( |
369 | function(producto) { | 368 | function(producto) { |
370 | var newArt = | 369 | var newArt = |
371 | { | 370 | { |
372 | id: 0, | 371 | id: 0, |
373 | codigo: producto.codigo, | 372 | codigo: producto.codigo, |
374 | sector: producto.sector, | 373 | sector: producto.sector, |
375 | sectorCodigo: producto.sector + '-' + producto.codigo, | 374 | sectorCodigo: producto.sector + '-' + producto.codigo, |
376 | descripcion: producto.descripcion, | 375 | descripcion: producto.descripcion, |
377 | item: $scope.articulosTabla.length + 1, | 376 | item: $scope.articulosTabla.length + 1, |
378 | nombre: producto.descripcion, | 377 | nombre: producto.descripcion, |
379 | precio: parseFloat(producto.precio.toFixed(4)), | 378 | precio: parseFloat(producto.precio.toFixed(4)), |
380 | costoUnitario: producto.costo, | 379 | costoUnitario: producto.costo, |
381 | editCantidad: false, | 380 | editCantidad: false, |
382 | editPrecio: false, | 381 | editPrecio: false, |
383 | rubro: producto.CodRub, | 382 | rubro: producto.CodRub, |
384 | exentoUnitario: producto.precio, | 383 | exentoUnitario: producto.precio, |
385 | ivaUnitario: producto.IMPIVA, | 384 | ivaUnitario: producto.IMPIVA, |
386 | impuestoInternoUnitario: producto.ImpInt, | 385 | impuestoInternoUnitario: producto.ImpInt, |
387 | impuestoInterno1Unitario: producto.ImpInt2, | 386 | impuestoInterno1Unitario: producto.ImpInt2, |
388 | impuestoInterno2Unitario: producto.ImpInt3, | 387 | impuestoInterno2Unitario: producto.ImpInt3, |
389 | precioLista: producto.precio, | 388 | precioLista: producto.precio, |
390 | combustible: 1, | 389 | combustible: 1, |
391 | facturado: 0 | 390 | facturado: 0 |
392 | }; | 391 | }; |
393 | $scope.articuloACargar = newArt; | 392 | $scope.articuloACargar = newArt; |
394 | $scope.cargando = false; | 393 | $scope.cargando = false; |
395 | }, function() { | 394 | }, function() { |
396 | // funcion ejecutada cuando se cancela el modal | 395 | // funcion ejecutada cuando se cancela el modal |
397 | } | 396 | } |
398 | ); | 397 | ); |
399 | }; | 398 | }; |
400 | 399 | ||
401 | $scope.seleccionarVendedor = function() { | 400 | $scope.seleccionarVendedor = function() { |
402 | var modalInstance = $uibModal.open( | 401 | var modalInstance = $uibModal.open( |
403 | { | 402 | { |
404 | ariaLabelledBy: 'Busqueda de Vendedores', | 403 | ariaLabelledBy: 'Busqueda de Vendedores', |
405 | templateUrl: 'modal-vendedores.html', | 404 | templateUrl: 'modal-vendedores.html', |
406 | controller: 'modalVendedoresCtrl', | 405 | controller: 'modalVendedoresCtrl', |
407 | size: 'lg' | 406 | size: 'lg' |
408 | } | 407 | } |
409 | ); | 408 | ); |
410 | modalInstance.result.then( | 409 | modalInstance.result.then( |
411 | function(vendedor) { | 410 | function(vendedor) { |
412 | addCabecera('Vendedor:', vendedor.NomVen); | 411 | addCabecera('Vendedor:', vendedor.NomVen); |
413 | $scope.notaPedido.vendedor = vendedor; | 412 | $scope.notaPedido.vendedor = vendedor; |
414 | }, function() { | 413 | }, function() { |
415 | 414 | ||
416 | } | 415 | } |
417 | ); | 416 | ); |
418 | }; | 417 | }; |
419 | 418 | ||
420 | $scope.seleccionarProveedor = function() { | 419 | $scope.seleccionarProveedor = function() { |
421 | var modalInstance = $uibModal.open( | 420 | var modalInstance = $uibModal.open( |
422 | { | 421 | { |
423 | ariaLabelledBy: 'Busqueda de Proveedor', | 422 | ariaLabelledBy: 'Busqueda de Proveedor', |
424 | templateUrl: 'modal-proveedor.html', | 423 | templateUrl: 'modal-proveedor.html', |
425 | controller: 'focaModalProveedorCtrl', | 424 | controller: 'focaModalProveedorCtrl', |
426 | size: 'lg', | 425 | size: 'lg', |
427 | resolve: { | 426 | resolve: { |
428 | transportista: function() { | 427 | transportista: function() { |
429 | return false; | 428 | return false; |
430 | } | 429 | } |
431 | } | 430 | } |
432 | } | 431 | } |
433 | ); | 432 | ); |
434 | modalInstance.result.then( | 433 | modalInstance.result.then( |
435 | function(proveedor) { | 434 | function(proveedor) { |
436 | $scope.notaPedido.proveedor = proveedor; | 435 | $scope.notaPedido.proveedor = proveedor; |
437 | addCabecera('Proveedor:', proveedor.NOM); | 436 | addCabecera('Proveedor:', proveedor.NOM); |
438 | }, function() { | 437 | }, function() { |
439 | 438 | ||
440 | } | 439 | } |
441 | ); | 440 | ); |
442 | }; | 441 | }; |
443 | 442 | ||
444 | $scope.seleccionarCliente = function() { | 443 | $scope.seleccionarCliente = function() { |
445 | 444 | ||
446 | var modalInstance = $uibModal.open( | 445 | var modalInstance = $uibModal.open( |
447 | { | 446 | { |
448 | ariaLabelledBy: 'Busqueda de Cliente', | 447 | ariaLabelledBy: 'Busqueda de Cliente', |
449 | templateUrl: 'foca-busqueda-cliente-modal.html', | 448 | templateUrl: 'foca-busqueda-cliente-modal.html', |
450 | controller: 'focaBusquedaClienteModalController', | 449 | controller: 'focaBusquedaClienteModalController', |
451 | size: 'lg' | 450 | size: 'lg' |
452 | } | 451 | } |
453 | ); | 452 | ); |
454 | modalInstance.result.then( | 453 | modalInstance.result.then( |
455 | function(cliente) { | 454 | function(cliente) { |
456 | $scope.abrirModalDomicilios(cliente); | 455 | $scope.abrirModalDomicilios(cliente); |
457 | }, function() { | 456 | }, function() { |
458 | 457 | ||
459 | } | 458 | } |
460 | ); | 459 | ); |
461 | }; | 460 | }; |
462 | 461 | ||
463 | $scope.abrirModalDomicilios = function(cliente) { | 462 | $scope.abrirModalDomicilios = function(cliente) { |
464 | var modalInstanceDomicilio = $uibModal.open( | 463 | var modalInstanceDomicilio = $uibModal.open( |
465 | { | 464 | { |
466 | ariaLabelledBy: 'Busqueda de Domicilios', | 465 | ariaLabelledBy: 'Busqueda de Domicilios', |
467 | templateUrl: 'modal-domicilio.html', | 466 | templateUrl: 'modal-domicilio.html', |
468 | controller: 'focaModalDomicilioController', | 467 | controller: 'focaModalDomicilioController', |
469 | resolve: { idCliente: function() { return cliente.cod; }}, | 468 | resolve: { idCliente: function() { return cliente.cod; }}, |
470 | size: 'lg', | 469 | size: 'lg', |
471 | } | 470 | } |
472 | ); | 471 | ); |
473 | modalInstanceDomicilio.result.then( | 472 | modalInstanceDomicilio.result.then( |
474 | function(domicilio) { | 473 | function(domicilio) { |
475 | $scope.notaPedido.domicilio = domicilio; | 474 | $scope.notaPedido.domicilio = domicilio; |
476 | $scope.notaPedido.cliente = { | 475 | $scope.notaPedido.cliente = { |
477 | COD: cliente.cod, | 476 | COD: cliente.cod, |
478 | CUIT: cliente.cuit, | 477 | CUIT: cliente.cuit, |
479 | NOM: cliente.nom | 478 | NOM: cliente.nom |
480 | }; | 479 | }; |
481 | addCabecera('Cliente:', cliente.nom); | 480 | addCabecera('Cliente:', cliente.nom); |
482 | var domicilioStamp = | 481 | var domicilioStamp = |
483 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 482 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
484 | domicilio.Localidad + ', ' + domicilio.Provincia; | 483 | domicilio.Localidad + ', ' + domicilio.Provincia; |
485 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 484 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
486 | addCabecera('Domicilio:', domicilioStamp); | 485 | addCabecera('Domicilio:', domicilioStamp); |
487 | }, function() { | 486 | }, function() { |
488 | $scope.seleccionarCliente(); | 487 | $scope.seleccionarCliente(); |
489 | return; | 488 | return; |
490 | } | 489 | } |
491 | ); | 490 | ); |
492 | }; | 491 | }; |
493 | 492 | ||
494 | $scope.mostrarFichaCliente = function() { | 493 | $scope.mostrarFichaCliente = function() { |
495 | $uibModal.open( | 494 | $uibModal.open( |
496 | { | 495 | { |
497 | ariaLabelledBy: 'Datos del Cliente', | 496 | ariaLabelledBy: 'Datos del Cliente', |
498 | templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', | 497 | templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', |
499 | controller: 'focaCrearNotaPedidoFichaClienteController', | 498 | controller: 'focaCrearNotaPedidoFichaClienteController', |
500 | size: 'lg' | 499 | size: 'lg' |
501 | } | 500 | } |
502 | ); | 501 | ); |
503 | }; | 502 | }; |
504 | 503 | ||
505 | $scope.getTotal = function() { | 504 | $scope.getTotal = function() { |
506 | var total = 0; | 505 | var total = 0; |
507 | var arrayTempArticulos = $scope.articulosTabla; | 506 | var arrayTempArticulos = $scope.articulosTabla; |
508 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 507 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
509 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 508 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
510 | } | 509 | } |
511 | return parseFloat(total.toFixed(2)); | 510 | return parseFloat(total.toFixed(2)); |
512 | }; | 511 | }; |
513 | 512 | ||
514 | $scope.getSubTotal = function() { | 513 | $scope.getSubTotal = function() { |
515 | if($scope.articuloACargar) { | 514 | if($scope.articuloACargar) { |
516 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 515 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
517 | } | 516 | } |
518 | }; | 517 | }; |
519 | 518 | ||
520 | $scope.abrirModalListaPrecio = function() { | 519 | $scope.abrirModalListaPrecio = function() { |
521 | var modalInstance = $uibModal.open( | 520 | var modalInstance = $uibModal.open( |
522 | { | 521 | { |
523 | ariaLabelledBy: 'Busqueda de Precio Condición', | 522 | ariaLabelledBy: 'Busqueda de Precio Condición', |
524 | templateUrl: 'modal-precio-condicion.html', | 523 | templateUrl: 'modal-precio-condicion.html', |
525 | controller: 'focaModalPrecioCondicionController', | 524 | controller: 'focaModalPrecioCondicionController', |
526 | size: 'lg' | 525 | size: 'lg' |
527 | } | 526 | } |
528 | ); | 527 | ); |
529 | modalInstance.result.then( | 528 | modalInstance.result.then( |
530 | function(precioCondicion) { | 529 | function(precioCondicion) { |
531 | var cabecera = ''; | 530 | var cabecera = ''; |
532 | var plazosConcat = ''; | 531 | var plazosConcat = ''; |
533 | if(!Array.isArray(precioCondicion)) { | 532 | if(!Array.isArray(precioCondicion)) { |
534 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 533 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
535 | $scope.plazosPagos = precioCondicion.plazoPago; | 534 | $scope.plazosPagos = precioCondicion.plazoPago; |
536 | $scope.idLista = precioCondicion.idListaPrecio; | 535 | $scope.idLista = precioCondicion.idListaPrecio; |
537 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 536 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
538 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 537 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
539 | } | 538 | } |
540 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); | 539 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); |
541 | } else { //Cuando se ingresan los plazos manualmente | 540 | } else { //Cuando se ingresan los plazos manualmente |
542 | $scope.notaPedido.idPrecioCondicion = 0; | 541 | $scope.notaPedido.idPrecioCondicion = 0; |
543 | $scope.idLista = -1; //-1, el modal productos busca todos los productos | 542 | $scope.idLista = -1; //-1, el modal productos busca todos los productos |
544 | $scope.plazosPagos = precioCondicion; | 543 | $scope.plazosPagos = precioCondicion; |
545 | for(var j = 0; j < precioCondicion.length; j++) { | 544 | for(var j = 0; j < precioCondicion.length; j++) { |
546 | plazosConcat += precioCondicion[j].dias + ' '; | 545 | plazosConcat += precioCondicion[j].dias + ' '; |
547 | } | 546 | } |
548 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 547 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
549 | } | 548 | } |
550 | $scope.articulosTabla = []; | 549 | $scope.articulosTabla = []; |
551 | addCabecera('Precios y condiciones:', cabecera); | 550 | addCabecera('Precios y condiciones:', cabecera); |
552 | }, function() { | 551 | }, function() { |
553 | 552 | ||
554 | } | 553 | } |
555 | ); | 554 | ); |
556 | }; | 555 | }; |
557 | 556 | ||
558 | $scope.abrirModalFlete = function() { | 557 | $scope.abrirModalFlete = function() { |
559 | var modalInstance = $uibModal.open( | 558 | var modalInstance = $uibModal.open( |
560 | { | 559 | { |
561 | ariaLabelledBy: 'Busqueda de Flete', | 560 | ariaLabelledBy: 'Busqueda de Flete', |
562 | templateUrl: 'modal-flete.html', | 561 | templateUrl: 'modal-flete.html', |
563 | controller: 'focaModalFleteController', | 562 | controller: 'focaModalFleteController', |
564 | size: 'lg', | 563 | size: 'lg', |
565 | resolve: { | 564 | resolve: { |
566 | parametrosFlete: | 565 | parametrosFlete: |
567 | function() { | 566 | function() { |
568 | return { | 567 | return { |
569 | flete: $scope.notaPedido.fob ? 'FOB' : | 568 | flete: $scope.notaPedido.fob ? 'FOB' : |
570 | ( $scope.notaPedido.flete ? '1' : | 569 | ( $scope.notaPedido.flete ? '1' : |
571 | ($scope.notaPedido.flete === undefined ? null : '0')), | 570 | ($scope.notaPedido.flete === undefined ? null : '0')), |
572 | bomba: $scope.notaPedido.bomba ? '1' : | 571 | bomba: $scope.notaPedido.bomba ? '1' : |
573 | ($scope.notaPedido.bomba === undefined ? null : '0'), | 572 | ($scope.notaPedido.bomba === undefined ? null : '0'), |
574 | kilometros: $scope.notaPedido.kilometros | 573 | kilometros: $scope.notaPedido.kilometros |
575 | }; | 574 | }; |
576 | } | 575 | } |
577 | } | 576 | } |
578 | } | 577 | } |
579 | ); | 578 | ); |
580 | modalInstance.result.then( | 579 | modalInstance.result.then( |
581 | function(datos) { | 580 | function(datos) { |
582 | $scope.notaPedido.flete = datos.flete; | 581 | $scope.notaPedido.flete = datos.flete; |
583 | $scope.notaPedido.fob = datos.FOB; | 582 | $scope.notaPedido.fob = datos.FOB; |
584 | $scope.notaPedido.bomba = datos.bomba; | 583 | $scope.notaPedido.bomba = datos.bomba; |
585 | $scope.notaPedido.kilometros = datos.kilometros; | 584 | $scope.notaPedido.kilometros = datos.kilometros; |
586 | addCabecera('FOB:', datos.FOB ? 'Si' : 'No'); | 585 | addCabecera('FOB:', datos.FOB ? 'Si' : 'No'); |
587 | addCabecera('Flete:', datos.flete ? 'Si' : 'No'); | 586 | addCabecera('Flete:', datos.flete ? 'Si' : 'No'); |
588 | if(datos.flete) { | 587 | if(datos.flete) { |
589 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); | 588 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); |
590 | addCabecera('Kilometros:', datos.kilometros); | 589 | addCabecera('Kilometros:', datos.kilometros); |
591 | } else { | 590 | } else { |
592 | removeCabecera('Bomba:'); | 591 | removeCabecera('Bomba:'); |
593 | removeCabecera('Kilometros:'); | 592 | removeCabecera('Kilometros:'); |
594 | $scope.notaPedido.bomba = false; | 593 | $scope.notaPedido.bomba = false; |
595 | $scope.notaPedido.kilometros = null; | 594 | $scope.notaPedido.kilometros = null; |
596 | } | 595 | } |
597 | }, function() { | 596 | }, function() { |
598 | 597 | ||
599 | } | 598 | } |
600 | ); | 599 | ); |
601 | }; | 600 | }; |
602 | 601 | ||
603 | $scope.abrirModalMoneda = function() { | 602 | $scope.abrirModalMoneda = function() { |
604 | var modalInstance = $uibModal.open( | 603 | var modalInstance = $uibModal.open( |
605 | { | 604 | { |
606 | ariaLabelledBy: 'Busqueda de Moneda', | 605 | ariaLabelledBy: 'Busqueda de Moneda', |
607 | templateUrl: 'modal-moneda.html', | 606 | templateUrl: 'modal-moneda.html', |
608 | controller: 'focaModalMonedaController', | 607 | controller: 'focaModalMonedaController', |
609 | size: 'lg' | 608 | size: 'lg' |
610 | } | 609 | } |
611 | ); | 610 | ); |
612 | modalInstance.result.then( | 611 | modalInstance.result.then( |
613 | function(moneda) { | 612 | function(moneda) { |
614 | $scope.abrirModalCotizacion(moneda); | 613 | $scope.abrirModalCotizacion(moneda); |
615 | }, function() { | 614 | }, function() { |
616 | 615 | ||
617 | } | 616 | } |
618 | ); | 617 | ); |
619 | }; | 618 | }; |
620 | 619 | ||
621 | $scope.abrirModalCotizacion = function(moneda) { | 620 | $scope.abrirModalCotizacion = function(moneda) { |
622 | var modalInstance = $uibModal.open( | 621 | var modalInstance = $uibModal.open( |
623 | { | 622 | { |
624 | ariaLabelledBy: 'Busqueda de Cotización', | 623 | ariaLabelledBy: 'Busqueda de Cotización', |
625 | templateUrl: 'modal-cotizacion.html', | 624 | templateUrl: 'modal-cotizacion.html', |
626 | controller: 'focaModalCotizacionController', | 625 | controller: 'focaModalCotizacionController', |
627 | size: 'lg', | 626 | size: 'lg', |
628 | resolve: {idMoneda: function() {return moneda.ID;}} | 627 | resolve: {idMoneda: function() {return moneda.ID;}} |
629 | } | 628 | } |
630 | ); | 629 | ); |
631 | modalInstance.result.then( | 630 | modalInstance.result.then( |
632 | function(cotizacion) { | 631 | function(cotizacion) { |
633 | var articulosTablaTemp = $scope.articulosTabla; | 632 | var articulosTablaTemp = $scope.articulosTabla; |
634 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 633 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
635 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 634 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
636 | $scope.notaPedido.cotizacion.VENDEDOR; | 635 | $scope.notaPedido.cotizacion.VENDEDOR; |
637 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 636 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
638 | cotizacion.VENDEDOR; | 637 | cotizacion.VENDEDOR; |
639 | } | 638 | } |
640 | $scope.articulosTabla = articulosTablaTemp; | 639 | $scope.articulosTabla = articulosTablaTemp; |
641 | $scope.notaPedido.moneda = moneda; | 640 | $scope.notaPedido.moneda = moneda; |
642 | $scope.notaPedido.cotizacion = cotizacion; | 641 | $scope.notaPedido.cotizacion = cotizacion; |
643 | addCabecera('Moneda:', moneda.DETALLE); | 642 | addCabecera('Moneda:', moneda.DETALLE); |
644 | addCabecera( | 643 | addCabecera( |
645 | 'Fecha cotizacion:', | 644 | 'Fecha cotizacion:', |
646 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 645 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
647 | ); | 646 | ); |
648 | addCabecera('Cotizacion:', cotizacion.VENDEDOR); | 647 | addCabecera('Cotizacion:', cotizacion.VENDEDOR); |
649 | }, function() { | 648 | }, function() { |
650 | 649 | ||
651 | } | 650 | } |
652 | ); | 651 | ); |
653 | }; | 652 | }; |
654 | 653 | ||
655 | $scope.agregarATabla = function(key) { | 654 | $scope.agregarATabla = function(key) { |
656 | if(key === 13) { | 655 | if(key === 13) { |
657 | if($scope.articuloACargar.cantidad === undefined || | 656 | if($scope.articuloACargar.cantidad === undefined || |
658 | $scope.articuloACargar.cantidad === 0 || | 657 | $scope.articuloACargar.cantidad === 0 || |
659 | $scope.articuloACargar.cantidad === null ) { | 658 | $scope.articuloACargar.cantidad === null ) { |
660 | focaModalService.alert('El valor debe ser al menos 1'); | 659 | focaModalService.alert('El valor debe ser al menos 1'); |
661 | return; | 660 | return; |
662 | } | 661 | } |
663 | delete $scope.articuloACargar.sectorCodigo; | 662 | delete $scope.articuloACargar.sectorCodigo; |
664 | $scope.articulosTabla.push($scope.articuloACargar); | 663 | $scope.articulosTabla.push($scope.articuloACargar); |
665 | $scope.cargando = true; | 664 | $scope.cargando = true; |
666 | } | 665 | } |
667 | }; | 666 | }; |
668 | 667 | ||
669 | $scope.quitarArticulo = function(key) { | 668 | $scope.quitarArticulo = function(key) { |
670 | $scope.articulosTabla.splice(key, 1); | 669 | $scope.articulosTabla.splice(key, 1); |
671 | }; | 670 | }; |
672 | 671 | ||
673 | $scope.editarArticulo = function(key, articulo) { | 672 | $scope.editarArticulo = function(key, articulo) { |
674 | if(key === 13) { | 673 | if(key === 13) { |
675 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 674 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
676 | articulo.cantidad === undefined) { | 675 | articulo.cantidad === undefined) { |
677 | focaModalService.alert('El valor debe ser al menos 1'); | 676 | focaModalService.alert('El valor debe ser al menos 1'); |
678 | return; | 677 | return; |
679 | } | 678 | } |
680 | articulo.editCantidad = false; | 679 | articulo.editCantidad = false; |
681 | articulo.editPrecio = false; | 680 | articulo.editPrecio = false; |
682 | } | 681 | } |
683 | }; | 682 | }; |
684 | 683 | ||
685 | $scope.cambioEdit = function(articulo, propiedad) { | 684 | $scope.cambioEdit = function(articulo, propiedad) { |
686 | if(propiedad === 'cantidad') { | 685 | if(propiedad === 'cantidad') { |
687 | articulo.editCantidad = true; | 686 | articulo.editCantidad = true; |
688 | } else if(propiedad === 'precio') { | 687 | } else if(propiedad === 'precio') { |
689 | articulo.editPrecio = true; | 688 | articulo.editPrecio = true; |
690 | } | 689 | } |
691 | }; | 690 | }; |
692 | 691 | ||
693 | $scope.limpiarFlete = function() { | 692 | $scope.limpiarFlete = function() { |
694 | $scope.notaPedido.fleteNombre = ''; | 693 | $scope.notaPedido.fleteNombre = ''; |
695 | $scope.notaPedido.chofer = ''; | 694 | $scope.notaPedido.chofer = ''; |
696 | $scope.notaPedido.vehiculo = ''; | 695 | $scope.notaPedido.vehiculo = ''; |
697 | $scope.notaPedido.kilometros = ''; | 696 | $scope.notaPedido.kilometros = ''; |
698 | $scope.notaPedido.costoUnitarioKmFlete = ''; | 697 | $scope.notaPedido.costoUnitarioKmFlete = ''; |
699 | $scope.choferes = ''; | 698 | $scope.choferes = ''; |
700 | $scope.vehiculos = ''; | 699 | $scope.vehiculos = ''; |
701 | }; | 700 | }; |
702 | 701 | ||
703 | $scope.limpiarPantalla = function() { | 702 | $scope.limpiarPantalla = function() { |
704 | $scope.limpiarFlete(); | 703 | $scope.limpiarFlete(); |
705 | $scope.notaPedido.flete = '0'; | 704 | $scope.notaPedido.flete = '0'; |
706 | $scope.notaPedido.bomba = '0'; | 705 | $scope.notaPedido.bomba = '0'; |
707 | $scope.notaPedido.precioCondicion = ''; | 706 | $scope.notaPedido.precioCondicion = ''; |
708 | $scope.articulosTabla = []; | 707 | $scope.articulosTabla = []; |
709 | $scope.notaPedido.vendedor.nombre = ''; | 708 | $scope.notaPedido.vendedor.nombre = ''; |
710 | $scope.notaPedido.cliente = {nombre: ''}; | 709 | $scope.notaPedido.cliente = {nombre: ''}; |
711 | $scope.notaPedido.domicilio = {dom: ''}; | 710 | $scope.notaPedido.domicilio = {dom: ''}; |
712 | $scope.domiciliosCliente = []; | 711 | $scope.domiciliosCliente = []; |
713 | }; | 712 | }; |
714 | 713 | ||
715 | $scope.resetFilter = function() { | 714 | $scope.resetFilter = function() { |
716 | $scope.articuloACargar = {}; | 715 | $scope.articuloACargar = {}; |
717 | $scope.cargando = true; | 716 | $scope.cargando = true; |
718 | }; | 717 | }; |
719 | //Recibe aviso si el teclado está en uso | 718 | //Recibe aviso si el teclado está en uso |
720 | $rootScope.$on('usarTeclado', function(event, data) { | 719 | $rootScope.$on('usarTeclado', function(event, data) { |
721 | if(data) { | 720 | if(data) { |
722 | $scope.mostrarTeclado = true; | 721 | $scope.mostrarTeclado = true; |
723 | return; | 722 | return; |
724 | } | 723 | } |
725 | $scope.mostrarTeclado = false; | 724 | $scope.mostrarTeclado = false; |
726 | }); | 725 | }); |
727 | 726 | ||
728 | $scope.selectFocus = function($event) { | 727 | $scope.selectFocus = function($event) { |
729 | // Si el teclado esta en uso no selecciona el valor | 728 | // Si el teclado esta en uso no selecciona el valor |
730 | if($scope.mostrarTeclado) { | 729 | if($scope.mostrarTeclado) { |
731 | return; | 730 | return; |
732 | } | 731 | } |
733 | $event.target.select(); | 732 | $event.target.select(); |
734 | }; | 733 | }; |
735 | 734 | ||
736 | $scope.salir = function() { | 735 | $scope.salir = function() { |
737 | $location.path('/'); | 736 | $location.path('/'); |
738 | }; | 737 | }; |
739 | 738 | ||
740 | $scope.parsearATexto = function(articulo) { | 739 | $scope.parsearATexto = function(articulo) { |
741 | articulo.cantidad = parseFloat(articulo.cantidad); | 740 | articulo.cantidad = parseFloat(articulo.cantidad); |
742 | articulo.precio = parseFloat(articulo.precio); | 741 | articulo.precio = parseFloat(articulo.precio); |
743 | }; | 742 | }; |
744 | 743 | ||
745 | function addArrayCabecera(array) { | 744 | function addArrayCabecera(array) { |
746 | for(var i = 0; i < array.length; i++) { | 745 | for(var i = 0; i < array.length; i++) { |
747 | addCabecera(array[i].label, array[i].valor); | 746 | addCabecera(array[i].label, array[i].valor); |
748 | } | 747 | } |
749 | } | 748 | } |
750 | 749 | ||
751 | function addCabecera(label, valor) { | 750 | function addCabecera(label, valor) { |
752 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 751 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
753 | if(propiedad.length === 1) { | 752 | if(propiedad.length === 1) { |
754 | propiedad[0].valor = valor; | 753 | propiedad[0].valor = valor; |
755 | } else { | 754 | } else { |
756 | $scope.cabecera.push({label: label, valor: valor}); | 755 | $scope.cabecera.push({label: label, valor: valor}); |
757 | } | 756 | } |
758 | } | 757 | } |
759 | 758 | ||
760 | function removeCabecera(label) { | 759 | function removeCabecera(label) { |
761 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 760 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
762 | if(propiedad.length === 1) { | 761 | if(propiedad.length === 1) { |
763 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); | 762 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); |
764 | } | 763 | } |
765 | } | 764 | } |
766 | 765 | ||
767 | function rellenar(relleno, longitud) { | 766 | function rellenar(relleno, longitud) { |
768 | relleno = '' + relleno; | 767 | relleno = '' + relleno; |
769 | while (relleno.length < longitud) { | 768 | while (relleno.length < longitud) { |
770 | relleno = '0' + relleno; | 769 | relleno = '0' + relleno; |
771 | } | 770 | } |
772 | 771 | ||
773 | return relleno; | 772 | return relleno; |
774 | } | 773 | } |
775 | 774 | ||
776 | function validarNotaRemitada(funcion) { | 775 | function validarNotaRemitada(funcion) { |
777 | if($scope.notaPedido.idRemito) { | 776 | if($scope.notaPedido.idRemito) { |
778 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 777 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
779 | } | 778 | } |
780 | else { | 779 | else { |
781 | funcion(); | 780 | funcion(); |
782 | } | 781 | } |
783 | } | 782 | } |
784 | } | 783 | } |
785 | ] | 784 | ] |
786 | ) | 785 | ) |
787 | .controller('notaPedidoListaCtrl', [ | 786 | .controller('notaPedidoListaCtrl', [ |
788 | '$scope', | 787 | '$scope', |
789 | 'crearNotaPedidoService', | 788 | 'crearNotaPedidoService', |
790 | '$location', | 789 | '$location', |
791 | function($scope, crearNotaPedidoService, $location) { | 790 | function($scope, crearNotaPedidoService, $location) { |
792 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { | 791 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { |
793 | $scope.notaPedidos = datos.data; | 792 | $scope.notaPedidos = datos.data; |
794 | }); | 793 | }); |
795 | $scope.editar = function(notaPedido) { | 794 | $scope.editar = function(notaPedido) { |
796 | crearNotaPedidoService.setNotaPedido(notaPedido); | 795 | crearNotaPedidoService.setNotaPedido(notaPedido); |
797 | $location.path('/venta-nota-pedido/abm/'); | 796 | $location.path('/venta-nota-pedido/abm/'); |
798 | }; | 797 | }; |
799 | $scope.crearPedido = function() { | 798 | $scope.crearPedido = function() { |
800 | crearNotaPedidoService.clearNotaPedido(); | 799 | crearNotaPedidoService.clearNotaPedido(); |
801 | $location.path('/venta-nota-pedido/abm/'); | 800 | $location.path('/venta-nota-pedido/abm/'); |
802 | }; | 801 | }; |
803 | } | 802 | } |
804 | ]) | 803 | ]) |
805 | .controller('focaCrearNotaPedidoFichaClienteController', [ | 804 | .controller('focaCrearNotaPedidoFichaClienteController', [ |
806 | '$scope', | 805 | '$scope', |
807 | 'crearNotaPedidoService', | 806 | 'crearNotaPedidoService', |
808 | '$location', | 807 | '$location', |
809 | function($scope, crearNotaPedidoService, $location) { | 808 | function($scope, crearNotaPedidoService, $location) { |
810 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { | 809 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { |
811 | $scope.notaPedidos = datos.data; | 810 | $scope.notaPedidos = datos.data; |
812 | }); | 811 | }); |
813 | $scope.editar = function(notaPedido) { | 812 | $scope.editar = function(notaPedido) { |
814 | crearNotaPedidoService.setNotaPedido(notaPedido); | 813 | crearNotaPedidoService.setNotaPedido(notaPedido); |
815 | $location.path('/venta-nota-pedido/abm/'); | 814 | $location.path('/venta-nota-pedido/abm/'); |
816 | }; | 815 | }; |
817 | $scope.crearPedido = function() { | 816 | $scope.crearPedido = function() { |
818 | crearNotaPedidoService.clearNotaPedido(); | 817 | crearNotaPedidoService.clearNotaPedido(); |
819 | $location.path('/venta-nota-pedido/abm/'); | 818 | $location.path('/venta-nota-pedido/abm/'); |
820 | }; | 819 | }; |
821 | } | 820 | } |
822 | ]); | 821 | ]); |