Redirect to New Invoice after Create Customer

I’d like to incorporate a redirect to “create new receipt” following the “create customer” page so instead of redirect to the Clients View, add a New Invoice for that Customer created on the database.

Has anyone implemented that already? Cheers

1 Like

I really like that idea.
Do me a favor and if you make a PR for it, can you make a setting for it as well?

I’ve found something that might help you:

$this->load->helper('redirect');
redirect('/invoices/url_invoices_create_for_customer');

Just so you know:

  • In V2 this will be improved (can’t do it in V1):
  • While creating invoice you type in customer
  • customer doesn’t exist, then you can get a little popup to quickly create that customer
  • and then you can continue with the invoice for the newly created customer

Saw there’s a bit more about it, could do just the redirect on line 104 from application/modules/clients/controllers/Clients.php to redirect to the customer created:

redirect('clients/view/' . $id);

But knowing that client $id now, might be worth it to trigger the script on the background:

// Creates the invoice
        $('#invoice_create_confirm').click(function () {
            // Posts the data to validate and create the invoice;
            // will create the new client if necessary
            $.post("<?php echo site_url('invoices/ajax/create'); ?>", {
                    client_id: $id.val(),
                    invoice_date_created: $('#invoice_date_created').val(),
                    invoice_group_id: $('#invoice_group_id').val(),
                    invoice_time_created: '<?php echo date('H:i:s') ?>',
                    invoice_password: $('#invoice_password').val(),
                    user_id: '<?php echo $this->session->userdata('user_id'); ?>',
                    payment_method: $('#payment_method_id').val()
                },

I will just have to look at the rest of the values.

                function (data) {
                    <?php echo(IP_DEBUG ? 'console.log(data);' : ''); ?>
                    var response = JSON.parse(data);
                    if (response.success === 1) {
                        // The validation was successful and invoice was created
                        window.location = "<?php echo site_url('invoices/view'); ?>/" + response.invoice_id;
                    }
                    else {
                        // The validation was not successful
                        $('.control-group').removeClass('has-error');
                        for (var key in response.validation_errors) {
                            $('#' + key).parent().parent().addClass('has-error');
                        }
                    }
                });
        });
1 Like

How I solved this:

FILE application/modules/layout/views/includes/head.php
FIND

$(document).on('click', '.client-create-invoice', function () {
            var client_id = $(this).data('client-id');
            $('#modal-placeholder').load("<?php echo site_url('invoices/ajax/modal_create_invoice'); ?>", {client_id: client_id});
        });

AFTER THAT, ADD

<?php if($_SERVER['HTTP_REFERER'] == site_url('clients/form')) { ?>           
			$(document).ready(function(){
				 $(".client-create-invoice").trigger('click');				 
			});					
        <?php } ?>

So everytime you’re redirected from “Customer Create” Page will open the modal to create a receipt for the recently created customer based on ID.

1 Like

In version 2 of InvoicePlane, would you want the same functionality there as well? Then i’ll add that to the list

1 Like

Well for me it’s easier like this, as most of the time when I create a customer I have to invoice them and just to automatize the process to save time and efforts.

1 Like

Understood man.
I hope you’ll like the solution in V2 the n where you can add your client fro. The “Invoice Create” page.
Little plus sign that quickly adds your client and then yo can add your invoice for the client that you just created