Tax calculation on line item - Quote Sugar 7.9

Hello,

I have noticed currently quote calculation on Quote level. I can apply to calculation tax on quote line item level. Because I have different type categories and product, so each product apply different type of VAT.

I have attached below screen shot. 

1) First product line item apply "20% (Vat on Income)"

2) Second product line item apply "5% (Vat on Income)"

3) Third product line item apply "0% (No Vat)"

Thanks

Asif

Offshore Evolution

Francesca Shiekh André Lopes Ramana Raju Santhana Alex Nassi 

Parents
  • I needed line item tax as well, I called the field line_tax_amount_c. In my case this is not a percentage but an amount, I have an API which retrieves the correct amount based on tax tables on our ERP system and returns it to the Quote. 

    I add up the line item tax at ProductBundle level:

    custom/Extension/modules/ProductBundles/Ext/Vardefs/vardef.ext.php

    <?php
    $dictionary['ProductBundle']['fields']['tax_amount_c']['labelValue']='Tax Amount';
    $dictionary['ProductBundle']['fields']['tax_amount_c']['calculated']='true';
    $dictionary['ProductBundle']['fields']['tax_amount_c']['formula']='rollupCurrencySum($products, "line_tax_amount_c")';
    $dictionary['ProductBundle']['fields']['tax_amount_c']['enforced']='true';
    $dictionary['ProductBundle']['fields']['tax_amount_c']['dependency']='';
    $dictionary['ProductBundle']['fields']['tax_amount_c']['related_fields']=array (
      0 => 'currency_id',
      1 => 'base_rate',
    );

    Then I add the Tax to the Bundle Total:

    custom/Extension/modules/ProductBundles/Ext/Vardefs/sugarfield_total.php

    <?php
    $dictionary['ProductBundle']['fields']['total']['formula']='currencyAdd($new_sub, $tax_amount_c)';
    $dictionary['ProductBundle']['fields']['total']['related_fields']=array (
      0 => 'currency_id',
      1 => 'base_rate',
      2 => 'new_sub',
      3 => 'tax_amount_c',
    );
    $dictionary['ProductBundle']['fields']['total']['calculated']='true';
    $dictionary['ProductBundle']['fields']['total']['enforced']='true';

    I then add the bundle tax for the total Tax at Quote level:

    custom/Extension/modules/Quotes/Ext/Vardefs/sugarfield_tax_amount_c.php

    <?php
    // created: 2017-06-13 11:14:46
    $dictionary['Quote']['fields']['tax_amount_c']['duplicate_merge_dom_value']=0;
    $dictionary['Quote']['fields']['tax_amount_c']['labelValue']='Tax';
    $dictionary['Quote']['fields']['tax_amount_c']['calculated']='true';
    $dictionary['Quote']['fields']['tax_amount_c']['formula']='rollupCurrencySum($product_bundles,"tax_amount_c")';
    $dictionary['Quote']['fields']['tax_amount_c']['enforced']='true';
    $dictionary['Quote']['fields']['tax_amount_c']['dependency']='';
    $dictionary['Quote']['fields']['tax_amount_c']['related_fields']=array (
      0 => 'currency_id',
      1 => 'base_rate',
    );

    The Quote total includes all the tax as it is because it's just a rollup total of the individual bundle totals, which include the line item tax per the customization above.

    HTH

    FrancescaS

  • Offshore Evolution, could you please share the code you used for creating the dropdown on the line?

    Is it an enum? Or a relate field to the TaxRates class? I've been trying relate fields, enums, as well as attempting to mimic the product template lookup, but I'm struggling to get this to work as you've done, and I have the exact same requirement. If you had the code to hand, I'd really appreciate a point in the right direction.

  • Hi Offshore Evolution,

    Its not that difficult as you think. All we need to do is to place it in the right file.Francesca Shiekh comment above is exactly how u need to do it. But one additional config.

    CUSTOM FIELD

    custom/Extension/modules/Products/Ext/Vardefs/sugarfield_line_tax_amount_c.php

    $dictionary['Product']['fields']['line_tax_amount_c']['duplicate_merge_dom_value']=0;
    $dictionary['Product']['fields']['line_tax_amount_c']['labelValue']='Tax Amount';
    $dictionary['Product']['fields']['line_tax_amount_c']['calculated']='true';
    $dictionary['Product']['fields']['line_tax_amount_c']['formula']='multiply($total_amount,divide($line_tax_percent_c,100))';
    $dictionary['Product']['fields']['line_tax_amount_c']['enforced']='true';
    $dictionary['Product']['fields']['line_tax_amount_c']['dependency']='';
    $dictionary['Product']['fields']['line_tax_amount_c']['related_fields']=array (
      0 => 'currency_id',
      1 => 'base_rate',
    );

    and in quote-data-group-list.php

                   array(
                      'name'=>'line_tax_percent_c',
                      'widthClass' => 'cell-small',
                      'label'=>'LBL_LINE_TAX_PERCENT_C',

                    ),
                    array(
                      'name'=>'line_tax_amount_c',
                      'label'=>'LBL_LINE_TAX_AMOUNT_C',
                      'type' => 'currency',
                      'widthClass' => 'cell-small',
                      'showTransactionalAmount' => true,
                      'related_fields' => array(
                        'total_amount',
                        'currency_id',
                        'base_rate',
                      ),
                    ),

    The additional part the Key is to add the custom field in Quotes record view 

    product_bundle_items

    /custom/modules/Quotes/clients/base/views/record/record.php

    array(
             'name' => 'product_bundle_items',
             'fields' => array(
                               'name',
                              'quote_id',
                              'description',
                              'quantity',
                              'product_template_name',
                              'product_template_id',
                              'deal_calc',
                              'mft_part_num',
                              'discount_price',
                              'discount_amount',
                              'tax',
                              'tax_class',
                              'subtotal',
                              'position',
                              'currency_id',
                              'base_rate',
                              'discount_select',
                              'line_tax_amount_c',
                              'custom_product_field_c',
                     ),
             'max_num' => -1,
    ),

    then Repair and rebuild 

  • You are right! Thank you Aravind Kumar

    FrancescaS

