From cc7fd615fc42b150654fd13dae5a573c360414fe Mon Sep 17 00:00:00 2001
From: yogeshwar <yogeshwar.g@vtigersolutions.com>
Date: Thu, 23 May 2024 13:44:58 +0530
Subject: [PATCH] E-ALL - Organization Module

---
 .../Inventory/partials/LineItemsContent.tpl   | 51 ++++++++++---------
 .../Inventory/partials/LineItemsEdit.tpl      | 13 ++---
 modules/Inventory/models/Charges.php          |  2 +-
 modules/Inventory/models/Record.php           |  2 +-
 4 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/layouts/v7/modules/Inventory/partials/LineItemsContent.tpl b/layouts/v7/modules/Inventory/partials/LineItemsContent.tpl
index 61abbcdd9..98878015f 100644
--- a/layouts/v7/modules/Inventory/partials/LineItemsContent.tpl
+++ b/layouts/v7/modules/Inventory/partials/LineItemsContent.tpl
@@ -90,7 +90,7 @@
 								{elseif $entityType eq '' and $SERVICE_ACTIVE eq 'true'}
 									<span class="lineItemPopup cursorPointer" data-popup="ServicesPopup" title="{vtranslate('Services',$MODULE)}" data-module-name="Services" data-field-name="serviceid">{Vtiger_Module_Model::getModuleIconPath('Services')}</span>
 								{else}
-									{if ($entityType eq 'Services') and (!$data.$productDeleted)}
+									{if ($entityType eq 'Services') and (isset($data.$productDeleted) && !$data.$productDeleted)}
 										<span class="lineItemPopup cursorPointer" data-popup="ServicesPopup" title="{vtranslate('Services',$MODULE)}" data-module-name="Services" data-field-name="serviceid">{Vtiger_Module_Model::getModuleIconPath('Services')}</span>
 									{elseif (!$data.$productDeleted)}
 										<span class="lineItemPopup cursorPointer" data-popup="ProductsPopup" title="{vtranslate('Products',$MODULE)}" data-module-name="Products" data-field-name="productid">{Vtiger_Module_Model::getModuleIconPath('Products')}</span>
@@ -104,6 +104,7 @@
 			<input type="hidden" value="{(isset($data.$subproduct_ids)) ? $data.$subproduct_ids : ""}" id="{$subproduct_ids}" name="{$subproduct_ids}" class="subProductIds" />
 			<div id="{$subprod_names}" name="{$subprod_names}" class="subInformation">
 				<span class="subProductsContainer">
+				{if isset($data.$subprod_qty_list)}
 					{foreach key=SUB_PRODUCT_ID item=SUB_PRODUCT_INFO from=$data.$subprod_qty_list}
 						<em> - {$SUB_PRODUCT_INFO.name} ({$SUB_PRODUCT_INFO.qty})
 							{if $SUB_PRODUCT_INFO.qty > getProductQtyInStock($SUB_PRODUCT_ID)}
@@ -111,9 +112,11 @@
 							{/if}
 						</em><br>
 					{/foreach}
+				{/if}
+					
 				</span>
 			</div>
-			{if $data.$productDeleted}
+			{if isset($data.$productDeleted) && $data.$productDeleted}
 				<div class="row-fluid deletedItem redColor">
 					{if empty($data.$productName)}
 						{vtranslate('LBL_THIS_LINE_ITEM_IS_DELETED_FROM_THE_SYSTEM_PLEASE_REMOVE_THIS_LINE_ITEM',$MODULE)}
@@ -123,7 +126,7 @@
 				</div>
 			{else}
 				{if $COMMENT_EDITABLE}
-					<div><br><textarea id="{$comment}" name="{$comment}" class="lineItemCommentBox">{decode_html($data.$comment)}</textarea></div>
+					<div><br><textarea id="{$comment}" name="{$comment}" class="lineItemCommentBox">{(isset($data.$comment)) ? decode_html($data.$comment):""}</textarea></div>
 				{/if}
 			{/if}
 		</td>
@@ -134,26 +137,26 @@
 			   data-rule-required=true data-rule-positive=true data-rule-greater_than_zero=true value="{if !empty($data.$qty)}{$data.$qty}{else}1{/if}"
 			   {if $QUANTITY_EDITABLE eq false} disabled=disabled {/if} />
 
