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