diff --git a/application/controllers/beheer/vatController.php b/application/controllers/beheer/vatController.php new file mode 100644 index 0000000..5213a82 --- /dev/null +++ b/application/controllers/beheer/vatController.php @@ -0,0 +1,36 @@ +load->model( $models ); + $this->load->library( $libraries ); + } + + public function index() + { + + } + + public function getVats( $archive ) + { + $vats = Vat::getVats( $archive ); + + $this->json($vats); + } +} \ No newline at end of file diff --git a/application/models/eloquent/Invoice.php b/application/models/eloquent/Invoice.php new file mode 100644 index 0000000..0c25d85 --- /dev/null +++ b/application/models/eloquent/Invoice.php @@ -0,0 +1,25 @@ +belongsTo( 'Project' ); + } + + public function payments() + { + return $this->hasMany( 'Payment' ); + } + + public function vat() + { + return $this->belongsTo( 'Vat' ); + } +} \ No newline at end of file diff --git a/application/models/eloquent/Payment.php b/application/models/eloquent/Payment.php index 376d9d8..9099ef0 100644 --- a/application/models/eloquent/Payment.php +++ b/application/models/eloquent/Payment.php @@ -10,9 +10,9 @@ class Payment extends BaseModel { protected $table = "payments"; - public function offer() + public function invoice() { - return $this->belongsTo( 'Offer' ); + return $this->belongsTo( 'Invoice' ); } public static function savePayment( $paymentID, $payment ) diff --git a/application/models/eloquent/Project.php b/application/models/eloquent/Project.php index 9d4a3ca..642f792 100644 --- a/application/models/eloquent/Project.php +++ b/application/models/eloquent/Project.php @@ -21,6 +21,16 @@ class Project extends BaseModel { return $this->hasMany( 'Projectemployee' ); } + public function projectcosts() + { + return $this->hasMany( 'Projectcost' ); + } + + public function invoices() + { + return $this->hasMany( 'Invoice' ); + } + public function projectleader() { return $this->belongsTo( 'User', 'projectleader_id' ); @@ -66,17 +76,16 @@ class Project extends BaseModel { }] ) ->with( [ 'offers' => function ( $q ) { - $q->whereArchive( 'F' ) - ->with( [ - 'payments' => function ( $q ) { - $q->selectRaw( '*' ); - }] ); + $q->whereArchive( 'F' ); }] ) ->with( [ 'projectemployees.user' => function ( $q ) { $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); }] ) ->with( 'projectemployees.projecthours' ) + ->with( 'projectcosts.external' ) + ->with( 'invoices.payments' ) + ->with( 'invoices.vat' ) ->with( 'customer' ); return $project; diff --git a/application/models/eloquent/Projectcost.php b/application/models/eloquent/Projectcost.php new file mode 100644 index 0000000..c8301d1 --- /dev/null +++ b/application/models/eloquent/Projectcost.php @@ -0,0 +1,21 @@ +belongsTo( 'Project' ); + } + + public function external() + { + return $this->belongsTo( 'External' ); + } + +} \ No newline at end of file diff --git a/application/models/eloquent/Vat.php b/application/models/eloquent/Vat.php new file mode 100644 index 0000000..9f17907 --- /dev/null +++ b/application/models/eloquent/Vat.php @@ -0,0 +1,30 @@ +hasMany( 'Invoice' ); + } + + public static function getVats( $archive ) + { + if ( $archive == 'F' ) + { + $vats = vat::whereArchive( 'F' )->get(); + } + else + { + $vats = Vat::get(); + } + + return $vats; + } + +} \ No newline at end of file diff --git a/application/views/modals/partials/_hours.php b/application/views/modals/partials/_hours.php index cdd548e..1b75e13 100644 --- a/application/views/modals/partials/_hours.php +++ b/application/views/modals/partials/_hours.php @@ -65,7 +65,7 @@ diff --git a/application/views/modals/partials/_invoices.php b/application/views/modals/partials/_invoices.php new file mode 100644 index 0000000..9138cc1 --- /dev/null +++ b/application/views/modals/partials/_invoices.php @@ -0,0 +1,182 @@ +
+
+

