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