-		{if $PURCHASE_COST_EDITABLE eq false and $MODULE neq 'PurchaseOrder'}
+		{if isset($PURCHASE_COST_EDITABLE) && $PURCHASE_COST_EDITABLE eq false and $MODULE neq 'PurchaseOrder'}
 			<input id="{$purchaseCost}" type="hidden" value="{if ((float)$data.$purchaseCost)}{((float)$data.$purchaseCost) / ((float)$data.$qty)}{else}0{/if}" />
             <span style="display:none" class="purchaseCost">0</span>
 			<input name="{$purchaseCost}" type="hidden" value="{if $data.$purchaseCost}{$data.$purchaseCost}{else}0{/if}" />
 		{/if}
-		{if $MARGIN_EDITABLE eq false}
+		{if isset($MARGIN_EDITABLE) && $MARGIN_EDITABLE eq false}
 			<input type="hidden" name="{$margin}" value="{if $data.$margin}{$data.$margin}{else}0{/if}"></span>
 			<span class="margin pull-right" style="display:none">{if $data.$margin}{$data.$margin}{else}0{/if}</span>
 		{/if}
 		{if $MODULE neq 'PurchaseOrder'}
 			<br>
-			<span class="stockAlert redColor {if $data.$qty <= $data.$qtyInStock}hide{/if}" >
+			<span class="stockAlert redColor {if isset($data.$qty) && $data.$qty <= $data.$qtyInStock}hide{/if}" >
 				{vtranslate('LBL_STOCK_NOT_ENOUGH',$MODULE)}
 				<br>
-				{vtranslate('LBL_MAX_QTY_SELECT',$MODULE)}&nbsp;<span class="maxQuantity">{$data.$qtyInStock}</span>
+				{vtranslate('LBL_MAX_QTY_SELECT',$MODULE)}&nbsp;<span class="maxQuantity">{(isset($data.$qtyInStock)) ? $data.$qtyInStock:""}</span>
 			</span>
 		{/if}
 	</td>
 
-	{if $PURCHASE_COST_EDITABLE}
+	{if isset($PURCHASE_COST_EDITABLE) && $PURCHASE_COST_EDITABLE}
 		<td>
 			<input id="{$purchaseCost}" type="hidden" value="{if $data.$purchaseCost}{((float)$data.$purchaseCost) / ((float)$data.$qty)}{else}0{/if}" />
 			<input name="{$purchaseCost}" type="hidden" value="{if $data.$purchaseCost}{$data.$purchaseCost}{else}0{/if}" />
@@ -178,9 +181,9 @@
 					<span>(-)&nbsp;
 						<strong><a href="javascript:void(0)" class="individualDiscount">{vtranslate('LBL_DISCOUNT',$MODULE)}
 								<span class="itemDiscount">
-									{if $ITEM_DISCOUNT_PERCENT_EDITABLE && $data.$discount_type eq 'percentage'}
+									{if isset($data.$discount_type) && $ITEM_DISCOUNT_PERCENT_EDITABLE && $data.$discount_type eq 'percentage'}
 										({$data.$discount_percent}%)
-									{else if $ITEM_DISCOUNT_AMOUNT_EDITABLE && $data.$discount_type eq 'amount'}
+									{else if isset($data.$discount_type) && $ITEM_DISCOUNT_AMOUNT_EDITABLE && $data.$discount_type eq 'amount'}
 										({$data.$discount_amount})
 									{else}
 										(0)
@@ -196,13 +199,13 @@
 					{/if}
 					<input type="hidden" id="discount_type{$row_no}" name="discount_type{$row_no}" value="{$DISCOUNT_TYPE}" class="discount_type" />
 					<p class="popover_title hide">
-						{vtranslate('LBL_SET_DISCOUNT_FOR',$MODULE)} : <span class="variable">{$data.$productTotal}</span>
+						{vtranslate('LBL_SET_DISCOUNT_FOR',$MODULE)} : <span class="variable">{isset($data.$productTotal) && $data.$productTotal}</span>
 					</p>
 					<table width="100%" border="0" cellpadding="5" cellspacing="0" class="table table-nobordered popupTable">
 						<!-- TODO : discount price and amount are hide by default we need to check id they are already selected if so we should not hide them  -->
 						<tr>
 							<td>
