Commit 8f25127247e77e8019507cfe6fde9b88a4a75a42

Authored by Nicolás Guarnieri
1 parent aff6290492
Exists in master and in 1 other branch develop

fix nota de pedido

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