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