Compare View

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