Commit ae30a41553c1af3d0397c5a89d4f9de5ef1f0940

Authored by Marcelo Puebla
1 parent 2de32ead93
Exists in master

Cambio el vendedor se saca del mismo cliente seleccionado, ya no hay modal para …

…elegir vendedor primero
Showing 2 changed files with 55 additions and 94 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', '$timeout', 3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout',
4 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService', 4 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService',
5 '$localStorage', 5 '$localStorage',
6 function ( 6 function (
7 $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService, 7 $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService,
8 remitoBusinessService, $rootScope, focaBotoneraLateralService, $localStorage) { 8 remitoBusinessService, $rootScope, focaBotoneraLateralService, $localStorage) {
9 config(); 9 config();
10 10
11 var cotizacionPArgentino = {}; 11 var cotizacionPArgentino = {};
12 12
13 function config() { 13 function config() {
14 $scope.tmpCantidad = Number; 14 $scope.tmpCantidad = Number;
15 $scope.tmpPrecio = Number; 15 $scope.tmpPrecio = Number;
16 $scope.botonera = crearRemitoService.getBotonera(); 16 $scope.botonera = crearRemitoService.getBotonera();
17 $scope.isNumber = angular.isNumber; 17 $scope.isNumber = angular.isNumber;
18 $scope.datepickerAbierto = false; 18 $scope.datepickerAbierto = false;
19 $scope.show = false; 19 $scope.show = false;
20 $scope.cargando = true; 20 $scope.cargando = true;
21 $scope.now = new Date(); 21 $scope.now = new Date();
22 $scope.puntoVenta = rellenar(0, 4); 22 $scope.puntoVenta = rellenar(0, 4);
23 $scope.comprobante = rellenar(0, 8); 23 $scope.comprobante = rellenar(0, 8);
24 $scope.dateOptions = { 24 $scope.dateOptions = {
25 maxDate: new Date(), 25 maxDate: new Date(),
26 minDate: new Date(2010, 0, 1) 26 minDate: new Date(2010, 0, 1)
27 }; 27 };
28 28
29
30 crearRemitoService.getParametros().then(function (res) { 29 crearRemitoService.getParametros().then(function (res) {
31 var parametros = JSON.parse(res.data[0].jsonText); 30 var parametros = JSON.parse(res.data[0].jsonText);
32 if ($localStorage.remito) { 31 if ($localStorage.remito) {
33 $timeout(function () { getLSRemito(); }); 32 $timeout(function () { getLSRemito(); });
34 } else { 33 } else {
35 for (var property in parametros) { 34 for (var property in parametros) {
36 $scope.remito[property] = parametros[property]; 35 $scope.remito[property] = parametros[property];
37 $scope.inicial[property] = parametros[property]; 36 $scope.inicial[property] = parametros[property];
38 } 37 }
39 setearRemito($scope.remito); 38 setearRemito($scope.remito);
39 $scope.remitoIsDirty = true;
40 } 40 }
41 }); 41 });
42 42
43 //SETEO BOTONERA LATERAL 43 //SETEO BOTONERA LATERAL
44 $timeout(function () { 44 $timeout(function () {
45 focaBotoneraLateralService.showSalir(false); 45 focaBotoneraLateralService.showSalir(false);
46 focaBotoneraLateralService.showPausar(true); 46 focaBotoneraLateralService.showPausar(true);
47 focaBotoneraLateralService.showGuardar(true, $scope.crearRemito); 47 focaBotoneraLateralService.showGuardar(true, $scope.crearRemito);
48 focaBotoneraLateralService.addCustomButton('Salir', salir); 48 focaBotoneraLateralService.addCustomButton('Salir', salir);
49 }); 49 });
50 50
51 init(); 51 init();
52 52
53 } 53 }
54 54
55 function init() { 55 function init() {
56 $scope.$broadcast('cleanCabecera'); 56 $scope.$broadcast('cleanCabecera');
57 $scope.remitoIsDirty = false;
58 $scope.remito = { 57 $scope.remito = {
59 id: 0, 58 id: 0,
60 estado: 0, 59 estado: 0,
61 vendedor: {}, 60 vendedor: {},
62 cliente: {}, 61 cliente: {},
63 proveedor: {}, 62 proveedor: {},
64 domicilio: { dom: '' }, 63 domicilio: { dom: '' },
65 moneda: {}, 64 moneda: {},
66 cotizacion: $scope.cotizacionPorDefecto || {}, 65 cotizacion: $scope.cotizacionPorDefecto || {},
67 articulosRemito: [] 66 articulosRemito: []
68 }; 67 };
69 68
70 $scope.notaPedido = { 69 $scope.notaPedido = {
71 id: 0 70 id: 0
72 }; 71 };
73 72
74 $scope.remito.articulosRemito = []; 73 $scope.remito.articulosRemito = [];
75 $scope.idLista = undefined; 74 $scope.idLista = undefined;
76 75
77 crearRemitoService.getNumeroRemito().then( 76 crearRemitoService.getNumeroRemito().then(
78 function (res) { 77 function (res) {
79 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 78 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
80 $scope.comprobante = rellenar(res.data.numeroRemito, 8); 79 $scope.comprobante = rellenar(res.data.numeroRemito, 8);
81 }, 80 },
82 function (err) { 81 function (err) {
83 focaModalService.alert('La terminal no esta configurada correctamente'); 82 focaModalService.alert('La terminal no esta configurada correctamente');
84 console.info(err); 83 console.info(err);
85 } 84 }
86 ); 85 );
87 86
88 $scope.inicial = angular.copy($scope.remito); 87 $scope.inicial = angular.copy($scope.remito);
89 } 88 }
90 89
91 $scope.$watch('remito', function (newValue) { 90 $scope.$watch('remito', function (newValue) {
92 focaBotoneraLateralService.setPausarData({ 91 focaBotoneraLateralService.setPausarData({
93 label: 'remito', 92 label: 'remito',
94 val: newValue 93 val: newValue
95 }); 94 });
96 }, true); 95 }, true);
97 96
98 $scope.seleccionarNotaPedido = function () { 97 $scope.seleccionarNotaPedido = function () {
99 if ($scope.remitoIsDirty) { 98 if ($scope.remitoIsDirty) {
100 focaModalService.confirm("¿Desea continuar? Se perderan los cambios") 99 focaModalService.confirm("¿Desea continuar? Se perderan los cambios")
101 .then(function () { 100 .then(function () {
102 $scope.getNotaPedidoModal(); 101 $scope.getNotaPedidoModal();
103 }); 102 });
104 } else { 103 } else {
105 $scope.getNotaPedidoModal() 104 $scope.getNotaPedidoModal()
106 } 105 }
107 } 106 }
108 107
109 $scope.getNotaPedidoModal = function () { 108 $scope.getNotaPedidoModal = function () {
110 if (varlidarRemitoFacturado()) { 109 if (varlidarRemitoFacturado()) {
111 var modalInstance = $uibModal.open( 110 var modalInstance = $uibModal.open(
112 { 111 {
113 ariaLabelledBy: 'Busqueda de Nota de Pedido', 112 ariaLabelledBy: 'Busqueda de Nota de Pedido',
114 templateUrl: 'foca-modal-nota-pedido.html', 113 templateUrl: 'foca-modal-nota-pedido.html',
115 controller: 'focaModalNotaPedidoController', 114 controller: 'focaModalNotaPedidoController',
116 size: 'lg', 115 size: 'lg',
117 resolve: { 116 resolve: {
118 usadoPor: function () { return 'remito'; }, 117 usadoPor: function () { return 'remito'; },
119 idVendedor: function () { return null; } 118 idVendedor: function () { return null; }
120 } 119 }
121 } 120 }
122 ); 121 );
123 modalInstance.result.then( 122 modalInstance.result.then(
124 function (notaPedido) { 123 function (notaPedido) {
125 //añado cabeceras 124 //añado cabeceras
126 $scope.remitoIsDirty = true; 125 $scope.remitoIsDirty = true;
127 $scope.notaPedido.id = notaPedido.id; 126 $scope.notaPedido.id = notaPedido.id;
128 $scope.$broadcast('removeCabecera', 'Bomba:'); 127 $scope.$broadcast('removeCabecera', 'Bomba:');
129 $scope.$broadcast('removeCabecera', 'Kilometros:'); 128 $scope.$broadcast('removeCabecera', 'Kilometros:');
130 var puntosDescarga = []; 129 var puntosDescarga = [];
131 notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedido) { 130 notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedido) {
132 puntosDescarga.push(notaPedido.puntoDescarga); 131 puntosDescarga.push(notaPedido.puntoDescarga);
133 }); 132 });
134 var cabeceras = [ 133 var cabeceras = [
135 { 134 {
136 label: 'Moneda:', 135 label: 'Moneda:',
137 valor: notaPedido.cotizacion.moneda.DETALLE 136 valor: notaPedido.cotizacion.moneda.DETALLE
138 }, 137 },
139 { 138 {
140 label: 'Fecha cotizacion:', 139 label: 'Fecha cotizacion:',
141 valor: $filter('date')(notaPedido.cotizacion.FECHA, 140 valor: $filter('date')(notaPedido.cotizacion.FECHA,
142 'dd/MM/yyyy') 141 'dd/MM/yyyy')
143 }, 142 },
144 { 143 {
145 label: 'Cotizacion:', 144 label: 'Cotizacion:',
146 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, 145 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR,
147 '2') 146 '2')
148 }, 147 },
149 { 148 {
150 label: 'Cliente:', 149 label: 'Cliente:',
151 valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) + 150 valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) +
152 ' - ' + notaPedido.cliente.NOM 151 ' - ' + notaPedido.cliente.NOM
153 }, 152 },
154 { 153 {
155 label: 'Domicilio:', 154 label: 'Domicilio:',
156 valor: notaPedido.domicilioStamp 155 valor: notaPedido.domicilioStamp
157 }, 156 },
158 { 157 {
159 label: 'Vendedor:', 158 label: 'Vendedor:',
160 valor: $filter('rellenarDigitos')( 159 valor: $filter('rellenarDigitos')(
161 notaPedido.vendedor.NUM, 3 160 notaPedido.vendedor.NUM, 3
162 ) + ' - ' + notaPedido.vendedor.NOM 161 ) + ' - ' + notaPedido.vendedor.NOM
163 }, 162 },
164 { 163 {
165 label: 'Proveedor:', 164 label: 'Proveedor:',
166 valor: $filter('rellenarDigitos') 165 valor: $filter('rellenarDigitos')
167 (notaPedido.proveedor.COD, 5) + ' - ' + 166 (notaPedido.proveedor.COD, 5) + ' - ' +
168 notaPedido.proveedor.NOM 167 notaPedido.proveedor.NOM
169 }, 168 },
170 { 169 {
171 label: 'Precio condicion:', 170 label: 'Precio condicion:',
172 valor: valorPrecioCondicion() + ' ' + 171 valor: valorPrecioCondicion() + ' ' +
173 remitoBusinessService 172 remitoBusinessService
174 .plazoToString(notaPedido.notaPedidoPlazo) 173 .plazoToString(notaPedido.notaPedidoPlazo)
175 }, 174 },
176 { 175 {
177 label: 'Flete:', 176 label: 'Flete:',
178 valor: notaPedido.fob === 1 ? 'FOB' : ( 177 valor: notaPedido.fob === 1 ? 'FOB' : (
179 notaPedido.flete === 1 ? 'Si' : 'No') 178 notaPedido.flete === 1 ? 'Si' : 'No')
180 }, 179 },
181 { 180 {
182 label: 'Puntos de descarga: ', 181 label: 'Puntos de descarga: ',
183 valor: $filter('rellenarDigitos')( 182 valor: $filter('rellenarDigitos')(
184 getCabeceraPuntoDescarga(puntosDescarga)) 183 getCabeceraPuntoDescarga(puntosDescarga))
185 } 184 }
186 ]; 185 ];
187 186
188 // Seteo checked en cabeceras 187 // Seteo checked en cabeceras
189 $filter('filter')($scope.botonera, 188 $filter('filter')($scope.botonera,
190 { label: 'Cliente' })[0].checked = true; 189 { label: 'Cliente' })[0].checked = true;
191 $filter('filter')($scope.botonera, 190 $filter('filter')($scope.botonera,
192 { label: 'Proveedor' })[0].checked = true; 191 { label: 'Proveedor' })[0].checked = true;
193 $filter('filter')($scope.botonera, 192 $filter('filter')($scope.botonera,
194 { label: 'Moneda' })[0].checked = true; 193 { label: 'Moneda' })[0].checked = true;
195 $filter('filter')($scope.botonera, 194 $filter('filter')($scope.botonera,
196 { label: 'Nota pedido' })[0].checked = true; 195 { label: 'Nota pedido' })[0].checked = true;
197 $filter('filter')($scope.botonera, 196 $filter('filter')($scope.botonera,
198 { label: 'Precios y condiciones' })[0].checked = true; 197 { label: 'Precios y condiciones' })[0].checked = true;
199 198
200 if (notaPedido.observaciones) { 199 if (notaPedido.observaciones) {
201 $filter('filter')($scope.botonera, 200 $filter('filter')($scope.botonera,
202 { label: 'Observaciones' })[0].checked = true; 201 { label: 'Observaciones' })[0].checked = true;
203 } 202 }
204 203
205 function valorPrecioCondicion() { 204 function valorPrecioCondicion() {
206 if (notaPedido.idPrecioCondicion > 0) { 205 if (notaPedido.idPrecioCondicion > 0) {
207 return notaPedido.precioCondicion.nombre; 206 return notaPedido.precioCondicion.nombre;
208 } else { 207 } else {
209 return 'Ingreso Manual'; 208 return 'Ingreso Manual';
210 } 209 }
211 } 210 }
212 211
213 if (notaPedido.flete === 1) { 212 if (notaPedido.flete === 1) {
214 var cabeceraBomba = { 213 var cabeceraBomba = {
215 label: 'Bomba:', 214 label: 'Bomba:',
216 valor: notaPedido.bomba === 1 ? 'Si' : 'No' 215 valor: notaPedido.bomba === 1 ? 'Si' : 'No'
217 }; 216 };
218 if (notaPedido.kilometros) { 217 if (notaPedido.kilometros) {
219 var cabeceraKilometros = { 218 var cabeceraKilometros = {
220 label: 'Kilometros:', 219 label: 'Kilometros:',
221 valor: notaPedido.kilometros 220 valor: notaPedido.kilometros
222 }; 221 };
223 cabeceras.push(cabeceraKilometros); 222 cabeceras.push(cabeceraKilometros);
224 } 223 }
225 cabeceras.push(cabeceraBomba); 224 cabeceras.push(cabeceraBomba);
226 } 225 }
227 226
228 delete notaPedido.id; 227 delete notaPedido.id;
229 $scope.remito = notaPedido; 228 $scope.remito = notaPedido;
230 $scope.remito.id = 0; 229 $scope.remito.id = 0;
231 $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo; 230 $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo;
232 231
233 notaPedido.articulosNotaPedido.forEach(function (articulo) { 232 notaPedido.articulosNotaPedido.forEach(function (articulo) {
234 articulo.id = 0; 233 articulo.id = 0;
235 articulo.idRemito = 0; 234 articulo.idRemito = 0;
236 articulo.precio = 235 articulo.precio =
237 (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4); 236 (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4);
238 }); 237 });
239 238
240 $scope.remito.articulosRemito = notaPedido.articulosNotaPedido; 239 $scope.remito.articulosRemito = notaPedido.articulosNotaPedido;
241 240
242 if (notaPedido.idPrecioCondicion > 0) { 241 if (notaPedido.idPrecioCondicion > 0) {
243 $scope.idLista = notaPedido.precioCondicion.idListaPrecio; 242 $scope.idLista = notaPedido.precioCondicion.idListaPrecio;
244 } else { 243 } else {
245 $scope.idLista = -1; 244 $scope.idLista = -1;
246 } 245 }
247 246
248 enableObservaciones(notaPedido.observaciones ? true : false); 247 enableObservaciones(notaPedido.observaciones ? true : false);
249 addArrayCabecera(cabeceras); 248 addArrayCabecera(cabeceras);
250 249
251 }, function () { 250 }, function () {
252 // funcion ejecutada cuando se cancela el modal 251 // funcion ejecutada cuando se cancela el modal
253 } 252 }
254 ); 253 );
255 } 254 }
256 }; 255 };
257 256
258 $scope.seleccionarRemito = function () { 257 $scope.seleccionarRemito = function () {
259 if ($scope.remitoIsDirty) { 258 if ($scope.remitoIsDirty) {
260 focaModalService.confirm("¿Desea continuar? Se perderan los cambios") 259 focaModalService.confirm("¿Desea continuar? Se perderan los cambios")
261 .then(function () { 260 .then(function () {
262 $scope.getRemitoModal(); 261 $scope.getRemitoModal();
263 }); 262 });
264 } else { 263 } else {
265 $scope.getRemitoModal() 264 $scope.getRemitoModal()
266 } 265 }
267 }; 266 };
268 $scope.getRemitoModal = function () { 267 $scope.getRemitoModal = function () {
269 var modalInstance = $uibModal.open( 268 var modalInstance = $uibModal.open(
270 { 269 {
271 ariaLabelledBy: 'Busqueda de Remito', 270 ariaLabelledBy: 'Busqueda de Remito',
272 templateUrl: 'foca-modal-remito.html', 271 templateUrl: 'foca-modal-remito.html',
273 controller: 'focaModalRemitoController', 272 controller: 'focaModalRemitoController',
274 size: 'lg', 273 size: 'lg',
275 resolve: { usadoPor: function () { return 'remito'; } } 274 resolve: { usadoPor: function () { return 'remito'; } }
276 } 275 }
277 ); 276 );
278 modalInstance.result.then( 277 modalInstance.result.then(
279 setearRemito, function () { 278 setearRemito, function () {
280 // funcion ejecutada cuando se cancela el modal 279 // funcion ejecutada cuando se cancela el modal
281 } 280 }
282 ); 281 );
283 } 282 }
284 //validacion por domicilio y por plazo pago 283 //validacion por domicilio y por plazo pago
285 $scope.crearRemito = function () { 284 $scope.crearRemito = function () {
286 if (!$scope.remito.vendedor.NUM) { 285 if (!$scope.remito.vendedor.NUM) {
287 focaModalService.alert('Ingrese Vendedor'); 286 focaModalService.alert('Ingrese Vendedor');
288 return; 287 return;
289 } else if (!$scope.remito.cliente.COD) { 288 } else if (!$scope.remito.cliente.COD) {
290 focaModalService.alert('Ingrese Cliente'); 289 focaModalService.alert('Ingrese Cliente');
291 return; 290 return;
292 } else if (!$scope.remito.proveedor) { 291 } else if (!$scope.remito.proveedor) {
293 focaModalService.alert('Ingrese Proveedor'); 292 focaModalService.alert('Ingrese Proveedor');
294 return; 293 return;
295 } else if (!$scope.remito.cotizacion.moneda.id && 294 } else if (!$scope.remito.cotizacion.moneda.id &&
296 !$scope.remito.cotizacion.moneda.ID) { 295 !$scope.remito.cotizacion.moneda.ID) {
297 focaModalService.alert('Ingrese Moneda'); 296 focaModalService.alert('Ingrese Moneda');
298 return; 297 return;
299 } else if (!$scope.remito.cotizacion.ID) { 298 } else if (!$scope.remito.cotizacion.ID) {
300 focaModalService.alert('Ingrese Cotización'); 299 focaModalService.alert('Ingrese Cotización');
301 return; 300 return;
302 } else if ($scope.remito.flete === undefined || $scope.remito.flete === null) { 301 } else if ($scope.remito.flete === undefined || $scope.remito.flete === null) {
303 focaModalService.alert('Ingrese Flete'); 302 focaModalService.alert('Ingrese Flete');
304 return; 303 return;
305 } else if ($scope.articulosFiltro().length === 0) { 304 } else if ($scope.articulosFiltro().length === 0) {
306 focaModalService.alert('Debe cargar al menos un articulo'); 305 focaModalService.alert('Debe cargar al menos un articulo');
307 return; 306 return;
308 } 307 }
309 focaBotoneraLateralService.startGuardar(); 308 focaBotoneraLateralService.startGuardar();
310 $scope.saveLoading = true; 309 $scope.saveLoading = true;
311 var save = { 310 var save = {
312 remito: { 311 remito: {
313 id: $scope.remito.id, 312 id: $scope.remito.id,
314 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), 313 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
315 idCliente: $scope.remito.cliente.COD, 314 idCliente: $scope.remito.cliente.COD,
316 nombreCliente: $scope.remito.cliente.NOM, 315 nombreCliente: $scope.remito.cliente.NOM,
317 cuitCliente: $scope.remito.cliente.CUIT, 316 cuitCliente: $scope.remito.cliente.CUIT,
318 total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, 317 total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR,
319 numeroNotaPedido: $scope.remito.numeroNotaPedido, 318 numeroNotaPedido: $scope.remito.numeroNotaPedido,
320 idVendedor: $scope.remito.idVendedor, 319 idVendedor: $scope.remito.idVendedor,
321 idProveedor: $scope.remito.idProveedor, 320 idProveedor: $scope.remito.idProveedor,
322 idDomicilio: $scope.remito.idDomicilio, 321 idDomicilio: $scope.remito.idDomicilio,
323 idCotizacion: $scope.remito.cotizacion.ID, 322 idCotizacion: $scope.remito.cotizacion.ID,
324 idPrecioCondicion: $scope.remito.idPrecioCondicion, 323 idPrecioCondicion: $scope.remito.idPrecioCondicion,
325 flete: $scope.remito.flete, 324 flete: $scope.remito.flete,
326 fob: $scope.remito.fob, 325 fob: $scope.remito.fob,
327 bomba: $scope.remito.bomba, 326 bomba: $scope.remito.bomba,
328 kilometros: $scope.remito.kilometros, 327 kilometros: $scope.remito.kilometros,
329 domicilioStamp: $scope.remito.domicilioStamp, 328 domicilioStamp: $scope.remito.domicilioStamp,
330 observaciones: $scope.remito.observaciones, 329 observaciones: $scope.remito.observaciones,
331 numeroRemito: parseInt($scope.comprobante), 330 numeroRemito: parseInt($scope.comprobante),
332 sucursal: parseInt($scope.puntoVenta), 331 sucursal: parseInt($scope.puntoVenta),
333 responsabilidadIvaCliente: $scope.remito.cliente.IVA, 332 responsabilidadIvaCliente: $scope.remito.cliente.IVA,
334 descuento: 0,//TODO, 333 descuento: 0,//TODO,
335 importeNeto: getImporte('netoUnitario'), 334 importeNeto: getImporte('netoUnitario'),
336 importeExento: getImporte('exentoUnitario'), 335 importeExento: getImporte('exentoUnitario'),
337 importeIva: getImporte('ivaUnitario'), 336 importeIva: getImporte('ivaUnitario'),
338 importeIvaServicios: 0,//TODO 337 importeIvaServicios: 0,//TODO
339 importeImpuestoInterno: getImporte('impuestoInternoUnitario'), 338 importeImpuestoInterno: getImporte('impuestoInternoUnitario'),
340 importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'), 339 importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'),
341 importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'), 340 importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'),
342 percepcion: 0,//TODO 341 percepcion: 0,//TODO
343 percepcionIva: 0,//TODO 342 percepcionIva: 0,//TODO
344 redondeo: 0,//TODO 343 redondeo: 0,//TODO
345 anulado: false, 344 anulado: false,
346 planilla: $filter('date')($scope.now, 'ddMMyyyy'), 345 planilla: $filter('date')($scope.now, 'ddMMyyyy'),
347 lugar: parseInt($scope.puntoVenta), 346 lugar: parseInt($scope.puntoVenta),
348 cuentaMadre: 0,//TODO 347 cuentaMadre: 0,//TODO
349 cuentaContable: 0,//TODO 348 cuentaContable: 0,//TODO
350 asiento: 0,//TODO 349 asiento: 0,//TODO
351 e_hd: '',//TODO 350 e_hd: '',//TODO
352 c_hd: '', 351 c_hd: '',
353 numeroLiquidoProducto: 0,//TODO 352 numeroLiquidoProducto: 0,//TODO
354 estado: 0, 353 estado: 0,
355 destinoVenta: 0,//TODO 354 destinoVenta: 0,//TODO
356 operacionTipo: 0, //TODO 355 operacionTipo: 0, //TODO
357 }, 356 },
358 notaPedido: $scope.notaPedido 357 notaPedido: $scope.notaPedido
359 }; 358 };
360 359
361 crearRemitoService.crearRemito(save).then( 360 crearRemitoService.crearRemito(save).then(
362 function (data) { 361 function (data) {
363 362
364 focaBotoneraLateralService.endGuardar(true); 363 focaBotoneraLateralService.endGuardar(true);
365 $scope.saveLoading = false; 364 $scope.saveLoading = false;
366 365
367 $scope.remito.id = data.data.id; 366 $scope.remito.id = data.data.id;
368 $scope.remito.numeroRemito = data.data.numero; 367 $scope.remito.numeroRemito = data.data.numero;
369 368
370 remitoBusinessService.addArticulos($scope.remito.articulosRemito, 369 remitoBusinessService.addArticulos($scope.remito.articulosRemito,
371 $scope.remito.id, $scope.remito.cotizacion.VENDEDOR); 370 $scope.remito.id, $scope.remito.cotizacion.VENDEDOR);
372 371
373 if (data.status === 500) { 372 if (data.status === 500) {
374 focaModalService.alert(data.data); 373 focaModalService.alert(data.data);
375 return; 374 return;
376 } 375 }
377 376
378 // TODO: updatear plazos 377 // TODO: updatear plazos
379 if ($scope.remito.id === 0) { 378 if ($scope.remito.id === 0) {
380 var plazos = $scope.remito.remitoPlazo; 379 var plazos = $scope.remito.remitoPlazo;
381 380
382 for (var j = 0; j < plazos.length; j++) { 381 for (var j = 0; j < plazos.length; j++) {
383 var json = { 382 var json = {
384 idRemito: $scope.remito.id, 383 idRemito: $scope.remito.id,
385 dias: plazos[j].dias 384 dias: plazos[j].dias
386 }; 385 };
387 crearRemitoService.crearPlazosParaRemito(json); 386 crearRemitoService.crearPlazosParaRemito(json);
388 } 387 }
389 } 388 }
390 389
391 abrirModalMail($scope.remito.id, 390 abrirModalMail($scope.remito.id,
392 $scope.remito.cliente, 391 $scope.remito.cliente,
393 $filter('comprobante')([ 392 $filter('comprobante')([
394 $scope.puntoVenta, 393 $scope.puntoVenta,
395 $scope.remito.numeroRemito 394 $scope.remito.numeroRemito
396 ]) 395 ])
397 ); 396 );
398 397
399 config(); 398 config();
400 399
401 }, function (error) { 400 }, function (error) {
402 focaModalService.alert(error.data || 'Hubo un error al crear el remito'); 401 focaModalService.alert(error.data || 'Hubo un error al crear el remito');
403 focaBotoneraLateralService.endGuardar(); 402 focaBotoneraLateralService.endGuardar();
404 $scope.saveLoading = false; 403 $scope.saveLoading = false;
405 console.info(error); 404 console.info(error);
406 } 405 }
407 ); 406 );
408 }; 407 };
409 408
410 $scope.seleccionarProductos = function () { 409 $scope.seleccionarProductos = function () {
411 if ($scope.idLista === undefined) { 410 if ($scope.idLista === undefined) {
412 focaModalService.alert( 411 focaModalService.alert(
413 'Primero seleccione una lista de precio y condicion'); 412 'Primero seleccione una lista de precio y condicion');
414 return; 413 return;
415 } 414 }
416 var modalInstance = $uibModal.open( 415 var modalInstance = $uibModal.open(
417 { 416 {
418 ariaLabelledBy: 'Busqueda de Productos', 417 ariaLabelledBy: 'Busqueda de Productos',
419 templateUrl: 'modal-busqueda-productos.html', 418 templateUrl: 'modal-busqueda-productos.html',
420 controller: 'modalBusquedaProductosCtrl', 419 controller: 'modalBusquedaProductosCtrl',
421 resolve: { 420 resolve: {
422 parametroProducto: { 421 parametroProducto: {
423 idLista: $scope.idLista, 422 idLista: $scope.idLista,
424 cotizacion: $scope.remito.cotizacion.VENDEDOR, 423 cotizacion: $scope.remito.cotizacion.VENDEDOR,
425 simbolo: $scope.remito.cotizacion.moneda.SIMBOLO 424 simbolo: $scope.remito.cotizacion.moneda.SIMBOLO
426 } 425 }
427 }, 426 },
428 size: 'lg' 427 size: 'lg'
429 } 428 }
430 ); 429 );
431 modalInstance.result.then( 430 modalInstance.result.then(
432 function (producto) { 431 function (producto) {
433 var newArt = 432 var newArt =
434 { 433 {
435 id: 0, 434 id: 0,
436 idRemito: 0, 435 idRemito: 0,
437 codigo: producto.codigo, 436 codigo: producto.codigo,
438 sector: producto.sector, 437 sector: producto.sector,
439 sectorCodigo: producto.sector + '-' + producto.codigo, 438 sectorCodigo: producto.sector + '-' + producto.codigo,
440 descripcion: producto.descripcion, 439 descripcion: producto.descripcion,
441 item: $scope.remito.articulosRemito.length + 1, 440 item: $scope.remito.articulosRemito.length + 1,
442 nombre: producto.descripcion, 441 nombre: producto.descripcion,
443 precio: parseFloat(producto.precio.toFixed(4)), 442 precio: parseFloat(producto.precio.toFixed(4)),
444 costoUnitario: producto.costo, 443 costoUnitario: producto.costo,
445 editCantidad: false, 444 editCantidad: false,
446 editPrecio: false, 445 editPrecio: false,
447 rubro: producto.CodRub, 446 rubro: producto.CodRub,
448 exentoUnitario: producto.precio, 447 exentoUnitario: producto.precio,
449 ivaUnitario: producto.IMPIVA, 448 ivaUnitario: producto.IMPIVA,
450 impuestoInternoUnitario: producto.ImpInt, 449 impuestoInternoUnitario: producto.ImpInt,
451 impuestoInterno1Unitario: producto.ImpInt2, 450 impuestoInterno1Unitario: producto.ImpInt2,
452 impuestoInterno2Unitario: producto.ImpInt3, 451 impuestoInterno2Unitario: producto.ImpInt3,
453 precioLista: producto.precio, 452 precioLista: producto.precio,
454 combustible: 1, 453 combustible: 1,
455 facturado: 0 454 facturado: 0
456 }; 455 };
457 $scope.articuloACargar = newArt; 456 $scope.articuloACargar = newArt;
458 $scope.cargando = false; 457 $scope.cargando = false;
459 }, function () { 458 }, function () {
460 // funcion ejecutada cuando se cancela el modal 459 // funcion ejecutada cuando se cancela el modal
461 } 460 }
462 ); 461 );
463 }; 462 };
464 463
465 $scope.seleccionarPuntosDeDescarga = function () { 464 $scope.seleccionarPuntosDeDescarga = function () {
466 if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { 465 if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) {
467 focaModalService.alert('Primero seleccione un cliente y un domicilio'); 466 focaModalService.alert('Primero seleccione un cliente y un domicilio');
468 return; 467 return;
469 } else { 468 } else {
470 var modalInstance = $uibModal.open( 469 var modalInstance = $uibModal.open(
471 { 470 {
472 ariaLabelledBy: 'Búsqueda de Puntos de descarga', 471 ariaLabelledBy: 'Búsqueda de Puntos de descarga',
473 templateUrl: 'modal-punto-descarga.html', 472 templateUrl: 'modal-punto-descarga.html',
474 controller: 'focaModalPuntoDescargaController', 473 controller: 'focaModalPuntoDescargaController',
475 size: 'lg', 474 size: 'lg',
476 resolve: { 475 resolve: {
477 filters: { 476 filters: {
478 idDomicilio: $scope.remito.domicilio.id, 477 idDomicilio: $scope.remito.domicilio.id,
479 idCliente: $scope.remito.cliente.COD, 478 idCliente: $scope.remito.cliente.COD,
480 articulos: $scope.remito.articulosRemito, 479 articulos: $scope.remito.articulosRemito,
481 puntosDescarga: $scope.remito.domicilio.puntosDescarga, 480 puntosDescarga: $scope.remito.domicilio.puntosDescarga,
482 domicilio: $scope.remito.domicilio 481 domicilio: $scope.remito.domicilio
483 } 482 }
484 } 483 }
485 } 484 }
486 ); 485 );
487 modalInstance.result.then( 486 modalInstance.result.then(
488 function (puntosDescarga) { 487 function (puntosDescarga) {
489 $scope.remito.domicilio.puntosDescarga = puntosDescarga; 488 $scope.remito.domicilio.puntosDescarga = puntosDescarga;
490 489
491 $scope.$broadcast('addCabecera', { 490 $scope.$broadcast('addCabecera', {
492 label: 'Puntos de descarga:', 491 label: 'Puntos de descarga:',
493 valor: getCabeceraPuntoDescarga( 492 valor: getCabeceraPuntoDescarga(
494 $scope.remito.domicilio.puntosDescarga) 493 $scope.remito.domicilio.puntosDescarga)
495 }); 494 });
496 }, function () { 495 }, function () {
497 $scope.abrirModalDomicilios($scope.cliente); 496 $scope.abrirModalDomicilios($scope.cliente);
498 } 497 }
499 ); 498 );
500 } 499 }
501 }; 500 };
502 501 $scope.seleccionarCliente = function () {
503 $scope.seleccionarVendedor = function (callback, ocultarVendedor) {
504 if (ocultarVendedor) {
505 callback();
506 return;
507 }
508
509 if (varlidarRemitoFacturado()) { 502 if (varlidarRemitoFacturado()) {
510 var parametrosModal = { 503 var modalInstance = $uibModal.open(
511 titulo: 'Búsqueda vendedores', 504 {
512 query: '/vendedor', 505 ariaLabelledBy: 'Busqueda de Cliente',
513 columnas: [ 506 templateUrl: 'foca-busqueda-cliente-modal.html',
514 { 507 controller: 'focaBusquedaClienteModalController',
515 propiedad: 'NUM', 508 resolve: {
516 nombre: 'Código', 509 vendedor: function () { return null; },
517 filtro: { 510 cobrador: function () { return null; }
518 nombre: 'rellenarDigitos',
519 parametro: 3
520 }
521 }, 511 },
522 { 512 size: 'lg'
523 propiedad: 'NOM', 513 }
524 nombre: 'Nombre' 514 );
525 } 515 modalInstance.result.then(
526 ], 516 function (cliente) {
527 size: 'md' 517 $scope.abrirModalDomicilios(cliente);
528 }; 518 $scope.cliente = cliente;
529 focaModalService.modal(parametrosModal).then(
530 function (vendedor) {
531 $scope.remitoIsDirty = true;
532 $scope.$broadcast('addCabecera', {
533 label: 'Vendedor:',
534 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
535 vendedor.NOM
536 });
537 $scope.remito.idVendedor = vendedor.id;
538 $scope.remito.vendedor = vendedor;
539 deleteCliente();
540 callback();
541 }, function () { 519 }, function () {
542
543 } 520 }
544 ); 521 );
545 } 522 }
546 }; 523 };
547 524
548 $scope.seleccionarCliente = function (ocultarVendedor) {
549
550 $scope.seleccionarVendedor(function () {
551 if (varlidarRemitoFacturado()) {
552 var modalInstance = $uibModal.open(
553 {
554 ariaLabelledBy: 'Busqueda de Cliente',
555 templateUrl: 'foca-busqueda-cliente-modal.html',
556 controller: 'focaBusquedaClienteModalController',
557 resolve: {
558 vendedor: function () { return $scope.remito.vendedor; },
559 cobrador: function () { return null; }
560 },
561 size: 'lg'
562 }
563 );
564 modalInstance.result.then(
565 function (cliente) {
566 $scope.abrirModalDomicilios(cliente);
567 $scope.cliente = cliente;
568 }, function () {
569 $scope.seleccionarCliente();
570 }
571 );
572 }
573 }, ocultarVendedor);
574 };
575
576 $scope.seleccionarProveedor = function () { 525 $scope.seleccionarProveedor = function () {
577 if (varlidarRemitoFacturado()) { 526 if (varlidarRemitoFacturado()) {
578 var parametrosModal = { 527 var parametrosModal = {
579 titulo: 'Búsqueda de Proveedor', 528 titulo: 'Búsqueda de Proveedor',
580 query: '/proveedor', 529 query: '/proveedor',
581 columnas: [ 530 columnas: [
582 { 531 {
583 nombre: 'Código', 532 nombre: 'Código',
584 propiedad: 'COD', 533 propiedad: 'COD',
585 filtro: { 534 filtro: {
586 nombre: 'rellenarDigitos', 535 nombre: 'rellenarDigitos',
587 parametro: 5 536 parametro: 5
588 } 537 }
589 }, 538 },
590 { 539 {
591 nombre: 'Nombre', 540 nombre: 'Nombre',
592 propiedad: 'NOM' 541 propiedad: 'NOM'
593 }, 542 },
594 { 543 {
595 nombre: 'CUIT', 544 nombre: 'CUIT',
596 propiedad: 'CUIT' 545 propiedad: 'CUIT'
597 } 546 }
598 ], 547 ],
599 tipo: 'POST', 548 tipo: 'POST',
600 json: { razonCuitCod: '' } 549 json: { razonCuitCod: '' }
601 }; 550 };
602 focaModalService.modal(parametrosModal).then( 551 focaModalService.modal(parametrosModal).then(
603 function (proveedor) { 552 function (proveedor) {
604 $scope.seleccionarFlete(proveedor); 553 $scope.seleccionarFlete(proveedor);
605 }, function () { } 554 }, function () { }
606 ); 555 );
607 } 556 }
608 }; 557 };
609 558
610 $scope.abrirModalDomicilios = function (cliente) { 559 $scope.abrirModalDomicilios = function (cliente) {
611 var modalInstanceDomicilio = $uibModal.open( 560 var modalInstanceDomicilio = $uibModal.open(
612 { 561 {
613 ariaLabelledBy: 'Busqueda de Domicilios', 562 ariaLabelledBy: 'Busqueda de Domicilios',
614 templateUrl: 'modal-domicilio.html', 563 templateUrl: 'modal-domicilio.html',
615 controller: 'focaModalDomicilioController', 564 controller: 'focaModalDomicilioController',
616 size: 'lg', 565 size: 'lg',
617 resolve: { 566 resolve: {
618 idCliente: function () { return cliente.cod; }, 567 idCliente: function () { return cliente.cod; },
619 esNuevo: function () { return cliente.esNuevo; } 568 esNuevo: function () { return cliente.esNuevo; }
620 } 569 }
621 } 570 }
622 ); 571 );
623 modalInstanceDomicilio.result.then( 572 modalInstanceDomicilio.result.then(
624 function (domicilio) { 573 function (domicilio) {
625 $scope.remito.domicilio = domicilio; 574 $scope.remito.domicilio = domicilio;
626 console.log(cliente);
627 $scope.remito.cliente = { 575 $scope.remito.cliente = {
628 COD: cliente.cod, 576 COD: cliente.cod,
629 CUIT: cliente.cuit, 577 CUIT: cliente.cuit,
630 NOM: cliente.nom, 578 NOM: cliente.nom,
631 MAIL: cliente.mail, 579 MAIL: cliente.mail,
632 MOD: cliente.mod, 580 MOD: cliente.mod,
633 IVA: cliente.iva 581 IVA: cliente.iva,
582 VEN: cliente.ven
634 }; 583 };
635 584 crearRemitoService.getVendedorById($scope.remito.cliente.VEN)
636 var domicilioStamp = 585 .then(function (res) {
637 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 586 $scope.remito.vendedor = res.data;
638 domicilio.Localidad + ', ' + domicilio.Provincia; 587 $scope.$broadcast('addCabecera', {
639 $scope.remito.domicilioStamp = domicilioStamp; 588 label: 'Vendedor:',
640 $scope.$broadcast('addCabecera', { 589 valor: $filter('rellenarDigitos')($scope.remito.vendedor.NUM, 3) + ' - ' +
641 label: 'Cliente:', 590 $scope.remito.vendedor.NOM
642 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom
643 });
644 $scope.$broadcast('addCabecera', {
645 label: 'Domicilio:',
646 valor: domicilioStamp
647 });
648
649 if (domicilio.verPuntos) {
650 delete $scope.remito.domicilio.verPuntos;
651 $scope.seleccionarPuntosDeDescarga();
652 } else {
653 crearRemitoService
654 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
655 .then(function (res) {
656 if (res.data.length) $scope.seleccionarPuntosDeDescarga();
657 }); 591 });
658 } 592 var domicilioStamp =
593 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
594 domicilio.Localidad + ', ' + domicilio.Provincia;
595 $scope.remito.domicilioStamp = domicilioStamp;
596 $scope.$broadcast('addCabecera', {
597 label: 'Cliente:',
598 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom
599 });
600 $scope.$broadcast('addCabecera', {
601 label: 'Domicilio:',
602 valor: domicilioStamp
603 });
604
605 if (domicilio.verPuntos) {
606 delete $scope.remito.domicilio.verPuntos;
607 $scope.seleccionarPuntosDeDescarga();
608 } else {
609 crearRemitoService
610 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
611 .then(function (res) {
612 if (res.data.length) $scope.seleccionarPuntosDeDescarga();
613 });
614 }
659 615
660 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 616 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
617 })
618 .catch(function (e) { console.log(e); })
661 }, function () { 619 }, function () {
662 $scope.seleccionarCliente(true); 620 $scope.seleccionarCliente(true);
663 return; 621 return;
664 } 622 }
665 ); 623 );
666 }; 624 };
667 625
668 $scope.getTotal = function () { 626 $scope.getTotal = function () {
669 var total = 0; 627 var total = 0;
670 var arrayTempArticulos = $scope.articulosFiltro(); 628 var arrayTempArticulos = $scope.articulosFiltro();
671 for (var i = 0; i < arrayTempArticulos.length; i++) { 629 for (var i = 0; i < arrayTempArticulos.length; i++) {
672 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 630 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
673 } 631 }
674 return parseFloat(total.toFixed(2)); 632 return parseFloat(total.toFixed(2));
675 }; 633 };
676 634
677 $scope.getSubTotal = function () { 635 $scope.getSubTotal = function () {
678 if ($scope.articuloACargar) { 636 if ($scope.articuloACargar) {
679 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 637 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
680 } 638 }
681 }; 639 };
682 640
683 $scope.seleccionarPreciosYCondiciones = function () { 641 $scope.seleccionarPreciosYCondiciones = function () {
684 if (!$scope.remito.cliente.COD) { 642 if (!$scope.remito.cliente.COD) {
685 focaModalService.alert('Primero seleccione un cliente'); 643 focaModalService.alert('Primero seleccione un cliente');
686 return; 644 return;
687 } 645 }
688 646
689 if ($scope.remito.articulosRemito.length !== 0) { 647 if ($scope.remito.articulosRemito.length !== 0) {
690 focaModalService.confirm('Se perderan los productos ingresados') 648 focaModalService.confirm('Se perderan los productos ingresados')
691 .then(function (data) { 649 .then(function (data) {
692 if (data && varlidarRemitoFacturado()) { 650 if (data && varlidarRemitoFacturado()) {
693 abrirModal(); 651 abrirModal();
694 } 652 }
695 }); 653 });
696 } else { 654 } else {
697 abrirModal(); 655 abrirModal();
698 } 656 }
699 657
700 function abrirModal() { 658 function abrirModal() {
701 var modalInstance = $uibModal.open( 659 var modalInstance = $uibModal.open(
702 { 660 {
703 ariaLabelledBy: 'Busqueda de Precio Condición', 661 ariaLabelledBy: 'Busqueda de Precio Condición',
704 templateUrl: 'modal-precio-condicion.html', 662 templateUrl: 'modal-precio-condicion.html',
705 controller: 'focaModalPrecioCondicionController', 663 controller: 'focaModalPrecioCondicionController',
706 size: 'lg', 664 size: 'lg',
707 resolve: { 665 resolve: {
708 idListaPrecio: function () { 666 idListaPrecio: function () {
709 return $scope.remito.cliente.MOD || null; 667 return $scope.remito.cliente.MOD || null;
710 } 668 }
711 } 669 }
712 } 670 }
713 ); 671 );
714 modalInstance.result.then( 672 modalInstance.result.then(
715 function (precioCondicion) { 673 function (precioCondicion) {
716 var cabecera = ''; 674 var cabecera = '';
717 var plazosConcat = ''; 675 var plazosConcat = '';
718 if (!Array.isArray(precioCondicion)) { 676 if (!Array.isArray(precioCondicion)) {
719 $scope.remito.idPrecioCondicion = precioCondicion.id; 677 $scope.remito.idPrecioCondicion = precioCondicion.id;
720 $scope.remito.remitoPlazo = precioCondicion.plazoPago; 678 $scope.remito.remitoPlazo = precioCondicion.plazoPago;
721 $scope.idLista = precioCondicion.idListaPrecio; 679 $scope.idLista = precioCondicion.idListaPrecio;
722 for (var i = 0; i < precioCondicion.plazoPago.length; i++) { 680 for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
723 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 681 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
724 } 682 }
725 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + 683 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
726 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); 684 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
727 } else { //Cuando se ingresan los plazos manualmente 685 } else { //Cuando se ingresan los plazos manualmente
728 $scope.remito.idPrecioCondicion = 0; 686 $scope.remito.idPrecioCondicion = 0;
729 //-1, el modal productos busca todos los productos 687 //-1, el modal productos busca todos los productos
730 $scope.idLista = -1; 688 $scope.idLista = -1;
731 $scope.remito.remitoPlazo = precioCondicion; 689 $scope.remito.remitoPlazo = precioCondicion;
732 for (var j = 0; j < precioCondicion.length; j++) { 690 for (var j = 0; j < precioCondicion.length; j++) {
733 plazosConcat += precioCondicion[j].dias + ' '; 691 plazosConcat += precioCondicion[j].dias + ' ';
734 } 692 }
735 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 693 cabecera = 'Ingreso manual ' + plazosConcat.trim();
736 } 694 }
737 $scope.remito.articulosRemito = []; 695 $scope.remito.articulosRemito = [];
738 $scope.$broadcast('addCabecera', { 696 $scope.$broadcast('addCabecera', {
739 label: 'Precios y condiciones:', 697 label: 'Precios y condiciones:',
740 valor: cabecera 698 valor: cabecera
741 }); 699 });
742 $scope.remito.precioCondicion = precioCondicion; 700 $scope.remito.precioCondicion = precioCondicion;
743 701
744 $filter('filter')($scope.botonera, 702 $filter('filter')($scope.botonera,
745 { label: 'Precios y Condiciones' })[0].checked = true; 703 { label: 'Precios y Condiciones' })[0].checked = true;
746 }, function () { 704 }, function () {
747 705
748 } 706 }
749 ); 707 );
750 } 708 }
751 }; 709 };
752 710
753 $scope.seleccionarFlete = function (proveedor) { 711 $scope.seleccionarFlete = function (proveedor) {
754 if (varlidarRemitoFacturado()) { 712 if (varlidarRemitoFacturado()) {
755 var modalInstance = $uibModal.open( 713 var modalInstance = $uibModal.open(
756 { 714 {
757 ariaLabelledBy: 'Busqueda de Flete', 715 ariaLabelledBy: 'Busqueda de Flete',
758 templateUrl: 'modal-flete.html', 716 templateUrl: 'modal-flete.html',
759 controller: 'focaModalFleteController', 717 controller: 'focaModalFleteController',
760 size: 'lg', 718 size: 'lg',
761 resolve: { 719 resolve: {
762 parametrosFlete: 720 parametrosFlete:
763 function () { 721 function () {
764 return { 722 return {
765 flete: $scope.remito.flete ? '1' : 723 flete: $scope.remito.flete ? '1' :
766 ($scope.remito.fob ? 'FOB' : 724 ($scope.remito.fob ? 'FOB' :
767 ($scope.remito.flete === undefined ? 725 ($scope.remito.flete === undefined ?
768 null : '0')), 726 null : '0')),
769 bomba: $scope.remito.bomba ? '1' : 727 bomba: $scope.remito.bomba ? '1' :
770 ($scope.remito.bomba === undefined ? 728 ($scope.remito.bomba === undefined ?
771 null : '0'), 729 null : '0'),
772 kilometros: $scope.remito.kilometros 730 kilometros: $scope.remito.kilometros
773 }; 731 };
774 } 732 }
775 } 733 }
776 } 734 }
777 ); 735 );
778 modalInstance.result.then( 736 modalInstance.result.then(
779 function (datos) { 737 function (datos) {
780 $scope.remitoIsDirty = true; 738 $scope.remitoIsDirty = true;
781 $scope.remito.proveedor = proveedor; 739 $scope.remito.proveedor = proveedor;
782 $scope.remito.idProveedor = proveedor.COD; 740 $scope.remito.idProveedor = proveedor.COD;
783 $scope.$broadcast('addCabecera', { 741 $scope.$broadcast('addCabecera', {
784 label: 'Proveedor:', 742 label: 'Proveedor:',
785 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 743 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
786 proveedor.NOM 744 proveedor.NOM
787 }); 745 });
788 746
789 $scope.remito.flete = datos.flete; 747 $scope.remito.flete = datos.flete;
790 $scope.remito.fob = datos.FOB; 748 $scope.remito.fob = datos.FOB;
791 $scope.remito.bomba = datos.bomba; 749 $scope.remito.bomba = datos.bomba;
792 $scope.remito.kilometros = datos.kilometros; 750 $scope.remito.kilometros = datos.kilometros;
793 751
794 $scope.$broadcast('addCabecera', { 752 $scope.$broadcast('addCabecera', {
795 label: 'Flete:', 753 label: 'Flete:',
796 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') 754 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No')
797 }); 755 });
798 if (datos.flete) { 756 if (datos.flete) {
799 $scope.$broadcast('addCabecera', { 757 $scope.$broadcast('addCabecera', {
800 label: 'Bomba:', 758 label: 'Bomba:',
801 valor: datos.bomba ? 'Si' : 'No' 759 valor: datos.bomba ? 'Si' : 'No'
802 }); 760 });
803 $scope.$broadcast('addCabecera', { 761 $scope.$broadcast('addCabecera', {
804 label: 'Kilometros:', 762 label: 'Kilometros:',
805 valor: datos.kilometros 763 valor: datos.kilometros
806 }); 764 });
807 } else { 765 } else {
808 $scope.$broadcast('removeCabecera', 'Bomba:'); 766 $scope.$broadcast('removeCabecera', 'Bomba:');
809 $scope.$broadcast('removeCabecera', 'Kilometros:'); 767 $scope.$broadcast('removeCabecera', 'Kilometros:');
810 $scope.remito.bomba = false; 768 $scope.remito.bomba = false;
811 $scope.remito.kilometros = null; 769 $scope.remito.kilometros = null;
812 } 770 }
813 771
814 $filter('filter')($scope.botonera, 772 $filter('filter')($scope.botonera,
815 { label: 'Proveedor' })[0].checked = true; 773 { label: 'Proveedor' })[0].checked = true;
816 }, function () { 774 }, function () {
817 $scope.seleccionarTransportista(); 775 $scope.seleccionarTransportista();
818 } 776 }
819 ); 777 );
820 } 778 }
821 }; 779 };
822 780
823 $scope.seleccionarMoneda = function () { 781 $scope.seleccionarMoneda = function () {
824 if (varlidarRemitoFacturado()) { 782 if (varlidarRemitoFacturado()) {
825 var parametrosModal = { 783 var parametrosModal = {
826 titulo: 'Búsqueda de monedas', 784 titulo: 'Búsqueda de monedas',
827 query: '/moneda', 785 query: '/moneda',
828 columnas: [ 786 columnas: [
829 { 787 {
830 propiedad: 'DETALLE', 788 propiedad: 'DETALLE',
831 nombre: 'Nombre' 789 nombre: 'Nombre'
832 }, 790 },
833 { 791 {
834 propiedad: 'SIMBOLO', 792 propiedad: 'SIMBOLO',
835 nombre: 'Símbolo' 793 nombre: 'Símbolo'
836 } 794 }
837 ], 795 ],
838 size: 'md' 796 size: 'md'
839 }; 797 };
840 focaModalService.modal(parametrosModal).then( 798 focaModalService.modal(parametrosModal).then(
841 function (moneda) { 799 function (moneda) {
842 800
843 if (moneda.ID !== 1) { 801 if (moneda.ID !== 1) {
844 $scope.abrirModalCotizacion(moneda); 802 $scope.abrirModalCotizacion(moneda);
845 return; 803 return;
846 } 804 }
847 805
848 crearRemitoService.getCotizacionByIdMoneda(1) 806 crearRemitoService.getCotizacionByIdMoneda(1)
849 .then(function (res) { 807 .then(function (res) {
850 808
851 cotizacionPArgentino = res.data[0].cotizaciones[0]; 809 cotizacionPArgentino = res.data[0].cotizaciones[0];
852 cotizacionPArgentino.moneda = moneda; 810 cotizacionPArgentino.moneda = moneda;
853 811
854 actualizarCabeceraMoneda(cotizacionPArgentino); 812 actualizarCabeceraMoneda(cotizacionPArgentino);
855 813
856 $scope.remito.cotizacion = cotizacionPArgentino; 814 $scope.remito.cotizacion = cotizacionPArgentino;
857 }); 815 });
858 }, function () { 816 }, function () {
859 817
860 } 818 }
861 ); 819 );
862 } 820 }
863 }; 821 };
864 822
865 $scope.seleccionarObservaciones = function () { 823 $scope.seleccionarObservaciones = function () {
866 focaModalService 824 focaModalService
867 .prompt({ 825 .prompt({
868 titulo: 'Observaciones', 826 titulo: 'Observaciones',
869 value: $scope.remito.observaciones, 827 value: $scope.remito.observaciones,
870 textarea: true, 828 textarea: true,
871 readonly: true 829 readonly: true
872 }) 830 })
873 .then(function (observaciones) { 831 .then(function (observaciones) {
874 $scope.remito.observaciones = observaciones; 832 $scope.remito.observaciones = observaciones;
875 }); 833 });
876 }; 834 };
877 835
878 $scope.abrirModalCotizacion = function (moneda) { 836 $scope.abrirModalCotizacion = function (moneda) {
879 var modalInstance = $uibModal.open( 837 var modalInstance = $uibModal.open(
880 { 838 {
881 ariaLabelledBy: 'Busqueda de Cotización', 839 ariaLabelledBy: 'Busqueda de Cotización',
882 templateUrl: 'modal-cotizacion.html', 840 templateUrl: 'modal-cotizacion.html',
883 controller: 'focaModalCotizacionController', 841 controller: 'focaModalCotizacionController',
884 size: 'lg', 842 size: 'lg',
885 resolve: { idMoneda: function () { return moneda.ID; } } 843 resolve: { idMoneda: function () { return moneda.ID; } }
886 } 844 }
887 ); 845 );
888 modalInstance.result.then( 846 modalInstance.result.then(
889 function (cotizacion) { 847 function (cotizacion) {
890 cotizacion.moneda = moneda; 848 cotizacion.moneda = moneda;
891 $scope.remitoIsDirty = true; 849 $scope.remitoIsDirty = true;
892 actualizarCabeceraMoneda(cotizacion); 850 actualizarCabeceraMoneda(cotizacion);
893 $scope.remito.cotizacion = cotizacion; 851 $scope.remito.cotizacion = cotizacion;
894 }, function () { 852 }, function () {
895 853
896 } 854 }
897 ); 855 );
898 }; 856 };
899 857
900 function actualizarCabeceraMoneda(cotizacion) { 858 function actualizarCabeceraMoneda(cotizacion) {
901 859
902 $scope.remito.articulosRemito.forEach(function (art) { 860 $scope.remito.articulosRemito.forEach(function (art) {
903 art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4); 861 art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4);
904 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); 862 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4);
905 }); 863 });
906 864
907 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { 865 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
908 $scope.$broadcast('removeCabecera', 'Moneda:'); 866 $scope.$broadcast('removeCabecera', 'Moneda:');
909 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 867 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
910 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 868 $scope.$broadcast('removeCabecera', 'Cotizacion:');
911 } else { 869 } else {
912 $scope.$broadcast('addCabecera', { 870 $scope.$broadcast('addCabecera', {
913 label: 'Moneda:', 871 label: 'Moneda:',
914 valor: cotizacion.moneda.DETALLE 872 valor: cotizacion.moneda.DETALLE
915 }); 873 });
916 $scope.$broadcast('addCabecera', { 874 $scope.$broadcast('addCabecera', {
917 label: 'Fecha cotizacion:', 875 label: 'Fecha cotizacion:',
918 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 876 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
919 }); 877 });
920 $scope.$broadcast('addCabecera', { 878 $scope.$broadcast('addCabecera', {
921 label: 'Cotizacion:', 879 label: 'Cotizacion:',
922 valor: $filter('number')(cotizacion.VENDEDOR, '2') 880 valor: $filter('number')(cotizacion.VENDEDOR, '2')
923 }); 881 });
924 } 882 }
925 } 883 }
926 884
927 $scope.agregarATabla = function (key) { 885 $scope.agregarATabla = function (key) {
928 if (key === 13) { 886 if (key === 13) {
929 if ($scope.articuloACargar.cantidad === undefined || 887 if ($scope.articuloACargar.cantidad === undefined ||
930 $scope.articuloACargar.cantidad === 0 || 888 $scope.articuloACargar.cantidad === 0 ||
931 $scope.articuloACargar.cantidad === null) { 889 $scope.articuloACargar.cantidad === null) {
932 focaModalService.alert('El valor debe ser al menos 1'); 890 focaModalService.alert('El valor debe ser al menos 1');
933 return; 891 return;
934 } 892 }
935 delete $scope.articuloACargar.sectorCodigo; 893 delete $scope.articuloACargar.sectorCodigo;
936 $scope.remito.articulosRemito.push($scope.articuloACargar); 894 $scope.remito.articulosRemito.push($scope.articuloACargar);
937 $scope.cargando = true; 895 $scope.cargando = true;
938 } 896 }
939 }; 897 };
940 898
941 $scope.quitarArticulo = function (articulo) { 899 $scope.quitarArticulo = function (articulo) {
942 articulo.idRemito = -1; 900 articulo.idRemito = -1;
943 }; 901 };
944 902
945 $scope.articulosFiltro = function () { 903 $scope.articulosFiltro = function () {
946 904
947 var result = $scope.remito.articulosRemito.filter(function (articulo) { 905 var result = $scope.remito.articulosRemito.filter(function (articulo) {
948 return articulo.idRemito >= 0; 906 return articulo.idRemito >= 0;
949 }); 907 });
950 908
951 // Agrego checked en cabecera si hay datos 909 // Agrego checked en cabecera si hay datos
952 if (result.length) { 910 if (result.length) {
953 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = true; 911 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = true;
954 } else { 912 } else {
955 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = false; 913 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = false;
956 } 914 }
957 return result; 915 return result;
958 }; 916 };
959 917
960 $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { 918 $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) {
961 if (key === 13) { 919 if (key === 13) {
962 if (!articulo.cantidad || !articulo.precio) { 920 if (!articulo.cantidad || !articulo.precio) {
963 focaModalService.alert('Los valores deben ser al menos 1'); 921 focaModalService.alert('Los valores deben ser al menos 1');
964 return; 922 return;
965 } else if (articulo.cantidad < 0 || articulo.precio < 0) { 923 } else if (articulo.cantidad < 0 || articulo.precio < 0) {
966 focaModalService.alert('Los valores no pueden ser negativos'); 924 focaModalService.alert('Los valores no pueden ser negativos');
967 return; 925 return;
968 } 926 }
969 articulo.cantidad = tmpCantidad; 927 articulo.cantidad = tmpCantidad;
970 articulo.precio = tmpPrecio; 928 articulo.precio = tmpPrecio;
971 $scope.getTotal(); 929 $scope.getTotal();
972 articulo.editCantidad = articulo.editPrecio = false; 930 articulo.editCantidad = articulo.editPrecio = false;
973 } 931 }
974 }; 932 };
975 933
976 $scope.cancelarEditar = function (articulo) { 934 $scope.cancelarEditar = function (articulo) {
977 $scope.tmpCantidad = articulo.cantidad; 935 $scope.tmpCantidad = articulo.cantidad;
978 $scope.tmpPrecio = articulo.precio; 936 $scope.tmpPrecio = articulo.precio;
979 articulo.editCantidad = articulo.editPrecio = false; 937 articulo.editCantidad = articulo.editPrecio = false;
980 }; 938 };
981 939
982 $scope.cambioEdit = function (articulo, propiedad) { 940 $scope.cambioEdit = function (articulo, propiedad) {
983 if (propiedad === 'cantidad') { 941 if (propiedad === 'cantidad') {
984 articulo.editCantidad = true; 942 articulo.editCantidad = true;
985 } else if (propiedad === 'precio') { 943 } else if (propiedad === 'precio') {
986 articulo.editPrecio = true; 944 articulo.editPrecio = true;
987 } 945 }
988 }; 946 };
989 947
990 $scope.resetFilter = function () { 948 $scope.resetFilter = function () {
991 $scope.articuloACargar = {}; 949 $scope.articuloACargar = {};
992 $scope.cargando = true; 950 $scope.cargando = true;
993 }; 951 };
994 //Recibe aviso si el teclado está en uso 952 //Recibe aviso si el teclado está en uso
995 $rootScope.$on('usarTeclado', function (event, data) { 953 $rootScope.$on('usarTeclado', function (event, data) {
996 if (data) { 954 if (data) {
997 $scope.mostrarTeclado = true; 955 $scope.mostrarTeclado = true;
998 return; 956 return;
999 } 957 }
1000 $scope.mostrarTeclado = false; 958 $scope.mostrarTeclado = false;
1001 }); 959 });
1002 960
1003 $scope.selectFocus = function ($event) { 961 $scope.selectFocus = function ($event) {
1004 // Si el teclado esta en uso no selecciona el valor 962 // Si el teclado esta en uso no selecciona el valor
1005 if ($scope.mostrarTeclado) { 963 if ($scope.mostrarTeclado) {
1006 return; 964 return;
1007 } 965 }
1008 $event.target.select(); 966 $event.target.select();
1009 }; 967 };
1010 968
1011 function addArrayCabecera(array) { 969 function addArrayCabecera(array) {
1012 for (var i = 0; i < array.length; i++) { 970 for (var i = 0; i < array.length; i++) {
1013 $scope.$broadcast('addCabecera', { 971 $scope.$broadcast('addCabecera', {
1014 label: array[i].label, 972 label: array[i].label,
1015 valor: array[i].valor 973 valor: array[i].valor
1016 }); 974 });
1017 } 975 }
1018 } 976 }
1019 977
1020 function rellenar(relleno, longitud) { 978 function rellenar(relleno, longitud) {
1021 relleno = '' + relleno; 979 relleno = '' + relleno;
1022 while (relleno.length < longitud) { 980 while (relleno.length < longitud) {
1023 relleno = '0' + relleno; 981 relleno = '0' + relleno;
1024 } 982 }
1025 return relleno; 983 return relleno;
1026 } 984 }
1027 985
1028 function varlidarRemitoFacturado() { 986 function varlidarRemitoFacturado() {
1029 if ($scope.remito.estado !== 5) { 987 if ($scope.remito.estado !== 5) {
1030 return true; 988 return true;
1031 } else { 989 } else {
1032 focaModalService.alert('No se puede editar un remito facturado'); 990 focaModalService.alert('No se puede editar un remito facturado');
1033 return false(); 991 return false();
1034 } 992 }
1035 } 993 }
1036 994
1037 function salir() { 995 function salir() {
1038 var confirmacion = false; 996 var confirmacion = false;
1039 997
1040 if (!angular.equals($scope.remito, $scope.inicial)) { 998 if (!angular.equals($scope.remito, $scope.inicial)) {
1041 confirmacion = true; 999 confirmacion = true;
1042 } 1000 }
1043 1001
1044 if (confirmacion) { 1002 if (confirmacion) {
1045 focaModalService.confirm( 1003 focaModalService.confirm(
1046 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 1004 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
1047 ).then(function (data) { 1005 ).then(function (data) {
1048 if (data) { 1006 if (data) {
1049 $location.path('/'); 1007 $location.path('/');
1050 } 1008 }
1051 }); 1009 });
1052 } else { 1010 } else {
1053 $location.path('/'); 1011 $location.path('/');
1054 } 1012 }
1055 } 1013 }
1056 1014
1057 function enableObservaciones(val) { 1015 function enableObservaciones(val) {
1058 var boton = $scope.botonera.filter(function (botonObs) { 1016 var boton = $scope.botonera.filter(function (botonObs) {
1059 return botonObs.label === 'Observaciones'; 1017 return botonObs.label === 'Observaciones';
1060 }); 1018 });
1061 boton[0].disable = !val; 1019 boton[0].disable = !val;
1062 } 1020 }
1063 1021
1064 function setearRemito(remito) { 1022 function setearRemito(remito) {
1065 //añado cabeceras 1023 //añado cabeceras
1066 $scope.$broadcast('removeCabecera', 'Moneda:'); 1024 $scope.$broadcast('removeCabecera', 'Moneda:');
1067 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 1025 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
1068 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 1026 $scope.$broadcast('removeCabecera', 'Cotizacion:');
1069 1027
1070 var cabeceras = []; 1028 var cabeceras = [];
1071 1029
1072 if (remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') { 1030 if (remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
1073 cabeceras.push({ 1031 cabeceras.push({
1074 label: 'Moneda:', 1032 label: 'Moneda:',
1075 valor: remito.cotizacion.moneda.DETALLE 1033 valor: remito.cotizacion.moneda.DETALLE
1076 }); 1034 });
1077 cabeceras.push({ 1035 cabeceras.push({
1078 label: 'Fecha cotizacion:', 1036 label: 'Fecha cotizacion:',
1079 valor: $filter('date')(remito.cotizacion.FECHA, 1037 valor: $filter('date')(remito.cotizacion.FECHA,
1080 'dd/MM/yyyy') 1038 'dd/MM/yyyy')
1081 }); 1039 });
1082 cabeceras.push({ 1040 cabeceras.push({
1083 label: 'Cotizacion:', 1041 label: 'Cotizacion:',
1084 valor: $filter('number')(remito.cotizacion.VENDEDOR, 1042 valor: $filter('number')(remito.cotizacion.VENDEDOR,
1085 '2') 1043 '2')
1086 }); 1044 });
1087 } 1045 }
1088 1046
1089 if (remito.cotizacion.moneda) { 1047 if (remito.cotizacion.moneda) {
1090 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 1048 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
1091 } 1049 }
1092 1050
1093 if (remito.cliente.COD) { 1051 if (remito.cliente.COD) {
1094 cabeceras.push({ 1052 cabeceras.push({
1095 label: 'Cliente:', 1053 label: 'Cliente:',
1096 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + 1054 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' +
1097 remito.cliente.NOM 1055 remito.cliente.NOM
1098 }); 1056 });
1099 cabeceras.push({ 1057 cabeceras.push({
1100 label: 'Domicilio:', 1058 label: 'Domicilio:',
1101 valor: remito.domicilioStamp 1059 valor: remito.domicilioStamp
1102 }); 1060 });
1103 1061
1104 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 1062 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
1105 } 1063 }
1106 if (remito.vendedor.NUM) { 1064 if (remito.vendedor.NUM) {
1107 cabeceras.push({ 1065 cabeceras.push({
1108 label: 'Vendedor:', 1066 label: 'Vendedor:',
1109 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + 1067 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) +
1110 ' - ' + remito.vendedor.NOM 1068 ' - ' + remito.vendedor.NOM
1111 }); 1069 });
1112 } 1070 }
1113 if (remito.proveedor.COD) { 1071 if (remito.proveedor.COD) {
1114 cabeceras.push({ 1072 cabeceras.push({
1115 label: 'Proveedor:', 1073 label: 'Proveedor:',
1116 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + 1074 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) +
1117 ' - ' + remito.proveedor.NOM 1075 ' - ' + remito.proveedor.NOM
1118 }); 1076 });
1119 1077
1120 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; 1078 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true;
1121 } 1079 }
1122 if (remito.flete !== undefined && remito.fob !== undefined) { 1080 if (remito.flete !== undefined && remito.fob !== undefined) {
1123 cabeceras.push({ 1081 cabeceras.push({
1124 label: 'Flete:', 1082 label: 'Flete:',
1125 valor: remito.fob ? 'FOB' : ( 1083 valor: remito.fob ? 'FOB' : (
1126 remito.flete ? 'Si' : 'No') 1084 remito.flete ? 'Si' : 'No')
1127 }); 1085 });
1128 } 1086 }
1129 if (remito.remitoPlazo) { 1087 if (remito.remitoPlazo) {
1130 cabeceras.push({ 1088 cabeceras.push({
1131 label: 'Precio condicion:', 1089 label: 'Precio condicion:',
1132 valor: valorPrecioCondicion() + ' ' + 1090 valor: valorPrecioCondicion() + ' ' +
1133 remitoBusinessService.plazoToString(remito.remitoPlazo) 1091 remitoBusinessService.plazoToString(remito.remitoPlazo)
1134 }); 1092 });
1135 1093
1136 $filter('filter')($scope.botonera, 1094 $filter('filter')($scope.botonera,
1137 { label: 'Precios y condiciones' })[0].checked = true; 1095 { label: 'Precios y condiciones' })[0].checked = true;
1138 } 1096 }
1139 function valorPrecioCondicion() { 1097 function valorPrecioCondicion() {
1140 if (remito.idPrecioCondicion > 0) { 1098 if (remito.idPrecioCondicion > 0) {
1141 return remito.precioCondicion.nombre; 1099 return remito.precioCondicion.nombre;
1142 } else { 1100 } else {
1143 return 'Ingreso Manual'; 1101 return 'Ingreso Manual';
1144 } 1102 }
1145 } 1103 }
1146 if (remito.flete === 1) { 1104 if (remito.flete === 1) {
1147 var cabeceraBomba = { 1105 var cabeceraBomba = {
1148 label: 'Bomba', 1106 label: 'Bomba',
1149 valor: remito.bomba === 1 ? 'Si' : 'No' 1107 valor: remito.bomba === 1 ? 'Si' : 'No'
1150 }; 1108 };
1151 if (remito.kilometros) { 1109 if (remito.kilometros) {
1152 var cabeceraKilometros = { 1110 var cabeceraKilometros = {
1153 label: 'Kilometros', 1111 label: 'Kilometros',
1154 valor: remito.kilometros 1112 valor: remito.kilometros
1155 }; 1113 };
1156 cabeceras.push(cabeceraKilometros); 1114 cabeceras.push(cabeceraKilometros);
1157 } 1115 }
1158 cabeceras.push(cabeceraBomba); 1116 cabeceras.push(cabeceraBomba);
1159 } 1117 }
1160 1118
1161 if (remito.idPrecioCondicion > 0) { 1119 if (remito.idPrecioCondicion > 0) {
1162 $scope.idLista = remito.precioCondicion.idListaPrecio; 1120 $scope.idLista = remito.precioCondicion.idListaPrecio;
1163 } else { 1121 } else {
1164 $scope.idLista = -1; 1122 $scope.idLista = -1;
1165 } 1123 }
1166 $scope.puntoVenta = rellenar(remito.sucursal, 4); 1124 $scope.puntoVenta = rellenar(remito.sucursal, 4);
1167 $scope.comprobante = rellenar(remito.numeroRemito, 8); 1125 $scope.comprobante = rellenar(remito.numeroRemito, 8);
1168 $scope.remito = remito; 1126 $scope.remito = remito;
1169 if ($scope.remito.puntosDescarga) { 1127 if ($scope.remito.puntosDescarga) {
1170 var puntosDescarga = $scope.remito.puntosDescarga; 1128 var puntosDescarga = $scope.remito.puntosDescarga;
1171 cabeceras.push({ 1129 cabeceras.push({
1172 label: 'Puntos de descarga: ', 1130 label: 'Puntos de descarga: ',
1173 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntosDescarga)) 1131 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntosDescarga))
1174 }); 1132 });
1175 } 1133 }
1176 $scope.remitoIsDirty = false; 1134 $scope.remitoIsDirty = false;
1177 1135
1178 if ($scope.remito.articulosRemito.length) { 1136 if ($scope.remito.articulosRemito.length) {
1179 $scope.remito.articulosRemito.forEach(function (articulo) { 1137 $scope.remito.articulosRemito.forEach(function (articulo) {
1180 articulo.precio = 1138 articulo.precio =
1181 (articulo.precio / $scope.remito.cotizacion.VENDEDOR).toFixed(4); 1139 (articulo.precio / $scope.remito.cotizacion.VENDEDOR).toFixed(4);
1182 }); 1140 });
1183 } 1141 }
1184 1142
1185 addArrayCabecera(cabeceras); 1143 addArrayCabecera(cabeceras);
1186 } 1144 }
1187 1145
1188 function getLSRemito() { 1146 function getLSRemito() {
1189 var remito = JSON.parse($localStorage.remito || null); 1147 var remito = JSON.parse($localStorage.remito || null);
1190 if (remito) { 1148 if (remito) {
1191 setearRemito(remito); 1149 setearRemito(remito);
1192 delete $localStorage.remito; 1150 delete $localStorage.remito;
1193 } 1151 }
1194 } 1152 }
1195 1153
1196 function deleteCliente() { 1154 function deleteCliente() {
1197 delete $scope.remito.domicilioStamp; 1155 delete $scope.remito.domicilioStamp;
1198 delete $scope.remito.puntosDescarga; 1156 delete $scope.remito.puntosDescarga;
1199 $scope.remito.domicilio = { dom: '' }; 1157 $scope.remito.domicilio = { dom: '' };
1200 $scope.remito.cliente = {}; 1158 $scope.remito.cliente = {};
1201 $scope.$broadcast('removeCabecera', 'Cliente:'); 1159 $scope.$broadcast('removeCabecera', 'Cliente:');
1202 $scope.$broadcast('removeCabecera', 'Domicilio:'); 1160 $scope.$broadcast('removeCabecera', 'Domicilio:');
1203 $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); 1161 $scope.$broadcast('removeCabecera', 'Puntos de descarga:');
1204 } 1162 }
1205 1163
1206 function getCabeceraPuntoDescarga(puntosDescarga) { 1164 function getCabeceraPuntoDescarga(puntosDescarga) {
1207 var puntosStamp = ''; 1165 var puntosStamp = '';
1208 puntosDescarga.forEach(function (punto, idx, arr) { 1166 puntosDescarga.forEach(function (punto, idx, arr) {
1209 puntosStamp += punto.descripcion; 1167 puntosStamp += punto.descripcion;
1210 if ((idx + 1) !== arr.length) puntosStamp += ', '; 1168 if ((idx + 1) !== arr.length) puntosStamp += ', ';
1211 }); 1169 });
1212 return puntosStamp; 1170 return puntosStamp;
1213 } 1171 }
1214 1172
1215 function abrirModalMail(id, cliente, numeroRemito) { 1173 function abrirModalMail(id, cliente, numeroRemito) {
1216 focaModalService.mail( 1174 focaModalService.mail(
1217 { 1175 {
1218 titulo: 'Comprobante de remito Nº ' + numeroRemito, 1176 titulo: 'Comprobante de remito Nº ' + numeroRemito,
1219 descarga: { 1177 descarga: {
1220 nombre: numeroRemito + '.pdf', 1178 nombre: numeroRemito + '.pdf',
1221 url: '/remito/comprobante', 1179 url: '/remito/comprobante',
1222 }, 1180 },
1223 envio: { 1181 envio: {
1224 mailCliente: cliente.MAIL, 1182 mailCliente: cliente.MAIL,
1225 url: '/remito/mail', 1183 url: '/remito/mail',
1226 }, 1184 },
1227 options: { 1185 options: {
1228 idRemito: id 1186 idRemito: id
1229 } 1187 }
1230 } 1188 }
1231 ) 1189 )
1 angular.module('focaCrearRemito') 1 angular.module('focaCrearRemito')
2 .service('crearRemitoService', ['$http', 'API_ENDPOINT', 2 .service('crearRemitoService', ['$http', 'API_ENDPOINT',
3 function($http, API_ENDPOINT) { 3 function($http, API_ENDPOINT) {
4 var route = API_ENDPOINT.URL; 4 var route = API_ENDPOINT.URL;
5 return { 5 return {
6 getVendedorById: function (idVendedor) {
7 return $http.get(route + '/vendedor-cobrador/' + idVendedor);
8 },
6 crearRemito: function(remito) { 9 crearRemito: function(remito) {
7 // TODO: Cambiar para usar el servicio /remito 10 // TODO: Cambiar para usar el servicio /remito
8 return $http.post(route + '/remito', remito); 11 return $http.post(route + '/remito', remito);
9 }, 12 },
10 getRemitoById: function(id) { 13 getRemitoById: function(id) {
11 return $http.get(route + '/remito/obtener/' + id); 14 return $http.get(route + '/remito/obtener/' + id);
12 }, 15 },
13 obtenerRemito: function() { 16 obtenerRemito: function() {
14 return $http.get(route +'/nota-pedido'); 17 return $http.get(route +'/nota-pedido');
15 }, 18 },
16 setRemito: function(remito) { 19 setRemito: function(remito) {
17 this.remito = remito; 20 this.remito = remito;
18 }, 21 },
19 clearRemito: function() { 22 clearRemito: function() {
20 this.remito = undefined; 23 this.remito = undefined;
21 }, 24 },
22 getRemito: function() { 25 getRemito: function() {
23 return this.remito; 26 return this.remito;
24 }, 27 },
25 getArticulosByIdRemito: function(id) { 28 getArticulosByIdRemito: function(id) {
26 return $http.get(route+'/articulos/nota-pedido/'+id); 29 return $http.get(route+'/articulos/nota-pedido/'+id);
27 }, 30 },
28 crearArticulosParaRemito: function(articuloRemito) { 31 crearArticulosParaRemito: function(articuloRemito) {
29 return $http.post(route + '/articulos/remito', 32 return $http.post(route + '/articulos/remito',
30 {articuloRemito: articuloRemito}); 33 {articuloRemito: articuloRemito});
31 }, 34 },
32 getProveedorById: function(id) { 35 getProveedorById: function(id) {
33 return $http.get(API_ENDPOINT.URL + '/proveedor/' + id); 36 return $http.get(API_ENDPOINT.URL + '/proveedor/' + id);
34 }, 37 },
35 getDomiciliosByIdRemito: function(id) { 38 getDomiciliosByIdRemito: function(id) {
36 return $http.get(route +'/nota-pedido/'+id+'/domicilios'); 39 return $http.get(route +'/nota-pedido/'+id+'/domicilios');
37 }, 40 },
38 getDomiciliosByIdCliente: function(id) { 41 getDomiciliosByIdCliente: function(id) {
39 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) 42 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega)
40 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); 43 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id );
41 }, 44 },
42 getPrecioCondicion: function() { 45 getPrecioCondicion: function() {
43 return $http.get(route + '/precio-condicion'); 46 return $http.get(route + '/precio-condicion');
44 }, 47 },
45 getPrecioCondicionById: function(id) { 48 getPrecioCondicionById: function(id) {
46 return $http.get(route + '/precio-condicion/' + id); 49 return $http.get(route + '/precio-condicion/' + id);
47 }, 50 },
48 getPlazoPagoByPrecioCondicion: function(id) { 51 getPlazoPagoByPrecioCondicion: function(id) {
49 return $http.get(route + '/plazo-pago/precio-condicion/'+ id); 52 return $http.get(route + '/plazo-pago/precio-condicion/'+ id);
50 }, 53 },
51 crearFlete: function(flete) { 54 crearFlete: function(flete) {
52 return $http.post(route + '/flete', {flete : flete}); 55 return $http.post(route + '/flete', {flete : flete});
53 }, 56 },
54 crearPlazosParaRemito: function(plazos) { 57 crearPlazosParaRemito: function(plazos) {
55 return $http.post(route + '/plazo-pago/remito', plazos); 58 return $http.post(route + '/plazo-pago/remito', plazos);
56 }, 59 },
57 getCotizacionByIdMoneda: function(id) { 60 getCotizacionByIdMoneda: function(id) {
58 return $http.get(route + '/moneda/' + id); 61 return $http.get(route + '/moneda/' + id);
59 }, 62 },
60 crearEstadoParaRemito: function(estado) { 63 crearEstadoParaRemito: function(estado) {
61 return $http.post(route + '/estado', {estado: estado}); 64 return $http.post(route + '/estado', {estado: estado});
62 }, 65 },
63 getNumeroRemito: function() { 66 getNumeroRemito: function() {
64 return $http.get(route + '/remito/numero-siguiente'); 67 return $http.get(route + '/remito/numero-siguiente');
65 }, 68 },
66 imprimirRemitoByIdRemito: function(idRemito) { 69 imprimirRemitoByIdRemito: function(idRemito) {
67 return $http.get(route + '/remito/comprobante/' + idRemito , { 70 return $http.get(route + '/remito/comprobante/' + idRemito , {
68 responseType: 'arraybuffer' 71 responseType: 'arraybuffer'
69 }); 72 });
70 }, 73 },
71 getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { 74 getPuntosDescargaByClienDom: function(idDomicilio, idCliente) {
72 return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + 75 return $http.get(API_ENDPOINT.URL + '/punto-descarga/' +
73 idDomicilio + '/' + idCliente); 76 idDomicilio + '/' + idCliente);
74 }, 77 },
75 enviarCorreo: function(options) { 78 enviarCorreo: function(options) {
76 return $http.post(API_ENDPOINT.URL + '/remito/mail', options); 79 return $http.post(API_ENDPOINT.URL + '/remito/mail', options);
77 }, 80 },
78 getParametros: function() { 81 getParametros: function() {
79 return $http.get(API_ENDPOINT.URL + '/parametros/remito'); 82 return $http.get(API_ENDPOINT.URL + '/parametros/remito');
80 }, 83 },
81 getBotonera: function() { 84 getBotonera: function() {
82 return [ 85 return [
83 { 86 {
84 label: 'Nota pedido', 87 label: 'Nota pedido',
85 image: 'notaDePedido.png' 88 image: 'notaDePedido.png'
86 }, 89 },
87 { 90 {
88 label: 'Cliente', 91 label: 'Cliente',
89 image: 'cliente.png' 92 image: 'cliente.png'
90 }, 93 },
91 { 94 {
92 label: 'Proveedor', 95 label: 'Proveedor',
93 image: 'proveedor.png' 96 image: 'proveedor.png'
94 }, 97 },
95 { 98 {
96 label: 'Moneda', 99 label: 'Moneda',
97 image: 'moneda.png' 100 image: 'moneda.png'
98 }, 101 },
99 { 102 {
100 label: 'Precios y condiciones', 103 label: 'Precios y condiciones',
101 image: 'precios-condiciones.png' 104 image: 'precios-condiciones.png'
102 }, 105 },
103 { 106 {
104 label: 'Productos', 107 label: 'Productos',
105 image: 'productos.png' 108 image: 'productos.png'
106 }, 109 },
107 { 110 {
108 label: 'Observaciones', 111 label: 'Observaciones',
109 image: 'botonObservaciones.png', 112 image: 'botonObservaciones.png',
110 disable: true 113 disable: true
111 } 114 }
112 ]; 115 ];
113 } 116 }
114 }; 117 };
115 }]); 118 }]);
116 119