ASTPP invoices template problem

By Yevgeniya Suminova on 2021-04-10
Updated by Yevgeniya Suminova on 2021-04-14

Contents

Problem.. 1

Problem solved. 1

Locations of files and codes. 1

Trying to overcome. 1

Changing template.php file. 1

Result. 1

End. 1

 

 

Problem

The company and Customer’s personal data are not displayed correctly on the invoices:

 

Problem solved

Below are new updated files that correct the template of invoices.

Path no.1:

/opt/ASTPP/web_interface/astpp/application/modules/invoices/views/view_invoice_template.php

view_invoice_template.php

Path no.2:

/opt/ASTPP/web_interface/astpp/application/modules/invoices/controllers/invoices.php

invoices.php

The original files OR their content must be replaced on the ASTPP server by the files that are provided above. The names of the files must remain same.

 

Locations of files and codes

We have found the location of the invoices template:

/opt/ASTPP/web_interface/astpp/application/modules/invoices/views/view_invoice_template.php

 

In the content we see the following part that is interesting for us:

<table class="table py-2">

        <tbody>

                <tr>

                        <td style="width: 50%; text-align: left">

                                <address>

                                        <br>

                        <?php echo $cmp_name;?>,<br>

                            <?php echo $cmp_address;?>,<br>

                            <?php echo $cmp_city_zipcode;?><br>

                            <?php echo $cmp_province_country;?><br>

                     <?php echo gettext('Phone').":"; ?> <?php echo $cmp_telephone;?><br>

                            <?php echo $cmp_tax;?><br>

                                </address>

                        </td>

 

                        <td style="width: 50%; text-align: right">

                                <address>

                                        <b><?php echo gettext('Bill To').":"; ?></b><br>

                            <?php echo $fullname;?><br>

                            <?php

                            if (isset($address_1) && trim($address_1) != '') {

                                echo ucfirst($address_1);

                            }

                            ?>

                            <?php

                            if (isset($address_2) && trim($address_2) != '') {

                                if(isset($address_1) && trim($address_1) != ''){

                                        echo ",<br>";

                                }

                                echo ucfirst($address_2);

                            }

                            ?>

                            <?php

                            if (isset($city_postalcode) && $city_postalcode != '') {

                                if(isset($address_2) && trim($address_2) != ''){

                                        echo ",<br>";

                                }

                                echo ucfirst($city_postalcode);

                            }

 

In the line marked yellow we see that the line in question has a variable “$cmp_province_country”

Now we need to understand where is the command that says which data must be stored in this variable. It is not in the same file.

We found the file “invoices.php” in “controllers” directory. Here is the path:

/opt/ASTPP/web_interface/astpp/application/modules/invoices/controllers/invoices.php

 

In the content of the file, we found the line that interests us (marked yellow). These lines make a part of the function:

function invoice_download($invoiceid)

 

 

                $data['cmp_name'] = $company_data->company_name;

                $data['cmp_address'] = $company_data->address;

                $data['cmp_city_zipcode'] = $company_data->city . ' - ' . $company_data->zipcode;

                $data['cmp_province_country'] = $company_data->province . ' , ' . $company_data->country;

                $data['cmp_telephone'] = $company_data->telephone;

                $data['cmp_tax'] = $company_data->invoice_taxes_number;

                $data['cmp_invoice_note'] = $company_data->invoice_note;

                $data['invoice_date'] = $invoicedata->generate_date;

                $data['invoice_due_date'] = $invoicedata->due_date;

                $data['account_number'] = $accountsdata->number;

                $data['invoice_notes'] = $accountsdata->invoice_note;

                $data['logo'] = (! empty($company_data->logo)) ? $company_data->logo : 'logo.jpg';

 

We see that it corresponds to what we see in the invoice. (province + “,” + “country”) where instead of the country we see the number 185.

We also understand that the data is taken from the database. We now will check the database.

We see that in the db there is a table invoice_conf. This table has following columns:

+--------------------------+--------------+------+-----+--------------------+----------------+

| Field                    | Type         | Null | Key | Default            | Extra          |

+--------------------------+--------------+------+-----+--------------------+----------------+

| id                       | int          | NO   | PRI | NULL               | auto_increment |

| accountid                | int          | NO   |     | NULL               |                |

| company_name             | varchar(100) | NO   |     | NULL               |                |

