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