Commit 034698b7ad403f56c5691958183756ab9d544033

Authored by Luigi
1 parent 9ceea494a8
Exists in master

Boton elimnar

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