Tried to add Line items to Cases

  1. Create one-to-many relationship between Cases and Line Item via Studio

Studio->Cases->Relationships-> ADD RELATIONSHIP

Relationship name → cases_aos_products_quotes_1


  1. You will see the below code in the vardefs.ext.php file

/custom/modules/Cases/Ext/Vardefs/vardefs.ext.php

 $dictionary['Case']['fields']['cases_aos_products_quotes_1'] =
  array(
      'lhs_module' => 'Cases',
      'lhs_table' => 'cases',
      'lhs_key' => 'id',
      'rhs_module' => 'AOS_Products_Quotes',
      'rhs_table' => 'aos_products_quotes',
      'rhs_key' => 'parent_id',
      'relationship_type' => 'one-to-many',
  );
  $dictionary['Case']['fields']['cases_aos_line_item_groups'] =
  array(
      'lhs_module' => 'Cases',
      'lhs_table' => 'cases',
      'lhs_key' => 'id',
      'rhs_module' => 'AOS_Line_Item_Groups',
      'rhs_table' => 'aos_line_item_groups',
      'rhs_key' => 'parent_id',
      'relationship_type' => 'one-to-many',
  );

  1. Add these code in the Edit & Detail views of module (custom/modules/Cases/metadata/)
      'lbl_line_items' =>
      array(
        0 =>
        array(
          0 =>
              array(
                  'name' => 'currency_id',
                  'studio' => 'visible',
                  'label' => 'LBL_CURRENCY',
              ),
          1 => '',
          ),
        1 =>
        array(
          0 =>
          array(
            'name' => 'line_items',
            'label' => 'LBL_LINE_ITEMS',
          ),
        ),
        2 =>
        array(
          0 =>
          array(
            'name' => 'total_amt',
            'label' => 'LBL_TOTAL_AMT',
          ),
        ),
        3 =>
        array(
          0 =>
          array(
            'name' => 'discount_amount',
            'label' => 'LBL_DISCOUNT_AMOUNT',
          ),
        ),
        4 =>
        array(
          0 =>
          array(
            'name' => 'subtotal_amount',
            'label' => 'LBL_SUBTOTAL_AMOUNT',
          ),
        ),
        5 =>
        array(
          0 =>
          array(
            'name' => 'shipping_amount',
            'label' => 'LBL_SHIPPING_AMOUNT',
          ),
        ),
        6 =>
        array(
          0 =>
          array(
            'name' => 'shipping_tax_amt',
            'label' => 'LBL_SHIPPING_TAX_AMT',
          ),
        ),
        7 =>
        array(
          0 =>
          array(
            'name' => 'tax_amount',
            'label' => 'LBL_TAX_AMOUNT',
          ),
        ),
        8 =>
        array(
          0 =>
          array(
            'name' => 'total_amount',
            'label' => 'LBL_GRAND_TOTAL',
          ),
        ),
      ),

Add the headers/labels into the language file

custom/modules/Cases/language/en_us.lang.php

  'LBL_IMPORT_LINE_ITEMS' => 'Import Line Items',
  'LBL_LINE_ITEMS' => 'Line Items',
  'LBL_GRAND_TOTAL' => 'Grand Total',
  'LBL_TOTAL_AMT' => 'Total',
  'LBL_TAX_AMOUNT' => 'Tax',
  'LBL_SUBTOTAL_AMOUNT' => 'Subtotal',
  'LBL_SHIPPING_AMOUNT' => 'Shipping',
  'LBL_SHIPPING_TAX_AMT' => 'Shipping Tax',
  'LBL_DISCOUNT_AMOUNT' => 'Discount',
  'LBL_ADD_PRODUCT_LINE' => 'Add Product Line',
  'LBL_ADD_SERVICE_LINE' => 'Add Service Line ',
  'LBL_REMOVE_PRODUCT_LINE' => 'Remove',
  'LBL_SERVICE_NAME' => 'Service',
  'LBL_SERVICE_LIST_PRICE' => 'List',
  'LBL_SERVICE_PRICE' => 'Sale Price',
  'LBL_SERVICE_DISCOUNT' => 'Discount',
  'LBL_VAT_AMT' => 'Tax Amount',
  'LBL_TOTAL_PRICE' => 'Total',
  'LBL_PRODUCT_QUANITY' => 'Quantity',
  'LBL_PRODUCT_NAME' => 'Product',
  'LBL_PART_NUMBER' => 'Part Number',
  'LBL_PRODUCT_NOTE' => 'Note',
  'LBL_PRODUCT_DESCRIPTION' => 'Description',
  'LBL_LIST_PRICE' => 'List',
  'LBL_DISCOUNT_AMT' => 'Discount',
  'LBL_UNIT_PRICE' => 'Sale Price',
  'LNK_LIST' => 'View Invoices',
  'LBL_AOS_CONTRACTS' => 'Contracts',
  'LBL_AOS_QUOTES' => 'Quotes',
  'LBL_ADD_GROUP' => 'Add Group',
  'LBL_DELETE_GROUP' => 'Delete Group',
  'LBL_GROUP_NAME' => 'Group Name',
  'LBL_GROUP_TOTAL' => 'Group Total',
  'LBL_DISCOUNT_AMOUNT_USDOLLAR' => 'Discount (Default Currency)',
  'LBL_TAX_AMOUNT_USDOLLAR' => 'Tax (Default Currency)',
  'LBL_SHIPPING_AMOUNT_USDOLLAR' => 'Shipping (Default Currency)',
  'LBL_TOTAL_AMT_USDOLLAR' => 'Total (Default Currency)',
  'LBL_SHIPPING_TAX_AMT_USDOLLAR' => 'Shipping Tax (Default Currency)',
  'LBL_GRAND_TOTAL_USDOLLAR' => 'Grand Total (Default Currency)',

  'LBL_SUBTOTAL_TAX_AMOUNT_USDOLLAR' => 'Subtotal + Tax (Default Currency)',

  'LBL_AOS_LINE_ITEM_GROUPS' => 'Line Item Groups',
  'LBL_EMAIL_QUOTE' => 'Email Quotation',
  'LBL_EMAIL_NAME' => 'Quote for',
  'LBL_EMAIL_PDF' => 'Email PDF',

  1. Create aos_line_items.php file

