Commit 0b6af05714d9196187799628ffeb0da0232666e4

Authored by Marcelo Puebla
Exists in develop

Merge branch 'master' into 'develop'

Fix variable ruta undefined

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