Example #1
0
 /**
  * get the incoming summary for the selected year
  *
  * @param integer $year
  */
 public static function getSummary($year, $payments = TRUE)
 {
     if (!is_numeric($year)) {
         return array();
     }
     $records = Doctrine_Query::create()->select("o.order_id,\n\n\t\t\t\tMONTH(i.invoice_date) as month,\n\n\t\t\t\tdate_format(i.invoice_date,'%M') as monthname,\n\n\t\t\t\tYEAR(i.invoice_date) as yearnum,\n\n\t\t\t\tSUM(o.total) as total,\n\n\t\t\t\tSUM(o.vat) as vat,\n\n\t\t\t\tSUM(o.grandtotal) as grandtotal")->from('Orders o')->leftJoin('o.Invoices i')->where('YEAR(i.invoice_date) = ?', $year)->andWhere('o.invoice_id <> ?', '')->andWhere('o.status_id = ?', Statuses::id("complete", "orders"))->groupBy('YEAR(i.invoice_date)')->addGroupBy('MONTH(i.invoice_date)')->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
     if ($payments) {
         for ($i = 0; $i < count($records); $i++) {
             $records[$i]['subrecords'] = Payments::getAllPaymentsbyMonthYear($records[$i]['month'], $year);
         }
     }
     return $records;
 }