Commit a0dc6692896162ca73aeaeed96c40891780f451f

Authored by Eric Fernandez
Exists in master

Merge branch 'develop' into 'master'

Develop

See merge request !67
1 { 1 {
2 "name": "foca-crear-hoja-ruta", 2 "name": "foca-crear-hoja-ruta",
3 "version": "0.0.1", 3 "version": "0.0.1",
4 "description": "foca-crear-hoja-ruta", 4 "description": "foca-crear-hoja-ruta",
5 "main": "index.js", 5 "main": "index.js",
6 "scripts": { 6 "scripts": {
7 "refresh" : "gulp uglify && cp tmp/foca-crear-hoja-ruta.js ../wrapper-demo/node_modules/foca-crear-hoja-ruta/dist/foca-crear-hoja-ruta.min.js",
7 "test": "test.html", 8 "test": "test.html",
8 "compile": "gulp uglify", 9 "compile": "gulp uglify",
9 "gulp-pre-commit": "gulp pre-commit", 10 "gulp-pre-commit": "gulp pre-commit",
10 "postinstall": "npm run compile && gulp clean-post-install", 11 "postinstall": "npm run compile && gulp clean-post-install",
11 "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump git+http://git.focasoftware.com/npm/foca-botonera-facturador.git git+http://git.focasoftware.com/npm/foca-directivas.git git+http://git.focasoftware.com/npm/foca-modal-remito.git" 12 "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump git+http://git.focasoftware.com/npm/foca-botonera-facturador.git git+http://git.focasoftware.com/npm/foca-directivas.git git+http://git.focasoftware.com/npm/foca-modal-remito.git"
12 }, 13 },
13 "pre-commit": [ 14 "pre-commit": [
14 "gulp-pre-commit" 15 "gulp-pre-commit"
15 ], 16 ],
16 "repository": { 17 "repository": {
17 "type": "git", 18 "type": "git",
18 "url": "https://debo.suite.repo/modulos-npm/foca-crear-hoja-ruta.git" 19 "url": "https://debo.suite.repo/modulos-npm/foca-crear-hoja-ruta.git"
19 }, 20 },
20 "author": "Foca Software", 21 "author": "Foca Software",
21 "license": "ISC", 22 "license": "ISC",
22 "devDependencies": { 23 "devDependencies": {
23 "angular": "^1.7.5", 24 "angular": "^1.7.5",
24 "angular-ladda": "^0.4.3", 25 "angular-ladda": "^0.4.3",
25 "angular-mocks": "^1.7.7", 26 "angular-mocks": "^1.7.7",
26 "angular-route": "^1.7.5", 27 "angular-route": "^1.7.5",
27 "bootstrap": "^4.1.3", 28 "bootstrap": "^4.1.3",
28 "foca-botonera-facturador": "git+http://git.focasoftware.com/npm/foca-botonera-facturador.git", 29 "foca-botonera-facturador": "git+http://git.focasoftware.com/npm/foca-botonera-facturador.git",
29 "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", 30 "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git",
30 "foca-modal-remito": "git+http://git.focasoftware.com/npm/foca-modal-remito.git", 31 "foca-modal-remito": "git+http://git.focasoftware.com/npm/foca-modal-remito.git",
31 "font-awesome": "^4.7.0", 32 "font-awesome": "^4.7.0",
32 "gulp": "^3.9.1", 33 "gulp": "^3.9.1",
33 "gulp-angular-templatecache": "^2.2.5", 34 "gulp-angular-templatecache": "^2.2.5",
34 "gulp-clean": "^0.4.0", 35 "gulp-clean": "^0.4.0",
35 "gulp-concat": "^2.6.1", 36 "gulp-concat": "^2.6.1",
36 "gulp-connect": "^5.6.1", 37 "gulp-connect": "^5.6.1",
37 "gulp-htmlmin": "^5.0.1", 38 "gulp-htmlmin": "^5.0.1",
38 "gulp-jshint": "^2.1.0", 39 "gulp-jshint": "^2.1.0",
39 "gulp-rename": "^1.4.0", 40 "gulp-rename": "^1.4.0",
40 "gulp-replace": "^1.0.0", 41 "gulp-replace": "^1.0.0",
41 "gulp-sequence": "^1.0.0", 42 "gulp-sequence": "^1.0.0",
42 "gulp-uglify": "^3.0.1", 43 "gulp-uglify": "^3.0.1",
43 "jasmine-core": "^3.3.0", 44 "jasmine-core": "^3.3.0",
44 "jquery": "^3.3.1", 45 "jquery": "^3.3.1",
45 "jshint": "^2.9.6", 46 "jshint": "^2.9.6",
46 "ladda": "1.0.6", 47 "ladda": "1.0.6",
47 "pre-commit": "^1.2.2", 48 "pre-commit": "^1.2.2",
48 "pump": "^3.0.0", 49 "pump": "^3.0.0",
49 "ui-bootstrap4": "^3.0.5" 50 "ui-bootstrap4": "^3.0.5"
50 } 51 }
51 } 52 }
52 53
src/js/controller.js
1 angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl', 1 angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
2 [ 2 [
3 '$scope', 3 '$scope',
4 '$uibModal', 4 '$uibModal',
5 '$location', 5 '$location',
6 '$filter', 6 '$filter',
7 '$timeout', 7 '$timeout',
8 'focaCrearHojaRutaService', 8 'focaCrearHojaRutaService',
9 'focaModalService', 9 'focaModalService',
10 'focaBotoneraLateralService', 10 'focaBotoneraLateralService',
11 'focaLoginService', 11 'focaLoginService',
12 '$localStorage', 12 '$localStorage',
13 'hojaRutaBusinessService', 13 'hojaRutaBusinessService',
14 '$cookies', 14 '$cookies',
15 function ($scope, $uibModal, $location, $filter, $timeout, 15 function ($scope, $uibModal, $location, $filter, $timeout,
16 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, 16 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService,
17 focaLoginSrv, $localStorage, hojaRutaBusinessService, $cookies) { 17 focaLoginSrv, $localStorage, hojaRutaBusinessService, $cookies) {
18
18 config(); 19 config();
19 20
20 function config() { 21 function config() {
21 22
22 $scope.botoneraPrincipal ? false : $scope.botoneraPrincipal = 23 $scope.botoneraPrincipal ? false : $scope.botoneraPrincipal =
23 focaCrearHojaRutaService.getBotones(); 24 focaCrearHojaRutaService.getBotones();
24 $scope.botonera = []; 25 $scope.botonera = [];
25 $scope.datepickerAbierto = false; 26 $scope.datepickerAbierto = false;
26 $scope.show = false; 27 $scope.show = false;
27 $scope.cisternaCargas = []; 28 $scope.cisternaCargas = [];
28 $scope.cargando = true; 29 $scope.cargando = true;
29 $scope.articulos = []; 30 $scope.articulos = [];
30 $scope.remito = { 31 $scope.remito = {
31 id: '', 32 id: '',
32 numeroRemito: '' 33 numeroRemito: ''
33 }; 34 };
34 $scope.now = new Date(); 35 $scope.now = new Date();
35 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); 36 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4);
36 $scope.comprobante = $filter('rellenarDigitos')(0, 8); 37 $scope.comprobante = $filter('rellenarDigitos')(0, 8);
37 38
38 //SETEO BOTONERA LATERAL 39 //SETEO BOTONERA LATERAL
39 $timeout(function () { 40 $timeout(function () {
40 focaBotoneraLateralService.showSalir(false); 41 focaBotoneraLateralService.showSalir(false);
41 focaBotoneraLateralService.showPausar(true); 42 focaBotoneraLateralService.showPausar(true);
42 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); 43 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta);
43 focaBotoneraLateralService.addCustomButton('Salir', salir); 44 focaBotoneraLateralService.addCustomButton('Salir', salir);
44 }); 45 });
45 46
46 focaCrearHojaRutaService.getParametros().then(function (res) { 47 focaCrearHojaRutaService.getParametros().then(function (res) {
47 48
48 var parametros = JSON.parse(res.data[0].jsonText); 49 var parametros = JSON.parse(res.data[0].jsonText);
49 50
50 $timeout(function () { 51 $timeout(function () {
51 getLSBotoneraPrincipal(); 52 getLSBotoneraPrincipal();
52 }); 53 });
53 54
54 if ($localStorage.data) { 55 if ($localStorage.data) {
55 $timeout(function () { 56 $timeout(function () {
56 getLSHojaRuta(); 57 getLSHojaRuta();
57 }); 58 });
58 59
59 } else { 60 } else {
60 for (var property in parametros) { 61 for (var property in parametros) {
61 $scope.hojaRuta[property] = parametros[property]; 62 $scope.hojaRuta[property] = parametros[property];
62 $scope.inicial[property] = parametros[property]; 63 $scope.inicial[property] = parametros[property];
63 } 64 }
64 //Setear Hoja de Ruta 65 //Setear Hoja de Ruta
65 66
66 if ($scope.remitoAbierto || $scope.cargaRemito || $scope.precargado) { 67 if ($scope.remitoAbierto || $scope.cargaRemito || $scope.precargado) {
67 setearHojaRuta($scope.hojaRuta); 68 setearHojaRuta($scope.hojaRuta);
68 } 69 }
69 } 70 }
70 }); 71 });
71 init(); 72 init();
72 } 73 }
73 function init() { 74 function init() {
74 $scope.$broadcast('cleanCabecera'); 75 $scope.$broadcast('cleanCabecera');
75 76
76 $scope.hojaRuta = { 77 $scope.hojaRuta = {
77 fecha: new Date(), 78 fecha: new Date(),
78 litros: 0, 79 litros: 0,
79 chofer: {}, 80 chofer: {},
80 vehiculo: { 81 vehiculo: {
81 capacidad: 0 82 capacidad: 0
82 }, 83 },
83 transportista: {}, 84 transportista: {},
84 remitosTabla: [] 85 remitosTabla: []
85 }; 86 };
86 $scope.idLista = undefined; 87 $scope.idLista = undefined;
87 88
88 focaCrearHojaRutaService.getNumeroHojaRuta().then( 89 focaCrearHojaRutaService.getNumeroHojaRuta().then(
89 function (res) { 90 function (res) {
90 $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4); 91 $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4);
91 $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8); 92 $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8);
92 }, 93 },
93 function (err) { 94 function (err) {
94 focaModalService.alert('La terminal no esta configurada correctamente'); 95 focaModalService.alert('La terminal no esta configurada correctamente');
95 console.info(err); 96 console.info(err);
96 } 97 }
97 ); 98 );
98 $scope.inicial = angular.copy($scope.hojaRuta); 99 $scope.inicial = angular.copy($scope.hojaRuta);
99 } 100 }
100 101
101 $scope.$watchGroup(['hojaRuta','precargado','cargaRemito','remitoAbierto'], function(newValues) { 102 $scope.$watchGroup(['hojaRuta', 'precargado', 'cargaRemito', 'remitoAbierto'],
102 focaBotoneraLateralService.setPausarData( 103 function (newValues) {
103 { 104 focaBotoneraLateralService.setPausarData(
104 label: 'data', 105 {
105 val: newValues 106 label: 'data',
106 } 107 val: newValues
107 ); 108 }
108 }); 109 );
110 });
109 111
110 $scope.seleccionarRemitoAbierto = function () { 112 $scope.seleccionarRemitoAbierto = function () {
111 $scope.remitoAbierto = true; 113 $scope.remitoAbierto = true;
112 $scope.cargaRemito = false; 114 $scope.cargaRemito = false;
113 $scope.precargado = false; 115 $scope.precargado = false;
114 116
115 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 117 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
116 $scope.$broadcast('cleanCabecera'); 118 $scope.$broadcast('cleanCabecera');
117 focaModalService.confirm('Se perderan los cambios') 119 focaModalService.confirm('Se perderan los cambios')
118 .then(function () { 120 .then(function () {
119 limpiarBotonera($scope.botonera); 121 limpiarBotonera($scope.botonera);
120 limpiarBotonera($scope.botoneraPrincipal); 122 limpiarBotonera($scope.botoneraPrincipal);
121 $filter('filter')($scope.botoneraPrincipal, { 123 $filter('filter')($scope.botoneraPrincipal, {
122 label: 'Remito Abierto', 124 label: 'Remito Abierto',
123 })[0].checked = true; 125 })[0].checked = true;
124 126
125 config(); 127 config();
126 128
127 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto(); 129 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
128 }); 130 });
129 } else { 131 } else {
130 $scope.$broadcast('cleanCabecera'); 132 $scope.$broadcast('cleanCabecera');
131 limpiarBotonera($scope.botoneraPrincipal); 133 limpiarBotonera($scope.botoneraPrincipal);
132 $filter('filter')($scope.botoneraPrincipal, { 134 $filter('filter')($scope.botoneraPrincipal, {
133 label: 'Remito Abierto', 135 label: 'Remito Abierto',
134 })[0].checked = true; 136 })[0].checked = true;
135 137
136 config(); 138 config();
137 139
138 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto(); 140 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
139 } 141 }
140 }; 142 };
141 143
142 $scope.seleccionarCargarRemitos = function () { 144 $scope.seleccionarCargarRemitos = function () {
143 $scope.cargaRemito = true; 145 $scope.cargaRemito = true;
144 $scope.remitoAbierto = false; 146 $scope.remitoAbierto = false;
145 $scope.precargado = false; 147 $scope.precargado = false;
146 148
147 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 149 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
148 $scope.$broadcast('cleanCabecera'); 150 $scope.$broadcast('cleanCabecera');
149 focaModalService.confirm('Se perderan los cambios') 151 focaModalService.confirm('Se perderan los cambios')
150 .then(function () { 152 .then(function () {
151 limpiarBotonera($scope.botonera); 153 limpiarBotonera($scope.botonera);
152 limpiarBotonera($scope.botoneraPrincipal); 154 limpiarBotonera($scope.botoneraPrincipal);
153 $scope.preCargados = false; 155 $scope.preCargados = false;
154 $filter('filter')($scope.botoneraPrincipal, { 156 $filter('filter')($scope.botoneraPrincipal, {
155 label: 'Cargar Remitos', 157 label: 'Cargar Remitos',
156 })[0].checked = true; 158 })[0].checked = true;
157 159
158 config(); 160 config();
159 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 161 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
160 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito(); 162 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito();
161 }); 163 });
162 } else { 164 } else {
163 $scope.$broadcast('cleanCabecera'); 165 $scope.$broadcast('cleanCabecera');
164 limpiarBotonera($scope.botoneraPrincipal); 166 limpiarBotonera($scope.botoneraPrincipal);
165 $filter('filter')($scope.botoneraPrincipal, { 167 $filter('filter')($scope.botoneraPrincipal, {
166 label: 'Cargar Remitos', 168 label: 'Cargar Remitos',
167 })[0].checked = true; 169 })[0].checked = true;
168 config(); 170 config();
169 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 171 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
170 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito(); 172 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito();
171 } 173 }
172 $scope.precargado = false; 174 $scope.precargado = false;
173 }; 175 };
174 176
175 $scope.seleccionarPrecargados = function () { 177 $scope.seleccionarPrecargados = function () {
176 $scope.precargado = true; 178 $scope.precargado = true;
177 $scope.cargaRemito = false; 179 $scope.cargaRemito = false;
178 $scope.remitoAbierto = false; 180 $scope.remitoAbierto = false;
179 181
180 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 182 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
181 focaModalService.confirm('Se perderan los cambios') 183 focaModalService.confirm('Se perderan los cambios')
182 .then(function () { 184 .then(function () {
183 $scope.$broadcast('cleanCabecera'); 185 $scope.$broadcast('cleanCabecera');
184 limpiarBotonera($scope.botonera); 186 limpiarBotonera($scope.botonera);
185 limpiarBotonera($scope.botoneraPrincipal); 187 limpiarBotonera($scope.botoneraPrincipal);
186 $filter('filter')($scope.botoneraPrincipal, { 188 $filter('filter')($scope.botoneraPrincipal, {
187 label: 'Precargado', 189 label: 'Precargado',
188 })[0].checked = true; 190 })[0].checked = true;
189 191
190 config(); 192 config();
191 193
192 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado(); 194 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado();
193 }); 195 });
194 } else { 196 } else {
195 $scope.$broadcast('cleanCabecera'); 197 $scope.$broadcast('cleanCabecera');
196 limpiarBotonera($scope.botoneraPrincipal); 198 limpiarBotonera($scope.botoneraPrincipal);
197 $filter('filter')($scope.botoneraPrincipal, { 199 $filter('filter')($scope.botoneraPrincipal, {
198 label: 'Precargado', 200 label: 'Precargado',
199 })[0].checked = true; 201 })[0].checked = true;
200 202
201 config(); 203 config();
202 204
203 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado(); 205 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado();
204 } 206 }
205 }; 207 };
206 208
207 $scope.quitarArticulo = function (key) { 209 $scope.quitarArticulo = function (key) {
208 $scope.articulos.splice(key, 1); 210 $scope.articulos.splice(key, 1);
209 }; 211 };
210 212
211 function validarHojaRuta() { 213 function validarHojaRuta() {
212 if ($scope.precargado) { 214 if ($scope.precargado) {
213 if (!$scope.hojaRuta.chofer.id) { 215 if (!$scope.hojaRuta.chofer.id) {
214 focaModalService.alert('Ingrese Chofer'); 216 focaModalService.alert('Ingrese Chofer');
215 return false; 217 return false;
216 } 218 }
217 if (!$scope.hojaRuta.vehiculo.id) { 219 if (!$scope.hojaRuta.vehiculo.id) {
218 focaModalService.alert('Ingrese Vehiculo'); 220 focaModalService.alert('Ingrese Vehiculo');
219 return false; 221 return false;
220 } 222 }
221 if (!$scope.hojaRuta.transportista.COD) { 223 if (!$scope.hojaRuta.transportista.COD) {
222 focaModalService.alert('Ingrese Transportista'); 224 focaModalService.alert('Ingrese Transportista');
223 return false; 225 return false;
224 } 226 }
225 if (!$scope.hojaRuta.datosExtra) { 227 if (!$scope.hojaRuta.datosExtra) {
226 focaModalService.alert('Ingrese Datos extra'); 228 focaModalService.alert('Ingrese Datos extra');
227 return false; 229 return false;
228 } 230 }
229 } else if ($scope.cargaRemito) { 231 } else if ($scope.cargaRemito) {
230 if (!$scope.hojaRuta.remitosTabla.length) { 232 if (!$scope.hojaRuta.remitosTabla.length) {
231 focaModalService.alert('Ingrese Remitos'); 233 focaModalService.alert('Ingrese Remitos');
232 return false; 234 return false;
233 } else if (!$scope.hojaRuta.chofer.id) { 235 } else if (!$scope.hojaRuta.chofer.id) {
234 focaModalService.alert('Ingrese Chofer'); 236 focaModalService.alert('Ingrese Chofer');
235 return false; 237 return false;
236 } 238 }
237 if (!$scope.hojaRuta.vehiculo.id) { 239 if (!$scope.hojaRuta.vehiculo.id) {
238 focaModalService.alert('Ingrese Vehiculo'); 240 focaModalService.alert('Ingrese Vehiculo');
239 return false; 241 return false;
240 } 242 }
241 if (!$scope.hojaRuta.transportista.COD) { 243 if (!$scope.hojaRuta.transportista.COD) {
242 focaModalService.alert('Ingrese Transportista'); 244 focaModalService.alert('Ingrese Transportista');
243 return false; 245 return false;
244 } 246 }
245 if (!$scope.hojaRuta.datosExtra) { 247 if (!$scope.hojaRuta.datosExtra) {
246 focaModalService.alert('Ingrese Datos extra'); 248 focaModalService.alert('Ingrese Datos extra');
247 return false; 249 return false;
248 } 250 }
249 } else if ($scope.remitoAbierto) { 251 } else if ($scope.remitoAbierto) {
250 if (!$scope.hojaRuta.transportista.COD) { 252 if (!$scope.hojaRuta.transportista.COD) {
251 focaModalService.alert('Ingrese Transportista'); 253 focaModalService.alert('Ingrese Transportista');
252 return false; 254 return false;
253 } else if (!$scope.hojaRuta.vehiculo.id) { 255 } else if (!$scope.hojaRuta.vehiculo.id) {
254 focaModalService.alert('Ingrese Vehiculo'); 256 focaModalService.alert('Ingrese Vehiculo');
255 return false; 257 return false;
256 } else if (!$scope.hojaRuta.chofer.id) { 258 } else if (!$scope.hojaRuta.chofer.id) {
257 focaModalService.alert('Ingrese Chofer'); 259 focaModalService.alert('Ingrese Chofer');
258 return false; 260 return false;
259 } else if (!$scope.hojaRuta.proveedor.COD) { 261 } else if (!$scope.hojaRuta.proveedor.COD) {
260 focaModalService.alert('Ingrese Proveedor'); 262 focaModalService.alert('Ingrese Proveedor');
261 return false; 263 return false;
262 } else if (!$scope.hojaRuta.cliente.COD) { 264 } else if (!$scope.hojaRuta.cliente.COD) {
263 focaModalService.alert('Ingrese un Cliente'); 265 focaModalService.alert('Ingrese un Cliente');
264 return; 266 return;
265 } 267 }
266 } 268 }
267 return true; 269 return true;
268 270
269 } 271 }
270 272
271 function getImporte(propiedad) { 273 function getImporte(propiedad) {
272 var importe = 0; 274 var importe = 0;
273 275
274 $scope.articulos.forEach(function (articulo) { 276 $scope.articulos.forEach(function (articulo) {
275 277
276 if (articulo[propiedad]) { 278 if (articulo[propiedad]) {
277 importe += articulo[propiedad] * articulo.cantidad; 279 importe += articulo[propiedad] * articulo.cantidad;
278 } 280 }
279 return; 281 return;
280 282
281 }); 283 });
282 284
283 return importe; 285 return importe;
284 } 286 }
285 287
286 function guardarRemitoAbierto() { 288 function guardarRemitoAbierto() {
287 //guardar nuevo objeto (?) 289 //guardar nuevo objeto (?)
288 var date = new Date(); 290 var date = new Date();
289 if ($scope.hojaRuta !== null) { 291 if ($scope.hojaRuta !== null) {
290 focaBotoneraLateralService.startGuardar(); 292 focaBotoneraLateralService.startGuardar();
291 var save = { 293 var save = {
292 remito: { 294 remito: {
293 id: 0, 295 id: 0,
294 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), 296 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
295 idCliente: $scope.hojaRuta.cliente.COD, 297 idCliente: $scope.hojaRuta.cliente.COD,
296 nombreCliente: $scope.hojaRuta.cliente.NOM, 298 nombreCliente: $scope.hojaRuta.cliente.NOM,
297 cuitCliente: $scope.hojaRuta.cliente.CUIT, 299 cuitCliente: $scope.hojaRuta.cliente.CUIT,
298 idVendedor: $cookies.get('vendedorCobrador'), 300 idVendedor: $cookies.get('vendedorCobrador'),
299 idProveedor: $scope.hojaRuta.proveedor.COD, 301 idProveedor: $scope.hojaRuta.proveedor.COD,
300 idDomicilio: $scope.hojaRuta.idDomicilio || 302 idDomicilio: $scope.hojaRuta.idDomicilio ||
301 $scope.hojaRuta.domicilio.id, 303 $scope.hojaRuta.domicilio.id,
302 idCotizacion: $scope.hojaRuta.cotizacion.ID, 304 idCotizacion: $scope.hojaRuta.cotizacion.ID,
303 domicilioStamp: $scope.hojaRuta.domicilioStamp, 305 domicilioStamp: $scope.hojaRuta.domicilioStamp,
304 observaciones: $scope.hojaRuta.observaciones, 306 observaciones: $scope.hojaRuta.observaciones,
305 idListaPrecio: $scope.hojaRuta.cliente.MOD.trim(), 307 idListaPrecio: $scope.hojaRuta.cliente.MOD.trim(),
306 total: getImporte('total') || 0, 308 total: getImporte('total') || 0,
307 descuento: 0,//TODO, 309 descuento: 0,//TODO,
308 importeNeto: getImporte('netoUnitario') || 0, //TODO: arreglar, 310 importeNeto: getImporte('netoUnitario') || 0, //TODO: arreglar,
309 importeExento: getImporte('exentoUnitario'), 311 importeExento: getImporte('exentoUnitario'),
310 importeIva: getImporte('ivaUnitario') || 0, //TODO: arreglar 312 importeIva: getImporte('ivaUnitario') || 0, //TODO: arreglar
311 importeIvaServicios: 0,//TODO 313 importeIvaServicios: 0,//TODO
312 importeImpuestoInterno: getImporte('impuestoInternoUnitario'), 314 importeImpuestoInterno: getImporte('impuestoInternoUnitario'),
313 importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'), 315 importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'),
314 importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'), 316 importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'),
315 percepcion: 0,//TODO 317 percepcion: 0,//TODO
316 percepcionIva: 0,//TODO 318 percepcionIva: 0,//TODO
317 redondeo: 0,//TODO 319 redondeo: 0,//TODO
318 anulado: false, 320 anulado: false,
319 planilla: $filter('date')($scope.now, 'ddMMyyyy'), 321 planilla: $filter('date')($scope.now, 'ddMMyyyy'),
320 lugar: parseInt($scope.puntoVenta), 322 lugar: parseInt($scope.puntoVenta),
321 cuentaMadre: 0,//TODO 323 cuentaMadre: 0,//TODO
322 cuentaContable: 0,//TODO 324 cuentaContable: 0,//TODO
323 asiento: 0,//TODO 325 asiento: 0,//TODO
324 e_hd: '',//TODO 326 e_hd: '',//TODO
325 c_hd: '', 327 c_hd: '',
326 numeroLiquidoProducto: 0,//TODO 328 numeroLiquidoProducto: 0,//TODO
327 estado: 0, 329 estado: 0,
328 destinoVenta: 0,//TODO 330 destinoVenta: 0,//TODO
329 operacionTipo: 0, //TODO 331 operacionTipo: 0, //TODO
332 flete: false,
333 fob: false,
334 bomba: false,
330 }, 335 },
331 notaPedido: { 336 notaPedido: {
332 id: 0 337 id: 0
333 } 338 }
334 }; 339 };
335 focaCrearHojaRutaService.crearRemito(save).then( 340 focaCrearHojaRutaService.crearRemito(save).then(
336 function (data) { 341 function (data) {
337 focaBotoneraLateralService.endGuardar(true); 342 focaBotoneraLateralService.endGuardar(true);
338 $scope.saveLoading = false; 343 $scope.saveLoading = false;
339 344
340 $scope.remito.id = data.data.id; 345 $scope.remito.id = data.data.id;
341 346
342 focaCrearHojaRutaService.guardarCisternas({ 347 focaCrearHojaRutaService.guardarCisternas({
343 cisternaCargas: $scope.cisternaCargas, 348 cisternaCargas: $scope.cisternaCargas,
344 cisternaMovimientos: $scope.cisternaMovimientos, 349 cisternaMovimientos: $scope.cisternaMovimientos,
345 fechaReparto: $scope.hojaRuta.fechaReparto, 350 fechaReparto: $scope.hojaRuta.fechaReparto,
346 idVehiculo: $scope.hojaRuta.vehiculo.id 351 idVehiculo: $scope.hojaRuta.vehiculo.id
347 }, data.data.id); 352 }, data.data.id);
348 $scope.remito.numeroRemito = data.data.numero; 353 $scope.remito.numeroRemito = data.data.numero;
349 354
350 // if ($scope.remito.remitoPuntoDescarga.length > 0) { 355 // if ($scope.remito.remitoPuntoDescarga.length > 0) {
351 // remitoBusinessService.addPuntosDescarga(data.data.id, 356 // remitoBusinessService.addPuntosDescarga(data.data.id,
352 // $scope.remito.remitoPuntoDescarga); 357 // $scope.remito.remitoPuntoDescarga);
353 // } 358 // }
354 359
355 hojaRutaBusinessService.addArticulos($scope.articulosRecibidos, 360 hojaRutaBusinessService.addArticulos($scope.articulosRecibidos,
356 data.data.id, $scope.hojaRuta.cotizacion.VENDEDOR); 361 data.data.id, $scope.hojaRuta.cotizacion.VENDEDOR);
357 362
358 guardarHojaRuta(data.data.id); 363 guardarHojaRuta(data.data.id);
359 364
360 }, function (error) { 365 }, function (error) {
361 focaModalService.alert( 366 focaModalService.alert(
362 error.data || 'Hubo un error al crear el remito'); 367 error.data || 'Hubo un error al crear el remito');
363 focaBotoneraLateralService.endGuardar(); 368 focaBotoneraLateralService.endGuardar();
364 $scope.saveLoading = false; 369 $scope.saveLoading = false;
365 console.info(error); 370 console.info(error);
366 } 371 }
367 ); 372 );
368 373
369 function guardarHojaRuta(idRemito) { 374 function guardarHojaRuta(idRemito) {
370 375
371 var save2 = { 376 var save2 = {
372 hojaRuta: { 377 hojaRuta: {
373 id: 0, 378 id: 0,
374 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) 379 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19)
375 .replace('T', ' '), 380 .replace('T', ' '),
376 idTransportista: $scope.hojaRuta.transportista.COD, 381 idTransportista: $scope.hojaRuta.transportista.COD,
377 idChofer: $scope.hojaRuta.chofer.id, 382 idChofer: $scope.hojaRuta.chofer.id,
378 idVehiculo: $scope.hojaRuta.vehiculo.id, 383 idVehiculo: $scope.hojaRuta.vehiculo.id,
379 proveedor: $scope.hojaRuta.proveedor.id, 384 proveedor: $scope.hojaRuta.proveedor.id,
380 fechaReparto: new Date($scope.hojaRuta.fechaReparto) 385 fechaReparto: new Date($scope.hojaRuta.fechaReparto)
381 .toISOString() 386 .toISOString()
382 .substring(0, 10), 387 .substring(0, 10),
383 estado: 0, 388 estado: 0,
384 abierta: 1 389 abierta: 1
385 }, 390 },
386 remitos: [{id: idRemito}] 391 remitos: [{ id: idRemito }]
387 }; 392 };
388 393
389 save2.hojaRuta = angular 394 save2.hojaRuta = angular
390 .extend({}, save2.hojaRuta, $scope.hojaRuta.datosExtra); 395 .extend({}, save2.hojaRuta, $scope.hojaRuta.datosExtra);
391 focaCrearHojaRutaService.crearHojaRuta(save2).then( 396 focaCrearHojaRutaService.crearHojaRuta(save2).then(
392 function (data) { 397 function (data) {
393 var remitoNumero; 398 var remitoNumero;
394 data.data.remitos.forEach(function(idRemitos) { 399 data.data.remitos.forEach(function (idRemitos) {
395 remitoNumero = idRemitos; 400 remitoNumero = idRemitos;
396 }); 401 });
397 focaModalService.alert( 402 focaModalService.alert(
398 'Hoja ruta creada Nยบ: ' + 403 'Hoja ruta creada Nยบ: ' +
399 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + 404 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' +
400 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) + 405 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) +
401 '\nRemito Abierto Nยบ: ' + 406 '\nRemito Abierto Nยบ: ' +
402 $filter('rellenarDigitos')(remitoNumero.sucursal, 4) + '-' + 407 $filter('rellenarDigitos')(remitoNumero.sucursal, 4) + '-' +
403 $filter('rellenarDigitos')(remitoNumero.numeroRemito,8) 408 $filter('rellenarDigitos')(remitoNumero.numeroRemito, 8)
404 ); 409 );
405 410
406 config(); 411 config();
407 }, 412 },
408 function (error) { 413 function (error) {
409 414
410 focaModalService 415 focaModalService
411 .alert('Hubo un error al crear la hoja de ruta'); 416 .alert('Hubo un error al crear la hoja de ruta');
412 417
413 console.info(error); 418 console.info(error);
414 } 419 }
415 ); 420 );
416 } 421 }
417 } 422 }
418 } 423 }
419 424
420 $scope.seleccionarCliente = function () { 425 $scope.seleccionarCliente = function () {
421 var modalInstance = $uibModal.open( 426 var modalInstance = $uibModal.open(
422 { 427 {
423 ariaLabelledBy: 'Busqueda de Cliente', 428 ariaLabelledBy: 'Busqueda de Cliente',
424 templateUrl: 'foca-busqueda-cliente-modal.html', 429 templateUrl: 'foca-busqueda-cliente-modal.html',
425 controller: 'focaBusquedaClienteModalController', 430 controller: 'focaBusquedaClienteModalController',
426 resolve: { 431 resolve: {
427 vendedor: function () { return null; }, 432 vendedor: function () { return null; },
428 cobrador: function () { return null; } 433 cobrador: function () { return null; }
429 }, 434 },
430 size: 'lg' 435 size: 'lg'
431 } 436 }
432 ); 437 );
433 modalInstance.result.then( 438 modalInstance.result.then(
434 function (cliente) { 439 function (cliente) {
435 $scope.abrirModalDomicilios(cliente); 440 $scope.abrirModalDomicilios(cliente);
436 $scope.cliente = cliente; 441 $scope.cliente = cliente;
437 }, function () { 442 }, function () {
438 } 443 }
439 ); 444 );
440 }; 445 };
441 446
442 $scope.abrirModalDomicilios = function (cliente) { 447 $scope.abrirModalDomicilios = function (cliente) {
443 var modalInstanceDomicilio = $uibModal.open( 448 var modalInstanceDomicilio = $uibModal.open(
444 { 449 {
445 ariaLabelledBy: 'Busqueda de Domicilios', 450 ariaLabelledBy: 'Busqueda de Domicilios',
446 templateUrl: 'modal-domicilio.html', 451 templateUrl: 'modal-domicilio.html',
447 controller: 'focaModalDomicilioController', 452 controller: 'focaModalDomicilioController',
448 size: 'lg', 453 size: 'lg',
449 resolve: { 454 resolve: {
450 idCliente: function () { return cliente.cod; }, 455 idCliente: function () { return cliente.cod; },
451 esNuevo: function () { return cliente.esNuevo; } 456 esNuevo: function () { return cliente.esNuevo; }
452 } 457 }
453 } 458 }
454 ); 459 );
455 modalInstanceDomicilio.result.then( 460 modalInstanceDomicilio.result.then(
456 function (domicilio) { 461 function (domicilio) {
457 $scope.hojaRuta.domicilio = domicilio; 462 $scope.hojaRuta.domicilio = domicilio;
458 $scope.hojaRuta.cliente = { 463 $scope.hojaRuta.cliente = {
459 COD: cliente.cod, 464 COD: cliente.cod,
460 CUIT: cliente.cuit, 465 CUIT: cliente.cuit,
461 NOM: cliente.nom, 466 NOM: cliente.nom,
462 MAIL: cliente.mail, 467 MAIL: cliente.mail,
463 MOD: cliente.mod, 468 MOD: cliente.mod,
464 IVA: cliente.iva, 469 IVA: cliente.iva,
465 VEN: cliente.ven 470 VEN: cliente.ven
466 }; 471 };
467 focaCrearHojaRutaService.getVendedorById($scope.hojaRuta.cliente.VEN) 472 focaCrearHojaRutaService.getVendedorById($scope.hojaRuta.cliente.VEN)
468 .then(function (res) { 473 .then(function (res) {
469 if (res.data !== '') { 474 if (res.data !== '') {
470 $scope.hojaRuta.vendedor = res.data; 475 $scope.hojaRuta.vendedor = res.data;
471 $scope.$broadcast('addCabecera', { 476 $scope.$broadcast('addCabecera', {
472 label: 'Vendedor:', 477 label: 'Vendedor:',
473 valor: $filter('rellenarDigitos')($scope.hojaRuta.vendedor 478 valor: $filter('rellenarDigitos')($scope.hojaRuta.vendedor
474 .NUM, 3) +' - ' + $scope.hojaRuta.vendedor.NOM 479 .NUM, 3) + ' - ' + $scope.hojaRuta.vendedor.NOM
475 }); 480 });
476 } 481 }
477 var domicilioStamp = 482 var domicilioStamp =
478 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 483 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
479 domicilio.Localidad + ', ' + domicilio.Provincia; 484 domicilio.Localidad + ', ' + domicilio.Provincia;
480 $scope.hojaRuta.domicilioStamp = domicilioStamp; 485 $scope.hojaRuta.domicilioStamp = domicilioStamp;
481 $scope.$broadcast('addCabecera', { 486 $scope.$broadcast('addCabecera', {
482 label: 'Cliente:', 487 label: 'Cliente:',
483 valor: $filter('rellenarDigitos')(cliente.cod, 3) + 488 valor: $filter('rellenarDigitos')(cliente.cod, 3) +
484 ' - ' + cliente.nom 489 ' - ' + cliente.nom
485 }); 490 });
486 $scope.$broadcast('addCabecera', { 491 $scope.$broadcast('addCabecera', {
487 label: 'Domicilio:', 492 label: 'Domicilio:',
488 valor: domicilioStamp 493 valor: domicilioStamp
489 }); 494 });
490 495
491 if (domicilio.verPuntos) { 496 if (domicilio.verPuntos) {
492 delete $scope.hojaRuta.domicilio.verPuntos; 497 delete $scope.hojaRuta.domicilio.verPuntos;
493 $scope.seleccionarPuntosDeDescarga(); 498 $scope.seleccionarPuntosDeDescarga();
494 } else { 499 } else {
495 focaCrearHojaRutaService 500 focaCrearHojaRutaService
496 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) 501 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
497 .then(function (res) { 502 .then(function (res) {
498 if (res.data.length) { 503 if (res.data.length) {
499 $scope.seleccionarPuntosDeDescarga(); 504 $scope.seleccionarPuntosDeDescarga();
500 } 505 }
501 }); 506 });
502 } 507 }
503 508
504 $filter('filter')($scope.botonera, { 509 $filter('filter')($scope.botonera, {
505 label: 'Cliente', 510 label: 'Cliente',
506 })[0].checked = true; 511 })[0].checked = true;
507 }) 512 })
508 .catch(function (e) { console.log(e); }); 513 .catch(function (e) { console.log(e); });
509 }, function () { 514 }, function () {
510 $scope.seleccionarCliente(true); 515 $scope.seleccionarCliente(true);
511 return; 516 return;
512 } 517 }
513 ); 518 );
514 }; 519 };
515 520
516 $scope.seleccionarPuntosDeDescarga = function () { 521 $scope.seleccionarPuntosDeDescarga = function () {
517 if (!$scope.hojaRuta.cliente.COD || !$scope.hojaRuta.domicilio.id) { 522 if (!$scope.hojaRuta.cliente.COD || !$scope.hojaRuta.domicilio.id) {
518 focaModalService.alert('Primero seleccione un cliente y un domicilio'); 523 focaModalService.alert('Primero seleccione un cliente y un domicilio');
519 return; 524 return;
520 } else { 525 } else {
521 var modalInstance = $uibModal.open( 526 var modalInstance = $uibModal.open(
522 { 527 {
523 ariaLabelledBy: 'Bรบsqueda de Puntos de descarga', 528 ariaLabelledBy: 'Bรบsqueda de Puntos de descarga',
524 templateUrl: 'modal-punto-descarga.html', 529 templateUrl: 'modal-punto-descarga.html',
525 controller: 'focaModalPuntoDescargaController', 530 controller: 'focaModalPuntoDescargaController',
526 size: 'lg', 531 size: 'lg',
527 resolve: { 532 resolve: {
528 filters: { 533 filters: {
529 idDomicilio: $scope.remito.domicilio.id, 534 idDomicilio: $scope.remito.domicilio.id,
530 idCliente: $scope.remito.cliente.COD, 535 idCliente: $scope.remito.cliente.COD,
531 articulos: $scope.remito.articulosRemito, 536 articulos: $scope.remito.articulosRemito,
532 puntosDescarga: $scope.remito.remitoPuntoDescarga, 537 puntosDescarga: $scope.remito.remitoPuntoDescarga,
533 domicilio: $scope.remito.domicilio 538 domicilio: $scope.remito.domicilio
534 } 539 }
535 } 540 }
536 } 541 }
537 ); 542 );
538 modalInstance.result.then( 543 modalInstance.result.then(
539 function(puntosDescarga) { 544 function (puntosDescarga) {
540 545
541 puntosDescarga.forEach(function(punto) { 546 puntosDescarga.forEach(function (punto) {
542 $scope.hojaRuta.remitoPuntoDescarga.push( 547 $scope.hojaRuta.remitoPuntoDescarga.push(
543 { 548 {
544 puntoDescarga: punto 549 puntoDescarga: punto
545 } 550 }
546 ); 551 );
547 }); 552 });
548 553
549 $scope.$broadcast('addCabecera', { 554 $scope.$broadcast('addCabecera', {
550 label: 'Puntos de descarga:', 555 label: 'Puntos de descarga:',
551 valor: getCabeceraPuntoDescarga(puntosDescarga) 556 valor: getCabeceraPuntoDescarga(puntosDescarga)
552 }); 557 });
553 }, function () { 558 }, function () {
554 $scope.abrirModalDomicilios($scope.cliente); 559 $scope.abrirModalDomicilios($scope.cliente);
555 } 560 }
556 ); 561 );
557 } 562 }
558 }; 563 };
559 564
560 $scope.seleccionarDetalleDeCarga = function () { 565 $scope.seleccionarDetalleDeCarga = function () {
561 if ($scope.hojaRuta.vehiculo.capacidad === 0) { 566 if ($scope.hojaRuta.vehiculo.capacidad === 0) {
562 focaModalService.alert('Debe ingresar vehiculo'); 567 focaModalService.alert('Debe ingresar vehiculo');
563 return; 568 return;
564 } else { 569 } else {
565 $scope.mostrarDetalle($scope.hojaRuta); 570 $scope.mostrarDetalle($scope.hojaRuta);
566 } 571 }
567 }; 572 };
568 573
569 function getCabeceraPuntoDescarga(puntosDescarga) { 574 function getCabeceraPuntoDescarga(puntosDescarga) {
570 var puntosStamp = ''; 575 var puntosStamp = '';
571 puntosDescarga.forEach(function (punto, idx, arr) { 576 puntosDescarga.forEach(function (punto, idx, arr) {
572 puntosStamp += punto.descripcion; 577 puntosStamp += punto.descripcion;
573 if ((idx + 1) !== arr.length) puntosStamp += ', '; 578 if ((idx + 1) !== arr.length) puntosStamp += ', ';
574 }); 579 });
575 return puntosStamp; 580 return puntosStamp;
576 } 581 }
577 582
578 $scope.crearHojaRuta = function () { 583 $scope.crearHojaRuta = function () {
579 584
580 var continuar = validarHojaRuta(); 585 var continuar = validarHojaRuta();
581 if (!continuar) { 586 if (!continuar) {
582 return; 587 return;
583 } else if ($scope.remitoAbierto) { 588 } else if ($scope.remitoAbierto) {
584 guardarRemitoAbierto(); 589 guardarRemitoAbierto();
585 return; 590 return;
586 } 591 }
587 var date = new Date(); 592 var date = new Date();
588 var save = { 593 var save = {
589 hojaRuta: { 594 hojaRuta: {
590 id: 0, 595 id: 0,
591 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) 596 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19)
592 .replace('T', ' '), 597 .replace('T', ' '),
593 idTransportista: $scope.hojaRuta.transportista.COD, 598 idTransportista: $scope.hojaRuta.transportista.COD,
594 idChofer: $scope.hojaRuta.chofer.id, 599 idChofer: $scope.hojaRuta.chofer.id,
595 idVehiculo: $scope.hojaRuta.vehiculo.id, 600 idVehiculo: $scope.hojaRuta.vehiculo.id,
596 tarifaFlete: $scope.hojaRuta.tarifario, 601 tarifaFlete: $scope.hojaRuta.tarifario,
597 fechaReparto: 602 fechaReparto:
598 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), 603 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10),
599 estado: 0 604 estado: 0
600 }, 605 },
601 remitos: $scope.hojaRuta.remitosTabla 606 remitos: $scope.hojaRuta.remitosTabla
602 }; 607 };
603 608
604 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); 609 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra);
605 focaCrearHojaRutaService.crearHojaRuta(save).then( 610 focaCrearHojaRutaService.crearHojaRuta(save).then(
606 function (data) { 611 function (data) {
607 focaModalService.alert( 612 focaModalService.alert(
608 'Hoja ruta creada Nยบ: ' + 613 'Hoja ruta creada Nยบ: ' +
609 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + 614 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' +
610 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) 615 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) + ' ' +
616 $filter('date')($scope.hojaRuta.fechaReparto, 'dd/MM/yyyy') + '-' +
617 $scope.hojaRuta.orden
611 ); 618 );
612 619
613 config(); 620 config();
614 }, 621 },
615 function (error) { 622 function (error) {
616 focaModalService.alert('Hubo un error al crear la hoja de ruta'); 623 focaModalService.alert('Hubo un error al crear la hoja de ruta');
617 console.info(error); 624 console.info(error);
618 } 625 }
619 ); 626 );
620 }; 627 };
621 628
622 $scope.seleccionarProveedor = function () { 629 $scope.seleccionarProveedor = function () {
623 var parametrosModal = { 630 var parametrosModal = {
624 titulo: 'Bรบsqueda de Proveedor', 631 titulo: 'Bรบsqueda de Proveedor',
625 query: '/proveedor', 632 query: '/proveedor',
626 columnas: [ 633 columnas: [
627 { 634 {
628 nombre: 'Cรณdigo', 635 nombre: 'Cรณdigo',
629 propiedad: 'COD', 636 propiedad: 'COD',
630 filtro: { 637 filtro: {
631 nombre: 'rellenarDigitos', 638 nombre: 'rellenarDigitos',
632 parametro: 5 639 parametro: 5
633 }
634 },
635 {
636 nombre: 'Nombre',
637 propiedad: 'NOM'
638 },
639 {
640 nombre: 'CUIT',
641 propiedad: 'CUIT'
642 } 640 }
643 ], 641 },
644 tipo: 'POST', 642 {
645 json: { razonCuitCod: '' } 643 nombre: 'Nombre',
646 }; 644 propiedad: 'NOM'
647 focaModalService.modal(parametrosModal).then( 645 },
648 function (proveedor) { 646 {
649 $filter('filter')($scope.botonera, { 647 nombre: 'CUIT',
650 label: 'Proveedor', 648 propiedad: 'CUIT'
651 })[0].checked = true; 649 }
650 ],
651 tipo: 'POST',
652 json: { razonCuitCod: '' }
653 };
654 focaModalService.modal(parametrosModal).then(
655 function (proveedor) {
656 $filter('filter')($scope.botonera, {
657 label: 'Proveedor',
658 })[0].checked = true;
652 659
653 $scope.$broadcast('addCabecera', { 660 $scope.$broadcast('addCabecera', {
654 label: 'Proveedor:', 661 label: 'Proveedor:',
655 valor: proveedor.COD + ' - ' + proveedor.NOM 662 valor: proveedor.COD + ' - ' + proveedor.NOM
656 }); 663 });
657 $scope.hojaRuta.proveedor = proveedor; 664 $scope.hojaRuta.proveedor = proveedor;
658 }, function () { } 665 }, function () { }
659 ); 666 );
660 }; 667 };
661 668
662 $scope.seleccionarTransportista = function () { 669 $scope.seleccionarTransportista = function () {
663 if (eligioPreConfirmado()) return; 670 if (eligioPreConfirmado()) return;
664 var parametrosModal = { 671 var parametrosModal = {
665 titulo: 'Bรบsqueda de transportista', 672 titulo: 'Bรบsqueda de transportista',
666 query: '/transportista', 673 query: '/transportista',
667 columnas: [ 674 columnas: [
668 { 675 {
669 nombre: 'Cรณdigo', 676 nombre: 'Cรณdigo',
670 propiedad: 'COD' 677 propiedad: 'COD'
671 }, 678 },
672 { 679 {
673 nombre: 'Nombre', 680 nombre: 'Nombre',
674 propiedad: 'NOM' 681 propiedad: 'NOM'
675 }, 682 },
676 { 683 {
677 nombre: 'CUIT', 684 nombre: 'CUIT',
678 propiedad: 'CUIT' 685 propiedad: 'CUIT'
679 } 686 }
680 ] 687 ]
681 }; 688 };
682 focaModalService.modal(parametrosModal).then( 689 focaModalService.modal(parametrosModal).then(
683 function (proveedor) { 690 function (proveedor) {
684 $scope.hojaRuta.transportista = proveedor; 691 $scope.hojaRuta.transportista = proveedor;
685 $scope.$broadcast('addCabecera', { 692 $scope.$broadcast('addCabecera', {
686 label: 'Transportista:', 693 label: 'Transportista:',
687 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 694 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
688 proveedor.NOM 695 proveedor.NOM
689 }); 696 });
690 697
691 $filter('filter')($scope.botonera, { 698 $filter('filter')($scope.botonera, {
692 label: 'Transportista', 699 label: 'Transportista',
693 })[0].checked = true; 700 })[0].checked = true;
694 }, function () { 701 }, function () {
695 702
696 } 703 }
697 ); 704 );
698 }; 705 };
699 706
700 $scope.seleccionarChofer = function () { 707 $scope.seleccionarChofer = function () {
701 var parametrosModal = { 708 var parametrosModal = {
702 titulo: 'Bรบsqueda de Chofer', 709 titulo: 'Bรบsqueda de Chofer',
703 query: '/chofer', 710 query: '/chofer',
704 columnas: [ 711 columnas: [
705 { 712 {
706 propiedad: 'id', 713 propiedad: 'id',
707 nombre: 'Cรณdigo', 714 nombre: 'Cรณdigo',
708 filtro: { 715 filtro: {
709 nombre: 'rellenarDigitos', 716 nombre: 'rellenarDigitos',
710 parametro: 3 717 parametro: 3
711 } 718 }
712 }, 719 },
713 { 720 {
714 propiedad: 'nombre', 721 propiedad: 'nombre',
715 nombre: 'Nombre' 722 nombre: 'Nombre'
716 }, 723 },
717 { 724 {
718 propiedad: 'dni', 725 propiedad: 'dni',
719 nombre: 'DNI' 726 nombre: 'DNI'
720 }, 727 },
721 { 728 {
722 propiedad: 'telefono', 729 propiedad: 'telefono',
723 nombre: 'Telรฉfono' 730 nombre: 'Telรฉfono'
724 } 731 }
725 ] 732 ]
726 }; 733 };
727 focaModalService.modal(parametrosModal).then( 734 focaModalService.modal(parametrosModal).then(
728 function (chofer) { 735 function (chofer) {
729 $scope.hojaRuta.chofer = chofer; 736 $scope.hojaRuta.chofer = chofer;
730 $scope.$broadcast('addCabecera', { 737 $scope.$broadcast('addCabecera', {
731 label: 'Chofer:', 738 label: 'Chofer:',
732 valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' + chofer.nombre 739 valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' + chofer.nombre
733 }); 740 });
734 741
735 $filter('filter')($scope.botonera, { 742 $filter('filter')($scope.botonera, {
736 label: 'Chofer', 743 label: 'Chofer',
737 })[0].checked = true; 744 })[0].checked = true;
738 }, function () { 745 }, function () {
739 // funcion ejecutada cuando se cancela el modal 746 // funcion ejecutada cuando se cancela el modal
740 } 747 }
741 ); 748 );
742 }; 749 };
743 750
744 $scope.seleccionarVehiculo = function () { 751 $scope.seleccionarVehiculo = function () {
745 if (!eligioFecha() || eligioPreConfirmado()) return; 752 if (!eligioFecha() || eligioPreConfirmado()) return;
746 modalVehiculos(); 753 modalVehiculos();
747 }; 754 };
748 755
749 $scope.seleccionarTarifario = function () { 756 $scope.seleccionarTarifario = function () {
750 focaModalService 757 focaModalService
751 .prompt({ 758 .prompt({
752 titulo: 'Tarifa flete', 759 titulo: 'Tarifa flete',
753 value: $scope.hojaRuta.tarifario 760 value: $scope.hojaRuta.tarifario
754 }) 761 })
755 .then(function (costo) { 762 .then(function (costo) {
756 if (isNaN(costo)) { 763 if (isNaN(costo)) {
757 focaModalService 764 focaModalService
758 .alert('Ingrese un valor vรกlido') 765 .alert('Ingrese un valor vรกlido')
759 .then(function () { 766 .then(function () {
760 $scope.seleccionarTarifario(); 767 $scope.seleccionarTarifario();
761 }); 768 });
762 769
763 return; 770 return;
764 } 771 }
765 772
766 $scope.hojaRuta.tarifario = costo; 773 $scope.hojaRuta.tarifario = costo;
767 $scope.$broadcast('addCabecera', { 774 $scope.$broadcast('addCabecera', {
768 label: 'Tarifario:', 775 label: 'Tarifario:',
769 valor: costo 776 valor: costo
770 }); 777 });
771 778
772 $filter('filter')($scope.botonera, { 779 $filter('filter')($scope.botonera, {
773 label: 'Tarifario', 780 label: 'Tarifario',
774 })[0].checked = true; 781 })[0].checked = true;
775 }); 782 });
776 }; 783 };
777 784
778 $scope.seleccionarRemitos = function () { 785 $scope.seleccionarRemitos = function () {
786
779 if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; 787 if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return;
788
780 var modalInstance = $uibModal.open( 789 var modalInstance = $uibModal.open(
781 { 790 {
782 ariaLabelledBy: 'Busqueda de Remito', 791 ariaLabelledBy: 'Busqueda de Remito',
783 templateUrl: 'foca-modal-remito.html', 792 templateUrl: 'foca-modal-remito.html',
784 controller: 'focaModalRemitoController', 793 controller: 'focaModalRemitoController',
785 size: 'lg', 794 size: 'lg',
786 resolve: { usadoPor: function () { return 'hojaRuta'; } } 795 resolve: { usadoPor: function () { return 'hojaRuta'; } }
787 } 796 }
788 ); 797 );
789 modalInstance.result.then( 798 modalInstance.result
790 function (remito) { 799 .then(function (remito) {
791 // TODO: borrar cuando no se use definitivamente 800 // TODO: borrar cuando no se use definitivamente
792 // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { 801 // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) {
793 // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { 802 // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) {
794 // focaModalService.alert('Remito ya incluido'); 803 // focaModalService.alert('Remito ya incluido');
795 // return; 804 // return;
796 // } 805 // }
797 // } 806 // }
798 807
799 // var litros = 0; 808 // var litros = 0;
800 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { 809 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) {
801 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); 810 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad);
802 // } 811 // }
803 812
804 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { 813 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) {
805 // focaModalService.alert( 814 // focaModalService.alert(
806 // 'Debe ingresar toda la informaciรณn para el transporte' 815 // 'Debe ingresar toda la informaciรณn para el transporte'
807 // ); 816 // );
808 // return; 817 // return;
809 // } 818 // }
810 819
811 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) 820 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad)
812 // { 821 // {
813 // var litrostotales = litros; 822 // var litrostotales = litros;
814 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; 823 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros;
815 // focaModalService.alert( 824 // focaModalService.alert(
816 // 'La carga excede la capacidad disponible del vehiculo. ' + 825 // 'La carga excede la capacidad disponible del vehiculo. ' +
817 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' 826 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros'
818 // ); 827 // );
819 // } 828 // }
820 829
821 // remito.litros = litros; 830 // remito.litros = litros;
822 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; 831 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros;
823 $scope.cargarCisterna(remito.id).then(function () { 832 $scope.cargarCisterna(remito.id)
824 $scope.hojaRuta.remitosTabla.push(remito); 833 .then(function () {
825 $filter('filter')($scope.botonera, { 834 $scope.hojaRuta.remitosTabla.push(remito);
826 label: 'Remitos', 835 $filter('filter')($scope.botonera, {
827 })[0].checked = true; 836 label: 'Remitos',
837 })[0].checked = true;
828 838
829 }, function (error) { 839 })
830 error.then($scope.seleccionarRemitos); 840 .catch(function (error) {
831 }); 841 console.error(error);
832 }, function () { 842 $scope.seleccionarRemitos();
833 // funcion ejecutada cuando se cancela el modal 843 });
834 } 844 })
835 ); 845 .catch(function (e) { console.error(e); });
836 }; 846 };
837 847
838 $scope.seleccionarVehiculosPrecargados = function () { 848 $scope.seleccionarVehiculosPrecargados = function () {
839 if (!eligioFecha()) return; 849 if (!eligioFecha()) return;
840 modalVehiculos(true); 850 modalVehiculos(true);
841 }; 851 };
842 852
843 $scope.cargarCisterna = function (idRemito) { 853 $scope.cargarCisterna = function (idRemito) {
844 if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; 854 if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return;
845 var modalInstance = $uibModal.open( 855 var modalInstance = $uibModal.open(
846 { 856 {
847 ariaLabelledBy: 'Busqueda de Vehiculo', 857 ariaLabelledBy: 'Busqueda de Vehiculo',
848 templateUrl: 'foca-detalle-vehiculo.html', 858 templateUrl: 'foca-detalle-vehiculo.html',
849 controller: 'focaDetalleVehiculo', 859 controller: 'focaDetalleVehiculo',
850 size: 'lg', 860 size: 'lg',
851 resolve: { 861 resolve: {
852 idVehiculo: function () { return $scope.hojaRuta.vehiculo.id; }, 862 idVehiculo: function () { return $scope.hojaRuta.vehiculo.id; },
853 idRemito: function () { return idRemito; }, 863 idRemito: function () { return idRemito; },
854 fechaReparto: function () { return $scope.hojaRuta.fechaReparto; } 864 fechaReparto: function () { return $scope.hojaRuta.fechaReparto; },
865 orden: function () { return $scope.hojaRuta.orden; }
855 } 866 }
856 } 867 }
857 ); 868 );
858 return modalInstance.result; 869 return modalInstance.result;
859 }; 870 };
860 871
861 $scope.seleccionarFechaEntrega = function () { 872 $scope.seleccionarFechaEntrega = function () {
862 873
863 var confirmacion = false; 874 var confirmacion = false;
864 875
865 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 876 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
866 confirmacion = true; 877 confirmacion = true;
867 } 878 }
868 879
869 if (confirmacion) { 880 if (confirmacion) {
870 focaModalService 881 focaModalService
871 .confirm('Si cambia la fecha se perderรกn los datos actuales') 882 .confirm('Si cambia la fecha se perderรกn los datos actuales')
872 .then(function (data) { 883 .then(function (data) {
873 if (data) { 884 if (data) {
874 $scope.hojaRuta.vehiculo.id = undefined; 885 $scope.hojaRuta.vehiculo.id = undefined;
875 $scope.hojaRuta.tarifario = null; 886 $scope.hojaRuta.tarifario = null;
876 $scope.hojaRuta.transportista = {}; 887 $scope.hojaRuta.transportista = {};
877 $scope.hojaRuta.chofer = {}; 888 $scope.hojaRuta.chofer = {};
878 $scope.hojaRuta.datosExtra = undefined; 889 $scope.hojaRuta.datosExtra = undefined;
879 elegirFecha(); 890 elegirFecha();
880 } 891 }
881 }, function () { 892 }, function () {
882 return; 893 return;
883 }); 894 });
884 } else { 895 } else {
885 elegirFecha(); 896 elegirFecha();
886 } 897 }
887 }; 898 };
888 899
889 function setearFecha(fecha) { 900 function setearFecha(fecha) {
890 $timeout(function () { 901 $timeout(function () {
891 $scope.$broadcast('addCabecera', { 902 $scope.$broadcast('addCabecera', {
892 label: 'Fecha de entrega: ', 903 label: 'Fecha de entrega: ',
893 valor: fecha.toLocaleDateString() 904 valor: fecha.toLocaleDateString()
894 }); 905 });
895 $scope.hojaRuta.fechaReparto = fecha; 906 $scope.hojaRuta.fechaReparto = fecha;
896 $scope.inicial.fechaReparto = fecha; 907 $scope.inicial.fechaReparto = fecha;
897 }); 908 });
898 } 909 }
899 910
900 $scope.seleccionarDatosExtra = function () { 911 $scope.seleccionarDatosExtra = function () {
901 var datosHojaRuta = $scope.hojaRuta.datosExtra; 912 var datosHojaRuta = $scope.hojaRuta.datosExtra;
902 var modalInstance = $uibModal.open( 913 var modalInstance = $uibModal.open(
903 { 914 {
904 templateUrl: 'foca-modal-datos-hoja-ruta.html', 915 templateUrl: 'foca-modal-datos-hoja-ruta.html',
905 controller: 'focaModalDatosHojaRutaCtrl', 916 controller: 'focaModalDatosHojaRutaCtrl',
906 size: 'lg', 917 size: 'lg',
907 resolve: { 918 resolve: {
908 parametrosDatos: function () { 919 parametrosDatos: function () {
909 return { 920 return {
910 datosHojaRuta: datosHojaRuta 921 datosHojaRuta: datosHojaRuta
911 }; 922 };
912 } 923 }
913 } 924 }
914 } 925 }
915 ); 926 );
916 return modalInstance.result.then(function (datosExtra) { 927 return modalInstance.result.then(function (datosExtra) {
917 928
918 $filter('filter')($scope.botonera, { 929 $filter('filter')($scope.botonera, {
919 label: 'Datos extra', 930 label: 'Datos extra',
920 })[0].checked = true; 931 })[0].checked = true;
921 932
922 $scope.hojaRuta.datosExtra = datosExtra; 933 $scope.hojaRuta.datosExtra = datosExtra;
923 }, function () { 934 }, function () {
924 //se ejecuta cuando se cancela el modal 935 //se ejecuta cuando se cancela el modal
925 }); 936 });
926 }; 937 };
927 938
928 $scope.desasociarRemito = function (key, idRemito) { 939 $scope.desasociarRemito = function (key, idRemito) {
929 var idsRemito = [idRemito]; 940 var idsRemito = [idRemito];
930 focaModalService.confirm('ยฟEstรก seguro que desea desasociar este remito del' + 941 focaModalService.confirm('ยฟEstรก seguro que desea desasociar este remito del' +
931 ' vehรญculo?').then(function () { 942 ' vehรญculo?').then(function () {
932 focaCrearHojaRutaService.desasociarRemitos(idsRemito, 943 focaCrearHojaRutaService.desasociarRemitos(idsRemito,
933 $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1) 944 $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1)
934 .then(function () { 945 .then(function () {
935 $scope.hojaRuta.remitosTabla.splice(key, 1); 946 $scope.hojaRuta.remitosTabla.splice(key, 1);
936 focaModalService.alert('Remito desasociado con รฉxito'); 947 focaModalService.alert('Remito desasociado con รฉxito');
937 }); 948 });
938 }); 949 });
939 }; 950 };
940 951
941 $scope.verProductosRemito = function (idRemito) { 952 $scope.verProductosRemito = function (idRemito) {
942 var parametrosModal = { 953 var parametrosModal = {
943 titulo: 'Articulos remito', 954 titulo: 'Articulos remito',
944 query: '/articulos/remito/' + idRemito, 955 query: '/articulos/remito/' + idRemito,
945 soloMostrar: true, 956 soloMostrar: true,
946 columnas: [ 957 columnas: [
947 { 958 {
948 nombre: 'Cรณdigo', 959 nombre: 'Cรณdigo',
949 propiedad: 'codigo' 960 propiedad: 'codigo'
950 }, 961 },
951 { 962 {
952 nombre: 'Descripciรณn', 963 nombre: 'Descripciรณn',
953 propiedad: 'descripcion' 964 propiedad: 'descripcion'
954 }, 965 },
955 { 966 {
956 nombre: 'Cantidad', 967 nombre: 'Cantidad',
957 propiedad: 'cantidad' 968 propiedad: 'cantidad'
958 } 969 }
959 ] 970 ]
960 }; 971 };
961 focaModalService.modal(parametrosModal).then(); 972 focaModalService.modal(parametrosModal).then();
962 }; 973 };
963 974
964 $scope.mostrarDetalle = function (hojasRutas) { 975 $scope.mostrarDetalle = function (hojasRutas) {
965 var modalInstance =$uibModal.open( 976 var modalInstance = $uibModal.open(
966 { 977 {
967 ariaLabelledBy: '', 978 ariaLabelledBy: '',
968 templateUrl: 'modal-detalle-carga.html', 979 templateUrl: 'modal-detalle-carga.html',
969 controller: 'focaModalDetalleController', 980 controller: 'focaModalDetalleController',
970 resolve: { 981 resolve: {
971 hojasRutas: function () { return hojasRutas; } 982 parametrosModal: function () {
983 return {
984 hojasRutas: hojasRutas,
985 orden: $scope.hojaRuta.orden
986 };
987 }
972 }, 988 },
973 size: 'lg', 989 size: 'lg',
974 backdrop: false 990 backdrop: false
975 } 991 }
976 ); 992 );
977 return modalInstance.result.then(function (res) { 993 return modalInstance.result
978 res.cisternas.forEach( function (cisterna) { 994 .then(function (res) {
979 $scope.cisternaCargas.push(cisterna.cisternaCarga); 995 res.cisternas.forEach(function (cisterna) {
980 }); 996 $scope.cisternaCargas.push(cisterna.cisternaCarga);
981 $scope.cisternaMovimientos = res.movimientos; 997 });
982 $scope.articulosRecibidos = res.articulos; 998 $scope.cisternaMovimientos = res.movimientos;
983 $scope.articulos = res.articulos; 999 $scope.articulosRecibidos = res.articulos;
984 $filter('filter')($scope.botonera, { 1000 $scope.articulos = res.articulos;
985 label: 'Detalle de Carga', 1001 $filter('filter')($scope.botonera, {
986 })[0].checked = true; 1002 label: 'Detalle de Carga',
987 }, function () { 1003 })[0].checked = true;
988 //se ejecuta cuando se cancela el modal 1004 })
989 }); 1005 .catch(function (e) { console.error(e); });
990 }; 1006 };
991 1007
992 function elegirFecha() { 1008 function elegirFecha() {
993 var fechaEntrega = { 1009 var fechaEntrega = {
994 titulo: 'Fecha de entrega', 1010 titulo: 'Fecha de entrega',
995 minDate: new Date() 1011 minDate: new Date()
996 }; 1012 };
997 focaModalService.modalFecha(fechaEntrega).then(function (fecha) { 1013 focaModalService.modalFecha(fechaEntrega).then(function (fecha) {
998 1014
999 $scope.hojaRuta.fechaReparto = fecha; 1015 $scope.hojaRuta.fechaReparto = fecha;
1000 1016
1001 $scope.$broadcast('addCabecera', { 1017 $scope.$broadcast('addCabecera', {
1002 label: 'Fecha de entrega: ', 1018 label: 'Fecha de entrega: ',
1003 valor: fecha.toLocaleDateString() 1019 valor: fecha.toLocaleDateString()
1004 }); 1020 });
1005 1021
1006 $filter('filter')($scope.botonera, { 1022 $filter('filter')($scope.botonera, {
1007 label: 'Fecha Entrega', 1023 label: 'Fecha Entrega',
1008 })[0].checked = true; 1024 })[0].checked = true;
1009 }); 1025 });
1010 } 1026 }
1011 1027
1012 function eligioPreConfirmado() { 1028 function eligioPreConfirmado() {
1013 if ($scope.eligioPreConfirmado) { 1029 if ($scope.eligioPreConfirmado) {
1014 focaModalService.alert('No puede elegir si eligiรณ un vehiculo pre cargado'); 1030 focaModalService.alert('No puede elegir si eligiรณ un vehiculo pre cargado');
1015 return true; 1031 return true;
1016 } 1032 }
1017 return false; 1033 return false;
1018 } 1034 }
1019 1035
1020 function eligioFecha() { 1036 function eligioFecha() {
1021 if (!$scope.hojaRuta.fechaReparto) { 1037 if (!$scope.hojaRuta.fechaReparto) {
1022 focaModalService.alert('Primero seleccione fecha de reparto'); 1038 focaModalService.alert('Primero seleccione fecha de reparto');
1023 return false; 1039 return false;
1024 } 1040 }
1025 return true; 1041 return true;
1026 } 1042 }
1027 1043
1028 function eligioVehiculo() { 1044 function eligioVehiculo() {
1029 if (!$scope.hojaRuta.vehiculo.id) { 1045 if (!$scope.hojaRuta.vehiculo.id) {
1030 focaModalService.alert('Primero seleccione vehiculo'); 1046 focaModalService.alert('Primero seleccione vehiculo');
1031 return false; 1047 return false;
1032 } 1048 }
1033 return true; 1049 return true;
1034 } 1050 }
1035 1051
1036 function modalVehiculos(preCargados) { 1052 function modalVehiculos(preCargados) {
1053
1037 var parametrosModal = {}; 1054 var parametrosModal = {};
1038 if (preCargados) { 1055 if (preCargados) {
1039 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + 1056 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' +
1040 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); 1057 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10);
1041 parametrosModal.titulo = 'Bรบsqueda de vehiculos precargados'; 1058 parametrosModal.titulo = 'Bรบsqueda de vehiculos precargados';
1042 } else { 1059 } else {
1043 parametrosModal.query = '/vehiculo'; 1060 parametrosModal.query = '/vehiculo';
1044 parametrosModal.titulo = 'Bรบsqueda de vehรญculos'; 1061 parametrosModal.titulo = 'Bรบsqueda de vehรญculos';
1045 } 1062 }
1046 parametrosModal.columnas = [ 1063 parametrosModal.columnas = [
1047 { 1064 {
1048 propiedad: 'codigo', 1065 propiedad: 'codigo',
1049 nombre: 'Cรณdigo' 1066 nombre: 'Cรณdigo'
1050 }, 1067 },
1051 { 1068 {
1052 propiedad: 'tractor', 1069 propiedad: 'tractor',
1053 nombre: 'tractor' 1070 nombre: 'tractor'
1054 }, 1071 },
1055 { 1072 {
1056 propiedad: 'semi', 1073 propiedad: 'semi',
1057 nombre: 'Semi' 1074 nombre: 'Semi'
1058 } 1075 }
1059 ]; 1076 ];
1077
1060 focaModalService.modal(parametrosModal).then(function (vehiculo) { 1078 focaModalService.modal(parametrosModal).then(function (vehiculo) {
1061 if (!preCargados && vehiculoEnUso(vehiculo)) return; 1079 if (!preCargados && vehiculoEnUso(vehiculo)) return;
1062 $scope.hojaRuta.vehiculo = vehiculo; 1080 $scope.hojaRuta.vehiculo = vehiculo;
1063 $scope.hojaRuta.transportista = vehiculo.transportista; 1081 $scope.hojaRuta.transportista = vehiculo.transportista;
1064 // mostrarDetalle(vehiculo); 1082 // mostrarDetalle(vehiculo);
1065 if (preCargados) { 1083 if (preCargados) {
1066 $scope.eligioPreConfirmado = true; 1084 $scope.eligioPreConfirmado = true;
1067 $scope.hojaRuta.vehiculo = vehiculo; 1085 $scope.hojaRuta.vehiculo = vehiculo;
1068 $scope.$broadcast('addCabecera', { 1086 $scope.$broadcast('addCabecera', {
1069 label: 'Transportista:', 1087 label: 'Transportista:',
1070 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + 1088 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) +
1071 ' - ' + vehiculo.transportista.NOM 1089 ' - ' + vehiculo.transportista.NOM
1072 }); 1090 });
1073 focaCrearHojaRutaService 1091 focaCrearHojaRutaService
1074 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) 1092 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto)
1075 .then(function (res) { 1093 .then(function (res) {
1076 $filter('filter')($scope.botonera, { 1094 $filter('filter')($scope.botonera, {
1077 label: 'Transportista', 1095 label: 'Transportista',
1078 })[0].checked = true; 1096 })[0].checked = true;
1079 1097
1080 $filter('filter')($scope.botonera, { 1098 $filter('filter')($scope.botonera, {
1081 label: 'Vehiculo', 1099 label: 'Vehiculo',
1082 })[0].checked = true; 1100 })[0].checked = true;
1083 1101
1084 $scope.hojaRuta.remitosTabla = res.data; 1102 $scope.hojaRuta.remitosTabla = res.data;
1085 }); 1103 });
1086 } else { 1104 } else {
1087 focaCrearHojaRutaService 1105 focaCrearHojaRutaService
1088 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) 1106 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true)
1089 .then(function (res) { 1107 .then(function (res) {
1090 1108
1091 $filter('filter')($scope.botonera, { 1109 $filter('filter')($scope.botonera, {
1092 label: 'Vehiculo', 1110 label: 'Vehiculo',
1093 })[0].checked = true; 1111 })[0].checked = true;
1094 1112
1095 $scope.hojaRuta.remitosTabla = res.data; 1113 $scope.hojaRuta.remitosTabla = res.data;
1096 }); 1114 });
1097 } 1115 }
1116
1117 focaCrearHojaRutaService
1118 .getNumeroOrden(vehiculo.id, $scope.hojaRuta.fechaReparto)
1119 .then(function (res) {
1120 $scope.hojaRuta.orden = res.data;
1121 });
1122
1098 $scope.$broadcast('addCabecera', { 1123 $scope.$broadcast('addCabecera', {
1099 label: 'Tractor:', 1124 label: 'Tractor:',
1100 valor: vehiculo.tractor 1125 valor: vehiculo.tractor
1101 }); 1126 });
1102 $scope.$broadcast('addCabecera', { 1127 $scope.$broadcast('addCabecera', {
1103 label: 'Semi:', 1128 label: 'Semi:',
1104 valor: vehiculo.semi 1129 valor: vehiculo.semi
1105 }); 1130 });
1106 $scope.$broadcast('addCabecera', { 1131 $scope.$broadcast('addCabecera', {
1107 label: 'Capacidad:', 1132 label: 'Capacidad:',
1108 valor: vehiculo.capacidad 1133 valor: vehiculo.capacidad
1109 }); 1134 });
1110 1135
1111 }); 1136 });
1112 } 1137 }
1113 1138
1114 function vehiculoEnUso(vehiculo) { 1139 function vehiculoEnUso(vehiculo) {
1115 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; 1140 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador;
1116 for (var i = 0; i < vehiculo.cisternas.length; i++) { 1141 for (var i = 0; i < vehiculo.cisternas.length; i++) {
1117 for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { 1142 for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
1118 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; 1143 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
1119 if (cisternaCarga.fechaReparto.substring(0, 10) === 1144 if (cisternaCarga.fechaReparto.substring(0, 10) ===
1120 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && 1145 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) &&
1121 cisternaCarga.idUsuarioProceso && 1146 cisternaCarga.idUsuarioProceso &&
1122 cisternaCarga.idUsuarioProceso !== idUsuario) { 1147 cisternaCarga.idUsuarioProceso !== idUsuario) {
1123 focaModalService.alert('El vehรญculo estรก siendo usado por otro' + 1148 focaModalService.alert('El vehรญculo estรก siendo usado por otro' +
1124 ' usuario'); 1149 ' usuario');
1125 return true; 1150 return true;
1126 } 1151 }
1127 } 1152 }
1128 } 1153 }
1129 return false; 1154 return false;
1130 } 1155 }
1131 1156
1132 function salir() { 1157 function salir() {
1133 var confirmacion = false; 1158 var confirmacion = false;
1134 1159
1135 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 1160 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
1136 confirmacion = true; 1161 confirmacion = true;
1137 } 1162 }
1138 1163
1139 if (confirmacion) { 1164 if (confirmacion) {
1140 focaModalService.confirm( 1165 focaModalService.confirm(
1141 'ยฟEstรก seguro de que desea salir? Se perderรกn todos los datos cargados.' 1166 'ยฟEstรก seguro de que desea salir? Se perderรกn todos los datos cargados.'
1142 ).then(function (data) { 1167 ).then(function (data) {
1143 if (data) { 1168 if (data) {
1144 $location.path('/'); 1169 $location.path('/');
1145 } 1170 }
1146 }); 1171 });
1147 } else { 1172 } else {
1148 $location.path('/'); 1173 $location.path('/');
1149 } 1174 }
1150 } 1175 }
1151 1176
1152 function limpiarBotonera(botonera) { 1177 function limpiarBotonera(botonera) {
1153 botonera.forEach(function (boton) { 1178 botonera.forEach(function (boton) {
1154 boton.checked = false; 1179 boton.checked = false;
1155 }); 1180 });
1156 } 1181 }
1157 function setearHojaRuta(hojaRuta) { 1182 function setearHojaRuta(hojaRuta) {
1158 $scope.$broadcast('cleanCabecera'); 1183 $scope.$broadcast('cleanCabecera');
1159 1184
1160 var cabeceras = []; 1185 var cabeceras = [];
1161 if (hojaRuta.fechaReparto) { 1186 if (hojaRuta.fechaReparto) {
1162 cabeceras.push({ 1187 cabeceras.push({
1163 label: 'Fecha de entrega:', 1188 label: 'Fecha de entrega:',
1164 valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') 1189 valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy')
1165 }); 1190 });
1166 1191
1167 $filter('filter')($scope.botonera, { 1192 $filter('filter')($scope.botonera, {
1168 label: 'Fecha Entrega' 1193 label: 'Fecha Entrega'
1169 })[0].checked = true; 1194 })[0].checked = true;
1170 } 1195 }
1171 if (hojaRuta.transportista.COD) { 1196 if (hojaRuta.transportista.COD) {
1172 cabeceras.push({ 1197 cabeceras.push({
1173 label: 'Transportista:', 1198 label: 'Transportista:',
1174 valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + 1199 valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' +
1175 hojaRuta.transportista.NOM 1200 hojaRuta.transportista.NOM
1176 }); 1201 });
1177 1202
1178 $filter('filter')($scope.botonera, { 1203 $filter('filter')($scope.botonera, {
1179 label: 'Transportista' 1204 label: 'Transportista'
1180 })[0].checked = true; 1205 })[0].checked = true;
1181 } 1206 }
1182 if (hojaRuta.chofer.id) { 1207 if (hojaRuta.chofer.id) {
1183 cabeceras.push({ 1208 cabeceras.push({
1184 label: 'Chofer:', 1209 label: 'Chofer:',
1185 valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + 1210 valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) +
1186 ' - ' + hojaRuta.chofer.nombre 1211 ' - ' + hojaRuta.chofer.nombre
1187 }); 1212 });
1188 1213
1189 $filter('filter')($scope.botonera, { 1214 $filter('filter')($scope.botonera, {
1190 label: 'Chofer' 1215 label: 'Chofer'
1191 })[0].checked = true; 1216 })[0].checked = true;
1192 } 1217 }
1193 if (hojaRuta.vehiculo.id) { 1218 if (hojaRuta.vehiculo.id) {
1194 cabeceras.push({ 1219 cabeceras.push({
1195 label: 'Tractor:', 1220 label: 'Tractor:',
1196 valor: hojaRuta.vehiculo.tractor 1221 valor: hojaRuta.vehiculo.tractor
1197 }); 1222 });
1198 cabeceras.push({ 1223 cabeceras.push({
1199 label: 'Semi:', 1224 label: 'Semi:',
1200 valor: hojaRuta.vehiculo.semi 1225 valor: hojaRuta.vehiculo.semi
1201 }); 1226 });
1202 cabeceras.push({ 1227 cabeceras.push({
1203 label: 'Capacidad:', 1228 label: 'Capacidad:',
1204 valor: hojaRuta.vehiculo.capacidad 1229 valor: hojaRuta.vehiculo.capacidad
1205 }); 1230 });
1206 1231
1207 $filter('filter')($scope.botonera, { 1232 $filter('filter')($scope.botonera, {
1208 label: 'Vehiculo' 1233 label: 'Vehiculo'
1209 })[0].checked = true; 1234 })[0].checked = true;
1210 } 1235 }
1211 if (hojaRuta.tarifario) { 1236 if (hojaRuta.tarifario) {
1212 cabeceras.push({ 1237 cabeceras.push({
1213 label: 'Tarifario:', 1238 label: 'Tarifario:',
1214 valor: hojaRuta.tarifario 1239 valor: hojaRuta.tarifario
1215 }); 1240 });
1216 1241
1217 $filter('filter')($scope.botonera, { 1242 $filter('filter')($scope.botonera, {
1218 label: 'Tarifario' 1243 label: 'Tarifario'
1219 })[0].checked = true; 1244 })[0].checked = true;
1220 } 1245 }
1221 1246
1222 addArrayCabecera(cabeceras); 1247 addArrayCabecera(cabeceras);
1223 $scope.hojaRuta = hojaRuta; 1248 $scope.hojaRuta = hojaRuta;
1224 } 1249 }
1225 1250
1226 function getLSHojaRuta() { 1251 function getLSHojaRuta() {
1227 if ($localStorage.data === undefined) return; 1252 if ($localStorage.data === undefined) return;
1228 1253
1229 var hojaRuta = (JSON.parse($localStorage.data))[0] || null; 1254 var hojaRuta = (JSON.parse($localStorage.data))[0] || null;
1230 if (hojaRuta) { 1255 if (hojaRuta) {
1231 setearHojaRuta(hojaRuta); 1256 setearHojaRuta(hojaRuta);
1232 delete $localStorage.data; 1257 delete $localStorage.data;
1233 } 1258 }
1234 } 1259 }
1235 1260
1236 function getLSBotoneraPrincipal() { 1261 function getLSBotoneraPrincipal() {
1237 if ($localStorage.data === undefined) return; 1262 if ($localStorage.data === undefined) return;
1238 1263
1239 var precargado = (JSON.parse($localStorage.data))[1] || null; 1264 var precargado = (JSON.parse($localStorage.data))[1] || null;
1240 var cargaRemito = (JSON.parse($localStorage.data))[2] || null; 1265 var cargaRemito = (JSON.parse($localStorage.data))[2] || null;
1241 var remitoAbierto = (JSON.parse($localStorage.data))[3] || null; 1266 var remitoAbierto = (JSON.parse($localStorage.data))[3] || null;
1242 if (remitoAbierto) { 1267 if (remitoAbierto) {
1243 $scope.remitoAbierto = remitoAbierto; 1268 $scope.remitoAbierto = remitoAbierto;
1244 $filter('filter')($scope.botoneraPrincipal, { 1269 $filter('filter')($scope.botoneraPrincipal, {
1245 label: 'Remito Abierto' 1270 label: 'Remito Abierto'
1246 })[0].checked = $scope.remitoAbierto; 1271 })[0].checked = $scope.remitoAbierto;
1247 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto(); 1272 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
1248 } 1273 }
1249 if (precargado) { 1274 if (precargado) {
1250 $scope.precargado = precargado; 1275 $scope.precargado = precargado;
1251 $filter('filter')($scope.botoneraPrincipal, { 1276 $filter('filter')($scope.botoneraPrincipal, {
1252 label: 'Precargados' 1277 label: 'Precargados'
1253 })[0].checked = $scope.precargado; 1278 })[0].checked = $scope.precargado;
1254 $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 1279 $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
1255 Array.prototype.push.apply($scope.botonera,focaCrearHojaRutaService.getBotoneraPrecargado()); 1280 Array.prototype.push.apply($scope.botonera,
1281 focaCrearHojaRutaService.getBotoneraPrecargado());
1256 } 1282 }
1257 if (cargaRemito) { 1283 if (cargaRemito) {
1258 $scope.cargaRemito = cargaRemito; 1284 $scope.cargaRemito = cargaRemito;
1259 $filter('filter')($scope.botoneraPrincipal, { 1285 $filter('filter')($scope.botoneraPrincipal, {
1260 label: 'Cargar Remitos' 1286 label: 'Cargar Remitos'
1261 })[0].checked = $scope.cargaRemito; 1287 })[0].checked = $scope.cargaRemito;
1262 $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 1288 $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
1263 Array.prototype.push.apply($scope.botonera,focaCrearHojaRutaService.getBotoneraCargarRemito()); 1289 Array.prototype.push.apply($scope.botonera,
1290 focaCrearHojaRutaService.getBotoneraCargarRemito());
1264 } 1291 }
1265 } 1292 }
1266 1293
1267 function addArrayCabecera(array) { 1294 function addArrayCabecera(array) {
1268 for (var i = 0; i < array.length; i++) { 1295 for (var i = 0; i < array.length; i++) {
src/js/controllerDetalles.js
1 angular.module('focaCrearHojaRuta') 1 angular.module('focaCrearHojaRuta')
2 .controller('focaModalDetalleController', [ 2 .controller('focaModalDetalleController', [
3 '$scope', '$timeout', '$uibModalInstance', 'focaModalService', 3 '$scope', '$timeout', '$uibModalInstance', 'focaModalService',
4 'focaCrearHojaRutaService', 'hojasRutas', 4 'focaCrearHojaRutaService', 'parametrosModal',
5 function ($scope, $timeout, $uibModalInstance, focaModalService, 5 function ($scope, $timeout, $uibModalInstance, focaModalService,
6 focaCrearHojaRutaService, hojasRutas) { 6 focaCrearHojaRutaService, parametrosModal) {
7 7
8 $scope.mostrar = false; 8 $scope.mostrar = false;
9 $scope.orden = parametrosModal.orden;
9 $scope.articulos = []; 10 $scope.articulos = [];
10 $scope.cisternaMovimientos = []; 11 $scope.cisternaMovimientos = [];
11 12
12 init(); 13 init();
13 function init() { 14 function init() {
14 $scope.hojasRutas = hojasRutas; 15 $scope.hojasRutas = parametrosModal.hojasRutas;
15 16
16 $scope.hojasRutas.vehiculo.cisternas = $scope.hojasRutas.vehiculo.cisternas.filter( 17 $scope.hojasRutas.vehiculo.cisternas = $scope.hojasRutas.vehiculo.cisternas.filter(
17 function (cisterna) { 18 function (cisterna) {
18 return !cisterna.desactivado; 19 return !cisterna.desactivado;
19 } 20 }
20 ); 21 );
21 focaCrearHojaRutaService.getArticulos() 22 focaCrearHojaRutaService.getArticulos()
22 .then(function (articulos) { 23 .then(function (articulos) {
23 $scope.articulos = articulos.data; 24 $scope.articulos = articulos.data;
24 }); 25 });
25 } 26 }
26 27
27 $scope.validarCisternaDisponible = function (cisterna) { 28 $scope.validarCisternaDisponible = function (cisterna) {
28 if (parseInt(cisterna.disponible) > cisterna.capacidad) { 29 if (parseInt(cisterna.disponible) > cisterna.capacidad) {
29 focaModalService.alert('No se puede ingresar una capacidad disponible ' + 30 focaModalService.alert('No se puede ingresar una capacidad disponible ' +
30 'superior a la ' + 'capacidad del vehiculo '); 31 'superior a la ' + 'capacidad del vehiculo ');
31 cisterna.disponible = cisterna.capacidad; 32 cisterna.disponible = cisterna.capacidad;
32 return; 33 return;
33 } 34 }
34 }; 35 };
35 36
36 $scope.seleccionarProductos = function (key, cisterna) { 37 $scope.seleccionarProductos = function (key, cisterna) {
37 focaModalService.modal({ 38 focaModalService.modal({
38 titulo: 'Productos', 39 titulo: 'Productos',
39 data: $scope.articulos, 40 data: $scope.articulos,
40 size: 'md', 41 size: 'md',
41 columnas: [ 42 columnas: [
42 { 43 {
43 propiedad: 'CodRub', 44 propiedad: 'CodRub',
44 nombre: 'Codigo' 45 nombre: 'Codigo'
45 }, 46 },
46 { 47 {
47 propiedad: 'descripcion', 48 propiedad: 'descripcion',
48 nombre: 'Nombre' 49 nombre: 'Nombre'
49 }, 50 },
50 ], 51 ],
51 }).then(function (res) { 52 }).then(function (res) {
52 cisterna.disponible = cisterna.capacidad; 53 cisterna.disponible = cisterna.capacidad;
53 var newArt = 54 var newArt =
54 { 55 {
55 id: 0, 56 id: 0,
56 idRemito: 0, 57 idRemito: 0,
57 codigo: res.codigo, 58 codigo: res.codigo,
58 sector: res.sector, 59 sector: res.sector,
59 sectorCodigo: res.sector + '-' + res.codigo, 60 sectorCodigo: res.sector + '-' + res.codigo,
60 descripcion: res.descripcion, 61 descripcion: res.descripcion,
61 item: key + 1, 62 item: key + 1,
62 nombre: res.descripcion, 63 nombre: res.descripcion,
63 precio: parseFloat(res.precio).toFixed(4), 64 precio: parseFloat(res.precio).toFixed(4),
64 costoUnitario: res.costo, 65 costoUnitario: res.costo,
65 editCantidad: false, 66 editCantidad: false,
66 editPrecio: false, 67 editPrecio: false,
67 rubro: res.CodRub, 68 rubro: res.CodRub,
68 ivaUnitario: res.IMPIVA, 69 ivaUnitario: res.IMPIVA,
69 impuestoInternoUnitario: res.ImpInt, 70 impuestoInternoUnitario: res.ImpInt,
70 impuestoInterno1Unitario: res.ImpInt2, 71 impuestoInterno1Unitario: res.ImpInt2,
71 impuestoInterno2Unitario: res.ImpInt3, 72 impuestoInterno2Unitario: res.ImpInt3,
72 precioLista: res.precio, 73 precioLista: res.precio,
73 combustible: 1, 74 combustible: 1,
74 facturado: 0, 75 facturado: 0,
75 idArticulo: res.id, 76 idArticulo: res.id,
76 tasaIva: res.tasaIVA 77 tasaIva: res.tasaIVA
77 }; 78 };
78 79
79 newArt.exentoUnitario = newArt.ivaUnitario ? 0 : res.neto; 80 newArt.exentoUnitario = newArt.ivaUnitario ? 0 : res.neto;
80 newArt.netoUnitario = newArt.ivaUnitario ? res.neto : 0; 81 newArt.netoUnitario = newArt.ivaUnitario ? res.neto : 0;
81 82
82 cisterna.articuloSeleccionado = newArt; 83 cisterna.articuloSeleccionado = newArt;
83 cisterna.nombreArticulo = res.descripcion; 84 cisterna.nombreArticulo = res.descripcion;
84 }).catch(function (e) { 85 }).catch(function (e) {
85 console.log(e); 86 console.log(e);
86 }); 87 });
87 }; 88 };
88 89
89 $scope.guardar = function () { 90 $scope.guardar = function () {
90 91
91 var cisternasFilter = validarArticulos(); 92 var cisternasFilter = validarArticulos();
92 93
93 var articulos = []; 94 var articulos = [];
94 if (cisternasFilter === undefined) { 95 if (cisternasFilter === undefined) {
95 return; 96 return;
96 } 97 }
97 cisternasFilter.forEach(function (cisterna) { 98 cisternasFilter.forEach(function (cisterna) {
98 99
99 var fechaReparto = $scope.hojasRutas.fechaReparto; 100 var fechaReparto = $scope.hojasRutas.fechaReparto;
100 101
101 var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) { 102 // var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) {
102 return carga.fechaReparto === fechaReparto; 103 // return carga.fechaReparto === fechaReparto;
103 }); 104 // });
104 105
105 if (filtroCisternaCarga.length) { 106 // if (filtroCisternaCarga.length) {
106 cisterna.cisternaCarga = filtroCisternaCarga[0]; 107 // cisterna.cisternaCarga = filtroCisternaCarga[0];
107 } else { 108 // } else {
108 cisterna.cisternaCarga = { 109 cisterna.cisternaCarga = {
109 confirmado: null, 110 confirmado: null,
110 fechaReparto: fechaReparto, 111 fechaReparto: fechaReparto,
111 idCisterna: cisterna.id, 112 idCisterna: cisterna.id,
113 orden: $scope.orden
112 }; 114 };
113 } 115 // }
114 116
115 //cargar 117 //cargar
116 if (cisterna.cisternaCarga.cantidad) { 118 if (cisterna.cisternaCarga.cantidad) {
117 cisterna.cisternaCarga.cantidad += cisterna.disponible; 119 cisterna.cisternaCarga.cantidad += cisterna.disponible;
118 } else { 120 } else {
119 cisterna.cisternaCarga.cantidad = cisterna.disponible; 121 cisterna.cisternaCarga.cantidad = cisterna.disponible;
120 cisterna.cisternaCarga.idProducto = 122 cisterna.cisternaCarga.idProducto =
121 cisterna.articuloSeleccionado.idArticulo; 123 cisterna.articuloSeleccionado.idArticulo;
122 } 124 }
123 125
124 //Guardar 126 //Guardar
125 var now = new Date(); 127 var now = new Date();
126 var cisternaMovimiento = { 128 var cisternaMovimiento = {
127 fecha: now.toISOString().slice(0, 19).replace('T', ' '), 129 fecha: now.toISOString().slice(0, 19).replace('T', ' '),
128 cantidad: cisterna.disponible, 130 cantidad: cisterna.disponible,
129 metodo: 'carga', 131 metodo: 'carga',
130 idCisternaCarga: cisterna.cisternaCarga.id, 132 idCisternaCarga: cisterna.cisternaCarga.id,
131 }; 133 };
132 134
133 cisterna.cisternaCarga.fechaReparto = fechaReparto; 135 cisterna.cisternaCarga.fechaReparto = fechaReparto;
134 cisterna.articuloSeleccionado.cantidad = cisterna.disponible; 136 cisterna.articuloSeleccionado.cantidad = cisterna.disponible;
135 articulos.push(cisterna.articuloSeleccionado); 137 articulos.push(cisterna.articuloSeleccionado);
136 $scope.cisternaMovimientos.push(cisternaMovimiento); 138 $scope.cisternaMovimientos.push(cisternaMovimiento);
137 }); 139 });
138 140
139 $uibModalInstance.close({ 141 $uibModalInstance.close({
140 cisternas: cisternasFilter, 142 cisternas: cisternasFilter,
141 movimientos: $scope.cisternaMovimientos, 143 movimientos: $scope.cisternaMovimientos,
142 articulos: articulos 144 articulos: articulos
143 }); 145 });
144 }; 146 };
145 147
146 $scope.cancel = function () { 148 $scope.cancel = function () {
147 $uibModalInstance.dismiss(null); 149 $uibModalInstance.dismiss(null);
148 }; 150 };
149 151
150 function validarArticulos () { 152 function validarArticulos () {
151 var cisternasFilter = $scope.hojasRutas.vehiculo.cisternas 153 var cisternasFilter = $scope.hojasRutas.vehiculo.cisternas
152 .filter(function (cisterna) { 154 .filter(function (cisterna) {
153 return parseInt(cisterna.disponible) > 0 || cisterna.articuloSeleccionado; 155 return parseInt(cisterna.disponible) > 0 || cisterna.articuloSeleccionado;
154 }); 156 });
155 157
156 var cisternasIncompletas = cisternasFilter.filter(function(cisterna) { 158 var cisternasIncompletas = cisternasFilter.filter(function(cisterna) {
157 return (cisterna.articuloSeleccionado && !cisterna.disponible) || 159 return (cisterna.articuloSeleccionado && !cisterna.disponible) ||
158 (!cisterna.articuloSeleccionado && cisterna.disponible); 160 (!cisterna.articuloSeleccionado && cisterna.disponible);
159 }); 161 });
160 162
161 if (cisternasIncompletas.length > 0 && cisternasFilter.length > 0 ) { 163 if (cisternasIncompletas.length > 0 && cisternasFilter.length > 0 ) {
162 focaModalService.alert('Ingrese todos los campos para completar el remito'); 164 focaModalService.alert('Ingrese todos los campos para completar el remito');
163 cisternasFilter = undefined; 165 cisternasFilter = undefined;
164 } 166 }
165 return cisternasFilter; 167 return cisternasFilter;
166 } 168 }
167 } 169 }
168 ]); 170 ]);
169 171
1 angular.module('focaCrearHojaRuta') 1 angular.module('focaCrearHojaRuta')
2 .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', '$cookies', 2 .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', '$cookies',
3 function($http, API_ENDPOINT, $cookies) { 3 function($http, API_ENDPOINT, $cookies) {
4 var route = API_ENDPOINT.URL; 4 var route = API_ENDPOINT.URL;
5 return { 5 return {
6 idUsuario: $cookies.get('vendedorCobrador'), 6 idUsuario: $cookies.get('vendedorCobrador'),
7 crearHojaRuta: function(hojaRuta) { 7 crearHojaRuta: function(hojaRuta) {
8 return $http.post(route + '/hoja-ruta', hojaRuta); 8 return $http.post(route + '/hoja-ruta', hojaRuta);
9 }, 9 },
10 crearRemito: function(remito) { 10 crearRemito: function(remito) {
11 // TODO: Cambiar para usar el servicio /remito 11 // TODO: Cambiar para usar el servicio /remito
12 return $http.post(route + '/remito/guardar', remito); 12 return $http.post(route + '/remito/guardar', remito);
13 }, 13 },
14 obtenerHojaRuta: function() { 14 obtenerHojaRuta: function() {
15 return $http.get(route +'/hoja-ruta'); 15 return $http.get(route +'/hoja-ruta');
16 }, 16 },
17 setHojaRuta: function(hojaRuta) { 17 setHojaRuta: function(hojaRuta) {
18 this.hojaRuta = hojaRuta; 18 this.hojaRuta = hojaRuta;
19 }, 19 },
20 clearHojaRuta: function() { 20 clearHojaRuta: function() {
21 this.hojaRuta = undefined; 21 this.hojaRuta = undefined;
22 }, 22 },
23 getHojaRuta: function() { 23 getHojaRuta: function() {
24 return this.hojaRuta; 24 return this.hojaRuta;
25 }, 25 },
26 getArticulosByIdHojaRuta: function(id) { 26 getArticulosByIdHojaRuta: function(id) {
27 return $http.get(route+'/articulos/hoja-ruta/'+id); 27 return $http.get(route+'/articulos/hoja-ruta/'+id);
28 }, 28 },
29 crearArticulosParaHojaRuta: function(articuloHojaRuta) { 29 crearArticulosParaHojaRuta: function(articuloHojaRuta) {
30 return $http.post(route + '/articulos/remito', 30 return $http.post(route + '/articulos/remito',
31 {articuloRemito: articuloHojaRuta}); 31 {articuloRemito: articuloHojaRuta});
32 }, 32 },
33 getDomiciliosByIdHojaRuta: function(id) { 33 getDomiciliosByIdHojaRuta: function(id) {
34 return $http.get(route +'/hoja-ruta/' + id + '/domicilios'); 34 return $http.get(route +'/hoja-ruta/' + id + '/domicilios');
35 }, 35 },
36 getDomiciliosByIdCliente: function(id) { 36 getDomiciliosByIdCliente: function(id) {
37 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) 37 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega)
38 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); 38 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id );
39 }, 39 },
40 getPrecioCondicion: function() { 40 getPrecioCondicion: function() {
41 return $http.get(route + '/precio-condicion'); 41 return $http.get(route + '/precio-condicion');
42 }, 42 },
43 getPrecioCondicionById: function(id) { 43 getPrecioCondicionById: function(id) {
44 return $http.get(route + '/precio-condicion/' + id); 44 return $http.get(route + '/precio-condicion/' + id);
45 }, 45 },
46 getPlazoPagoByPrecioCondicion: function(id) { 46 getPlazoPagoByPrecioCondicion: function(id) {
47 return $http.get(route + '/plazo-pago/precio-condicion/' + id); 47 return $http.get(route + '/plazo-pago/precio-condicion/' + id);
48 }, 48 },
49 crearFlete: function(flete) { 49 crearFlete: function(flete) {
50 return $http.post(route + '/flete', {flete : flete}); 50 return $http.post(route + '/flete', {flete : flete});
51 }, 51 },
52 crearPlazosParaHojaRuta: function(plazos) { 52 crearPlazosParaHojaRuta: function(plazos) {
53 return $http.post(route + '/plazo-pago/hoja-ruta', plazos); 53 return $http.post(route + '/plazo-pago/hoja-ruta', plazos);
54 }, 54 },
55 getCotizacionByIdMoneda: function(id) { 55 getCotizacionByIdMoneda: function(id) {
56 return $http.get(route + '/moneda/' + id); 56 return $http.get(route + '/moneda/' + id);
57 }, 57 },
58 crearEstadoParaHojaRuta: function(estado) { 58 crearEstadoParaHojaRuta: function(estado) {
59 return $http.post(route + '/estado', {estado: estado}); 59 return $http.post(route + '/estado', {estado: estado});
60 }, 60 },
61 getNumeroHojaRuta: function() { 61 getNumeroHojaRuta: function() {
62 return $http.get(route + '/hoja-ruta/numero-siguiente'); 62 return $http.get(route + '/hoja-ruta/numero-siguiente');
63 }, 63 },
64 getRemitosByIdVehiculo: function(idVehiculo, fechaReparto, sinConfirmar) { 64 getRemitosByIdVehiculo: function(idVehiculo, fechaReparto, sinConfirmar) {
65 var noCofirmados = sinConfirmar ? '/sinConfirmar' : ''; 65 var noCofirmados = sinConfirmar ? '/sinConfirmar' : '';
66 return $http.get(route + '/vehiculo/obtener/remitos/' + 66 return $http.get(route + '/vehiculo/obtener/remitos/' +
67 idVehiculo + '/' + fechaReparto.toISOString().substring(0, 10) + noCofirmados); 67 idVehiculo + '/' + fechaReparto.toISOString().substring(0, 10) + noCofirmados);
68 }, 68 },
69 desasociarRemitos: function(idsRemitos, idVehiculo, sinRemitos) { 69 desasociarRemitos: function(idsRemitos, idVehiculo, sinRemitos) {
70 return $http.post(route + '/vehiculo/desasociar-remitos', 70 return $http.post(route + '/vehiculo/desasociar-remitos',
71 { 71 {
72 idsRemitos: idsRemitos, 72 idsRemitos: idsRemitos,
73 idVehiculo: idVehiculo, 73 idVehiculo: idVehiculo,
74 vehiculoSinRemitos: sinRemitos 74 vehiculoSinRemitos: sinRemitos
75 }); 75 });
76 }, 76 },
77 getParametros: function() { 77 getParametros: function() {
78 return $http.get(API_ENDPOINT.URL + '/parametros/hojaRuta'); 78 return $http.get(API_ENDPOINT.URL + '/parametros/hojaRuta');
79 }, 79 },
80 getBotonera: function() { 80 getBotonera: function() {
81 return [ 81 return [
82 { 82 {
83 label: 'Fecha Entrega', 83 label: 'Fecha Entrega',
84 image: 'FechaEntrega.png' 84 image: 'FechaEntrega.png'
85 }, 85 },
86 { 86 {
87 label: 'Transportista', 87 label: 'Transportista',
88 image: 'transportista.png' 88 image: 'transportista.png'
89 }, 89 },
90 { 90 {
91 label: 'Chofer', 91 label: 'Chofer',
92 image: 'chofer.png' 92 image: 'chofer.png'
93 }, 93 },
94 { 94 {
95 label: 'Vehiculo', 95 label: 'Vehiculo',
96 image: 'vehiculos.png' 96 image: 'vehiculos.png'
97 }, 97 },
98 { 98 {
99 label: 'Tarifario', 99 label: 'Tarifario',
100 image: 'tarifario.png' 100 image: 'tarifario.png'
101 }, 101 },
102 { 102 {
103 label: 'Remitos', 103 label: 'Remitos',
104 image: 'remito.png' 104 image: 'remito.png'
105 }, 105 },
106 { 106 {
107 label: 'Vehiculos precargados', 107 label: 'Vehiculos precargados',
108 image: 'vehiculos.png' 108 image: 'vehiculos.png'
109 }, 109 },
110 { 110 {
111 label: 'Datos extra', 111 label: 'Datos extra',
112 image: 'tarifario.png' 112 image: 'tarifario.png'
113 } 113 }
114 ]; 114 ];
115 }, 115 },
116 getBotones: function () { 116 getBotones: function () {
117 return [ 117 return [
118 { 118 {
119 label: 'Precargados', 119 label: 'Precargados',
120 image: 'vehiculos.png' 120 image: 'vehiculos.png'
121 }, 121 },
122 { 122 {
123 label: 'Cargar Remitos', 123 label: 'Cargar Remitos',
124 image: 'remito.png' 124 image: 'remito.png'
125 }, 125 },
126 { 126 {
127 label: 'Remito Abierto', 127 label: 'Remito Abierto',
128 image: 'remitoabierto.png' 128 image: 'remitoabierto.png'
129 } 129 }
130 ]; 130 ];
131 }, 131 },
132 getRemitoAbierto: function () { 132 getRemitoAbierto: function () {
133 return [ 133 return [
134 { 134 {
135 label: 'Fecha Entrega', 135 label: 'Fecha Entrega',
136 image: 'FechaEntrega.png' 136 image: 'FechaEntrega.png'
137 }, 137 },
138 { 138 {
139 label: 'Transportista', 139 label: 'Transportista',
140 image: 'transportista.png' 140 image: 'transportista.png'
141 }, 141 },
142 { 142 {
143 label: 'Vehiculo', 143 label: 'Vehiculo',
144 image: 'vehiculos.png' 144 image: 'vehiculos.png'
145 }, 145 },
146 { 146 {
147 label: 'Chofer', 147 label: 'Chofer',
148 image: 'chofer.png' 148 image: 'chofer.png'
149 }, 149 },
150 { 150 {
151 label: 'Proveedor', 151 label: 'Proveedor',
152 image: 'proveedor.png' 152 image: 'proveedor.png'
153 }, 153 },
154 { 154 {
155 label: 'Tarifario', 155 label: 'Tarifario',
156 image: 'tarifario.png' 156 image: 'tarifario.png'
157 }, 157 },
158 { 158 {
159 label: 'Cliente', 159 label: 'Cliente',
160 image: 'cliente.png' 160 image: 'cliente.png'
161 }, 161 },
162 { 162 {
163 label: 'Detalle de Carga', 163 label: 'Detalle de Carga',
164 image: 'detalleDeCarga.png' 164 image: 'detalleDeCarga.png'
165 } 165 }
166 ]; 166 ];
167 }, 167 },
168 getArticulos : function () { 168 getArticulos : function () {
169 return $http.get(API_ENDPOINT.URL + '/articulos'); 169 return $http.get(API_ENDPOINT.URL + '/articulos');
170 }, 170 },
171 getVendedorById : function (idVendedor) { 171 getVendedorById : function (idVendedor) {
172 return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + idVendedor); 172 return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + idVendedor);
173 }, 173 },
174 getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { 174 getPuntosDescargaByClienDom: function(idDomicilio, idCliente) {
175 return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + 175 return $http.get(API_ENDPOINT.URL + '/punto-descarga/' +
176 idDomicilio + '/' + idCliente); 176 idDomicilio + '/' + idCliente);
177 }, 177 },
178 getBotoneraPrecargado: function () { 178 getBotoneraPrecargado: function () {
179 return [ 179 return [
180 { 180 {
181 label: 'Fecha Entrega', 181 label: 'Fecha Entrega',
182 image: 'FechaEntrega.png' 182 image: 'FechaEntrega.png'
183 }, 183 },
184 { 184 {
185 label: 'Transportista', 185 label: 'Transportista',
186 image: 'transportista.png' 186 image: 'transportista.png'
187 }, 187 },
188 { 188 {
189 label: 'Chofer', 189 label: 'Chofer',
190 image: 'chofer.png' 190 image: 'chofer.png'
191 }, 191 },
192 { 192 {
193 label: 'VehiculosPrecargados', 193 label: 'VehiculosPrecargados',
194 image: 'vehiculos.png' 194 image: 'vehiculos.png'
195 }, 195 },
196 { 196 {
197 label: 'Tarifario', 197 label: 'Tarifario',
198 image: 'tarifario.png' 198 image: 'tarifario.png'
199 }, 199 },
200 { 200 {
201 label: 'Datos extra', 201 label: 'Datos extra',
202 image: 'tarifario.png' 202 image: 'tarifario.png'
203 } 203 }
204 ]; 204 ];
205 }, 205 },
206 getBotoneraCargarRemito: function () { 206 getBotoneraCargarRemito: function () {
207 return [ 207 return [
208 { 208 {
209 label: 'Fecha Entrega', 209 label: 'Fecha Entrega',
210 image: 'FechaEntrega.png' 210 image: 'FechaEntrega.png'
211 }, 211 },
212 { 212 {
213 label: 'Transportista', 213 label: 'Transportista',
214 image: 'transportista.png' 214 image: 'transportista.png'
215 }, 215 },
216 { 216 {
217 label: 'Chofer', 217 label: 'Chofer',
218 image: 'chofer.png' 218 image: 'chofer.png'
219 }, 219 },
220 { 220 {
221 label: 'Vehiculo', 221 label: 'Vehiculo',
222 image: 'flete.png' 222 image: 'flete.png'
223 }, 223 },
224 { 224 {
225 label: 'Remitos', 225 label: 'Remitos',
226 image: 'remito.png' 226 image: 'remito.png'
227 }, 227 },
228 { 228 {
229 label: 'Tarifario', 229 label: 'Tarifario',
230 image: 'tarifario.png' 230 image: 'tarifario.png'
231 }, 231 },
232 { 232 {
233 label: 'Datos extra', 233 label: 'Datos extra',
234 image: 'tarifario.png' 234 image: 'tarifario.png'
235 } 235 }
236 ]; 236 ];
237 }, 237 },
238 guardarCisternas: function(cisterna, idRemito) { 238 guardarCisternas: function(cisterna, idRemito) {
239 239
240 cisterna.cisternaMovimientos.forEach(function(cisternaMovimiento) { 240 cisterna.cisternaMovimientos.forEach(function(cisternaMovimiento) {
241 cisternaMovimiento.idRemito = idRemito; 241 cisternaMovimiento.idRemito = idRemito;
242 }); 242 });
243 243
244 return $http.post(API_ENDPOINT.URL + '/cisterna/guardar/cargar/' + 244 return $http.post(API_ENDPOINT.URL + '/cisterna/guardar/cargar/' +
245 this.idUsuario + '/' + idRemito, cisterna); 245 this.idUsuario + '/' + idRemito, cisterna);
246 }, 246 },
247 crearArticulosParaRemito: function(articuloRemito) { 247 crearArticulosParaRemito: function(articuloRemito) {
248 return $http.post(route + '/articulos/remito', 248 return $http.post(route + '/articulos/remito',
249 {articuloRemito: articuloRemito}); 249 {articuloRemito: articuloRemito});
250 },
251 getNumeroOrden: function(idVehiculo, fecha) {
252 return $http.get(route + '/hoja-ruta/obtener/numero-orden/' +
253 idVehiculo + '/' + fecha.toISOString().slice(0, 10));
250 } 254 }
251 }; 255 };
252 }]); 256 }]);
253 257