Commit 793054655b75e5ebf1c8119e4a8aeec57abb9c17

Authored by Mauricio Cattafi
Exists in master and in 1 other branch develop

Merge branch 'develop' into 'master'

Develop

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