GSTHelper using x++.
class GSTHelper { ITaxDocument taxDocument; Common sourceHeader; Common sourceLine; Amount CGSTAmount,IGSTAmount,SGSTAmount,reverseAmount,recoverableAmount; real CGSTRate,IGSTRate,SGSTRate; Amount CESSAmount; real CESSRate; HSNCode_IN HSNOrSACCode; Amount taxBaseAmount,discountAmount; ClassName bundlerClassName; /*Amount CGSTAmountMiscChrg,IGSTAmountMiscChrg,SGSTAmountMiscChrg; real CGSTRateMiscChrg,IGSTRateMiscChrg,SGSTRateMiscChrg;*/ RecId TaxDocumentRecId; boolean isUTGST; #define.TaxType('GST') #define.CGST('CGST') #define.IGST('IGST') #define.SGST('SGST') #define.CESS('CESS') public classname parmBundlerClassName(ClassName _bundlerClassName) { bundlerClassName = _bundlerClassName; return bundlerClassName; } public Amount parmCGSTAmount(Amount _cgstAmount = CGSTAmount) { CGSTAmount = _cgstAmount; return CGSTAmount; } public real parmCGSTRate(real _cgstRate = CGSTRate) { CGSTRate = _cgstRate; return CGSTRate; } public HSNCode_IN parmHSNOrSACCode(HSNCode_IN _HSNOrSACCode = HSNOrSACCode) { HSNOrSACCode = _HSNOrSACCode; return HSNOrSACCode; } public Amount parmIGSTAmount(Amount _igstAmount = IGSTAmount) { IGSTAmount = _igstAmount; return IGSTAmount; } public real parmIGSTRate(real _igstRate = IGSTRate) { IGSTRate = _igstRate; return IGSTRate; } public Amount parmCESSAmount(Amount _cessAmount = CESSAmount) { CESSAmount = _cessAmount; return CESSAmount; } public real parmCESSRate(real _cessRate = CESSRate) { CESSRate = _cessRate; return CESSRate; } public boolean parmIsUTGST(boolean _isUTGST = isUTGST) { isUTGST = _isUTGST; return isUTGST; } public Amount parmSGSTAmount(Amount _sgstAmount = SGSTAmount) { SGSTAmount = _sgstAmount; return SGSTAmount; } public Amount parmReverseChargeAmount(Amount _reverseAmount = reverseAmount) { reverseAmount = _reverseAmount; return reverseAmount; } public Amount parmRecoverableAmount(Amount _recoverableAmount = recoverableAmount) { recoverableAmount = _recoverableAmount; return recoverableAmount; } public real parmsGSTRate(real _sgstRate = sGSTRate) { SGSTRate = _sgstRate; return SGSTRate; } public Common parmSourceHeader(Common _sourceHeader = sourceHeader) { sourceHeader = _sourceHeader; return sourceHeader; } public Common parmSourceLine(Common _sourceLine = sourceLine) { sourceLine = _sourceLine; return sourceLine; } public amount parmTaxBaseAmount(Amount _taxBaseAmount = taxBaseAmount) { taxBaseAmount = _taxBaseAmount; return taxBaseAmount; } public RecID parmTaxDocumentRecID(RecId _TaxDocumentRecID = TaxDocumentRecId) { TaxDocumentRecId = _TaxDocumentRecID; return TaxDocumentRecId; } private void initFromSourceHeaderLine(Common sourceHeader,Common sourceLine,ClassName _bundlerClassName = "") { this.parmSourceHeader(_sourceHeader); this.parmSourceLine(_sourceLine); this.parmBundlerClassName(_bundlerClassName); } public void calculate() { /*#TaxEngineModelFields #TaxEngineModelLineMeasures #TaxEngineModelFrameworkFields*/ //#TaxEngineService //#Tax TaxableDocumentDescriptor bundler; ITaxableDocument taxableDocumentObject; ITaxDocumentLine iTaxDocumentLine; TaxComponentTable_IN taxComponentTable_IN; ITaxDocumentComponentLine taxDocumentComponentLine; ITaxDocumentComponentLineEnumerator taxDocumentComponentLineEnumerator; ClassId bundlerId; bundler = TaxableDocumentDescriptorFactory::getTaxableDocumentDescriptor(sourceHeader); if (bundler) { taxableDocumentObject = TaxableDocumentObject::constructServer(bundler); taxDocument = TaxBusinessService::getTaxDocumentBySource(sourceHeader.TableId, sourceHeader.RecId); if(!taxDocument) { bundlerId = className2Id(bundlerClassName); if (bundlerId != 0) { bundler = TaxableDocumentDescriptor::getTaxDocumentdescriptor(bundlerId, sourceLine); taxableDocumentObject = TaxableDocumentObject::constructServer(bundler); taxDocument = TaxBusinessService::calculateTax(taxableDocumentObject, false); } } } if(taxDocument) { iTaxDocumentLine = taxDocument.findLineBySource(sourceLine.TableId,sourceLine.RecId); if(iTaxDocumentLine) { this.parmHSNOrSACCode(iTaxDocumentLine.getFieldValue("HSN Code") ? iTaxDocumentLine.getFieldValue("HSN Code") : iTaxDocumentLine.getFieldValue("SAC")); this.parmTaxBaseAmount(itaxDocumentLine.getFieldValue("Base Amount")); this.parmTaxDocumentRecID(TaxDocument::findByGUID(taxDocument.getGUID()).RecId); taxDocumentComponentLineEnumerator = iTaxDocumentLine.componentLines(); while (taxDocumentComponentLineEnumerator.moveNext()) { taxDocumentComponentLine = taxDocumentComponentLineEnumerator.current(); this.parmRecoverableAmount(taxDocumentComponentLine.getMeasure("Recoverable Amount").value().value()); this.parmReverseChargeAmount(taxDocumentComponentLine.getMeasure("Reverse Charge Amount").value().value()); switch(taxDocumentComponentLine.metaData().taxComponent()) { case #CGST : { this.parmCGSTRate(taxDocumentComponentLine.getMeasure("Rate").value().value()); this.parmCGSTAmount(taxDocumentComponentLine.getMeasure("Tax Amount").value().value()); } break; case #IGST : { this.parmIGSTRate(taxDocumentComponentLine.getMeasure("Rate").value().value()); this.parmIGSTAmount(taxDocumentComponentLine.getMeasure("Tax Amount").value().value()); } break; case #SGST : { this.parmSGSTRate(taxDocumentComponentLine.getMeasure("Rate").value().value()); this.parmSGSTAmount(taxDocumentComponentLine.getMeasure("Tax Amount").value().value()); } break; case #CESS: { this.parmCESSRate(taxDocumentComponentLine.getMeasure("Rate").value().value()); this.parmCESSAmount(taxDocumentComponentLine.getMeasure("Tax Amount").value().value()); } break; } } } } } public static GSTHelper constructCalculate(Common sourceHeader,Common sourceLine,classname _bundlerClassName = "") { GSTHelper gstHelper = new GSTHelper(); gstHelper.initFromSourceHeaderLine(_sourceHeader,_sourceLine,_bundlerClassName); gstHelper.calculate(); //gstHelper.calculateMiscChrgGST(); return gstHelper; } }
Keep Daxing!!