Commit 3489d0cd332f847bbf28e52f9db9b782d50e86ad

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'master' into 'develop'

Master(mpuebla)

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