Commit 276bdb44c815ffbd7d738c7c9d6b983c30972990

Authored by Eric Fernandez
1 parent 1525e781c8
Exists in master

cargo domicilio

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