<?php defined('SYSPATH') or die('No direct access allowed.');

/**
 * Mark all invoices that have been paid as complete, so that they are not processed again.
 *
 * @package    Invoice
 * @category   Tasks
 * @author     Deon George
 * @copyright  (c) 2009-2013 Open Source Billing
 * @license    http://dev.osbill.net/license.html
 */
class Task_Invoice_Complete extends Minion_Task {
	protected function _execute(array $params) {
		$c = array();

		$o = ORM::factory('Invoice')
			->where_unprocessed();

		foreach ($o->find_all() as $io) {
			if ($io->due() == 0)
				$io->process_status = 1;

			$io->save();

			if ($io->saved())
				array_push($c,$io->id);
		}

		return sprintf('%s invoices updated (%s)',count($c),join('|',$c));
	}
}
?>