Thursday, February 9, 2023

Vendor Undo Settlement using X++:

 Vendor Undo Settlement using X++:



final class RunnableClass
{
    public static void main(Args _args)
    {
        VendTrans       vendTRANS;
        VendSettlement  vendSettlement;
        DialogField     dialogField1;
        Dialog          dialog = new Dialog();

        dialog.caption('Voucher');

        dialogField1 = dialog.addField(ExtendedTypeStr(Name));
        
        dialog.run();

        if (dialog.closedOk())
        {
            select firstonly * from vendTRANS
                where vendTRANS.Voucher == dialogField1.value();
             //  && findCustTRANS.TransType == LedgerTransType::Payment;
            // vendTRANS.AmountMST <= 0 &&
            ////vendTRANS.TransType == LedgerTransType::Vend &&
            // vendTRANS.TransType != LedgerTransType::Settlement &&
            //!vendTRANS.closed

            if (vendTRANS)
            {
                ttsbegin;

                VendTable           VendTable        = VendTable::find(vendTRANS.AccountNum);
                SpecTransManager    specTransManager = SpecTransManager::newRefTableId(VendTable, tableNum(VendSettlement), true);
                boolean 	    isFound = false;
				
                while select forupdate vendSettlement
                    where vendSettlement.TransCompany == vendTRANS.DataAreaId
			&& vendSettlement.TransRecId == vendTRANS.RecId
			&& vendSettlement.AccountNum == vendTRANS.AccountNum
			&& vendSettlement.CanBeReversed == NoYes::Yes
                {
                    vendSettlement.reread();
		    vendSettlement.CustVendSettlement::markThisAndRelatedOffsets(specTransManager, vendTRANS.CurrencyCode);

                    isFound = true;
                }

                if (isFound && VendTrans::reverseTransact(VendTable, null, SettleDatePrinc::DateOfPayment, vendSettlement.TransDate)) 
		{
		    specTransManager.deleteAll();
		}
                ttscommit;
            }
        }
    }
}







No comments:

Post a Comment