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