-								<input type="radio" name="discount{$row_no}" {$data.$checked_discount_zero} {if empty($data.$discount_type)}checked{/if} class="discounts" data-discount-type="zero" />
+								<input type="radio" name="discount{$row_no}" {(isset($data.$checked_discount_zero)) ? $data.$checked_discount_zero:""} {if empty($data.$discount_type)}checked{/if} class="discounts" data-discount-type="zero" />
 								&nbsp;
 								{vtranslate('LBL_ZERO_DISCOUNT',$MODULE)}
 							</td>
@@ -214,25 +217,25 @@
 						{if $ITEM_DISCOUNT_PERCENT_EDITABLE}
 							<tr>
 								<td>
-									<input type="radio" name="discount{$row_no}" {$data.$checked_discount_percent} class="discounts" data-discount-type="percentage" />
+									<input type="radio" name="discount{$row_no}" {(isset($data.$checked_discount_percent)) ? $data.$checked_discount_percent : ""} class="discounts" data-discount-type="percentage" />
 									&nbsp; %
 									{vtranslate('LBL_OF_PRICE',$MODULE)}
 								</td>
 								<td>
 									<span class="pull-right">&nbsp;%</span>
-									<input type="text" data-rule-positive=true data-rule-inventory_percentage=true id="discount_percentage{$row_no}" name="discount_percentage{$row_no}" value="{$data.$discount_percent}" class="discount_percentage span1 pull-right discountVal {if empty($data.$checked_discount_percent)}hide{/if}" />
+									<input type="text" data-rule-positive=true data-rule-inventory_percentage=true id="discount_percentage{$row_no}" name="discount_percentage{$row_no}" value="{(isset($data.$discount_percent)) ? $data.$discount_percent : ""}" class="discount_percentage span1 pull-right discountVal {if empty($data.$checked_discount_percent)}hide{/if}" />
 								</td>
 							</tr>
 						{/if}
 						{if $ITEM_DISCOUNT_AMOUNT_EDITABLE}
 							<tr>
 								<td class="LineItemDirectPriceReduction">
-									<input type="radio" name="discount{$row_no}" {$data.$checked_discount_amount} class="discounts" data-discount-type="amount" />
+									<input type="radio" name="discount{$row_no}" {(isset($data.$checked_discount_amount)) ? $data.$checked_discount_amount : ""} class="discounts" data-discount-type="amount" />
 									&nbsp;
 									{vtranslate('LBL_DIRECT_PRICE_REDUCTION',$MODULE)}
 								</td>
 								<td>
-									<input type="text" data-rule-positive=true id="discount_amount{$row_no}" name="discount_amount{$row_no}" value="{$data.$discount_amount}" class="span1 pull-right discount_amount discountVal {if empty($data.$checked_discount_amount)}hide{/if}"/>
+									<input type="text" data-rule-positive=true id="discount_amount{$row_no}" name="discount_amount{$row_no}" value="{(isset($data.$discount_amount)) ? $data.$discount_amount : ""}" class="span1 pull-right discount_amount discountVal {if empty($data.$checked_discount_amount)}hide{/if}"/>
 								</td>
 							</tr>
 						{/if}
@@ -249,9 +252,9 @@
 			<span class="taxDivContainer">
 				<div class="taxUI hide" id="tax_div{$row_no}">
 					<p class="popover_title hide">
-						{vtranslate('LBL_SET_TAX_FOR',$MODULE)} : <span class="variable">{$data.$totalAfterDiscount}</span>
+						{vtranslate('LBL_SET_TAX_FOR',$MODULE)} : <span class="variable">{(isset($data.$totalAfterDiscount)) ? $data.$totalAfterDiscount : ""}</span>
 					</p>
-					{if $data.taxes && php7_count($data.taxes) > 0}
+					{if isset($data.taxes) && $data.taxes && php7_count($data.taxes) > 0}
 						<div class="individualTaxDiv">
 							<!-- we will form the table with all taxes -->
 							<table width="100%" border="0" cellpadding="5" cellspacing="0" class="table table-nobordered popupTable" id="tax_table{$row_no}">
@@ -279,16 +282,16 @@
 	{/if}
 
 	<td>
-		<div id="productTotal{$row_no}" align="right" class="productTotal">{if $data.$productTotal}{$data.$productTotal}{else}0{/if}</div>
+		<div id="productTotal{$row_no}" align="right" class="productTotal">{if isset($data.$productTotal) && $data.$productTotal}{$data.$productTotal}{else}0{/if}</div>
 		{if $ITEM_DISCOUNT_AMOUNT_EDITABLE || $ITEM_DISCOUNT_PERCENT_EDITABLE}