| address                  | varchar(300) | NO   |     | NULL               |                |

| city                     | varchar(20)  | NO   |     | NULL               |                |

| province                 | varchar(20)  | NO   |     | NULL               |                |

| country                  | varchar(20)  | NO   |     | NULL               |                |

| zipcode                  | varchar(10)  | NO   |     | NULL               |                |

| telephone                | varchar(20)  | NO   |     | NULL               |                |

| fax                      | varchar(20)  | NO   |     | NULL               |                |

| emailaddress             | varchar(100) | NO   |     | NULL               |                |

| website                  | varchar(100) | NO   |     | NULL               |                |

| invoice_prefix           | varchar(11)  | NO   |     | INV_               |                |

| invoice_start_from       | int          | NO   |     | 1                  |                |

| logo                     | varchar(100) | NO   |     | NULL               |                |

| favicon                  | varchar(100) | NO   |     | NULL               |                |

| invoice_note             | text         | NO   |     | NULL               |                |

| invoice_due_notification | tinyint(1)   | NO   |     | 0                  |                |

| invoice_notification     | tinyint(1)   | NO   |     | 0                  |                |

| no_usage_invoice         | tinyint      | NO   |     | 0                  |                |

| interval                 | varchar(11)  | NO   |     | NULL               |                |

| notify_before_day        | int          | NO   |     | 1                  |                |

| invoice_taxes_number     | varchar(100) | NO   |     | ABN 12 345 678 901 |                |

| domain                   | varchar(100) | NO   |     | NULL               |                |

| website_title            | varchar(100) | NO   |     | NULL               |                |

| website_footer           | varchar(100) | NO   |     | NULL               |                |

| reseller_id              | int          | NO   |     | 0                  |                |

+--------------------------+--------------+------+-----+--------------------+----------------+

 

We will now check the output with the following command:

mysql> select company_name, address, city, province, country, zipcode, telephone from invoice_conf;

+--------------+-----------------+----------+----------+---------+---------+-----------------+

| company_name | address         | city     | province | country | zipcode | telephone       |

+--------------+-----------------+----------+----------+---------+---------+-----------------+

| 4z.com Sŕrl  | Case Postale 32 | Lausanne | Vaud     | 185     | CH-1015 |  +4122 550 5500 |

| 5196284617   |                 |          |          | 88      |         |                 |

+--------------+-----------------+----------+----------+---------+---------+-----------------+

 

So, the Country in this table is not entered fully, but just it’s id.

 

Trying to overcome

We will try to enter the country instead of province in our company’s profile. It is possible, but the “185” is of course not eliminated.
The other problem to understand is, why there are doubled entries under customer’s address:

In customer’s profile the data is entered as follows:

At closer look we understand that there are more problematic lines for us:

First, we will try to change positions of zipcode and the city:

nano /opt/ASTPP/web_interface/astpp/application/modules/invoices/controllers/invoices.php

 

                $data['cmp_name'] = $company_data->company_name;

                $data['cmp_address'] = $company_data->address;

                $data['cmp_city_zipcode'] = $company_data->zipcode . ' - ' . $company_data->city;

                $data['cmp_province_country'] = $company_data->province . ' , ' . $company_data->country;

                $data['cmp_telephone'] = $company_data->telephone;

                $data['cmp_tax'] = $company_data->invoice_taxes_number;

                $data['cmp_invoice_note'] = $company_data->invoice_note;

                $data['invoice_date'] = $invoicedata->generate_date;

                $data['invoice_due_date'] = $invoicedata->due_date;

                $data['account_number'] = $accountsdata->number;

                $data['invoice_notes'] = $accountsdata->invoice_note;

                $data['logo'] = (! empty($company_data->logo)) ? $company_data->logo : 'logo.jpg';

 

Here is the result:

As the downloading of the invoice is a programmed function, all previously generated invoices also change the information if we download them after modifying the code.

Now we will remove the $company_data->country from the next line.

Below is the result. It looks good.

Now we will take care of Customer’s side data.

before:

