Commit 7ccf0d39e88b006fa2054be1f28c1f8e945abc13

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

Merge branch 'master' into 'develop'

Master(mpuebla)

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