Commit a9b60dfe62d4f34cb2ce662a02cd82c44ac2d39c

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'develop' into 'master'

Develop

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