Commit c5dd54f9e4212d474126ddf6d7032ea3a0306960

Authored by Benjamin Rodriguez
1 parent cb5724bba4
Exists in master and in 2 other branches develop, lab

cambio nombre variable

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