Commit 0fb9e9af2f550dafd52d9de3eb2551d9dc385415

Authored by Eric Fernandez
1 parent bd0491de7f
Exists in master

no es necesario parsear

Showing 1 changed file with 4 additions and 4 deletions   Show diff stats
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', 4 'focaModalService',
5 function( 5 function(
6 $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService 6 $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService
7 ) { 7 ) {
8 $scope.botonera = [ 8 $scope.botonera = [
9 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, 9 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}},
10 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, 10 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}},
11 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, 11 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}},
12 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, 12 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}},
13 { 13 {
14 texto: 'Precios y condiciones', 14 texto: 'Precios y condiciones',
15 accion: function() {$scope.abrirModalListaPrecio();}}, 15 accion: function() {$scope.abrirModalListaPrecio();}},
16 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, 16 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}},
17 {texto: '', accion: function() {}}, 17 {texto: '', accion: function() {}},
18 {texto: '', accion: function() {}} 18 {texto: '', accion: function() {}}
19 ]; 19 ];
20 $scope.datepickerAbierto = false; 20 $scope.datepickerAbierto = false;
21 21
22 $scope.show = false; 22 $scope.show = false;
23 $scope.cargando = true; 23 $scope.cargando = true;
24 $scope.dateOptions = { 24 $scope.dateOptions = {
25 maxDate: new Date(), 25 maxDate: new Date(),
26 minDate: new Date(2010, 0, 1) 26 minDate: new Date(2010, 0, 1)
27 }; 27 };
28 28
29 $scope.notaPedido = { 29 $scope.notaPedido = {
30 vendedor: {}, 30 vendedor: {},
31 cliente: {}, 31 cliente: {},
32 proveedor: {}, 32 proveedor: {},
33 domicilio: {dom: ''}, 33 domicilio: {dom: ''},
34 moneda: {}, 34 moneda: {},
35 cotizacion: {} 35 cotizacion: {}
36 }; 36 };
37 var monedaPorDefecto; 37 var monedaPorDefecto;
38 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 38 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
39 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { 39 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) {
40 monedaPorDefecto = { 40 monedaPorDefecto = {
41 id: res.data[0].ID, 41 id: res.data[0].ID,
42 detalle: res.data[0].DETALLE, 42 detalle: res.data[0].DETALLE,
43 simbolo: res.data[0].SIMBOLO, 43 simbolo: res.data[0].SIMBOLO,
44 cotizaciones: res.data[0].cotizaciones 44 cotizaciones: res.data[0].cotizaciones
45 }; 45 };
46 addCabecera('Moneda:', monedaPorDefecto.detalle); 46 addCabecera('Moneda:', monedaPorDefecto.detalle);
47 addCabecera('Fecha cotizacion:', 47 addCabecera('Fecha cotizacion:',
48 new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); 48 new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString());
49 addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION); 49 addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION);
50 $scope.notaPedido.moneda = monedaPorDefecto; 50 $scope.notaPedido.moneda = monedaPorDefecto;
51 $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; 51 $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0];
52 }); 52 });
53 53
54 $scope.cabecera = []; 54 $scope.cabecera = [];
55 $scope.showCabecera = true; 55 $scope.showCabecera = true;
56 56
57 $scope.now = new Date(); 57 $scope.now = new Date();
58 $scope.puntoVenta = Math.round(Math.random() * 10000); 58 $scope.puntoVenta = Math.round(Math.random() * 10000);
59 $scope.comprobante = Math.round(Math.random() * 1000000); 59 $scope.comprobante = Math.round(Math.random() * 1000000);
60 60
61 $scope.articulosTabla = []; 61 $scope.articulosTabla = [];
62 $scope.idLista = undefined; 62 $scope.idLista = undefined;
63 //La pantalla solo se usa para cargar pedidos 63 //La pantalla solo se usa para cargar pedidos
64 //var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); 64 //var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
65 65
66 crearNotaPedidoService.getPrecioCondicion().then( 66 crearNotaPedidoService.getPrecioCondicion().then(
67 function(res) { 67 function(res) {
68 $scope.precioCondiciones = res.data; 68 $scope.precioCondiciones = res.data;
69 } 69 }
70 ); 70 );
71 //La pantalla solo se usa para cargar pedidos 71 //La pantalla solo se usa para cargar pedidos
72 // if (notaPedidoTemp !== undefined) { 72 // if (notaPedidoTemp !== undefined) {
73 // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); 73 // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga);
74 // $scope.notaPedido = notaPedidoTemp; 74 // $scope.notaPedido = notaPedidoTemp;
75 // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); 75 // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString();
76 // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); 76 // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString();
77 // $scope.idLista = $scope.notaPedido.precioCondicion; 77 // $scope.idLista = $scope.notaPedido.precioCondicion;
78 // crearNotaPedidoService 78 // crearNotaPedidoService
79 // .getArticulosByIdNotaPedido($scope.notaPedido.id).then( 79 // .getArticulosByIdNotaPedido($scope.notaPedido.id).then(
80 // function(res) { 80 // function(res) {
81 // $scope.articulosTabla = res.data; 81 // $scope.articulosTabla = res.data;
82 // } 82 // }
83 // ); 83 // );
84 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO 84 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO
85 //(NO REQUERIDO EN ESTA VERSION) 85 //(NO REQUERIDO EN ESTA VERSION)
86 // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( 86 // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then(
87 // function(res) { 87 // function(res) {
88 // $scope.notaPedido.domicilio = res.data; 88 // $scope.notaPedido.domicilio = res.data;
89 // } 89 // }
90 // ); 90 // );
91 // } else { 91 // } else {
92 // $scope.notaPedido.fechaCarga = new Date(); 92 // $scope.notaPedido.fechaCarga = new Date();
93 // $scope.notaPedido.bomba = '0'; 93 // $scope.notaPedido.bomba = '0';
94 // $scope.notaPedido.flete = '0'; 94 // $scope.notaPedido.flete = '0';
95 // $scope.idLista = undefined; 95 // $scope.idLista = undefined;
96 // } 96 // }
97 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO 97 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO
98 // $scope.addNewDom = function() { 98 // $scope.addNewDom = function() {
99 // $scope.notaPedido.domicilio.push({ 'id': 0 }); 99 // $scope.notaPedido.domicilio.push({ 'id': 0 });
100 // }; 100 // };
101 // $scope.removeNewChoice = function(choice) { 101 // $scope.removeNewChoice = function(choice) {
102 // if ($scope.notaPedido.domicilio.length > 1) { 102 // if ($scope.notaPedido.domicilio.length > 1) {
103 // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( 103 // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(
104 // function(c) { 104 // function(c) {
105 // return c.$$hashKey === choice.$$hashKey; 105 // return c.$$hashKey === choice.$$hashKey;
106 // } 106 // }
107 // ), 1); 107 // ), 1);
108 // } 108 // }
109 // }; 109 // };
110 110
111 $scope.crearNotaPedido = function() { 111 $scope.crearNotaPedido = function() {
112 if(!$scope.notaPedido.vendedor.codigo) { 112 if(!$scope.notaPedido.vendedor.codigo) {
113 focaModalService.alert('Ingrese Vendedor'); 113 focaModalService.alert('Ingrese Vendedor');
114 return; 114 return;
115 } else if(!$scope.notaPedido.cliente.id) { 115 } else if(!$scope.notaPedido.cliente.id) {
116 focaModalService.alert('Ingrese Cliente'); 116 focaModalService.alert('Ingrese Cliente');
117 return; 117 return;
118 } else if(!$scope.notaPedido.proveedor.codigo) { 118 } else if(!$scope.notaPedido.proveedor.codigo) {
119 focaModalService.alert('Ingrese Proveedor'); 119 focaModalService.alert('Ingrese Proveedor');
120 return; 120 return;
121 } else if(!$scope.notaPedido.moneda.id) { 121 } else if(!$scope.notaPedido.moneda.id) {
122 focaModalService.alert('Ingrese Moneda'); 122 focaModalService.alert('Ingrese Moneda');
123 return; 123 return;
124 } else if(!$scope.notaPedido.cotizacion.ID) { 124 } else if(!$scope.notaPedido.cotizacion.ID) {
125 focaModalService.alert('Ingrese Cotización'); 125 focaModalService.alert('Ingrese Cotización');
126 return; 126 return;
127 } else if(!$scope.plazosPagos) { 127 } else if(!$scope.plazosPagos) {
128 focaModalService.alert('Ingrese Precios y Condiciones'); 128 focaModalService.alert('Ingrese Precios y Condiciones');
129 return; 129 return;
130 } else if(!$scope.notaPedido.flete) { 130 } else if(!$scope.notaPedido.flete) {
131 focaModalService.alert('Ingrese Flete'); 131 focaModalService.alert('Ingrese Flete');
132 return; 132 return;
133 } else if(!$scope.notaPedido.domicilio.id) { 133 } else if(!$scope.notaPedido.domicilio.id) {
134 focaModalService.aler('Ingrese Domicilio'); 134 focaModalService.aler('Ingrese Domicilio');
135 return; 135 return;
136 } else if($scope.articulosTabla.length === 0) { 136 } else if($scope.articulosTabla.length === 0) {
137 focaModalService.alert('Debe cargar al menos un articulo'); 137 focaModalService.alert('Debe cargar al menos un articulo');
138 return; 138 return;
139 } 139 }
140 var date = new Date(); 140 var date = new Date();
141 var notaPedido = { 141 var notaPedido = {
142 id: 0, 142 id: 0,
143 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) 143 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
144 .toISOString().slice(0, 19).replace('T', ' '), 144 .toISOString().slice(0, 19).replace('T', ' '),
145 idVendedor: $scope.notaPedido.vendedor.codigo, 145 idVendedor: $scope.notaPedido.vendedor.codigo,
146 idCliente: $scope.notaPedido.cliente.id, 146 idCliente: $scope.notaPedido.cliente.id,
147 idProveedor: $scope.notaPedido.proveedor.codigo, 147 idProveedor: $scope.notaPedido.proveedor.codigo,
148 idDomicilio: $scope.notaPedido.domicilio.id, 148 idDomicilio: $scope.notaPedido.domicilio.id,
149 idCotizacion: $scope.notaPedido.cotizacion.id, 149 idCotizacion: $scope.notaPedido.cotizacion.ID,
150 flete: $scope.notaPedido.flete ? 1 : 0, 150 flete: $scope.notaPedido.flete,
151 fob: $scope.notaPedido.fob ? 1 : 0, 151 fob: $scope.notaPedido.fob,
152 bomba: $scope.notaPedido.bomba ? 1 : 0, 152 bomba: $scope.notaPedido.bomba,
153 kilometros: $scope.notaPedido.kilometros, 153 kilometros: $scope.notaPedido.kilometros,
154 total: $scope.getTotal() 154 total: $scope.getTotal()
155 }; 155 };
156 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 156 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
157 function(data) { 157 function(data) {
158 158
159 var articulosNotaPedido = $scope.articulosTabla; 159 var articulosNotaPedido = $scope.articulosTabla;
160 for(var i = 0; i < articulosNotaPedido.length; i++) { 160 for(var i = 0; i < articulosNotaPedido.length; i++) {
161 delete articulosNotaPedido[i].editCantidad; 161 delete articulosNotaPedido[i].editCantidad;
162 delete articulosNotaPedido[i].editPrecio; 162 delete articulosNotaPedido[i].editPrecio;
163 articulosNotaPedido[i].idNotaPedido = data.data.id; 163 articulosNotaPedido[i].idNotaPedido = data.data.id;
164 crearNotaPedidoService 164 crearNotaPedidoService
165 .crearArticulosParaNotaPedido(articulosNotaPedido[i]); 165 .crearArticulosParaNotaPedido(articulosNotaPedido[i]);
166 } 166 }
167 var plazos = $scope.plazosPagos; 167 var plazos = $scope.plazosPagos;
168 for(var j = 0; j < plazos.length; j++) { 168 for(var j = 0; j < plazos.length; j++) {
169 var json = { 169 var json = {
170 idPedido: data.data.id, 170 idPedido: data.data.id,
171 dias: plazos[j].dias 171 dias: plazos[j].dias
172 }; 172 };
173 crearNotaPedidoService.crearPlazosParaNotaPedido(json); 173 crearNotaPedidoService.crearPlazosParaNotaPedido(json);
174 } 174 }
175 focaModalService.alert('Nota pedido creada'); 175 focaModalService.alert('Nota pedido creada');
176 $scope.cabecera = []; 176 $scope.cabecera = [];
177 addCabecera('Moneda:', $scope.notaPedido.moneda.detalle); 177 addCabecera('Moneda:', $scope.notaPedido.moneda.detalle);
178 addCabecera( 178 addCabecera(
179 'Fecha cotizacion:', 179 'Fecha cotizacion:',
180 $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') 180 $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy')
181 ); 181 );
182 addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.cotizacion); 182 addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.cotizacion);
183 $scope.notaPedido.vendedor = {}; 183 $scope.notaPedido.vendedor = {};
184 $scope.notaPedido.cliente = {}; 184 $scope.notaPedido.cliente = {};
185 $scope.notaPedido.proveedor = {}; 185 $scope.notaPedido.proveedor = {};
186 $scope.notaPedido.domicilio = {}; 186 $scope.notaPedido.domicilio = {};
187 $scope.notaPedido.flete = null; 187 $scope.notaPedido.flete = null;
188 $scope.notaPedido.fob = null; 188 $scope.notaPedido.fob = null;
189 $scope.notaPedido.bomba = null; 189 $scope.notaPedido.bomba = null;
190 $scope.notaPedido.kilometros = null; 190 $scope.notaPedido.kilometros = null;
191 $scope.articulosTabla = []; 191 $scope.articulosTabla = [];
192 } 192 }
193 ); 193 );
194 }; 194 };
195 195
196 $scope.seleccionarArticulo = function() { 196 $scope.seleccionarArticulo = function() {
197 if ($scope.idLista === undefined) { 197 if ($scope.idLista === undefined) {
198 focaModalService.alert( 198 focaModalService.alert(
199 'Primero seleccione una lista de precio y condicion'); 199 'Primero seleccione una lista de precio y condicion');
200 return; 200 return;
201 } 201 }
202 var modalInstance = $uibModal.open( 202 var modalInstance = $uibModal.open(
203 { 203 {
204 ariaLabelledBy: 'Busqueda de Productos', 204 ariaLabelledBy: 'Busqueda de Productos',
205 templateUrl: 'modal-busqueda-productos.html', 205 templateUrl: 'modal-busqueda-productos.html',
206 controller: 'modalBusquedaProductosCtrl', 206 controller: 'modalBusquedaProductosCtrl',
207 resolve: { 207 resolve: {
208 idLista: function() { return $scope.idLista; }, 208 idLista: function() { return $scope.idLista; },
209 cotizacion: $scope.notaPedido.cotizacion.COTIZACION 209 cotizacion: $scope.notaPedido.cotizacion.COTIZACION
210 }, 210 },
211 size: 'lg' 211 size: 'lg'
212 } 212 }
213 ); 213 );
214 modalInstance.result.then( 214 modalInstance.result.then(
215 function(producto) { 215 function(producto) {
216 var newArt = 216 var newArt =
217 { 217 {
218 id: 0, 218 id: 0,
219 codigo: producto.codigo, 219 codigo: producto.codigo,
220 sector: producto.sector, 220 sector: producto.sector,
221 sectorCodigo: producto.sector + '-' + producto.codigo, 221 sectorCodigo: producto.sector + '-' + producto.codigo,
222 descripcion: producto.descripcion, 222 descripcion: producto.descripcion,
223 item: $scope.articulosTabla.length + 1, 223 item: $scope.articulosTabla.length + 1,
224 nombre: producto.descripcion, 224 nombre: producto.descripcion,
225 precio: parseFloat(producto.precio.toFixed(2)), 225 precio: parseFloat(producto.precio.toFixed(2)),
226 costoUnitario: producto.costo, 226 costoUnitario: producto.costo,
227 editCantidad: false, 227 editCantidad: false,
228 editPrecio: false 228 editPrecio: false
229 }; 229 };
230 $scope.articuloACargar = newArt; 230 $scope.articuloACargar = newArt;
231 $scope.cargando = false; 231 $scope.cargando = false;
232 }, function() { 232 }, function() {
233 // funcion ejecutada cuando se cancela el modal 233 // funcion ejecutada cuando se cancela el modal
234 } 234 }
235 ); 235 );
236 }; 236 };
237 237
238 $scope.seleccionarVendedor = function() { 238 $scope.seleccionarVendedor = function() {
239 var modalInstance = $uibModal.open( 239 var modalInstance = $uibModal.open(
240 { 240 {
241 ariaLabelledBy: 'Busqueda de Vendedores', 241 ariaLabelledBy: 'Busqueda de Vendedores',
242 templateUrl: 'modal-vendedores.html', 242 templateUrl: 'modal-vendedores.html',
243 controller: 'modalVendedoresCtrl', 243 controller: 'modalVendedoresCtrl',
244 size: 'lg' 244 size: 'lg'
245 } 245 }
246 ); 246 );
247 modalInstance.result.then( 247 modalInstance.result.then(
248 function(vendedor) { 248 function(vendedor) {
249 addCabecera('Vendedor:', vendedor.NomVen); 249 addCabecera('Vendedor:', vendedor.NomVen);
250 $scope.notaPedido.vendedor.codigo = vendedor.CodVen; 250 $scope.notaPedido.vendedor.codigo = vendedor.CodVen;
251 }, function() { 251 }, function() {
252 252
253 } 253 }
254 ); 254 );
255 }; 255 };
256 256
257 $scope.seleccionarProveedor = function() { 257 $scope.seleccionarProveedor = function() {
258 var modalInstance = $uibModal.open( 258 var modalInstance = $uibModal.open(
259 { 259 {
260 ariaLabelledBy: 'Busqueda de Proveedor', 260 ariaLabelledBy: 'Busqueda de Proveedor',
261 templateUrl: 'modal-proveedor.html', 261 templateUrl: 'modal-proveedor.html',
262 controller: 'focaModalProveedorCtrl', 262 controller: 'focaModalProveedorCtrl',
263 size: 'lg' 263 size: 'lg'
264 } 264 }
265 ); 265 );
266 modalInstance.result.then( 266 modalInstance.result.then(
267 function(proveedor) { 267 function(proveedor) {
268 $scope.notaPedido.proveedor.codigo = proveedor.COD; 268 $scope.notaPedido.proveedor.codigo = proveedor.COD;
269 addCabecera('Proveedor:', proveedor.NOM); 269 addCabecera('Proveedor:', proveedor.NOM);
270 }, function() { 270 }, function() {
271 271
272 } 272 }
273 ); 273 );
274 }; 274 };
275 275
276 $scope.seleccionarCliente = function() { 276 $scope.seleccionarCliente = function() {
277 277
278 var modalInstance = $uibModal.open( 278 var modalInstance = $uibModal.open(
279 { 279 {
280 ariaLabelledBy: 'Busqueda de Cliente', 280 ariaLabelledBy: 'Busqueda de Cliente',
281 templateUrl: 'foca-busqueda-cliente-modal.html', 281 templateUrl: 'foca-busqueda-cliente-modal.html',
282 controller: 'focaBusquedaClienteModalController', 282 controller: 'focaBusquedaClienteModalController',
283 size: 'lg' 283 size: 'lg'
284 } 284 }
285 ); 285 );
286 modalInstance.result.then( 286 modalInstance.result.then(
287 function(cliente) { 287 function(cliente) {
288 crearNotaPedidoService.getDomiciliosByIdCliente(cliente.cod).then( 288 crearNotaPedidoService.getDomiciliosByIdCliente(cliente.cod).then(
289 function(data) { 289 function(data) {
290 if(data.data.length === 0){ 290 if(data.data.length === 0){
291 focaModalService 291 focaModalService
292 .alert('El cliente no tienen domicilios de entrega') 292 .alert('El cliente no tienen domicilios de entrega')
293 .then( 293 .then(
294 function() { 294 function() {
295 $scope.seleccionarCliente(); 295 $scope.seleccionarCliente();
296 } 296 }
297 ); 297 );
298 return; 298 return;
299 } 299 }
300 $scope.abrirModalDomicilios(cliente); 300 $scope.abrirModalDomicilios(cliente);
301 } 301 }
302 ); 302 );
303 }, function() { 303 }, function() {
304 304
305 } 305 }
306 ); 306 );
307 }; 307 };
308 308
309 $scope.abrirModalDomicilios = function(cliente) { 309 $scope.abrirModalDomicilios = function(cliente) {
310 var modalInstanceDomicilio = $uibModal.open( 310 var modalInstanceDomicilio = $uibModal.open(
311 { 311 {
312 ariaLabelledBy: 'Busqueda de Domicilios', 312 ariaLabelledBy: 'Busqueda de Domicilios',
313 templateUrl: 'modal-domicilio.html', 313 templateUrl: 'modal-domicilio.html',
314 controller: 'focaModalDomicilioController', 314 controller: 'focaModalDomicilioController',
315 resolve: { idCliente: function() { return cliente.cod; }}, 315 resolve: { idCliente: function() { return cliente.cod; }},
316 size: 'lg', 316 size: 'lg',
317 } 317 }
318 ); 318 );
319 modalInstanceDomicilio.result.then( 319 modalInstanceDomicilio.result.then(
320 function(domicilio) { 320 function(domicilio) {
321 $scope.notaPedido.domicilio.id = domicilio.id; 321 $scope.notaPedido.domicilio.id = domicilio.id;
322 $scope.notaPedido.cliente.id = cliente.cod; 322 $scope.notaPedido.cliente.id = cliente.cod;
323 addCabecera('Cliente:', cliente.nom); 323 addCabecera('Cliente:', cliente.nom);
324 addCabecera('Domicilio:', domicilio.dom); 324 addCabecera('Domicilio:', domicilio.dom);
325 }, function() { 325 }, function() {
326 $scope.seleccionarCliente(); 326 $scope.seleccionarCliente();
327 return; 327 return;
328 } 328 }
329 ); 329 );
330 }; 330 };
331 331
332 $scope.mostrarFichaCliente = function() { 332 $scope.mostrarFichaCliente = function() {
333 $uibModal.open( 333 $uibModal.open(
334 { 334 {
335 ariaLabelledBy: 'Datos del Cliente', 335 ariaLabelledBy: 'Datos del Cliente',
336 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', 336 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html',
337 controller: 'focaCrearNotaPedidoFichaClienteController', 337 controller: 'focaCrearNotaPedidoFichaClienteController',
338 size: 'lg' 338 size: 'lg'
339 } 339 }
340 ); 340 );
341 }; 341 };
342 342
343 $scope.getTotal = function() { 343 $scope.getTotal = function() {
344 var total = 0; 344 var total = 0;
345 var arrayTempArticulos = $scope.articulosTabla; 345 var arrayTempArticulos = $scope.articulosTabla;
346 for (var i = 0; i < arrayTempArticulos.length; i++) { 346 for (var i = 0; i < arrayTempArticulos.length; i++) {
347 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 347 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
348 } 348 }
349 return parseFloat(total.toFixed(2)); 349 return parseFloat(total.toFixed(2));
350 }; 350 };
351 351
352 $scope.getSubTotal = function() { 352 $scope.getSubTotal = function() {
353 if($scope.articuloACargar) { 353 if($scope.articuloACargar) {
354 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 354 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
355 } 355 }
356 }; 356 };
357 357
358 $scope.abrirModalListaPrecio = function() { 358 $scope.abrirModalListaPrecio = function() {
359 var modalInstance = $uibModal.open( 359 var modalInstance = $uibModal.open(
360 { 360 {
361 ariaLabelledBy: 'Busqueda de Precio Condición', 361 ariaLabelledBy: 'Busqueda de Precio Condición',
362 templateUrl: 'modal-precio-condicion.html', 362 templateUrl: 'modal-precio-condicion.html',
363 controller: 'focaModalPrecioCondicionController', 363 controller: 'focaModalPrecioCondicionController',
364 size: 'lg' 364 size: 'lg'
365 } 365 }
366 ); 366 );
367 modalInstance.result.then( 367 modalInstance.result.then(
368 function(precioCondicion) { 368 function(precioCondicion) {
369 var cabecera = ''; 369 var cabecera = '';
370 var plazosConcat = ''; 370 var plazosConcat = '';
371 if(!Array.isArray(precioCondicion)) { 371 if(!Array.isArray(precioCondicion)) {
372 $scope.plazosPagos = precioCondicion.plazoPago; 372 $scope.plazosPagos = precioCondicion.plazoPago;
373 $scope.idLista = precioCondicion.idListaPrecio; 373 $scope.idLista = precioCondicion.idListaPrecio;
374 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 374 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
375 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 375 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
376 } 376 }
377 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); 377 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim();
378 } else { //Cuando se ingresan los plazos manualmente 378 } else { //Cuando se ingresan los plazos manualmente
379 $scope.idLista = -1; //-1, el modal productos busca todos los productos 379 $scope.idLista = -1; //-1, el modal productos busca todos los productos
380 $scope.plazosPagos = precioCondicion; 380 $scope.plazosPagos = precioCondicion;
381 for(var j = 0; j < precioCondicion.length; j++) { 381 for(var j = 0; j < precioCondicion.length; j++) {
382 plazosConcat += precioCondicion[j].dias + ' '; 382 plazosConcat += precioCondicion[j].dias + ' ';
383 } 383 }
384 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 384 cabecera = 'Ingreso manual ' + plazosConcat.trim();
385 } 385 }
386 $scope.articulosTabla = []; 386 $scope.articulosTabla = [];
387 addCabecera('Precios y condiciones:', cabecera); 387 addCabecera('Precios y condiciones:', cabecera);
388 }, function() { 388 }, function() {
389 389
390 } 390 }
391 ); 391 );
392 }; 392 };
393 393
394 $scope.abrirModalFlete = function() { 394 $scope.abrirModalFlete = function() {
395 var modalInstance = $uibModal.open( 395 var modalInstance = $uibModal.open(
396 { 396 {
397 ariaLabelledBy: 'Busqueda de Flete', 397 ariaLabelledBy: 'Busqueda de Flete',
398 templateUrl: 'modal-flete.html', 398 templateUrl: 'modal-flete.html',
399 controller: 'focaModalFleteController', 399 controller: 'focaModalFleteController',
400 size: 'lg', 400 size: 'lg',
401 resolve: { 401 resolve: {
402 parametrosFlete: 402 parametrosFlete:
403 function() { 403 function() {
404 return { 404 return {
405 flete: $scope.notaPedido.flete ? '1' : 405 flete: $scope.notaPedido.flete ? '1' :
406 ($scope.notaPedido.fob ? 'FOB' : 406 ($scope.notaPedido.fob ? 'FOB' :
407 ($scope.notaPedido.flete === undefined ? null : '0')), 407 ($scope.notaPedido.flete === undefined ? null : '0')),
408 bomba: $scope.notaPedido.bomba ? '1' : 408 bomba: $scope.notaPedido.bomba ? '1' :
409 ($scope.notaPedido.bomba === undefined ? null : '0'), 409 ($scope.notaPedido.bomba === undefined ? null : '0'),
410 kilometros: $scope.notaPedido.kilometros 410 kilometros: $scope.notaPedido.kilometros
411 }; 411 };
412 } 412 }
413 } 413 }
414 } 414 }
415 ); 415 );
416 modalInstance.result.then( 416 modalInstance.result.then(
417 function(datos) { 417 function(datos) {
418 $scope.notaPedido.flete = datos.flete; 418 $scope.notaPedido.flete = datos.flete;
419 $scope.notaPedido.fob = datos.FOB; 419 $scope.notaPedido.fob = datos.FOB;
420 $scope.notaPedido.bomba = datos.bomba; 420 $scope.notaPedido.bomba = datos.bomba;
421 $scope.notaPedido.kilometros = datos.kilometros; 421 $scope.notaPedido.kilometros = datos.kilometros;
422 422
423 addCabecera('Flete:', datos.flete ? 'Si' : 423 addCabecera('Flete:', datos.flete ? 'Si' :
424 ($scope.notaPedido.fob ? 'FOB' : 'No')); 424 ($scope.notaPedido.fob ? 'FOB' : 'No'));
425 if(datos.flete) { 425 if(datos.flete) {
426 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); 426 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No');
427 addCabecera('Kilometros:', datos.kilometros ? 'Si' : 'No'); 427 addCabecera('Kilometros:', datos.kilometros ? 'Si' : 'No');
428 } else { 428 } else {
429 removeCabecera('Bomba:'); 429 removeCabecera('Bomba:');
430 removeCabecera('Kilometros:'); 430 removeCabecera('Kilometros:');
431 $scope.notaPedido.fob = false; 431 $scope.notaPedido.fob = false;
432 $scope.notaPedido.bomba = false; 432 $scope.notaPedido.bomba = false;
433 $scope.notaPedido.kilometros = null; 433 $scope.notaPedido.kilometros = null;
434 } 434 }
435 }, function() { 435 }, function() {
436 436
437 } 437 }
438 ); 438 );
439 }; 439 };
440 440
441 $scope.abrirModalMoneda = function() { 441 $scope.abrirModalMoneda = function() {
442 var modalInstance = $uibModal.open( 442 var modalInstance = $uibModal.open(
443 { 443 {
444 ariaLabelledBy: 'Busqueda de Moneda', 444 ariaLabelledBy: 'Busqueda de Moneda',
445 templateUrl: 'modal-moneda.html', 445 templateUrl: 'modal-moneda.html',
446 controller: 'focaModalMonedaController', 446 controller: 'focaModalMonedaController',
447 size: 'lg' 447 size: 'lg'
448 } 448 }
449 ); 449 );
450 modalInstance.result.then( 450 modalInstance.result.then(
451 function(moneda) { 451 function(moneda) {
452 $scope.abrirModalCotizacion(moneda); 452 $scope.abrirModalCotizacion(moneda);
453 }, function() { 453 }, function() {
454 454
455 } 455 }
456 ); 456 );
457 }; 457 };
458 458
459 $scope.abrirModalCotizacion = function(moneda) { 459 $scope.abrirModalCotizacion = function(moneda) {
460 var modalInstance = $uibModal.open( 460 var modalInstance = $uibModal.open(
461 { 461 {
462 ariaLabelledBy: 'Busqueda de Cotización', 462 ariaLabelledBy: 'Busqueda de Cotización',
463 templateUrl: 'modal-cotizacion.html', 463 templateUrl: 'modal-cotizacion.html',
464 controller: 'focaModalCotizacionController', 464 controller: 'focaModalCotizacionController',
465 size: 'lg', 465 size: 'lg',
466 resolve: {idMoneda: function() {return moneda.ID;}} 466 resolve: {idMoneda: function() {return moneda.ID;}}
467 } 467 }
468 ); 468 );
469 modalInstance.result.then( 469 modalInstance.result.then(
470 function(cotizacion) { 470 function(cotizacion) {
471 var articulosTablaTemp = $scope.articulosTabla; 471 var articulosTablaTemp = $scope.articulosTabla;
472 for(var i = 0; i < articulosTablaTemp.length; i++) { 472 for(var i = 0; i < articulosTablaTemp.length; i++) {
473 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 473 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
474 $scope.notaPedido.cotizacion.COTIZACION; 474 $scope.notaPedido.cotizacion.COTIZACION;
475 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 475 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
476 cotizacion.COTIZACION; 476 cotizacion.COTIZACION;
477 } 477 }
478 $scope.articulosTabla = articulosTablaTemp; 478 $scope.articulosTabla = articulosTablaTemp;
479 $scope.notaPedido.moneda = { 479 $scope.notaPedido.moneda = {
480 id: moneda.ID, 480 id: moneda.ID,
481 detalle: moneda.DETALLE, 481 detalle: moneda.DETALLE,
482 simbolo: moneda.SIMBOLO 482 simbolo: moneda.SIMBOLO
483 }; 483 };
484 $scope.notaPedido.cotizacion = { 484 $scope.notaPedido.cotizacion = {
485 ID: cotizacion.ID, 485 ID: cotizacion.ID,
486 COTIZACION: cotizacion.COTIZACION, 486 COTIZACION: cotizacion.COTIZACION,
487 FECHA: cotizacion.fecha 487 FECHA: cotizacion.fecha
488 }; 488 };
489 addCabecera('Moneda:', moneda.DETALLE); 489 addCabecera('Moneda:', moneda.DETALLE);
490 addCabecera( 490 addCabecera(
491 'Fecha cotizacion:', 491 'Fecha cotizacion:',
492 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 492 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
493 ); 493 );
494 addCabecera('Cotizacion:', cotizacion.COTIZACION); 494 addCabecera('Cotizacion:', cotizacion.COTIZACION);
495 }, function() { 495 }, function() {
496 496
497 } 497 }
498 ); 498 );
499 }; 499 };
500 500
501 $scope.agregarATabla = function(key) { 501 $scope.agregarATabla = function(key) {
502 if(key === 13) { 502 if(key === 13) {
503 if($scope.articuloACargar.cantidad === undefined || 503 if($scope.articuloACargar.cantidad === undefined ||
504 $scope.articuloACargar.cantidad === 0 || 504 $scope.articuloACargar.cantidad === 0 ||
505 $scope.articuloACargar.cantidad === null ){ 505 $scope.articuloACargar.cantidad === null ){
506 focaModalService.alert('El valor debe ser al menos 1'); 506 focaModalService.alert('El valor debe ser al menos 1');
507 return; 507 return;
508 } 508 }
509 delete $scope.articuloACargar.sectorCodigo; 509 delete $scope.articuloACargar.sectorCodigo;
510 $scope.articulosTabla.push($scope.articuloACargar); 510 $scope.articulosTabla.push($scope.articuloACargar);
511 $scope.cargando = true; 511 $scope.cargando = true;
512 } 512 }
513 }; 513 };
514 514
515 $scope.quitarArticulo = function(key) { 515 $scope.quitarArticulo = function(key) {
516 $scope.articulosTabla.splice(key, 1); 516 $scope.articulosTabla.splice(key, 1);
517 }; 517 };
518 518
519 $scope.editarArticulo = function(key, articulo) { 519 $scope.editarArticulo = function(key, articulo) {
520 if(key === 13) { 520 if(key === 13) {
521 if(articulo.cantidad === null || articulo.cantidad === 0 || 521 if(articulo.cantidad === null || articulo.cantidad === 0 ||
522 articulo.cantidad === undefined){ 522 articulo.cantidad === undefined){
523 focaModalService.alert('El valor debe ser al menos 1'); 523 focaModalService.alert('El valor debe ser al menos 1');
524 return; 524 return;
525 } 525 }
526 articulo.editCantidad = false; 526 articulo.editCantidad = false;
527 articulo.editPrecio = false; 527 articulo.editPrecio = false;
528 } 528 }
529 }; 529 };
530 530
531 $scope.cambioEdit = function(articulo, propiedad) { 531 $scope.cambioEdit = function(articulo, propiedad) {
532 if(propiedad === 'cantidad') { 532 if(propiedad === 'cantidad') {
533 articulo.editCantidad = true; 533 articulo.editCantidad = true;
534 } else if(propiedad === 'precio') { 534 } else if(propiedad === 'precio') {
535 articulo.editPrecio = true; 535 articulo.editPrecio = true;
536 } 536 }
537 }; 537 };
538 538
539 $scope.limpiarFlete = function() { 539 $scope.limpiarFlete = function() {
540 $scope.notaPedido.fleteNombre = ''; 540 $scope.notaPedido.fleteNombre = '';
541 $scope.notaPedido.chofer = ''; 541 $scope.notaPedido.chofer = '';
542 $scope.notaPedido.vehiculo = ''; 542 $scope.notaPedido.vehiculo = '';
543 $scope.notaPedido.kilometros = ''; 543 $scope.notaPedido.kilometros = '';
544 $scope.notaPedido.costoUnitarioKmFlete = ''; 544 $scope.notaPedido.costoUnitarioKmFlete = '';
545 $scope.choferes = ''; 545 $scope.choferes = '';
546 $scope.vehiculos = ''; 546 $scope.vehiculos = '';
547 }; 547 };
548 548
549 $scope.limpiarPantalla = function() { 549 $scope.limpiarPantalla = function() {
550 $scope.limpiarFlete(); 550 $scope.limpiarFlete();
551 $scope.notaPedido.flete = '0'; 551 $scope.notaPedido.flete = '0';
552 $scope.notaPedido.bomba = '0'; 552 $scope.notaPedido.bomba = '0';
553 $scope.notaPedido.precioCondicion = ''; 553 $scope.notaPedido.precioCondicion = '';
554 $scope.articulosTabla = []; 554 $scope.articulosTabla = [];
555 $scope.notaPedido.vendedor.nombre = ''; 555 $scope.notaPedido.vendedor.nombre = '';
556 $scope.notaPedido.cliente = {nombre: ''}; 556 $scope.notaPedido.cliente = {nombre: ''};
557 $scope.notaPedido.domicilio = {dom: ''}; 557 $scope.notaPedido.domicilio = {dom: ''};
558 $scope.domiciliosCliente = []; 558 $scope.domiciliosCliente = [];
559 }; 559 };
560 560
561 $scope.resetFilter = function() { 561 $scope.resetFilter = function() {
562 $scope.articuloACargar = {}; 562 $scope.articuloACargar = {};
563 $scope.cargando = true; 563 $scope.cargando = true;
564 }; 564 };
565 565
566 $scope.selectFocus = function($event) { 566 $scope.selectFocus = function($event) {
567 $event.target.select(); 567 $event.target.select();
568 }; 568 };
569 569
570 $scope.salir = function() { 570 $scope.salir = function() {
571 $location.path('/'); 571 $location.path('/');
572 }; 572 };
573 573
574 function addCabecera(label, valor) { 574 function addCabecera(label, valor) {
575 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 575 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
576 if(propiedad.length === 1) { 576 if(propiedad.length === 1) {
577 propiedad[0].valor = valor; 577 propiedad[0].valor = valor;
578 } else { 578 } else {
579 $scope.cabecera.push({label: label, valor: valor}); 579 $scope.cabecera.push({label: label, valor: valor});
580 } 580 }
581 } 581 }
582 582
583 function removeCabecera(label) { 583 function removeCabecera(label) {
584 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 584 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
585 if(propiedad.length === 1){ 585 if(propiedad.length === 1){
586 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); 586 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1);
587 } 587 }
588 } 588 }
589 } 589 }
590 ] 590 ]
591 ) 591 )
592 .controller('notaPedidoListaCtrl', [ 592 .controller('notaPedidoListaCtrl', [
593 '$scope', 593 '$scope',
594 'crearNotaPedidoService', 594 'crearNotaPedidoService',
595 '$location', 595 '$location',
596 function($scope, crearNotaPedidoService, $location) { 596 function($scope, crearNotaPedidoService, $location) {
597 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 597 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
598 $scope.notaPedidos = datos.data; 598 $scope.notaPedidos = datos.data;
599 }); 599 });
600 $scope.editar = function(notaPedido) { 600 $scope.editar = function(notaPedido) {
601 crearNotaPedidoService.setNotaPedido(notaPedido); 601 crearNotaPedidoService.setNotaPedido(notaPedido);
602 $location.path('/venta-nota-pedido/abm/'); 602 $location.path('/venta-nota-pedido/abm/');
603 }; 603 };
604 $scope.crearPedido = function() { 604 $scope.crearPedido = function() {
605 crearNotaPedidoService.clearNotaPedido(); 605 crearNotaPedidoService.clearNotaPedido();
606 $location.path('/venta-nota-pedido/abm/'); 606 $location.path('/venta-nota-pedido/abm/');
607 }; 607 };
608 } 608 }
609 ]) 609 ])
610 .controller('focaCrearNotaPedidoFichaClienteController', [ 610 .controller('focaCrearNotaPedidoFichaClienteController', [
611 '$scope', 611 '$scope',
612 'crearNotaPedidoService', 612 'crearNotaPedidoService',
613 '$location', 613 '$location',
614 function($scope, crearNotaPedidoService, $location) { 614 function($scope, crearNotaPedidoService, $location) {
615 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 615 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
616 $scope.notaPedidos = datos.data; 616 $scope.notaPedidos = datos.data;
617 }); 617 });
618 $scope.editar = function(notaPedido) { 618 $scope.editar = function(notaPedido) {
619 crearNotaPedidoService.setNotaPedido(notaPedido); 619 crearNotaPedidoService.setNotaPedido(notaPedido);
620 $location.path('/venta-nota-pedido/abm/'); 620 $location.path('/venta-nota-pedido/abm/');
621 }; 621 };
622 $scope.crearPedido = function() { 622 $scope.crearPedido = function() {
623 crearNotaPedidoService.clearNotaPedido(); 623 crearNotaPedidoService.clearNotaPedido();
624 $location.path('/venta-nota-pedido/abm/'); 624 $location.path('/venta-nota-pedido/abm/');
625 }; 625 };
626 } 626 }
627 ]); 627 ]);
628 628