Skip to content

Instantly share code, notes, and snippets.

@MisterPhoton
Created July 7, 2010 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MisterPhoton/467033 to your computer and use it in GitHub Desktop.
Save MisterPhoton/467033 to your computer and use it in GitHub Desktop.
/**
* Returns all payments or invoices made within a certain date range.
*
* @param Zend_Date $start
* @param Zend_Date $end
* @return System_Db_DataObject_Collection
*/
public static function getPaymentsByDateRange(Zend_Date $start, Zend_Date $end) {
require_once 'System/Db/DataObject/Collection.php';
$collection = new System_Db_DataObject_Collection(self::getDao(), 'Guide_Invoice_Payment');
$startDate = $start->get('yyyy-MM-dd 00:00:00');
$endDate = $end->get('yyyy-MM-dd 23:59:59');
// Payments will have dateCreated set, but not date. Invoices will have a dateCreated date of the time the proposal was
// created and a date value of the time the proposal was converted to an invoice, which is what we want in this case.
$collection->getSelect()->where('void = 0')
->where('proposal = 0')
->where(sprintf("dateCreated >= '%s' AND dateCreated <= '%s'", $startDate, $endDate))
->orWhere(sprintf("date >= '%s' AND date <= '%s'", $startDate, $endDate));
return $collection;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment