Commit 94969fae0570427ffc283b0b4e5d2db98f29998f

Authored by Luigi
1 parent c93664d299
Exists in master

Boton para domicilio de Entrega

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