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