Payments tab & table in client view

Hi all,

I wanted to display payments on the client view the same way quotes and invoices are displayed (see screen capture of tabs at http://i60.tinypic.com/m8pmwi.png) and to my surprise I found that few changes to the code sufficed to accomplish the task (see screen capture of full screen http://i57.tinypic.com/2ah8gvq.png).

The files to modify are:

  • ~InvoicePlane/application/modules/clients/controllers/clients.php
  • ~InvoicePlane/application/modules/clients/views/view.php
  • ~InvoicePlane/application/modules/payments/models/mdl_payments.php
  • ~InvoicePlane/application/modules/payments/views/partial_payment_table.php

and the changes are detailed in the next post.

Since I am not familiar enough with github, for now I prefer someone else to upload the code changes to the official repository.

Miquel

Note: changes applied to version 1.1.1

Changes to file ~InvoicePlane/application/modules/clients/controllers/clients.php:

--- ~current_InvoicePlane/application/modules/clients/controllers/clients.php
+++ ~new_InvoicePlane/application/modules/clients/controllers/clients.php
@@ -119,6 +119,7 @@
         $this->load->model('clients/mdl_client_notes');
         $this->load->model('invoices/mdl_invoices');
         $this->load->model('quotes/mdl_quotes');
+        $this->load->model('payments/mdl_payments');
         $this->load->model('custom_fields/mdl_custom_fields');
 
         $client = $this->mdl_clients->with_total()->with_total_balance()->with_total_paid()->where('ip_clients.client_id', $client_id)->get()->row();
@@ -134,6 +135,7 @@
                 'client_notes'     => $this->mdl_client_notes->where('client_id', $client_id)->get()->result(),
                 'invoices'         => $this->mdl_invoices->by_client($client_id)->limit(20)->get()->result(),
                 'quotes'           => $this->mdl_quotes->by_client($client_id)->limit(20)->get()->result(),
+                'payments'         => $this->mdl_payments->by_client($client_id)->limit(20)->get()->result(),
                 'custom_fields'    => $this->mdl_custom_fields->by_table('ip_client_custom')->get()->result(),
                 'quote_statuses'   => $this->mdl_quotes->statuses(),
                 'invoice_statuses' => $this->mdl_invoices->statuses(),
@@ -144,6 +146,7 @@
             array(
                 array('invoice_table', 'invoices/partial_invoice_table'),
                 array('quote_table', 'quotes/partial_quote_table'),
+                array('payment_table', 'payments/partial_payment_table'),
                 array('partial_notes', 'clients/partial_notes'),
                 array('content', 'clients/view')
             )

Changes to file ~InvoicePlane/application/modules/clients/views/view.php:

--- ~current_InvoicePlane/application/modules/clients/views/view.php
+++ ~new_InvoicePlane/application/modules/clients/views/view.php
@@ -48,9 +48,9 @@
             <i class="fa fa-file"></i> <?php echo lang('create_quote'); ?>
         </a>
         <a href="#" class="btn btn-sm btn-default client-create-invoice"
-            data-client-name="<?php echo $client->client_name; ?>">
-            <i class="fa fa-file-text""></i> <?php echo lang('create_invoice'); ?>
-        </a>
+           data-client-name="<?php echo $client->client_name; ?>">
+           <i class="fa fa-file-text""></i> <?php echo lang('create_invoice'); ?>
+        </a>
         <a href="<?php echo site_url('clients/form/' . $client->client_id); ?>"
            class="btn btn-sm btn-default">
             <i class="fa fa-edit"></i> <?php echo lang('edit'); ?>
@@ -187,6 +187,10 @@
             <?php echo $invoice_table; ?>
         </div>
 
+        <div id="clientPayments" class="tab-pane">
+            <?php echo $payment_table; ?>
+        </div>
+
     </div>
 
 </div>
@@ -198,6 +202,7 @@
             <li class="active"><a data-toggle="tab" href="#clientDetails"><?php echo lang('details'); ?></a></li>
             <li><a data-toggle="tab" href="#clientQuotes"><?php echo lang('quotes'); ?></a></li>
             <li><a data-toggle="tab" href="#clientInvoices"><?php echo lang('invoices'); ?></a></li>
+            <li><a data-toggle="tab" href="#clientPayments"><?php echo lang('payments'); ?></a></li>
         </ul>
     </div>
 </nav>

Changes to file ~InvoicePlane/application/modules/payments/models/mdl_payments.php:

--- ~current_InvoicePlane/application/modules/payments/models/mdl_payments.php
+++ ~current_InvoicePlane/application/modules/payments/models/mdl_payments.php
@@ -29,6 +29,7 @@
             ip_payment_methods.*,
             ip_invoice_amounts.*,
             ip_clients.client_name,
+            ip_clients.client_id,
             ip_invoices.invoice_number,
             ip_invoices.invoice_date_created,
             ip_payments.*", FALSE);
@@ -169,6 +170,12 @@
         return TRUE;
     }
 
+    public function by_client($client_id)
+    {
+        $this->filter_where('ip_clients.client_id', $client_id);
+        return $this;
+    }    
+    
 }
 
 ?>

Changes to file ~InvoicePlane/application/modules/payments/views/partial_payment_table.php

--- ~current_InvoicePlane/application/modules/payments/views/partial_payment_table.php
+++ ~new_InvoicePlane/application/modules/payments/views/partial_payment_table.php
@@ -20,7 +20,12 @@
                 <td><?php echo date_from_mysql($payment->payment_date); ?></td>
                 <td><?php echo date_from_mysql($payment->invoice_date_created); ?></td>
                 <td><?php echo anchor('invoices/view/' . $payment->invoice_id, $payment->invoice_number); ?></td>
-                <td><?php echo $payment->client_name; ?></td>
+                <td>
+                    <a href="<?php echo site_url('clients/view/' . $payment->client_id); ?>"
+                        title="<?php echo lang('view_client'); ?>">
+                    <?php echo $payment->client_name; ?>
+                    </a>
+                </td>
                 <td><?php echo format_currency($payment->payment_amount); ?></td>
                 <td><?php echo $payment->payment_method_name; ?></td>
                 <td><?php echo $payment->payment_note; ?></td>

Miquel

Thank you for your great contribution! I’ll add this tomorrow to the files for the next version.
:thumbsup:

Can you provide the changes as a patch file? Would make it easier for us to integrate it.

And Github is not that hard to use, just give it a try :wink: (assuming you didn’t mean git itself. But you should consider learning git. It will make your life much easier if something goes wrong)

ok, let me read something about GitHub for Dummies and I will try to enter the changes myself to the development branch… hopefully you will not have to revert them :smile:

Miquel

I’ll wait. Have some other things to do anyway so take your time. Release for v1.2.0 is planned for late January or something.

Yeah take your time :slight_smile: And you can’t break anything, you don’t have write access to the repo :wink: (to contribute something you have to “fork” (make a copy of) the repository, then apply your changes. Finally you submit a pull request where we can look at your changes and accept them or not)

There is also Try Git where you can learn git directly in the browser.

My first ever pull-request on GitHub! :smiley:

Thanks for the patience and the encouragement.

Miquel

:tada:
Congratulations!

See, isn’t that hard :slight_smile: :thumbsup: