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