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