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