if ($invoicedata->accountid != '' && isset($invoicedata->accountid)) {

 

                $query = $this->db->get_where('accounts', array(

                    'id' => $invoicedata->accountid

                ));

                $accountsdata = $query->first_row();

 

                if ($accountsdata->company_name == '') {

                    $data['fullname'] = $accountsdata->first_name . ' ' . $accountsdata->last_name;

                } else {

                    $data['fullname'] = ucfirst($accountsdata->company_name);

                }

 

                $data['address_1'] = $accountsdata->address_1;

                $data['address_2'] = $accountsdata->address_2;

 

                if ($accountsdata->city != '' && $accountsdata->postal_code != '') {

                    $data['city_postalcode'] = $accountsdata->city . ' - ' . $accountsdata->postal_code;

                }

                if ($accountsdata->city == '' && $accountsdata->postal_code != '') {

                    $data['city_postalcode'] = $accountsdata->postal_code;

                }

                if ($accountsdata->city != '' && $accountsdata->postal_code == '') {

                    $data['city_postalcode'] = $accountsdata->city;

                }

 

 

after:

 

if ($invoicedata->accountid != '' && isset($invoicedata->accountid)) {

 

                $query = $this->db->get_where('accounts', array(

                    'id' => $invoicedata->accountid

                ));

                $accountsdata = $query->first_row();

 

                if ($accountsdata->company_name == '') {

                    $data['fullname'] = $accountsdata->first_name . ' ' . $accountsdata->last_name;

                } else {

                    $data['fullname'] = ucfirst($accountsdata->company_name);

                }

 

                $data['address_1'] = $accountsdata->address_1;

                $data['address_2'] = $accountsdata->address_2;

 

                if ($accountsdata->city != '' && $accountsdata->postal_code != '') {

                    $data['city_postalcode'] = $accountsdata->postal_code . '   ' . $accountsdata->city;

                }

                if ($accountsdata->city == '' && $accountsdata->postal_code != '') {

                    $data['city_postalcode'] = $accountsdata->postal_code;

                }

                if ($accountsdata->city != '' && $accountsdata->postal_code == '') {

                    $data['city_postalcode'] = $accountsdata->city;

                }

 

result:

Changing template.php file

before:

<table class="table py-2">

        <tbody>

                <tr>

                        <td style="width: 50%; text-align: left">

                                <address>

                                        <br>

                        <?php echo $cmp_name;?>,<br>

                            <?php echo $cmp_address;?>,<br>

                            <?php echo $cmp_city_zipcode;?><br>

                            <?php echo $cmp_province_country;?><br>

                     <?php echo gettext('Phone').":"; ?> <?php echo $cmp_telephone;?><br>

                            <?php echo $cmp_tax;?><br>

                                </address>

                        </td>

 

after:

<table class="table py-2">

        <tbody>

                <tr>

                        <td style="width: 50%; text-align: left">

                                <address>

                                        <br>

                        <?php echo $cmp_name;?><br>

                            <?php echo $cmp_address;?><br>

                            <?php echo $cmp_city_zipcode;?><br>

                            <?php echo $cmp_province_country;?><br>

                     <?php echo gettext('Phone').":"; ?> <?php echo $cmp_telephone;?><br>

                            <?php echo $cmp_tax;?><br>

                                </address>

                        </td>

 

 

before:

<td style="width: 50%; text-align: right">

                                <address>

                                        <b><?php echo gettext('Bill To').":"; ?></b><br>

                            <?php echo $fullname;?><br>

                            <?php

                            if (isset($address_1) && trim($address_1) != '') {

                                echo ucfirst($address_1);

                            }

                            ?>

                            <?php

                            if (isset($address_2) && trim($address_2) != '') {

                                if(isset($address_1) && trim($address_1) != ''){

                                        echo ",<br>";

                                }

                                echo ucfirst($address_2);

                            }

                            ?>

 

after:

<td style="width: 50%; text-align: right">

                                <address>

                                        <b><?php echo gettext('Bill To').":"; ?></b><br>

                            <?php echo $fullname;?><br>

                            <?php

                            if (isset($address_1) && trim($address_1) != '') {

                                echo ucfirst($address_1);

                            }

                            ?>

                            <?php

                            if (isset($address_2) && trim($address_2) != '') {

                                if(isset($address_1) && trim($address_1) != ''){

                                        echo ",<br>";

                                }

                                echo ucfirst($address_2);

                            }

                            ?><br>

 

Then we did many other changes that will be difficult to reflect here.

Result

Below are the new updated files that correct the template of invoices:

view_invoice_template.php

invoices.php

End

***

© 4z.com