Obtaining physical information from the integral spectra of unresolved stellar populations is the key to investigating a galaxy's evolution, during which modelling the levels of heavy elements within the galaxy over time is fundamental but often missed. While most studies of chemical evolution tend to focus on gas and stellar metallicities separately, these quantities can – and should – be treated on equal footing, since the stars whose metallicities we measure form from the same gas we are also interested in studying. In this talk, a novel semi-analytic spectral fitting approach is introduced to better infer the physical properties of galaxies from their spectra. We construct simple yet general chemical evolution models that account for gas inflow and outflow processes as well as star formation, which are fitted directly to galaxies’ absorption-line spectra, while their emission lines are used to constrain current gas-phase metallicity and star formation rate. By applying this method to samples from the SDSS-IV/MaNGA survey, we discuss how this approach can be used to investigate the mass accumulation and chemical enrichment of galaxies in both gas and stellar phases. In addition, we will see what we can learn about the evolution of galaxies from the derived gas inflow, outflow and radial flow histories, especially how the feedback from AGN and the environment has played a role.