Problems, need help? Have a tip or advice? Post it here.
14 posts Page 1 of 2
Hi all,

I have the following thing…

I have an invoicing app and the workflow for my invoices are quote -- invoiced -- paid. Well my invoices need a unique number and I started to use a UID field (viewtopic.php?f=8&t=11372&p=30049#p30049) in my invoices template for that.

Code: Select all
<cms:editable 
    type='uid'
    name='invoice_number'
    label='Invoice Number'
    desc='will be generated automatically'
    search_type='integer'
    begin_from='1'
    min_length='7'
    prefix='In-'
    suffix='-[DD][MM][YYYY]'
    />


I basically have folder for the stage of the invoice so unpaid invoices are in the folder invoiced and paid are in the folder paid and so on.
Now most invoices start with a quote but it should not have that uid … because invoices should be in a running number e.g 1,2,3 .. some quotes never become a real invoice so they should not have that uid otherwise the required running numbers of the invoices aren't there . Normally I use a separate field for that but i like to know if its possible to use the uid feature.. So is it possible to generate the uid only if the invoice page are getting moved to the invoiced folder?
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Hi,

Am I right in understanding then that "quote -- invoiced -- paid" are folders and a new page begins life with its folder set to 'quote' and then later folder of the same page is changed to 'invoiced' to convert it into an invoice?

Please confirm.
Thanks.
Hi,

quote -- invoiced -- paid, are folders yes. No not all start as a quote sometimes it's direct an invoice.
The problem is according to accounting rules the invoice numbers as to be in an ordered running sequence so 1,2,3 not 1,3,2 or 1,nothing,3.

For now I use this to set the number sequence

Code: Select all
<!-- set invoicenumber -->
<cms:pages folder='Invoiced' include_subfolders='1' masterpage='sales.php' limit='1' orderby='invoice_number'>
<cms:if invoice_number >
<cms:set lastno="<cms:show invoice_number/>"/>
<cms:set new_invoice_no="<cms:add lastno '1' />" 'global'/>
<cms:else />
<cms:set new_invoice_no='1' 'global'/>
</cms:if>
</cms:pages>
<!-- end set invoicenumber -->


I hoped a little to get it done on a neater way with an UID field
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
This seems to be a perfect case for the 'Conditional Fields' feature introduced with v2.2 (viewtopic.php?f=5&t=11512).

We can make the 'uid' field conditional to the folders in a way that it gets activated only when the 'invoice' folder is selected.

If the solution interests you, you'll need to download the 'uid' addon again (from viewtopic.php?f=8&t=11372&p=30049#p30049) as it has been modified to work with Couch v2.2.

With that in place, amend your template to make the uid field's definition as follows -
Code: Select all
<cms:func _into='my_cond' k_page_folder_id='' _no_js='1'>
    <cms:set invoice_folder_id = '' />
    <cms:folders root='invoiced' depth='1'>
        <cms:set invoice_folder_id = k_folder_id scope='parent' />
    </cms:folders>
   
    <cms:if k_page_folder_id eq invoice_folder_id >show<cms:else />hide</cms:if>
</cms:func>


<cms:editable
    type='uid'
    name='invoice_number'
    label='Invoice Number'
    desc='will be generated automatically'
    search_type='integer'
    begin_from='1'
    min_length='7'
    prefix='In-'
    suffix='-[DD][MM][YYYY]'
    not_active=my_cond
/>

A little explanation about the code above -
by adding the 'no_active' parameter, we have made the 'uid' field dependent upon a function named 'my_cond'.

The 'my_cond' field has the '_no_js' parameter set to 1 because we do not want it to auto-generate JS for us (it will fail because the generated JS works only for type checkbox, dropdown or radio custom editable regions - the folder dropdown is not one - and also because we are using arbitrary Couch tags within the function).

The 'my_cond' function has a parameter named 'k_page_folder_id' which is the name of the 'folders' dropdown so when Couch calls this function (while saving the page) to ask whether or not the uid field is active, it also passes to it the current value (ID of the selected folder) in the folders field.

The function checks the selected folder's ID with the ID of the 'invoiced' folder (using <cms:folders> to get this value) and if the two match, allows the uid field to become active.

In the code above I have used a value of 'invoiced' for the folder we are interested in - if is different on your system, please correct it,

Hope this helps. Do let me know.
Hi KK,

Thanks, I'm testing it now ... It seems to work!


Thanks again for the great support!
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Hi KK,

Nope doesn't seem to work this only hides the UID number but still generates it ... (or I must have done something wrong)

When I make quote and save it in the quotes folder it still gets a number.... it only doesn't show it, that's all..

So if I take the last generated number from my invoices and that number is 17 and I save a quote it gets the number 18 (only hidden this time), when I after that save a new invoice it gets the number 19 (and not 18). This results in a faulty numbering of my invoices e.g. number 17 is followed by number 19 and not 18 because that number is allocated to the quote with that number( and that one maybe never becomes an invoice) . By accounting rules this is not allowed
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Are you sure you took notice of the following? -
If the solution interests you, you'll need to download the 'uid' addon again (from viewtopic.php?f=8&t=11372&p=30049#p30049) as it has been modified to work with Couch v2.2.
Yep I did ....
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
That is strange.. I double checked it on my setup and it is working exactly as expected (in any other state other than 'invoice', the uid field remains completely inactive so no question of it generating a new number).

I can only say that please double check that you are indeed using Couch v2.2 and the latest version of uid.

If you wish, get me FTP+Couch access to your setup and I can take a look.
Hi KK,

Found it my mistake I have folder structure like this

- Invoiced
-- Closed Invoices
-- Open Invoices
- Quotes

My conversion from quotes to invoices can be directly to Closed Invoices and to Open Invoices depending on payment conditions, this messed it up a bit .... sorry !
I removed the "depth='1'" , plus I removed all the previous made quotes .... it seems to work now!

Thanks again
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
14 posts Page 1 of 2