Commit 92c64cb9680a5d59f380593c41a44c28e89dbb05

Authored by Marcelo Puebla
Exists in develop

Merge branch 'develop' into 'develop'

Develop

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