Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hello everyone,

I am trying to create a "invoice" section with Couch.

I have set a mosaic with 2 tiles.
One being linked to some products in another page, and the other being to insert custom products with custom name, pricing and description.

I managed to make the calculation between all the fields to get the total of the invoice, with Javascript.
But I need to store the total amount in a couch variable to use it else where.

Here's the code I have right now for the operations :

Code: Select all
<cms:capture into='operation_1' scope='global'>
    <cms:show_mosaic 'invoice_content'>
    <cms:if k_tile_name='invoice_items' >
        <cms:related_pages 'invoice_product' >
        <cms:mul product_pricing invoice_item_qty />+
        </cms:related_pages>
    </cms:if>
</cms:show_mosaic>
</cms:capture>

<cms:capture into='operation_2' scope='global'>
<cms:show_mosaic 'invoice_content'>
    <cms:if k_tile_name='invoice_items_custom' >
        <cms:mul invoice_item_pricing_custom invoice_item_qty_custom />+
    </cms:if>
</cms:show_mosaic>
</cms:capture>


Which outputs :
Code: Select all
50+ 55.25+1000+ 500+

In my example. The plus signs are because I have added a "+" symbol avec each oprations in the captured variable, as you can see up there.

The code to ouput that line is :
Code: Select all
<cms:show operation_1/><cms:show operation_2/>


Since there's multiple tiles in the same mosaic, I can't just do :
Code: Select all
<cms:set total="<cms:add operation_1 operation_2/>"/>

This would output "1050".
Because it only takes the first iteration of each tiles.

How can I make this work so that it ouputs the real total, which would be "1605.25", and store it in a couch variable?

I have worked on this for hours and can't figure it out.
Thanks a lot!
Not sure if I got it right but, I think, you can just keep a running total as you iterate through the tiles.
Example code -
Code: Select all
<cms:set my_total='0' />

<cms:show_mosaic 'invoice_content'>
    <cms:if k_tile_name='invoice_items' >
        <cms:related_pages 'invoice_product' >
            <cms:incr my_total "<cms:mul product_pricing invoice_item_qty />" />
        </cms:related_pages>
    </cms:if>
   
    <cms:if k_tile_name='invoice_items_custom' >
        <cms:incr my_total "<cms:mul invoice_item_pricing_custom invoice_item_qty_custom />" />
    </cms:if>
</cms:show_mosaic>

<cms:show my_total />

Would that help?
That's perfect! Thanks a lot KK
Haven't thought of using "cms:incr" and a variable set to 0.

Thanks again
Je vous en prie :)
4 posts Page 1 of 1

Who is online

In total there are 13 users online :: 0 registered, 0 hidden and 13 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 13 guests