Commit 0e6b5fe45b211d846e7650c2d276e0d4c2b335fd

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master (pmarco)

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