if :object_type = '18' and (:transaction_type = 'A' or :transaction_type = 'U')
then --BY Prashant For TDS above 50 Lakh 13/05/2024 - Deleted old Rahul TN
DECLARE EXIT HANDLER FOR SQL_ERROR_CODE 1299
BEGIN
cnt := 0;
END;
---
cnt := 0;
Select Count(*) into cnt
From OPCH T0 where "DocEntry" = :list_of_cols_val_tab_del;
if cnt > 0 then
select "PIndicator" into PIndicator from OPCH Where "DocEntry"
= :list_of_cols_val_tab_del;
select "CardCode" into BP from OPCH Where "DocEntry" = :list_of_cols_val_tab_del;
select ifnull(sum(Basic),0) into TotalBusiness from (
select opch."CardCode", opch."DocNum",
sum(pch1."LineTotal") Basic
from opch
inner join pch1 on opch."DocEntry" = pch1."DocEntry"
inner join pch12 on pch12."DocEntry" =Opch."DocEntry"
where "CANCELED" = 'N' and pch1."TaxOnly" = 'N' and
"CardCode" = :BP and "PIndicator" = :PIndicator and
pch12."CountryB" = 'IN'
group by opch."CardCode", opch."DocNum",
opch."DocEntry"
union all
select orpc."CardCode", orpc."DocNum", -
sum(rpc1."LineTotal")
from orpc
inner join rpc1 on orpc."DocEntry" = rpc1."DocEntry"
inner join rpc12 on rpc12."DocEntry" =
orpc."DocEntry"
where RPC1."BaseType" <> 203 and "CANCELED" = 'N' and
rpc1."TaxOnly" = 'N' and
"CardCode" = :BP and "PIndicator" = :PIndicator and
"CountryB" = 'IN'
group by orpc."CardCode", orpc."DocNum",
orpc."DocEntry"
) Z
group by "CardCode";
Select top 1 "CountryB" into CountryB from PCH12 Where "DocEntry"
= :list_of_cols_val_tab_del;
select sum("LineTotal") into InvoiceValue from OPCH inner join PCH1 on
OPCH."DocEntry" = PCH1."DocEntry"
Where OPCH."DocEntry" = :list_of_cols_val_tab_del;
--select max(T1."Name") into Tax from INV1 T0
--Inner join OSTC T1 On T0."TaxCode" = T1."Code" Where T0."DocEntry"
= :list_of_cols_val_tab_del;
SELECT IfNull(max(T1."WTCode"),'') into Tax FROM OPCH T0 LEFT JOIN PCH5 T1 ON
T0."DocEntry" = T1."AbsEntry"
Where T0."DocEntry" = :list_of_cols_val_tab_del;
--select case when ifnull((select top 1 ifnull("TaxId0",'NO PAN') from crd7 where
"CardCode" = :BP and length("TaxId0") = 10),'') = '' then 'NO PAN'
--else
--(select top 1 ifnull("TaxId0",'NO PAN') from crd7 where "CardCode" = :BP and
length("TaxId0") = 10)
--end into pan from dummy ;
select case when (:TotalBusiness - :InvoiceValue) > 5000000 then :InvoiceValue
else
:TotalBusiness - 5000000 end into
TDSBaseAmount From Dummy;
--select case when :PAN like 'NO PAN' then (:TDSBaseAmount * 0.75/100) when :PAN
not like 'NO PAN' then (:TDSBaseAmount * 0.075/100) end
--into TDSValue From Dummy;
if :TotalBusiness > 5000000 and (:Tax not like '%94Q%' ) and :CountryB = 'IN' then
-- and :PAN not like 'NO PAN' then
-- if cnt > 0 and :BP = '1001' then
error := 4;
error_message := 'Please select TDS 194Q for vendor - ' || :BP || -- ', PAN - '
|| :PAN ||
', Total Business including current Invoice - '
|| cast(:TotalBusiness as nvarchar(200)) || ', TDS value must be calculated on - '
|| cast(:TDSBaseAmount as nvarchar(200));
End If;
End If;
End If;