+ facturen +

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  + factuurnummer + + factuurdatum + + bedrag (excl) + + bedrag (incl) + + prognose(excl) + + prognose datum + + btw tarief + +   +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + % + + + + + +
+ + + + + + + + + + + + + + + + + + +
  + datum + + bedrag + +
  + + + + + + + + + + + +
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/application/views/modals/partials/_payments.php b/application/views/modals/partials/_payments.php deleted file mode 100644 index f71e5d4..0000000 --- a/application/views/modals/partials/_payments.php +++ /dev/null @@ -1,75 +0,0 @@ -
-
-

- betalingen -

-
-
- - - - - - - - - - - - - - - - - - - - -
- offertenummer - - datum - - bedrag - -   -
- - - - - - - - - - - - - - -
- -
-
-
\ No newline at end of file diff --git a/application/views/modals/partials/_projectcosts.php b/application/views/modals/partials/_projectcosts.php index 8193ced..5d38a8d 100644 --- a/application/views/modals/partials/_projectcosts.php +++ b/application/views/modals/partials/_projectcosts.php @@ -23,50 +23,49 @@   - + - + - - uur + + paceholder="omschrijving" + data-bind="textInput:description, visible:inEdit, + event:{change:$root.saveProjectcosts"/> - + + value:date, visible:inEdit, + event:{change:$root.saveProjectcosts}"/> - + + data-bind="textInput:costs, visible:inEdit, + event:{change:$root.saveProjectcosts,keyup:$root.validateNumber.bind($data, 'costs')}"/> @@ -78,8 +77,8 @@ - diff --git a/application/views/modals/project_modal.php b/application/views/modals/project_modal.php index 4b5b7d3..d0579de 100644 --- a/application/views/modals/project_modal.php +++ b/application/views/modals/project_modal.php @@ -2,120 +2,160 @@ +
-
-
-
- -
- - - selecteer een klant - -
-
-
-
-
- -
- + + selecteer een klant + +
+
+
+
+
+ +
+ -
-
-
-
-
- -
-
+ +
+
+
+
+
+ +
+
- +
+
+
-
-
-
-
-
- -
-
+
+
+ +
+
- +
+
+
+
+
+
+
+
+
+ load->view( 'modals/partials/_projectoffers' ); ?> +
+
+ load->view( 'modals/partials/_projectcosts' ); ?> +
+
+
+
+ load->view( 'modals/partials/_invoices' ); ?> +
+
+
+
+
+
+ load->view( 'modals/partials/_projectemployees' ); ?> +
+
+ load->view( 'modals/partials/_hours' ); ?> +
+
+
+ +
+
+
+ load->view( 'modals/partials/_projectfiles' ); ?> +
+
+ load->view( 'modals/partials/_projectcomments' ); ?>
-
-
- - - - - - - - - - - -
-
- load->view( 'modals/partials/_projectoffers' ); ?> -
-
- load->view( 'modals/partials/_projectemployees' ); ?> -
-
-
-
- load->view('modals/partials/_payments'); ?> -
-
- load->view('modals/partials/_hours'); ?> -
-
- load->view('modals/partials/_projectcosts'); ?> -
-
-
-
- load->view('modals/partials/_projectfiles'); ?> -
-
- load->view('modals/partials/_projectcomments'); ?>
- \ No newline at end of file diff --git a/application/views/partials/_js.php b/application/views/partials/_js.php index 7d9300e..1ca6652 100644 --- a/application/views/partials/_js.php +++ b/application/views/partials/_js.php @@ -92,4 +92,5 @@ + \ No newline at end of file diff --git a/public/css/main.css b/public/css/main.css index f3b4b71..197214a 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -48,6 +48,10 @@ background-color: #0099B8; color: #fff !important; } +.table-cyanish-header-light { + background-color: #54CDE3; + color: #fff !important; +} .table-indigoish-header { background-color: #4D64FA; diff --git a/public/js/lib/dataservices/vatDataService.js b/public/js/lib/dataservices/vatDataService.js new file mode 100644 index 0000000..8a6a54b --- /dev/null +++ b/public/js/lib/dataservices/vatDataService.js @@ -0,0 +1,18 @@ +/** + * Created by Pensare Software. + * User: Theo Weijmer + * Date: 23/01/2018 + * Time: 19:33 + */ + +dbo.vatDataService = { + + getVats: function ( archive = 'F', callback ) { + $.getJSON( 'index.php/beheer/vatController/getVats/' + archive ) + .done( function ( data ) { + callback( data ); + } ); + } +} + + diff --git a/public/js/lib/helpers.js b/public/js/lib/helpers.js index d435e2c..133cadc 100644 --- a/public/js/lib/helpers.js +++ b/public/js/lib/helpers.js @@ -36,7 +36,7 @@ dbo.helpers = { } } - pointedString = dbo.helpers.reverseString( pointedString ); + pointedString = dbo.helpers.reverseString( pointedString ); return pointedString; }, @@ -51,17 +51,29 @@ dbo.helpers = { return valid; }, + findArrayElement: function ( toFind, element, value, array ) { + console.log( array ); + if ( !Array.isArray( array ) ) return null; +console.log( value ); + var foundValue = null + $.each( array, function ( i, p ) { + if ( p[toFind] == value ) foundValue = p[element]; + } ); +console.log( foundValue ); + return foundValue; + }, + reverseString: function ( string = '' ) { string = string.toString(); if ( string.length == 0 ) return ''; return string.split( '' ).reverse().join( '' ); }, - mysql2date : function(date){ - if( ! date ) return null; - if( date.length != 10 ) return null; + mysql2date: function ( date ) { + if ( !date ) return null; + if ( date.length != 10 ) return null; - var dateParts = date.split("-"); + var dateParts = date.split( "-" ); var newDate = dateParts[2] + '-' + dateParts[1] + '-' + dateParts[0]; diff --git a/public/js/lib/modals/projectModal.js b/public/js/lib/modals/projectModal.js index 1ff3adb..0b22dac 100644 --- a/public/js/lib/modals/projectModal.js +++ b/public/js/lib/modals/projectModal.js @@ -13,12 +13,15 @@ $( function () { projectEmployees: ko.observableArray( [] ), customers : ko.observableArray( [] ), users : ko.observableArray( [] ), - payments : ko.observableArray( [] ), + invoices : ko.observableArray( [] ), projecthours : ko.observableArray( [] ), offerFiles : ko.observableArray( [] ), offerComments : ko.observableArray( [] ), projectFiles : ko.observableArray( [] ), projectComments : ko.observableArray( [] ), + externals : ko.observableArray( [] ), + projectcosts : ko.observableArray( [] ), + vats : ko.observableArray( [] ), showProject : ko.observable( false ), projectID : null, callback : null, @@ -36,11 +39,31 @@ $( function () { vm.customers( data ); dbo.userDataService.getAllUsers( 'F', function ( data ) { vm.users( data ); - vm.refreshProject(); + dbo.externalDataService.getAllExternals( 'F', function ( data ) { + dbo.vatDataService.getVats( 'F', function ( data ) { + vm.vats( data ) + vm.refreshProject(); + } ); + } ); } ); } ); }, + togglePayments: function () { + this.showPayment( !this.showPayment() ); + + var showPayments = sessionStorage.showPayments || []; + + if ( this.showPayment() ) { + showPayments.push( this.id ); + } else { + var index = showPayments.indexOf( this.id ); + showPayments.splice( index, 1 ); + } + + sessionStorage.setItem( "showPayment", showPayments ); + }, + editProjectemployee: function () { var self = this; var vm = dbo.editProjectModal; @@ -85,6 +108,25 @@ $( function () { service.newOffer( vm.projectID, vm.customerID() ); }, + newInvoice: function () { + var vm = dbo.editProjectModal; + + var invoice = { + id : 0, + project_id : vm.projectID, + invoicenumber : '', + invoicedate : null, + invoiceamount : 0, + forecastamount: 0, + forecastdate : null, + inEdit : true, + showPayments : false, + payments : [] + } + + vm.invoices.push( new vm.Invoice( invoice ) ); + }, + newPayment: function () { var vm = dbo.editProjectModal; @@ -113,6 +155,21 @@ $( function () { vm.projecthours.push( new vm.Projecthour( projecthour ) ); }, + newProjectcost: function () { + var vm = dbo.editProjectModal; + + var projectcost = { + id : 0, + external_id: null, + description: '', + date : null, + costs : 0, + inEdit : true + }; + + vm.projectcosts.push( new vm.Projectcost( projectcost ) ); + }, + editOffer: function () { var service = dbo.offersService; service.vm = dbo.editProjectModal; @@ -406,14 +463,19 @@ $( function () { } ); } ); + vm.projectcosts.removeAll(); + $.each( data.projectcosts, function ( i, p ) { + vm.projectcosts.push( new vm.Projectcost( p ) ); + } ); + vm.offers.removeAll(); - vm.payments.removeAll(); $.each( data.offers, function ( i, p ) { vm.offers.push( new dbo.offersService.Offer( p ) ); + } ); - $.each( p.payments, function ( z, q ) { - vm.payments.push( new vm.Payment( q, p ) ); - } ); + vm.invoices.removeAll(); + $.each( data.invoices, function ( i, p ) { + vm.invoices.push( new vm.Invoice( p ) ); } ); vm.busy = false; @@ -432,18 +494,6 @@ $( function () { self.inEdit = ko.observable( sessionStorage.editEmployee == data.id ); }, - Payment: function ( data, offer = false ) { - var inEdit = sessionStorage.editPayment == data.id; - if ( !inEdit ) inEdit = data.inEdit || false; - - this.id = data.id; - this.offer_id = ko.observable( data.offer_id ); - this.offernumber = ko.observable( offer ? offer.offernumber : null ); - this.paymentdate = ko.observable( dbo.helpers.mysql2date( data.paymentdate ) ); - this.paymentamount = ko.observable( data.paymentamount ); - this.inEdit = ko.observable( inEdit ); - }, - Projecthour: function ( data, fullname ) { var inEdit = sessionStorage.editPayment == data.id; if ( !inEdit ) inEdit = data.inEdit || false; @@ -454,6 +504,58 @@ $( function () { this.hourdate = ko.observable( dbo.helpers.mysql2date( data.hourdate ) ); this.hours = ko.observable( data.hours ); this.inEdit = ko.observable( inEdit ); + }, + + Projectcost: function ( data ) { + this.id = data.id; + this.external_id = ko.observable( data.external_id ); + this.contactperson = ko.observable( data.external ? data.external.contactperson : '' ); + this.description = ko.observable( data.description ); + this.date = ko.observable( dbo.helpers.mysql2date( data.date ) ); + this.costs = ko.observable( data.costs ); + this.inEdit = ko.observable( data.inEdit || false ); + }, + + Invoice: function ( data ) { + var vm = dbo.editProjectModal; + var self = this; + var inEdit = sessionStorage.editInvoice == data.id; + if ( !inEdit ) inEdit = data.inEdit || false; + + self.id = data.id; + self.project_id = ko.observable( data.project_id ); + self.invoicenumber = ko.observable( data.invoicenumber ); + self.invoicedate = ko.observable( dbo.helpers.mysql2date( data.invoicedate ) ); + self.invoiceamount = ko.observable( data.invoiceamount.toFixed(2) ); + self.forecastamount = ko.observable( data.forecastamount.toFixed(2) ); + self.forecastdate = ko.observable( dbo.helpers.mysql2date( data.forecastdate ) ); + self.vat_id = ko.observable( data.vat_id ); + + self.inEdit = ko.observable( inEdit ); + self.showPayments = ko.observable( data.showPayments || false ); + + self.inclBtw = ko.pureComputed(function(){ + if( ! self.vat_id() ) return self.invoiceamount(); + + return (Number(self.invoiceamount()) + (self.invoiceamount() * + (dbo.helpers.findArrayElement('id', 'vatrate', self.vat_id(), this.vats()) /100))).toFixed(2); + }, dbo.editProjectModal) + + self.payments = ko.observableArray( [] ); + $.each( data.payments, function ( i, p ) { + self.payments.push( new vm.Payment( p, self.invoicenumber ) ); + } ); + }, + + Payment: function ( data, invoicenumber = '' ) { + var inEdit = sessionStorage.editPayment == data.id; + if ( !inEdit ) inEdit = data.inEdit || false; + + this.id = data.id; + this.invoicenumber = ko.observable( invoicenumber ); + this.paymentdate = ko.observable( dbo.helpers.mysql2date( data.paymentdate ) ); + this.paymentamount = ko.observable( data.paymentamount ); + this.inEdit = ko.observable( inEdit ); } };