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