Commit 8f2576328be8a8686e150eaa7e7848e30c24f066
Exists in
master
Merge remote-tracking branch 'upstream/develop'
Showing
2 changed files
Show diff stats
src/js/businessService.js
| 1 | angular.module('focaCrearNotaPedido') | 1 | angular.module('focaCrearNotaPedido') |
| 2 | .factory('notaPedidoBusinessService', [ | 2 | .factory('notaPedidoBusinessService', [ |
| 3 | 'crearNotaPedidoService', | 3 | 'crearNotaPedidoService', |
| 4 | function(crearNotaPedidoService) { | 4 | function(crearNotaPedidoService) { |
| 5 | return { | 5 | return { |
| 6 | addArticulos: function(articulosNotaPedido, idNotaPedido, cotizacion) { | 6 | addArticulos: function(articulosNotaPedido, idNotaPedido, cotizacion) { |
| 7 | for(var i = 0; i < articulosNotaPedido.length; i++) { | 7 | for(var i = 0; i < articulosNotaPedido.length; i++) { |
| 8 | delete articulosNotaPedido[i].editCantidad; | 8 | delete articulosNotaPedido[i].editCantidad; |
| 9 | delete articulosNotaPedido[i].editPrecio; | 9 | delete articulosNotaPedido[i].editPrecio; |
| 10 | articulosNotaPedido[i].idNotaPedido = idNotaPedido; | 10 | articulosNotaPedido[i].idNotaPedido = idNotaPedido; |
| 11 | articulosNotaPedido[i].precio = articulosNotaPedido[i].precio * cotizacion; | 11 | articulosNotaPedido[i].precio = articulosNotaPedido[i].precio * cotizacion; |
| 12 | crearNotaPedidoService.crearArticulosParaNotaPedido(articulosNotaPedido[i]); | 12 | crearNotaPedidoService.crearArticulosParaNotaPedido(articulosNotaPedido[i]); |
| 13 | } | 13 | } |
| 14 | }, | 14 | }, |
| 15 | addEstado: function(idNotaPedido, idVendedor) { | 15 | addEstado: function(idNotaPedido, idVendedor) { |
| 16 | var date = new Date(); | 16 | var date = new Date(); |
| 17 | var estado = { | 17 | var estado = { |
| 18 | idNotaPedido: idNotaPedido, | 18 | idNotaPedido: idNotaPedido, |
| 19 | fecha: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) | 19 | fecha: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) |
| 20 | .toISOString().slice(0, 19).replace('T', ' '), | 20 | .toISOString().slice(0, 19).replace('T', ' '), |
| 21 | estado: 0, | 21 | estado: 0, |
| 22 | idVendedor: idVendedor | 22 | idVendedor: idVendedor |
| 23 | }; | 23 | }; |
| 24 | crearNotaPedidoService.crearEstadoParaNotaPedido(estado); | 24 | crearNotaPedidoService.crearEstadoParaNotaPedido(estado); |
| 25 | }, | 25 | }, |
| 26 | addPuntosDescarga: function(idNotaPedido, puntosDescarga) { | 26 | addPuntosDescarga: function(idNotaPedido, puntosDescarga) { |
| 27 | 27 | ||
| 28 | var puntos = []; | 28 | var puntos = []; |
| 29 | 29 | ||
| 30 | puntosDescarga.forEach(function(punto) { | 30 | puntosDescarga.forEach(function(punto) { |
| 31 | puntos.push({ | 31 | puntos.push({ |
| 32 | idPuntoDescarga: punto.id, | 32 | idPuntoDescarga: punto.puntoDescarga.id, |
| 33 | idNotaPedido: idNotaPedido, | 33 | idNotaPedido: idNotaPedido, |
| 34 | }); | 34 | }); |
| 35 | }); | 35 | }); |
| 36 | 36 | ||
| 37 | return crearNotaPedidoService.crearPuntosDescarga(puntos); | 37 | return crearNotaPedidoService.crearPuntosDescarga(puntos); |
| 38 | }, | 38 | }, |
| 39 | calcularArticulos: function(articulos, cotizacion) { | 39 | calcularArticulos: function(articulos, cotizacion) { |
| 40 | for(var i = 0; i < articulos.length; i++) { | 40 | for(var i = 0; i < articulos.length; i++) { |
| 41 | articulos[i].precio = articulos[i].precio / cotizacion; | 41 | articulos[i].precio = articulos[i].precio / cotizacion; |
| 42 | } | 42 | } |
| 43 | }, | 43 | }, |
| 44 | plazoToString: function(plazos) { | 44 | plazoToString: function(plazos) { |
| 45 | var result = ''; | 45 | var result = ''; |
| 46 | for(var i = 0; i < plazos.length; i++) { | 46 | for(var i = 0; i < plazos.length; i++) { |
| 47 | result += plazos[i].dias + ' '; | 47 | result += plazos[i].dias + ' '; |
| 48 | } | 48 | } |
| 49 | return result.trim(); | 49 | return result.trim(); |
| 50 | } | 50 | } |
| 51 | }; | 51 | }; |
| 52 | }]); | 52 | }]); |
| 53 | 53 |
src/js/controller.js
| 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
| 2 | [ | 2 | [ |
| 3 | '$scope', | 3 | '$scope', |
| 4 | '$uibModal', | 4 | '$uibModal', |
| 5 | '$location', | 5 | '$location', |
| 6 | '$filter', | 6 | '$filter', |
| 7 | '$timeout', | 7 | '$timeout', |
| 8 | 'crearNotaPedidoService', | 8 | 'crearNotaPedidoService', |
| 9 | 'focaBotoneraLateralService', | 9 | 'focaBotoneraLateralService', |
| 10 | 'focaModalService', | 10 | 'focaModalService', |
| 11 | 'notaPedidoBusinessService', | 11 | 'notaPedidoBusinessService', |
| 12 | '$rootScope', | 12 | '$rootScope', |
| 13 | 'focaSeguimientoService', | 13 | 'focaSeguimientoService', |
| 14 | 'APP', | 14 | 'APP', |
| 15 | 'focaLoginService', | 15 | 'focaLoginService', |
| 16 | '$localStorage', | 16 | '$localStorage', |
| 17 | function( | 17 | function( |
| 18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, | 18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, |
| 19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, | 19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, |
| 20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) | 20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) |
| 21 | { | 21 | { |
| 22 | config(); | 22 | config(); |
| 23 | var cotizacionPArgentino = {}; | ||
| 23 | var cotizacionPArgentino = {}; | 24 | |
| 24 | 25 | function config() { | |
| 25 | function config() { | 26 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA |
| 26 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA | 27 | $scope.tmpCantidad = Number; |
| 27 | $scope.tmpCantidad = Number; | 28 | $scope.tmpPrecio = Number; |
| 28 | $scope.tmpPrecio = Number; | 29 | $scope.notaPedido = {}; |
| 29 | $scope.notaPedido = {}; | 30 | $scope.isNumber = angular.isNumber; |
| 30 | $scope.isNumber = angular.isNumber; | 31 | $scope.datepickerAbierto = false; |
| 31 | $scope.datepickerAbierto = false; | 32 | $scope.show = false; |
| 32 | $scope.show = false; | 33 | $scope.cargando = true; |
| 33 | $scope.cargando = true; | 34 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
| 34 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 35 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
| 35 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 36 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
| 36 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 37 | $scope.dateOptions = { |
| 37 | $scope.dateOptions = { | 38 | maxDate: new Date(), |
| 38 | maxDate: new Date(), | 39 | minDate: new Date(2010, 0, 1) |
| 39 | minDate: new Date(2010, 0, 1) | 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.crearNotaPedido); |
| 46 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 47 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 47 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 48 | }); |
| 48 | }); | 49 | |
| 49 | 50 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR | |
| 50 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR | 51 | if (APP === 'distribuidor') { |
| 51 | if (APP === 'distribuidor') { | 52 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; |
| 52 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; | 53 | } |
| 53 | } | 54 | |
| 54 | 55 | crearNotaPedidoService.getParametros().then(function(res) { | |
| 55 | crearNotaPedidoService.getParametros().then(function(res) { | 56 | var parametros = JSON.parse(res.data[0].jsonText); |
| 56 | var parametros = JSON.parse(res.data[0].jsonText); | 57 | if ($localStorage.notaPedido) { |
| 57 | if ($localStorage.notaPedido) { | 58 | $timeout(function() { getLSNotaPedido();} ); |
| 58 | $timeout(function() { getLSNotaPedido();} ); | 59 | } else { |
| 59 | } else { | 60 | for (var property in parametros) { |
| 60 | for (var property in parametros) { | 61 | $scope.notaPedido[property] = parametros[property]; |
| 61 | $scope.notaPedido[property] = parametros[property]; | 62 | $scope.inicial[property] = parametros[property]; |
| 62 | $scope.inicial[property] = parametros[property]; | 63 | } |
| 63 | } | 64 | setearNotaPedido($scope.notaPedido); |
| 64 | setearNotaPedido($scope.notaPedido); | 65 | } |
| 65 | } | 66 | }); |
| 66 | }); | 67 | |
| 67 | 68 | init(); | |
| 68 | init(); | 69 | |
| 69 | 70 | } | |
| 70 | } | 71 | |
| 71 | 72 | function init() { | |
| 72 | function init() { | 73 | $scope.$broadcast('cleanCabecera'); |
| 73 | $scope.$broadcast('cleanCabecera'); | 74 | |
| 74 | 75 | $scope.notaPedido = { | |
| 75 | $scope.notaPedido = { | 76 | id: 0, |
| 76 | id: 0, | 77 | cliente: {}, |
| 77 | cliente: {}, | 78 | proveedor: {}, |
| 78 | proveedor: {}, | 79 | domicilio: {dom: ''}, |
| 79 | domicilio: {dom: ''}, | 80 | vendedor: {}, |
| 80 | vendedor: {}, | 81 | fechaCarga: new Date(), |
| 81 | fechaCarga: new Date(), | 82 | cotizacion: {}, |
| 82 | cotizacion: {}, | 83 | articulosNotaPedido: [], |
| 83 | articulosNotaPedido: [], | 84 | notaPedidoPlazo: [], |
| 84 | notaPedidoPlazo: [], | 85 | notaPedidoPuntoDescarga: [] |
| 85 | notaPedidoPuntoDescarga: [] | 86 | }; |
| 86 | }; | 87 | $scope.idLista = undefined; |
| 87 | $scope.idLista = undefined; | 88 | |
| 88 | 89 | crearNotaPedidoService.getNumeroNotaPedido().then( | |
| 89 | crearNotaPedidoService.getNumeroNotaPedido().then( | 90 | function(res) { |
| 90 | function(res) { | 91 | $scope.puntoVenta = $filter('rellenarDigitos')( |
| 91 | $scope.puntoVenta = $filter('rellenarDigitos')( | 92 | res.data.sucursal, 4 |
| 92 | res.data.sucursal, 4 | 93 | ); |
| 93 | ); | 94 | |
| 94 | 95 | $scope.comprobante = $filter('rellenarDigitos')( | |
| 95 | $scope.comprobante = $filter('rellenarDigitos')( | 96 | res.data.numeroNotaPedido, 8 |
| 96 | res.data.numeroNotaPedido, 8 | 97 | ); |
| 97 | ); | 98 | }, |
| 98 | }, | 99 | function(err) { |
| 99 | function(err) { | 100 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 100 | focaModalService.alert('La terminal no esta configurada correctamente'); | 101 | console.info(err); |
| 101 | console.info(err); | 102 | } |
| 102 | } | 103 | ); |
| 103 | ); | 104 | |
| 104 | 105 | if (APP === 'distribuidor') { | |
| 105 | if (APP === 'distribuidor') { | 106 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( |
| 106 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( | 107 | function(res) { |
| 107 | function(res) { | 108 | var vendedor = res.data; |
| 108 | var vendedor = res.data; | 109 | $scope.$broadcast('addCabecera', { |
| 109 | $scope.$broadcast('addCabecera', { | 110 | label: 'Vendedor:', |
| 110 | label: 'Vendedor:', | 111 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
| 111 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 112 | vendedor.NOM |
| 112 | vendedor.NOM | 113 | }); |
| 113 | }); | 114 | |
| 114 | 115 | $scope.notaPedido.vendedor = vendedor; | |
| 115 | $scope.notaPedido.vendedor = vendedor; | 116 | $scope.inicial.vendedor = $scope.notaPedido.vendedor; |
| 116 | $scope.inicial.vendedor = $scope.notaPedido.vendedor; | 117 | } |
| 117 | } | 118 | ); |
| 118 | ); | 119 | } |
| 119 | } | 120 | |
| 120 | 121 | $scope.inicial = angular.copy($scope.notaPedido); | |
| 121 | $scope.inicial = angular.copy($scope.notaPedido); | 122 | } |
| 122 | } | 123 | |
| 123 | 124 | $scope.$watch('notaPedido', function(newValue) { | |
| 124 | $scope.$watch('notaPedido', function(newValue) { | 125 | focaBotoneraLateralService.setPausarData({ |
| 125 | focaBotoneraLateralService.setPausarData({ | 126 | label: 'notaPedido', |
| 126 | label: 'notaPedido', | 127 | val: newValue |
| 127 | val: newValue | 128 | }); |
| 128 | }); | 129 | }, true); |
| 129 | }, true); | 130 | |
| 130 | 131 | $scope.crearNotaPedido = function() { | |
| 131 | $scope.crearNotaPedido = function() { | 132 | if (!$scope.notaPedido.cliente.COD) { |
| 132 | if (!$scope.notaPedido.cliente.COD) { | 133 | focaModalService.alert('Ingrese Cliente'); |
| 133 | focaModalService.alert('Ingrese Cliente'); | 134 | return; |
| 134 | return; | 135 | } else if ($scope.notaPedido.idRemito === -1) { |
| 135 | } else if ($scope.notaPedido.idRemito === -1) { | 136 | focaBotoneraLateralService.alert('No se puede modificar esta nota de pedido'); |
| 136 | focaBotoneraLateralService.alert('No se puede modificar esta nota de pedido'); | 137 | return; |
| 137 | return; | 138 | } else if (!$scope.notaPedido.proveedor.COD) { |
| 138 | } else if (!$scope.notaPedido.proveedor.COD) { | 139 | focaModalService.alert('Ingrese Proveedor'); |
| 139 | focaModalService.alert('Ingrese Proveedor'); | 140 | return; |
| 140 | return; | 141 | } else if (!$scope.notaPedido.cotizacion.ID) { |
| 141 | } else if (!$scope.notaPedido.cotizacion.ID) { | 142 | focaModalService.alert('Ingrese Cotización'); |
| 142 | focaModalService.alert('Ingrese Cotización'); | 143 | return; |
| 143 | return; | 144 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { |
| 144 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { | 145 | focaModalService.alert('Ingrese Moneda'); |
| 145 | focaModalService.alert('Ingrese Moneda'); | 146 | return; |
| 146 | return; | 147 | } else if (!$scope.notaPedido.notaPedidoPlazo) { |
| 147 | } else if (!$scope.notaPedido.notaPedidoPlazo) { | 148 | focaModalService.alert('Ingrese Precios y Condiciones'); |
| 148 | focaModalService.alert('Ingrese Precios y Condiciones'); | 149 | return; |
| 149 | return; | 150 | } else if ( |
| 150 | } else if ( | 151 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
| 151 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 152 | { |
| 152 | { | 153 | focaModalService.alert('Ingrese Flete'); |
| 153 | focaModalService.alert('Ingrese Flete'); | 154 | return; |
| 154 | return; | 155 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
| 155 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 156 | focaModalService.alert('Ingrese Domicilio'); |
| 156 | focaModalService.alert('Ingrese Domicilio'); | 157 | return; |
| 157 | return; | 158 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { |
| 158 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { | 159 | focaModalService.alert('Debe cargar al menos un articulo'); |
| 159 | focaModalService.alert('Debe cargar al menos un articulo'); | 160 | return; |
| 160 | return; | 161 | } |
| 161 | } | 162 | |
| 162 | 163 | focaBotoneraLateralService.startGuardar(); | |
| 163 | focaBotoneraLateralService.startGuardar(); | 164 | $scope.saveLoading = true; |
| 164 | $scope.saveLoading = true; | 165 | var notaPedido = { |
| 165 | var notaPedido = { | 166 | id: $scope.notaPedido.id, |
| 166 | id: $scope.notaPedido.id, | 167 | fechaCarga: new Date($scope.notaPedido.fechaCarga) |
| 167 | fechaCarga: new Date($scope.notaPedido.fechaCarga) | 168 | .toISOString().slice(0, 19).replace('T', ' '), |
| 168 | .toISOString().slice(0, 19).replace('T', ' '), | 169 | idVendedor: $scope.notaPedido.vendedor.id, |
| 169 | idVendedor: $scope.notaPedido.vendedor.id, | 170 | idCliente: $scope.notaPedido.cliente.COD, |
| 170 | idCliente: $scope.notaPedido.cliente.COD, | 171 | nombreCliente: $scope.notaPedido.cliente.NOM, |
| 171 | nombreCliente: $scope.notaPedido.cliente.NOM, | 172 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
| 172 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 173 | idProveedor: $scope.notaPedido.proveedor.COD, |
| 173 | idProveedor: $scope.notaPedido.proveedor.COD, | 174 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 174 | idDomicilio: $scope.notaPedido.domicilio.id, | 175 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
| 175 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 176 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
| 176 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 177 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 177 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 178 | flete: $scope.notaPedido.flete, |
| 178 | flete: $scope.notaPedido.flete, | 179 | fob: $scope.notaPedido.fob, |
| 179 | fob: $scope.notaPedido.fob, | 180 | bomba: $scope.notaPedido.bomba, |
| 180 | bomba: $scope.notaPedido.bomba, | 181 | kilometros: $scope.notaPedido.kilometros, |
| 181 | kilometros: $scope.notaPedido.kilometros, | 182 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
| 182 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 183 | observaciones: $scope.notaPedido.observaciones, |
| 183 | observaciones: $scope.notaPedido.observaciones, | 184 | estado: 0, |
| 184 | estado: 0, | 185 | total: $scope.getTotal() |
| 185 | total: $scope.getTotal() | 186 | }; |
| 186 | }; | 187 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
| 187 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 188 | function(data) { |
| 188 | function(data) { | 189 | // Al guardar los datos de la nota de pedido logueamos la |
| 189 | // Al guardar los datos de la nota de pedido logueamos la | 190 | // actividad para su seguimiento. |
| 190 | // actividad para su seguimiento. | 191 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
| 191 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 192 | focaSeguimientoService.guardarPosicion( |
| 192 | focaSeguimientoService.guardarPosicion( | 193 | 'Nota de pedido', |
| 193 | 'Nota de pedido', | 194 | data.data.id, |
| 194 | data.data.id, | 195 | '' |
| 195 | '' | 196 | ); |
| 196 | ); | 197 | notaPedidoBusinessService.addArticulos( |
| 197 | notaPedidoBusinessService.addArticulos( | 198 | $scope.notaPedido.articulosNotaPedido, |
| 198 | $scope.notaPedido.articulosNotaPedido, | 199 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
| 199 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 200 | |
| 200 | 201 | if ($scope.notaPedido.notaPedidoPuntoDescarga) { | |
| 201 | if ($scope.notaPedido.notaPedidoPuntoDescarga) { | 202 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
| 202 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 203 | $scope.notaPedido.notaPedidoPuntoDescarga); |
| 203 | $scope.notaPedido.notaPedidoPuntoDescarga); | 204 | } |
| 204 | } | 205 | |
| 205 | 206 | var plazos = $scope.notaPedido.notaPedidoPlazo; | |
| 206 | var plazos = $scope.notaPedido.notaPedidoPlazo; | 207 | var plazosACrear = []; |
| 207 | var plazosACrear = []; | 208 | plazos.forEach(function(plazo) { |
| 208 | plazos.forEach(function(plazo) { | 209 | plazosACrear.push({ |
| 209 | plazosACrear.push({ | 210 | idNotaPedido: data.data.id, |
| 210 | idNotaPedido: data.data.id, | 211 | dias: plazo.dias |
| 211 | dias: plazo.dias | 212 | }); |
| 212 | }); | 213 | }); |
| 213 | }); | 214 | |
| 214 | 215 | if (plazosACrear.length) { | |
| 215 | if (plazosACrear.length) { | 216 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); |
| 216 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 217 | } |
| 217 | } | 218 | |
| 218 | 219 | notaPedidoBusinessService.addEstado(data.data.id, | |
| 219 | notaPedidoBusinessService.addEstado(data.data.id, | 220 | $scope.notaPedido.vendedor.id); |
| 220 | $scope.notaPedido.vendedor.id); | 221 | |
| 221 | 222 | focaBotoneraLateralService.endGuardar(true); | |
| 222 | focaBotoneraLateralService.endGuardar(true); | 223 | $scope.saveLoading = false; |
| 223 | $scope.saveLoading = false; | 224 | |
| 224 | 225 | config(); | |
| 225 | config(); | 226 | }, function(error) { |
| 226 | }, function(error) { | 227 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
| 227 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 228 | focaBotoneraLateralService.endGuardar(); |
| 228 | focaBotoneraLateralService.endGuardar(); | 229 | $scope.saveLoading = false; |
| 229 | $scope.saveLoading = false; | 230 | console.info(error); |
| 230 | console.info(error); | 231 | }); |
| 231 | }); | 232 | }; |
| 232 | }; | 233 | |
| 233 | 234 | $scope.seleccionarNotaPedido = function() { | |
| 234 | $scope.seleccionarNotaPedido = function() { | 235 | var modalInstance = $uibModal.open( |
| 235 | var modalInstance = $uibModal.open( | 236 | { |
| 236 | { | 237 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
| 237 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 238 | templateUrl: 'foca-modal-nota-pedido.html', |
| 238 | templateUrl: 'foca-modal-nota-pedido.html', | 239 | controller: 'focaModalNotaPedidoController', |
| 239 | controller: 'focaModalNotaPedidoController', | 240 | size: 'lg', |
| 240 | size: 'lg', | 241 | resolve: { |
| 241 | resolve: { | 242 | usadoPor: function() {return 'notaPedido';}, |
| 242 | usadoPor: function() {return 'notaPedido';}, | 243 | idVendedor: function() { |
| 243 | idVendedor: function() { | 244 | if (APP === 'distribuidor') |
| 244 | if (APP === 'distribuidor') | 245 | return $scope.notaPedido.vendedor.id; |
| 245 | return $scope.notaPedido.vendedor.id; | 246 | else |
| 246 | else | 247 | return null; |
| 247 | return null; | 248 | } |
| 248 | } | 249 | } |
| 249 | } | 250 | } |
| 250 | } | 251 | ); |
| 251 | ); | 252 | modalInstance.result.then(setearNotaPedido); |
| 252 | modalInstance.result.then(setearNotaPedido); | 253 | }; |
| 253 | }; | 254 | |
| 254 | 255 | $scope.seleccionarProductos = function() { | |
| 256 | |||
| 255 | $scope.seleccionarProductos = function() { | 257 | if ($scope.idLista === undefined) { |
| 256 | if ($scope.idLista === undefined) { | 258 | focaModalService.alert( |
| 257 | focaModalService.alert( | 259 | 'Primero seleccione una lista de precio y condicion'); |
| 258 | 'Primero seleccione una lista de precio y condicion'); | 260 | return; |
| 261 | } else if (!validarNotaRemitada()) { | ||
| 262 | return; | ||
| 259 | return; | 263 | } |
| 264 | |||
| 260 | } | 265 | var modalInstance = $uibModal.open( |
| 261 | var modalInstance = $uibModal.open( | 266 | { |
| 262 | { | 267 | ariaLabelledBy: 'Busqueda de Productos', |
| 263 | ariaLabelledBy: 'Busqueda de Productos', | 268 | templateUrl: 'modal-busqueda-productos.html', |
| 264 | templateUrl: 'modal-busqueda-productos.html', | 269 | controller: 'modalBusquedaProductosCtrl', |
| 265 | controller: 'modalBusquedaProductosCtrl', | 270 | resolve: { |
| 266 | resolve: { | 271 | parametroProducto: { |
| 267 | parametroProducto: { | 272 | idLista: $scope.idLista, |
| 268 | idLista: $scope.idLista, | 273 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 269 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 274 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO |
| 270 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO | 275 | } |
| 271 | } | 276 | }, |
| 272 | }, | 277 | size: 'lg' |
| 273 | size: 'lg' | 278 | } |
| 274 | } | 279 | ); |
| 275 | ); | 280 | modalInstance.result.then( |
| 276 | modalInstance.result.then( | 281 | function(producto) { |
| 277 | function(producto) { | 282 | var newArt = |
| 278 | var newArt = | 283 | { |
| 279 | { | 284 | id: 0, |
| 280 | id: 0, | 285 | codigo: producto.codigo, |
| 281 | codigo: producto.codigo, | 286 | sector: producto.sector, |
| 282 | sector: producto.sector, | 287 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 283 | sectorCodigo: producto.sector + '-' + producto.codigo, | 288 | descripcion: producto.descripcion, |
| 284 | descripcion: producto.descripcion, | 289 | item: $scope.notaPedido.articulosNotaPedido.length + 1, |
| 285 | item: $scope.notaPedido.articulosNotaPedido.length + 1, | 290 | nombre: producto.descripcion, |
| 286 | nombre: producto.descripcion, | 291 | precio: parseFloat(producto.precio.toFixed(4)), |
| 287 | precio: parseFloat(producto.precio.toFixed(4)), | 292 | costoUnitario: producto.costo, |
| 288 | costoUnitario: producto.costo, | 293 | editCantidad: false, |
| 289 | editCantidad: false, | 294 | editPrecio: false, |
| 290 | editPrecio: false, | 295 | rubro: producto.CodRub, |
| 291 | rubro: producto.CodRub, | 296 | ivaUnitario: producto.IMPIVA, |
| 292 | ivaUnitario: producto.IMPIVA, | 297 | impuestoInternoUnitario: producto.ImpInt, |
| 293 | impuestoInternoUnitario: producto.ImpInt, | 298 | impuestoInterno1Unitario: producto.ImpInt2, |
| 294 | impuestoInterno1Unitario: producto.ImpInt2, | 299 | impuestoInterno2Unitario: producto.ImpInt3, |
| 295 | impuestoInterno2Unitario: producto.ImpInt3, | 300 | precioLista: producto.precio, |
| 296 | precioLista: producto.precio, | 301 | combustible: 1, |
| 297 | combustible: 1, | 302 | facturado: 0, |
| 298 | facturado: 0, | 303 | idArticulo: producto.id, |
| 299 | idArticulo: producto.id, | 304 | tasaIva: producto.tasaIVA |
| 300 | tasaIva: producto.tasaIVA | 305 | }; |
| 301 | }; | 306 | |
| 302 | 307 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; | |
| 303 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; | 308 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; |
| 304 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; | 309 | |
| 305 | 310 | $scope.articuloACargar = newArt; | |
| 306 | $scope.articuloACargar = newArt; | 311 | $scope.cargando = false; |
| 307 | $scope.cargando = false; | 312 | }, function() { |
| 308 | }, function() { | 313 | // funcion ejecutada cuando se cancela el modal |
| 309 | // funcion ejecutada cuando se cancela el modal | 314 | } |
| 310 | } | 315 | ); |
| 311 | ); | 316 | }; |
| 312 | }; | 317 | |
| 313 | 318 | $scope.seleccionarPuntosDeDescarga = function() { | |
| 314 | $scope.seleccionarPuntosDeDescarga = function() { | 319 | if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
| 315 | if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 320 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
| 316 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 321 | return; |
| 317 | return; | 322 | } else { |
| 318 | } else { | 323 | var modalInstance = $uibModal.open( |
| 319 | var modalInstance = $uibModal.open( | 324 | { |
| 320 | { | 325 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
| 321 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 326 | templateUrl: 'modal-punto-descarga.html', |
| 322 | templateUrl: 'modal-punto-descarga.html', | 327 | controller: 'focaModalPuntoDescargaController', |
| 323 | controller: 'focaModalPuntoDescargaController', | 328 | size: 'lg', |
| 324 | size: 'lg', | 329 | resolve: { |
| 325 | resolve: { | 330 | filters: { |
| 326 | filters: { | 331 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 327 | idDomicilio: $scope.notaPedido.domicilio.id, | 332 | idCliente: $scope.notaPedido.cliente.COD, |
| 328 | idCliente: $scope.notaPedido.cliente.COD, | 333 | articulos: $scope.notaPedido.articulosNotaPedido, |
| 329 | articulos: $scope.notaPedido.articulosNotaPedido, | 334 | puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga, |
| 330 | puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga, | 335 | domicilio: $scope.notaPedido.domicilio |
| 331 | domicilio: $scope.notaPedido.domicilio | 336 | } |
| 332 | } | 337 | } |
| 333 | } | 338 | } |
| 334 | } | 339 | ); |
| 335 | ); | 340 | modalInstance.result.then( |
| 336 | modalInstance.result.then( | 341 | function(puntoDescarga) { |
| 337 | function(puntoDescarga) { | 342 | |
| 343 | puntoDescarga.forEach(function(punto) { | ||
| 344 | $scope.notaPedido.notaPedidoPuntoDescarga.push( | ||
| 345 | { | ||
| 346 | puntoDescarga: punto | ||
| 347 | } | ||
| 348 | ) | ||
| 349 | }); | ||
| 338 | $scope.notaPedido.notaPedidoPuntoDescarga = puntoDescarga; | 350 | |
| 339 | 351 | $scope.$broadcast('addCabecera', { | |
| 340 | $scope.$broadcast('addCabecera', { | 352 | label: 'Puntos de descarga:', |
| 341 | label: 'Puntos de descarga:', | 353 | valor: getCabeceraPuntoDescarga(puntoDescarga) |
| 342 | valor: getCabeceraPuntoDescarga(puntoDescarga) | 354 | }); |
| 343 | }); | 355 | }, function() { |
| 344 | }, function() { | 356 | $scope.abrirModalDomicilios($scope.cliente); |
| 345 | $scope.abrirModalDomicilios($scope.cliente); | 357 | } |
| 346 | } | 358 | ); |
| 347 | ); | 359 | } |
| 348 | } | 360 | }; |
| 349 | }; | 361 | |
| 350 | 362 | $scope.seleccionarProveedor = function() { | |
| 351 | $scope.seleccionarProveedor = function() { | 363 | $scope.abrirModalProveedores(function() { |
| 352 | $scope.abrirModalProveedores(function() { | 364 | if (validarNotaRemitada()) { |
| 353 | if (validarNotaRemitada()) { | 365 | var modalInstance = $uibModal.open( |
| 354 | var modalInstance = $uibModal.open( | 366 | { |
| 355 | { | 367 | ariaLabelledBy: 'Busqueda de Flete', |
| 356 | ariaLabelledBy: 'Busqueda de Flete', | 368 | templateUrl: 'modal-flete.html', |
| 357 | templateUrl: 'modal-flete.html', | 369 | controller: 'focaModalFleteController', |
| 358 | controller: 'focaModalFleteController', | 370 | size: 'lg', |
| 359 | size: 'lg', | 371 | resolve: { |
| 360 | resolve: { | 372 | parametrosFlete: |
| 361 | parametrosFlete: | 373 | function() { |
| 362 | function() { | 374 | return { |
| 363 | return { | 375 | flete: $scope.notaPedido.fob ? 'FOB' : |
| 364 | flete: $scope.notaPedido.fob ? 'FOB' : | 376 | ( $scope.notaPedido.flete ? '1' : |
| 365 | ( $scope.notaPedido.flete ? '1' : | 377 | ($scope.notaPedido.flete === undefined ? |
| 366 | ($scope.notaPedido.flete === undefined ? | 378 | null : '0')), |
| 367 | null : '0')), | 379 | bomba: $scope.notaPedido.bomba ? '1' : |
| 368 | bomba: $scope.notaPedido.bomba ? '1' : | 380 | ($scope.notaPedido.bomba === undefined ? |
| 369 | ($scope.notaPedido.bomba === undefined ? | 381 | null : '0'), |
| 370 | null : '0'), | 382 | kilometros: $scope.notaPedido.kilometros |
| 371 | kilometros: $scope.notaPedido.kilometros | 383 | }; |
| 372 | }; | 384 | } |
| 373 | } | 385 | } |
| 374 | } | 386 | } |
| 375 | } | 387 | ); |
| 376 | ); | 388 | modalInstance.result.then( |
| 377 | modalInstance.result.then( | 389 | function(datos) { |
| 378 | function(datos) { | 390 | $scope.notaPedido.flete = datos.flete; |
| 379 | $scope.notaPedido.flete = datos.flete; | 391 | $scope.notaPedido.fob = datos.FOB; |
| 380 | $scope.notaPedido.fob = datos.FOB; | 392 | $scope.notaPedido.bomba = datos.bomba; |
| 381 | $scope.notaPedido.bomba = datos.bomba; | 393 | $scope.notaPedido.kilometros = datos.kilometros; |
| 382 | $scope.notaPedido.kilometros = datos.kilometros; | 394 | $scope.$broadcast('addCabecera', { |
| 383 | $scope.$broadcast('addCabecera', { | 395 | label: 'Flete:', |
| 384 | label: 'Flete:', | 396 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
| 385 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 397 | }); |
| 386 | }); | 398 | if (datos.flete) { |
| 387 | if (datos.flete) { | 399 | $scope.$broadcast('addCabecera', { |
| 388 | $scope.$broadcast('addCabecera', { | 400 | label: 'Bomba:', |
| 389 | label: 'Bomba:', | 401 | valor: datos.bomba ? 'Si' : 'No' |
| 390 | valor: datos.bomba ? 'Si' : 'No' | 402 | }); |
| 391 | }); | 403 | $scope.$broadcast('addCabecera', { |
| 392 | $scope.$broadcast('addCabecera', { | 404 | label: 'Kilometros:', |
| 393 | label: 'Kilometros:', | 405 | valor: datos.kilometros |
| 394 | valor: datos.kilometros | 406 | }); |
| 395 | }); | 407 | } else { |
| 396 | } else { | 408 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 397 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 409 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 398 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 410 | $scope.notaPedido.bomba = false; |
| 399 | $scope.notaPedido.bomba = false; | 411 | $scope.notaPedido.kilometros = null; |
| 400 | $scope.notaPedido.kilometros = null; | 412 | } |
| 401 | } | 413 | |
| 402 | 414 | $filter('filter')($scope.botonera, | |
| 403 | $filter('filter')($scope.botonera, | 415 | { label: 'Proveedor'})[0].checked = true; |
| 404 | { label: 'Proveedor'})[0].checked = true; | 416 | }, function() { |
| 405 | }, function() { | 417 | $scope.seleccionarTransportista(); |
| 406 | $scope.seleccionarTransportista(); | 418 | } |
| 407 | } | 419 | ); |
| 408 | ); | 420 | } |
| 409 | } | 421 | }); |
| 410 | }); | 422 | }; |
| 411 | }; | 423 | |
| 412 | 424 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { | |
| 413 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { | 425 | if (APP === 'distribuidor' || ocultarVendedor) { |
| 414 | if (APP === 'distribuidor' || ocultarVendedor) { | 426 | callback(); |
| 415 | callback(); | 427 | return; |
| 416 | return; | 428 | } |
| 417 | } | 429 | |
| 418 | 430 | if (validarNotaRemitada()) { | |
| 419 | if (validarNotaRemitada()) { | 431 | var parametrosModal = { |
| 420 | var parametrosModal = { | 432 | titulo: 'Búsqueda vendedores', |
| 421 | titulo: 'Búsqueda vendedores', | 433 | query: '/vendedor', |
| 422 | query: '/vendedor', | 434 | columnas: [ |
| 423 | columnas: [ | 435 | { |
| 424 | { | 436 | propiedad: 'NUM', |
| 425 | propiedad: 'NUM', | 437 | nombre: 'Código', |
| 426 | nombre: 'Código', | 438 | filtro: { |
| 427 | filtro: { | 439 | nombre: 'rellenarDigitos', |
| 428 | nombre: 'rellenarDigitos', | 440 | parametro: 3 |
| 429 | parametro: 3 | 441 | } |
| 430 | } | 442 | }, |
| 431 | }, | 443 | { |
| 432 | { | 444 | propiedad: 'NOM', |
| 433 | propiedad: 'NOM', | 445 | nombre: 'Nombre' |
| 434 | nombre: 'Nombre' | 446 | } |
| 435 | } | 447 | ], |
| 436 | ], | 448 | size: 'md' |
| 437 | size: 'md' | 449 | }; |
| 438 | }; | 450 | focaModalService.modal(parametrosModal).then( |
| 439 | focaModalService.modal(parametrosModal).then( | 451 | function(vendedor) { |
| 440 | function(vendedor) { | 452 | $scope.$broadcast('addCabecera', { |
| 441 | $scope.$broadcast('addCabecera', { | 453 | label: 'Vendedor:', |
| 442 | label: 'Vendedor:', | 454 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
| 443 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 455 | vendedor.NOM |
| 444 | vendedor.NOM | 456 | }); |
| 445 | }); | 457 | $scope.notaPedido.vendedor = vendedor; |
| 446 | $scope.notaPedido.vendedor = vendedor; | 458 | deleteCliente(); |
| 447 | deleteCliente(); | 459 | callback(); |
| 448 | callback(); | 460 | }, function() {} |
| 449 | }, function() {} | 461 | ); |
| 450 | ); | 462 | } |
| 451 | } | 463 | }; |
| 452 | }; | 464 | |
| 453 | 465 | $scope.seleccionarCliente = function(ocultarVendedor) { | |
| 454 | $scope.seleccionarCliente = function(ocultarVendedor) { | 466 | $scope.seleccionarVendedor(function() { |
| 455 | $scope.seleccionarVendedor(function() { | 467 | if (validarNotaRemitada()) { |
| 456 | if (validarNotaRemitada()) { | 468 | var modalInstance = $uibModal.open( |
| 457 | var modalInstance = $uibModal.open( | 469 | { |
| 458 | { | 470 | ariaLabelledBy: 'Busqueda de Cliente', |
| 459 | ariaLabelledBy: 'Busqueda de Cliente', | 471 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 460 | templateUrl: 'foca-busqueda-cliente-modal.html', | 472 | controller: 'focaBusquedaClienteModalController', |
| 461 | controller: 'focaBusquedaClienteModalController', | 473 | resolve: { |
| 462 | resolve: { | 474 | vendedor: function() { return $scope.notaPedido.vendedor; }, |
| 463 | vendedor: function() { return $scope.notaPedido.vendedor; }, | 475 | cobrador: function() { return null; } |
| 464 | cobrador: function() { return null; } | 476 | }, |
| 465 | }, | 477 | size: 'lg' |
| 466 | size: 'lg' | 478 | } |
| 467 | } | 479 | ); |
| 468 | ); | 480 | modalInstance.result.then( |
| 469 | modalInstance.result.then( | 481 | function(cliente) { |
| 470 | function(cliente) { | 482 | $scope.abrirModalDomicilios(cliente); |
| 471 | $scope.abrirModalDomicilios(cliente); | 483 | $scope.cliente = cliente; |
| 472 | $scope.cliente = cliente; | 484 | }, function() { |
| 473 | }, function() { | 485 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); |
| 474 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); | 486 | } |
| 475 | } | 487 | ); |
| 476 | ); | 488 | } |
| 477 | } | 489 | }, ocultarVendedor); |
| 478 | }, ocultarVendedor); | 490 | }; |
| 479 | }; | 491 | |
| 480 | 492 | $scope.abrirModalProveedores = function(callback) { | |
| 481 | $scope.abrirModalProveedores = function(callback) { | 493 | if (validarNotaRemitada()) { |
| 482 | if (validarNotaRemitada()) { | 494 | var parametrosModal = { |
| 483 | var parametrosModal = { | 495 | titulo: 'Búsqueda de Proveedor', |
| 484 | titulo: 'Búsqueda de Proveedor', | 496 | query: '/proveedor', |
| 485 | query: '/proveedor', | 497 | columnas: [ |
| 486 | columnas: [ | 498 | { |
| 487 | { | 499 | nombre: 'Código', |
| 488 | nombre: 'Código', | 500 | propiedad: 'COD', |
| 489 | propiedad: 'COD', | 501 | filtro: { |
| 490 | filtro: { | 502 | nombre: 'rellenarDigitos', |
| 491 | nombre: 'rellenarDigitos', | 503 | parametro: 5 |
| 492 | parametro: 5 | 504 | } |
| 493 | } | 505 | }, |
| 494 | }, | 506 | { |
| 495 | { | 507 | nombre: 'Nombre', |
| 496 | nombre: 'Nombre', | 508 | propiedad: 'NOM' |
| 497 | propiedad: 'NOM' | 509 | }, |
| 498 | }, | 510 | { |
| 499 | { | 511 | nombre: 'CUIT', |
| 500 | nombre: 'CUIT', | 512 | propiedad: 'CUIT' |
| 501 | propiedad: 'CUIT' | 513 | } |
| 502 | } | 514 | ], |
| 503 | ], | 515 | tipo: 'POST', |
| 504 | tipo: 'POST', | 516 | json: {razonCuitCod: ''} |
| 505 | json: {razonCuitCod: ''} | 517 | }; |
| 506 | }; | 518 | focaModalService.modal(parametrosModal).then( |
| 507 | focaModalService.modal(parametrosModal).then( | 519 | function(proveedor) { |
| 508 | function(proveedor) { | 520 | $scope.notaPedido.proveedor = proveedor; |
| 509 | $scope.notaPedido.proveedor = proveedor; | 521 | $scope.$broadcast('addCabecera', { |
| 510 | $scope.$broadcast('addCabecera', { | 522 | label: 'Proveedor:', |
| 511 | label: 'Proveedor:', | 523 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
| 512 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 524 | proveedor.NOM |
| 513 | proveedor.NOM | 525 | }); |
| 514 | }); | 526 | callback(); |
| 515 | callback(); | 527 | }, function() { |
| 516 | }, function() { | 528 | |
| 517 | 529 | } | |
| 518 | } | 530 | ); |
| 519 | ); | 531 | } |
| 520 | } | 532 | }; |
| 521 | }; | 533 | |
| 522 | 534 | $scope.abrirModalDomicilios = function(cliente) { | |
| 523 | $scope.abrirModalDomicilios = function(cliente) { | 535 | var modalInstanceDomicilio = $uibModal.open( |
| 524 | var modalInstanceDomicilio = $uibModal.open( | 536 | { |
| 525 | { | 537 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 526 | ariaLabelledBy: 'Busqueda de Domicilios', | 538 | templateUrl: 'modal-domicilio.html', |
| 527 | templateUrl: 'modal-domicilio.html', | 539 | controller: 'focaModalDomicilioController', |
| 528 | controller: 'focaModalDomicilioController', | 540 | resolve: { |
| 529 | resolve: { | 541 | idCliente: function() { return cliente.cod; }, |
| 530 | idCliente: function() { return cliente.cod; }, | 542 | esNuevo: function() { return cliente.esNuevo; } |
| 531 | esNuevo: function() { return cliente.esNuevo; } | 543 | }, |
| 532 | }, | 544 | size: 'lg', |
| 533 | size: 'lg', | 545 | } |
| 534 | } | 546 | ); |
| 535 | ); | 547 | modalInstanceDomicilio.result.then( |
| 536 | modalInstanceDomicilio.result.then( | 548 | function(domicilio) { |
| 537 | function(domicilio) { | 549 | $scope.notaPedido.domicilio = domicilio; |
| 538 | $scope.notaPedido.domicilio = domicilio; | 550 | $scope.notaPedido.cliente = { |
| 539 | $scope.notaPedido.cliente = { | 551 | COD: cliente.cod, |
| 540 | COD: cliente.cod, | 552 | CUIT: cliente.cuit, |
| 541 | CUIT: cliente.cuit, | 553 | NOM: cliente.nom, |
| 542 | NOM: cliente.nom, | 554 | MOD: cliente.mod |
| 543 | MOD: cliente.mod | 555 | }; |
| 544 | }; | 556 | var domicilioStamp = |
| 545 | var domicilioStamp = | 557 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
| 546 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 558 | domicilio.Localidad + ', ' + domicilio.Provincia; |
| 547 | domicilio.Localidad + ', ' + domicilio.Provincia; | 559 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
| 548 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 560 | |
| 549 | |||
| 550 | $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntoDescarga; | ||
| 551 | 561 | $scope.$broadcast('addCabecera', { | |
| 552 | $scope.$broadcast('addCabecera', { | 562 | label: 'Cliente:', |
| 553 | label: 'Cliente:', | 563 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom |
| 554 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom | 564 | }); |
| 555 | }); | 565 | |
| 556 | 566 | $scope.$broadcast('addCabecera', { | |
| 557 | $scope.$broadcast('addCabecera', { | 567 | label: 'Domicilio:', |
| 558 | label: 'Domicilio:', | 568 | valor: domicilioStamp |
| 559 | valor: domicilioStamp | 569 | }); |
| 560 | }); | 570 | |
| 561 | 571 | if (domicilio.verPuntos) { | |
| 562 | if (domicilio.verPuntos) { | 572 | delete $scope.notaPedido.domicilio.verPuntos; |
| 563 | delete $scope.notaPedido.domicilio.verPuntos; | 573 | $scope.seleccionarPuntosDeDescarga(); |
| 564 | $scope.seleccionarPuntosDeDescarga(); | ||
| 565 | } else { | ||
| 566 | crearNotaPedidoService | ||
| 567 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | ||
| 568 | .then(function(res) { | ||
| 569 | if (res.data.length) $scope.seleccionarPuntosDeDescarga(); | ||
| 570 | }); | 574 | } |
| 571 | } | 575 | |
| 572 | 576 | // Seteo checked en botonera | |
| 573 | // Seteo checked en botonera | 577 | $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = true; |
| 574 | $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = true; | 578 | |
| 575 | 579 | }, function() { | |
| 576 | }, function() { | 580 | $scope.seleccionarCliente(true); |
| 577 | $scope.seleccionarCliente(true); | 581 | return; |
| 578 | return; | 582 | } |
| 579 | } | 583 | ); |
| 580 | ); | 584 | }; |
| 581 | }; | 585 | |
| 582 | 586 | $scope.getTotal = function() { | |
| 583 | $scope.getTotal = function() { | 587 | var total = 0; |
| 584 | var total = 0; | 588 | if ($scope.notaPedido.articulosNotaPedido) { |
| 585 | if ($scope.notaPedido.articulosNotaPedido) { | 589 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; |
| 586 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; | 590 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 587 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 591 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 588 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 592 | } |
| 589 | } | 593 | } |
| 590 | } | 594 | return parseFloat(total.toFixed(2)); |
| 591 | return parseFloat(total.toFixed(2)); | 595 | }; |
| 592 | }; | 596 | |
| 593 | 597 | $scope.getSubTotal = function() { | |
| 594 | $scope.getSubTotal = function() { | 598 | if ($scope.articuloACargar) { |
| 595 | if ($scope.articuloACargar) { | 599 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 596 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 600 | } |
| 597 | } | 601 | }; |
| 598 | }; | 602 | |
| 599 | 603 | $scope.seleccionarPreciosYCondiciones = function() { | |
| 604 | |||
| 605 | if (!validarNotaRemitada()) { | ||
| 606 | return; | ||
| 607 | } | ||
| 608 | |||
| 600 | $scope.seleccionarPreciosYCondiciones = function() { | 609 | if (!$scope.notaPedido.cliente.COD) { |
| 601 | if (!$scope.notaPedido.cliente.COD) { | 610 | focaModalService.alert('Primero seleccione un cliente'); |
| 602 | focaModalService.alert('Primero seleccione un cliente'); | 611 | return; |
| 603 | return; | 612 | } |
| 604 | } | 613 | if ($scope.notaPedido.articulosNotaPedido.length !== 0) { |
| 605 | if ($scope.notaPedido.articulosNotaPedido.length !== 0) { | 614 | focaModalService.confirm('Se perderan los productos ingresados') |
| 606 | focaModalService.confirm('Se perderan los productos ingresados') | 615 | .then(function(data) { |
| 607 | .then(function(data) { | 616 | if (data) { |
| 608 | if (data) { | 617 | abrirModal(); |
| 609 | abrirModal(); | 618 | } |
| 610 | } | 619 | }); |
| 611 | }); | 620 | } else if (validarNotaRemitada()) { |
| 612 | } else if (validarNotaRemitada()) { | 621 | abrirModal(); |
| 613 | abrirModal(); | 622 | } |
| 614 | } | 623 | function abrirModal() { |
| 615 | function abrirModal() { | 624 | var modalInstance = $uibModal.open( |
| 616 | var modalInstance = $uibModal.open( | 625 | { |
| 617 | { | 626 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 618 | ariaLabelledBy: 'Busqueda de Precio Condición', | 627 | templateUrl: 'modal-precio-condicion.html', |
| 619 | templateUrl: 'modal-precio-condicion.html', | 628 | controller: 'focaModalPrecioCondicionController', |
| 620 | controller: 'focaModalPrecioCondicionController', | 629 | size: 'lg', |
| 621 | size: 'lg', | 630 | resolve: { |
| 622 | resolve: { | 631 | idListaPrecio: function() { |
| 623 | idListaPrecio: function() { | 632 | return $scope.notaPedido.cliente.MOD || null; |
| 624 | return $scope.notaPedido.cliente.MOD || null; | 633 | } |
| 625 | } | 634 | } |
| 626 | } | 635 | } |
| 627 | } | 636 | ); |
| 628 | ); | 637 | |
| 629 | 638 | modalInstance.result.then( | |
| 630 | modalInstance.result.then( | 639 | function(precioCondicion) { |
| 631 | function(precioCondicion) { | 640 | var cabecera = ''; |
| 632 | var cabecera = ''; | 641 | var plazosConcat = ''; |
| 633 | var plazosConcat = ''; | 642 | if (!Array.isArray(precioCondicion)) { |
| 634 | if (!Array.isArray(precioCondicion)) { | 643 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; |
| 635 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; | 644 | $scope.notaPedido.precioCondicion = precioCondicion; |
| 636 | $scope.notaPedido.precioCondicion = precioCondicion; | 645 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
| 637 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 646 | $scope.idLista = precioCondicion.idListaPrecio; |
| 638 | $scope.idLista = precioCondicion.idListaPrecio; | 647 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 639 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { | 648 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
| 640 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 649 | } |
| 641 | } | 650 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + |
| 642 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + | 651 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); |
| 643 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); | 652 | } else { //Cuando se ingresan los plazos manualmente |
| 644 | } else { //Cuando se ingresan los plazos manualmente | 653 | $scope.notaPedido.idPrecioCondicion = 0; |
| 645 | $scope.notaPedido.idPrecioCondicion = 0; | 654 | //-1, el modal productos busca todos los productos |
| 646 | //-1, el modal productos busca todos los productos | 655 | $scope.idLista = -1; |
| 647 | $scope.idLista = -1; | 656 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; |
| 648 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; | 657 | for (var j = 0; j < precioCondicion.length; j++) { |
| 649 | for (var j = 0; j < precioCondicion.length; j++) { | 658 | plazosConcat += precioCondicion[j].dias + ' '; |
| 650 | plazosConcat += precioCondicion[j].dias + ' '; | 659 | } |
| 651 | } | 660 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
| 652 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 661 | } |
| 653 | } | 662 | $scope.notaPedido.articulosNotaPedido = []; |
| 654 | $scope.notaPedido.articulosNotaPedido = []; | 663 | $scope.$broadcast('addCabecera', { |
| 655 | $scope.$broadcast('addCabecera', { | 664 | label: 'Precios y condiciones:', |
| 656 | label: 'Precios y condiciones:', | 665 | valor: cabecera |
| 657 | valor: cabecera | 666 | }); |
| 658 | }); | 667 | |
| 659 | 668 | $filter('filter')($scope.botonera, | |
| 660 | $filter('filter')($scope.botonera, | 669 | { label: 'Precios y Condiciones'})[0].checked = true; |
| 661 | { label: 'Precios y Condiciones'})[0].checked = true; | 670 | }, function() { |
| 662 | }, function() { | 671 | |
| 663 | 672 | } | |
| 664 | } | 673 | ); |
| 665 | ); | 674 | } |
| 666 | } | 675 | }; |
| 667 | }; | 676 | |
| 668 | 677 | $scope.seleccionarMoneda = function() { | |
| 669 | $scope.seleccionarMoneda = function() { | 678 | if (validarNotaRemitada()) { |
| 670 | if (validarNotaRemitada()) { | 679 | var parametrosModal = { |
| 671 | var parametrosModal = { | 680 | titulo: 'Búsqueda de monedas', |
| 672 | titulo: 'Búsqueda de monedas', | 681 | query: '/moneda', |
| 673 | query: '/moneda', | 682 | columnas: [ |
| 674 | columnas: [ | 683 | { |
| 675 | { | 684 | propiedad: 'DETALLE', |
| 676 | propiedad: 'DETALLE', | 685 | nombre: 'Nombre' |
| 677 | nombre: 'Nombre' | 686 | }, |
| 678 | }, | 687 | { |
| 679 | { | 688 | propiedad: 'SIMBOLO', |
| 680 | propiedad: 'SIMBOLO', | 689 | nombre: 'Símbolo' |
| 681 | nombre: 'Símbolo' | 690 | } |
| 682 | } | 691 | ], |
| 683 | ], | 692 | size: 'md' |
| 684 | size: 'md' | 693 | }; |
| 685 | }; | 694 | focaModalService.modal(parametrosModal).then( |
| 686 | focaModalService.modal(parametrosModal).then( | 695 | function(moneda) { |
| 687 | function(moneda) { | ||
| 688 | if (moneda.ID !== 1) { | ||
| 689 | $scope.abrirModalCotizacion(moneda); | 696 | |
| 697 | if (moneda.ID !== 1) { | ||
| 698 | $scope.abrirModalCotizacion(moneda); | ||
| 699 | return; | ||
| 700 | } | ||
| 701 | |||
| 702 | crearNotaPedidoService.getCotizacionByIdMoneda(1) | ||
| 703 | .then(function (res) { | ||
| 704 | |||
| 705 | cotizacionPArgentino = res.data[0].cotizaciones[0]; | ||
| 706 | cotizacionPArgentino.moneda = moneda; | ||
| 707 | |||
| 708 | actualizarCabeceraMoneda(cotizacionPArgentino); | ||
| 709 | $scope.notaPedido.cotizacion = cotizacionPArgentino; | ||
| 710 | }); | ||
| 690 | } | 711 | } |
| 691 | crearNotaPedidoService.getCotizacionByIdMoneda(1) | 712 | ); |
| 692 | .then(function (res){ | 713 | } |
| 693 | cotizacionPArgentino = res.data[0]; | 714 | }; |
| 694 | $scope.notaPedido.cotizacion = cotizacionPArgentino; | 715 | |
| 695 | $scope.notaPedido.cotizacion.moneda = moneda; | 716 | $scope.seleccionarObservaciones = function() { |
| 696 | actualizarCabeceraMoneda(cotizacionPArgentino); | 717 | var observacion = { |
| 697 | }); | 718 | titulo: 'Ingrese Observaciones', |
| 698 | } | 719 | value: $scope.notaPedido.observaciones, |
| 699 | ); | 720 | maxlength: 155, |
| 700 | } | 721 | textarea: true |
| 701 | }; | 722 | }; |
| 702 | 723 | ||
| 703 | $scope.seleccionarObservaciones = function() { | 724 | focaModalService |
| 704 | var observacion = { | 725 | .prompt(observacion) |
| 705 | titulo: 'Ingrese Observaciones', | 726 | .then(function(observaciones) { |
| 706 | value: $scope.notaPedido.observaciones, | 727 | $scope.notaPedido.observaciones = observaciones; |
| 707 | maxlength: 155, | 728 | }); |
| 708 | textarea: true | 729 | }; |
| 709 | }; | 730 | |
| 710 | 731 | $scope.abrirModalCotizacion = function(moneda) { | |
| 711 | focaModalService | 732 | var modalInstance = $uibModal.open( |
| 712 | .prompt(observacion) | 733 | { |
| 713 | .then(function(observaciones) { | 734 | ariaLabelledBy: 'Busqueda de Cotización', |
| 714 | $scope.notaPedido.observaciones = observaciones; | 735 | templateUrl: 'modal-cotizacion.html', |
| 715 | }); | 736 | controller: 'focaModalCotizacionController', |
| 716 | }; | 737 | size: 'lg', |
| 717 | 738 | resolve: { | |
| 718 | $scope.abrirModalCotizacion = function(moneda) { | 739 | idMoneda: function() { |
| 719 | var modalInstance = $uibModal.open( | 740 | return moneda.ID; |
| 720 | { | 741 | } |
| 721 | ariaLabelledBy: 'Busqueda de Cotización', | 742 | } |
| 722 | templateUrl: 'modal-cotizacion.html', | 743 | } |
| 723 | controller: 'focaModalCotizacionController', | 744 | ); |
| 724 | size: 'lg', | 745 | modalInstance.result.then( |
| 725 | resolve: { | 746 | function(cotizacion) { |
| 726 | idMoneda: function() { | ||
| 727 | return moneda.ID; | ||
| 728 | } | ||
| 729 | } | ||
| 730 | } | ||
| 731 | ); | ||
| 732 | modalInstance.result.then( | ||
| 733 | function(cotizacion) { | ||
| 734 | var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; | ||
| 735 | for (var i = 0; i < articulosTablaTemp.length; i++) { | ||
| 736 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | ||
| 737 | $scope.notaPedido.cotizacion.VENDEDOR; | ||
| 738 | articulosTablaTemp[i].precio = (articulosTablaTemp[i].precio / | ||
| 739 | cotizacion.VENDEDOR).toFixed(4); | ||
| 740 | } | ||
| 741 | $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; | ||
| 742 | $scope.notaPedido.cotizacion = cotizacion; | ||
| 743 | $scope.notaPedido.cotizacion.moneda = moneda; | ||
| 744 | actualizarCabeceraMoneda(cotizacion); | ||
| 745 | |||
| 746 | $filter('filter')($scope.botonera, { label: 'Moneda'})[0].checked = true; | ||
| 747 | }, function() { | ||
| 748 | |||
| 749 | } | ||
| 750 | ); | ||
| 751 | }; | ||
| 752 | |||
| 753 | function actualizarCabeceraMoneda (cotizacion) { | ||
| 754 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | 747 | |
| 748 | cotizacion.moneda = moneda; | ||
| 749 | actualizarCabeceraMoneda(cotizacion); | ||
| 750 | |||
| 751 | $scope.notaPedido.cotizacion = cotizacion; | ||
| 755 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 752 | $filter('filter')($scope.botonera, { label: 'Moneda'})[0].checked = true; |
| 756 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 753 | }, function() { |
| 757 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 754 | |
| 758 | } else { | 755 | } |
| 759 | $scope.$broadcast('addCabecera', { | 756 | ); |
| 760 | label: 'Moneda:', | 757 | }; |
| 761 | valor: cotizacion.moneda.DETALLE | 758 | |
| 759 | function actualizarCabeceraMoneda (cotizacion) { | ||
| 760 | |||
| 761 | $scope.notaPedido.articulosNotaPedido.forEach(function(art) { | ||
| 762 | art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); | ||
| 763 | art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); | ||
| 764 | }); | ||
| 765 | |||
| 766 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | ||
| 767 | $scope.$broadcast('removeCabecera', 'Moneda:'); | ||
| 768 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | ||
| 769 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | ||
| 770 | } else { | ||
| 771 | $scope.$broadcast('addCabecera', { | ||
| 772 | label: 'Moneda:', | ||
| 773 | valor: cotizacion.moneda.DETALLE | ||
| 774 | }); | ||
| 775 | $scope.$broadcast('addCabecera', { | ||
| 776 | label: 'Fecha cotizacion:', | ||
| 777 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | ||
| 778 | }); | ||
| 779 | $scope.$broadcast('addCabecera', { | ||
| 780 | label: 'Cotizacion:', | ||
| 781 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | ||
| 782 | }); | ||
| 783 | } | ||
| 784 | } | ||
| 785 | |||
| 762 | }); | 786 | $scope.agregarATabla = function(key) { |
| 763 | $scope.$broadcast('addCabecera', { | 787 | if (key === 13) { |
| 764 | label: 'Fecha cotizacion:', | 788 | if ($scope.articuloACargar.cantidad === undefined || |
| 765 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 789 | $scope.articuloACargar.cantidad === 0 || |
| 766 | }); | 790 | $scope.articuloACargar.cantidad === null ) { |
| 767 | $scope.$broadcast('addCabecera', { | 791 | focaModalService.alert('El valor debe ser al menos 1'); |
| 768 | label: 'Cotizacion:', | 792 | return; |
| 769 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 793 | } |
| 770 | }); | 794 | delete $scope.articuloACargar.sectorCodigo; |
| 771 | } | 795 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); |
| 772 | } | 796 | $scope.cargando = true; |
| 773 | 797 | } | |
| 774 | $scope.agregarATabla = function(key) { | 798 | }; |
| 775 | if (key === 13) { | 799 | |
| 776 | if ($scope.articuloACargar.cantidad === undefined || | 800 | $scope.quitarArticulo = function(key) { |
| 777 | $scope.articuloACargar.cantidad === 0 || | 801 | if (validarNotaRemitada()) { |
| 802 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); | ||
| 803 | } | ||
| 778 | $scope.articuloACargar.cantidad === null ) { | 804 | }; |
| 779 | focaModalService.alert('El valor debe ser al menos 1'); | 805 | |
| 780 | return; | 806 | $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) { |
| 781 | } | 807 | if (key === 13) { |
| 782 | delete $scope.articuloACargar.sectorCodigo; | 808 | if (!articulo.cantidad || !articulo.precio) { |
| 783 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); | 809 | focaModalService.alert('Los valores deben ser al menos 1'); |
| 784 | $scope.cargando = true; | 810 | return; |
| 785 | } | 811 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { |
| 786 | }; | 812 | focaModalService.alert('Los valores no pueden ser negativos'); |
| 787 | 813 | return; | |
| 788 | $scope.quitarArticulo = function(key) { | 814 | } |
| 789 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); | 815 | articulo.cantidad = tmpCantidad; |
| 790 | }; | 816 | articulo.precio = tmpPrecio; |
| 791 | 817 | $scope.getTotal(); | |
| 792 | $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) { | 818 | articulo.editCantidad = articulo.editPrecio = false; |
| 793 | if (key === 13) { | 819 | } |
| 794 | if (!articulo.cantidad || !articulo.precio) { | 820 | }; |
| 795 | focaModalService.alert('Los valores deben ser al menos 1'); | 821 | |
| 796 | return; | 822 | $scope.cancelarEditar = function(articulo) { |
| 797 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { | 823 | $scope.tmpCantidad = articulo.cantidad; |
| 798 | focaModalService.alert('Los valores no pueden ser negativos'); | 824 | $scope.tmpPrecio = articulo.precio; |
| 799 | return; | 825 | articulo.editCantidad = articulo.editPrecio = false; |
| 800 | } | 826 | }; |
| 801 | articulo.cantidad = tmpCantidad; | 827 | |
| 802 | articulo.precio = tmpPrecio; | 828 | $scope.cambioEdit = function(articulo, propiedad) { |
| 803 | $scope.getTotal(); | 829 | if (propiedad === 'cantidad') { |
| 804 | articulo.editCantidad = articulo.editPrecio = false; | 830 | articulo.editCantidad = true; |
| 805 | } | 831 | } else if (propiedad === 'precio') { |
| 806 | }; | 832 | articulo.editPrecio = true; |
| 807 | 833 | } | |
| 808 | $scope.cancelarEditar = function(articulo) { | 834 | }; |
| 809 | $scope.tmpCantidad = articulo.cantidad; | 835 | |
| 810 | $scope.tmpPrecio = articulo.precio; | 836 | $scope.resetFilter = function() { |
| 811 | articulo.editCantidad = articulo.editPrecio = false; | 837 | $scope.articuloACargar = {}; |
| 812 | }; | 838 | $scope.cargando = true; |
| 813 | 839 | }; | |
| 814 | $scope.cambioEdit = function(articulo, propiedad) { | 840 | //Recibe aviso si el teclado está en uso |
| 815 | if (propiedad === 'cantidad') { | 841 | $rootScope.$on('usarTeclado', function(event, data) { |
| 816 | articulo.editCantidad = true; | 842 | if (data) { |
| 817 | } else if (propiedad === 'precio') { | 843 | $scope.mostrarTeclado = true; |
| 818 | articulo.editPrecio = true; | 844 | return; |
| 819 | } | 845 | } |
| 820 | }; | 846 | $scope.mostrarTeclado = false; |
| 821 | 847 | }); | |
| 822 | $scope.resetFilter = function() { | 848 | |
| 823 | $scope.articuloACargar = {}; | 849 | $scope.selectFocus = function($event) { |
| 824 | $scope.cargando = true; | 850 | // Si el teclado esta en uso no selecciona el valor |
| 825 | }; | 851 | if ($scope.mostrarTeclado) { |
| 826 | //Recibe aviso si el teclado está en uso | 852 | return; |
| 827 | $rootScope.$on('usarTeclado', function(event, data) { | 853 | } |
| 828 | if (data) { | 854 | $event.target.select(); |
| 829 | $scope.mostrarTeclado = true; | 855 | }; |
| 830 | return; | 856 | |
| 831 | } | 857 | $scope.salir = function() { |
| 832 | $scope.mostrarTeclado = false; | 858 | $location.path('/'); |
| 833 | }); | 859 | }; |
| 834 | 860 | ||
| 835 | $scope.selectFocus = function($event) { | 861 | $scope.parsearATexto = function(articulo) { |
| 836 | // Si el teclado esta en uso no selecciona el valor | 862 | articulo.cantidad = parseFloat(articulo.cantidad); |
| 837 | if ($scope.mostrarTeclado) { | 863 | articulo.precio = parseFloat(articulo.precio); |
| 838 | return; | 864 | }; |
| 839 | } | 865 | |
| 840 | $event.target.select(); | 866 | // TODO: quitar watch usar función de articulos pedido cuando se haga |
| 841 | }; | 867 | $scope.$watch('notaPedido.articulosNotaPedido', function() { |
| 842 | 868 | if ($scope.notaPedido.articulosNotaPedido.length) { | |
| 843 | $scope.salir = function() { | 869 | $filter('filter')($scope.botonera, |
| 844 | $location.path('/'); | 870 | { label: 'Productos'})[0].checked = true; |
| 845 | }; | 871 | } else { |
| 846 | 872 | $filter('filter')($scope.botonera, | |
| 847 | $scope.parsearATexto = function(articulo) { | 873 | { label: 'Productos'})[0].checked = false; |
| 848 | articulo.cantidad = parseFloat(articulo.cantidad); | 874 | } |
| 849 | articulo.precio = parseFloat(articulo.precio); | 875 | }, true); |
| 850 | }; | 876 | |
| 851 | 877 | function setearNotaPedido(notaPedido) { | |
| 852 | // TODO: quitar watch usar función de articulos pedido cuando se haga | 878 | //añado cabeceras |
| 853 | $scope.$watch('notaPedido.articulosNotaPedido', function() { | 879 | $scope.notaPedido = notaPedido; |
| 854 | if ($scope.notaPedido.articulosNotaPedido.length) { | 880 | if (!$scope.notaPedido.domicilio) { |
| 855 | $filter('filter')($scope.botonera, | 881 | $scope.notaPedido.domicilio = { |
| 856 | { label: 'Productos'})[0].checked = true; | 882 | id: $scope.notaPedido.idDomicilio |
| 857 | } else { | 883 | }; |
| 858 | $filter('filter')($scope.botonera, | 884 | } |
| 859 | { label: 'Productos'})[0].checked = false; | 885 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 860 | } | 886 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 861 | }, true); | 887 | $scope.$broadcast('cleanCabecera'); |
| 862 | 888 | ||
| 863 | function setearNotaPedido(notaPedido) { | 889 | var cabeceras = []; |
| 864 | //añado cabeceras | 890 | |
| 865 | $scope.notaPedido = notaPedido; | 891 | if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { |
| 866 | if (!$scope.notaPedido.domicilio) { | 892 | cabeceras.push({ |
| 867 | $scope.notaPedido.domicilio = { | 893 | label: 'Moneda:', |
| 868 | id: $scope.notaPedido.idDomicilio | 894 | valor: notaPedido.cotizacion.moneda.DETALLE |
| 869 | }; | 895 | }); |
| 870 | } | 896 | cabeceras.push({ |
| 871 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 897 | label: 'Fecha cotizacion:', |
| 872 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 898 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
| 873 | $scope.$broadcast('cleanCabecera'); | 899 | 'dd/MM/yyyy') |
| 874 | 900 | }); | |
| 875 | var cabeceras = []; | 901 | cabeceras.push({ |
| 876 | 902 | label: 'Cotizacion:', | |
| 877 | if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 903 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
| 878 | cabeceras.push({ | 904 | '2') |
| 879 | label: 'Moneda:', | 905 | }); |
| 880 | valor: notaPedido.cotizacion.moneda.DETALLE | 906 | } |
| 881 | }); | 907 | |
| 882 | cabeceras.push({ | 908 | if (notaPedido.cotizacion.moneda) { |
| 883 | label: 'Fecha cotizacion:', | 909 | $filter('filter')($scope.botonera, { label: 'Moneda'})[0].checked = true; |
| 884 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 910 | } |
| 885 | 'dd/MM/yyyy') | 911 | |
| 886 | }); | 912 | if (notaPedido.vendedor.NUM) { |
| 887 | cabeceras.push({ | 913 | cabeceras.push({ |
| 888 | label: 'Cotizacion:', | 914 | label: 'Vendedor:', |
| 889 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 915 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + |
| 890 | '2') | 916 | ' - ' + notaPedido.vendedor.NOM |
| 891 | }); | 917 | }); |
| 892 | } | 918 | } |
| 893 | 919 | ||
| 894 | if (notaPedido.cotizacion.moneda) { | 920 | if (notaPedido.cliente.COD) { |
| 895 | $filter('filter')($scope.botonera, { label: 'Moneda'})[0].checked = true; | 921 | cabeceras.push({ |
| 896 | } | 922 | label: 'Cliente:', |
| 897 | 923 | valor: notaPedido.cliente.NOM | |
| 898 | if (notaPedido.vendedor.NUM) { | 924 | }); |
| 899 | cabeceras.push({ | 925 | cabeceras.push({ |
| 900 | label: 'Vendedor:', | 926 | label: 'Domicilio:', |
| 901 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + | 927 | valor: notaPedido.domicilioStamp |
| 902 | ' - ' + notaPedido.vendedor.NOM | 928 | }); |
| 903 | }); | 929 | |
| 904 | } | 930 | $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = true; |
| 905 | 931 | } | |
| 906 | if (notaPedido.cliente.COD) { | 932 | |
| 907 | cabeceras.push({ | 933 | if (notaPedido.proveedor.COD) { |
| 908 | label: 'Cliente:', | 934 | cabeceras.push({ |
| 909 | valor: notaPedido.cliente.NOM | 935 | label: 'Proveedor:', |
| 910 | }); | 936 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + |
| 911 | cabeceras.push({ | 937 | ' - ' + notaPedido.proveedor.NOM |
| 912 | label: 'Domicilio:', | 938 | }); |
| 913 | valor: notaPedido.domicilioStamp | 939 | |
| 914 | }); | 940 | $filter('filter')($scope.botonera, { label: 'Proveedor'})[0].checked = true; |
| 915 | 941 | } | |
| 916 | $filter('filter')($scope.botonera, { label: 'Cliente'})[0].checked = true; | 942 | |
| 917 | } | 943 | if (notaPedido.notaPedidoPlazo.length) { |
| 918 | 944 | cabeceras.push({ | |
| 919 | if (notaPedido.proveedor.COD) { | 945 | label: 'Precios y condiciones:', |
| 920 | cabeceras.push({ | 946 | valor: valorPrecioCondicion() + ' ' + |
| 921 | label: 'Proveedor:', | 947 | notaPedidoBusinessService |
| 922 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + | 948 | .plazoToString(notaPedido.notaPedidoPlazo) |
| 923 | ' - ' + notaPedido.proveedor.NOM | 949 | }); |
| 924 | }); | 950 | |
| 925 | 951 | $filter('filter')($scope.botonera, | |
| 926 | $filter('filter')($scope.botonera, { label: 'Proveedor'})[0].checked = true; | 952 | { label: 'Precios y condiciones'})[0].checked = true; |
| 927 | } | 953 | } |
| 928 | 954 | ||
| 929 | if (notaPedido.notaPedidoPlazo.length) { | 955 | if (notaPedido.flete !== undefined) { |
| 930 | cabeceras.push({ | 956 | cabeceras.push({ |
| 931 | label: 'Precios y condiciones:', | 957 | label: 'Flete:', |
| 932 | valor: valorPrecioCondicion() + ' ' + | 958 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
| 933 | notaPedidoBusinessService | 959 | notaPedido.flete === 1 ? 'Si' : 'No') |
| 934 | .plazoToString(notaPedido.notaPedidoPlazo) | 960 | }); |
| 935 | }); | 961 | } |
| 936 | 962 | ||
| 937 | $filter('filter')($scope.botonera, | 963 | function valorPrecioCondicion() { |
| 938 | { label: 'Precios y Condiciones'})[0].checked = true; | 964 | if (notaPedido.idPrecioCondicion > 0) { |
| 939 | } | 965 | return notaPedido.precioCondicion.nombre; |
| 940 | 966 | } else { | |
| 941 | if (notaPedido.flete !== undefined) { | 967 | return 'Ingreso Manual'; |
| 942 | cabeceras.push({ | 968 | } |
| 943 | label: 'Flete:', | 969 | } |
| 944 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 970 | |
| 945 | notaPedido.flete === 1 ? 'Si' : 'No') | 971 | if (notaPedido.flete === 1) { |
| 946 | }); | 972 | var cabeceraBomba = { |
| 947 | } | 973 | label: 'Bomba:', |
| 948 | 974 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | |
| 949 | function valorPrecioCondicion() { | 975 | }; |
| 950 | if (notaPedido.idPrecioCondicion > 0) { | 976 | if (notaPedido.kilometros) { |
| 951 | return notaPedido.precioCondicion.nombre; | 977 | var cabeceraKilometros = { |
| 952 | } else { | 978 | label: 'Kilometros:', |
| 953 | return 'Ingreso Manual'; | 979 | valor: notaPedido.kilometros |
| 954 | } | 980 | }; |
| 955 | } | 981 | cabeceras.push(cabeceraKilometros); |
| 956 | 982 | } | |
| 957 | if (notaPedido.flete === 1) { | 983 | cabeceras.push(cabeceraBomba); |
| 958 | var cabeceraBomba = { | 984 | } |
| 959 | label: 'Bomba:', | 985 | |
| 960 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 986 | if (notaPedido.idPrecioCondicion > 0) { |
| 961 | }; | 987 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
| 962 | if (notaPedido.kilometros) { | 988 | } else if (notaPedido.idPrecioCondicion) { |
| 963 | var cabeceraKilometros = { | 989 | $scope.idLista = -1; |
| 964 | label: 'Kilometros:', | 990 | } |
| 965 | valor: notaPedido.kilometros | 991 | |
| 966 | }; | 992 | $scope.puntoVenta = $filter('rellenarDigitos')( |
| 967 | cabeceras.push(cabeceraKilometros); | 993 | notaPedido.sucursal, 4 |
| 968 | } | 994 | ); |
| 969 | cabeceras.push(cabeceraBomba); | 995 | |
| 970 | } | 996 | $scope.comprobante = $filter('rellenarDigitos')( |
| 971 | 997 | notaPedido.numeroNotaPedido, 8 | |
| 972 | if (notaPedido.idPrecioCondicion > 0) { | 998 | ); |
| 973 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 999 | |
| 974 | } else if (notaPedido.idPrecioCondicion) { | 1000 | if (notaPedido.notaPedidoPuntoDescarga.length) { |
| 975 | $scope.idLista = -1; | 1001 | var puntos = []; |
| 976 | } | 1002 | notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga) { |
| 977 | 1003 | puntos.push(notaPedidoPuntoDescarga.puntoDescarga); | |
| 978 | $scope.puntoVenta = $filter('rellenarDigitos')( | 1004 | }); |
| 979 | notaPedido.sucursal, 4 | 1005 | cabeceras.push({ |
| 980 | ); | 1006 | label: 'Puntos de descarga: ', |
| 981 | 1007 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) | |
| 982 | $scope.comprobante = $filter('rellenarDigitos')( | 1008 | }); |
| 983 | notaPedido.numeroNotaPedido, 8 | 1009 | } |
| 984 | ); | 1010 | |
| 985 | 1011 | if ($scope.notaPedido.articulosNotaPedido.length) { | |
| 986 | if (notaPedido.notaPedidoPuntoDescarga.length) { | 1012 | $scope.notaPedido.articulosNotaPedido.forEach(function (articulo) { |
| 987 | var puntos = []; | 1013 | articulo.precio = |
| 988 | notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga) { | 1014 | (articulo.precio / $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); |
| 989 | puntos.push(notaPedidoPuntoDescarga); | 1015 | }); |
| 990 | }); | 1016 | } |
| 991 | cabeceras.push({ | 1017 | |
| 992 | label: 'Puntos de descarga: ', | 1018 | addArrayCabecera(cabeceras); |
| 993 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) | 1019 | } |
| 994 | }); | 1020 | |
| 995 | } | 1021 | function getCabeceraPuntoDescarga(puntoDescarga) { |
| 996 | 1022 | var puntosStamp = ''; | |
| 997 | if ($scope.notaPedido.articulosNotaPedido.length) { | 1023 | puntoDescarga.forEach(function(punto, idx, arr) { |
| 998 | $scope.notaPedido.articulosNotaPedido.forEach(function (articulo) { | 1024 | puntosStamp += punto.descripcion; |
| 999 | articulo.precio = | 1025 | if ((idx + 1) !== arr.length) puntosStamp += ', '; |
| 1000 | (articulo.precio / $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); | 1026 | }); |
| 1001 | }); | 1027 | return puntosStamp; |
| 1002 | } | 1028 | } |
| 1003 | 1029 | ||
| 1004 | addArrayCabecera(cabeceras); | 1030 | function addArrayCabecera(array) { |
| 1005 | } | 1031 | for (var i = 0; i < array.length; i++) { |
| 1006 | 1032 | $scope.$broadcast('addCabecera', { | |
| 1007 | function getCabeceraPuntoDescarga(puntoDescarga) { | 1033 | label: array[i].label, |
| 1008 | var puntosStamp = ''; | 1034 | valor: array[i].valor |
| 1009 | puntoDescarga.forEach(function(punto, idx, arr) { | 1035 | }); |
| 1010 | puntosStamp += punto.descripcion; | 1036 | } |
| 1011 | if ((idx + 1) !== arr.length) puntosStamp += ', '; | 1037 | } |
| 1012 | }); | 1038 | |
| 1013 | return puntosStamp; | 1039 | function validarNotaRemitada() { |
| 1014 | } | 1040 | if (!$scope.notaPedido.idRemito) { |
| 1015 | 1041 | return true; | |
| 1016 | function addArrayCabecera(array) { | 1042 | } else { |
| 1017 | for (var i = 0; i < array.length; i++) { | 1043 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
| 1018 | $scope.$broadcast('addCabecera', { | 1044 | return false; |
| 1019 | label: array[i].label, | 1045 | } |
| 1020 | valor: array[i].valor | 1046 | } |
| 1021 | }); | 1047 | |
| 1022 | } | 1048 | function salir() { |
| 1023 | } | 1049 | var confirmacion = false; |
| 1024 | 1050 |