-			<div id="discountTotal{$row_no}" align="right" class="discountTotal">{if $data.$discountTotal}{$data.$discountTotal}{else}0{/if}</div>
-			<div id="totalAfterDiscount{$row_no}" align="right" class="totalAfterDiscount">{if $data.$totalAfterDiscount}{$data.$totalAfterDiscount}{else}0{/if}</div>
+			<div id="discountTotal{$row_no}" align="right" class="discountTotal">{if isset($data.$discountTotal) && $data.$discountTotal}{$data.$discountTotal}{else}0{/if}</div>
+			<div id="totalAfterDiscount{$row_no}" align="right" class="totalAfterDiscount">{if isset($data.$totalAfterDiscount) && $data.$totalAfterDiscount}{$data.$totalAfterDiscount}{else}0{/if}</div>
 		{/if}
 
-		<div id="taxTotal{$row_no}" align="right" class="productTaxTotal {if $IS_GROUP_TAX_TYPE}hide{/if}">{if $data.$taxTotal}{$data.$taxTotal}{else}0{/if}</div>
+		<div id="taxTotal{$row_no}" align="right" class="productTaxTotal {if $IS_GROUP_TAX_TYPE}hide{/if}">{if isset($data.$taxTotal) && $data.$taxTotal}{$data.$taxTotal}{else}0{/if}</div>
 	</td>
 
-	{if $MARGIN_EDITABLE && $PURCHASE_COST_EDITABLE}
+	{if isset($MARGIN_EDITABLE) && $MARGIN_EDITABLE && $PURCHASE_COST_EDITABLE}
 		<td>
 			<input type="hidden" name="{$margin}" value="{if $data.$margin}{$data.$margin}{else}0{/if}"></span>
 		<span class="margin pull-right">{if $data.$margin}{$data.$margin}{else}0{/if}</span>
@@ -296,6 +299,6 @@
 	{/if}
 
 	<td>
-		<span id="netPrice{$row_no}" class="pull-right netPrice">{if $data.$netPrice}{$data.$netPrice}{else}0{/if}</span>
+		<span id="netPrice{$row_no}" class="pull-right netPrice">{if isset($data.$netPrice) && $data.$netPrice}{$data.$netPrice}{else}0{/if}</span>
 	</td>
 {/strip}
diff --git a/layouts/v7/modules/Inventory/partials/LineItemsEdit.tpl b/layouts/v7/modules/Inventory/partials/LineItemsEdit.tpl
index a32fe88aa..1551cc8fc 100644
--- a/layouts/v7/modules/Inventory/partials/LineItemsEdit.tpl
+++ b/layouts/v7/modules/Inventory/partials/LineItemsEdit.tpl
@@ -185,7 +185,7 @@
 						{include file="partials/LineItemsContent.tpl"|@vtemplate_path:'Inventory' row_no=0 data=[] IGNORE_UI_REGISTRATION=true}
 					</tr>
 					{foreach key=row_no item=data from=$RELATED_PRODUCTS}
-						<tr id="row{$row_no}" data-row-num="{$row_no}" class="lineItemRow" {if $data["entityType$row_no"] eq 'Products'}data-quantity-in-stock={$data["qtyInStock$row_no"]}{/if}>
+						<tr id="row{$row_no}" data-row-num="{$row_no}" class="lineItemRow" {if isset($data["entityType$row_no"]) && $data["entityType$row_no"] eq 'Products'}data-quantity-in-stock={$data["qtyInStock$row_no"]}{/if}>
 							{include file="partials/LineItemsContent.tpl"|@vtemplate_path:'Inventory' row_no=$row_no data=$data}
 						</tr>
 					{/foreach}
@@ -297,7 +297,7 @@
 						</td>
 					</tr>
 				{/if}
-				{if $SH_PERCENT_EDITABLE}
+				{if $SH_PERCENT_EDITABLE && isset($FINAL.chargesAndItsTaxes)}
 					{assign var=CHARGE_AND_CHARGETAX_VALUES value=$FINAL.chargesAndItsTaxes}
 					<tr>
 						<td width="83%">
@@ -337,7 +337,8 @@
 						<span class="pull-right"><strong>{vtranslate('LBL_PRE_TAX_TOTAL', $MODULE)} </strong></span>
 					</td>
 					<td>
