[ExtensionOf(ClassStr(SalesInvoiceJournalCreateBase))]
final class salesInvoiceJournalCreateBase_Extension
{
protected void initJournalHeader()
{
Str60 packingslipId;
SalesParmSubTable SalesParmSubTableRef;
CustPackingSlipJour custPackingSlipJour;
custInvoiceJour custInvoiceJourLocal;
EEMC_PackingSlipConsumedTmp packingSlipConsumedTmp;
EEMC_PackingSlipTmp packingSlipTmp, packingSlipTmpUpdate;
CustParameters custParameters = CustParameters::find();
next initJournalHeader();
if(custParameters.EEMC_PackingSlipTOInvoice == NoYes::Yes)
{
while select SalesParmSubTableRef where SalesParmSubTableRef.ParmId==salesParmTable.ParmId && SalesParmSubTableRef.JournalRefTableId ==tableNum(CustPackingSlipJour)
{
select packingSlipTmp where packingSlipTmp.PackingSlipId == CustPackingSlipJour::findRecId(SalesParmSubTableRef.JournalRefRecId).PackingSlipId;
if(!packingSlipTmp)
{
packingslipId = CustPackingSlipJour::findRecId(SalesParmSubTableRef.JournalRefRecId).PackingSlipId;
packingSlipTmp.PackingSlipId = packingslipId;
packingSlipTmp.insert();
}
}
select firstonly packingSlipTmp where packingSlipTmp.Marked == NoYes::No;
if(packingSlipTmp)
{
if(packingSlipTmp.PackingSlipId && custParameters.EEMC_PackingSlipTOInvoice == NoYes::Yes)
{
if(custParameters.EEMC_InvoiceNonDuplicating == NoYes::Yes)
{
select custInvoiceJourLocal where custInvoiceJourLocal.InvoiceId == packingSlipTmp.PackingSlipId;
if(!custInvoiceJourLocal)
{
custInvoiceJour.InvoiceId = packingSlipTmp.PackingSlipId;
custInvoiceJour.EEMC_InvoiceId = packingSlipTmp.PackingSlipId;
select forupdate packingSlipTmpUpdate where packingSlipTmpUpdate.RecId == packingSlipTmp.RecId;
ttsbegin;
packingSlipTmpUpdate.Marked = NoYes::Yes;
packingSlipTmpUpdate.update();
ttscommit;
info(strFmt("Invoice Id : %1", packingSlipTmp.PackingSlipId));
}
else
{
throw error(strFmt("Invoice number : %1 Can't be duplicated", custInvoiceJourLocal.InvoiceId));
}
}
else
{
custInvoiceJour.InvoiceId = packingSlipTmp.PackingSlipId;
custInvoiceJour.EEMC_InvoiceId = packingSlipTmp.PackingSlipId;
select forupdate packingSlipTmpUpdate where packingSlipTmpUpdate.RecId == packingSlipTmp.RecId;
ttsbegin;
packingSlipTmpUpdate.Marked = NoYes::Yes;
packingSlipTmpUpdate.update();
ttscommit;
info(strFmt("Invoice Id : %1", packingSlipTmp.PackingSlipId));
}
}
}
}
else
{
select firstonly SalesParmSubTableRef where SalesParmSubTableRef.ParmId==salesParmTable.ParmId && SalesParmSubTableRef.JournalRefTableId ==tableNum(CustPackingSlipJour);
if(CustPackingSlipJour::findRecId(SalesParmSubTableRef.JournalRefRecId).PackingSlipId && CustParameters::find().UseDeliveryNoteAsInvoice==NoYes::Yes)
custInvoiceJour.InvoiceId= CustPackingSlipJour::findRecId(SalesParmSubTableRef.JournalRefRecId).PackingSlipId;
if(!custInvoiceJour.InvoiceId)
custInvoiceJour.InvoiceId = this.getJournalNumber();
}
}
}