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