Commit 62374fe31a767e41a1570547fd3b579f7f08f19e

Authored by Jose Pinto
Exists in master and in 1 other branch develop

Merge remote-tracking branch 'upstream/master'

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