-						{assign var=PRE_TAX_TOTAL value=$FINAL.preTaxTotal}
+					
+						{assign var=PRE_TAX_TOTAL value="{(isset($FINAL.preTaxTotal)) ? $FINAL.preTaxTotal:""}"}
 						<span class="pull-right" id="preTaxTotal">{if $PRE_TAX_TOTAL}{$PRE_TAX_TOTAL}{else}0{/if}</span>
 						<input type="hidden" id="pre_tax_total" name="pre_tax_total" value="{if $PRE_TAX_TOTAL}{$PRE_TAX_TOTAL}{else}0{/if}"/>
 					</td>
@@ -360,7 +361,7 @@
 												   data-rule-positive=true data-rule-inventory_percentage=true />&nbsp;%
 										</td>
 										<td style="text-align: right;" class="lineOnTop">
-											<input type="text" size="6" name="{$tax_detail.taxname}_group_amount" id="group_tax_amount{$smarty.foreach.group_tax_loop.iteration}" style="cursor:pointer;" value="{$tax_detail.amount}" readonly class="cursorPointer span1 groupTaxTotal" />
+											<input type="text" size="6" name="{$tax_detail.taxname}_group_amount" id="group_tax_amount{$smarty.foreach.group_tax_loop.iteration}" style="cursor:pointer;" value="{(isset($tax_detail.amount))?$tax_detail.amount:''}" readonly class="cursorPointer span1 groupTaxTotal" />
 										</td>
 									</tr>
 								{/foreach}
@@ -394,7 +395,7 @@
 												{/if}
 												<tr>
 													{assign var=SH_TAX_VALUE value=$CHARGE_TAX_MODEL->getTax()}
-													{if $CHARGE_AND_CHARGETAX_VALUES[$CHARGE_ID]['value'] neq NULL}
+													{if isset($CHARGE_AND_CHARGETAX_VALUES[$CHARGE_ID]['value']) && $CHARGE_AND_CHARGETAX_VALUES[$CHARGE_ID]['value'] neq NULL}
 														{assign var=SH_TAX_VALUE value=0}
 														{if $CHARGE_AND_CHARGETAX_VALUES[$CHARGE_ID]['taxes'][$CHARGE_TAX_ID]}
 															{assign var=SH_TAX_VALUE value=$CHARGE_AND_CHARGETAX_VALUES[$CHARGE_ID]['taxes'][$CHARGE_TAX_ID]}
@@ -447,7 +448,7 @@
 							</div>
 						</td>
 						<td>
-							<span class="pull-right" id="deductTaxesTotalAmount">{if $FINAL.deductTaxesTotalAmount}{$FINAL.deductTaxesTotalAmount}{else}0{/if}</span>
+							<span class="pull-right" id="deductTaxesTotalAmount">{if isset($FINAL.deductTaxesTotalAmount) && $FINAL.deductTaxesTotalAmount}{$FINAL.deductTaxesTotalAmount}{else}0{/if}</span>
 						</td>
 					</tr>
 				{/if}
diff --git a/modules/Inventory/models/Charges.php b/modules/Inventory/models/Charges.php
index 56e08e106..8c2f484b9 100644
--- a/modules/Inventory/models/Charges.php
+++ b/modules/Inventory/models/Charges.php
@@ -64,7 +64,7 @@ class Inventory_Charges_Model extends Vtiger_Base_Model {
 	 * @return <Array> list of Inventory_TaxRecord_Model
 	 */
 	public function getSelectedTaxes($deleted = true) {
-		if (!$this->taxes) {
+		if (!isset($this->taxes)) {
 			$taxModelsList = array();
 			$isTaxable = $this->isTaxable();
 			if ($isTaxable) {
diff --git a/modules/Inventory/models/Record.php b/modules/Inventory/models/Record.php
index 318244586..728a222a2 100644
--- a/modules/Inventory/models/Record.php
+++ b/modules/Inventory/models/Record.php
@@ -681,7 +681,7 @@ class Inventory_Record_Model extends Vtiger_Record_Model {
 		if ($chargeId) {
 			$chargeTaxModelsList = array();
 			$chargesAndItsTaxes = $this->getCharges();
-			$chargeInfo = $chargesAndItsTaxes[$chargeId];
+			$chargeInfo = isset($chargesAndItsTaxes[$chargeId]) ? $chargesAndItsTaxes[$chargeId] : "";
 			if ($chargeInfo && $chargeInfo['taxes']) {
 				$taxes = array_keys($chargeInfo['taxes']);
 				foreach ($taxes as $taxId) {
-- 
GitLab