News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Billing documents (invoice & receipt) numbering

Started by its4yougr, July 19, 2017, 09:05:40 AM

Previous topic - Next topic

its4yougr

Hi
   I have an installation here (myteachers.gr) with VM 3.0.18, Joomla 3.6.5, One Page Checkout for Virtuemart from vmonepage.com & PHP 5.6.31, where I have done some modifications on the orders using template overrides and changes on some views (as far as I can remember).

The way it works is as follows: When a customer checks out he/she has to choose if he wants a receipt or an invoice. This is implemented using a shopper field. If the order is confirmed then from his orders list the customer can choose to print out the receipt or the invoice (which is a custom one) which has as receipt or invoice number the order number. To give you more info I posting the code that I have implemented in the list.php file inside the orders directory under my template so that you get an idea:

<?php
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select($db->quoteName(array('parastatiko','first_name','last_name','afm','virtuemart_order_id','address_type')));
            $query->from($db->quoteName('#__virtuemart_order_userinfos'));
            $query->where($db->quoteName('virtuemart_order_id') . ' = '. $db->quote($row->virtuemart_order_id).' AND '. $db->quoteName('address_type') . ' = '.'"BT"');
            $db->setQuery($query);
            $results = $db->loadObjectList();
            $item = $db->loadObject();
         ?>

The problem that I am facing with is that using the order number for invoice or receipt number is not correct. This number has to be increasing as follows:

Initially:
invoice_number = 0
receipt_number = 0

if
1st Order --> Invoice
invoice_number+1 (0+1=1)
invoice_number = 1

if
2nd Order --> Invoice
invoice_number+1 (1+1=2)
invoice_number = 2

if
3rd Order --> Receipt
receipt_number+1 (0+1=1)
receipt_number = 1

if
4th Order --> Receipt
receipt_number+1 (1+1=2)
receipt_number = 2

if
5th Order --> Receipt
receipt_number+1 (2+1=3)
receipt_number = 3

if
6th Order --> Invoice
invoice_number+1 (2+1=3)
invoice_number = 3

if 7th Order --> Receipt
receipt_number+1 (3+1=4)
receipt_number = 4

Therefore after the 7th Order :
invoice_number = 3
receipt_number = 4

Now these Invoice number and Receipt number can be implemented using DB fields (invoice_number & receipt_number) in the orders table so that when the order gets deleted then these will go to the previous number.....

The problem is that I am not a php programmer and I need help on doing what is described above. Is it possible that someone could help me?
Please let me know if you need access to the site.

Thank you in advance
BR
George
Κατασκευή Ιστοσελίδων Θεσσαλονίκη - http://www.its4you.gr/
WebDesign Internet Marketing - http://www.webdesign-internetmarketing.com/

K&K media production

You can't do this with an template override, you need a custom plugin to trigger order events.

A single counter for each customer?

Quotethat when the order gets deleted then these will go to the previous number.....

This can't work:

order 3 has invoice number 3, you delete order 3, next order will have also invoice number 3 -> in result your customer has 2 different orders with the same invoice number

its4yougr

Hi
Thank you very much for your reply ! !
QuoteYou can't do this with an template override, you need a custom plugin to trigger order events.

I have done this and the only problem that I have is the correct invoice / receipt number.


QuoteA single counter for each customer?

No a single counter for invoices and a single counter for receipts..... This is the idea.

Now when an order that had a receipt (for some reason) gets deleted then the next order that would again have a receipt should get the same receipt number. Same situation if there were not receipts involved just invoices.

Please see my example so that you understand better.

Do I need a different db table to keep track of the orders and their receipt / invoices numbers?

Thanks
George
Κατασκευή Ιστοσελίδων Θεσσαλονίκη - http://www.its4you.gr/
WebDesign Internet Marketing - http://www.webdesign-internetmarketing.com/

K&K media production

#3
QuoteNow when an order that had a receipt (for some reason) gets deleted then the next order that would again have a receipt should get the same receipt number. Same situation if there were not receipts involved just invoices.

You should talk with your tax consultant, this is not legally to generate multiple invoices with same invoice number.


What happens if you have 5 orders with invoice numbers 1-5 and you delete order 3? What will be the next number?

its4yougr

QuoteWhat happens if you have 5 orders with invoice numbers 1-5 and you delete order 3? What will be the next number?

