Page 1 of 1

Job Costing. Adding Cost Centres and Stages

PostPosted: Wed Jan 25, 2017 10:59 am
by DannyC
Hi,

I want to tweak the Job Costing module so that when a Stage is added under a Cost Centre (by the way - is the only way to add a stage by dragging it over the cost centre?) I want to automatically set the Classification too. In this scenario, the naming of the Stage and Classification are matched so that I can choose the correct classification.

My problem is that I can't find the method under the JobCosting class where the Stage is added.
I can see JobCosting.CostCentres.Added but can't find the syntax to get to Stages.

Can you help?

Re: Job Costing. Adding Cost Centres and Stages  Topic is solved

PostPosted: Mon Jan 30, 2017 11:10 am
by Mike.Sheen
Hi Danny,

You just need to add a handler to each Cost Centre's stage collection - do this on when the job is read, and when a cost centre is added:

Code: Select all
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
   JobCostForm = JiwaForm
   AddHandler JobCostForm.Job.Read, AddressOf JobReadEnd
   AddHandler JobCostForm.Job.CostCentres.Added, AddressOf CostCentreAdded      
End Sub

Private Sub JobReadEnd()
   For Each costCentre As JiwaJobCosting.CostCentre In JobCostForm.Job.CostCentres
      AddHandler costCentre.Stages.Added, AddressOf StageAdded
   Next
End Sub

Private Sub CostCentreAdded(CostCentre As JiwaJobCosting.CostCentre)
   ' Add a handler for the stage added event
   AddHandler CostCentre.Stages.Added, AddressOf StageAdded
End Sub

Private Sub StageAdded(Stage As JiwaJobCosting.Stage)      
   JiwaApplication.Manager.DisplayMessage(JobCostForm, String.Format("Stage '{0}' was added to Cost Centre '{1}'", Stage.Stage.Name, Stage.Stages.CostCentre.CostCentre.Name), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information, System.Windows.Forms.MessageBoxDefaultButton.Button1)
End Sub


Attached is a sample plugin demonstrating this (in VB.NET which I assumed you would have preferred).

Re: Job Costing. Adding Cost Centres and Stages

PostPosted: Wed Feb 01, 2017 12:08 pm
by DannyC
Thats great Mike.
When looking at the Stages, the classification appears to be Read Only.
Is there a way I can set it on the fly when dragging it over to the left?

And yes - VB .Net is preferred. You know me too well!

Re: Job Costing. Adding Cost Centres and Stages

PostPosted: Thu Feb 02, 2017 5:21 pm
by Mike.Sheen
DannyC wrote:When looking at the Stages, the classification appears to be Read Only.
Is there a way I can set it on the fly when dragging it over to the left?


It's read only because it's an object - it's an Entity, so something like:

Code: Select all
Stage.Classification.ReadRecordFromName("Test")


should set the classification for the stage.