Commit 9231617cb28cd067ec95d1116b3449b97399c0a5

Authored by Marcelo Puebla
Exists in master and in 1 other branch develop

Merge branch 'develop' of git.focasoftware.com:npm/foca-crear-remito

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