We consider a Markov-modulated .uid .ow production model under D-policy, that is, as soon as the stock reaches level 0, the machine becomes idle, until the total stock exceeds a predetermined threshold D. Thus, the production process alternates between a busy and an idle machine. During the busy period the stock decreases linearly due to continuous production and increases due to supply; during the idle period no production is rendered by the machine and the stock level increases only by supply arrivals. We consider two types of models with different supply process patterns: continuous inflows with linear rates (fluid type), and batch inflows, where the supplies arrive according to a Markov additive process and their sizes are dependent and have phase-type distributions depending on the type of arrival (MAP-type). Four types of costs are considered: a setup cost, a production cost, a penalty cost for an idle machine, and a cost for the stock. Based on tools from multi-dimensional martingales and hitting times theory, we derive explicit formulas for these cost functionals in the discounted case. Numerical examples, a sensitivity analysis, and insights are provided.