Commit 4d0f692eed11226d3d392c28c9a8f4e97bd6bead

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master(efernandez)

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