Commit 31982966b7841d669b82797bbc60b78bd0da9d01
1 parent
e90b8e9ec8
Exists in
master
delete prop verPuntos
Showing
1 changed file
with
1 additions
and
0 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
2 | [ | 2 | [ |
3 | '$scope', | 3 | '$scope', |
4 | '$uibModal', | 4 | '$uibModal', |
5 | '$location', | 5 | '$location', |
6 | '$filter', | 6 | '$filter', |
7 | '$timeout', | 7 | '$timeout', |
8 | 'crearNotaPedidoService', | 8 | 'crearNotaPedidoService', |
9 | 'focaBotoneraLateralService', | 9 | 'focaBotoneraLateralService', |
10 | 'focaModalService', | 10 | 'focaModalService', |
11 | 'notaPedidoBusinessService', | 11 | 'notaPedidoBusinessService', |
12 | '$rootScope', | 12 | '$rootScope', |
13 | 'focaSeguimientoService', | 13 | 'focaSeguimientoService', |
14 | 'APP', | 14 | 'APP', |
15 | 'focaLoginService', | 15 | 'focaLoginService', |
16 | function( | 16 | function( |
17 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, | 17 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, |
18 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, | 18 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, |
19 | $rootScope, focaSeguimientoService, APP, focaLoginService) | 19 | $rootScope, focaSeguimientoService, APP, focaLoginService) |
20 | { | 20 | { |
21 | if(APP === 'distribuidor') { | 21 | if(APP === 'distribuidor') { |
22 | var idVendedor = focaLoginService.getLoginData().vendedorCobrador; | 22 | var idVendedor = focaLoginService.getLoginData().vendedorCobrador; |
23 | $scope.botonera = crearNotaPedidoService.getBotonera(idVendedor); | 23 | $scope.botonera = crearNotaPedidoService.getBotonera(idVendedor); |
24 | crearNotaPedidoService.getVendedorById(idVendedor).then( | 24 | crearNotaPedidoService.getVendedorById(idVendedor).then( |
25 | function(res) { | 25 | function(res) { |
26 | var vendedor = res.data; | 26 | var vendedor = res.data; |
27 | $scope.$broadcast('addCabecera', { | 27 | $scope.$broadcast('addCabecera', { |
28 | label: 'Vendedor:', | 28 | label: 'Vendedor:', |
29 | valor: vendedor.NomVen | 29 | valor: vendedor.NomVen |
30 | }); | 30 | }); |
31 | $scope.notaPedido.vendedor = vendedor; | 31 | $scope.notaPedido.vendedor = vendedor; |
32 | } | 32 | } |
33 | ); | 33 | ); |
34 | }else { | 34 | }else { |
35 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 35 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
36 | } | 36 | } |
37 | 37 | ||
38 | $scope.isNumber = angular.isNumber; | 38 | $scope.isNumber = angular.isNumber; |
39 | $scope.datepickerAbierto = false; | 39 | $scope.datepickerAbierto = false; |
40 | $scope.show = false; | 40 | $scope.show = false; |
41 | $scope.cargando = true; | 41 | $scope.cargando = true; |
42 | $scope.dateOptions = { | 42 | $scope.dateOptions = { |
43 | maxDate: new Date(), | 43 | maxDate: new Date(), |
44 | minDate: new Date(2010, 0, 1) | 44 | minDate: new Date(2010, 0, 1) |
45 | }; | 45 | }; |
46 | 46 | ||
47 | $scope.notaPedido = { | 47 | $scope.notaPedido = { |
48 | id: 0, | 48 | id: 0, |
49 | vendedor: {}, | 49 | vendedor: {}, |
50 | cliente: {}, | 50 | cliente: {}, |
51 | proveedor: {}, | 51 | proveedor: {}, |
52 | domicilio: {dom: ''}, | 52 | domicilio: {dom: ''}, |
53 | moneda: {}, | 53 | moneda: {}, |
54 | cotizacion: {} | 54 | cotizacion: {} |
55 | }; | 55 | }; |
56 | var monedaPorDefecto; | 56 | var monedaPorDefecto; |
57 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 57 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
58 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | 58 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { |
59 | monedaPorDefecto = res.data[0]; | 59 | monedaPorDefecto = res.data[0]; |
60 | $scope.notaPedido.moneda = monedaPorDefecto; | 60 | $scope.notaPedido.moneda = monedaPorDefecto; |
61 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; | 61 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; |
62 | }); | 62 | }); |
63 | 63 | ||
64 | $scope.cabecera = []; | 64 | $scope.cabecera = []; |
65 | $scope.showCabecera = true; | 65 | $scope.showCabecera = true; |
66 | 66 | ||
67 | $scope.now = new Date(); | 67 | $scope.now = new Date(); |
68 | $scope.puntoVenta = '0000'; | 68 | $scope.puntoVenta = '0000'; |
69 | $scope.comprobante = '00000000'; | 69 | $scope.comprobante = '00000000'; |
70 | $scope.articulosTabla = []; | 70 | $scope.articulosTabla = []; |
71 | $scope.idLista = undefined; | 71 | $scope.idLista = undefined; |
72 | 72 | ||
73 | //SETEO BOTONERA LATERAL | 73 | //SETEO BOTONERA LATERAL |
74 | $timeout(function() { | 74 | $timeout(function() { |
75 | focaBotoneraLateralService.showSalir(false); | 75 | focaBotoneraLateralService.showSalir(false); |
76 | focaBotoneraLateralService.showPausar(true); | 76 | focaBotoneraLateralService.showPausar(true); |
77 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 77 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); |
78 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 78 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
79 | }); | 79 | }); |
80 | 80 | ||
81 | crearNotaPedidoService.getNumeroNotaPedido().then( | 81 | crearNotaPedidoService.getNumeroNotaPedido().then( |
82 | function(res) { | 82 | function(res) { |
83 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 83 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
84 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 84 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
85 | }, | 85 | }, |
86 | function(err) { | 86 | function(err) { |
87 | focaModalService.alert('La terminal no esta configurada correctamente'); | 87 | focaModalService.alert('La terminal no esta configurada correctamente'); |
88 | console.info(err); | 88 | console.info(err); |
89 | } | 89 | } |
90 | ); | 90 | ); |
91 | 91 | ||
92 | $scope.crearNotaPedido = function() { | 92 | $scope.crearNotaPedido = function() { |
93 | if(!$scope.notaPedido.vendedor.CodVen) { | 93 | if(!$scope.notaPedido.vendedor.CodVen) { |
94 | focaModalService.alert('Ingrese Vendedor'); | 94 | focaModalService.alert('Ingrese Vendedor'); |
95 | return; | 95 | return; |
96 | } else if(!$scope.notaPedido.cliente.COD) { | 96 | } else if(!$scope.notaPedido.cliente.COD) { |
97 | focaModalService.alert('Ingrese Cliente'); | 97 | focaModalService.alert('Ingrese Cliente'); |
98 | return; | 98 | return; |
99 | } else if(!$scope.notaPedido.proveedor.COD) { | 99 | } else if(!$scope.notaPedido.proveedor.COD) { |
100 | focaModalService.alert('Ingrese Proveedor'); | 100 | focaModalService.alert('Ingrese Proveedor'); |
101 | return; | 101 | return; |
102 | } else if(!$scope.notaPedido.moneda.ID) { | 102 | } else if(!$scope.notaPedido.moneda.ID) { |
103 | focaModalService.alert('Ingrese Moneda'); | 103 | focaModalService.alert('Ingrese Moneda'); |
104 | return; | 104 | return; |
105 | } else if(!$scope.notaPedido.cotizacion.ID) { | 105 | } else if(!$scope.notaPedido.cotizacion.ID) { |
106 | focaModalService.alert('Ingrese Cotización'); | 106 | focaModalService.alert('Ingrese Cotización'); |
107 | return; | 107 | return; |
108 | } else if(!$scope.plazosPagos) { | 108 | } else if(!$scope.plazosPagos) { |
109 | focaModalService.alert('Ingrese Precios y Condiciones'); | 109 | focaModalService.alert('Ingrese Precios y Condiciones'); |
110 | return; | 110 | return; |
111 | } else if( | 111 | } else if( |
112 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 112 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
113 | { | 113 | { |
114 | focaModalService.alert('Ingrese Flete'); | 114 | focaModalService.alert('Ingrese Flete'); |
115 | return; | 115 | return; |
116 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 116 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
117 | focaModalService.alert('Ingrese Domicilio'); | 117 | focaModalService.alert('Ingrese Domicilio'); |
118 | return; | 118 | return; |
119 | } else if($scope.articulosTabla.length === 0) { | 119 | } else if($scope.articulosTabla.length === 0) { |
120 | focaModalService.alert('Debe cargar al menos un articulo'); | 120 | focaModalService.alert('Debe cargar al menos un articulo'); |
121 | return; | 121 | return; |
122 | } | 122 | } |
123 | focaBotoneraLateralService.startGuardar(); | 123 | focaBotoneraLateralService.startGuardar(); |
124 | $scope.saveLoading = true; | 124 | $scope.saveLoading = true; |
125 | var notaPedido = { | 125 | var notaPedido = { |
126 | id: $scope.notaPedido.id, | 126 | id: $scope.notaPedido.id, |
127 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), | 127 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), |
128 | idVendedor: $scope.notaPedido.vendedor.CodVen, | 128 | idVendedor: $scope.notaPedido.vendedor.CodVen, |
129 | idCliente: $scope.notaPedido.cliente.COD, | 129 | idCliente: $scope.notaPedido.cliente.COD, |
130 | nombreCliente: $scope.notaPedido.cliente.NOM, | 130 | nombreCliente: $scope.notaPedido.cliente.NOM, |
131 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 131 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
132 | idProveedor: $scope.notaPedido.proveedor.COD, | 132 | idProveedor: $scope.notaPedido.proveedor.COD, |
133 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID | 133 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID |
134 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 134 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
135 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 135 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
136 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 136 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
137 | flete: $scope.notaPedido.flete, | 137 | flete: $scope.notaPedido.flete, |
138 | fob: $scope.notaPedido.fob, | 138 | fob: $scope.notaPedido.fob, |
139 | bomba: $scope.notaPedido.bomba, | 139 | bomba: $scope.notaPedido.bomba, |
140 | kilometros: $scope.notaPedido.kilometros, | 140 | kilometros: $scope.notaPedido.kilometros, |
141 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 141 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
142 | estado: 0, | 142 | estado: 0, |
143 | total: $scope.getTotal() | 143 | total: $scope.getTotal() |
144 | }; | 144 | }; |
145 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 145 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
146 | function(data) { | 146 | function(data) { |
147 | // Al guardar los datos de la nota de pedido logueamos la | 147 | // Al guardar los datos de la nota de pedido logueamos la |
148 | // actividad para su seguimiento. | 148 | // actividad para su seguimiento. |
149 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 149 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
150 | focaSeguimientoService.guardarPosicion( | 150 | focaSeguimientoService.guardarPosicion( |
151 | 'Nota de pedido', | 151 | 'Nota de pedido', |
152 | data.data.id, | 152 | data.data.id, |
153 | '' | 153 | '' |
154 | ); | 154 | ); |
155 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, | 155 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, |
156 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 156 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
157 | 157 | ||
158 | if($scope.notaPedido.puntosDescarga) { | 158 | if($scope.notaPedido.puntosDescarga) { |
159 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 159 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
160 | $scope.notaPedido.puntosDescarga); | 160 | $scope.notaPedido.puntosDescarga); |
161 | } | 161 | } |
162 | 162 | ||
163 | var plazos = $scope.plazosPagos; | 163 | var plazos = $scope.plazosPagos; |
164 | var plazosACrear = []; | 164 | var plazosACrear = []; |
165 | plazos.forEach(function(plazo) { | 165 | plazos.forEach(function(plazo) { |
166 | plazosACrear.push({ | 166 | plazosACrear.push({ |
167 | idNotaPedido: data.data.id, | 167 | idNotaPedido: data.data.id, |
168 | dias: plazo.dias | 168 | dias: plazo.dias |
169 | }); | 169 | }); |
170 | }); | 170 | }); |
171 | if(plazosACrear.length){ | 171 | if(plazosACrear.length){ |
172 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 172 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); |
173 | } | 173 | } |
174 | 174 | ||
175 | notaPedidoBusinessService.addEstado(data.data.id, | 175 | notaPedidoBusinessService.addEstado(data.data.id, |
176 | $scope.notaPedido.vendedor.CodVen); | 176 | $scope.notaPedido.vendedor.CodVen); |
177 | 177 | ||
178 | focaBotoneraLateralService.endGuardar(true); | 178 | focaBotoneraLateralService.endGuardar(true); |
179 | $scope.saveLoading = false; | 179 | $scope.saveLoading = false; |
180 | $scope.$broadcast('cleanCabecera'); | 180 | $scope.$broadcast('cleanCabecera'); |
181 | $scope.$broadcast('addCabecera', { | 181 | $scope.$broadcast('addCabecera', { |
182 | label: 'Moneda:', | 182 | label: 'Moneda:', |
183 | valor: $scope.notaPedido.moneda.DETALLE | 183 | valor: $scope.notaPedido.moneda.DETALLE |
184 | }); | 184 | }); |
185 | $scope.$broadcast('addCabecera', { | 185 | $scope.$broadcast('addCabecera', { |
186 | label: 'Fecha cotizacion:', | 186 | label: 'Fecha cotizacion:', |
187 | valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') | 187 | valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') |
188 | }); | 188 | }); |
189 | $scope.$broadcast('addCabecera', { | 189 | $scope.$broadcast('addCabecera', { |
190 | label: 'Moneda:', | 190 | label: 'Moneda:', |
191 | valor: $scope.notaPedido.moneda.DETALLE | 191 | valor: $scope.notaPedido.moneda.DETALLE |
192 | }); | 192 | }); |
193 | $scope.$broadcast('addCabecera', { | 193 | $scope.$broadcast('addCabecera', { |
194 | label: 'Cotizacion:', | 194 | label: 'Cotizacion:', |
195 | valor: $filter('number')($scope.notaPedido.cotizacion.VENDEDOR, '2') | 195 | valor: $filter('number')($scope.notaPedido.cotizacion.VENDEDOR, '2') |
196 | }); | 196 | }); |
197 | crearNotaPedidoService.getNumeroNotaPedido().then( | 197 | crearNotaPedidoService.getNumeroNotaPedido().then( |
198 | function(res) { | 198 | function(res) { |
199 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 199 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
200 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 200 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
201 | }, | 201 | }, |
202 | function(err) { | 202 | function(err) { |
203 | focaModalService.alert( | 203 | focaModalService.alert( |
204 | 'La terminal no esta configurada correctamente'); | 204 | 'La terminal no esta configurada correctamente'); |
205 | console.info(err); | 205 | console.info(err); |
206 | } | 206 | } |
207 | ); | 207 | ); |
208 | $scope.notaPedido.vendedor = {}; | 208 | $scope.notaPedido.vendedor = {}; |
209 | $scope.notaPedido.cliente = {}; | 209 | $scope.notaPedido.cliente = {}; |
210 | $scope.notaPedido.proveedor = {}; | 210 | $scope.notaPedido.proveedor = {}; |
211 | $scope.notaPedido.domicilio = {}; | 211 | $scope.notaPedido.domicilio = {}; |
212 | $scope.notaPedido.flete = undefined; | 212 | $scope.notaPedido.flete = undefined; |
213 | $scope.notaPedido.fob = undefined; | 213 | $scope.notaPedido.fob = undefined; |
214 | $scope.notaPedido.bomba = undefined; | 214 | $scope.notaPedido.bomba = undefined; |
215 | $scope.notaPedido.kilometros = undefined; | 215 | $scope.notaPedido.kilometros = undefined; |
216 | $scope.articulosTabla = []; | 216 | $scope.articulosTabla = []; |
217 | }, | 217 | }, |
218 | function(error) { | 218 | function(error) { |
219 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 219 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
220 | focaBotoneraLateralService.endGuardar(); | 220 | focaBotoneraLateralService.endGuardar(); |
221 | $scope.saveLoading = false; | 221 | $scope.saveLoading = false; |
222 | console.info(error); | 222 | console.info(error); |
223 | } | 223 | } |
224 | ); | 224 | ); |
225 | }; | 225 | }; |
226 | 226 | ||
227 | $scope.seleccionarNotaPedido = function() { | 227 | $scope.seleccionarNotaPedido = function() { |
228 | var modalInstance = $uibModal.open( | 228 | var modalInstance = $uibModal.open( |
229 | { | 229 | { |
230 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 230 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
231 | templateUrl: 'foca-modal-nota-pedido.html', | 231 | templateUrl: 'foca-modal-nota-pedido.html', |
232 | controller: 'focaModalNotaPedidoController', | 232 | controller: 'focaModalNotaPedidoController', |
233 | size: 'lg', | 233 | size: 'lg', |
234 | resolve: { | 234 | resolve: { |
235 | usadoPor: function() {return 'notaPedido';}, | 235 | usadoPor: function() {return 'notaPedido';}, |
236 | idVendedor: function() { | 236 | idVendedor: function() { |
237 | if(APP === 'distribuidor') | 237 | if(APP === 'distribuidor') |
238 | return $scope.notaPedido.vendedor.CodVen; | 238 | return $scope.notaPedido.vendedor.CodVen; |
239 | else | 239 | else |
240 | return null; | 240 | return null; |
241 | } | 241 | } |
242 | } | 242 | } |
243 | } | 243 | } |
244 | ); | 244 | ); |
245 | modalInstance.result.then( | 245 | modalInstance.result.then( |
246 | function(notaPedido) { | 246 | function(notaPedido) { |
247 | $scope.now = new Date(notaPedido.fechaCarga); | 247 | $scope.now = new Date(notaPedido.fechaCarga); |
248 | //añado cabeceras | 248 | //añado cabeceras |
249 | $scope.notaPedido.id = notaPedido.id; | 249 | $scope.notaPedido.id = notaPedido.id; |
250 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 250 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
251 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 251 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
252 | var cabeceras = [ | 252 | var cabeceras = [ |
253 | { | 253 | { |
254 | label: 'Moneda:', | 254 | label: 'Moneda:', |
255 | valor: notaPedido.cotizacion.moneda.DETALLE | 255 | valor: notaPedido.cotizacion.moneda.DETALLE |
256 | }, | 256 | }, |
257 | { | 257 | { |
258 | label: 'Fecha cotizacion:', | 258 | label: 'Fecha cotizacion:', |
259 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 259 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
260 | 'dd/MM/yyyy') | 260 | 'dd/MM/yyyy') |
261 | }, | 261 | }, |
262 | { | 262 | { |
263 | label: 'Cotizacion:', | 263 | label: 'Cotizacion:', |
264 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 264 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
265 | '2') | 265 | '2') |
266 | }, | 266 | }, |
267 | { | 267 | { |
268 | label: 'Cliente:', | 268 | label: 'Cliente:', |
269 | valor: notaPedido.cliente.NOM | 269 | valor: notaPedido.cliente.NOM |
270 | }, | 270 | }, |
271 | { | 271 | { |
272 | label: 'Domicilio:', | 272 | label: 'Domicilio:', |
273 | valor: notaPedido.domicilioStamp | 273 | valor: notaPedido.domicilioStamp |
274 | }, | 274 | }, |
275 | { | 275 | { |
276 | label: 'Vendedor:', | 276 | label: 'Vendedor:', |
277 | valor: notaPedido.vendedor.NomVen | 277 | valor: notaPedido.vendedor.NomVen |
278 | }, | 278 | }, |
279 | { | 279 | { |
280 | label: 'Proveedor:', | 280 | label: 'Proveedor:', |
281 | valor: notaPedido.proveedor.NOM | 281 | valor: notaPedido.proveedor.NOM |
282 | }, | 282 | }, |
283 | { | 283 | { |
284 | label: 'Precios y condiciones:', | 284 | label: 'Precios y condiciones:', |
285 | valor: valorPrecioCondicion() + ' ' + | 285 | valor: valorPrecioCondicion() + ' ' + |
286 | notaPedidoBusinessService | 286 | notaPedidoBusinessService |
287 | .plazoToString(notaPedido.notaPedidoPlazo) | 287 | .plazoToString(notaPedido.notaPedidoPlazo) |
288 | }, | 288 | }, |
289 | { | 289 | { |
290 | label: 'Flete:', | 290 | label: 'Flete:', |
291 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 291 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
292 | notaPedido.flete === 1 ? 'Si' : 'No') | 292 | notaPedido.flete === 1 ? 'Si' : 'No') |
293 | } | 293 | } |
294 | ]; | 294 | ]; |
295 | 295 | ||
296 | function valorPrecioCondicion() { | 296 | function valorPrecioCondicion() { |
297 | if(notaPedido.idPrecioCondicion > 0) { | 297 | if(notaPedido.idPrecioCondicion > 0) { |
298 | return notaPedido.precioCondicion.nombre; | 298 | return notaPedido.precioCondicion.nombre; |
299 | } else { | 299 | } else { |
300 | return 'Ingreso Manual'; | 300 | return 'Ingreso Manual'; |
301 | } | 301 | } |
302 | } | 302 | } |
303 | 303 | ||
304 | if(notaPedido.flete === 1) { | 304 | if(notaPedido.flete === 1) { |
305 | var cabeceraBomba = { | 305 | var cabeceraBomba = { |
306 | label: 'Bomba:', | 306 | label: 'Bomba:', |
307 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 307 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
308 | }; | 308 | }; |
309 | if(notaPedido.kilometros) { | 309 | if(notaPedido.kilometros) { |
310 | var cabeceraKilometros = { | 310 | var cabeceraKilometros = { |
311 | label: 'Kilometros:', | 311 | label: 'Kilometros:', |
312 | valor: notaPedido.kilometros | 312 | valor: notaPedido.kilometros |
313 | }; | 313 | }; |
314 | cabeceras.push(cabeceraKilometros); | 314 | cabeceras.push(cabeceraKilometros); |
315 | } | 315 | } |
316 | cabeceras.push(cabeceraBomba); | 316 | cabeceras.push(cabeceraBomba); |
317 | } | 317 | } |
318 | $scope.articulosTabla = notaPedido.articulosNotaPedido; | 318 | $scope.articulosTabla = notaPedido.articulosNotaPedido; |
319 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, | 319 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, |
320 | notaPedido.cotizacion.VENDEDOR); | 320 | notaPedido.cotizacion.VENDEDOR); |
321 | if(notaPedido.idPrecioCondicion > 0) { | 321 | if(notaPedido.idPrecioCondicion > 0) { |
322 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 322 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
323 | } else { | 323 | } else { |
324 | $scope.idLista = -1; | 324 | $scope.idLista = -1; |
325 | } | 325 | } |
326 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); | 326 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); |
327 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); | 327 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); |
328 | $scope.notaPedido = notaPedido; | 328 | $scope.notaPedido = notaPedido; |
329 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; | 329 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; |
330 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; | 330 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; |
331 | $scope.notaPedido.puntosDescarga = | 331 | $scope.notaPedido.puntosDescarga = |
332 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); | 332 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); |
333 | addArrayCabecera(cabeceras); | 333 | addArrayCabecera(cabeceras); |
334 | 334 | ||
335 | }, function() { | 335 | }, function() { |
336 | // funcion ejecutada cuando se cancela el modal | 336 | // funcion ejecutada cuando se cancela el modal |
337 | } | 337 | } |
338 | ); | 338 | ); |
339 | }; | 339 | }; |
340 | 340 | ||
341 | $scope.seleccionarProductos = function() { | 341 | $scope.seleccionarProductos = function() { |
342 | if ($scope.idLista === undefined) { | 342 | if ($scope.idLista === undefined) { |
343 | focaModalService.alert( | 343 | focaModalService.alert( |
344 | 'Primero seleccione una lista de precio y condicion'); | 344 | 'Primero seleccione una lista de precio y condicion'); |
345 | return; | 345 | return; |
346 | } | 346 | } |
347 | var modalInstance = $uibModal.open( | 347 | var modalInstance = $uibModal.open( |
348 | { | 348 | { |
349 | ariaLabelledBy: 'Busqueda de Productos', | 349 | ariaLabelledBy: 'Busqueda de Productos', |
350 | templateUrl: 'modal-busqueda-productos.html', | 350 | templateUrl: 'modal-busqueda-productos.html', |
351 | controller: 'modalBusquedaProductosCtrl', | 351 | controller: 'modalBusquedaProductosCtrl', |
352 | resolve: { | 352 | resolve: { |
353 | parametroProducto: { | 353 | parametroProducto: { |
354 | idLista: $scope.idLista, | 354 | idLista: $scope.idLista, |
355 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 355 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
356 | simbolo: $scope.notaPedido.moneda.SIMBOLO | 356 | simbolo: $scope.notaPedido.moneda.SIMBOLO |
357 | } | 357 | } |
358 | }, | 358 | }, |
359 | size: 'lg' | 359 | size: 'lg' |
360 | } | 360 | } |
361 | ); | 361 | ); |
362 | modalInstance.result.then( | 362 | modalInstance.result.then( |
363 | function(producto) { | 363 | function(producto) { |
364 | var newArt = | 364 | var newArt = |
365 | { | 365 | { |
366 | id: 0, | 366 | id: 0, |
367 | codigo: producto.codigo, | 367 | codigo: producto.codigo, |
368 | sector: producto.sector, | 368 | sector: producto.sector, |
369 | sectorCodigo: producto.sector + '-' + producto.codigo, | 369 | sectorCodigo: producto.sector + '-' + producto.codigo, |
370 | descripcion: producto.descripcion, | 370 | descripcion: producto.descripcion, |
371 | item: $scope.articulosTabla.length + 1, | 371 | item: $scope.articulosTabla.length + 1, |
372 | nombre: producto.descripcion, | 372 | nombre: producto.descripcion, |
373 | precio: parseFloat(producto.precio.toFixed(4)), | 373 | precio: parseFloat(producto.precio.toFixed(4)), |
374 | costoUnitario: producto.costo, | 374 | costoUnitario: producto.costo, |
375 | editCantidad: false, | 375 | editCantidad: false, |
376 | editPrecio: false, | 376 | editPrecio: false, |
377 | rubro: producto.CodRub, | 377 | rubro: producto.CodRub, |
378 | exentoUnitario: producto.precio, | 378 | exentoUnitario: producto.precio, |
379 | ivaUnitario: producto.IMPIVA, | 379 | ivaUnitario: producto.IMPIVA, |
380 | impuestoInternoUnitario: producto.ImpInt, | 380 | impuestoInternoUnitario: producto.ImpInt, |
381 | impuestoInterno1Unitario: producto.ImpInt2, | 381 | impuestoInterno1Unitario: producto.ImpInt2, |
382 | impuestoInterno2Unitario: producto.ImpInt3, | 382 | impuestoInterno2Unitario: producto.ImpInt3, |
383 | precioLista: producto.precio, | 383 | precioLista: producto.precio, |
384 | combustible: 1, | 384 | combustible: 1, |
385 | facturado: 0, | 385 | facturado: 0, |
386 | idArticulo: producto.id | 386 | idArticulo: producto.id |
387 | }; | 387 | }; |
388 | $scope.articuloACargar = newArt; | 388 | $scope.articuloACargar = newArt; |
389 | $scope.cargando = false; | 389 | $scope.cargando = false; |
390 | }, function() { | 390 | }, function() { |
391 | // funcion ejecutada cuando se cancela el modal | 391 | // funcion ejecutada cuando se cancela el modal |
392 | } | 392 | } |
393 | ); | 393 | ); |
394 | }; | 394 | }; |
395 | 395 | ||
396 | $scope.seleccionarPuntosDeDescarga = function() { | 396 | $scope.seleccionarPuntosDeDescarga = function() { |
397 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 397 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
398 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 398 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
399 | return; | 399 | return; |
400 | }else { | 400 | }else { |
401 | var modalInstance = $uibModal.open( | 401 | var modalInstance = $uibModal.open( |
402 | { | 402 | { |
403 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 403 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
404 | templateUrl: 'modal-punto-descarga.html', | 404 | templateUrl: 'modal-punto-descarga.html', |
405 | controller: 'focaModalPuntoDescargaController', | 405 | controller: 'focaModalPuntoDescargaController', |
406 | size: 'lg', | 406 | size: 'lg', |
407 | resolve: { | 407 | resolve: { |
408 | filters: { | 408 | filters: { |
409 | /*TODO: al traer nota de pedido ya creada | 409 | /*TODO: al traer nota de pedido ya creada |
410 | obtener idDomicilio correctamente*/ | 410 | obtener idDomicilio correctamente*/ |
411 | idDomicilio: $scope.notaPedido.domicilio.id, | 411 | idDomicilio: $scope.notaPedido.domicilio.id, |
412 | idCliente: $scope.notaPedido.cliente.COD, | 412 | idCliente: $scope.notaPedido.cliente.COD, |
413 | articulos: $scope.articulosTabla, | 413 | articulos: $scope.articulosTabla, |
414 | puntosDescarga: $scope.notaPedido.puntosDescarga | 414 | puntosDescarga: $scope.notaPedido.puntosDescarga |
415 | } | 415 | } |
416 | } | 416 | } |
417 | } | 417 | } |
418 | ); | 418 | ); |
419 | modalInstance.result.then( | 419 | modalInstance.result.then( |
420 | function(puntosDescarga) { | 420 | function(puntosDescarga) { |
421 | $scope.notaPedido.puntosDescarga = puntosDescarga; | 421 | $scope.notaPedido.puntosDescarga = puntosDescarga; |
422 | }, function() { | 422 | }, function() { |
423 | $scope.abrirModalDomicilios($scope.cliente); | 423 | $scope.abrirModalDomicilios($scope.cliente); |
424 | } | 424 | } |
425 | ); | 425 | ); |
426 | } | 426 | } |
427 | }; | 427 | }; |
428 | 428 | ||
429 | $scope.seleccionarVendedor = function() { | 429 | $scope.seleccionarVendedor = function() { |
430 | if(validarNotaRemitada()) { | 430 | if(validarNotaRemitada()) { |
431 | var modalInstance = $uibModal.open( | 431 | var modalInstance = $uibModal.open( |
432 | { | 432 | { |
433 | ariaLabelledBy: 'Busqueda de Vendedores', | 433 | ariaLabelledBy: 'Busqueda de Vendedores', |
434 | templateUrl: 'modal-vendedores.html', | 434 | templateUrl: 'modal-vendedores.html', |
435 | controller: 'modalVendedoresCtrl', | 435 | controller: 'modalVendedoresCtrl', |
436 | size: 'lg' | 436 | size: 'lg' |
437 | } | 437 | } |
438 | ); | 438 | ); |
439 | modalInstance.result.then( | 439 | modalInstance.result.then( |
440 | function(vendedor) { | 440 | function(vendedor) { |
441 | $scope.$broadcast('addCabecera', { | 441 | $scope.$broadcast('addCabecera', { |
442 | label: 'Vendedor:', | 442 | label: 'Vendedor:', |
443 | valor: vendedor.NomVen | 443 | valor: vendedor.NomVen |
444 | }); | 444 | }); |
445 | $scope.notaPedido.vendedor = vendedor; | 445 | $scope.notaPedido.vendedor = vendedor; |
446 | }, function() { | 446 | }, function() { |
447 | 447 | ||
448 | } | 448 | } |
449 | ); | 449 | ); |
450 | } | 450 | } |
451 | }; | 451 | }; |
452 | 452 | ||
453 | $scope.seleccionarProveedor = function() { | 453 | $scope.seleccionarProveedor = function() { |
454 | if(validarNotaRemitada()) { | 454 | if(validarNotaRemitada()) { |
455 | var modalInstance = $uibModal.open( | 455 | var modalInstance = $uibModal.open( |
456 | { | 456 | { |
457 | ariaLabelledBy: 'Busqueda de Proveedor', | 457 | ariaLabelledBy: 'Busqueda de Proveedor', |
458 | templateUrl: 'modal-proveedor.html', | 458 | templateUrl: 'modal-proveedor.html', |
459 | controller: 'focaModalProveedorCtrl', | 459 | controller: 'focaModalProveedorCtrl', |
460 | size: 'lg', | 460 | size: 'lg', |
461 | resolve: { | 461 | resolve: { |
462 | transportista: function() { | 462 | transportista: function() { |
463 | return false; | 463 | return false; |
464 | } | 464 | } |
465 | } | 465 | } |
466 | } | 466 | } |
467 | ); | 467 | ); |
468 | modalInstance.result.then( | 468 | modalInstance.result.then( |
469 | function(proveedor) { | 469 | function(proveedor) { |
470 | $scope.notaPedido.proveedor = proveedor; | 470 | $scope.notaPedido.proveedor = proveedor; |
471 | $scope.$broadcast('addCabecera', { | 471 | $scope.$broadcast('addCabecera', { |
472 | label: 'Proveedor:', | 472 | label: 'Proveedor:', |
473 | valor: proveedor.NOM | 473 | valor: proveedor.NOM |
474 | }); | 474 | }); |
475 | }, function() { | 475 | }, function() { |
476 | 476 | ||
477 | } | 477 | } |
478 | ); | 478 | ); |
479 | } | 479 | } |
480 | }; | 480 | }; |
481 | 481 | ||
482 | $scope.seleccionarCliente = function() { | 482 | $scope.seleccionarCliente = function() { |
483 | if(!$scope.notaPedido.vendedor.CodVen) { | 483 | if(!$scope.notaPedido.vendedor.CodVen) { |
484 | focaModalService.alert('Primero seleccione un vendedor'); | 484 | focaModalService.alert('Primero seleccione un vendedor'); |
485 | return; | 485 | return; |
486 | } | 486 | } |
487 | if(validarNotaRemitada()) { | 487 | if(validarNotaRemitada()) { |
488 | var modalInstance = $uibModal.open( | 488 | var modalInstance = $uibModal.open( |
489 | { | 489 | { |
490 | ariaLabelledBy: 'Busqueda de Cliente', | 490 | ariaLabelledBy: 'Busqueda de Cliente', |
491 | templateUrl: 'foca-busqueda-cliente-modal.html', | 491 | templateUrl: 'foca-busqueda-cliente-modal.html', |
492 | controller: 'focaBusquedaClienteModalController', | 492 | controller: 'focaBusquedaClienteModalController', |
493 | resolve: { | 493 | resolve: { |
494 | vendedor: function() { return $scope.notaPedido.vendedor; } | 494 | vendedor: function() { return $scope.notaPedido.vendedor; } |
495 | }, | 495 | }, |
496 | size: 'lg' | 496 | size: 'lg' |
497 | } | 497 | } |
498 | ); | 498 | ); |
499 | modalInstance.result.then( | 499 | modalInstance.result.then( |
500 | function(cliente) { | 500 | function(cliente) { |
501 | $scope.abrirModalDomicilios(cliente); | 501 | $scope.abrirModalDomicilios(cliente); |
502 | $scope.cliente = cliente; | 502 | $scope.cliente = cliente; |
503 | }, function() {} | 503 | }, function() {} |
504 | ); | 504 | ); |
505 | } | 505 | } |
506 | }; | 506 | }; |
507 | 507 | ||
508 | $scope.abrirModalDomicilios = function(cliente) { | 508 | $scope.abrirModalDomicilios = function(cliente) { |
509 | var modalInstanceDomicilio = $uibModal.open( | 509 | var modalInstanceDomicilio = $uibModal.open( |
510 | { | 510 | { |
511 | ariaLabelledBy: 'Busqueda de Domicilios', | 511 | ariaLabelledBy: 'Busqueda de Domicilios', |
512 | templateUrl: 'modal-domicilio.html', | 512 | templateUrl: 'modal-domicilio.html', |
513 | controller: 'focaModalDomicilioController', | 513 | controller: 'focaModalDomicilioController', |
514 | resolve: { | 514 | resolve: { |
515 | idCliente: function() { return cliente.cod; }, | 515 | idCliente: function() { return cliente.cod; }, |
516 | esNuevo: function() { return cliente.esNuevo; } | 516 | esNuevo: function() { return cliente.esNuevo; } |
517 | }, | 517 | }, |
518 | size: 'lg', | 518 | size: 'lg', |
519 | } | 519 | } |
520 | ); | 520 | ); |
521 | modalInstanceDomicilio.result.then( | 521 | modalInstanceDomicilio.result.then( |
522 | function(domicilio) { | 522 | function(domicilio) { |
523 | $scope.notaPedido.domicilio = domicilio; | 523 | $scope.notaPedido.domicilio = domicilio; |
524 | $scope.notaPedido.cliente = { | 524 | $scope.notaPedido.cliente = { |
525 | COD: cliente.cod, | 525 | COD: cliente.cod, |
526 | CUIT: cliente.cuit, | 526 | CUIT: cliente.cuit, |
527 | NOM: cliente.nom | 527 | NOM: cliente.nom |
528 | }; | 528 | }; |
529 | var domicilioStamp = | 529 | var domicilioStamp = |
530 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 530 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
531 | domicilio.Localidad + ', ' + domicilio.Provincia; | 531 | domicilio.Localidad + ', ' + domicilio.Provincia; |
532 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 532 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
533 | 533 | ||
534 | $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; | 534 | $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; |
535 | 535 | ||
536 | $scope.$broadcast('addCabecera', { | 536 | $scope.$broadcast('addCabecera', { |
537 | label: 'Cliente:', | 537 | label: 'Cliente:', |
538 | valor: cliente.nom | 538 | valor: cliente.nom |
539 | }); | 539 | }); |
540 | $scope.$broadcast('addCabecera', { | 540 | $scope.$broadcast('addCabecera', { |
541 | label: 'Domicilio:', | 541 | label: 'Domicilio:', |
542 | valor: domicilioStamp | 542 | valor: domicilioStamp |
543 | }); | 543 | }); |
544 | if(domicilio.verPuntos) { | 544 | if(domicilio.verPuntos) { |
545 | delete $scope.notaPedido.domicilio.verPuntos; | ||
545 | $scope.seleccionarPuntosDeDescarga(); | 546 | $scope.seleccionarPuntosDeDescarga(); |
546 | }else { | 547 | }else { |
547 | crearNotaPedidoService | 548 | crearNotaPedidoService |
548 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | 549 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) |
549 | .then(function(res) { | 550 | .then(function(res) { |
550 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); | 551 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); |
551 | }); | 552 | }); |
552 | } | 553 | } |
553 | }, function() { | 554 | }, function() { |
554 | $scope.seleccionarCliente(); | 555 | $scope.seleccionarCliente(); |
555 | return; | 556 | return; |
556 | } | 557 | } |
557 | ); | 558 | ); |
558 | }; | 559 | }; |
559 | 560 | ||
560 | $scope.getTotal = function() { | 561 | $scope.getTotal = function() { |
561 | var total = 0; | 562 | var total = 0; |
562 | var arrayTempArticulos = $scope.articulosTabla; | 563 | var arrayTempArticulos = $scope.articulosTabla; |
563 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 564 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
564 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 565 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
565 | } | 566 | } |
566 | return parseFloat(total.toFixed(2)); | 567 | return parseFloat(total.toFixed(2)); |
567 | }; | 568 | }; |
568 | 569 | ||
569 | $scope.getSubTotal = function() { | 570 | $scope.getSubTotal = function() { |
570 | if($scope.articuloACargar) { | 571 | if($scope.articuloACargar) { |
571 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 572 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
572 | } | 573 | } |
573 | }; | 574 | }; |
574 | 575 | ||
575 | $scope.seleccionarPreciosYCondiciones = function() { | 576 | $scope.seleccionarPreciosYCondiciones = function() { |
576 | if(validarNotaRemitada()) { | 577 | if(validarNotaRemitada()) { |
577 | var modalInstance = $uibModal.open( | 578 | var modalInstance = $uibModal.open( |
578 | { | 579 | { |
579 | ariaLabelledBy: 'Busqueda de Precio Condición', | 580 | ariaLabelledBy: 'Busqueda de Precio Condición', |
580 | templateUrl: 'modal-precio-condicion.html', | 581 | templateUrl: 'modal-precio-condicion.html', |
581 | controller: 'focaModalPrecioCondicionController', | 582 | controller: 'focaModalPrecioCondicionController', |
582 | size: 'lg' | 583 | size: 'lg' |
583 | } | 584 | } |
584 | ); | 585 | ); |
585 | modalInstance.result.then( | 586 | modalInstance.result.then( |
586 | function(precioCondicion) { | 587 | function(precioCondicion) { |
587 | var cabecera = ''; | 588 | var cabecera = ''; |
588 | var plazosConcat = ''; | 589 | var plazosConcat = ''; |
589 | if(!Array.isArray(precioCondicion)) { | 590 | if(!Array.isArray(precioCondicion)) { |
590 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 591 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
591 | $scope.plazosPagos = precioCondicion.plazoPago; | 592 | $scope.plazosPagos = precioCondicion.plazoPago; |
592 | $scope.idLista = precioCondicion.idListaPrecio; | 593 | $scope.idLista = precioCondicion.idListaPrecio; |
593 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 594 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
594 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 595 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
595 | } | 596 | } |
596 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); | 597 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); |
597 | } else { //Cuando se ingresan los plazos manualmente | 598 | } else { //Cuando se ingresan los plazos manualmente |
598 | $scope.notaPedido.idPrecioCondicion = 0; | 599 | $scope.notaPedido.idPrecioCondicion = 0; |
599 | //-1, el modal productos busca todos los productos | 600 | //-1, el modal productos busca todos los productos |
600 | $scope.idLista = -1; | 601 | $scope.idLista = -1; |
601 | $scope.plazosPagos = precioCondicion; | 602 | $scope.plazosPagos = precioCondicion; |
602 | for(var j = 0; j < precioCondicion.length; j++) { | 603 | for(var j = 0; j < precioCondicion.length; j++) { |
603 | plazosConcat += precioCondicion[j].dias + ' '; | 604 | plazosConcat += precioCondicion[j].dias + ' '; |
604 | } | 605 | } |
605 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 606 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
606 | } | 607 | } |
607 | $scope.articulosTabla = []; | 608 | $scope.articulosTabla = []; |
608 | $scope.$broadcast('addCabecera', { | 609 | $scope.$broadcast('addCabecera', { |
609 | label: 'Precios y condiciones:', | 610 | label: 'Precios y condiciones:', |
610 | valor: cabecera | 611 | valor: cabecera |
611 | }); | 612 | }); |
612 | }, function() { | 613 | }, function() { |
613 | 614 | ||
614 | } | 615 | } |
615 | ); | 616 | ); |
616 | } | 617 | } |
617 | }; | 618 | }; |
618 | 619 | ||
619 | $scope.seleccionarFlete = function() { | 620 | $scope.seleccionarFlete = function() { |
620 | if(validarNotaRemitada()) { | 621 | if(validarNotaRemitada()) { |
621 | var modalInstance = $uibModal.open( | 622 | var modalInstance = $uibModal.open( |
622 | { | 623 | { |
623 | ariaLabelledBy: 'Busqueda de Flete', | 624 | ariaLabelledBy: 'Busqueda de Flete', |
624 | templateUrl: 'modal-flete.html', | 625 | templateUrl: 'modal-flete.html', |
625 | controller: 'focaModalFleteController', | 626 | controller: 'focaModalFleteController', |
626 | size: 'lg', | 627 | size: 'lg', |
627 | resolve: { | 628 | resolve: { |
628 | parametrosFlete: | 629 | parametrosFlete: |
629 | function() { | 630 | function() { |
630 | return { | 631 | return { |
631 | flete: $scope.notaPedido.fob ? 'FOB' : | 632 | flete: $scope.notaPedido.fob ? 'FOB' : |
632 | ( $scope.notaPedido.flete ? '1' : | 633 | ( $scope.notaPedido.flete ? '1' : |
633 | ($scope.notaPedido.flete === undefined ? | 634 | ($scope.notaPedido.flete === undefined ? |
634 | null : '0')), | 635 | null : '0')), |
635 | bomba: $scope.notaPedido.bomba ? '1' : | 636 | bomba: $scope.notaPedido.bomba ? '1' : |
636 | ($scope.notaPedido.bomba === undefined ? | 637 | ($scope.notaPedido.bomba === undefined ? |
637 | null : '0'), | 638 | null : '0'), |
638 | kilometros: $scope.notaPedido.kilometros | 639 | kilometros: $scope.notaPedido.kilometros |
639 | }; | 640 | }; |
640 | } | 641 | } |
641 | } | 642 | } |
642 | } | 643 | } |
643 | ); | 644 | ); |
644 | modalInstance.result.then( | 645 | modalInstance.result.then( |
645 | function(datos) { | 646 | function(datos) { |
646 | $scope.notaPedido.flete = datos.flete; | 647 | $scope.notaPedido.flete = datos.flete; |
647 | $scope.notaPedido.fob = datos.FOB; | 648 | $scope.notaPedido.fob = datos.FOB; |
648 | $scope.notaPedido.bomba = datos.bomba; | 649 | $scope.notaPedido.bomba = datos.bomba; |
649 | $scope.notaPedido.kilometros = datos.kilometros; | 650 | $scope.notaPedido.kilometros = datos.kilometros; |
650 | $scope.$broadcast('addCabecera', { | 651 | $scope.$broadcast('addCabecera', { |
651 | label: 'Flete:', | 652 | label: 'Flete:', |
652 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 653 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
653 | }); | 654 | }); |
654 | if(datos.flete) { | 655 | if(datos.flete) { |
655 | $scope.$broadcast('addCabecera', { | 656 | $scope.$broadcast('addCabecera', { |
656 | label: 'Bomba:', | 657 | label: 'Bomba:', |
657 | valor: datos.bomba ? 'Si' : 'No' | 658 | valor: datos.bomba ? 'Si' : 'No' |
658 | }); | 659 | }); |
659 | $scope.$broadcast('addCabecera', { | 660 | $scope.$broadcast('addCabecera', { |
660 | label: 'Kilometros:', | 661 | label: 'Kilometros:', |
661 | valor: datos.kilometros | 662 | valor: datos.kilometros |
662 | }); | 663 | }); |
663 | } else { | 664 | } else { |
664 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 665 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
665 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 666 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
666 | $scope.notaPedido.bomba = false; | 667 | $scope.notaPedido.bomba = false; |
667 | $scope.notaPedido.kilometros = null; | 668 | $scope.notaPedido.kilometros = null; |
668 | } | 669 | } |
669 | }, function() { | 670 | }, function() { |
670 | 671 | ||
671 | } | 672 | } |
672 | ); | 673 | ); |
673 | } | 674 | } |
674 | }; | 675 | }; |
675 | 676 | ||
676 | $scope.seleccionarMoneda = function() { | 677 | $scope.seleccionarMoneda = function() { |
677 | if(validarNotaRemitada()) { | 678 | if(validarNotaRemitada()) { |
678 | var modalInstance = $uibModal.open( | 679 | var modalInstance = $uibModal.open( |
679 | { | 680 | { |
680 | ariaLabelledBy: 'Busqueda de Moneda', | 681 | ariaLabelledBy: 'Busqueda de Moneda', |
681 | templateUrl: 'modal-moneda.html', | 682 | templateUrl: 'modal-moneda.html', |
682 | controller: 'focaModalMonedaController', | 683 | controller: 'focaModalMonedaController', |
683 | size: 'lg' | 684 | size: 'lg' |
684 | } | 685 | } |
685 | ); | 686 | ); |
686 | modalInstance.result.then( | 687 | modalInstance.result.then( |
687 | function(moneda) { | 688 | function(moneda) { |
688 | $scope.abrirModalCotizacion(moneda); | 689 | $scope.abrirModalCotizacion(moneda); |
689 | }, function() { | 690 | }, function() { |
690 | 691 | ||
691 | } | 692 | } |
692 | ); | 693 | ); |
693 | } | 694 | } |
694 | }; | 695 | }; |
695 | 696 | ||
696 | $scope.abrirModalCotizacion = function(moneda) { | 697 | $scope.abrirModalCotizacion = function(moneda) { |
697 | var modalInstance = $uibModal.open( | 698 | var modalInstance = $uibModal.open( |
698 | { | 699 | { |
699 | ariaLabelledBy: 'Busqueda de Cotización', | 700 | ariaLabelledBy: 'Busqueda de Cotización', |
700 | templateUrl: 'modal-cotizacion.html', | 701 | templateUrl: 'modal-cotizacion.html', |
701 | controller: 'focaModalCotizacionController', | 702 | controller: 'focaModalCotizacionController', |
702 | size: 'lg', | 703 | size: 'lg', |
703 | resolve: {idMoneda: function() {return moneda.ID;}} | 704 | resolve: {idMoneda: function() {return moneda.ID;}} |
704 | } | 705 | } |
705 | ); | 706 | ); |
706 | modalInstance.result.then( | 707 | modalInstance.result.then( |
707 | function(cotizacion) { | 708 | function(cotizacion) { |
708 | var articulosTablaTemp = $scope.articulosTabla; | 709 | var articulosTablaTemp = $scope.articulosTabla; |
709 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 710 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
710 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 711 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
711 | $scope.notaPedido.cotizacion.VENDEDOR; | 712 | $scope.notaPedido.cotizacion.VENDEDOR; |
712 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 713 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
713 | cotizacion.VENDEDOR; | 714 | cotizacion.VENDEDOR; |
714 | } | 715 | } |
715 | $scope.articulosTabla = articulosTablaTemp; | 716 | $scope.articulosTabla = articulosTablaTemp; |
716 | $scope.notaPedido.moneda = moneda; | 717 | $scope.notaPedido.moneda = moneda; |
717 | $scope.notaPedido.cotizacion = cotizacion; | 718 | $scope.notaPedido.cotizacion = cotizacion; |
718 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { | 719 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { |
719 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 720 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
720 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 721 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
721 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 722 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
722 | }else { | 723 | }else { |
723 | $scope.$broadcast('addCabecera', { | 724 | $scope.$broadcast('addCabecera', { |
724 | label: 'Moneda:', | 725 | label: 'Moneda:', |
725 | valor: moneda.DETALLE | 726 | valor: moneda.DETALLE |
726 | }); | 727 | }); |
727 | $scope.$broadcast('addCabecera', { | 728 | $scope.$broadcast('addCabecera', { |
728 | label: 'Fecha cotizacion:', | 729 | label: 'Fecha cotizacion:', |
729 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 730 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
730 | }); | 731 | }); |
731 | $scope.$broadcast('addCabecera', { | 732 | $scope.$broadcast('addCabecera', { |
732 | label: 'Cotizacion:', | 733 | label: 'Cotizacion:', |
733 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 734 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
734 | }); | 735 | }); |
735 | } | 736 | } |
736 | }, function() { | 737 | }, function() { |
737 | 738 | ||
738 | } | 739 | } |
739 | ); | 740 | ); |
740 | }; | 741 | }; |
741 | 742 | ||
742 | $scope.agregarATabla = function(key) { | 743 | $scope.agregarATabla = function(key) { |
743 | if(key === 13) { | 744 | if(key === 13) { |
744 | if($scope.articuloACargar.cantidad === undefined || | 745 | if($scope.articuloACargar.cantidad === undefined || |
745 | $scope.articuloACargar.cantidad === 0 || | 746 | $scope.articuloACargar.cantidad === 0 || |
746 | $scope.articuloACargar.cantidad === null ) { | 747 | $scope.articuloACargar.cantidad === null ) { |
747 | focaModalService.alert('El valor debe ser al menos 1'); | 748 | focaModalService.alert('El valor debe ser al menos 1'); |
748 | return; | 749 | return; |
749 | } | 750 | } |
750 | delete $scope.articuloACargar.sectorCodigo; | 751 | delete $scope.articuloACargar.sectorCodigo; |
751 | $scope.articulosTabla.push($scope.articuloACargar); | 752 | $scope.articulosTabla.push($scope.articuloACargar); |
752 | $scope.cargando = true; | 753 | $scope.cargando = true; |
753 | } | 754 | } |
754 | }; | 755 | }; |
755 | 756 | ||
756 | $scope.quitarArticulo = function(key) { | 757 | $scope.quitarArticulo = function(key) { |
757 | $scope.articulosTabla.splice(key, 1); | 758 | $scope.articulosTabla.splice(key, 1); |
758 | }; | 759 | }; |
759 | 760 | ||
760 | $scope.editarArticulo = function(key, articulo) { | 761 | $scope.editarArticulo = function(key, articulo) { |
761 | if(key === 13) { | 762 | if(key === 13) { |
762 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 763 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
763 | articulo.cantidad === undefined) { | 764 | articulo.cantidad === undefined) { |
764 | focaModalService.alert('El valor debe ser al menos 1'); | 765 | focaModalService.alert('El valor debe ser al menos 1'); |
765 | return; | 766 | return; |
766 | } | 767 | } |
767 | articulo.editCantidad = false; | 768 | articulo.editCantidad = false; |
768 | articulo.editPrecio = false; | 769 | articulo.editPrecio = false; |
769 | } | 770 | } |
770 | }; | 771 | }; |
771 | 772 | ||
772 | $scope.cambioEdit = function(articulo, propiedad) { | 773 | $scope.cambioEdit = function(articulo, propiedad) { |
773 | if(propiedad === 'cantidad') { | 774 | if(propiedad === 'cantidad') { |
774 | articulo.editCantidad = true; | 775 | articulo.editCantidad = true; |
775 | } else if(propiedad === 'precio') { | 776 | } else if(propiedad === 'precio') { |
776 | articulo.editPrecio = true; | 777 | articulo.editPrecio = true; |
777 | } | 778 | } |
778 | }; | 779 | }; |
779 | 780 | ||
780 | $scope.resetFilter = function() { | 781 | $scope.resetFilter = function() { |
781 | $scope.articuloACargar = {}; | 782 | $scope.articuloACargar = {}; |
782 | $scope.cargando = true; | 783 | $scope.cargando = true; |
783 | }; | 784 | }; |
784 | //Recibe aviso si el teclado está en uso | 785 | //Recibe aviso si el teclado está en uso |
785 | $rootScope.$on('usarTeclado', function(event, data) { | 786 | $rootScope.$on('usarTeclado', function(event, data) { |
786 | if(data) { | 787 | if(data) { |
787 | $scope.mostrarTeclado = true; | 788 | $scope.mostrarTeclado = true; |
788 | return; | 789 | return; |
789 | } | 790 | } |
790 | $scope.mostrarTeclado = false; | 791 | $scope.mostrarTeclado = false; |
791 | }); | 792 | }); |
792 | 793 | ||
793 | $scope.selectFocus = function($event) { | 794 | $scope.selectFocus = function($event) { |
794 | // Si el teclado esta en uso no selecciona el valor | 795 | // Si el teclado esta en uso no selecciona el valor |
795 | if($scope.mostrarTeclado) { | 796 | if($scope.mostrarTeclado) { |
796 | return; | 797 | return; |
797 | } | 798 | } |
798 | $event.target.select(); | 799 | $event.target.select(); |
799 | }; | 800 | }; |
800 | 801 | ||
801 | $scope.salir = function() { | 802 | $scope.salir = function() { |
802 | $location.path('/'); | 803 | $location.path('/'); |
803 | }; | 804 | }; |
804 | 805 | ||
805 | $scope.parsearATexto = function(articulo) { | 806 | $scope.parsearATexto = function(articulo) { |
806 | articulo.cantidad = parseFloat(articulo.cantidad); | 807 | articulo.cantidad = parseFloat(articulo.cantidad); |
807 | articulo.precio = parseFloat(articulo.precio); | 808 | articulo.precio = parseFloat(articulo.precio); |
808 | }; | 809 | }; |
809 | 810 | ||
810 | function addArrayCabecera(array) { | 811 | function addArrayCabecera(array) { |
811 | for(var i = 0; i < array.length; i++) { | 812 | for(var i = 0; i < array.length; i++) { |
812 | $scope.$broadcast('addCabecera', { | 813 | $scope.$broadcast('addCabecera', { |
813 | label: array[i].label, | 814 | label: array[i].label, |
814 | valor: array[i].valor | 815 | valor: array[i].valor |
815 | }); | 816 | }); |
816 | } | 817 | } |
817 | } | 818 | } |
818 | 819 | ||
819 | function rellenar(relleno, longitud) { | 820 | function rellenar(relleno, longitud) { |
820 | relleno = '' + relleno; | 821 | relleno = '' + relleno; |
821 | while (relleno.length < longitud) { | 822 | while (relleno.length < longitud) { |
822 | relleno = '0' + relleno; | 823 | relleno = '0' + relleno; |
823 | } | 824 | } |
824 | 825 | ||
825 | return relleno; | 826 | return relleno; |
826 | } | 827 | } |
827 | 828 | ||
828 | function validarNotaRemitada() { | 829 | function validarNotaRemitada() { |
829 | if(!$scope.notaPedido.idRemito) { | 830 | if(!$scope.notaPedido.idRemito) { |
830 | return true; | 831 | return true; |
831 | }else{ | 832 | }else{ |
832 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 833 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
833 | return false; | 834 | return false; |
834 | } | 835 | } |
835 | } | 836 | } |
836 | function formatearPuntosDescarga(puntosDescarga) { | 837 | function formatearPuntosDescarga(puntosDescarga) { |
837 | var result = []; | 838 | var result = []; |
838 | 839 | ||
839 | puntosDescarga.forEach(function(el) { | 840 | puntosDescarga.forEach(function(el) { |
840 | var puntoDescarga = result.filter(function(resultPunto) { | 841 | var puntoDescarga = result.filter(function(resultPunto) { |
841 | return resultPunto.id == el.idPuntoDescarga; | 842 | return resultPunto.id == el.idPuntoDescarga; |
842 | }); | 843 | }); |
843 | 844 | ||
844 | if(puntoDescarga.length) { | 845 | if(puntoDescarga.length) { |
845 | puntoDescarga[0].articulosAgregados.push({ | 846 | puntoDescarga[0].articulosAgregados.push({ |
846 | cantidad: el.cantidad, | 847 | cantidad: el.cantidad, |
847 | descripcion: el.producto.descripcion, | 848 | descripcion: el.producto.descripcion, |
848 | id: el.producto.id | 849 | id: el.producto.id |
849 | }); | 850 | }); |
850 | }else { | 851 | }else { |
851 | result.push({ | 852 | result.push({ |
852 | id: el.puntoDescarga.id, | 853 | id: el.puntoDescarga.id, |
853 | id_cliente: el.puntoDescarga.id_cliente, | 854 | id_cliente: el.puntoDescarga.id_cliente, |
854 | id_da_config_0: el.puntoDescarga.id_da_config_0, | 855 | id_da_config_0: el.puntoDescarga.id_da_config_0, |
855 | latitud: el.puntoDescarga.latitud, | 856 | latitud: el.puntoDescarga.latitud, |
856 | longitud: el.puntoDescarga.longitud, | 857 | longitud: el.puntoDescarga.longitud, |
857 | descripcion: el.puntoDescarga.descripcion, | 858 | descripcion: el.puntoDescarga.descripcion, |
858 | articulosAgregados: [ | 859 | articulosAgregados: [ |
859 | { | 860 | { |
860 | cantidad: el.cantidad, | 861 | cantidad: el.cantidad, |
861 | descripcion: el.producto.descripcion, | 862 | descripcion: el.producto.descripcion, |
862 | id: el.producto.id | 863 | id: el.producto.id |
863 | } | 864 | } |
864 | ] | 865 | ] |
865 | }); | 866 | }); |
866 | } | 867 | } |
867 | }); | 868 | }); |
868 | return result; | 869 | return result; |
869 | } | 870 | } |
870 | 871 | ||
871 | function salir() { | 872 | function salir() { |
872 | var notaPedido = { | 873 | var notaPedido = { |
873 | id: 0, | 874 | id: 0, |
874 | vendedor: {}, | 875 | vendedor: {}, |
875 | cliente: {}, | 876 | cliente: {}, |
876 | proveedor: {}, | 877 | proveedor: {}, |
877 | domicilio: {dom: ''}, | 878 | domicilio: {dom: ''}, |
878 | moneda: $scope.notaPedido.moneda, | 879 | moneda: $scope.notaPedido.moneda, |
879 | cotizacion: $scope.notaPedido.cotizacion | 880 | cotizacion: $scope.notaPedido.cotizacion |
880 | }; | 881 | }; |
881 | if(JSON.stringify($scope.notaPedido) !== JSON.stringify(notaPedido)) { | 882 | if(JSON.stringify($scope.notaPedido) !== JSON.stringify(notaPedido)) { |
882 | focaModalService | 883 | focaModalService |
883 | .confirm('¿Esta seguro de que desea salir? ' + | 884 | .confirm('¿Esta seguro de que desea salir? ' + |
884 | 'Se perderán todos los datos cargados.') | 885 | 'Se perderán todos los datos cargados.') |
885 | .then(function(data) { | 886 | .then(function(data) { |
886 | if(data) $location.path('/'); | 887 | if(data) $location.path('/'); |
887 | }); | 888 | }); |
888 | }else { | 889 | }else { |
889 | $location.path('/'); | 890 | $location.path('/'); |
890 | } | 891 | } |
891 | } | 892 | } |
892 | } | 893 | } |
893 | ]); | 894 | ]); |
894 | 895 |