static void DeleteDuplicateGSTRate(Args _args)
{
TaxRuntimeLookupCondition taxRuntimeLookupCondition, taxRuntimeLookupConditionGroup, taxRuntimeLookupConditionSelect;
TaxRuntimeLookupMeasureResult taxRuntimeLookupMeasureResult;
TaxRuntimeLookupMeasureResultDetail taxRuntimeLookupMeasureResultDetail;
TaxRuntimeLookup taxRuntimeLookup;
TaxRuntimeLookupVersion taxRuntimeLookupVersion;
TaxRuntimeDocComponentMeasure taxRuntimeDocComponentMeasure;
TaxRuntimeDocComponentMeasureVersion taxRuntimeDocComponentMeasureVersion;
TaxRuntimeDocComponent taxRuntimeDocComponent;
TaxRuntimeDocComponentVersion taxRuntimeDocComponentVersion;
TaxRuntimeDocTaxType taxRuntimeDocTaxType;
TaxRuntimeDocTaxTypeVersion taxRuntimeDocTaxTypeVersion;
TaxRuntimeTaxMeasureValue taxRuntimeTaxMeasureValue;
container gstType;
Query query;
QueryBuildDataSource qbds;
QueryHavingFilter havingFilter;
QueryRun queryRun;
int counter;
container gstRate;
query = new Query();
qbds = query.addDataSource(tableNum(TaxRuntimeLookupCondition));
qbds.addSelectionField(fieldNum(TaxRuntimeLookupCondition, RecId), SelectionField::Sum);
qbds.addRange(fieldNum(TaxRuntimeLookupCondition, DimValue1)).value(SysQuery::valueNotEmptyString());
qbds.addRange(fieldNum(TaxRuntimeLookupCondition, Ledger)).value(SysQuery::value(CompanyInfo::find().RecId));
//qbds.addRange(fieldNum(TaxRuntimeLookupCondition, DimValue2)).value(SysQuery::value('34013019'));
qbds.orderMode(OrderMode::GroupBy);
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, DimValue1));
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, DimValue2));
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, DimValue3));
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, Ledger));
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, DateRangeFrom1));
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, DateRangeTo1));
havingFilter = query.addHavingFilter(qbds, fieldStr(TaxRuntimeLookupCondition, RecId), AggregateFunction::Count);
havingFilter.value('>3');
queryRun = new QueryRun(query);
while (queryRun.next())
{
taxRuntimeLookupConditionGroup = queryRun.getNo(1);
gstType = conNull();
gstRate = conNull();
while select forUpdate taxRuntimeLookupCondition
where taxRuntimeLookupCondition.DimValue1 == taxRuntimeLookupConditionGroup.DimValue1 &&
taxRuntimeLookupCondition.DimValue2 == taxRuntimeLookupConditionGroup.DimValue2 &&
taxRuntimeLookupCondition.DimValue3 == taxRuntimeLookupConditionGroup.DimValue3 &&
taxRuntimeLookupCondition.Ledger == taxRuntimeLookupConditionGroup.Ledger &&
taxRuntimeLookupCondition.DateRangeFrom1 == taxRuntimeLookupConditionGroup.DateRangeFrom1 &&
taxRuntimeLookupCondition.DateRangeTo1 == taxRuntimeLookupConditionGroup.DateRangeTo1
{
taxRuntimeLookupVersion = TaxRuntimeLookupVersion::find(taxRuntimeLookupCondition.LookupVersion);
taxRuntimeLookup = TaxRuntimeLookup::find(taxRuntimeLookupVersion.Lookup);
select firstOnly taxRuntimeDocComponentMeasure
where taxRuntimeDocComponentMeasure.RecId == taxruntimelookup.LookupOwnerRecId;
select firstOnly taxRuntimeDocComponent
where taxRuntimeDocComponent.Name == 'IGST';
if (taxRuntimeDocComponentMeasure.TaxRuntimeDocComponent == taxRuntimeDocComponent.RecId)
{
select firstOnly taxRuntimeLookupMeasureResult
join forUpdate taxRuntimeLookupMeasureResultDetail
where taxRuntimeLookupMeasureResult.LookupCondition == taxRuntimeLookupCondition.RecId
&& taxRuntimeLookupMeasureResultDetail.LookupMeasureResult == taxRuntimeLookupMeasureResult.RecId;
if (taxRuntimeLookupMeasureResult.RecId)
{
//taxRuntimeTaxMeasureValue = taxRuntimeLookupMeasureResultDetail.Value;
if (gstType == conNull()) // for the 1st record
{
gstType = ['IGST'];
gstRate = [taxRuntimeLookupMeasureResultDetail.Value];
}
else if (conPeek(gstRate, 1) == taxRuntimeLookupMeasureResultDetail.Value) // for duplicate based on value
{
ttsBegin;
taxRuntimeLookupCondition.delete();
ttsCommit;
counter++;
}
}
//if (gstType == 'CGST' || gstType == 'SGST')
//{
//gstCompFoundNo++;
//}
//else if (gstType == 'IGST')
//{
//gstCompFoundNo++;
//}
}
}
}
info(strFmt('Total => %1', counter));
}
{
TaxRuntimeLookupCondition taxRuntimeLookupCondition, taxRuntimeLookupConditionGroup, taxRuntimeLookupConditionSelect;
TaxRuntimeLookupMeasureResult taxRuntimeLookupMeasureResult;
TaxRuntimeLookupMeasureResultDetail taxRuntimeLookupMeasureResultDetail;
TaxRuntimeLookup taxRuntimeLookup;
TaxRuntimeLookupVersion taxRuntimeLookupVersion;
TaxRuntimeDocComponentMeasure taxRuntimeDocComponentMeasure;
TaxRuntimeDocComponentMeasureVersion taxRuntimeDocComponentMeasureVersion;
TaxRuntimeDocComponent taxRuntimeDocComponent;
TaxRuntimeDocComponentVersion taxRuntimeDocComponentVersion;
TaxRuntimeDocTaxType taxRuntimeDocTaxType;
TaxRuntimeDocTaxTypeVersion taxRuntimeDocTaxTypeVersion;
TaxRuntimeTaxMeasureValue taxRuntimeTaxMeasureValue;
container gstType;
Query query;
QueryBuildDataSource qbds;
QueryHavingFilter havingFilter;
QueryRun queryRun;
int counter;
container gstRate;
query = new Query();
qbds = query.addDataSource(tableNum(TaxRuntimeLookupCondition));
qbds.addSelectionField(fieldNum(TaxRuntimeLookupCondition, RecId), SelectionField::Sum);
qbds.addRange(fieldNum(TaxRuntimeLookupCondition, DimValue1)).value(SysQuery::valueNotEmptyString());
qbds.addRange(fieldNum(TaxRuntimeLookupCondition, Ledger)).value(SysQuery::value(CompanyInfo::find().RecId));
//qbds.addRange(fieldNum(TaxRuntimeLookupCondition, DimValue2)).value(SysQuery::value('34013019'));
qbds.orderMode(OrderMode::GroupBy);
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, DimValue1));
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, DimValue2));
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, DimValue3));
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, Ledger));
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, DateRangeFrom1));
qbds.addGroupByField(fieldNum(TaxRuntimeLookupCondition, DateRangeTo1));
havingFilter = query.addHavingFilter(qbds, fieldStr(TaxRuntimeLookupCondition, RecId), AggregateFunction::Count);
havingFilter.value('>3');
queryRun = new QueryRun(query);
while (queryRun.next())
{
taxRuntimeLookupConditionGroup = queryRun.getNo(1);
gstType = conNull();
gstRate = conNull();
while select forUpdate taxRuntimeLookupCondition
where taxRuntimeLookupCondition.DimValue1 == taxRuntimeLookupConditionGroup.DimValue1 &&
taxRuntimeLookupCondition.DimValue2 == taxRuntimeLookupConditionGroup.DimValue2 &&
taxRuntimeLookupCondition.DimValue3 == taxRuntimeLookupConditionGroup.DimValue3 &&
taxRuntimeLookupCondition.Ledger == taxRuntimeLookupConditionGroup.Ledger &&
taxRuntimeLookupCondition.DateRangeFrom1 == taxRuntimeLookupConditionGroup.DateRangeFrom1 &&
taxRuntimeLookupCondition.DateRangeTo1 == taxRuntimeLookupConditionGroup.DateRangeTo1
{
taxRuntimeLookupVersion = TaxRuntimeLookupVersion::find(taxRuntimeLookupCondition.LookupVersion);
taxRuntimeLookup = TaxRuntimeLookup::find(taxRuntimeLookupVersion.Lookup);
select firstOnly taxRuntimeDocComponentMeasure
where taxRuntimeDocComponentMeasure.RecId == taxruntimelookup.LookupOwnerRecId;
select firstOnly taxRuntimeDocComponent
where taxRuntimeDocComponent.Name == 'IGST';
if (taxRuntimeDocComponentMeasure.TaxRuntimeDocComponent == taxRuntimeDocComponent.RecId)
{
select firstOnly taxRuntimeLookupMeasureResult
join forUpdate taxRuntimeLookupMeasureResultDetail
where taxRuntimeLookupMeasureResult.LookupCondition == taxRuntimeLookupCondition.RecId
&& taxRuntimeLookupMeasureResultDetail.LookupMeasureResult == taxRuntimeLookupMeasureResult.RecId;
if (taxRuntimeLookupMeasureResult.RecId)
{
//taxRuntimeTaxMeasureValue = taxRuntimeLookupMeasureResultDetail.Value;
if (gstType == conNull()) // for the 1st record
{
gstType = ['IGST'];
gstRate = [taxRuntimeLookupMeasureResultDetail.Value];
}
else if (conPeek(gstRate, 1) == taxRuntimeLookupMeasureResultDetail.Value) // for duplicate based on value
{
ttsBegin;
taxRuntimeLookupCondition.delete();
ttsCommit;
counter++;
}
}
//if (gstType == 'CGST' || gstType == 'SGST')
//{
//gstCompFoundNo++;
//}
//else if (gstType == 'IGST')
//{
//gstCompFoundNo++;
//}
}
}
}
info(strFmt('Total => %1', counter));
}
No comments:
Post a Comment