Commit 2ed3c8ad383582e256b73217ff1960d0a98b84ae
1 parent
01aedd2808
Exists in
master
fuera boton proveedor y flete, agrego boton transportista
Showing
2 changed files
with
63 additions
and
60 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
2 | [ | 2 | [ |
3 | '$scope', | 3 | '$scope', |
4 | '$uibModal', | 4 | '$uibModal', |
5 | '$location', | 5 | '$location', |
6 | '$filter', | 6 | '$filter', |
7 | '$timeout', | 7 | '$timeout', |
8 | 'crearNotaPedidoService', | 8 | 'crearNotaPedidoService', |
9 | 'focaBotoneraLateralService', | 9 | 'focaBotoneraLateralService', |
10 | 'focaModalService', | 10 | 'focaModalService', |
11 | 'notaPedidoBusinessService', | 11 | 'notaPedidoBusinessService', |
12 | '$rootScope', | 12 | '$rootScope', |
13 | 'focaSeguimientoService', | 13 | 'focaSeguimientoService', |
14 | 'APP', | 14 | 'APP', |
15 | 'focaLoginService', | 15 | 'focaLoginService', |
16 | '$localStorage', | 16 | '$localStorage', |
17 | function( | 17 | function( |
18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, | 18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, |
19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, | 19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, |
20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) | 20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) |
21 | { | 21 | { |
22 | config(); | 22 | config(); |
23 | 23 | ||
24 | function config() { | 24 | function config() { |
25 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA | 25 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA |
26 | $scope.notaPedido = {}; | 26 | $scope.notaPedido = {}; |
27 | $scope.isNumber = angular.isNumber; | 27 | $scope.isNumber = angular.isNumber; |
28 | $scope.datepickerAbierto = false; | 28 | $scope.datepickerAbierto = false; |
29 | $scope.show = false; | 29 | $scope.show = false; |
30 | $scope.cargando = true; | 30 | $scope.cargando = true; |
31 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 31 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
32 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 32 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
33 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 33 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
34 | $scope.dateOptions = { | 34 | $scope.dateOptions = { |
35 | maxDate: new Date(), | 35 | maxDate: new Date(), |
36 | minDate: new Date(2010, 0, 1) | 36 | minDate: new Date(2010, 0, 1) |
37 | }; | 37 | }; |
38 | 38 | ||
39 | //SETEO BOTONERA LATERAL | 39 | //SETEO BOTONERA LATERAL |
40 | $timeout(function() { | 40 | $timeout(function() { |
41 | focaBotoneraLateralService.showSalir(false); | 41 | focaBotoneraLateralService.showSalir(false); |
42 | focaBotoneraLateralService.showPausar(true); | 42 | focaBotoneraLateralService.showPausar(true); |
43 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 43 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); |
44 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 44 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
45 | }); | 45 | }); |
46 | 46 | ||
47 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR | 47 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR |
48 | if (APP === 'distribuidor') { | 48 | if (APP === 'distribuidor') { |
49 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; | 49 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; |
50 | } | 50 | } |
51 | 51 | ||
52 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 52 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
53 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | 53 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { |
54 | var monedaPorDefecto = res.data[0]; | 54 | var monedaPorDefecto = res.data[0]; |
55 | 55 | ||
56 | $scope.notaPedido.cotizacion = Object.assign( | 56 | $scope.notaPedido.cotizacion = Object.assign( |
57 | {moneda: monedaPorDefecto}, | 57 | {moneda: monedaPorDefecto}, |
58 | monedaPorDefecto.cotizaciones[0] | 58 | monedaPorDefecto.cotizaciones[0] |
59 | ); | 59 | ); |
60 | $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; | 60 | $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; |
61 | }); | 61 | }); |
62 | 62 | ||
63 | init(); | 63 | init(); |
64 | $timeout(function() {getLSNotaPedido();}); | 64 | $timeout(function() {getLSNotaPedido();}); |
65 | } | 65 | } |
66 | 66 | ||
67 | function init() { | 67 | function init() { |
68 | $scope.$broadcast('cleanCabecera'); | 68 | $scope.$broadcast('cleanCabecera'); |
69 | 69 | ||
70 | $scope.notaPedido = { | 70 | $scope.notaPedido = { |
71 | id: 0, | 71 | id: 0, |
72 | cliente: {}, | 72 | cliente: {}, |
73 | proveedor: {}, | 73 | proveedor: {}, |
74 | domicilio: {dom: ''}, | 74 | domicilio: {dom: ''}, |
75 | vendedor: {}, | 75 | vendedor: {}, |
76 | fechaCarga: new Date(), | 76 | fechaCarga: new Date(), |
77 | cotizacion: {}, | 77 | cotizacion: {}, |
78 | articulosNotaPedido: [], | 78 | articulosNotaPedido: [], |
79 | notaPedidoPlazo: [] | 79 | notaPedidoPlazo: [] |
80 | }; | 80 | }; |
81 | $scope.idLista = undefined; | 81 | $scope.idLista = undefined; |
82 | 82 | ||
83 | crearNotaPedidoService.getNumeroNotaPedido().then( | 83 | crearNotaPedidoService.getNumeroNotaPedido().then( |
84 | function(res) { | 84 | function(res) { |
85 | $scope.puntoVenta = $filter('rellenarDigitos')( | 85 | $scope.puntoVenta = $filter('rellenarDigitos')( |
86 | res.data.sucursal, 4 | 86 | res.data.sucursal, 4 |
87 | ); | 87 | ); |
88 | 88 | ||
89 | $scope.comprobante = $filter('rellenarDigitos')( | 89 | $scope.comprobante = $filter('rellenarDigitos')( |
90 | res.data.numeroNotaPedido, 8 | 90 | res.data.numeroNotaPedido, 8 |
91 | ); | 91 | ); |
92 | }, | 92 | }, |
93 | function(err) { | 93 | function(err) { |
94 | focaModalService.alert('La terminal no esta configurada correctamente'); | 94 | focaModalService.alert('La terminal no esta configurada correctamente'); |
95 | console.info(err); | 95 | console.info(err); |
96 | } | 96 | } |
97 | ); | 97 | ); |
98 | 98 | ||
99 | if (APP === 'distribuidor') { | 99 | if (APP === 'distribuidor') { |
100 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( | 100 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( |
101 | function(res) { | 101 | function(res) { |
102 | var vendedor = res.data; | 102 | var vendedor = res.data; |
103 | $scope.$broadcast('addCabecera', { | 103 | $scope.$broadcast('addCabecera', { |
104 | label: 'Vendedor:', | 104 | label: 'Vendedor:', |
105 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 105 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
106 | vendedor.NOM | 106 | vendedor.NOM |
107 | }); | 107 | }); |
108 | 108 | ||
109 | $scope.notaPedido.vendedor = vendedor; | 109 | $scope.notaPedido.vendedor = vendedor; |
110 | $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor; | 110 | $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor; |
111 | } | 111 | } |
112 | ); | 112 | ); |
113 | } | 113 | } |
114 | 114 | ||
115 | $scope.inicial = angular.copy($scope.notaPedido); | 115 | $scope.inicial = angular.copy($scope.notaPedido); |
116 | } | 116 | } |
117 | 117 | ||
118 | $scope.$watch('notaPedido', function(newValue) { | 118 | $scope.$watch('notaPedido', function(newValue) { |
119 | focaBotoneraLateralService.setPausarData({ | 119 | focaBotoneraLateralService.setPausarData({ |
120 | label: 'notaPedido', | 120 | label: 'notaPedido', |
121 | val: newValue | 121 | val: newValue |
122 | }); | 122 | }); |
123 | }, true); | 123 | }, true); |
124 | 124 | ||
125 | $scope.crearNotaPedido = function() { | 125 | $scope.crearNotaPedido = function() { |
126 | if (!$scope.notaPedido.cliente.COD) { | 126 | if (!$scope.notaPedido.cliente.COD) { |
127 | focaModalService.alert('Ingrese Cliente'); | 127 | focaModalService.alert('Ingrese Cliente'); |
128 | return; | 128 | return; |
129 | } else if (!$scope.notaPedido.proveedor.COD) { | 129 | } else if (!$scope.notaPedido.proveedor.COD) { |
130 | focaModalService.alert('Ingrese Proveedor'); | 130 | focaModalService.alert('Ingrese Proveedor'); |
131 | return; | 131 | return; |
132 | } else if (!$scope.notaPedido.cotizacion.ID) { | 132 | } else if (!$scope.notaPedido.cotizacion.ID) { |
133 | focaModalService.alert('Ingrese Cotización'); | 133 | focaModalService.alert('Ingrese Cotización'); |
134 | return; | 134 | return; |
135 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { | 135 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { |
136 | focaModalService.alert('Ingrese Moneda'); | 136 | focaModalService.alert('Ingrese Moneda'); |
137 | return; | 137 | return; |
138 | } else if (!$scope.notaPedido.notaPedidoPlazo) { | 138 | } else if (!$scope.notaPedido.notaPedidoPlazo) { |
139 | focaModalService.alert('Ingrese Precios y Condiciones'); | 139 | focaModalService.alert('Ingrese Precios y Condiciones'); |
140 | return; | 140 | return; |
141 | } else if ( | 141 | } else if ( |
142 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 142 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
143 | { | 143 | { |
144 | focaModalService.alert('Ingrese Flete'); | 144 | focaModalService.alert('Ingrese Flete'); |
145 | return; | 145 | return; |
146 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 146 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
147 | focaModalService.alert('Ingrese Domicilio'); | 147 | focaModalService.alert('Ingrese Domicilio'); |
148 | return; | 148 | return; |
149 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { | 149 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { |
150 | focaModalService.alert('Debe cargar al menos un articulo'); | 150 | focaModalService.alert('Debe cargar al menos un articulo'); |
151 | return; | 151 | return; |
152 | } | 152 | } |
153 | focaBotoneraLateralService.startGuardar(); | 153 | focaBotoneraLateralService.startGuardar(); |
154 | $scope.saveLoading = true; | 154 | $scope.saveLoading = true; |
155 | var notaPedido = { | 155 | var notaPedido = { |
156 | id: $scope.notaPedido.id, | 156 | id: $scope.notaPedido.id, |
157 | fechaCarga: new Date($scope.notaPedido.fechaCarga) | 157 | fechaCarga: new Date($scope.notaPedido.fechaCarga) |
158 | .toISOString().slice(0, 19).replace('T', ' '), | 158 | .toISOString().slice(0, 19).replace('T', ' '), |
159 | idVendedor: $scope.notaPedido.vendedor.id, | 159 | idVendedor: $scope.notaPedido.vendedor.id, |
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, | 164 | idDomicilio: $scope.notaPedido.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 | observaciones: $scope.notaPedido.observaciones, | 173 | observaciones: $scope.notaPedido.observaciones, |
174 | estado: 0, | 174 | estado: 0, |
175 | total: $scope.getTotal() | 175 | total: $scope.getTotal() |
176 | }; | 176 | }; |
177 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 177 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
178 | function(data) { | 178 | function(data) { |
179 | // Al guardar los datos de la nota de pedido logueamos la | 179 | // Al guardar los datos de la nota de pedido logueamos la |
180 | // actividad para su seguimiento. | 180 | // actividad para su seguimiento. |
181 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 181 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
182 | focaSeguimientoService.guardarPosicion( | 182 | focaSeguimientoService.guardarPosicion( |
183 | 'Nota de pedido', | 183 | 'Nota de pedido', |
184 | data.data.id, | 184 | data.data.id, |
185 | '' | 185 | '' |
186 | ); | 186 | ); |
187 | notaPedidoBusinessService.addArticulos( | 187 | notaPedidoBusinessService.addArticulos( |
188 | $scope.notaPedido.articulosNotaPedido, | 188 | $scope.notaPedido.articulosNotaPedido, |
189 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 189 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
190 | 190 | ||
191 | if ($scope.notaPedido.notaPedidoPuntoDescarga) { | 191 | if ($scope.notaPedido.notaPedidoPuntoDescarga) { |
192 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 192 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
193 | $scope.notaPedido.notaPedidoPuntoDescarga); | 193 | $scope.notaPedido.notaPedidoPuntoDescarga); |
194 | } | 194 | } |
195 | 195 | ||
196 | var plazos = $scope.notaPedido.notaPedidoPlazo; | 196 | var plazos = $scope.notaPedido.notaPedidoPlazo; |
197 | var plazosACrear = []; | 197 | var plazosACrear = []; |
198 | plazos.forEach(function(plazo) { | 198 | plazos.forEach(function(plazo) { |
199 | plazosACrear.push({ | 199 | plazosACrear.push({ |
200 | idNotaPedido: data.data.id, | 200 | idNotaPedido: data.data.id, |
201 | dias: plazo.dias | 201 | dias: plazo.dias |
202 | }); | 202 | }); |
203 | }); | 203 | }); |
204 | 204 | ||
205 | if (plazosACrear.length) { | 205 | if (plazosACrear.length) { |
206 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 206 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); |
207 | } | 207 | } |
208 | 208 | ||
209 | notaPedidoBusinessService.addEstado(data.data.id, | 209 | notaPedidoBusinessService.addEstado(data.data.id, |
210 | $scope.notaPedido.vendedor.id); | 210 | $scope.notaPedido.vendedor.id); |
211 | 211 | ||
212 | focaBotoneraLateralService.endGuardar(true); | 212 | focaBotoneraLateralService.endGuardar(true); |
213 | $scope.saveLoading = false; | 213 | $scope.saveLoading = false; |
214 | 214 | ||
215 | init(); | 215 | init(); |
216 | }, function(error) { | 216 | }, function(error) { |
217 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 217 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
218 | focaBotoneraLateralService.endGuardar(); | 218 | focaBotoneraLateralService.endGuardar(); |
219 | $scope.saveLoading = false; | 219 | $scope.saveLoading = false; |
220 | console.info(error); | 220 | console.info(error); |
221 | } | 221 | } |
222 | ); | 222 | ); |
223 | }; | 223 | }; |
224 | 224 | ||
225 | $scope.seleccionarNotaPedido = function() { | 225 | $scope.seleccionarNotaPedido = function() { |
226 | var modalInstance = $uibModal.open( | 226 | var modalInstance = $uibModal.open( |
227 | { | 227 | { |
228 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 228 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
229 | templateUrl: 'foca-modal-nota-pedido.html', | 229 | templateUrl: 'foca-modal-nota-pedido.html', |
230 | controller: 'focaModalNotaPedidoController', | 230 | controller: 'focaModalNotaPedidoController', |
231 | size: 'lg', | 231 | size: 'lg', |
232 | resolve: { | 232 | resolve: { |
233 | usadoPor: function() {return 'notaPedido';}, | 233 | usadoPor: function() {return 'notaPedido';}, |
234 | idVendedor: function() { | 234 | idVendedor: function() { |
235 | if(APP === 'distribuidor') | 235 | if(APP === 'distribuidor') |
236 | return $scope.notaPedido.vendedor.id; | 236 | return $scope.notaPedido.vendedor.id; |
237 | else | 237 | else |
238 | return null; | 238 | return null; |
239 | } | 239 | } |
240 | } | 240 | } |
241 | } | 241 | } |
242 | ); | 242 | ); |
243 | modalInstance.result.then(setearNotaPedido); | 243 | modalInstance.result.then(setearNotaPedido); |
244 | }; | 244 | }; |
245 | 245 | ||
246 | $scope.seleccionarProductos = function() { | 246 | $scope.seleccionarProductos = function() { |
247 | if ($scope.idLista === undefined) { | 247 | if ($scope.idLista === undefined) { |
248 | focaModalService.alert( | 248 | focaModalService.alert( |
249 | 'Primero seleccione una lista de precio y condicion'); | 249 | 'Primero seleccione una lista de precio y condicion'); |
250 | return; | 250 | return; |
251 | } | 251 | } |
252 | var modalInstance = $uibModal.open( | 252 | var modalInstance = $uibModal.open( |
253 | { | 253 | { |
254 | ariaLabelledBy: 'Busqueda de Productos', | 254 | ariaLabelledBy: 'Busqueda de Productos', |
255 | templateUrl: 'modal-busqueda-productos.html', | 255 | templateUrl: 'modal-busqueda-productos.html', |
256 | controller: 'modalBusquedaProductosCtrl', | 256 | controller: 'modalBusquedaProductosCtrl', |
257 | resolve: { | 257 | resolve: { |
258 | parametroProducto: { | 258 | parametroProducto: { |
259 | idLista: $scope.idLista, | 259 | idLista: $scope.idLista, |
260 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 260 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
261 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO | 261 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO |
262 | } | 262 | } |
263 | }, | 263 | }, |
264 | size: 'lg' | 264 | size: 'lg' |
265 | } | 265 | } |
266 | ); | 266 | ); |
267 | modalInstance.result.then( | 267 | modalInstance.result.then( |
268 | function(producto) { | 268 | function(producto) { |
269 | var newArt = | 269 | var newArt = |
270 | { | 270 | { |
271 | id: 0, | 271 | id: 0, |
272 | codigo: producto.codigo, | 272 | codigo: producto.codigo, |
273 | sector: producto.sector, | 273 | sector: producto.sector, |
274 | sectorCodigo: producto.sector + '-' + producto.codigo, | 274 | sectorCodigo: producto.sector + '-' + producto.codigo, |
275 | descripcion: producto.descripcion, | 275 | descripcion: producto.descripcion, |
276 | item: $scope.notaPedido.articulosNotaPedido.length + 1, | 276 | item: $scope.notaPedido.articulosNotaPedido.length + 1, |
277 | nombre: producto.descripcion, | 277 | nombre: producto.descripcion, |
278 | precio: parseFloat(producto.precio.toFixed(4)), | 278 | precio: parseFloat(producto.precio.toFixed(4)), |
279 | costoUnitario: producto.costo, | 279 | costoUnitario: producto.costo, |
280 | editCantidad: false, | 280 | editCantidad: false, |
281 | editPrecio: false, | 281 | editPrecio: false, |
282 | rubro: producto.CodRub, | 282 | rubro: producto.CodRub, |
283 | exentoUnitario: producto.precio, | 283 | exentoUnitario: producto.precio, |
284 | ivaUnitario: producto.IMPIVA, | 284 | ivaUnitario: producto.IMPIVA, |
285 | impuestoInternoUnitario: producto.ImpInt, | 285 | impuestoInternoUnitario: producto.ImpInt, |
286 | impuestoInterno1Unitario: producto.ImpInt2, | 286 | impuestoInterno1Unitario: producto.ImpInt2, |
287 | impuestoInterno2Unitario: producto.ImpInt3, | 287 | impuestoInterno2Unitario: producto.ImpInt3, |
288 | precioLista: producto.precio, | 288 | precioLista: producto.precio, |
289 | combustible: 1, | 289 | combustible: 1, |
290 | facturado: 0, | 290 | facturado: 0, |
291 | idArticulo: producto.id | 291 | idArticulo: producto.id |
292 | }; | 292 | }; |
293 | $scope.articuloACargar = newArt; | 293 | $scope.articuloACargar = newArt; |
294 | $scope.cargando = false; | 294 | $scope.cargando = false; |
295 | }, function() { | 295 | }, function() { |
296 | // funcion ejecutada cuando se cancela el modal | 296 | // funcion ejecutada cuando se cancela el modal |
297 | } | 297 | } |
298 | ); | 298 | ); |
299 | }; | 299 | }; |
300 | 300 | ||
301 | $scope.seleccionarPuntosDeDescarga = function() { | 301 | $scope.seleccionarPuntosDeDescarga = function() { |
302 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 302 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
303 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 303 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
304 | return; | 304 | return; |
305 | }else { | 305 | }else { |
306 | var modalInstance = $uibModal.open( | 306 | var modalInstance = $uibModal.open( |
307 | { | 307 | { |
308 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 308 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
309 | templateUrl: 'modal-punto-descarga.html', | 309 | templateUrl: 'modal-punto-descarga.html', |
310 | controller: 'focaModalPuntoDescargaController', | 310 | controller: 'focaModalPuntoDescargaController', |
311 | size: 'lg', | 311 | size: 'lg', |
312 | resolve: { | 312 | resolve: { |
313 | filters: { | 313 | filters: { |
314 | idDomicilio: $scope.notaPedido.domicilio.id, | 314 | idDomicilio: $scope.notaPedido.domicilio.id, |
315 | idCliente: $scope.notaPedido.cliente.COD, | 315 | idCliente: $scope.notaPedido.cliente.COD, |
316 | articulos: $scope.notaPedido.articulosNotaPedido, | 316 | articulos: $scope.notaPedido.articulosNotaPedido, |
317 | puntosDescarga: $scope.notaPedido.notaPedidoPuntoDescarga | 317 | puntosDescarga: $scope.notaPedido.notaPedidoPuntoDescarga |
318 | } | 318 | } |
319 | } | 319 | } |
320 | } | 320 | } |
321 | ); | 321 | ); |
322 | modalInstance.result.then( | 322 | modalInstance.result.then( |
323 | function(puntosDescarga) { | 323 | function(puntosDescarga) { |
324 | $scope.notaPedido.notaPedidoPuntoDescarga = puntosDescarga; | 324 | $scope.notaPedido.notaPedidoPuntoDescarga = puntosDescarga; |
325 | 325 | ||
326 | //AGREGO PUNTOS DE DESCARGA A CABECERA | 326 | //AGREGO PUNTOS DE DESCARGA A CABECERA |
327 | var puntosStamp = ''; | 327 | var puntosStamp = ''; |
328 | puntosDescarga.forEach(function(punto, idx, arr) { | 328 | puntosDescarga.forEach(function(punto, idx, arr) { |
329 | puntosStamp += punto.descripcion; | 329 | puntosStamp += punto.descripcion; |
330 | if((idx + 1) !== arr.length) puntosStamp += ', '; | 330 | if((idx + 1) !== arr.length) puntosStamp += ', '; |
331 | }); | 331 | }); |
332 | 332 | ||
333 | $scope.$broadcast('addCabecera', { | 333 | $scope.$broadcast('addCabecera', { |
334 | label: 'Puntos de descarga:', | 334 | label: 'Puntos de descarga:', |
335 | valor: puntosStamp | 335 | valor: puntosStamp |
336 | }); | 336 | }); |
337 | }, function() { | 337 | }, function() { |
338 | $scope.abrirModalDomicilios($scope.cliente); | 338 | $scope.abrirModalDomicilios($scope.cliente); |
339 | } | 339 | } |
340 | ); | 340 | ); |
341 | } | 341 | } |
342 | }; | 342 | }; |
343 | 343 | ||
344 | $scope.seleccionarTransportista = function() { | ||
345 | $scope.seleccionarProveedor(function() { | ||
346 | if (validarNotaRemitada()) { | ||
347 | var modalInstance = $uibModal.open( | ||
348 | { | ||
349 | ariaLabelledBy: 'Busqueda de Flete', | ||
350 | templateUrl: 'modal-flete.html', | ||
351 | controller: 'focaModalFleteController', | ||
352 | size: 'lg', | ||
353 | resolve: { | ||
354 | parametrosFlete: | ||
355 | function() { | ||
356 | return { | ||
357 | flete: $scope.notaPedido.fob ? 'FOB' : | ||
358 | ( $scope.notaPedido.flete ? '1' : | ||
359 | ($scope.notaPedido.flete === undefined ? | ||
360 | null : '0')), | ||
361 | bomba: $scope.notaPedido.bomba ? '1' : | ||
362 | ($scope.notaPedido.bomba === undefined ? | ||
363 | null : '0'), | ||
364 | kilometros: $scope.notaPedido.kilometros | ||
365 | }; | ||
366 | } | ||
367 | } | ||
368 | } | ||
369 | ); | ||
370 | modalInstance.result.then( | ||
371 | function(datos) { | ||
372 | $scope.notaPedido.flete = datos.flete; | ||
373 | $scope.notaPedido.fob = datos.FOB; | ||
374 | $scope.notaPedido.bomba = datos.bomba; | ||
375 | $scope.notaPedido.kilometros = datos.kilometros; | ||
376 | $scope.$broadcast('addCabecera', { | ||
377 | label: 'Flete:', | ||
378 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | ||
379 | }); | ||
380 | if (datos.flete) { | ||
381 | $scope.$broadcast('addCabecera', { | ||
382 | label: 'Bomba:', | ||
383 | valor: datos.bomba ? 'Si' : 'No' | ||
384 | }); | ||
385 | $scope.$broadcast('addCabecera', { | ||
386 | label: 'Kilometros:', | ||
387 | valor: datos.kilometros | ||
388 | }); | ||
389 | } else { | ||
390 | $scope.$broadcast('removeCabecera', 'Bomba:'); | ||
391 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | ||
392 | $scope.notaPedido.bomba = false; | ||
393 | $scope.notaPedido.kilometros = null; | ||
394 | } | ||
395 | }, function() { | ||
396 | $scope.seleccionarTransportista(); | ||
397 | } | ||
398 | ); | ||
399 | } | ||
400 | }); | ||
401 | }; | ||
402 | |||
344 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { | 403 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { |
345 | if (APP === 'distribuidor' || ocultarVendedor) { | 404 | if (APP === 'distribuidor' || ocultarVendedor) { |
346 | callback(); | 405 | callback(); |
347 | return; | 406 | return; |
348 | } | 407 | } |
349 | 408 | ||
350 | if(validarNotaRemitada()) { | 409 | if(validarNotaRemitada()) { |
351 | var parametrosModal = { | 410 | var parametrosModal = { |
352 | titulo: 'Búsqueda vendedores', | 411 | titulo: 'Búsqueda vendedores', |
353 | query: '/vendedor', | 412 | query: '/vendedor', |
354 | columnas: [ | 413 | columnas: [ |
355 | { | 414 | { |
356 | propiedad: 'NUM', | 415 | propiedad: 'NUM', |
357 | nombre: 'Código', | 416 | nombre: 'Código', |
358 | filtro: { | 417 | filtro: { |
359 | nombre: 'rellenarDigitos', | 418 | nombre: 'rellenarDigitos', |
360 | parametro: 3 | 419 | parametro: 3 |
361 | } | 420 | } |
362 | }, | 421 | }, |
363 | { | 422 | { |
364 | propiedad: 'NOM', | 423 | propiedad: 'NOM', |
365 | nombre: 'Nombre' | 424 | nombre: 'Nombre' |
366 | } | 425 | } |
367 | ], | 426 | ], |
368 | size: 'md' | 427 | size: 'md' |
369 | }; | 428 | }; |
370 | focaModalService.modal(parametrosModal).then( | 429 | focaModalService.modal(parametrosModal).then( |
371 | function(vendedor) { | 430 | function(vendedor) { |
372 | $scope.$broadcast('addCabecera', { | 431 | $scope.$broadcast('addCabecera', { |
373 | label: 'Vendedor:', | 432 | label: 'Vendedor:', |
374 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 433 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
375 | vendedor.NOM | 434 | vendedor.NOM |
376 | }); | 435 | }); |
377 | $scope.notaPedido.vendedor = vendedor; | 436 | $scope.notaPedido.vendedor = vendedor; |
378 | deleteCliente(); | 437 | deleteCliente(); |
379 | callback(); | 438 | callback(); |
380 | }, function() {} | 439 | }, function() {} |
381 | ); | 440 | ); |
382 | } | 441 | } |
383 | }; | 442 | }; |
384 | 443 | ||
385 | $scope.seleccionarCliente = function(ocultarVendedor) { | 444 | $scope.seleccionarCliente = function(ocultarVendedor) { |
386 | $scope.seleccionarVendedor(function() { | 445 | $scope.seleccionarVendedor(function() { |
387 | if (!$scope.notaPedido.vendedor.NUM) { | 446 | if (!$scope.notaPedido.vendedor.NUM) { |
388 | focaModalService.alert('Primero seleccione un vendedor'); | 447 | focaModalService.alert('Primero seleccione un vendedor'); |
389 | return; | 448 | return; |
390 | } | 449 | } |
391 | if (validarNotaRemitada()) { | 450 | if (validarNotaRemitada()) { |
392 | var modalInstance = $uibModal.open( | 451 | var modalInstance = $uibModal.open( |
393 | { | 452 | { |
394 | ariaLabelledBy: 'Busqueda de Cliente', | 453 | ariaLabelledBy: 'Busqueda de Cliente', |
395 | templateUrl: 'foca-busqueda-cliente-modal.html', | 454 | templateUrl: 'foca-busqueda-cliente-modal.html', |
396 | controller: 'focaBusquedaClienteModalController', | 455 | controller: 'focaBusquedaClienteModalController', |
397 | resolve: { | 456 | resolve: { |
398 | vendedor: function() { return $scope.notaPedido.vendedor; }, | 457 | vendedor: function() { return $scope.notaPedido.vendedor; }, |
399 | cobrador: function() { return null; } | 458 | cobrador: function() { return null; } |
400 | }, | 459 | }, |
401 | size: 'lg' | 460 | size: 'lg' |
402 | } | 461 | } |
403 | ); | 462 | ); |
404 | modalInstance.result.then( | 463 | modalInstance.result.then( |
405 | function(cliente) { | 464 | function(cliente) { |
406 | $scope.abrirModalDomicilios(cliente); | 465 | $scope.abrirModalDomicilios(cliente); |
407 | $scope.cliente = cliente; | 466 | $scope.cliente = cliente; |
408 | }, function() { | 467 | }, function() { |
409 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); | 468 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); |
410 | } | 469 | } |
411 | ); | 470 | ); |
412 | } | 471 | } |
413 | }, ocultarVendedor); | 472 | }, ocultarVendedor); |
414 | }; | 473 | }; |
415 | 474 | ||
416 | $scope.seleccionarProveedor = function() { | 475 | $scope.seleccionarProveedor = function(callback) { |
417 | if(validarNotaRemitada()) { | 476 | if(validarNotaRemitada()) { |
418 | var parametrosModal = { | 477 | var parametrosModal = { |
419 | titulo: 'Búsqueda de Proveedor', | 478 | titulo: 'Búsqueda de Proveedor', |
420 | query: '/proveedor', | 479 | query: '/proveedor', |
421 | columnas: [ | 480 | columnas: [ |
422 | { | 481 | { |
423 | nombre: 'Código', | 482 | nombre: 'Código', |
424 | propiedad: 'COD', | 483 | propiedad: 'COD', |
425 | filtro: { | 484 | filtro: { |
426 | nombre: 'rellenarDigitos', | 485 | nombre: 'rellenarDigitos', |
427 | parametro: 5 | 486 | parametro: 5 |
428 | } | 487 | } |
429 | }, | 488 | }, |
430 | { | 489 | { |
431 | nombre: 'Nombre', | 490 | nombre: 'Nombre', |
432 | propiedad: 'NOM' | 491 | propiedad: 'NOM' |
433 | }, | 492 | }, |
434 | { | 493 | { |
435 | nombre: 'CUIT', | 494 | nombre: 'CUIT', |
436 | propiedad: 'CUIT' | 495 | propiedad: 'CUIT' |
437 | } | 496 | } |
438 | ], | 497 | ], |
439 | tipo: 'POST', | 498 | tipo: 'POST', |
440 | json: {razonCuitCod: ''} | 499 | json: {razonCuitCod: ''} |
441 | }; | 500 | }; |
442 | focaModalService.modal(parametrosModal).then( | 501 | focaModalService.modal(parametrosModal).then( |
443 | function(proveedor) { | 502 | function(proveedor) { |
444 | $scope.notaPedido.proveedor = proveedor; | 503 | $scope.notaPedido.proveedor = proveedor; |
445 | $scope.$broadcast('addCabecera', { | 504 | $scope.$broadcast('addCabecera', { |
446 | label: 'Proveedor:', | 505 | label: 'Proveedor:', |
447 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 506 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
448 | proveedor.NOM | 507 | proveedor.NOM |
449 | }); | 508 | }); |
509 | callback(); | ||
450 | }, function() { | 510 | }, function() { |
451 | 511 | ||
452 | } | 512 | } |
453 | ); | 513 | ); |
454 | } | 514 | } |
455 | }; | 515 | }; |
456 | 516 | ||
457 | $scope.abrirModalDomicilios = function(cliente) { | 517 | $scope.abrirModalDomicilios = function(cliente) { |
458 | var modalInstanceDomicilio = $uibModal.open( | 518 | var modalInstanceDomicilio = $uibModal.open( |
459 | { | 519 | { |
460 | ariaLabelledBy: 'Busqueda de Domicilios', | 520 | ariaLabelledBy: 'Busqueda de Domicilios', |
461 | templateUrl: 'modal-domicilio.html', | 521 | templateUrl: 'modal-domicilio.html', |
462 | controller: 'focaModalDomicilioController', | 522 | controller: 'focaModalDomicilioController', |
463 | resolve: { | 523 | resolve: { |
464 | idCliente: function() { return cliente.cod; }, | 524 | idCliente: function() { return cliente.cod; }, |
465 | esNuevo: function() { return cliente.esNuevo; } | 525 | esNuevo: function() { return cliente.esNuevo; } |
466 | }, | 526 | }, |
467 | size: 'lg', | 527 | size: 'lg', |
468 | } | 528 | } |
469 | ); | 529 | ); |
470 | modalInstanceDomicilio.result.then( | 530 | modalInstanceDomicilio.result.then( |
471 | function(domicilio) { | 531 | function(domicilio) { |
472 | $scope.notaPedido.domicilio = domicilio; | 532 | $scope.notaPedido.domicilio = domicilio; |
473 | $scope.notaPedido.cliente = { | 533 | $scope.notaPedido.cliente = { |
474 | COD: cliente.cod, | 534 | COD: cliente.cod, |
475 | CUIT: cliente.cuit, | 535 | CUIT: cliente.cuit, |
476 | NOM: cliente.nom | 536 | NOM: cliente.nom |
477 | }; | 537 | }; |
478 | var domicilioStamp = | 538 | var domicilioStamp = |
479 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 539 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
480 | domicilio.Localidad + ', ' + domicilio.Provincia; | 540 | domicilio.Localidad + ', ' + domicilio.Provincia; |
481 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 541 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
482 | 542 | ||
483 | $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntosDescarga; | 543 | $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntosDescarga; |
484 | 544 | ||
485 | $scope.$broadcast('addCabecera', { | 545 | $scope.$broadcast('addCabecera', { |
486 | label: 'Cliente:', | 546 | label: 'Cliente:', |
487 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom | 547 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom |
488 | }); | 548 | }); |
489 | $scope.$broadcast('addCabecera', { | 549 | $scope.$broadcast('addCabecera', { |
490 | label: 'Domicilio:', | 550 | label: 'Domicilio:', |
491 | valor: domicilioStamp | 551 | valor: domicilioStamp |
492 | }); | 552 | }); |
493 | if (domicilio.verPuntos) { | 553 | if (domicilio.verPuntos) { |
494 | delete $scope.notaPedido.domicilio.verPuntos; | 554 | delete $scope.notaPedido.domicilio.verPuntos; |
495 | $scope.seleccionarPuntosDeDescarga(); | 555 | $scope.seleccionarPuntosDeDescarga(); |
496 | } else { | 556 | } else { |
497 | crearNotaPedidoService | 557 | crearNotaPedidoService |
498 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | 558 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) |
499 | .then(function(res) { | 559 | .then(function(res) { |
500 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); | 560 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); |
501 | }); | 561 | }); |
502 | } | 562 | } |
503 | }, function() { | 563 | }, function() { |
504 | $scope.seleccionarCliente(true); | 564 | $scope.seleccionarCliente(true); |
505 | return; | 565 | return; |
506 | } | 566 | } |
507 | ); | 567 | ); |
508 | }; | 568 | }; |
509 | 569 | ||
510 | $scope.getTotal = function() { | 570 | $scope.getTotal = function() { |
511 | var total = 0; | 571 | var total = 0; |
512 | if ($scope.notaPedido.articulosNotaPedido) { | 572 | if ($scope.notaPedido.articulosNotaPedido) { |
513 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; | 573 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; |
514 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 574 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
515 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 575 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
516 | } | 576 | } |
517 | } | 577 | } |
518 | 578 | ||
519 | return parseFloat(total.toFixed(2)); | 579 | return parseFloat(total.toFixed(2)); |
520 | }; | 580 | }; |
521 | 581 | ||
522 | $scope.getSubTotal = function() { | 582 | $scope.getSubTotal = function() { |
523 | if($scope.articuloACargar) { | 583 | if($scope.articuloACargar) { |
524 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 584 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
525 | } | 585 | } |
526 | }; | 586 | }; |
527 | 587 | ||
528 | $scope.seleccionarPreciosYCondiciones = function() { | 588 | $scope.seleccionarPreciosYCondiciones = function() { |
529 | if(validarNotaRemitada()) { | 589 | if(validarNotaRemitada()) { |
530 | var modalInstance = $uibModal.open( | 590 | var modalInstance = $uibModal.open( |
531 | { | 591 | { |
532 | ariaLabelledBy: 'Busqueda de Precio Condición', | 592 | ariaLabelledBy: 'Busqueda de Precio Condición', |
533 | templateUrl: 'modal-precio-condicion.html', | 593 | templateUrl: 'modal-precio-condicion.html', |
534 | controller: 'focaModalPrecioCondicionController', | 594 | controller: 'focaModalPrecioCondicionController', |
535 | size: 'lg' | 595 | size: 'lg' |
536 | } | 596 | } |
537 | ); | 597 | ); |
538 | modalInstance.result.then( | 598 | modalInstance.result.then( |
539 | function(precioCondicion) { | 599 | function(precioCondicion) { |
540 | var cabecera = ''; | 600 | var cabecera = ''; |
541 | var plazosConcat = ''; | 601 | var plazosConcat = ''; |
542 | if(!Array.isArray(precioCondicion)) { | 602 | if(!Array.isArray(precioCondicion)) { |
543 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; | 603 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; |
544 | $scope.notaPedido.precioCondicion = precioCondicion; | 604 | $scope.notaPedido.precioCondicion = precioCondicion; |
545 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 605 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
546 | $scope.idLista = precioCondicion.idListaPrecio; | 606 | $scope.idLista = precioCondicion.idListaPrecio; |
547 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 607 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
548 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 608 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
549 | } | 609 | } |
550 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + | 610 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + |
551 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); | 611 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); |
552 | } else { //Cuando se ingresan los plazos manualmente | 612 | } else { //Cuando se ingresan los plazos manualmente |
553 | $scope.notaPedido.idPrecioCondicion = 0; | 613 | $scope.notaPedido.idPrecioCondicion = 0; |
554 | //-1, el modal productos busca todos los productos | 614 | //-1, el modal productos busca todos los productos |
555 | $scope.idLista = -1; | 615 | $scope.idLista = -1; |
556 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; | 616 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; |
557 | for(var j = 0; j < precioCondicion.length; j++) { | 617 | for(var j = 0; j < precioCondicion.length; j++) { |
558 | plazosConcat += precioCondicion[j].dias + ' '; | 618 | plazosConcat += precioCondicion[j].dias + ' '; |
559 | } | 619 | } |
560 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 620 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
561 | } | 621 | } |
562 | $scope.notaPedido.articulosNotaPedido = []; | 622 | $scope.notaPedido.articulosNotaPedido = []; |
563 | $scope.$broadcast('addCabecera', { | 623 | $scope.$broadcast('addCabecera', { |
564 | label: 'Precios y condiciones:', | 624 | label: 'Precios y condiciones:', |
565 | valor: cabecera | 625 | valor: cabecera |
566 | }); | 626 | }); |
567 | }, function() { | 627 | }, function() { |
568 | 628 | ||
569 | } | 629 | } |
570 | ); | 630 | ); |
571 | } | 631 | } |
572 | }; | 632 | }; |
573 | 633 | ||
574 | $scope.seleccionarFlete = function() { | 634 | $scope.seleccionarFlete = function() { |
575 | if(validarNotaRemitada()) { | 635 | |
576 | var modalInstance = $uibModal.open( | ||
577 | { | ||
578 | ariaLabelledBy: 'Busqueda de Flete', | ||
579 | templateUrl: 'modal-flete.html', | ||
580 | controller: 'focaModalFleteController', | ||
581 | size: 'lg', | ||
582 | resolve: { | ||
583 | parametrosFlete: | ||
584 | function() { | ||
585 | return { | ||
586 | flete: $scope.notaPedido.fob ? 'FOB' : | ||
587 | ( $scope.notaPedido.flete ? '1' : | ||
588 | ($scope.notaPedido.flete === undefined ? | ||
589 | null : '0')), | ||
590 | bomba: $scope.notaPedido.bomba ? '1' : | ||
591 | ($scope.notaPedido.bomba === undefined ? | ||
592 | null : '0'), | ||
593 | kilometros: $scope.notaPedido.kilometros | ||
594 | }; | ||
595 | } | ||
596 | } | ||
597 | } | ||
598 | ); | ||
599 | modalInstance.result.then( | ||
600 | function(datos) { | ||
601 | $scope.notaPedido.flete = datos.flete; | ||
602 | $scope.notaPedido.fob = datos.FOB; | ||
603 | $scope.notaPedido.bomba = datos.bomba; | ||
604 | $scope.notaPedido.kilometros = datos.kilometros; | ||
605 | $scope.$broadcast('addCabecera', { | ||
606 | label: 'Flete:', | ||
607 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | ||
608 | }); | ||
609 | if(datos.flete) { | ||
610 | $scope.$broadcast('addCabecera', { | ||
611 | label: 'Bomba:', | ||
612 | valor: datos.bomba ? 'Si' : 'No' | ||
613 | }); | ||
614 | $scope.$broadcast('addCabecera', { | ||
615 | label: 'Kilometros:', | ||
616 | valor: datos.kilometros | ||
617 | }); | ||
618 | } else { | ||
619 | $scope.$broadcast('removeCabecera', 'Bomba:'); | ||
620 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | ||
621 | $scope.notaPedido.bomba = false; | ||
622 | $scope.notaPedido.kilometros = null; | ||
623 | } | ||
624 | }, function() { | ||
625 | |||
626 | } | ||
627 | ); | ||
628 | } | ||
629 | }; | 636 | }; |
630 | 637 | ||
631 | $scope.seleccionarMoneda = function() { | 638 | $scope.seleccionarMoneda = function() { |
632 | if(validarNotaRemitada()) { | 639 | if(validarNotaRemitada()) { |
633 | var parametrosModal = { | 640 | var parametrosModal = { |
634 | titulo: 'Búsqueda de monedas', | 641 | titulo: 'Búsqueda de monedas', |
635 | query: '/moneda', | 642 | query: '/moneda', |
636 | columnas: [ | 643 | columnas: [ |
637 | { | 644 | { |
638 | propiedad: 'DETALLE', | 645 | propiedad: 'DETALLE', |
639 | nombre: 'Nombre' | 646 | nombre: 'Nombre' |
640 | }, | 647 | }, |
641 | { | 648 | { |
642 | propiedad: 'SIMBOLO', | 649 | propiedad: 'SIMBOLO', |
643 | nombre: 'Símbolo' | 650 | nombre: 'Símbolo' |
644 | } | 651 | } |
645 | ], | 652 | ], |
646 | size: 'md' | 653 | size: 'md' |
647 | }; | 654 | }; |
648 | focaModalService.modal(parametrosModal).then( | 655 | focaModalService.modal(parametrosModal).then( |
649 | function(moneda) { | 656 | function(moneda) { |
650 | $scope.abrirModalCotizacion(moneda); | 657 | $scope.abrirModalCotizacion(moneda); |
651 | }, function() { | 658 | }, function() { |
652 | 659 | ||
653 | } | 660 | } |
654 | ); | 661 | ); |
655 | } | 662 | } |
656 | }; | 663 | }; |
657 | 664 | ||
658 | $scope.seleccionarObservaciones = function() { | 665 | $scope.seleccionarObservaciones = function() { |
659 | focaModalService | 666 | focaModalService |
660 | .prompt({ | 667 | .prompt({ |
661 | titulo: 'Ingrese observaciones', | 668 | titulo: 'Ingrese observaciones', |
662 | value: $scope.notaPedido.observaciones, | 669 | value: $scope.notaPedido.observaciones, |
663 | textarea: true | 670 | textarea: true |
664 | }) | 671 | }) |
665 | .then(function(observaciones) { | 672 | .then(function(observaciones) { |
666 | $scope.notaPedido.observaciones = observaciones; | 673 | $scope.notaPedido.observaciones = observaciones; |
667 | }); | 674 | }); |
668 | }; | 675 | }; |
669 | 676 | ||
670 | $scope.abrirModalCotizacion = function(moneda) { | 677 | $scope.abrirModalCotizacion = function(moneda) { |
671 | var modalInstance = $uibModal.open( | 678 | var modalInstance = $uibModal.open( |
672 | { | 679 | { |
673 | ariaLabelledBy: 'Busqueda de Cotización', | 680 | ariaLabelledBy: 'Busqueda de Cotización', |
674 | templateUrl: 'modal-cotizacion.html', | 681 | templateUrl: 'modal-cotizacion.html', |
675 | controller: 'focaModalCotizacionController', | 682 | controller: 'focaModalCotizacionController', |
676 | size: 'lg', | 683 | size: 'lg', |
677 | resolve: { | 684 | resolve: { |
678 | idMoneda: function() { | 685 | idMoneda: function() { |
679 | return moneda.ID; | 686 | return moneda.ID; |
680 | } | 687 | } |
681 | } | 688 | } |
682 | } | 689 | } |
683 | ); | 690 | ); |
684 | modalInstance.result.then( | 691 | modalInstance.result.then( |
685 | function(cotizacion) { | 692 | function(cotizacion) { |
686 | var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; | 693 | var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; |
687 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 694 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
688 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 695 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
689 | $scope.notaPedido.cotizacion.VENDEDOR; | 696 | $scope.notaPedido.cotizacion.VENDEDOR; |
690 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 697 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
691 | cotizacion.VENDEDOR; | 698 | cotizacion.VENDEDOR; |
692 | } | 699 | } |
693 | $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; | 700 | $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; |
694 | $scope.notaPedido.cotizacion = cotizacion; | 701 | $scope.notaPedido.cotizacion = cotizacion; |
695 | $scope.notaPedido.cotizacion.moneda = moneda; | 702 | $scope.notaPedido.cotizacion.moneda = moneda; |
696 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { | 703 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { |
697 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 704 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
698 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 705 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
699 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 706 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
700 | } else { | 707 | } else { |
701 | $scope.$broadcast('addCabecera', { | 708 | $scope.$broadcast('addCabecera', { |
702 | label: 'Moneda:', | 709 | label: 'Moneda:', |
703 | valor: moneda.DETALLE | 710 | valor: moneda.DETALLE |
704 | }); | 711 | }); |
705 | $scope.$broadcast('addCabecera', { | 712 | $scope.$broadcast('addCabecera', { |
706 | label: 'Fecha cotizacion:', | 713 | label: 'Fecha cotizacion:', |
707 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 714 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
708 | }); | 715 | }); |
709 | $scope.$broadcast('addCabecera', { | 716 | $scope.$broadcast('addCabecera', { |
710 | label: 'Cotizacion:', | 717 | label: 'Cotizacion:', |
711 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 718 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
712 | }); | 719 | }); |
713 | } | 720 | } |
714 | }, function() { | 721 | }, function() { |
715 | 722 | ||
716 | } | 723 | } |
717 | ); | 724 | ); |
718 | }; | 725 | }; |
719 | 726 | ||
720 | $scope.agregarATabla = function(key) { | 727 | $scope.agregarATabla = function(key) { |
721 | if(key === 13) { | 728 | if(key === 13) { |
722 | if($scope.articuloACargar.cantidad === undefined || | 729 | if($scope.articuloACargar.cantidad === undefined || |
723 | $scope.articuloACargar.cantidad === 0 || | 730 | $scope.articuloACargar.cantidad === 0 || |
724 | $scope.articuloACargar.cantidad === null ) { | 731 | $scope.articuloACargar.cantidad === null ) { |
725 | focaModalService.alert('El valor debe ser al menos 1'); | 732 | focaModalService.alert('El valor debe ser al menos 1'); |
726 | return; | 733 | return; |
727 | } | 734 | } |
728 | delete $scope.articuloACargar.sectorCodigo; | 735 | delete $scope.articuloACargar.sectorCodigo; |
729 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); | 736 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); |
730 | $scope.cargando = true; | 737 | $scope.cargando = true; |
731 | } | 738 | } |
732 | }; | 739 | }; |
733 | 740 | ||
734 | $scope.quitarArticulo = function(key) { | 741 | $scope.quitarArticulo = function(key) { |
735 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); | 742 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); |
736 | }; | 743 | }; |
737 | 744 | ||
738 | $scope.editarArticulo = function(key, articulo) { | 745 | $scope.editarArticulo = function(key, articulo) { |
739 | if(key === 13) { | 746 | if(key === 13) { |
740 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 747 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
741 | articulo.cantidad === undefined) { | 748 | articulo.cantidad === undefined) { |
742 | focaModalService.alert('El valor debe ser al menos 1'); | 749 | focaModalService.alert('El valor debe ser al menos 1'); |
743 | return; | 750 | return; |
744 | } | 751 | } |
745 | articulo.editCantidad = false; | 752 | articulo.editCantidad = false; |
746 | articulo.editPrecio = false; | 753 | articulo.editPrecio = false; |
747 | } | 754 | } |
748 | }; | 755 | }; |
749 | 756 | ||
750 | $scope.cambioEdit = function(articulo, propiedad) { | 757 | $scope.cambioEdit = function(articulo, propiedad) { |
751 | if(propiedad === 'cantidad') { | 758 | if(propiedad === 'cantidad') { |
752 | articulo.editCantidad = true; | 759 | articulo.editCantidad = true; |
753 | } else if(propiedad === 'precio') { | 760 | } else if(propiedad === 'precio') { |
754 | articulo.editPrecio = true; | 761 | articulo.editPrecio = true; |
755 | } | 762 | } |
756 | }; | 763 | }; |
757 | 764 | ||
758 | $scope.resetFilter = function() { | 765 | $scope.resetFilter = function() { |
759 | $scope.articuloACargar = {}; | 766 | $scope.articuloACargar = {}; |
760 | $scope.cargando = true; | 767 | $scope.cargando = true; |
761 | }; | 768 | }; |
762 | //Recibe aviso si el teclado está en uso | 769 | //Recibe aviso si el teclado está en uso |
763 | $rootScope.$on('usarTeclado', function(event, data) { | 770 | $rootScope.$on('usarTeclado', function(event, data) { |
764 | if(data) { | 771 | if(data) { |
765 | $scope.mostrarTeclado = true; | 772 | $scope.mostrarTeclado = true; |
766 | return; | 773 | return; |
767 | } | 774 | } |
768 | $scope.mostrarTeclado = false; | 775 | $scope.mostrarTeclado = false; |
769 | }); | 776 | }); |
770 | 777 | ||
771 | $scope.selectFocus = function($event) { | 778 | $scope.selectFocus = function($event) { |
772 | // Si el teclado esta en uso no selecciona el valor | 779 | // Si el teclado esta en uso no selecciona el valor |
773 | if($scope.mostrarTeclado) { | 780 | if($scope.mostrarTeclado) { |
774 | return; | 781 | return; |
775 | } | 782 | } |
776 | $event.target.select(); | 783 | $event.target.select(); |
777 | }; | 784 | }; |
778 | 785 | ||
779 | $scope.salir = function() { | 786 | $scope.salir = function() { |
780 | $location.path('/'); | 787 | $location.path('/'); |
781 | }; | 788 | }; |
782 | 789 | ||
783 | $scope.parsearATexto = function(articulo) { | 790 | $scope.parsearATexto = function(articulo) { |
784 | articulo.cantidad = parseFloat(articulo.cantidad); | 791 | articulo.cantidad = parseFloat(articulo.cantidad); |
785 | articulo.precio = parseFloat(articulo.precio); | 792 | articulo.precio = parseFloat(articulo.precio); |
786 | }; | 793 | }; |
787 | 794 | ||
788 | function setearNotaPedido(notaPedido) { | 795 | function setearNotaPedido(notaPedido) { |
789 | //añado cabeceras | 796 | //añado cabeceras |
790 | $scope.notaPedido = notaPedido; | 797 | $scope.notaPedido = notaPedido; |
791 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 798 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
792 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 799 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
793 | 800 | ||
794 | var cabeceras = []; | 801 | var cabeceras = []; |
795 | 802 | ||
796 | if (notaPedido.cotizacion) { | 803 | if (notaPedido.cotizacion) { |
797 | cabeceras.push({ | 804 | cabeceras.push({ |
798 | label: 'Moneda:', | 805 | label: 'Moneda:', |
799 | valor: notaPedido.cotizacion.moneda.DETALLE | 806 | valor: notaPedido.cotizacion.moneda.DETALLE |
800 | }); | 807 | }); |
801 | cabeceras.push({ | 808 | cabeceras.push({ |
802 | label: 'Fecha cotizacion:', | 809 | label: 'Fecha cotizacion:', |
803 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 810 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
804 | 'dd/MM/yyyy') | 811 | 'dd/MM/yyyy') |
805 | }); | 812 | }); |
806 | cabeceras.push({ | 813 | cabeceras.push({ |
807 | label: 'Cotizacion:', | 814 | label: 'Cotizacion:', |
808 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 815 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
809 | '2') | 816 | '2') |
810 | }); | 817 | }); |
811 | } | 818 | } |
812 | if (notaPedido.cliente.COD) { | 819 | if (notaPedido.cliente.COD) { |
813 | cabeceras.push({ | 820 | cabeceras.push({ |
814 | label: 'Cliente:', | 821 | label: 'Cliente:', |
815 | valor: notaPedido.cliente.NOM | 822 | valor: notaPedido.cliente.NOM |
816 | }); | 823 | }); |
817 | cabeceras.push({ | 824 | cabeceras.push({ |
818 | label: 'Domicilio:', | 825 | label: 'Domicilio:', |
819 | valor: notaPedido.domicilioStamp | 826 | valor: notaPedido.domicilioStamp |
820 | }); | 827 | }); |
821 | } | 828 | } |
822 | if (notaPedido.vendedor.NUM) { | 829 | if (notaPedido.vendedor.NUM) { |
823 | cabeceras.push({ | 830 | cabeceras.push({ |
824 | label: 'Vendedor:', | 831 | label: 'Vendedor:', |
825 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + | 832 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + |
826 | ' - ' + notaPedido.vendedor.NOM | 833 | ' - ' + notaPedido.vendedor.NOM |
827 | }); | 834 | }); |
828 | } | 835 | } |
829 | if (notaPedido.proveedor.COD) { | 836 | if (notaPedido.proveedor.COD) { |
830 | cabeceras.push({ | 837 | cabeceras.push({ |
831 | label: 'Proveedor:', | 838 | label: 'Proveedor:', |
832 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + | 839 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + |
833 | ' - ' + notaPedido.proveedor.NOM | 840 | ' - ' + notaPedido.proveedor.NOM |
834 | }); | 841 | }); |
835 | } | 842 | } |
836 | if (notaPedido.notaPedidoPlazo.length) { | 843 | if (notaPedido.notaPedidoPlazo.length) { |
837 | cabeceras.push({ | 844 | cabeceras.push({ |
838 | label: 'Precios y condiciones:', | 845 | label: 'Precios y condiciones:', |
839 | valor: valorPrecioCondicion() + ' ' + | 846 | valor: valorPrecioCondicion() + ' ' + |
840 | notaPedidoBusinessService | 847 | notaPedidoBusinessService |
841 | .plazoToString(notaPedido.notaPedidoPlazo) | 848 | .plazoToString(notaPedido.notaPedidoPlazo) |
842 | }); | 849 | }); |
843 | } | 850 | } |
844 | if (notaPedido.flete !== undefined) { | 851 | if (notaPedido.flete !== undefined) { |
845 | cabeceras.push({ | 852 | cabeceras.push({ |
846 | label: 'Flete:', | 853 | label: 'Flete:', |
847 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 854 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
848 | notaPedido.flete === 1 ? 'Si' : 'No') | 855 | notaPedido.flete === 1 ? 'Si' : 'No') |
849 | }); | 856 | }); |
850 | } | 857 | } |
851 | 858 | ||
852 | 859 | ||
853 | function valorPrecioCondicion() { | 860 | function valorPrecioCondicion() { |
854 | if (notaPedido.idPrecioCondicion > 0) { | 861 | if (notaPedido.idPrecioCondicion > 0) { |
855 | return notaPedido.precioCondicion.nombre; | 862 | return notaPedido.precioCondicion.nombre; |
856 | } else { | 863 | } else { |
857 | return 'Ingreso Manual'; | 864 | return 'Ingreso Manual'; |
858 | } | 865 | } |
859 | } | 866 | } |
860 | 867 | ||
861 | if (notaPedido.flete === 1) { | 868 | if (notaPedido.flete === 1) { |
862 | var cabeceraBomba = { | 869 | var cabeceraBomba = { |
863 | label: 'Bomba:', | 870 | label: 'Bomba:', |
864 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 871 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
865 | }; | 872 | }; |
866 | if (notaPedido.kilometros) { | 873 | if (notaPedido.kilometros) { |
867 | var cabeceraKilometros = { | 874 | var cabeceraKilometros = { |
868 | label: 'Kilometros:', | 875 | label: 'Kilometros:', |
869 | valor: notaPedido.kilometros | 876 | valor: notaPedido.kilometros |
870 | }; | 877 | }; |
871 | cabeceras.push(cabeceraKilometros); | 878 | cabeceras.push(cabeceraKilometros); |
872 | } | 879 | } |
873 | cabeceras.push(cabeceraBomba); | 880 | cabeceras.push(cabeceraBomba); |
874 | } | 881 | } |
875 | 882 | ||
876 | notaPedidoBusinessService.calcularArticulos($scope.notaPedido.articulosNotaPedido, | 883 | notaPedidoBusinessService.calcularArticulos($scope.notaPedido.articulosNotaPedido, |
877 | notaPedido.cotizacion.VENDEDOR); | 884 | notaPedido.cotizacion.VENDEDOR); |
878 | 885 | ||
879 | if (notaPedido.idPrecioCondicion > 0) { | 886 | if (notaPedido.idPrecioCondicion > 0) { |
880 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 887 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
881 | } else { | 888 | } else { |
882 | $scope.idLista = -1; | 889 | $scope.idLista = -1; |
883 | } | 890 | } |
884 | 891 | ||
885 | $scope.puntoVenta = $filter('rellenarDigitos')( | 892 | $scope.puntoVenta = $filter('rellenarDigitos')( |
886 | notaPedido.sucursal, 4 | 893 | notaPedido.sucursal, 4 |
887 | ); | 894 | ); |
888 | 895 | ||
889 | $scope.comprobante = $filter('rellenarDigitos')( | 896 | $scope.comprobante = $filter('rellenarDigitos')( |
890 | notaPedido.numeroNotaPedido, 8 | 897 | notaPedido.numeroNotaPedido, 8 |
891 | ); | 898 | ); |
892 | 899 | ||
893 | $scope.notaPedido.notaPedidoPuntoDescarga = | 900 | $scope.notaPedido.notaPedidoPuntoDescarga = |
894 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga || []); | 901 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga || []); |
895 | addArrayCabecera(cabeceras); | 902 | addArrayCabecera(cabeceras); |
896 | } | 903 | } |
897 | 904 | ||
898 | function addArrayCabecera(array) { | 905 | function addArrayCabecera(array) { |
899 | for(var i = 0; i < array.length; i++) { | 906 | for(var i = 0; i < array.length; i++) { |
900 | $scope.$broadcast('addCabecera', { | 907 | $scope.$broadcast('addCabecera', { |
901 | label: array[i].label, | 908 | label: array[i].label, |
902 | valor: array[i].valor | 909 | valor: array[i].valor |
903 | }); | 910 | }); |
904 | } | 911 | } |
905 | } | 912 | } |
906 | 913 | ||
907 | function validarNotaRemitada() { | 914 | function validarNotaRemitada() { |
908 | if(!$scope.notaPedido.idRemito) { | 915 | if(!$scope.notaPedido.idRemito) { |
909 | return true; | 916 | return true; |
910 | }else{ | 917 | }else{ |
911 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 918 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
912 | return false; | 919 | return false; |
913 | } | 920 | } |
914 | } | 921 | } |
915 | 922 | ||
916 | function formatearPuntosDescarga(puntosDescarga) { | 923 | function formatearPuntosDescarga(puntosDescarga) { |
917 | var result = []; | 924 | var result = []; |
918 | 925 | ||
919 | puntosDescarga.forEach(function(el) { | 926 | puntosDescarga.forEach(function(el) { |
920 | var puntoDescarga = result.filter(function(resultPunto) { | 927 | var puntoDescarga = result.filter(function(resultPunto) { |
921 | return resultPunto.id === el.idPuntoDescarga; | 928 | return resultPunto.id === el.idPuntoDescarga; |
922 | }); | 929 | }); |
923 | 930 | ||
924 | if (puntoDescarga.length) { | 931 | if (puntoDescarga.length) { |
925 | puntoDescarga[0].articulosAgregados.push({ | 932 | puntoDescarga[0].articulosAgregados.push({ |
926 | cantidad: el.cantidad, | 933 | cantidad: el.cantidad, |
927 | descripcion: el.producto.descripcion, | 934 | descripcion: el.producto.descripcion, |
928 | id: el.producto.id | 935 | id: el.producto.id |
929 | }); | 936 | }); |
930 | } else { | 937 | } else { |
931 | result.push({ | 938 | result.push({ |
932 | id: el.puntoDescarga.id, | 939 | id: el.puntoDescarga.id, |
933 | id_cliente: el.puntoDescarga.id_cliente, | 940 | id_cliente: el.puntoDescarga.id_cliente, |
934 | id_da_config_0: el.puntoDescarga.id_da_config_0, | 941 | id_da_config_0: el.puntoDescarga.id_da_config_0, |
935 | latitud: el.puntoDescarga.latitud, | 942 | latitud: el.puntoDescarga.latitud, |
936 | longitud: el.puntoDescarga.longitud, | 943 | longitud: el.puntoDescarga.longitud, |
937 | descripcion: el.puntoDescarga.descripcion, | 944 | descripcion: el.puntoDescarga.descripcion, |
src/js/service.js
1 | angular.module('focaCrearNotaPedido') | 1 | angular.module('focaCrearNotaPedido') |
2 | .factory('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 2 | .factory('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { |
3 | var route = API_ENDPOINT.URL; | 3 | var route = API_ENDPOINT.URL; |
4 | return { | 4 | return { |
5 | crearNotaPedido: function(notaPedido) { | 5 | crearNotaPedido: function(notaPedido) { |
6 | return $http.post(route + '/nota-pedido', {notaPedido: notaPedido}); | 6 | return $http.post(route + '/nota-pedido', {notaPedido: notaPedido}); |
7 | }, | 7 | }, |
8 | obtenerNotaPedido: function() { | 8 | obtenerNotaPedido: function() { |
9 | return $http.get(route +'/nota-pedido'); | 9 | return $http.get(route +'/nota-pedido'); |
10 | }, | 10 | }, |
11 | setNotaPedido: function(notaPedido) { | 11 | setNotaPedido: function(notaPedido) { |
12 | this.notaPedido = notaPedido; | 12 | this.notaPedido = notaPedido; |
13 | }, | 13 | }, |
14 | clearNotaPedido: function() { | 14 | clearNotaPedido: function() { |
15 | this.notaPedido = undefined; | 15 | this.notaPedido = undefined; |
16 | }, | 16 | }, |
17 | getNotaPedido: function() { | 17 | getNotaPedido: function() { |
18 | return this.notaPedido; | 18 | return this.notaPedido; |
19 | }, | 19 | }, |
20 | getArticulosByIdNotaPedido: function(id) { | 20 | getArticulosByIdNotaPedido: function(id) { |
21 | return $http.get(route+'/articulos/nota-pedido/'+id); | 21 | return $http.get(route+'/articulos/nota-pedido/'+id); |
22 | }, | 22 | }, |
23 | crearArticulosParaNotaPedido: function(articuloNotaPedido) { | 23 | crearArticulosParaNotaPedido: function(articuloNotaPedido) { |
24 | return $http.post(route + '/articulos/nota-pedido', | 24 | return $http.post(route + '/articulos/nota-pedido', |
25 | {articuloNotaPedido: articuloNotaPedido}); | 25 | {articuloNotaPedido: articuloNotaPedido}); |
26 | }, | 26 | }, |
27 | getDomiciliosByIdNotaPedido: function(id) { | 27 | getDomiciliosByIdNotaPedido: function(id) { |
28 | return $http.get(route +'/nota-pedido/'+id+'/domicilios'); | 28 | return $http.get(route +'/nota-pedido/'+id+'/domicilios'); |
29 | }, | 29 | }, |
30 | getDomiciliosByIdCliente: function(id) { | 30 | getDomiciliosByIdCliente: function(id) { |
31 | var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) | 31 | var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) |
32 | return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); | 32 | return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); |
33 | }, | 33 | }, |
34 | getPrecioCondicion: function() { | 34 | getPrecioCondicion: function() { |
35 | return $http.get(route + '/precio-condicion'); | 35 | return $http.get(route + '/precio-condicion'); |
36 | }, | 36 | }, |
37 | getPrecioCondicionById: function(id) { | 37 | getPrecioCondicionById: function(id) { |
38 | return $http.get(route + '/precio-condicion/' + id); | 38 | return $http.get(route + '/precio-condicion/' + id); |
39 | }, | 39 | }, |
40 | getPlazoPagoByPrecioCondicion: function(id) { | 40 | getPlazoPagoByPrecioCondicion: function(id) { |
41 | return $http.get(route + '/plazo-pago/precio-condicion/'+ id); | 41 | return $http.get(route + '/plazo-pago/precio-condicion/'+ id); |
42 | }, | 42 | }, |
43 | crearFlete: function(flete) { | 43 | crearFlete: function(flete) { |
44 | return $http.post(route + '/flete', {flete : flete}); | 44 | return $http.post(route + '/flete', {flete : flete}); |
45 | }, | 45 | }, |
46 | crearPlazosParaNotaPedido: function(plazos) { | 46 | crearPlazosParaNotaPedido: function(plazos) { |
47 | return $http.post(route + '/plazo-pago/nota-pedido', {plazos: plazos}); | 47 | return $http.post(route + '/plazo-pago/nota-pedido', {plazos: plazos}); |
48 | }, | 48 | }, |
49 | getCotizacionByIdMoneda: function(id) { | 49 | getCotizacionByIdMoneda: function(id) { |
50 | return $http.get(route + '/moneda/' + id); | 50 | return $http.get(route + '/moneda/' + id); |
51 | }, | 51 | }, |
52 | crearEstadoParaNotaPedido: function(estado) { | 52 | crearEstadoParaNotaPedido: function(estado) { |
53 | return $http.post(route + '/estado', {estado: estado}); | 53 | return $http.post(route + '/estado', {estado: estado}); |
54 | }, | 54 | }, |
55 | getNumeroNotaPedido: function() { | 55 | getNumeroNotaPedido: function() { |
56 | return $http.get(route + '/nota-pedido/numero-siguiente'); | 56 | return $http.get(route + '/nota-pedido/numero-siguiente'); |
57 | }, | 57 | }, |
58 | getBotonera: function() { | 58 | getBotonera: function() { |
59 | var result = [ | 59 | var result = [ |
60 | { | 60 | { |
61 | label: 'Cliente', | 61 | label: 'Cliente', |
62 | image: 'cliente.png' | 62 | image: 'cliente.png' |
63 | }, | 63 | }, |
64 | { | 64 | { |
65 | label: 'Proveedor', | 65 | label: 'Transportista', |
66 | image: 'proveedor.png' | 66 | image: 'proveedor.png' |
67 | }, | 67 | }, |
68 | { | 68 | { |
69 | label: 'Moneda', | 69 | label: 'Moneda', |
70 | image: 'moneda.png' | 70 | image: 'moneda.png' |
71 | }, | 71 | }, |
72 | { | 72 | { |
73 | label: 'Precios y condiciones', | 73 | label: 'Precios y condiciones', |
74 | image: 'precios-condiciones.png' | 74 | image: 'precios-condiciones.png' |
75 | }, | 75 | }, |
76 | { | 76 | { |
77 | label: 'Flete', | ||
78 | image: 'flete.png' | ||
79 | }, | ||
80 | { | ||
81 | label: 'Productos', | 77 | label: 'Productos', |
82 | image: 'productos.png' | 78 | image: 'productos.png' |
83 | }, | 79 | }, |
84 | { | 80 | { |
85 | label: 'Observaciones', | 81 | label: 'Observaciones', |
86 | image: 'productos.png' | 82 | image: 'productos.png' |
87 | } | 83 | } |
88 | ]; | 84 | ]; |
89 | return result; | 85 | return result; |
90 | }, | 86 | }, |
91 | crearPuntosDescarga: function(puntosDescarga) { | 87 | crearPuntosDescarga: function(puntosDescarga) { |
92 | return $http.post(route + '/puntos-descarga/nota-pedido', | 88 | return $http.post(route + '/puntos-descarga/nota-pedido', |
93 | {puntosDescarga: puntosDescarga}); | 89 | {puntosDescarga: puntosDescarga}); |
94 | }, | 90 | }, |
95 | getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { | 91 | getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { |
96 | return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + | 92 | return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + |
97 | idDomicilio + '/' + idCliente); | 93 | idDomicilio + '/' + idCliente); |
98 | }, | 94 | }, |
99 | getVendedorById: function(id) { | 95 | getVendedorById: function(id) { |
100 | return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + id); | 96 | return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + id); |
101 | } | 97 | } |
102 | }; | 98 | }; |
103 | }]); | 99 | }]); |
104 | 100 |