Spreadsheet

This commit is contained in:
2018-07-29 21:26:49 +02:00
parent 30535f7048
commit b86c3fc4b9
26 changed files with 1286 additions and 432 deletions
+22
View File
@@ -24,6 +24,28 @@ class Invoice extends BaseModel {
return $this->belongsTo( 'Vat' );
}
public static function invoicePerYear( $projectID, $year, $thatYear = TRUE )
{
$invoices = Invoice::selectRAW( 'SUM(invoiceamount * ( 1 +(vatrate / 100))) AS invoicetotal' )
->join( 'vats', 'vats.id', '=', 'invoices.vat_id' )
->whereProjectId( $projectID );
if ( $thatYear )
{
$invoices = $invoices->whereRaw( "YEAR(invoicedate) = {$year}" );
}
else
{
$invoices = $invoices->whereRaw( "YEAR(invoicedate) != {$year}" );
}
if ( $invoices->count() == 0 ) return 0;
$invoices = $invoices->first();
return $invoices->invoicetotal;
}
public static function saveInvoice( $invoiceID, $invoice )
{
$invoice = (array) $invoice;