Conversie codeigniter 4

This commit is contained in:
2026-01-09 11:41:28 +01:00
parent dbd8c8aed2
commit f0b9c6ad40
242 changed files with 20034 additions and 346 deletions
@@ -0,0 +1,75 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 30/07/2018
* Time: 10:48
*/
class InvoiceForecastSheet {
const HEADERS = [
'A' => 'project',
'B' => 'klant',
'C' => 'Nog te factureren incl. btw',
'D' => 'Nog te factureren incl. btw lopend boekjaar incl. btw',
'E' => 'Nog te factureren na lopend boekjaar inc. btw',
'F' => 'Nog te prognotiseren inc. btw'
];
private $invoiceForecast;
private $sheet;
private $row;
public function __construct( $invoiceForecast, $sheet )
{
$this->invoiceForecast = $invoiceForecast;
$this->sheet = $sheet;
$this->handle();
}
private function handle()
{
$this->setHeader();
$this->setBody();
$this->setTotals();
}
private function setHeader()
{
foreach ( self::HEADERS as $cell => $header )
{
$this->sheet->setCellValue( $cell . '1', $header );
$this->sheet->getColumnDimension( $cell )->setAutoSize( TRUE );
}
}
private function setBody()
{
$this->row = 2;
foreach ( $this->invoiceForecast AS $project )
{
$this->sheet->setCellValue( 'A' . $this->row, $project['projectname'] );
$this->sheet->setCellValue( 'B' . $this->row, $project['customer'] );
$this->sheet->setCellValue( 'C' . $this->row, str_replace( '.', '', $project['needInvoice'] ?? '' ) );
$this->sheet->setCellValue( 'D' . $this->row, str_replace( '.', '', $project['forecastThisYear'] ?? '' ) );
$this->sheet->setCellValue( 'E' . $this->row, str_replace( '.', '', $project['forecastOtherYears'] ?? '' ) );
$this->sheet->setCellValue( 'F' . $this->row, str_replace( '.', '', $project['forecastRemaining'] ?? '' ) );
$this->row ++;
}
}
private function setTotals()
{
$lastRow = $this->row - 1;
$this->sheet->setCellValue( 'C' . $this->row, '=SUM(C2:C' . $lastRow . ')' );
$this->sheet->setCellValue( 'D' . $this->row, '=SUM(D2:D' . $lastRow . ')' );
$this->sheet->setCellValue( 'E' . $this->row, '=SUM(E2:E' . $lastRow . ')' );
$this->sheet->setCellValue( 'F' . $this->row, '=SUM(F2:F' . $lastRow . ')' );
}
}
@@ -0,0 +1,80 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 29/07/2018
* Time: 20:40
*/
class InvoiceOverviewSheet {
const HEADERS = [
'A' => 'project',
'B' => 'klant',
'C' => 'Totaal te factureren excl. btw',
'D' => 'Totaal te factureren incl. btw',
'E' => 'Gefactureerd overige jaren incl. btw',
'F' => 'Gefactureerd lopende boekjaar incl. btw',
'G' => 'Gefactureerd totaal incl. btw',
'H' => 'Nog te factureren incl. btw'
];
private $invoiceOverview;
private $sheet;
private $row;
public function __construct( $invoiceOverview, $sheet )
{
$this->invoiceOverview = $invoiceOverview;
$this->sheet = $sheet;
$this->handle();
}
private function handle()
{
$this->setHeader();
$this->setBody();
$this->setTotals();
}
private function setHeader()
{
foreach ( self::HEADERS as $cell => $header )
{
$this->sheet->setCellValue( $cell . '1', $header );
$this->sheet->getColumnDimension( $cell )->setAutoSize( TRUE );
}
}
private function setBody()
{
$this->row = 2;
foreach ( $this->invoiceOverview AS $project )
{
$this->sheet->setCellValue( 'A' . $this->row, $project['projectname'] );
$this->sheet->setCellValue( 'B' . $this->row, $project['customer'] );
$this->sheet->setCellValue( 'C' . $this->row, str_replace( '.', '', $project['totalToInvoicingExcl'] ?? '' ) );
$this->sheet->setCellValue( 'D' . $this->row, str_replace( '.', '', $project['totalToInvoicingIncl'] ?? '' ) );
$this->sheet->setCellValue( 'E' . $this->row, str_replace( '.', '', $project['totalInvoicedOtherYears'] ?? '' ) );
$this->sheet->setCellValue( 'F' . $this->row, str_replace( '.', '', $project['totalInvoicedThisYear'] ?? '' ) );
$this->sheet->setCellValue( 'G' . $this->row, str_replace( '.', '', $project['invoicesTotal'] ?? '' ) );
$this->sheet->setCellValue( 'H' . $this->row, str_replace( '.', '', $project['needInvoice'] ?? '' ) );
$this->row ++;
}
}
private function setTotals()
{
$lastRow = $this->row - 1;
$this->sheet->setCellValue( 'C' . $this->row, '=SUM(C2:C' . $lastRow . ')' );
$this->sheet->setCellValue( 'D' . $this->row, '=SUM(D2:D' . $lastRow . ')' );
$this->sheet->setCellValue( 'E' . $this->row, '=SUM(E2:E' . $lastRow . ')' );
$this->sheet->setCellValue( 'F' . $this->row, '=SUM(F2:F' . $lastRow . ')' );
$this->sheet->setCellValue( 'G' . $this->row, '=SUM(G2:G' . $lastRow . ')' );
$this->sheet->setCellValue( 'H' . $this->row, '=SUM(H2:H' . $lastRow . ')' );
}
}
@@ -0,0 +1,136 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 29/07/2018
* Time: 20:04
*/
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class InvoiceSpreadsheet {
private $invoiceReport;
private $spreadsheet;
private $invoiceSheet;
private $fullpathname;
private $filename;
private $ci;
public function __construct( $invoiceReport )
{
$this->ci =& get_instance();
$this->invoiceReport = $invoiceReport;
$this->ci->load->helper( 'download' );
$this->handle();
}
private function handle()
{
$this->setSpreadsheet();
$this->setInvoiceOverviewSheet();
$this->setInvoiceForecast();
$this->setMonthForecast();
$this->setMonthPayment();
$this->setInvoiced();
$this->setFilename();
$this->setFullPathname();
$this->createFile();
$this->downloadSpreadsheet();
}
private function setSpreadsheet()
{
$this->spreadsheet = new Spreadsheet();
}
private function setInvoiceOverviewSheet()
{
$invoiceSheet = new Worksheet( $this->spreadsheet, 'Facturen' );
$this->invoiceSheet =
$this->spreadsheet->addSheet( $invoiceSheet );
new InvoiceOverviewSheet( $this->invoiceReport['invoiceOverview'], $this->invoiceSheet );
}
private function setInvoiceForecast()
{
$invoiceSheet = new Worksheet( $this->spreadsheet, 'prognose' );
$this->invoiceSheet =
$this->spreadsheet->addSheet( $invoiceSheet );
new InvoiceForecastSheet( $this->invoiceReport['forecasts'], $this->invoiceSheet );
}
private function setMonthForecast()
{
$invoiceSheet = new Worksheet( $this->spreadsheet, 'maandprognose' );
$this->invoiceSheet =
$this->spreadsheet->addSheet( $invoiceSheet );
new MonthForecastSheet( $this->invoiceReport['monthForecasts'], $this->invoiceSheet );
}
private function setMonthPayment()
{
$invoiceSheet = new Worksheet( $this->spreadsheet, 'maand betalingen' );
$this->invoiceSheet =
$this->spreadsheet->addSheet( $invoiceSheet );
new MonthPaymentSheet( $this->invoiceReport['monthPayments'], $this->invoiceSheet );
}
private function setInvoiced()
{
$invoiceSheet = new Worksheet( $this->spreadsheet, 'verstuurde facturen' );
$this->invoiceSheet =
$this->spreadsheet->addSheet( $invoiceSheet );
new InvoicedSheet( $this->invoiceReport['invoiced'], $this->invoiceSheet );
}
private function setFilename()
{
$this->filename = 'facturen' . date( 'YmdHis' ) . '.xlsx';
}
private function setFullPathname()
{
$this->fullpathname = MYROOTPATH . 'documents/spreadsheets/' . $this->filename;
}
private function createFile()
{
$writer = new Xlsx( $this->spreadsheet );
$writer->save( $this->fullpathname );
}
private function downloadSpreadsheet()
{
$data = file_get_contents( $this->fullpathname );
force_download( $this->filename, $data );
}
}
@@ -0,0 +1,67 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 30/07/2018
* Time: 10:48
*/
class InvoicedSheet {
const HEADERS = [
'A' => 'factuurnummer',
'B' => 'project',
'C' => 'klant',
'D' => 'factuurdatum',
'E' => 'exc btw',
'F' => 'btw',
'G' => 'incl btw'
];
private $invoiced;
private $sheet;
private $row;
public function __construct( $invoiced, $sheet )
{
$this->invoiced = $invoiced;
$this->sheet = $sheet;
$this->handle();
}
private function handle()
{
$this->setHeader();
$this->setBody();
}
private function setHeader()
{
foreach ( self::HEADERS as $cell => $header )
{
$this->sheet->setCellValue( $cell . '1', $header );
$this->sheet->getColumnDimension( $cell )->setAutoSize( TRUE );
}
}
private function setBody()
{
$this->row = 2;
foreach ( $this->invoiced AS $invoice )
{
$vat = ROUND($invoice->invoiceamount * 0.21, 2);
$this->sheet->setCellValue( 'A' . $this->row, $invoice->invoicenumber );
$this->sheet->setCellValue( 'B' . $this->row, ($invoice->projectnumber . ' ' . $invoice['projectname']));
$this->sheet->setCellValue( 'C' . $this->row, $invoice->name );
$this->sheet->setCellValue( 'D' . $this->row, $invoice->invoicenumber );
$this->sheet->setCellValue( 'E' . $this->row, $invoice->invoiceamount );
$this->sheet->setCellValue( 'F' . $this->row, $vat );
$this->sheet->setCellValue( 'G' . $this->row, $invoice->invoiceamount + $vat );
$this->row ++;
}
}
}
@@ -0,0 +1,101 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 30/07/2018
* Time: 10:48
*/
class MonthForecastSheet {
const HEADERS = [
'A' => 'project',
'B' => 'klant',
'C' => 'Nog te factureren incl. btw',
'D' => 'januari',
'E' => 'februari',
'F' => 'maart',
'G' => 'april',
'H' => 'mei',
'I' => 'juni',
'J' => 'juli',
'K' => 'augustus',
'L' => 'september',
'M' => 'oktober',
'N' => 'november',
'O' => 'december',
'P' => 'Nog te factureren na lopend boekjaar inc. btw',
'Q' => 'Nog te prognotiseren inc. btw'
];
const MONTH_COLUMNS = ['D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O'];
private $invoiceForecast;
private $sheet;
private $row;
public function __construct( $invoiceForecast, $sheet )
{
$this->invoiceForecast = $invoiceForecast;
$this->sheet = $sheet;
$this->handle();
}
private function handle()
{
$this->setHeader();
$this->setBody();
$this->setTotals();
}
private function setHeader()
{
foreach ( self::HEADERS as $cell => $header )
{
$this->sheet->setCellValue( $cell . '1', $header );
$this->sheet->getColumnDimension( $cell )->setAutoSize( TRUE );
}
}
private function setBody()
{
$this->row = 2;
foreach ( $this->invoiceForecast AS $project )
{
$this->sheet->setCellValue( 'A' . $this->row, $project['projectname'] );
$this->sheet->setCellValue( 'B' . $this->row, $project['customer'] );
$this->sheet->setCellValue( 'C' . $this->row, str_replace( '.', '', $project['needInvoice'] ?? '' ) );
$columnCount = 0;
foreach ( $project['forecastMonths'] as $month )
{
$column = self::MONTH_COLUMNS[ $columnCount ];
$forecast = $month['forecastamount'];
$this->sheet->setCellValue( $column . $this->row, $forecast );
$columnCount ++;
}
$this->sheet->setCellValue( 'P' . $this->row, str_replace( '.', '', $project['forecastOtherYears'] ?? '' ) );
$this->sheet->setCellValue( 'Q' . $this->row, str_replace( '.', '', $project['forecastRemaining'] ?? '' ) );
$this->row ++;
}
}
private function setTotals()
{
$lastRow = $this->row - 1;
$this->sheet->setCellValue( 'C' . $this->row, '=SUM(C2:C' . $lastRow . ')' );
$this->sheet->setCellValue( 'D' . $this->row, '=SUM(D2:D' . $lastRow . ')' );
foreach ( self::MONTH_COLUMNS as $column )
{
$this->sheet->setCellValue( $column . $this->row, '=SUM(' . $column . '2:' . $column . $lastRow . ')' );
}
$this->sheet->setCellValue( 'P' . $this->row, '=SUM(P2:P' . $lastRow . ')' );
$this->sheet->setCellValue( 'Q' . $this->row, '=SUM(Q2:Q' . $lastRow . ')' );
}
}
@@ -0,0 +1,95 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 30/07/2018
* Time: 10:48
*/
class MonthPaymentSheet {
const HEADERS = [
'A' => 'project',
'B' => 'klant',
'C' => 'januari',
'D' => 'februari',
'E' => 'maart',
'F' => 'april',
'G' => 'mei',
'H' => 'juni',
'I' => 'juli',
'J' => 'augustus',
'K' => 'september',
'L' => 'oktober',
'M' => 'november',
'N' => 'december',
'O' => 'Totaal betaald lopend boekjaar inc. btw'
];
const MONTH_COLUMNS = ['C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'];
private $invoiceForecast;
private $sheet;
private $row;
public function __construct( $invoiceForecast, $sheet )
{
$this->invoiceForecast = $invoiceForecast;
$this->sheet = $sheet;
$this->handle();
}
private function handle()
{
$this->setHeader();
$this->setBody();
$this->setTotals();
}
private function setHeader()
{
foreach ( self::HEADERS as $cell => $header )
{
$this->sheet->setCellValue( $cell . '1', $header );
$this->sheet->getColumnDimension( $cell )->setAutoSize( TRUE );
}
}
private function setBody()
{
$this->row = 2;
foreach ( $this->invoiceForecast AS $project )
{
$this->sheet->setCellValue( 'A' . $this->row, $project['projectname'] );
$this->sheet->setCellValue( 'B' . $this->row, $project['customer'] );
$columnCount = 0;
foreach ( $project['monthPayments'] as $month )
{
$column = self::MONTH_COLUMNS[ $columnCount ];
$forecast = $month['paymentamount'];
$this->sheet->setCellValue( $column . $this->row, $forecast );
$columnCount ++;
}
$formula = '=SUM(C'.$this->row.':N'.$this->row.')';
$this->sheet->setCellValue( 'O' . $this->row, $formula);
$this->row ++;
}
}
private function setTotals()
{
$lastRow = $this->row - 1;
foreach ( self::MONTH_COLUMNS as $column )
{
$this->sheet->setCellValue( $column . $this->row, '=SUM(' . $column . '2:' . $column . $lastRow . ')' );
}
$this->sheet->setCellValue( 'O' . $this->row, '=SUM(O2:O' . $lastRow . ')' );
}
}
@@ -0,0 +1,125 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 29/07/2018
* Time: 13:14
*/
class InvoiceForecast {
private $year;
private $project;
private $customer;
private $forecast;
private $currentYear;
private $projectname;
private $needInvoice;
private $projectDetails;
private $forecastThisYear = 0;
private $forecastRemaining;
private $forecastOtherYears = 0;
public function __construct( $project, $needInvoice, $year )
{
$this->project = $project;
$this->needInvoice = $needInvoice;
$this->year = $year;
$this->handle();
}
public function getProjectDetails()
{
return $this->projectDetails;
}
public function getNeedInvoice()
{
return $this->needInvoice;
}
public function getForecastOtherYear()
{
return $this->forecastOtherYears;
}
public function getForecastRemaining()
{
return $this->forecastRemaining;
}
private function handle()
{
$this->setCurrentyear();
$this->setProjectname();
$this->setCustomer();
$this->loopForecasts();
$this->setForecastRemaining();
$this->setProjectDetails();
}
private function setCurrentyear()
{
$this->currentYear = date( 'Y' );
}
private function setProjectname()
{
$this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')';
}
private function setCustomer()
{
$this->customer = $this->project->customer->name;
}
private function loopForecasts()
{
if ( is_null( $this->project->forecasts ) ) return $this->forecastThisYear = 0;
foreach ( $this->project->forecasts as $this->forecast )
{
$this->setForecastThisYear();
$this->setForecastOtherYears();
}
}
private function setForecastThisYear()
{
if ( $this->forecast->year == $this->year )
$this->forecastThisYear += $this->forecast->forecastamount;
}
private function setForecastOtherYears()
{
if ( $this->forecast->year != $this->year )
$this->forecastOtherYears += $this->forecast->forecastamount;
}
private function setForecastRemaining()
{
$this->forecastRemaining =
$this->needInvoice - $this->forecastThisYear - $this->forecastOtherYears;
}
private function setProjectDetails()
{
$this->projectDetails = [
'projectnumber' => $this->project->projectnumber,
'projectname' => $this->projectname,
'customer' => $this->customer,
'needInvoice' => number_format( $this->needInvoice, 0, ',', '.' ),
'forecastThisYear' => number_format( $this->forecastThisYear, 0, ',', '.' ),
'forecastOtherYears' => number_format( $this->forecastOtherYears, 0, ',', '.' ),
'forecastRemaining' => number_format( $this->forecastRemaining, 0, ',', '.' ),
];
}
}
@@ -0,0 +1,151 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 29/07/2018
* Time: 10:29
*/
class InvoiceOverview {
private $project;
private $year;
private $projectname;
private $customer;
private $totalToInvoicingExcl;
private $totalToInvoicingIncl;
private $totalInvoicedOtherYears;
private $totalInvoicedThisYear;
private $invoicesTotal;
private $needInvoice;
private $projectDetails;
private $projectnumber;
private $projectPayment;
private $invoicesToPay;
public function __construct( $project, $year )
{
$this->project = $project;
$this->year = $year;
$this->handle();
}
public function getProjectDetails()
{
return $this->projectDetails;
}
public function getNeedinvoice()
{
return $this->needInvoice;
}
private function handle()
{
$this->setProjectnumber();
$this->setProjectname();
$this->setCustomer();
$this->setTotalToInvoicingExcl();
$this->setTotalToInvoicingIncl();
$this->setTotalInvoicedOtherYears();
$this->setTotalInvoicedThisYear();
$this->setPaymentPerProject();
$this->setInvoicesTotal();
$this->setInvoicesToPay();
$this->setNeedInvoice();
$this->setProjectDetails();
}
private function setProjectnumber()
{
$this->projectnumber = $this->project->projectnumber;
}
private function setProjectname()
{
$this->projectname = $this->project->projectname;
}
private function setCustomer()
{
$this->customer = $this->project->customer->name;
}
private function setTotalToInvoicingExcl()
{
$offer = $this->project->offer;
$this->totalToInvoicingExcl =
$offer->own_revenue + $offer->other_revenue + $offer->costs;
}
private function setTotalToInvoicingIncl()
{
$this->totalToInvoicingIncl =
$this->totalToInvoicingExcl * ( 1 + ( $this->project->vat->vatrate / 100 ) );
}
private function setTotalInvoicedOtherYears()
{
$this->totalInvoicedOtherYears =
Invoice::invoicePerYear( $this->project->id, $this->year, FALSE );
}
private function setTotalInvoicedThisYear()
{
$this->totalInvoicedThisYear =
Invoice::invoicePerYear( $this->project->id, $this->year, TRUE );
}
private function setPaymentPerProject()
{
$this->projectPayment = Payment::getPaymentPerProject( $this->project->id );
}
private function setInvoicesTotal()
{
$this->invoicesTotal =
$this->totalInvoicedOtherYears + $this->totalInvoicedThisYear;
}
private function setInvoicesToPay()
{
$this->invoicesToPay = $this->invoicesTotal - $this->projectPayment;
}
private function setNeedInvoice()
{
$this->needInvoice =
$this->totalToInvoicingIncl - $this->invoicesTotal;
}
private function setProjectDetails()
{
$this->projectDetails = [
'projectnumber' => $this->projectnumber,
'projectname' => $this->projectname,
'customer' => $this->customer,
'totalToInvoicingExcl' => number_format( $this->totalToInvoicingExcl ?? 0, 0, ',', '.' ),
'totalToInvoicingIncl' => number_format( $this->totalToInvoicingIncl ?? 0, 0, ',', '.' ),
'totalInvoicedOtherYears' => number_format( $this->totalInvoicedOtherYears ?? 0, 0, ',', '.' ),
'totalInvoicedThisYear' => number_format( $this->totalInvoicedThisYear ?? 0, 0, ',', '.' ),
'invoicesTotal' => number_format( $this->invoicesTotal ?? 0, 0, ',', '.' ),
'projectPayment' => number_format( $this->projectPayment ?? 0, 0, ',', '.' ),
'invoiceToPay' => number_format( $this->invoicesToPay ?? 0, 0, ',', '.' ),
'needInvoice' => number_format( $this->needInvoice ?? 0, 0, ',', '.' )
];
}
}
+133
View File
@@ -0,0 +1,133 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 29/07/2018
* Time: 10:19
*/
class Invoices {
private $year;
private $project;
private $projects;
private $monthPayment;
private $monthPayments;
private $monthForecast;
private $monthForecasts;
private $invoiceOverview;
private $invoiceForecast;
private $invoiceForecasts;
private $invoiceOverviews = [];
private $invoiceReport = [];
private $orderType;
private $orderDirection;
private $archive;
private $invoicedYears;
private $invoiced;
public function __construct( $year, $orderType, $orderDirection, $archive )
{
$this->year = $year;
$this->orderType = $orderType;
$this->orderDirection = $orderDirection;
$this->archive = $archive;
$this->handle();
}
public function getInvoiceReport()
{
return $this->invoiceReport;
}
private function handle()
{
$this->setProjects();
$this->loopProjects();
//only projects with payments also archived projects
$this->setMonthPayments();
$this->setInvoicedyears();
$this->setInvoiced();
$this->setInvoiceReport();
}
private function setProjects()
{
$this->projects =
Project::getProjectsForReport( $this->orderType, $this->orderDirection, $this->archive );
}
private function loopProjects()
{
foreach ( $this->projects as $this->project )
{
$this->setInvoiceOverview();
$this->setInvoiceForecasts();
$this->setMonthForecasts();
}
}
private function setInvoiceOverview()
{
$this->invoiceOverview = new InvoiceOverview( $this->project, $this->year );
$this->invoiceOverviews[] = $this->invoiceOverview->getProjectDetails();
}
private function setInvoiceForecasts()
{
$this->invoiceForecast =
new InvoiceForecast( $this->project, $this->invoiceOverview->getNeedinvoice(), $this->year );
$this->invoiceForecasts[] = $this->invoiceForecast->getProjectDetails();
}
public function setMonthForecasts()
{
$this->monthForecast =
new MonthForecast( $this->invoiceForecast, $this->project, $this->year );
$this->monthForecasts[] = $this->monthForecast->getProjectDetails();
}
public function setMonthPayments()
{
$monthPayment = new MonthPayments(
$this->year, $this->orderType, $this->orderDirection );
$this->monthPayments = $monthPayment->getProjectDetails();
}
private function setInvoiced()
{
$this->invoiced = Invoice::getInvoiced( $this->year, $this->orderType, $this->orderDirection );
}
private function setInvoicedYears()
{
$this->invoicedYears = Invoice::selectRaw( 'DATE_FORMAT(invoicedate, "%Y") AS years' )
->distinct()
->orderBy( 'invoicedate' )
->pluck( 'years' );
}
private function setInvoiceReport()
{
$this->invoiceReport = [
'invoiceOverview' => $this->invoiceOverviews,
'forecasts' => $this->invoiceForecasts,
'monthForecasts' => $this->monthForecasts,
'monthPayments' => $this->monthPayments,
'invoicedYears' => $this->invoicedYears,
'invoiced' => $this->invoiced
];
}
}
@@ -0,0 +1,92 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 29/07/2018
* Time: 14:23
*/
class MonthForecast {
private $year;
private $project;
private $forecast;
private $customer;
private $projectname;
private $forecastMonths;
private $projectDetails;
private $invoiceForecast;
public function __construct( InvoiceForecast $invoiceForecast, $project, $year )
{
$this->project = $project;
$this->invoiceForecast = $invoiceForecast;
$this->year = $year;
$this->handle();
}
public function getProjectDetails()
{
return $this->projectDetails;
}
private function handle()
{
$this->setProjectname();
$this->setCustomer();
$this->setInitialsForecastMonths();
$this->loopForecasts();
$this->setProjectDetails();
}
private function setProjectname()
{
$this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')';
}
private function setCustomer()
{
$this->customer = $this->project->customer->name;
}
private function setInitialsForecastMonths()
{
for ( $i = 0; $i < 12; $i ++ )
{
$this->forecastMonths[ $i ] = ['forecastamount' => 0];
}
}
private function loopForecasts()
{
foreach ( $this->project->forecasts as $this->forecast )
{
$this->setMonthForecast();
}
}
private function setMonthForecast()
{
if ( $this->forecast->year == $this->year )
$this->forecastMonths[ $this->forecast->month_id ]['forecastamount'] += $this->forecast->forecastamount;
}
private function setProjectDetails()
{
$this->projectDetails = [
'projectnumber' => $this->project->projectnumber,
'projectname' => $this->projectname,
'customer' => $this->customer,
'needInvoice' => number_format( $this->invoiceForecast->getNeedInvoice(), 0, ',', '.' ),
'forecastOtherYears' => number_format( $this->invoiceForecast->getForecastOtherYear(), 0, ',', '.' ),
'forecastRemaining' => number_format( $this->invoiceForecast->getForecastRemaining(), 0, ',', '.' ),
'forecastMonths' => $this->forecastMonths
];
}
}
@@ -0,0 +1,128 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 29/07/2018
* Time: 14:23
*/
class MonthPayments {
private $year;
private $project;
private $payment;
private $customer;
private $projectname;
private $monthPayments;
private $projectDetails;
private $projectsWithPayments;
private $totalProjectPayments;
private $orderType;
private $orderDirection;
public function __construct( $year, $orderType, $orderDirection )
{
$this->year = $year;
$this->orderType = $orderType;
$this->orderDirection = $orderDirection;
$this->handle();
}
public function getProjectDetails()
{
return $this->projectDetails;
}
private function handle()
{
$this->setProjectsWithPayments();
$this->loopProjectsWithPayments();
}
private function setProjectsWithPayments()
{
$projectsArray = Payment::getProjectsWithPayments( $this->year );
$this->projectsWithPayments =
Project::getProjectsForReport(
$this->orderType, $this->orderDirection, FALSE, $projectsArray );
}
private function loopProjectsWithPayments()
{
foreach ( $this->projectsWithPayments as $this->project )
{
$this->setProjectname();
$this->setCustomer();
$this->setInitialsMonthPayments();
$this->loopPayments();
$this->setProjectDetails();
}
}
private function setProjectname()
{
$this->projectname = $this->project->projectname . '(' . $this->project->projectnumber . ')';
}
private function setCustomer()
{
$this->customer = $this->project->customer->name;
}
private function setInitialsMonthPayments()
{
for ( $i = 1; $i <= 12; $i ++ )
{
$this->monthPayments[ $i ] = ['paymentamount' => 0];
}
}
private function loopPayments()
{
$this->totalProjectPayments = 0;
foreach ( $this->project->invoices as $invoice )
{
foreach ( $invoice->payments as $this->payment )
{
$this->setMonthPayments();
$this->setTotalProjectPayments();
}
}
}
private function setMonthPayments()
{
$paymentYear = date( 'Y', strtotime( $this->payment->paymentdate ) );
$paymentMonth = date( 'n', strtotime( $this->payment->paymentdate ) );
if ( $paymentYear == $this->year )
$this->monthPayments[ $paymentMonth ]['paymentamount'] += $this->payment->paymentamount;
}
private function setTotalProjectPayments()
{
$paymentYear = date( 'Y', strtotime( $this->payment->paymentdate ) );
if ( $paymentYear == $this->year )
$this->totalProjectPayments += $this->payment->paymentamount;
}
private function setProjectDetails()
{
$this->projectDetails[] = [
'projectnumber' => $this->project->projectnumber,
'projectname' => $this->projectname,
'customer' => $this->customer,
'monthPayments' => $this->monthPayments,
'totalProjectPayments' => number_format( $this->totalProjectPayments, 0, ',', '.' )
];
}
}
+279
View File
@@ -0,0 +1,279 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 20/02/2018
* Time: 16:49
*/
class Recapprojects {
private $index;
private $field;
private $archive;
private $project;
private $projects;
private $direction;
private $employeeHours;
private $invoicedYears = [];
private $projectTotals;
private $employeeBudget;
private $uniqueEmployee;
private $uniqueEmployees;
private $currentFinancialYear;
private $projectEmployeeDetail;
private $projectEmployeeDetails;
public function __construct( $archive, $field, $direction )
{
$this->archive = $archive;
$this->field = $field;
$this->direction = $direction;
$this->handle();
}
public function getProjects()
{
return $this->projects;
}
private function handle()
{
$this->setProjects();
$this->setUniqueEmployees();
$this->loopProjects();
$this->setInvoicedYears();
$this->loopProjectsForInvoicedYears();
}
private function setProjects()
{
$this->projects = Project::getActiveProjects(
$this->archive, $this->field, $this->direction )->toArray();
}
private function setUniqueEmployees()
{
$this->uniqueEmployees =
Projectemployee::getUniqueEmployeesWithActivity();
}
private function loopProjects()
{
$this->index = 0;
foreach ( $this->projects as $this->project )
{
$this->projectTotals = 0;
$this->setProjectEmployeeDetails();
$this->loopUniqueEmployees();
$this->setBudget();
$this->setProjectCosts();
$this->setBudgetAvailable();
$this->setSaldo();
$this->setInvoiced();
$this->setWorkInProgress();
$this->setCurrentFinancialYear();
$this->index ++;
}
}
private function setProjectEmployeeDetails()
{
$this->projectEmployeeDetails =
Projectemployee::getProjectemployeeDetailsPerProject( $this->project['id'] );
}
private function loopUniqueEmployees()
{
foreach ( $this->uniqueEmployees as $this->uniqueEmployee )
{
$this->setProjectEmployeeDetail();
$this->setEmployeeBudget();
$this->setEmployeeHours();
$this->setEmployeeDetails();
$this->setProjectTotals();
}
}
private function setProjectEmployeeDetail()
{
foreach ( $this->projectEmployeeDetails as $this->projectEmployeeDetail )
{
if ( $this->uniqueEmployee->id == $this->projectEmployeeDetail->id ) return;
}
$this->projectEmployeeDetail = FALSE;
}
private function setEmployeeBudget()
{
if( property_exists($this, 'uniqueEmployee') ) return $this->employeeBudget = 0;
if( is_null($this->projectEmployeeDetail)) return $this->employeeBudget = 0;
$this->employeeBudget =
is_null( $this->projectEmployeeDetail['budget'] ) ? 0 : $this->projectEmployeeDetail['budget'];
}
private function setEmployeeHours()
{
$this->employeeHours =
$this->projectEmployeeDetail ? $this->projectEmployeeDetail->hours : 0;
}
private function setEmployeeDetails()
{
$this->projects[ $this->index ]['employees'][] = [
'id' => $this->uniqueEmployee->id,
'fullname' => $this->uniqueEmployee->fullname,
'hours' => $this->employeeHours,
'revenues' => $this->projectEmployeeDetail ? $this->projectEmployeeDetail->revenues : 0,
'budget' => $this->employeeBudget,
'availableHours' => $this->employeeBudget - $this->employeeHours
];
}
private function setProjectTotals()
{
if ( ! isset( $this->projects[ $this->index ]['projectHours'] ) )
$this->projects[ $this->index ]['projectHours'] = 0;
if ( ! isset( $this->projects[ $this->index ]['projectEuros'] ) )
$this->projects[ $this->index ]['projectEuros'] = 0;
if ( ! isset( $this->projects[ $this->index ]['hoursAvailable'] ) )
$this->projects[ $this->index ]['hoursAvailable'] = 0;
$this->projects[ $this->index ]['projectHours'] +=
$this->projectEmployeeDetail ? $this->projectEmployeeDetail->hours : 0;
$this->projects[ $this->index ]['projectEuros'] +=
$this->projectEmployeeDetail ? $this->projectEmployeeDetail->revenues : 0;
$this->projects[ $this->index ]['hoursAvailable'] +=
$this->employeeBudget - $this->employeeHours;
}
private function setBudget()
{
$this->projects[ $this->index ]['budget'] =
round( ( $this->projects[ $this->index ]['own_revenue'] + $this->projects[ $this->index ]['other_revenue'] ), 0 );
}
private function setProjectCosts()
{
$this->projects[ $this->index ]['projectcosts'] =
Projectcost::getCostsPerPerProject( $this->projects[ $this->index ]['id'] );
}
private function setBudgetAvailable()
{
$this->projects[ $this->index ]['budgetAvailable'] =
$this->projects[ $this->index ]['budget'] - $this->projects[ $this->index ]['projectcosts'];
}
private function setSaldo()
{
$this->projects[ $this->index ]['saldo'] =
$this->projects[ $this->index ]['budgetAvailable'] - $this->projects[ $this->index ]['projectEuros'];
}
private function setInvoiced()
{
$invoiced = \Invoice::getInvoicedPerYearPerProject( $this->projects[ $this->index ]['id'] );
foreach ( $invoiced ? $invoiced : [] as $invoice )
{
$this->projects[ $this->index ]['invoiced'][] = [
'year' => $invoice->invoiceyear,
'invoiced' => $invoice->invoiced
];
$this->setTotalInvoiced( $invoice->invoiced );
}
if ( ! isset( $this->projects[ $this->index ]['invoiced'] ) )
{
$this->projects[ $this->index ]['invoiced'] = [];
$this->projects[ $this->index ]['totalInvoiced'] = 0;
}
}
private function setTotalInvoiced( $invoiced )
{
if ( ! isset( $this->projects[ $this->index ]['totalInvoiced'] ) )
$this->projects[ $this->index ]['totalInvoiced'] = 0;
$this->projects[ $this->index ]['totalInvoiced'] += $invoiced;
}
private function setWorkInProgress()
{
$this->projects[ $this->index ]['workInProgress'] =
$this->projects[ $this->index ]['projectEuros'] +
$this->projects[ $this->index ]['projectcosts'] -
$this->projects[ $this->index ]['totalInvoiced'];
if ( $this->projects[ $this->index ]['workInProgress'] < 0 )
$this->projects[ $this->index ]['workInProgress'] = 0;
}
private function setCurrentFinancialYear()
{
$this->currentFinancialYear = $this->project['current_financial_year'];
}
private function setInvoicedYears()
{
foreach ( $this->projects as $this->project )
{
foreach ( $this->project['invoiced'] as $year )
{
if ( in_array( $year['year'], $this->invoicedYears ) ) continue;
array_push( $this->invoicedYears, $year['year'] );
}
}
}
private function loopProjectsForInvoicedYears()
{
$this->index = 0;
foreach ( $this->projects as $this->project )
{
foreach ( $this->invoicedYears as $invoiceYear )
{
$hasYear = FALSE;
foreach ( $this->project['invoiced'] as $year )
{
if ( $invoiceYear == $year['year'] ) $hasYear = TRUE;
}
if ( ! $hasYear ) $this->projects[ $this->index ]['invoiced'][] = [
'year' => $invoiceYear,
'invoiced' => 0
];
}
usort( $this->projects[ $this->index ]['invoiced'], function ( $a, $b ) {
return $a['year'] - $b['year'];
} );
$this->index ++;
}
}
}