PurchPrepayTable PurchPrepayTable;
PurchTable purchTable = purchTable::find(Z_PurchId);
PurchFormLetter purchFormLetter;
;
ttsBegin;
delete_from purchPrepayTable where purchPrepayTable.PurchTable == purchTable.PurchId;
PurchPrepayTable.Description = "";
PurchPrepayTable.Type = PurchPrepayType::Percent;
purchPrepayTable.Value = 100.00;
PurchPrepayTable.Currency = purchTable.CurrencyCode;
PurchPrepayTable.PrepayCategoryId= Z_PurchPrepayCategoryId;
PurchPrepayTable.PurchTable = purchTable.PurchId;
purchPrepayTable.recalculatePrepayLimit();
purchPrepayTable.recalculateAmounts(false);
purchPrepayTable.insert();
//Posting PO Confirmation
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchTable, Z_HachuId);
//Posting PO Invoice
purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
PurchFormLetter.parmInvoiceType(PurchInvoiceType::VendorAdvance);
purchFormLetter.update(purchTable, Z_HachuId);
ttsCommit;