C Journal Batches

From Sage Evolution SDK | Documentation Portal
Jump to: navigation, search

Journal Batches can be created and populated by the SDK. However they cannot be processed.

The following example displays how to create and save a Journal Batch.

{
    string BatchNum = "JB002";
    //check if Batch code exists in pastel
    if (JournalBatch.FindByCode(BatchNum) == -1)
    {
        // Batch code does not exist, then create it
        JournalBatch createbatch = new JournalBatch();
        createbatch.Code = BatchNum;
        createbatch.Description = "JB Batch";
        createbatch.Owner = new Agent("Admin");
        createbatch.Save();
    }
 
    JournalBatch batch = new JournalBatch(BatchNum);
 
    var detail = new JournalBatchDetail();
    detail.Date = DateTime.Today;
    detail.Account = new GLAccount("Advertising");
    detail.Debit = 500;
    detail.Description = "So and so";
    detail.Reference = "Ref001";
    batch.Detail.Add(detail);
    batch.Save();//Save each JournalBatchDetail seperately or comment out to save both together
 
    detail = new JournalBatchDetail();
    detail.Date = DateTime.Today;
    detail.Account = new GLAccount("Advertising");
    detail.Credit = 500;
    detail.Description = "So and so";
    detail.Reference = "Ref001";
    detail.Tax = 50;
    detail.TaxRate = new TaxRate(1);//Specify a tax type
    detail.TaxAccount = new GLAccount("Accruals");//Specify a tax account
    batch.Detail.Add(detail);
    batch.Save();
 
    //If required the clone method can be used to copy the previous line
    batch = new JournalBatch(batch.Code);
    batch.Detail.Add(detail.Clone());
    batch.Save();
}