Commit 723e4d087648fdb7babaa2d73d7fd88f9944d434

Authored by Eric Fernandez
1 parent ebd6bf8064
Exists in master

pre-commit

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