Joomla Component Builder

It is a component generation tool for Joomla developed by Llewellyn van der Merwe.

It allows without almost writing a line of code to generate the file tree and component code for administration and site.

The tool can be downloaded from JED Joomla or directly from its github website  pkg-component-builder/releases

A nice presentation is available on the Jooma Magazine tools-to-build-a-component-7-joomla-component-builder

I also followed the presentation This makes it possible to create a simple component of the hello type.

YouTube

 

 

The subject

It is a question of creating a component that will allow to calculate its taxes according to the income and its number of shares.

The calculation is made according to the tax brackets of the year in question and a coefficient to be applied for each bracket.

We will be satisfied with a simple calculation by deducting donations to associations and investments of the "PER" type.

Modelling

the data used for the component shall be modelled.To start using "Component Builder"

In our case, this will be the calculation data, i.e. the tax brackets and coefficients to be applied for a fiscal year.


With regard to income data, use will be made of net tax income, the method of deduction of expenses (10% or real) the number of shares, donations to associations and the investment on the ELP. Let's Baptize Our Component

com_jtax

To do the modeling, I use the tool   PlantUML

The 2 "classes" will be mapped to 2 tables in the database

Joomla``

#__jtax_impot`and `

#__jtax_annee and a row from the data table We will create a link between each row of the table "tax"

"year"

 

 

 Creating the component in component builder

 

Go to the administrator interface under Components/Component Builder/Joomla Components

Click on New

For my part I just filled in the fields for "System Name" and "Short Description" and "Company Name" "Author" "Author Email" "Author Website"

 

 Creating fields associated with the component

 for each row and each table reflecting the modelling.We create a field ("Field") with the name "Income" to indicate the min and max of all fields of this typeI created a field type ("Fieldtype")

 Name
Type tranche1 to tranche4
Income coef1 to coef4
FLOAT income
Income deduction
Income name
STRING nbparts
FLOAT PEL

Income

 

Example for the PEL field is given for type Income

 

 

The format is specified in the database

 

For the number of shares field I set a step to 0.5 to have the half shares

 

 Creating administrator views associated with the component

 which determine the association between field lists and database tables, and the creation of associated controllers/modelsThese are the views (

admin views

The association is made through the "Linked Fields", taken in relation to the previously created "Fields".

  • For my part 2 views:

the Year view, (Year in configuration) associated with the 2 Years views (for the item list) and Year for each item

Tax - read/write List View:
Edit View: tax

impots

 

Linked Fields (Taxation)FieldAdmin BehaviourOrder in list viewstab
Order in Edit Name (Key - Required) [name - text] Show in All List Views 1 Details
1 Tranche 1 [tranche1 - income] Default 0 Details
2 Tranche 2 [tranche2 - income] Default 0 Details
3 Tranche 3 [tranche3 - income] Default 0 Details
4 Tranche 4 [tranche4 - income] Default 0 Details
5 Rate tranche 1 [rate1 - rate] Default 0 Details
6 Rate tranche 2 [rate2 - rate] Default 0 Details
7 Rate tranche 3 [rate3 - rate] Default 0 Details
8 Rate tranche 4 [rate4 - rate] Default 0 Details

9

the tax view, associated with the two tax views (for the list of items) and tax for each item

Year - read/write List View:
Edit View: year

years

 

Linked Fields (Annee)FieldAdmin BehaviourOrder in list viewstab
Order in Edit Name (not-required) [name - text] Show in All List Views 1 Details
0 Year [year - sql] Show in All List Views 2 Details
1 Income [income - income] Show in All List Views 3 Details
2 Number of shares [nbparts - integer] Show in All List Views 4 Details
3 Deduction [deduction - radio] Show in All List Views 5 Details
4 ELP [pel - income] Default 0 Details
6 Donations [donations - income] Default 0 Details

7

 

Classes generated by Component Builder

 Link views to component

 

This is to be done in the editing of the component

I checked the boxes to add the links to the "dashboard" and the menu

 Compile component

 

This generates an installable package with all associated sources

Go to the Component Builder/Compile Menu

 

Install component

click on the "Install com_jtax xxx" button

 Test the dashboard

 

We get the following "dashboard":

And if we click on

year add And if we click on

Tax add

 

 Add a button to the admin view

 

Go to admin view/Custom Buttons tab

The php code will be added to the associated controller.

 

 Testing the Calculate button

 

 

 

 Managing views for the site

 

We must first create the "Dynamic Get"

Adding Dynamic Gets

For my part I added 2 for the list of taxes and one for the display of the tax

For the list I selected the type getListQuery.la table Tax

) The main interest is to be able to filter unpublished models (tab

"Tweak"

 

For the list I added a join to retrieve the name of the year in question ("year_name") at the model level

 

For the items "Tax" I selected the type getItem

 

 

 

Added Site View for Tax Lists

 

 

Added a specific code for the Site List view

<?php $edit = "index.php?option=com_jtax&amp;view=impots&amp;task=impot.edit";?>
<table class="table table-striped">
<?php foreach ($this->items as $i => $item): ?>
  <?php
   $canCheckin = $this->user->authorise(&#039;core.manage&#039;, &#039;com_checkin&#039;) || $item->checked_out == $this->user->id || $item->checked_out == 0;
    $userChkOut = Factory::getContainer()->
      get(\Joomla\CMS\User\UserFactoryInterface::class)->
        loadUserById($item->checked_out ?? 0);
    $canDo = JtaxHelper::getActions(&#039;impot&#039;,$item,&#039;impots&#039;);
  ?>
  <tr class="row<?php echo $i % 2; ?>">
         <td class="hidden-phone">
      <a href="<?php echo $edit; ?>&amp;id=<?php echo $item->id; ?>"><?php echo $this->escape($item->name); ?></a>
    </td>
    <td class="hidden-phone">
      <?php echo $this->escape($item->year_name); ?>
    </td>    
  </tr>
<?php endforeach; ?>
</table>
<div style="display:none;">
<?php echo LayoutHelper::render(&#039;input&#039;, []); ?>
</div>

The added code is this (Add/edit Custom code)

 

 

Adding the Site view associated with the admin view

 

To be declared in the admin view

 Classes generated by the site part