Commit 2f9276f19b6e7da0069d98fc08d9d28eb217fccc

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master(efernandez)

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