Reply Children
  • Hello Francesca Shiekh,

    Thanks for Francesca Shiekh and Aravind Kumar.

    Line item level tax is working for me.

    How can I calculate Group level total tax add in Group total ?

    How can I calculate total tax add in Quote Grand total ?

  • I added a calculated field for the bundle tax total:

    custom/Extension/modules/ProductBundles/fields/tax_amount_c.php

    <?php
    $dictionary['ProductBundle']['fields']['tax_amount_c']['labelValue']='Tax Amount';
    $dictionary['ProductBundle']['fields']['tax_amount_c']['calculated']='true';
    $dictionary['ProductBundle']['fields']['tax_amount_c']['formula']='rollupCurrencySum($products, "line_tax_amount_c")';
    $dictionary['ProductBundle']['fields']['tax_amount_c']['enforced']='true';
    $dictionary['ProductBundle']['fields']['tax_amount_c']['dependency']='';
    $dictionary['ProductBundle']['fields']['tax_amount_c']['related_fields']=array (
      0 => 'currency_id',
      1 => 'base_rate',
    );

     

    and one for the Quote tax total

    <?php
    // created: 2017-06-13 11:14:46
    $dictionary['Quote']['fields']['tax_amount_c']['duplicate_merge_dom_value']=0;
    $dictionary['Quote']['fields']['tax_amount_c']['labelValue']='Tax';
    $dictionary['Quote']['fields']['tax_amount_c']['calculated']='true';
    $dictionary['Quote']['fields']['tax_amount_c']['formula']='rollupCurrencySum($product_bundles,"tax_amount_c")';
    $dictionary['Quote']['fields']['tax_amount_c']['enforced']='true';
    $dictionary['Quote']['fields']['tax_amount_c']['dependency']='';
    $dictionary['Quote']['fields']['tax_amount_c']['related_fields']=array (
      0 => 'currency_id',
      1 => 'base_rate',
    );

     

    ?>

    Note that they happen to be named the same but are separate fields, one in ProductBundles, the other in Quotes.

     

     

    And the ProductBundle total:

    custom/Extension/modules/ProductBundles/Ext/Vardefs/sugarfield_total.php

     

    $dictionary['ProductBundle']['fields']['total']['formula']='currencyAdd($new_sub, $tax_amount_c)';
    $dictionary['ProductBundle']['fields']['total']['related_fields']=array (
      0 => 'currency_id',
      1 => 'base_rate',
      2 => 'new_sub',
      3 => 'tax_amount_c',
    );
    $dictionary['ProductBundle']['fields']['total']['calculated']='true';
    $dictionary['ProductBundle']['fields']['total']['enforced']='true';

     

    The Quote total is a rollup of ProductBundle total so it does not need changing.

     

     

    This is not the only way, you could redefine the calculations for the existing tax fields, but I found it easier to create my own tax fields.

     

    You will need to edit your views to include your new calculated fields:

    custom/modules/ProductBundles/clients/base/views/quote-data-group-footer/quote-data-group-footer.php

    and 

    custom/modules/Quotes/clients/base/views/quote-data-grand-totals-footer/quote-data-grand-totals-footer.php

    and

    custom/modules/Quotes/clients/base/views/quote-data-grand-totals-header/quote-data-grand-totals-header.php

     

     

    I hope I didn't miss anything.

    FrancescaS

  • Hi Francesca Shiekh,

    It is working fine. Thank you very much for help.

    Thanks

    Asif

  • I have created custom field "line_tax_percent_c" and "custom_toggle" in "Quote Line Item(Product)". When I have edited quote line item but it's db store value not come.

    I have set field in "custom/modules/Products/clients/base/views/quote-data-group-list/quote-data-group-list.php".

    <?php
    /*
     * Your installation or use of this SugarCRM file is subject to the applicable
     * terms available at
     * http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.
     * If you do not agree to all of the applicable terms or do not have the
     * authority to bind the entity as an authorized representative, then do not
     * install or use this SugarCRM file.
     *
     * Copyright (C) SugarCRM Inc. All rights reserved.
     */
    $viewdefs['Products']['base']['view']['quote-data-group-list'] = array(
        'panels' => array(
            array(
                'name' => 'products_quote_data_group_list',
                'label' => 'LBL_PRODUCTS_QUOTE_DATA_LIST',
                'fields' => array(
                    array(
                        'name' => 'line_num',
                        'label' => null,
                        'widthClass' => 'cell-xsmall',
                        'css_class' => 'line_num tcenter',
                        'type' => 'line-num',
                        'readonly' => true,
                    ),
                    array(
                        'name' => 'quantity',
                        'label' => 'LBL_QUANTITY',
                        'widthClass' => 'cell-small',
                        'css_class' => 'quantity',
                        'type' => 'float',
                    ),
                    array(
                        'name' => 'product_template_name',
                        'label' => 'LBL_ITEM_NAME',
                        'widthClass' => 'cell-large',
                        'type' => 'quote-data-relate',
                        'required' => true,
                    ),
                    array(
                        'name' => 'mft_part_num',
                        'label' => 'LBL_MFT_PART_NUM',
                        'type' => 'base',
                    ),
                    array(
                        'name' => 'discount_price',
                        'label' => 'LBL_DISCOUNT_PRICE',
                        'type' => 'currency',
                        'convertToBase' => true,
                        'showTransactionalAmount' => true,
                        'related_fields' => array(
                            'discount_price',
                            'currency_id',
                            'base_rate',
                        ),
                    ),
                    array(
                        'name' => 'discount',
                        'type' => 'fieldset',
                        'css_class' => 'quote-discount-percent',
                        'label' => 'LBL_DISCOUNT_AMOUNT',
                        'fields' => array(
                            array(
                                'name' => 'discount_amount',
                                'label' => 'LBL_DISCOUNT_AMOUNT',
                                'type' => 'discount',
                                'convertToBase' => true,
                                'showTransactionalAmount' => true,
                            ),
                            array(
                                'type' => 'discount-select',
                                'name' => 'discount_select',
                                'no_default_action' => true,
                                'buttons' => array(
                                    array(
                                        'type' => 'rowaction',
                                        'name' => 'select_discount_amount_button',
                                        'label' => 'LBL_DISCOUNT_AMOUNT',
                                        'event' => 'button:discount_select_change:click',
                                    ),
                                    array(
                                        'type' => 'rowaction',
                                        'name' => 'select_discount_percent_button',
                                        'label' => 'LBL_DISCOUNT_PERCENT',
                                        'event' => 'button:discount_select_change:click',
                                    ),
                                ),
                            ),
                        ),
                    ),
                    array(
                      'name'=>'customrow_toggle_c',
                      'widthClass' => 'cell-small',
                      'label'=>'LBL_CUSTOMROW_TOGGLE',
                      'type' => 'varchar',
                    ),
                    array(
                      'name'=>'line_tax_percent_c',
                      'widthClass' => 'cell-small',
                      'label'=>'LBL_LINE_TAX_PERCENT_C',
                      'type' => 'float',

                    ),
                    array(
                      'name'=>'line_tax_amount_c',
                      'label'=>'LBL_LINE_TAX_AMOUNT_C',
                      'type' => 'currency',
                      'widthClass' => 'cell-small',
                      'showTransactionalAmount' => true,
                      'related_fields' => array(
                        'total_amount',
                        'currency_id',
                        'base_rate',
                      ),
                    ),
                    array(
                        'name' => 'total_amount',
                        'label' => 'LBL_LINE_ITEM_TOTAL',
                        'type' => 'currency',
                        'widthClass' => 'cell-medium',
                        'showTransactionalAmount' => true,
                        'related_fields' => array(
                            'total_amount',
                            'currency_id',
                            'base_rate',
                        ),
                    ),
                ),
            ),
        ),
    );

    Francesca Shiekh Aravind Kumar

    Thanks

    Asif

  • Hi Offshore Evolution, Did you followed Francesca Shiekh code? so what was the field type you have mentioned? Is it not working on Edit View alone or you cant view that values in Detail View?

    Provide us your Field Creation details code and the modification you have made.

  • Hi Aravind Kumar,

    It is not displaying value in detail or edit record page. I have set same as Francesca Shiekh code.

    1) line_tax_percent_c - It is float type field but it is not displaying value.

    2) line_tax_amount_c - It is currency formula field but it is displaying value.

    3) customrow_toggle_c - it is varchar type field but it is not displaying value.

  • Offshore Evolution did you add your field in custom/modules/Quotes/clients/base/views/record/record.php under 

    product_bundle_items

    it should work

  • Hi Aravind Kumar,

    It is working. Thanks for help.

    Thanks

    Asif