Commit 4f01e66a4421945ed59f01c0a71e2d92c8364751

Authored by Eric Fernandez
Exists in master

Merge branch 'master' of https://debo.suite.repo/modulos-npm/foca-crear-nota-pedido

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