custom/Extension/modules/Cases/Ext/Vardefs/aos_line_items.php

$dictionary['Case']['fields']['tax_amount'] =
  array(
      'required' => false,
      'name' => 'tax_amount',
      'vname' => 'LBL_TAX_AMOUNT',
      'type' => 'currency',
      'massupdate' => 0,
      'comments' => '',
      'help' => '',
      'importable' => 'true',
      'duplicate_merge' => 'disabled',
      'duplicate_merge_dom_value' => '0',
      'audited' => 1,
      'reportable' => true,
      'len' => '26,6',
);
  $dictionary['Case']['fields']['shipping_tax_amt'] =
  array(
      'required' => false,
      'name' => 'shipping_tax_amt',
      'vname' => 'LBL_SHIPPING_TAX_AMT',
      'type' => 'currency',
      'massupdate' => 0,
      'comments' => '',
      'help' => '',
      'importable' => 'true',
      'duplicate_merge' => 'disabled',
      'duplicate_merge_dom_value' => '0',
      'audited' => 0,
      'reportable' => true,
      'len' => '26,6',
      'size' => '10',
      'enable_range_search' => false,
      'function' =>
          array(
              'name' => 'display_shipping_vat',
              'returns' => 'html',
              'include' => 'modules/AOS_Products_Quotes/Line_Items.php'
          ),
        );
  $dictionary['Case']['fields']['shipping_amount'] =
  array(
      'required' => false,
      'name' => 'shipping_amount',
      'vname' => 'LBL_SHIPPING_AMOUNT',
      'type' => 'currency',
      'massupdate' => 0,
      'comments' => '',
      'help' => '',
      'importable' => 'true',
      'duplicate_merge' => 'disabled',
      'duplicate_merge_dom_value' => '0',
      'audited' => 0,
      'reportable' => true,
      'len' => '26,6',
  );
  $dictionary['Case']['fields']['subtotal_amount'] =
  array(
      'required' => false,
      'name' => 'subtotal_amount',
      'vname' => 'LBL_SUBTOTAL_AMOUNT',
      'type' => 'currency',
      'massupdate' => 0,
      'comments' => '',
      'help' => '',
      'importable' => 'true',
      'duplicate_merge' => 'disabled',
      'duplicate_merge_dom_value' => '0',
      'audited' => 1,
      'reportable' => true,
      'len' => '26,6',
  );
