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