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