$dictionary['Case']['fields']['currency_id'] =
  array(
      'required' => false,
      'name' => 'currency_id',
      'vname' => 'LBL_CURRENCY',
      'type' => 'id',
      'massupdate' => 0,
      'comments' => '',
      'help' => '',
      'importable' => 'true',
      'duplicate_merge' => 'disabled',
      'duplicate_merge_dom_value' => 0,
      'audited' => false,
      'reportable' => false,
      'len' => 36,
      'size' => '20',
      'studio' => 'visible',
      'function' =>
          array(
              'name' => 'getCurrencyDropDown',
              'returns' => 'html',
              'onListView' => true,
          ),
        );
  $dictionary['Case']['fields']['discount_amount'] =
  array(
      'required' => false,
      'name' => 'discount_amount',
      'vname' => 'LBL_DISCOUNT_AMOUNT',
      'type' => 'currency',
      'massupdate' => 0,
      'comments' => '',
      'help' => '',
      'importable' => 'true',
      'duplicate_merge' => 'disabled',
      'duplicate_merge_dom_value' => '0',
      'audited' => 1,
      'reportable' => true,
      'len' => '26,6',
  );
  $dictionary['Case']['fields']['line_items'] =
  array(
      'required' => false,
      'name' => 'line_items',
      'vname' => 'LBL_LINE_ITEMS',
      'type' => 'function',
      'source' => 'non-db',
      'massupdate' => 0,
      'importable' => 'false',
      'duplicate_merge' => 'disabled',
      'duplicate_merge_dom_value' => 0,
      'audited' => false,
      'reportable' => false,
      'inline_edit' => false,
      'function' =>
          array(
              'name' => 'display_lines',
              'returns' => 'html',
              'include' => 'modules/AOS_Products_Quotes/Line_Items.php'
          ),
        );
  $dictionary['Case']['fields']['total_amount'] =
  array(
      'required' => false,
      'name' => 'total_amount',
      'vname' => 'LBL_GRAND_TOTAL',
      'type' => 'currency',
      'massupdate' => 0,
      'comments' => '',
      'help' => '',
      'importable' => 'true',
      'duplicate_merge' => 'disabled',
      'duplicate_merge_dom_value' => '0',
      'audited' => false,
      'reportable' => true,
      'len' => '26,6',
      'enable_range_search' => true,
      'options' => 'numeric_range_search_dom',
  );
  $dictionary['Case']['fields']['aos_products_quotes'] =
  array(
      'name' => 'aos_products_quotes',
      'vname' => 'LBL_AOS_PRODUCT_QUOTES',
      'type' => 'link',
      'relationship' => 'cases_aos_products_quotes_1',
      'module' => 'AOS_Products_Quotes',
      'bean_name' => 'AOS_Products_Quotes',
      'source' => 'non-db',
  );
 $dictionary['Case']['fields']['cases_aos_products_quotes_1'] =
  array(
      'lhs_module' => 'Cases',
      'lhs_table' => 'cases',
      'lhs_key' => 'id',
      'rhs_module' => 'AOS_Products_Quotes',
      'rhs_table' => 'aos_products_quotes',
      'rhs_key' => 'parent_id',
      'relationship_type' => 'one-to-many',
  );
  $dictionary['Case']['fields']['cases_aos_line_item_groups'] =
  array(
      'lhs_module' => 'Cases',
      'lhs_table' => 'cases',
      'lhs_key' => 'id',
      'rhs_module' => 'AOS_Line_Item_Groups',
      'rhs_table' => 'aos_line_item_groups',
      'rhs_key' => 'parent_id',
      'relationship_type' => 'one-to-many',
  );

  1. Add logic for saving Positions in the Cases module

custom/modules/Cases/logic_hooks.php

$hook_array['after_save'][] = Array(
    1,
    'save line-item groups on Case',
    'custom/modules/Cases/CaseLineItemHooks.php',
    'CaseLineItemHooks',
    'saveLineItems',
);

custom/modules/Cases/CaseLineItemHooks.php

<?php
// custom/modules/Cases/CaseLineItemHooks.php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class CaseLineItemHooks
{

    public function saveLineItems($bean, $event, $arguments)
    {
        // only trigger when there's actually group data in the POST
        if (!empty($_POST['group_']))
        {
            // load the AOS bundle handler
            require_once 'modules/AOS_Line_Item_Groups/AOS_Line_Item_Groups.php';
            $grp = BeanFactory::newBean('AOS_Line_Item_Groups');
            // save_groups expects: POST array, the parent bean, and the prefix used in the form
            $grp->save_groups($_POST, $bean, 'group_');
        }
    }
}

To add the Email PDF, and Email Quotation options into the Cases module.

image

custom/modules/AOS_Quotes/metadata/detailviewdefs.php

 4 =>
 array(
          'customCode' => '<input type="button" class="button" onClick="showPopup(\'emailpdf\');" value="{$MOD.LBL_EMAIL_PDF}">',
   ),
  5 =>
   array(
            'customCode' => '<input type="button" class="button" onClick="showPopup(\'email\');return false;" value="{$MOD.LBL_EMAIL_QUOTE}">',
    ),

Could someone please try this code in their dev server and report here? :pray: :pray: :pray:

problem facing - 1) When we add product line items and save, it does not show the grand total and other values in the detail view. 2) When we delete one of line item and try to save the record, it gets stuck and page keep on loading. Only way to stop it by restarting the php services on the server. systemctl restart php7.4-fpm.