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