Commit f66f5562a8b3185a6fc4c50e599349b007a57214

Authored by Nicolás Guarnieri
Exists in master

Merge branch 'master' into 'master'

guardar idremito en numero pedido

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