Suppose  we have :
Order #1 with invoice #1
Order #2 with invoice #2
Order #3 with invoice #3
Order #4 with invoice #4
Order #5 with receipt #1
Order #6 with invoice #5
Order #7 with invoice #6
Order #8 with receipt #2
Order #9 with receipt #3
Order #10 with invoice #7
Order #11 with invoice #8
Order #12 with receipt #4

Now if Order #12 gets deleted and the next order is to have receipt it will get receipt #4 and if it's to get invoice it will get invoice #9. If some of the orders 1-11 gets deleted then nothing should change we will just have a deleted order. The next order will be number 13 with receipt #5 and / or invoice #9. Therefore we should keep track of the last order and manage the receipt / invoice # accordingly. Even though this is not finally necessary.... The easiest way is to continue numbering and just mark the deleted order as well as the invoice and / or receipt as canceled or something like that.

Thanks

I hope I make sense....

Thanks
Κατασκευή Ιστοσελίδων Θεσσαλονίκη - http://www.its4you.gr/
WebDesign Internet Marketing - http://www.webdesign-internetmarketing.com/

K&K media production

No, this makes no sense to generate invoices and receipts with same numbers for different orders. This numbers should be unique.

its4yougr

QuoteNo, this makes no sense to generate invoices and receipts with same numbers for different orders. This numbers should be unique.

The idea here (under Greek tax law) is to have a different serial numbering for invoices and receipts. That means that at some point there will be two orders which will have the same number for billing document but one will be an invoice and the other a receipt.

The way it works right now is to get the order number which is unique and in front of it to put the word invoice or receipt depending on the customer's choice. My client's accountant needs what I have described above.

Note: Invoices are for companies and receipts are for individuals

Thanks
Κατασκευή Ιστοσελίδων Θεσσαλονίκη - http://www.its4you.gr/
WebDesign Internet Marketing - http://www.webdesign-internetmarketing.com/

K&K media production

No you will have 2 or more orders with same invoice numbers!

Order 3 has invoice number 3 -> the company prints the invoice with this invoice number 3

You delete Order 3

The next order  will get also invoice number 3 -> the company prints his invoice and get also a invoice with numer 3

result: 2 different orders / companys with 2 different invoices with same invoice number

its4yougr

Yes U R right.....
Sorry I didn't think of it this way......
Therefore when an order gets deleted (might never happen) the invoices and / or receipts will keep getting the next number in their order....

Now the question is if this could be programmed into my installation..... Could you do it?

Thanks
George
Κατασκευή Ιστοσελίδων Θεσσαλονίκη - http://www.its4you.gr/
WebDesign Internet Marketing - http://www.webdesign-internetmarketing.com/

AH

Why not give everyone an invoice and use the order_id as the invoice number
Regards
A

Joomla 4.4.5
php 8.1

its4yougr

In Greece we have the option to get either a receipt (if the customer is an individual) or an invoice (for businesses).
On the invoice there are the VAT number, address, name etc information that an individual doesn't want to supply all the time.....

Yes you are right and this is how I have done it I used the order number for invoice or receipt but we need to have to series of numbers one for invoice and another for receipts....

The best scenario is to use another db table to keep track of the two series? What would be the code for updating the db table for the receipt or invoice numbers?

Is there any possibility that you could write the code for all of this?

Thanks
Κατασκευή Ιστοσελίδων Θεσσαλονίκη - http://www.its4you.gr/
WebDesign Internet Marketing - http://www.webdesign-internetmarketing.com/

K&K media production

As invoice number you can use the default invoice number of vm. A second number for your receipts may be the order id or order number.

If you need your own counters for both, use a simple custom sql table.


QuoteIs there any possibility that you could write the code for all of this?

Yes, but as commercial job.

its4yougr

QuoteAs invoice number you can use the default invoice number of vm. A second number for your receipts may be the order id or order number.
Yes U R right, virtuemart_order_id and virtuemart_invoice_id numbers could be found on __virtuemart_invoices table but how are these get incremented?
Don't forget that here we have the customer's choice for a receipt or invoice.....

I think that we will need a different simple custom sql table (as U proposed) where depending of the choice of the customer we will have a different incrementing number for invoices and a different one for receipts. Both should also be related to the virtuemart_order_id.

Do I need to PM you for a price quote for that?

Thanks
Κατασκευή Ιστοσελίδων Θεσσαλονίκη - http://www.its4you.gr/
WebDesign Internet Marketing - http://www.webdesign-internetmarketing.com/

AH

I think K&K might be able to help you with the commercial job



Regards
A

Joomla 4.4.5
php 8.1