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