42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 21/02/2018
|
|
* Time: 10:34
|
|
*/
|
|
|
|
class Invoices_model extends MY_Model {
|
|
|
|
protected $tablename = 'invoices';
|
|
|
|
public function getInvoicedPerYearPerProject( $projectID )
|
|
{
|
|
$this->sql = "
|
|
SELECT ROUND(COALESCE(SUM(invoiceamount), 0),0) AS invoiced, YEAR(invoicedate) AS invoiceyear
|
|
FROM invoices
|
|
WHERE project_id = {$projectID}
|
|
GROUP BY YEAR(invoicedate)
|
|
ORDER BY YEAR(invoicedate) ";
|
|
|
|
$invoiced = $this->get_query_result();
|
|
|
|
return $invoiced;
|
|
}
|
|
|
|
public function getOutstandingPerProject( $projectID )
|
|
{
|
|
$this->sql = "
|
|
SELECT (own_revenue + other_revenue) - SUM(INV.invoiceamount) AS outstanding
|
|
FROM invoices INV
|
|
JOIN projects PRJ
|
|
ON PRJ.id = INV.project_id
|
|
JOIN offers OFF
|
|
ON PRJ.id = OFF.project_id
|
|
WHERE PRJ.id = {$projectID} ";
|
|
|
|
$invoiced = $this->get_query_row( 'outstanding' );
|
|
|
|
return $invoiced;
|
|
}
|
|
} |