Removalls and offers revenues

This commit is contained in:
2018-06-10 17:31:05 +02:00
parent 8fe98e6ccb
commit c539d03fb6
20 changed files with 449 additions and 158 deletions
@@ -63,7 +63,7 @@ class OffersController extends MY_Controller {
{
$removeOffer = new RemoveOffer( $offerID );
if ( $removeOffer->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
if ( $removeOffer->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] );
Offer::removeOffer( $offerID );
@@ -256,28 +256,39 @@ class ProjectsController extends MY_Controller {
Project::whereId( $projectID )->update( ['archive' => $status] );
}
public function removeProject( $projectID )
{
$removeProject = new RemoveProject( $projectID );
if ( $removeProject->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
Project::removeProject( $projectID );
$this->json( ['result' => TRUE] );
}
public function removeProjectemployee( $projectemployeeID )
{
$removeProjectemployee = new RemoveProjectemployee( $projectemployeeID );
if ( $removeProjectemployee->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
if ( $removeProjectemployee->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] );
Projectemployee::removeProjectemployee( $projectemployeeID );
$this->json( ['result' => TRUE] );
}
public function removeInvoice( $invoiceID )
{
$removeInvoice = new RemoveInvoice( $invoiceID );
if ( $removeInvoice->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] );
Invoice::whereId( $invoiceID )->delete();
return $this->json( ['result' => TRUE] );
}
public function removeIncomingInvoice( $invoiceID )
{
// $removeInvoice = new RemoveInvoice( $invoiceID );
//
// if ( $removeInvoice->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] );
Projectcost::whereId( $invoiceID )->delete();
return $this->json( ['result' => TRUE] );
}
public function removePayment( $paymentID )
{
$removePayment = new RemovePayment( $paymentID );
@@ -322,4 +333,15 @@ class ProjectsController extends MY_Controller {
$this->json( ['result' => TRUE] );
}
public function removeProject( $projectID )
{
$removeProject = new RemoveProject( $projectID );
if ( $removeProject->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] );
Project::removeProject( $projectID );
$this->json( ['result' => TRUE] );
}
}
@@ -0,0 +1,53 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/06/2018
* Time: 17:06
*/
class RemoveInvoice {
private $invoiceID;
private $payments;
private $removeAllowed;
public function __construct( $invoiceID )
{
$this->setInvoiceID( $invoiceID );
$this->handle();
}
public function getRemoveAllowed()
{
return $this->removeAllowed;
}
private function setInvoiceID( $invoiceID )
{
$this->invoiceID = $invoiceID;
}
private function handle()
{
$this->setPayment();
$this->setRemoveAllowed();
}
private function setPayment()
{
$payments = Payment::whereInvoiceId( $this->invoiceID );
$this->payments = $payments->count() == 0 ? TRUE : FALSE;
}
private function setRemoveAllowed()
{
if ( $this->payments === FALSE ) return $this->removeAllowed = FALSE;
$this->removeAllowed = TRUE;
}
}
@@ -0,0 +1,46 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/06/2018
* Time: 15:56
*/
class RemoveInvoices {
private $invoiceID;
private $payments;
private $removeAllowed;
public function __construct( $invoiceID )
{
$this->setInvoiceID($invoiceID);
$this->handle();
}
private function setInvoiceID( $invoiceID )
{
$this->invoiceID = $invoiceID;
}
private function handle()
{
$this->setPayments();
$this->setRemoveAllowed();
}
private function setPayments()
{
$payments = Payment::whereInvoiceId($this->invoiceID);
$this->payments = $payments->count() == 0 ? TRUE : FALSE;
}
private function setRemoveAllowed()
{
$this->removeAllowed = $this->payments;
}
}
@@ -0,0 +1,52 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/06/2018
* Time: 16:28
*/
class RemoveOffer {
private $offerID;
private $project;
private $removeAllowed;
public function __construct($offerID)
{
$this->setOfferID($offerID);
$this->handle();
}
public function getRemoveAllowed()
{
return $this->removeAllowed;
}
private function setOfferID( $offerID )
{
$this->offerID = $offerID;
}
private function handle()
{
$this->setProject();
$this->setRemoveAllowed();
}
private function setProject()
{
$offer = Offer::Find($this->offerID);
$this->project = is_null($offer->project_id) ? TRUE : FALSE;
}
private function setRemoveAllowed()
{
if( $this->project === FALSE ) return $this->removeAllowed = FALSE;
$this->removeAllowed = TRUE;
}
}
@@ -0,0 +1,97 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/06/2018
* Time: 15:53
*/
class RemoveProject {
private $projectID;
private $forecast;
private $invoices;
private $projectemployees;
private $reservations;
private $removeAllowed;
private $projectcosts;
public function __construct( $projectID )
{
$this->setProjectID( $projectID );
$this->handle();
}
public function getRemoveAllowed()
{
return $this->removeAllowed;
}
private function setProjectID( $projectID )
{
$this->projectID = $projectID;
}
private function handle()
{
$this->setForecast();
$this->setInvoices();
$this->setProjectemployees();
$this->setReservations();
$this->setRemoveAllowed();
$this->setProjectCosts();
}
private function setForecast()
{
$forecast = Forecast::whereProjectId( $this->projectID );
$this->forecast = $forecast->count() == 0 ? TRUE : FALSE;
}
private function setInvoices()
{
$invoices = Invoice::whereProjectId( $this->projectID );
$this->invoices = $invoices->count() == 0 ? TRUE : FALSE;
}
private function setProjectemployees( )
{
$setProjectemployees = Projectemployee::whereProjectId($this->projectID);
$this->projectemployees = $setProjectemployees->count() == 0 ? TRUE : FALSE;
}
private function setReservations( )
{
$reservations = Reservation::whereProjectId($this->projectID);
$this->reservations = $reservations->count() == 0 ? TRUE : FALSE;
}
private function setProjectcosts( )
{
$projectcosts = Projectcost::whereProjectId($this->projectID);
$this->projectcosts = $projectcosts->count() == 0 ? TRUE : FALSE;
}
private function setRemoveAllowed()
{
if( $this->forecast === false ) return $this->removeAllowed = FALSE;
if( $this->invoices === false ) return $this->removeAllowed = FALSE;
if( $this->projectemployees === false ) return $this->removeAllowed = FALSE;
if( $this->reservations === false ) return $this->removeAllowed = FALSE;
if( $this->projectcosts === false ) return $this->removeAllowed = FALSE;
$this->removeAllowed = TRUE;
}
}
@@ -0,0 +1,53 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 17:45
*/
class RemoveProjectemployee {
private $projectemployeeID;
private $removeAllowed;
private $projecthours;
public function __construct( $projectemployeeID )
{
$this->setProjectemployeeID( $projectemployeeID );
$this->handle();
}
public function getRemoveAllowed()
{
return $this->removeAllowed;
}
private function setProjectemployeeID( $projectemployeeID )
{
$this->projectemployeeID = $projectemployeeID;
}
private function handle()
{
$this->setProjectHours();
$this->setRemoveAllowed();
}
private function setProjecthours()
{
$projecthours = Projecthour::whereProjectemployeeId($this->projectemployeeID);
$this->projecthours = $projecthours->count() == 0 ?TRUE : FALSE;
}
private function setRemoveAllowed()
{
if( $this->projecthours === false ) return $this->removeAllowed = FALSE;
$this->removeAllowed = TRUE;
}
}
@@ -1,43 +0,0 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 17:45
*/
class RemoveProject {
private $projectID;
private $allowDelete = TRUE;
public function __construct( $projectID )
{
$this->setProjectID( $projectID );
$this->handle();
}
public function getAllowDelete()
{
return $this->allowDelete;
}
private function setProjectID( $projectID )
{
$this->projectID = $projectID;
}
private function handle()
{
$this->checkForOffers();
}
private function checkForOffers()
{
$offers = Offer::whereProjectId($this->projectID);
if( $offers->count() > 0 ) $this->allowDelete = FALSE;
}
}
@@ -1,36 +0,0 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 17:45
*/
class RemoveProjectemployee {
private $projectemployeeID;
private $allowDelete = TRUE;
public function __construct( $projectemployeeID )
{
$this->setProjectemployeeID( $projectemployeeID );
$this->handle();
}
public function getAllowDelete()
{
return $this->allowDelete;
}
private function setProjectemployeeID( $projectemployeeID )
{
$this->projectemployeeID = $projectemployeeID;
}
private function handle()
{
}
}
@@ -1,36 +0,0 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/12/2017
* Time: 17:45
*/
class RemoveOffer {
private $offerID;
private $allowDelete = TRUE;
public function __construct( $userID )
{
$this->setOfferID( $userID );
$this->handle();
}
public function getAllowDelete()
{
return $this->allowDelete;
}
private function setOfferID( $customerID )
{
$this->offerID = $customerID;
}
private function handle()
{
}
}
+2
View File
@@ -80,6 +80,8 @@ class Project extends BaseModel {
public static function removeProject( $projectID )
{
Offer::whereProjectId( $projectID )->update( ['project_id' => NULL] );
Project::whereId( $projectID )->delete();
}
@@ -14,7 +14,7 @@ class Qinvoiceoverview {
$sql = "
SELECT PRJ.id, PRJ.projectnumber,
PRJ.projectname,
(own_revenue + other_revenue ) AS revenues,
(own_revenue + other_revenue + OFF.costs ) AS revenues,
CUS.name AS customername,
SUM(IF( YEAR(invoicedate) = {$year}, invoiceamount* ((100 + VTS.vatrate)/100), 0)) AS currentyear,
SUM(IF( YEAR(invoicedate) != {$year}, invoiceamount * ((100 + VTS.vatrate)/100), 0)) AS otheryear,
@@ -27,7 +27,7 @@ class Invoices_model extends MY_Model {
public function getOutstandingPerProject( $projectID )
{
$this->sql = "
SELECT (own_revenue + other_revenue) AS totalrevenue,
SELECT (own_revenue + other_revenue + OFF.costs) AS totalrevenue,
ROUND(SUM(INV.invoiceamount * ((100 + vatrate) / 100)), 0) AS totalinvoiced,
(
SELECT SUM(paymentamount) PAYMENTAMOUNT
@@ -94,7 +94,7 @@
<td>
<i class="icon fa-edit pointer" title="wijzig" data-bind="click:$root.editProjectcosts"></i>
<i class="icon fa-trash redish pointer" title="verwijder"
data-bind="click:$root.removeProjecthour"></i>
data-bind="click:$root.removeProjectcosts"></i>
</td>
</tr>
</tbody>
@@ -117,6 +117,13 @@
</h4>
</div>
<div class="divider"></div>
<label class="col-md-6 col-form-label">kosten(excl.btw)</label>
<div class="col-md-6">
<h4 class="form-control-label">
<i class="icon fa-euro"> </i><span class="euro-amount" data-bind="text:costs"></span>
</h4>
</div>
<div class="divider"></div>
<label class="col-md-6 col-form-label">Totaal omzet(excl.btw)</label>
<div class="col-md-6">
<h4><i class="icon fa-euro"> </i><span class="euro-amount" data-bind="text:totalRevenues"></span></h4>
@@ -121,6 +121,20 @@ dbo.projectDataService = {
} );
},
removeInvoice: function ( invoiceID, callback ) {
$.getJSON( 'index.php/projects/projectsController/removeInvoice/' + invoiceID )
.done( function ( data ) {
callback( data );
} );
},
removeIncomingInvoice: function ( invoiceID, callback ) {
$.getJSON( 'index.php/projects/projectsController/removeIncomingInvoice/' + invoiceID )
.done( function ( data ) {
callback( data );
} );
},
removeProjectemployee: function ( projectemployeeID, callback ) {
$.getJSON( 'index.php/projects/projectsController/removeProjectemployee/' + projectemployeeID )
.done( function ( data ) {
+83 -23
View File
@@ -28,27 +28,28 @@ $( function () {
showProject : ko.observable( false ),
projectID : null,
callback : null,
customerID : ko.observable( null ),
projectnumber : ko.observable(),
projectleaderID : ko.observable(),
archive : ko.observable( false ),
startdate : ko.observable( null ),
enddate : ko.observable( null ),
vat_id : ko.observable(),
projectname : ko.observable(),
busy : false,
ownRevenue : ko.observable(),
otherRevenue : ko.observable(),
projectname : ko.observable(),
years : ko.observableArray( dbo.years ),
months : ko.observableArray( dbo.monthArray ),
outstanding : ko.observable(),
documents : ko.observableArray( [] ),
comments : ko.observableArray( [] ),
activeTab : ko.observable(),
totalRevenues : ko.observable(),
totalInvoiced : ko.observable(),
totalRevenuesIncl : ko.observable(),
customerID : ko.observable( null ),
projectnumber : ko.observable(),
projectleaderID : ko.observable(),
archive : ko.observable( false ),
startdate : ko.observable( null ),
enddate : ko.observable( null ),
vat_id : ko.observable(),
projectname : ko.observable(),
busy : false,
ownRevenue : ko.observable(),
otherRevenue : ko.observable(),
costs : ko.observable(),
projectname : ko.observable(),
years : ko.observableArray( dbo.years ),
months : ko.observableArray( dbo.monthArray ),
outstanding : ko.observable(),
documents : ko.observableArray( [] ),
comments : ko.observableArray( [] ),
activeTab : ko.observable(),
totalRevenues : ko.observable(),
totalInvoiced : ko.observable(),
totalRevenuesIncl: ko.observable(),
outstanding : ko.observable(),
outstandingInvoices: ko.observable(),
payed : ko.observable(),
@@ -554,7 +555,65 @@ $( function () {
} else {
tellMe( {
title : 'fout bij verwijderen projectmedewerker',
message : 'de projectmedewerker kan niet worden verwijderd',
message : 'de projectmedewerker kan niet worden verwijderd, verwijder eerst alle uren behorende bij deze medewerker bij dit project',
modalClass: 'modal-danger'
} );
}
} );
}
} );
},
removeInvoice: function () {
var vm = dbo.editProjectModal;
var self = this;
tellMe( {
title : 'verwijderen factuur',
message : 'weet u zeker dat u deze factuur wilt verwijderen, dit kan niet ongedaan worden gemaakt',
notify : true,
noText : 'nee verwijder de factuur niet',
yesText : 'ja verwijder de factuur',
modalClass: 'modal-warning'
}, function ( response ) {
console.log( response );
if ( response ) {
dbo.projectDataService.removeInvoice( self.id, function ( data ) {
if ( data.result ) {
vm.refreshProject();
} else {
tellMe( {
title : 'fout bij verwijderen factuur',
message : 'de factuur kan niet worden verwijderd, verwijder eerst alle betalingen op deze factuur',
modalClass: 'modal-danger'
} );
}
} );
}
} );
},
removeProjectcosts: function () {
var vm = dbo.editProjectModal;
var self = this;
tellMe( {
title : 'verwijderen inkomende factuur',
message : 'weet u zeker dat u deze inkomende factuur wilt verwijderen, dit kan niet ongedaan worden gemaakt',
notify : true,
noText : 'nee verwijder de inkomende factuur niet',
yesText : 'ja verwijder de inkomende factuur',
modalClass: 'modal-warning'
}, function ( response ) {
console.log( response );
if ( response ) {
dbo.projectDataService.removeIncomingInvoice( self.id, function ( data ) {
if ( data.result ) {
vm.refreshProject();
} else {
tellMe( {
title : 'fout bij verwijderen inkomende factuur',
message : 'de inkomende factuur kan niet worden verwijderd',
modalClass: 'modal-danger'
} );
}
@@ -775,7 +834,8 @@ $( function () {
_.each( data.offers, function ( p, i ) {
if ( i == 0 ) {
vm.ownRevenue( dbo.helpers.numberWithPoints( Math.round( Number( p.own_revenue ) ) ) );
vm.otherRevenue( dbo.helpers.numberWithPoints( Math.round( Number( p.other_revenue ) ) ) );
vm.otherRevenue( dbo.helpers.numberWithPoints( Math.round( Number( p.other_revenue ) ) ) )
vm.costs(dbo.helpers.numberWithPoints( Math.round( Number( p.costs ) ) ) )
}
vm.offers.push( new dbo.offersService.Offer( p ) );
} );
@@ -92,7 +92,7 @@ dbo.projectsInit = function () {
} else {
tellMe( {
title : 'fout bij verwijderen project',
message : 'de project kan niet worden verwijderd',
message : 'de project kan niet worden verwijderd, verwijder eerst de gerelateerde gegevens (facturen, reserveringen, projectmedewerkers, prognoses) ',
modalClass: 'modal-danger'
} );
}
@@ -104,8 +104,8 @@ dbo.outgoinginvoicesInit = function () {
self.customername = data.customername;
self.statusProject = Math.abs( openstaand ) > 2 ? 'OPEN' : 'CLOSED';
self.fullname = data.fullname;
self.revenues = dbo.helpers.numberWithPoints( data.revenues );
self.totalInvoice = dbo.helpers.numberWithPoints( totalInvoice );
self.revenues = dbo.helpers.numberWithPoints( Number(data.revenues).toFixed(0) );
self.totalInvoice = dbo.helpers.numberWithPoints( Number(totalInvoice).toFixed(0) );
self.openstaand = dbo.helpers.numberWithPoints( Math.round( openstaand ) );
self.openstaandIncl = dbo.helpers.numberWithPoints( Math.round( openstaand * 1.21 ) );
self.invoicedOtherYears = dbo.helpers.numberWithPoints( Math.round( data.otheryear ) );
+1 -1
View File
@@ -69,7 +69,7 @@ dbo.offersService = {
} else {
tellMe( {
title : 'fout bij verwijderen offerte',
message : 'de offerte kan niet worden verwijderd',
message : 'de offerte kan niet worden verwijderd, verwijder eerst het gerelateerde project',
modalClass: 'modal-danger'
} );
}