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