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