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