Compare View

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