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