Commit 13c557af9ef000a9c1634eef1ad585f34a596cba

Authored by Luigi
1 parent f8dd86067a
Exists in master and in 1 other branch develop

setear idLista al seleccionar remito

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