128 lines
2.7 KiB
PHP
128 lines
2.7 KiB
PHP
<?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[] = [
|
|
'projectname' => $this->projectname,
|
|
'customer' => $this->customer,
|
|
'monthPayments' => $this->monthPayments,
|
|
'totalProjectPayments' => number_format( $this->totalProjectPayments, 0, ',', '.' )
|
|
];
|
|
}
|
|
}
|