Custom batch to delete vendor voucher.#SADA => RENDeleteVendVoucherRENDeleteVendVoucher.PNG
// This is a framework class. Customizing this class may cause problems with future upgrades to the software.
class RENDeleteVendVoucher extends RunBaseBatch
{
// Packed variables
TransDate transDate;
Voucher voucher;
Voucher CostLedgerVoucher;
InvoiceId invoiceId;
NoYesId recalcAccount;
AccountNum AccountNum;
boolean isInvoice;
LedgerJournalNameId JournalName;
//
A_EInvoicePurchImportMode A_EInvoicePurchImportMode;
Filename Filename;
//
NumberSequenceGroupID NumberSequenceGroup;
TaxBookRecId taxBookRecId;
TaxBookSectionRecId taxBookSectionRecId;
// Dialog fields
DialogField dlgVoucher;
DialogField dlgTransDate;
DialogField dlgRecalcAccount;
DialogField dlgJournalName;
#define.CurrentVersion(6)
#define.Version1(6)
#localmacro.CurrentList
transDate,
voucher,
CostLedgerVoucher,
invoiceId,
recalcAccount,
AccountNum,
isInvoice,
NumberSequenceGroup,
JournalName
#endmacro
}
public boolean allowSaveLast()
{
boolean ret;
ret = false;
return ret;
}
/// <summary>
/// Indicates whether the class is shown in the list of <c>Journal</c> types.
/// </summary>
/// <returns>
/// true if the class is shown in the list of <c>Journal</c> types; otherwise, false.
/// </returns>
/// <remarks>
/// A class that can be used in a batch journal is a class where the same parameters can be used
/// repeatedly. The dialog box can be shown and the parameters can be changed, but parameters of some
/// classes might build on data that is only valid for a short time. Running a class two times with the
/// same parameters is not always possible. If the <c>RunBaseBatch.canGoBatch</c> method is false, this
/// method will not have any effect.
/// </remarks>
public boolean canGoBatchJournal()
{
return false;
}
private void Delete()
{
VendInvoiceJour VendInvoiceJour;
VendInvoiceTrans VendInvoiceTrans;
VendInvoicePurchLink VendInvoicePurchLink;
VendInvoiceInfoTable VendInvoiceInfoTable;
SourceDocumentLine SourceDocumentLine;
VendInvoicePackingSlipQuantityMatch VendInvoicePackingSlipQuantityMatch;
VendPackingSlipTrans VendPackingSlipTrans;
VendPackingSlipJour vendPackingSlipJour;
PurchTable PurchTable;
Purchline Purchline;
PurchParmSubLine PurchParmSubLine;
inventReportDimHistory inventReportDimHistory;
InventTransOrigin InventTransOrigin;
InventTrans InventTrans;
inventTransPosting inventTransPosting;
inventSettlement inventSettlement;
// ALT_SC_20161201_DelVoucher Begin
Boolean WithTrans = false;
// ALT_SC_20161201_DelVoucher End
//SN_ID_PurchImport
LedgerJournalTrans ledgerJournaalTrans;
LedgerJournalTable ledgerJournalTable;
//EN_ID_PurchImport
;
unchecked(Uncheck::TableSecurityPermission)
{
while select forupdate VendInvoiceJour
where VendInvoiceJour.LedgerVoucher == voucher
&& VendInvoiceJour.InvoiceDate == transDate
{
isInvoice = true;
accountnum = VendInvoiceJour.InvoiceAccount;
NumberSequenceGroup = VendInvoiceJour.numberSequenceGroup;
invoiceId = VendInvoiceJour.InvoiceId;
CostLedgerVoucher = VendInvoiceJour.CostLedgerVoucher;
while select forupdate VendInvoiceTrans
where VendInvoiceTrans.InvoiceId == VendInvoiceJour.InvoiceId
&& VendInvoiceTrans.PurchId == VendInvoiceJour.PurchId
&& VendInvoiceTrans.InvoiceDate==transDate
{
// ALT_SC_20161201_DelVoucher Begin
WithTrans = false;
// ALT_SC_20161201_DelVoucher End
setprefix("InventTrans");
while select InventTransOrigin
where InventTransOrigin.InventTransId == VendInvoiceTrans.InventTransId &&
InventTransOrigin.ItemId == VendInvoiceTrans.ItemId
{
// ALT_SC_20161201_DelVoucher Begin
WithTrans = true;
// ALT_SC_20161201_DelVoucher End
while select forupdate inventTrans
where
(inventTrans.Voucher == voucher ||
inventTrans.Voucher == VendInvoiceJour.CostLedgerVoucher)
&& inventTrans.InventTransOrigin == InventTransOrigin.RecId
&& inventTrans.InvoiceId == InvoiceId
&& inventTrans.DateFinancial == transDate
&& (
(inventTrans.Statusissue == statusissue::Sold && inventTrans.StatusReceipt == statusreceipt::None) ||
(inventTrans.Statusissue == statusissue::None && inventTrans.StatusReceipt == statusreceipt::Purchased)
)
&& inventTrans.PackingSlipId == ""
{
while select forupdate PurchTable
where PurchTable.PurchId==VendInvoiceTrans.OrigPurchId
{
PurchTable.DocumentState = VersioningDocumentState::Confirmed;
//PurchTable.DocumentStatus = Documentstatus::PackingSlip;
PurchTable.PurchStatus = PurchStatus::Received;
// ALT_SC_20170211_DeleteVoucherRts Begin
PurchTable.SAD_RTSIntegrationSynchWithRTS = NoYes::No;
// ALT_SC_20170211_DeleteVoucherRts End
PurchTable.update();
}
setprefix("PurchLine");
while select forupdate Purchline
where Purchline.InventTransId==InventTransOrigin.InventTransId
{
Purchline.RemainPurchPhysical += Purchline.unitConvertInvent2Purch(inventTrans.Qty);
Purchline.RemainInventPhysical += (inventTrans.Qty);
if(PurchLine.PurchaseType == PurchaseType::ReturnItem)
{
Purchline.ReturnStatus = returnStatusLine::Awaiting;
}
Purchline.IsFinalized =NoYes::No;
Purchline.setPurchStatus();
Purchline.update();
INFOLOG.add(EXCEPTION::Info,"update Purch line " + Purchline.PurchId +
" in transaction " + int642str(Purchline.RecId));
}
inventTrans.delete();
INFOLOG.add(EXCEPTION::Info,"Delete no packing inventtrans " + voucher +
" in transaction " + int642str(inventTrans.RecId));
}
setprefix("InventTrans");
while select forupdate inventTrans
where
(inventTrans.Voucher == voucher ||
inventTrans.Voucher == VendInvoiceJour.CostLedgerVoucher)
&& inventTrans.InvoiceId == invoiceId
&& inventTrans.InventTransOrigin == InventTransOrigin.RecId
&& inventTrans.DateFinancial == transDate
&& (
(inventTrans.Statusissue == statusissue::Sold && inventTrans.StatusReceipt == statusreceipt::None) ||
(inventTrans.Statusissue == statusissue::None && inventTrans.StatusReceipt == statusreceipt::Purchased)
)
&& inventTrans.PackingSlipId != ""
{
while select forUpdate VendPackingSlipTrans
where VendPackingSlipTrans.PackingSlipId == InventTrans.PackingSlipId &&
VendPackingSlipTrans.InventTransId == InventTransOrigin.InventTransId
{
VendInvoicePackingSlipQuantityMatch = VendInvoicePackingSlipQuantityMatch::find(
VendInvoiceTrans.SourceDocumentLine,
VendPackingSlipTrans.SourceDocumentLine,
true);
if (VendInvoicePackingSlipQuantityMatch)
{
SourceDocumentLine = SourceDocumentLine::find(VendPackingSlipTrans.SourceDocumentLine,true);
SourceDocumentLine.AccountingStatus = SourceDocumentLineAccountingStatus::Completed;
SourceDocumentLine.update();
VendInvoicePackingSlipQuantityMatch.delete();
VendPackingSlipTrans.FullyMatched = NoYes::No;
VendPackingSlipTrans.update();
}
}
inventTrans.CostAmountPosted =0;
inventTrans.CurrencyCode ="";
inventTrans.InvoiceId ="";
inventTrans.Voucher ="";
inventTrans.DateFinancial =datenull();
inventTrans.StatusReceipt =StatusReceipt::Received;
inventTrans.CostAmountStd =0;
inventTrans.CostAmountAdjustment=0;
if(inventTrans.InvoiceReturned)
{
inventTrans.InvoiceReturned = noyes::No;
//ALT_SB_20160908_RenDelVendVoucherUpdate - begin
//inventTrans.StatusReceipt = StatusReceipt::Received;
if(inventTrans.Qty < 0)
{
inventTrans.StatusReceipt = StatusReceipt::None;
inventTrans.StatusIssue = StatusIssue::Deducted;
}
else
{
inventTrans.StatusReceipt = StatusReceipt::Received;
inventTrans.StatusIssue = StatusIssue::None;
}
//inventTrans.StatusIssue = StatusIssue::None;
//ALT_SB_20160908_RenDelVendVoucherUpdate - end
inventTrans.CostAmountOperations = 0;
}
setprefix("PurchLine");
while select forupdate PurchTable
where PurchTable.PurchId==VendInvoiceTrans.OrigPurchId
{
PurchTable.DocumentState = VersioningDocumentState::Confirmed;
//PurchTable.DocumentStatus = Documentstatus::PackingSlip;
PurchTable.PurchStatus = PurchStatus::Received;
// ALT_SC_20170211_DeleteVoucherRts Begin
PurchTable.SAD_RTSIntegrationSynchWithRTS = NoYes::No;
// ALT_SC_20170211_DeleteVoucherRts End
PurchTable.update();
}
while select forupdate Purchline
where Purchline.InventTransId==InventTransOrigin.InventTransId
{
Purchline.RemainPurchFinancial += Purchline.unitConvertInvent2Purch(inventTrans.Qty);
Purchline.RemainInventFinancial += inventTrans.Qty;
if(Purchline.PurchaseType == PurchaseType::ReturnItem)
{
Purchline.ReturnStatus = returnStatusLine::Received;
}
Purchline.IsFinalized =NoYes::No;
Purchline.setPurchStatus();
Purchline.update();
INFOLOG.add(EXCEPTION::Info,"update Purch line " + Purchline.PurchId +
" in transaction " + int642str(Purchline.RecId));
}
inventTrans.update();
INFOLOG.add(EXCEPTION::Info,"Updated packing inventtrans " + voucher +
" in transaction " + int642str(inventTrans.RecId));
}
}
// ALT_SC_20161201_DelVoucher Begin
if (!WithTrans)
{
while select forupdate Purchline
where Purchline.InventTransId==VendInvoiceTrans.InventTransId
{
Purchline.RemainPurchPhysical += VendInvoiceTrans.Qty;
Purchline.RemainInventPhysical += Purchline.calcQtyOrdered(Purchline.RemainPurchPhysical);
if(Purchline.PurchaseType == PurchaseType::ReturnItem)
{
Purchline.ReturnStatus = returnStatusLine::Received;
}
Purchline.IsFinalized =NoYes::No;
Purchline.setPurchStatus();
Purchline.update();
INFOLOG.add(EXCEPTION::Info,"update Purch line " + Purchline.PurchId +
" in transaction " + int642str(Purchline.RecId));
}
}
// ALT_SC_20161201_DelVoucher End
setprefix("VendInvoicePurchLink");
while select forupdate VendInvoicePurchLink
where VendInvoicePurchLink.invoiceId ==voucher
&& VendInvoicePurchLink.invoiceDate==transDate
{
VendInvoicePurchLink.delete();
INFOLOG.add(eXCEPTION::Info,"Deleted voucher " + voucher +
" in transaction " + int642str(VendInvoicePurchLink.RecId));
}
setprefix("PurchTable");
while select forupdate PurchTable
where PurchTable.PurchId==VendInvoiceTrans.OrigPurchId
{
PurchTable.DocumentState = VersioningDocumentState::Confirmed;
//PurchTable.DocumentStatus = Documentstatus::PackingSlip;
PurchTable.PurchStatus = PurchStatus::Received;
// ALT_SC_20170211_DeleteVoucherRts Begin
PurchTable.SAD_RTSIntegrationSynchWithRTS = NoYes::No;
// ALT_SC_20170211_DeleteVoucherRts End
PurchTable.update();
INFOLOG.add(EXCEPTION::Info,"update Purch table " + voucher +
" in transaction " + int642str(PurchTable.RecId));
}
setprefix("InventReportDimHistory");
while select forupdate inventReportDimHistory
where inventReportDimHistory.TransRefId == voucher
&& inventReportDimHistory.InventTransId == VendInvoiceTrans.InventTransId
{
inventReportDimHistory.delete();
INFOLOG.add(EXCEPTION::Info,"deleted inventreportdimhistory " + voucher +
" in transaction " + int642str(inventReportDimHistory.RecId));
}
setprefix("PurchParmSubLine");
while select forupdate PurchParmSubLine
where PurchParmSubLine.ParmId == vendInvoiceJour.ParmId
{
PurchParmSubLine.delete();
infolog.add(EXCEPTION::Info,"deleted voucher " + voucher +
" in transaction " + int642str(PurchParmSubLine.RecId));
}
setprefix("VendInvoiceTrans");
VendInvoiceTrans.delete();
INFOLOG.add(EXCEPTION::Info,"deleted voucher " + voucher +
" in transaction " + int642str(VendInvoiceTrans.RecId));
}
if (VendInvoiceJour.ParmId)
{
setprefix("VendInvoiceInfoTable");
while select forupdate VendInvoiceInfoTable
where VendInvoiceInfoTable.ParmId == VendInvoiceJour.ParmId
{
if(VendInvoiceInfoTable.A_EinvoiceFilename)
{
//A_EinvoiceDeletionHandler::updateFileLocation(A_EInvoicePurchImportMode::PendingInvoices, VendInvoiceInfoTable.A_EinvoiceFilename);
Filename = ledgerJournalTable.A_EinvoiceFilename;
A_EInvoicePurchImportMode = A_EInvoicePurchImportMode::PendingInvoices;
}
VendInvoiceInfoTable.delete();
}
}
//SN_ID_PurchImport
while select forupdate ledgerJournalTable where ledgerJournalTable.Posted
&& ledgerJournalTable.A_EinvoiceFilename!=strMin()
exists join ledgerJournaalTrans
where ledgerJournaalTrans.JournalNum==ledgerJournalTable.JournalNum
&& ledgerJournaalTrans.Voucher==voucher
&& ledgerJournaalTrans.TransDate == transDate
{
Filename = ledgerJournalTable.A_EinvoiceFilename;
A_EInvoicePurchImportMode = A_EInvoicePurchImportMode::InvoiceJournal;
//A_EinvoiceDeletionHandler::updateFileLocation(A_EInvoicePurchImportMode::InvoiceJournal, ledgerJournalTable.A_EinvoiceFilename);
ledgerJournalTable.A_EinvoiceFilename='';
ledgerJournalTable.doUpdate();
}
//EN_ID
setprefix("VendInvoiceJour");
VendInvoiceJour.delete();
INFOLOG.add(EXCEPTION::Info,"deleted voucher " + voucher +
" in transaction " + int642str(VendInvoiceJour.RecId));
}
//
}
if(this.DeleteLedger(VendInvoiceJour))
{
setprefix("InventSettlement");
while select forupdate inventSettlement
where inventSettlement.Voucher ==voucher
&& inventSettlement.TransDate==transDate
{
inventSettlement.delete();
INFOLOG.add(EXCEPTION::Info,"Deleted voucher " + voucher +
" in transaction " + int642str(inventSettlement.RecId));
}
setprefix("InventTransPosting");
while select forupdate inventTransPosting
where inventTransPosting.Voucher ==voucher
&& inventTransPosting.TransDate==transDate
&& inventTransPosting.InventTransPostingType==InventTransPostingType::Financial
{
inventTransPosting.delete();
INFOLOG.add(EXCEPTION::Info,"Deleted voucher " + voucher +
" in transaction " + int642str(inventTransPosting.RecId));
}
}
}
//ALT_EA_20180313_VendDeleteVoucherChanged New Method
private void Delete_VoucherChanged()
{
LedgerJournalVoucherChanged LedgerJournalVoucherChanged;
RENLogDeleteVoucher RENLogDeleteVoucher;
DialogButton confirm;
Voucher voucherToDelete;
transDate voucherDateToDelete;
;
while select LedgerJournalVoucherChanged
where ((LedgerJournalVoucherChanged.FromVoucher == voucher &&
LedgerJournalVoucherChanged.FromDate == transDate) ||
(LedgerJournalVoucherChanged.ToVoucher == voucher &&
LedgerJournalVoucherChanged.ToDate == transDate))
{
if(LedgerJournalVoucherChanged.FromVoucher == voucher &&
LedgerJournalVoucherChanged.FromDate == transDate)
{
voucherToDelete = LedgerJournalVoucherChanged.ToVoucher;
voucherDateToDelete = LedgerJournalVoucherChanged.ToDate;
}
else
{
voucherToDelete = LedgerJournalVoucherChanged.FromVoucher;
voucherDateToDelete = LedgerJournalVoucherChanged.FromDate;
}
confirm = Box::yesNo(strFmt("@SAD434", voucherToDelete, voucherDateToDelete),DialogButton::Yes,"@ANR779");
if(confirm == DialogButton::Yes)
{
this.DeleteUpdateLedger(voucherToDelete,voucherDateToDelete);
RENLogDeleteVoucher.clear();
RENLogDeleteVoucher.selectForUpdate(true);
RENLogDeleteVoucher.Voucher = voucherToDelete;
RENLogDeleteVoucher.DocumentNum = invoiceId;
RENLogDeleteVoucher.DocumentDate = voucherDateToDelete;
RENLogDeleteVoucher.AccountNum = accountnum;
RENLogDeleteVoucher.ModuleCustVendLedger = RENModuleCustVendLedger::Ledger;
RENLogDeleteVoucher.Recovered = NoYes::Yes;
RENLogDeleteVoucher.RecoveredDate = Datenull();
RENLogDeleteVoucher.InfologData = INFOLOG.infologData();
RENLogDeleteVoucher.insert();
}
}
}
private boolean DeleteLedger(VendInvoiceJour VendInvoiceJour)
{
VendTrans VendTrans;
VendTransOpen VendTransOpen;
VendPromissoryNoteInvoice VendPromissoryNoteInvoice;
VendPromissoryNoteInvoice VendPromissoryNoteInvoice_T;
VendPromissoryNoteJour VendPromissoryNoteJour;
//ALT_LR_20200225_AssetFix - begin
AssetBook AssetBook;
//ALT_LR_20200225_AssetFix - end
taxTrans taxTrans;
taxTransGeneralJournalAccountEntry taxTransGeneralJournalAccountEntry;
CosCostTrans CosCostTrans;
AssetTrans AssetTrans;
bankAccountTrans bankAccountTrans;
ledgerJournalTrans ledgerJournalTrans;
NumberSequenceGroupId NumberSequenceGroupLocal;
boolean ret = true;
;
while select forupdate VendPromissoryNoteInvoice
where VendPromissoryNoteInvoice.InvoiceVoucher == voucher
&& VendPromissoryNoteInvoice.invoiceDate == transDate
{
while select forupdate VendPromissoryNoteJour
where VendPromissoryNoteInvoice.PromissoryNoteId == VendPromissoryNoteJour.PromissoryNoteId
{
while select forupdate VendPromissoryNoteInvoice_T
where VendPromissoryNoteInvoice_T.PromissoryNoteId == VendPromissoryNoteJour.PromissoryNoteId
{
this.DeleteUpdateLedger(VendPromissoryNoteInvoice_T.Voucher,VendPromissoryNoteInvoice_T.InvoiceDate);
while select forupdate vendTrans
where vendTrans.Voucher == VendPromissoryNoteInvoice_T.Voucher
&& vendTrans.TransDate == VendPromissoryNoteInvoice_T.InvoiceDate
{
setprefix("vendTransOpen");
while select forupdate vendTransOpen
where vendTransOpen.RefRecId == vendTrans.RecId
&& vendTransOpen.TransDate == VendPromissoryNoteInvoice_T.InvoiceDate
{
vendTransOpen.delete();
INFOLOG.add(EXCEPTION::Info,"deleted voucher " + voucher +
" in transaction " + int642str(vendTransOpen.RecId));
}
setprefix("VendTrans");
vendTrans.delete();
INFOLOG.add(EXCEPTION::Info,"deleted voucher " + voucher +
" in transaction " + int642str(vendTrans.RecId));
}
VendPromissoryNoteInvoice_T.delete();
INFOLOG.add(eXCEPTION::Info,"Deleted Bill Of Exchange jour" + voucher +
" in transaction " + int642str(VendInvoiceJour.RecId));
}
VendPromissoryNoteJour.delete();
INFOLOG.add(eXCEPTION::Info,"Deleted Bill Of Exchange trans " + voucher +
" in transaction " + int642str(VendInvoiceJour.RecId));
}
VendPromissoryNoteInvoice.delete();
INFOLOG.add(eXCEPTION::Info,"Deleted Bill Of Exchange invoice " + voucher +
" in transaction " + int642str(VendInvoiceJour.RecId));
}
setprefix("TaxTrans");
while select forupdate taxTrans
where taxTrans.Voucher ==voucher
&& taxTrans.TransDate==transDate
{
taxBookRecId = taxTrans.TaxBook;
taxBookSectionRecId = taxTrans.TaxBookSection;
taxTrans.delete();
delete_from taxTransGeneralJournalAccountEntry where taxTransGeneralJournalAccountEntry.TaxTrans == taxTrans.RecId;
INFOLOG.add(EXCEPTION::Info,"deleted voucher " + voucher +
" in transaction " + int642str(taxTrans.RecId));
}
this.DeleteUpdateLedger(voucher, transDate,CostLedgerVoucher);
while select forupdate CosCostTrans
where CosCostTrans.Voucher ==voucher
&& CosCostTrans.TransDate==transDate
{
CosCostTrans.delete();
INFOLOG.add(eXCEPTION::Info,"Deleted voucher " + voucher +
" in transaction " + int642str(CosCostTrans.RecId));
}
while select forupdate AssetTrans
where AssetTrans.Voucher ==voucher
&& AssetTrans.TransDate==transDate
{
//ALT_LR_20200225_AssetFix - begin
select forUpdate AssetBook where AssetBook.BookId == AssetTrans.BookId &&
AssetBook.AssetId == AssetTrans.AssetId;
if(AssetBook.Status == AssetStatus::Open && !AssetBook.LastDepreciationDate)
{
AssetBook.Status = AssetStatus::NoAcquisition;
AssetBook.AcquisitionDate = dateNull();
AssetBook.VendAccount = "";
AssetBook.PurchId = "";
AssetBook.VendInvoiceId = "";
AssetBook.DepreciationStartDate = dateNull();
AssetBook.UsedFromDate = dateNull();
AssetBook.update();
}
//ALT_LR_20200225_AssetFix - end
AssetTrans.delete();
INFOLOG.add(eXCEPTION::Info,"Deleted voucher " + voucher +
" in transaction " + int642str(AssetTrans.RecId));
}
setprefix("BankAccountTrans");
while select forupdate bankAccountTrans
where bankAccountTrans.Voucher ==voucher
&& bankAccountTrans.TransDate==transDate
{
bankAccountTrans.delete();
INFOLOG.add(eXCEPTION::Info,"Deleted voucher " + voucher +
" in transaction " + int642str(bankAccountTrans.RecId));
}
setprefix("LedgerJournalTrans");
while select forupdate ledgerJournalTrans
where ledgerJournalTrans.Voucher ==voucher
&& ledgerJournalTrans.TransDate==transDate
{
ledgerJournalTrans.delete();
INFOLOG.add(eXCEPTION::Info,"deleted voucher " + voucher +
" in transaction " + int642str(ledgerJournalTrans.RecId));
}
while select forupdate VendTrans
where VendTrans.Voucher ==voucher
&& VendTrans.TransDate==transDate
{
setprefix("VendTransOpen");
while select forupdate VendTransOpen
where VendTransOpen.RefRecId ==VendTrans.RecId
&& VendTransOpen.TransDate==transDate
{
VendTransOpen.delete();
INFOLOG.add(EXCEPTION::Info,"deleted voucher " + voucher +
" in transaction " + int642str(VendTransOpen.RecId));
}
setprefix("VendTrans");
VendTrans.delete();
INFOLOG.add(EXCEPTION::Info,"deleted voucher " + voucher +
" in transaction " + int642str(VendTrans.RecId));
}
return ret;
}
private void DeleteUpdateLedger(Voucher _voucher,TransDate _transDate,Voucher _costLedgerVoucher = strMin())
{
generalJournalAccountEntry generalJournalAccountEntry;
generalJournalEntry generalJournalEntry;
subledgerVoucherGeneralJournalEntry subledgerVoucherGeneralJournalEntry;
ledgerEntry ledgerEntry;
ledgerEntryJournal ledgerEntryJournal;
ledgerEntryJournalizing ledgerEntryJournalizing;
;
while select RecId from generalJournalAccountEntry
join RecId from generalJournalEntry
where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
join RecId from subledgerVoucherGeneralJournalEntry
where subledgerVoucherGeneralJournalEntry.GeneralJournalEntry == generalJournalEntry.RecId
&& subledgerVoucherGeneralJournalEntry.VoucherDataAreaId == curext()
&& subledgerVoucherGeneralJournalEntry.AccountingDate == _transDate
&& (
(subledgerVoucherGeneralJournalEntry.Voucher == _voucher) ||
(_costLedgerVoucher && subledgerVoucherGeneralJournalEntry.Voucher == _costLedgerVoucher)
)
{
delete_from ledgerEntry
where ledgerEntry.GeneralJournalAccountEntry == generalJournalAccountEntry.RecId;
delete_from ledgerEntryJournal
where ledgerEntryJournal.RecId == generalJournalEntry.LedgerEntryJournal;
delete_from ledgerEntryJournalizing
where ledgerEntryJournalizing.GeneralJournalAccountEntry == generalJournalAccountEntry.RecId;
}
delete_from ledgerEntry
exists join generalJournalAccountEntry
where generalJournalAccountEntry.RecId == ledgerEntry.GeneralJournalAccountEntry
exists join generalJournalEntry
where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
exists join subledgerVoucherGeneralJournalEntry
where subledgerVoucherGeneralJournalEntry.GeneralJournalEntry == generalJournalEntry.RecId
&& subledgerVoucherGeneralJournalEntry.VoucherDataAreaId == curext()
&& subledgerVoucherGeneralJournalEntry.AccountingDate == _transDate
&& (
(subledgerVoucherGeneralJournalEntry.Voucher == _voucher) ||
(_costLedgerVoucher && subledgerVoucherGeneralJournalEntry.Voucher == _costLedgerVoucher)
);
delete_from generalJournalAccountEntry
exists join generalJournalEntry
where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
&& generalJournalEntry.Ledger == Ledger::current()
exists join subledgerVoucherGeneralJournalEntry
where subledgerVoucherGeneralJournalEntry.GeneralJournalEntry == generalJournalEntry.RecId
&& subledgerVoucherGeneralJournalEntry.VoucherDataAreaId == curext()
&& subledgerVoucherGeneralJournalEntry.AccountingDate == _transDate
&& (
(subledgerVoucherGeneralJournalEntry.Voucher == _voucher) ||
(_costLedgerVoucher && subledgerVoucherGeneralJournalEntry.Voucher == _costLedgerVoucher)
);
GeneralJournalEntry::deleteOrphans();
delete_from subledgerVoucherGeneralJournalEntry
where subledgerVoucherGeneralJournalEntry.VoucherDataAreaId == curext()
&& subledgerVoucherGeneralJournalEntry.AccountingDate == _transDate
&& (
(subledgerVoucherGeneralJournalEntry.Voucher == _voucher) ||
(_costLedgerVoucher && subledgerVoucherGeneralJournalEntry.Voucher == _costLedgerVoucher)
)
notexists join generalJournalEntry
where generalJournalEntry.RecId == subledgerVoucherGeneralJournalEntry.GeneralJournalEntry
&& generalJournalEntry.Ledger == Ledger::current();
}
/// <summary>
/// Returns a class that contains the methods that are described by the <c>RunBaseDialogable</c>
/// interface.
/// </summary>
/// <returns>
/// A class that contains the methods that are described by the <c>RunBaseDialogable</c> interface.
/// </returns>
/// <remarks>
/// A dialog box can be either built by using the <c>Dialog</c> class or by using a class that is
/// created in the Application Object Tree (AOT).
/// </remarks>
public Object dialog()
{
DialogRunbase dialog = super();
;
dlgVoucher = dialog.addFieldValue(extendedTypeStr(voucher ),voucher ,"@ANR773" );
dlgTransDate = dialog.addFieldValue(extendedTypeStr(transDate ),transDate ,"@ANR774" );
dlgRecalcAccount = dialog.addFieldValue(extendedTypeStr(NoYesId ),recalcAccount ,"@SYS15182");
//dlgJournalName = dialog.addFieldValue(extendedTypeStr(LedgerJournalNameId ),JournalName);
dlgRecalcAccount.visible(false);
return dialog;
}
public void dialogPostRun(DialogRunbase dialog)
{
;
super(dialog);
}
public boolean getFromDialog()
{
;
transDate = dlgTransDate.value();
voucher = dlgVoucher.value();
recalcAccount = dlgRecalcAccount.value();
//JournalName = dlgJournalName.value();
return super();
}
public boolean init()
{
return true;
}
protected void new()
{
super();
}
public container pack()
{
return [#CurrentVersion,#CurrentList];
}
public NoYesId parmRecalcAccount(NoYesId _recalcAccount = recalcAccount)
{
recalcAccount = _recalcAccount;
return recalcAccount;
}
public TransDate parmTransDate(TransDate _transDate = transDate)
{
transDate = _transDate;
return transDate;
}
public Voucher parmVoucher(Voucher _voucher = voucher)
{
voucher = _voucher;
return voucher;
}
/// <summary>
/// Contains the code that does the actual job of the class.
/// </summary>
public void run()
{
#OCCRetryCount
if (! this.validate())
throw error("");
try
{
ttsbegin;
this.Delete();
this.updatelog();
//ALT_EA_20180313_VendDeleteVoucherChanged Strat
this.Delete_VoucherChanged();
A_EinvoiceDeletionHandler::updateFileLocation(A_EInvoicePurchImportMode, Filename);
//ALT_EA_20180313_VendDeleteVoucherChanged End
ttscommit;
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}
public boolean runsImpersonated()
{
return true;
}
public void saveLast()
{
//super();
}
public boolean unpack(container packedClass)
{
Version version = RunBase::getVersion(packedClass);
;
switch (version)
{
case #CurrentVersion:
[version,#CurrentList] = packedClass;
break;
default:
return false;
}
return true;
}
void updatelog()
{
RENLogDeleteVoucher RENLogDeleteVoucher;
;
RENLogDeleteVoucher.clear();
RENLogDeleteVoucher = RENLogDeleteVoucher::find(Voucher,
RENModuleCustVendLedger::Vend,
DocumentStatus::Invoice,
true);
RENLogDeleteVoucher.selectForUpdate(true);
RENLogDeleteVoucher.Voucher = Voucher;
RENLogDeleteVoucher.DocumentNum = invoiceId;
RENLogDeleteVoucher.DocumentDate = transDate;
RENLogDeleteVoucher.DocumentStatus = DocumentStatus::Invoice;
RENLogDeleteVoucher.AccountNum = accountnum;
RENLogDeleteVoucher.ModuleCustVendLedger = RENModuleCustVendLedger::Vend;
RENLogDeleteVoucher.numberSequenceGroup = numberSequenceGroup;
RENLogDeleteVoucher.recalcAccount = recalcAccount;
RENLogDeleteVoucher.TaxBook = taxBookRecId;
RENLogDeleteVoucher.TaxBookSection = taxBookSectionRecId;
RENLogDeleteVoucher.Recovered = !isInvoice;
RENLogDeleteVoucher.RecoveredDate = Datenull();
RENLogDeleteVoucher.InfologData = INFOLOG.infologData();
if(RENLogDeleteVoucher.RecId)
{
RENLogDeleteVoucher.update();
}
else
{
RENLogDeleteVoucher.insert();
}
}
public boolean validate(Object _calledFrom = null)
{
VendInvoiceJour VendInvoiceJour;
VendPromissoryNoteInvoice VendPromissoryNoteInvoice;
VendPromissoryNoteJour VendPromissoryNoteJour;
CustTrans custTrans;
VendTrans vendTrans;
// ALT_DP_20150528_LedgerMisc - begin
TaxReportPeriod taxReportPeriod;
TaxTrans taxTrans;
#ISOCountryRegionCodes
InventTrans inventTrans;
// ALT_DP_20150528_LedgerMisc - end
boolean ret = true;
;
vendTrans = VendTrans::findVoucherDate(voucher,transDate);
if (!VendTrans)
{
return checkFailed("@ANR780");
}
if (vendTrans.remainAmountCur() != vendTrans.AmountCur)
{
return checkFailed("@ANR782");
}
custTrans = custTrans::findVoucherDate(voucher,transDate);
if (custTrans)
{
return checkFailed("@ANR777");
}
while select forupdate VendInvoiceJour
where VendInvoiceJour.LedgerVoucher == voucher &&
VendInvoiceJour.InvoiceDate == transDate
{
// ALT_DP_20150528_LedgerMisc - begin
if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoIT]))
{
select firstonly RecId, TaxPeriod from taxReportPeriod
where taxReportPeriod.FromDate <= VendInvoiceJour.InvoiceDate &&
taxReportPeriod.ToDate >= VendInvoiceJour.InvoiceDate &&
taxReportPeriod.Closed
exists join taxTrans
where taxTrans.TaxPeriod == taxReportPeriod.TaxPeriod &&
taxTrans.TransDate == VendInvoiceJour.InvoiceDate &&
taxTrans.Voucher == VendInvoiceJour.LedgerVoucher;
if (taxReportPeriod)
{
return checkFailed(strFmt("@SYS79476", "@SYS79287", taxReportPeriod.TaxPeriod));
}
}
select firstonly RecId from inventTrans
where inventTrans.DateFinancial == VendInvoiceJour.InvoiceDate &&
inventTrans.Voucher == VendInvoiceJour.CostLedgerVoucher;
if (inventTrans)
{
if (! InventClosing::checkOpen(VendInvoiceJour.InvoiceDate))
return false;
}
// ALT_DP_20150528_LedgerMisc - end
while select * from VendPromissoryNoteInvoice
where VendPromissoryNoteInvoice.InvoiceVoucher == VendInvoiceJour.LedgerVoucher &&
VendPromissoryNoteInvoice.invoiceDate == VendInvoiceJour.InvoiceDate
{
select firstonly VendPromissoryNoteJour
where VendPromissoryNoteInvoice.PromissoryNoteId == VendPromissoryNoteJour.PromissoryNoteId &&
VendPromissoryNoteJour.Status != CustVendNegInstStatus::Drawn;
if (VendPromissoryNoteJour.RecId)
{
return checkFailed("@REN164");
}
}
}
return ret;
}
server static RENDeleteVendVoucher construct()
{
return new RENDeleteVendVoucher();
}
// Here goes a description of the class
static ClassDescription description()
{
return "@ANR779";
}
static void main(Args args)
{
RENDeleteVendVoucher RENDeleteVendVoucher;
VendTrans VendTrans;
FormDataSource formDataSource;
;
RENDeleteVendVoucher = RENDeleteVendVoucher::construct();
if(args && args.record() && args.dataset() == tableNum(VendTrans))
{
formDataSource = args.record().dataSource();
VendTrans.data(args.record());
RENDeleteVendVoucher.parmTransDate(VendTrans.TransDate);
RENDeleteVendVoucher.parmVoucher(VendTrans.Voucher);
}
if (RENDeleteVendVoucher.prompt())
RENDeleteVendVoucher.run();
if(formDataSource)
{
formDataSource.research();
}
}