Hey Guys,
We are using SAGE 300 ERP. Also I am uisng respective AOM. Last some days I am trying to compose and post the data to AP-Payment entry as Misc payment) through API defined on ACCPAC.Advantage. But I am getting error as "1024" while i am trying to execute following statement of CreatePaymentBatch method (First line of that method)
// 1. RecordCreate batch to get the next available key for the batch.
_apPaymentBatch.RecordCreate(ViewRecordCreate.Insert);
This is the program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACCPAC.Advantage;
using SAGE.Entity;
using SAGE.Accessor.Base;
namespace SAGE.Accessor.SAGEViews
{
public class AP0030PaymentEntryCompositeView : IDisposable
{
DBLink _link;
IConnectionManager _connectionManager;
private View _apPaymentBatch;
private View _apPaymentHeader;
private View _apMiscellaneousPaymentDetail;
private View _apAppliedPaymentsDetail;
//private View _apAdjustmentAndDistributionDetailField;
//private View _apCreateOpenDocumentListFlat;
private View _apAdvanceCreditsDetail;
private View _apPaymentOptionalFields;
//private View _apPaymentControl;
//private View _apGeneratePaymentBatch;
public AP0030PaymentEntryCompositeView(string userName, string password)
{
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
{
_connectionManager = ConnectionManager.GetInstance(userName, password);
_link = _connectionManager.Connection;
}
else
{
_connectionManager = ConnectionManager.GetInstance();
_link = _connectionManager.Connection;
}
_apPaymentBatch = _link.OpenView("AP0030");
_apPaymentHeader = _link.OpenView("AP0031");
_apMiscellaneousPaymentDetail = _link.OpenView("AP0032");
_apAppliedPaymentsDetail = _link.OpenView("AP0033");
_apAdvanceCreditsDetail = _link.OpenView("AP0170");
_apPaymentOptionalFields = _link.OpenView("AP0406");
_apPaymentBatch.Compose(new View[] { _apPaymentHeader });
_apPaymentHeader.Compose(new View[] { _apPaymentBatch, _apMiscellaneousPaymentDetail, _apAppliedPaymentsDetail, _apPaymentOptionalFields,_apAdvanceCreditsDetail });
_apMiscellaneousPaymentDetail.Compose(new View[] { _apPaymentHeader });
_apAppliedPaymentsDetail.Compose(new View[] { _apPaymentHeader});
_apPaymentOptionalFields.Compose(new View[] { _apPaymentHeader });
}
public SAGEAPMiscellaneousPaymentBatch CreatePaymentBatch(SAGEAPMiscellaneousPaymentBatch miscBatchPayment)
{
try
{
// 1. RecordCreate batch to get the next available key for the batch.
_apPaymentBatch.RecordCreate(ViewRecordCreate.Insert);
// 2. Set the fields in the batch.
_apPaymentBatch.Fields.FieldByName("BATCHDESC").SetValue(miscBatchPayment.BATCHDESC, false);
_apPaymentBatch.Fields.FieldByName("IDBANK").SetValue(miscBatchPayment.IDBANK, true);
// 3. Update batch. (The batch record is already inserted by the RecordGenerate call, in step 1.)
_apPaymentBatch.Update();
//Get the batch control number
miscBatchPayment.CNTBTCH = _apPaymentBatch.Fields.Convert<int>("CNTBTCH");
foreach (SAGEPaymentHeader header in miscBatchPayment.SAGEPaymentHeader)
{
// 4. RecordCreate header to get the next available key for the header. The key for the batch in the header view is assumed to be set already.
_apPaymentHeader.RecordCreate(ViewRecordCreate.DelayKey);
// 5. Set the fields in the header.
//Set the payment type
_apPaymentHeader.Fields.FieldByName("RMITTYPE").SetValue(4, true);
//Set the check number
_apPaymentHeader.Fields.FieldByName("IDRMIT").SetValue(header.IDRMIT, false);
//Set the check date
_apPaymentHeader.Fields.FieldByName("DATERMIT").SetValue(header.DATERMIT, false);
//Set the payee name
_apPaymentHeader.Fields.FieldByName("NAMERMIT").SetValue(header.NAMERMIT, false);
//Set the check language
_apPaymentHeader.Fields.FieldByName("CHECKLANG").SetValue(header.CHECKLANG, false);
//Set the check reference description
_apPaymentHeader.Fields.FieldByName("TXTRMITREF").SetValue(header.TXTRMITREF, false);
//Set the invoice number
_apPaymentHeader.Fields.FieldByName("IDINVCMTCH").SetValue(header.IDINVCMTCH, false);
int detailLineNumber = 0;
foreach (SAGEPaymentDetail paymentDetail in header.PaymentDetail)
{
// 6. RecordCreate detail to initialize the fields.
_apMiscellaneousPaymentDetail.RecordCreate(ViewRecordCreate.NoInsert);
//Set the fields
//Set the control number
_apMiscellaneousPaymentDetail.Fields.FieldByName("CNTLINE").SetValue(detailLineNumber, false);
paymentDetail.CNTLINE = detailLineNumber;
//Set the GL account number
_apMiscellaneousPaymentDetail.Fields.FieldByName("IDACCT").SetValue(paymentDetail.IDACCT, true);
//Set the reference
_apMiscellaneousPaymentDetail.Fields.FieldByName("GLREF").SetValue(paymentDetail.GLREF, false);
//Set the amount
_apMiscellaneousPaymentDetail.Fields.FieldByName("AMTNETTC").SetValue(paymentDetail.AMTNETTC, false);
_apMiscellaneousPaymentDetail.Fields.FieldByName("AMTDISTTC").SetValue(paymentDetail.AMTDISTTC, false);
_apMiscellaneousPaymentDetail.Fields.FieldByName("AMTDISTHC").SetValue(paymentDetail.AMTDISTHC, false);
_apMiscellaneousPaymentDetail.Fields.FieldByName("AMTNETHC").SetValue(paymentDetail.AMTNETHC, false);
// 9. Insert detail.
_apMiscellaneousPaymentDetail.Insert();// Insert the detail line (only in memory at this point).
detailLineNumber++;
}
// 11. Insert header. (This will do a Post of the details.)
_apPaymentHeader.Insert();
header.CNTENTR = _apPaymentHeader.Fields.Convert<int>("CNTENTR");
}
}
catch (ViewException ex)
{
}
catch (Exception dx)
{
}
return miscBatchPayment;
}
public void Dispose()
{
_apPaymentOptionalFields.Dispose();
//_apAdvanceCreditsDetail.Dispose();
//_apCreateOpenDocumentListFlat.Dispose();
//_apAdjustmentAndDistributionDetailField.Dispose();
//_apAppliedPaymentsDetail.Dispose();
_apMiscellaneousPaymentDetail.Dispose();
_apPaymentHeader.Dispose();
_apPaymentBatch.Dispose();
_link.Dispose();
}
}
}
Entites
-------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SAGE.Entity
{
/// <summary>
/// APBTA - AP Payment Batch
/// </summary>
public class SAGEAPMiscellaneousPaymentBatch
{
public SAGEAPMiscellaneousPaymentBatch()
{
SAGEPaymentHeader = new List<SAGEPaymentHeader>();
}
/// <summary>
/// Payment batch type
/// </summary>
public string BTCHTYPE { get; set; }
/// <summary>
/// Batch number
/// </summary>
public int CNTBTCH { get; set; }
/// <summary>
/// Batch description
/// </summary>
public string BATCHDESC { get; set; }
/// <summary>
/// Bank information
/// </summary>
public string IDBANK { get; set; }
/// <summary>
/// SAGE Payment header
/// </summary>
public List<SAGEPaymentHeader> SAGEPaymentHeader { get; set; }
}
/// <summary>
/// APTCR - AP Payment Header
/// </summary>
public class SAGEPaymentHeader
{
public SAGEPaymentHeader()
{
PaymentDetail = new List<SAGEPaymentDetail>();
}
/// <summary>
/// Entry number
/// </summary>
public int CNTENTR { get; set; }
/// <summary>
/// Check number
/// </summary>
public string IDRMIT { get; set; }
/// <summary>
/// Check date
/// </summary>
public DateTime DATERMIT { get; set; }
/// <summary>
/// Payee name
/// </summary>
public string NAMERMIT { get; set; }
/// <summary>
/// Payment language
/// </summary>
public string CHECKLANG { get; set; }
/// <summary>
/// Entry reference
/// </summary>
public string TXTRMITREF { get; set; }
/// <summary>
/// Invoice number
/// </summary>
public string IDINVCMTCH { get; set; }
/// <summary>
/// Payment Detail
/// </summary>
public List<SAGEPaymentDetail> PaymentDetail { get; set; }
}
/// <summary>
/// APTCN - Miscellaneous Payments (Detail)
/// </summary>
public class SAGEPaymentDetail
{
/// <summary>
/// Line number
/// </summary>
public int CNTLINE { get; set; }
/// <summary>
/// GL Account
/// </summary>
public string IDACCT { get; set; }
/// <summary>
/// GL Reference
/// </summary>
public string GLREF { get; set; }
/// <summary>
/// GL Description
/// </summary>
public string GLDESC { get; set; }
/// <summary>
/// Amount
/// </summary>
public decimal AMTNETTC { get; set; }
/// <summary>
/// Distribution amount
/// </summary>
public decimal AMTDISTTC { get { return AMTNETTC; } }
/// <summary>
/// Func. Dist. Amount
/// </summary>
public decimal AMTDISTHC { get { return AMTNETTC; } }
/// <summary>
/// Func. Dist. Amount Net of Taxes
/// </summary>
public decimal AMTNETHC { get { return AMTNETTC; } }
}
}
Data like
------------
SAGEAPMiscellaneousPaymentBatch batch = new SAGEAPMiscellaneousPaymentBatch();
batch.BATCHDESC = "Service testing bacth";
batch.IDBANK = "HUNT01";
var payment1 = new SAGEPaymentHeader()
{
IDRMIT = "69563",
DATERMIT = DateTime.Now.AddDays(-12),
NAMERMIT = "Jeff",
CHECKLANG = "ENG",
TXTRMITREF = "First record",
IDINVCMTCH = "5675432",
};
payment1.PaymentDetail.Add(new SAGEPaymentDetail() { IDACCT = "0103-000", GLREF = "Line number 12", AMTNETTC = 250.57m });
batch.SAGEPaymentHeader.Add(payment1);
var payment2 = new SAGEPaymentHeader()
{
IDRMIT = "69564",
DATERMIT = DateTime.Now.AddDays(-12),
NAMERMIT = "Nergis",
CHECKLANG = "ENG",
TXTRMITREF = "Second record",
IDINVCMTCH = "5675442",
};
payment2.PaymentDetail.Add(new SAGEPaymentDetail() { IDACCT = "0103-000", GLREF = "Line number 56", AMTNETTC = 1653.86m });
batch.SAGEPaymentHeader.Add(payment2);
paymentEntryApp.CreateBatchPayment(batch);
Any one can take a look. Thank in advance