Invoice report

This commit is contained in:
2018-03-07 17:03:45 +01:00
parent f540bab261
commit ad478b02b1
25 changed files with 1006 additions and 125 deletions
@@ -212,6 +212,42 @@ class ProjectsController extends MY_Controller {
$this->json( ['success' => TRUE, 'projecthourID' => $paymentID] );
}
public function saveForecast()
{
$forecastValidation = new ForecastValidation();
if ( ! $forecastValidation->getValidationResult() )
return $this->json( [
'success' => FALSE, 'messages' => $forecastValidation->getErrorMessages()] );
$forecast = $this->input->post();
$forecastID = $forecast['id'];
unset( $forecast['id'] );
$forecastID = Forecast::saveForecast( $forecastID, $forecast );
$this->json( ['success' => TRUE, 'forecastID' => $forecastID] );
}
public function saveReservation()
{
$reservationValidation = new ReservationValidation();
if ( ! $reservationValidation->getValidationResult() )
return $this->json( [
'success' => FALSE, 'messages' => $reservationValidation->getErrorMessages()] );
$reservation = $this->input->post();
$reservationID = $reservation['id'];
unset( $reservation['id'] );
$reservationID = Reservation::saveReservation( $reservationID, $reservation );
$this->json( ['success' => TRUE, 'reservationID' => $reservationID] );
}
public function archiveProject( $projectID, $status )
{
Project::whereId( $projectID )->update( ['archive' => $status] );
@@ -261,4 +297,26 @@ class ProjectsController extends MY_Controller {
$this->json( ['result' => TRUE] );
}
public function removeForecast( $forecastID )
{
$removeForecast = new RemoveForecast( $forecastID );
if ( $removeForecast->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
Forecast::removeForecast( $forecastID );
$this->json( ['result' => TRUE] );
}
public function removeReservation( $reservationID )
{
$removeReservation = new RemoveReservation( $reservationID );
if ( $removeReservation->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
Forecast::removeReservation( $reservationID );
$this->json( ['result' => TRUE] );
}
}
@@ -62,6 +62,17 @@ class EmployeeHoursController extends MY_Controller {
$result = $query->result();
foreach ( $result as $project )
{
$sql = QinvoiceMonthOverview::fire( $project->id, $year );
$query = $this->db->query( $sql );
$months = $query->result();
$project->months = $months;
}
$this->json( $result );
}
@@ -0,0 +1,36 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 17:45
*/
class RemoveForecast {
private $forecastID;
private $allowDelete = TRUE;
public function __construct( $forecastID )
{
$this->setForecastID( $forecastID );
$this->handle();
}
public function getAllowDelete()
{
return $this->allowDelete;
}
private function setForecastID( $forecastID )
{
$this->forecastID = $forecastID;
}
private function handle()
{
}
}
@@ -0,0 +1,36 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 17:45
*/
class RemoveReservation {
private $reservationID;
private $allowDelete = TRUE;
public function __construct( $reservationID )
{
$this->setReservationID( $reservationID );
$this->handle();
}
public function getAllowDelete()
{
return $this->allowDelete;
}
private function setReservationID( $reservationID )
{
$this->reservationID = $reservationID;
}
private function handle()
{
}
}
@@ -0,0 +1,40 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/07/16
* Time: 13:35
*/
require_once( APPPATH . 'libraries/validation/inputValidations/BaseValidation.php' );
class ForecastValidation extends BaseValidation {
protected $validationFields = [
'project_id' => [
'validations' => 'required|integer',
'fieldname' => 'project'
],
'year' => [
'validations' => 'integer',
'fieldname' => 'jaar'
],
'month_id' => [
'validations' => 'integer',
'fieldname' => 'maand'
],
'forecastamount' => [
'validations' => 'number',
'fieldname' => 'bedrag'
]
];
public function __construct()
{
parent::__construct();
$this->ci =& get_instance();
}
}
@@ -0,0 +1,32 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/07/16
* Time: 13:35
*/
require_once( APPPATH . 'libraries/validation/inputValidations/BaseValidation.php' );
class ReservationValidation extends BaseValidation {
protected $validationFields = [
'project_id' => [
'validations' => 'required|integer',
'fieldname' => 'project'
],
'reservationamount' => [
'validations' => 'number',
'fieldname' => 'bedrag'
]
];
public function __construct()
{
parent::__construct();
$this->ci =& get_instance();
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 07/03/2018
* Time: 09:24
*/
class Forecast extends BaseModel {
public function project()
{
return $this->belongsTo( 'Project' );
}
public static function saveForecast( $forecastID, $forecast )
{
$forecast = (array) $forecast;
if ( $forecastID == 0 )
{
$forecast = self::create( $forecast );
$forecastID = $forecast['id'];
}
else
{
self::whereId( $forecastID )->update( $forecast );
}
return $forecastID;
}
public static function removeForecast( $forecastID )
{
Forecast::whereId( $forecastID )->delete();
}
}
+12
View File
@@ -31,6 +31,16 @@ class Project extends BaseModel {
return $this->hasMany( 'Invoice' );
}
public function forecasts()
{
return $this->hasMany( 'Forecast' );
}
public function reservations()
{
return $this->hasMany( 'Reservation' );
}
public function projectleader()
{
return $this->belongsTo( 'User', 'projectleader_id' );
@@ -96,6 +106,8 @@ class Project extends BaseModel {
'projectemployees.user' => function ( $q ) {
$q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" );
}] )
->with(['forecasts'])
->with(['reservations'])
->with( 'projectemployees.projecthours' )
->with( 'projectcosts.external' )
->with( 'invoices.payments' )
@@ -0,0 +1,38 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 07/03/2018
* Time: 09:24
*/
class Reservation extends BaseModel {
public function project()
{
return $this->belongsTo( 'Project' );
}
public static function saveReservation( $reservationID, $reservation )
{
$reservation = (array) $reservation;
if ( $reservationID == 0 )
{
$reservation = self::create( $reservation );
$reservationID = $reservation['id'];
}
else
{
self::whereId( $reservationID )->update( $reservation );
}
return $reservationID;
}
public static function removeReservation( $reservationID )
{
Reservation::whereId( $reservationID )->delete();
}
}
@@ -0,0 +1,43 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 07/03/2018
* Time: 15:31
*/
class QinvoiceMonthOverview {
public static function fire( $projectID, $year )
{
$sql = "SELECT MNT.id,
month,
COALESCE(forecastamount, 0) AS forecastamount,
COALESCE(paymentamount, 0) AS paymentamount
FROM months MNT
LEFT JOIN (
SELECT SUM(forecastamount) AS forecastamount, month_id
FROM forecasts
WHERE project_id = {$projectID}
AND `year` = {$year}
GROUP BY month_id
) AS FCT
ON MNT.id = FCT.month_id + 1
LEFT JOIN (
SELECT SUM(paymentamount) AS paymentamount, MONTH(paymentdate) AS month_id
FROM payments PAY
JOIN invoices INV
ON INV.id = PAY.invoice_id
WHERE INV.project_id = {$projectID}
AND YEAR(paymentdate) = {$year}
GROUP BY month_id
) AS PAY
ON MNT.id = PAY.month_id
JOIN projects PRJ
GROUP BY MNT.id
ORDER BY MNT.id ";
return $sql;
}
}
@@ -16,11 +16,16 @@ class Qinvoiceoverview {
PRJ.projectname,
(own_revenue + other_revenue ) AS revenues,
CUS.name AS customername,
IF( YEAR(invoicedate) = {$year},SUM(invoiceamount), 0) AS currentyear,
IF( YEAR(invoicedate) != {$year},SUM(invoiceamount), 0) AS otheryear,
COALESCE(Q1.currentyearpayed, 0) AS currentyearpayed,
COALESCE(Q1.otheryearpayed, 0) AS otheryearpayed,
CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname
SUM(IF( YEAR(invoicedate) = {$year},invoiceamount, 0)) AS currentyear,
SUM(IF( YEAR(invoicedate) != {$year},invoiceamount, 0)) AS otheryear,
SUM(COALESCE(Q1.currentyearpayed, 0)) AS currentyearpayed,
SUM(COALESCE(Q1.otheryearpayed, 0)) AS otheryearpayed,
CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname,
( SELECT vatrate FROM vats WHERE archive = 'F' LIMIT 1 ) AS vatrate,
COALESCE(reserved, 0 ) AS reserved,
COALESCE(reservedpayed, 0 ) AS reservedpayed,
COALESCE(currentforecast, 0) AS currentforecast,
COALESCE(otherforecast, 0) AS otherforecast
FROM invoices INV
RIGHT JOIN projects PRJ
ON PRJ.id = INV.project_id
@@ -38,6 +43,22 @@ class Qinvoiceoverview {
GROUP BY invoice_id
) AS Q1
ON INV.id = Q1.invoice_id
LEFT JOIN (
SELECT project_id,
SUM(IF(payed='UNPAYED', reservationamount, 0)) reserved,
SUM(IF(payed='PAYED', reservationamount, 0)) reservedpayed
FROM reservations
GROUP BY project_id
) AS Q2
ON PRJ.id = Q2.project_id
LEFT JOIN (
SELECT project_id,
SUM(IF(year = {$year}, IF(month_id >= MONTH(NOW()) -1, forecastamount, 0), 0)) AS currentforecast,
SUM(IF(year > {$year}, forecastamount, 0)) AS otherforecast
FROM forecasts
GROUP BY project_id
) AS Q3
ON PRJ.id = Q3.project_id
GROUP BY PRJ.projectnumber, PRJ.projectname ";
return $sql;
@@ -0,0 +1,78 @@
<div class="panel panel-bordered panel-primary panel-line">
<div class="panel-heading panel-heading-project">
<h3 class="">
prognoses
</h3>
</div>
<div class="panel-body panel-body-project">
<table class="table table-sm">
<thead>
<th class="table-cyanish-header" width="25%">
jaar
</th>
<th class="table-cyanish-header" width="25%">
maand
</th>
<th class="table-cyanish-header align-right" width="35%">
bedrag
</th>
<th class="table-cyanish-header" width="15%">&nbsp;</th>
</thead>
<tbody data-bind="foreach:forecasts">
<tr>
<td>
<span data-bind="text:dbo.helpers.findArrayElement('year', 'year', year(), $root.years()),
visible:! inEdit()"></span>
<select class="form-control form-control-sm"
data-bind="options:$root.years,
optionsText:'year',
optionsValue:'year',
value:year,
optionsCaption:'voer jaar in',
visible: inEdit(),
event:{change:$root.saveForecast}">
</select>
</td>
<td>
<span data-bind="text:dbo.helpers.findArrayElement('monthID', 'month', month_id(), $root.months()),
visible:! inEdit()"></span>
<select class="form-control form-control-sm"
data-bind="options:$root.months,
optionsText:'month',
optionsValue:'monthID',
value:month_id,
optionsCaption:'voer maand in',
visible: inEdit(),
event:{change:$root.saveForecast}">
</select>
</td>
<td class="align-right">
<span data-bind="visible:!inEdit()">
<i class="icon fa-euro"></i>
<span data-bind="text:dbo.helpers.numberWithPoints(forecastamount())"></span>
</span>
<input type="text"
class="form-control form-control-sm align-right"
paceholder="bedrag"
data-bind="textInput:forecastamount, visible:inEdit,
event:{change:$root.saveForecast,keyup:$root.validateNumber.bind($data, 'forecastamount')}"/>
</td>
<td>
<i class="icon fa-edit pointer" title="wijzig" data-bind="click:$root.editForecast"></i>
<i class="icon fa-trash redish pointer" title="verwijder"
data-bind="click:$root.removeForecast"></i>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="4">
<button class="btn btn-primary btn-round btn-sm" data-bind="click:addForecast">
nieuwe prognose
</button>
</th>
</tr>
</tfoot>
</table>
</div>
</div>
@@ -126,7 +126,6 @@
</th>
<th class="table-cyanish-header-light">
</th>
<th width="50%">&nbsp;</th>
</thead>
<tbody data-bind="foreach:payments">
<tr>
@@ -0,0 +1,55 @@
<div class="panel panel-bordered panel-primary panel-line">
<div class="panel-heading panel-heading-project">
<h3 class="">
Reserveringen
</h3>
</div>
<div class="panel-body panel-body-project">
<table class="table table-sm">
<thead>
<th class="table-cyanish-header" width="40%">
bedrag
</th>
<th class="table-cyanish-header" width="40%">
betaald
</th>
<th class="table-cyanish-header" width="20%">&nbsp;</th>
</thead>
<tbody data-bind="foreach:reservations">
<tr>
<td class="align-right">
<span data-bind="visible:!inEdit()">
<i class="icon fa-euro"></i>
<span data-bind="text:dbo.helpers.numberWithPoints(reservationamount())"></span>
</span>
<input type="text"
class="form-control form-control-sm align-right"
paceholder="bedrag"
data-bind="textInput:reservationamount, visible:inEdit,
event:{change:$root.saveReservation,keyup:$root.validateNumber.bind($data, 'reservationamount')}"/>
</td>
<td>
<i class="icon fa-square-o pointer" title="niet betaald"
data-bind="click:$root.setPayment.bind($data, 'PAYED'), visible:payed()=='UNPAYED'"></i>
<i class="icon fa-check pointer" title="betaald"
data-bind="click:$root.setPayment.bind($data, 'UNPAYED'), visible: payed()=='PAYED'"></i>
</td>
<td>
<i class="icon fa-edit pointer" title="wijzig" data-bind="click:$root.editReservation"></i>
<i class="icon fa-trash redish pointer" title="verwijder"
data-bind="click:$root.removeReservation"></i>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="4">
<button class="btn btn-primary btn-round btn-sm" data-bind="click:addReservation">
nieuwe reservering
</button>
</th>
</tr>
</tfoot>
</table>
</div>
</div>
+7 -1
View File
@@ -58,11 +58,17 @@
<div class="col-md-7">
<?php $this->load->view( 'modals/partials/_projectcosts' ); ?>
</div>
<div class="col-md-5">
<?php $this->load->view('modals/partials/_forecasts'); ?>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="col-md-9">
<?php $this->load->view( 'modals/partials/_invoices' ); ?>
</div>
<div class="col-md-3">
<?php $this->load->view( 'modals/partials/_reservations' ); ?>
</div>
</div>
</div>
<div class="tab-pane animation-slide-top" id="employees">
@@ -14,91 +14,28 @@
</div>
<div class="row">
<div class="col-md-12">
<table class="table table-condensed" style="font-size:0.8em;">
<thead>
<tr>
<th class="rotate">
<div><span>project</span></div>
</th>
<th class="rotate">
<div><span>klant</span></div>
</th>
<th class="rotate">
<div><span>status afgehandeld</span></div>
</th>
<th class="rotate">
<div><span>projectleider</span></div>
</th>
<th class="rotate">
<div><span>te factureren(excl btw)</span></div>
</th>
<th class="rotate">
<div><span>te factureren(incl btw)</span></div>
</th>
<th class="rotate">
<div><span>gefactureerd voorgaande jaren(incl btw)</span></div>
</th>
<th class="rotate">
<div><span>gefactureerd lopend jaar(incl btw)</span></div>
</th>
<th class="rotate">
<div><span>totaal gefactureerd(incl btw)</span></div>
</th>
<th class="rotate">
<div><span>betaald voorgaande jaren</span></div>
</th>
<th class="rotate">
<div><span>betaald lopend jaar</span></div>
</th>
<th class="rotate">
<div><span>totaal betaald</span></div>
</th>
</tr>
</thead>
<tbody>
<!-- ko foreach: projects -->
<tr>
<td><span data-bind="text:projectnumber"></span></td>
<td><span data-bind="text:customername"></span></td>
<td><span data-bind="text:statusProject == 'CLOSED' ? 'afgesloten' : 'open'"></span></td>
<td><span data-bind="text:fullname"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:openstaand"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:openstaandIncl"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:invoicedOtherYears"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:invoicedCurentYear"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:totalInvoiced"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:invoicedOtherYearsPayed"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:invoicedCurentYearPayed"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:totalInvoicedPayed"></span>
</td>
</tr>
<!-- /ko -->
</tbody>
</table>
<div class="nav-tabs-horizontal">
<ul class="nav nav-tabs nav-tabs-solid">
<li class="nav-item" data-bind="click:setActivetab.bind($data, 'invoice')" style="z-index:10">
<a class="nav-link" data-bind="css:{'active':invoiceTab() == 'invoice'}">facturen</a>
</li>
<li class="nav-item" data-bind="click:setActivetab.bind($data, 'forecast')" style="z-index:10">
<a class="nav-link" data-bind="css:{'active':invoiceTab() == 'forecast'}">prognoses</a>
</li>
<li class="nav-item" data-bind="click:setActivetab.bind($data, 'monthforecast')" style="z-index:10">
<a class="nav-link" data-bind="css:{'active':invoiceTab() == 'monthforecast'}">maand prognoses</a>
</li>
<li class="nav-item" data-bind="click:setActivetab.bind($data, 'monthpayments')" style="z-index:10">
<a class="nav-link" data-bind="css:{'active':invoiceTab() == 'monthpayments'}">maand betalingen</a>
</li>
<li class="nav-item" data-bind="click:setActivetab.bind($data, 'externals')" style="z-index:10">
<a class="nav-link" data-bind="css:{'active':invoiceTab() == 'externals'}">onderaannemers</a>
</li>
</ul>
<div class="tab-content">
<?php $this->load->view('reports/invoices/_invoicetable'); ?>
</div>
</div>
</div>
</div>
</div>
@@ -0,0 +1,172 @@
<table class="table table-condensed" style="font-size:0.8em;">
<thead>
<tr>
<th class="rotate">
<div><span>project</span></div>
</th>
<th class="rotate">
<div><span>klant</span></div>
</th>
<th class="rotate">
<div><span>status afgehandeld</span></div>
</th>
<th class="rotate">
<div><span>projectleider</span></div>
</th>
<!-- ko if:$root.invoiceTab() == 'invoice' -->
<th class="rotate">
<div><span>te factureren(excl btw)</span></div>
</th>
<th class="rotate">
<div><span>te factureren(incl btw)</span></div>
</th>
<th class="rotate">
<div><span>gefactureerd voorgaande jaren(incl btw)</span></div>
</th>
<th class="rotate">
<div><span>gefactureerd lopend jaar(incl btw)</span></div>
</th>
<th class="rotate">
<div><span>totaal gefactureerd(incl btw)</span></div>
</th>
<th class="rotate">
<div><span>betaald voorgaande jaren</span></div>
</th>
<th class="rotate">
<div><span>betaald lopend jaar</span></div>
</th>
<th class="rotate">
<div><span>totaal betaald</span></div>
</th>
<th class="rotate">
<div><span>nog niet betaald</span></div>
</th>
<!-- /ko -->
<!-- ko if:$root.invoiceTab() == 'forecast' -->
<th class="rotate">
<div><span>nog te factureren</span></div>
</th>
<th class="rotate">
<div><span>nog te factureren lopend jaar</span></div>
</th>
<th class="rotate">
<div><span>nog te factureren na lopend jaar</span></div>
</th>
<th class="rotate">
<div><span>verschil prognose - werkelijk</span></div>
</th>
<!-- /ko -->
<!-- ko if:$root.invoiceTab() == 'monthforecast' || $root.invoiceTab() == 'monthpayments' -->
<!-- ko foreach:months -->
<th><span data-bind="text:month"></span></th>
<!-- /ko -->
<!-- /ko -->
</tr>
</thead>
<tbody>
<!-- ko foreach: projects -->
<tr>
<td><span data-bind="text:projectnumber"></span></td>
<td><span data-bind="text:customername"></span></td>
<td><span data-bind="text:statusProject == 'CLOSED' ? 'afgesloten' : 'open'"></span></td>
<td><span data-bind="text:fullname"></span>
</td>
<!-- ko if:$root.invoiceTab() == 'invoice' -->
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:revenues"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:totalInvoice"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:invoicedOtherYears"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:invoicedCurentYear"></span>
</td>
<th class="align-right focus-green">
<i class="icon fa-euro"></i>
<span data-bind="text:totalInvoiced"></span>
</th>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:invoicedOtherYearsPayed"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:invoicedCurentYearPayed"></span>
</td>
<th class="align-right focus-green">
<i class="icon fa-euro"></i>
<span data-bind="text:totalInvoicedPayed"></span>
</th>
<th class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:notPayed"></span>
</th>
<!-- /ko -->
<!-- ko if:$root.invoiceTab() == 'forecast' -->
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:toInvoice"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:currentforecast"></span>
</td>
<td class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:otherforecast"></span>
</td>
<th class="align-right">
<i class="icon fa-euro"></i>
<span data-bind="text:missingForecast"></span>
</th>
<!-- /ko -->
<!-- ko if:$root.invoiceTab() == 'monthforecast' -->
<!-- ko foreach:months -->
<td class="align-right">
<span data-bind="text:forecastamount">
</span>
</td>
<!-- /ko -->
<!-- /ko -->
<!-- ko if:$root.invoiceTab() == 'monthpayments' -->
<!-- ko foreach:months -->
<td class="align-right">
<span data-bind="text:paymentamount">
</span>
</td>
<!-- /ko -->
<!-- /ko -->
</tr>
<!-- /ko -->
</tbody>
<tfoot>
<tr>
<th colspan="4" class="align-right">
totaal
</th>
<!-- ko if:$root.invoiceTab() == 'monthforecast' -->
<!-- ko foreach:months -->
<th class="align-right">
<span data-bind="text:dbo.helpers.numberWithPoints($root['forecast' + month]())">
</span>
</th>
<!-- /ko -->
<!-- /ko -->
<!-- ko if:$root.invoiceTab() == 'monthpayments' -->
<!-- ko foreach:months -->
<th class="align-right">
<span data-bind="text:dbo.helpers.numberWithPoints($root['payment' + month]())">
</span>
</th>
<!-- /ko -->
<!-- /ko -->
</tr>
</tfoot>
</table>