I have some difficulty to create a receipt Prepayment with accpac Erp 5.5 on C# or in VBA. I don't know witch view I need to use to apply to my customer is it AR0061 or AR0044. I try to use rvspy but a lot of information is create on this file ....
Here my code in C# but when I post this batch, batch error is created.
DBLink dbLinkMain;
//Connection à ACCPAC
ACCPAC.Advantage.Session session = new ACCPAC.Advantage.Session();
session.Init("", "AR", "AR1234", "55A");
session.Open("ADMIN", "ADMIN", "SAMINC", DateTime.Today, 0);
dbLinkMain = session.OpenDBLink(DBLinkType.Company, DBLinkFlags.ReadWrite);
try
{
ACCPAC.Advantage.View ARRECMAC1batch = dbLinkMain.OpenView("AR0041");
ACCPAC.Advantage.ViewFields ARRECMAC1batchFields = ARRECMAC1batch.Fields;
ACCPAC.Advantage.View ARRECMAC1header = dbLinkMain.OpenView("AR0042");
ACCPAC.Advantage.ViewFields ARRECMAC1headerFields = ARRECMAC1header.Fields;
ACCPAC.Advantage.View ARRECMAC1detail1 = dbLinkMain.OpenView("AR0044");
ACCPAC.Advantage.ViewFields ARRECMAC1detail1Fields = ARRECMAC1detail1.Fields;
ACCPAC.Advantage.View ARRECMAC1detail2 = dbLinkMain.OpenView("AR0045");
ACCPAC.Advantage.ViewFields ARRECMAC1detail2Fields = ARRECMAC1detail2.Fields;
ACCPAC.Advantage.View ARRECMAC1detail3 = dbLinkMain.OpenView("AR0043");
ACCPAC.Advantage.ViewFields ARRECMAC1detail3Fields = ARRECMAC1detail3.Fields;
ACCPAC.Advantage.View ARRECMAC1detail4 = dbLinkMain.OpenView("AR0061");
ACCPAC.Advantage.ViewFields ARRECMAC1detail4Fields = ARRECMAC1detail4.Fields;
ACCPAC.Advantage.View ARRECMAC1detail5 = dbLinkMain.OpenView("AR0406");
ACCPAC.Advantage.ViewFields ARRECMAC1detail5Fields = ARRECMAC1detail5.Fields;
ACCPAC.Advantage.View ARRECMAC1detail6 = dbLinkMain.OpenView("AR0170");
ACCPAC.Advantage.ViewFields ARRECMAC1detail6Fields = ARRECMAC1detail6.Fields;
ACCPAC.Advantage.View[] ARRECMAC1batchVArr = { ARRECMAC1header };
ARRECMAC1batch.Compose(ARRECMAC1batchVArr);
ACCPAC.Advantage.View[] ARRECMAC1headerVArr = { ARRECMAC1batch, ARRECMAC1detail3, ARRECMAC1detail1, ARRECMAC1detail5, ARRECMAC1detail6 };
ARRECMAC1header.Compose(ARRECMAC1headerVArr);
ACCPAC.Advantage.View[] ARRECMAC1detail1VArr = { ARRECMAC1header, ARRECMAC1detail2, ARRECMAC1detail4 };
ARRECMAC1detail1.Compose(ARRECMAC1detail1VArr);
ACCPAC.Advantage.View[] ARRECMAC1detail2VArr = { ARRECMAC1detail1 };
ARRECMAC1detail2.Compose(ARRECMAC1detail2VArr);
ACCPAC.Advantage.View[] ARRECMAC1detail3VArr = { ARRECMAC1header };
ARRECMAC1detail3.Compose(ARRECMAC1detail3VArr);
ACCPAC.Advantage.View[] ARRECMAC1detail4VArr = { ARRECMAC1batch, ARRECMAC1header, ARRECMAC1detail3, ARRECMAC1detail1, ARRECMAC1detail2 };
ARRECMAC1detail4.Compose(ARRECMAC1detail4VArr);
ACCPAC.Advantage.View[] ARRECMAC1detail5VArr = { ARRECMAC1header };
ARRECMAC1detail5.Compose(ARRECMAC1detail5VArr);
ACCPAC.Advantage.View[] ARRECMAC1detail6VArr = { ARRECMAC1header };
ARRECMAC1detail6.Compose(ARRECMAC1detail6VArr);
ARRECMAC1batch.Fields.FieldByName("CODEPYMTYP").SetValue("CA", true);
ARRECMAC1batch.Init();
ARRECMAC1header.Fields.FieldByName("CODEPYMTYP").SetValue("CA", true);
ARRECMAC1header.Fields.FieldByName("CNTITEM").SetValue(1, true);
ARRECMAC1batch.Fields.FieldByName("DATEBTCH").SetValue(DateTime.Today, true);
ARRECMAC1batch.Fields.FieldByName("BATCHDESC").SetValue("CVent", true);
ARRECMAC1batch.Fields.FieldByName("IDBANK").SetValue("GENERAL", true);
string description = "Cvent (Test :" + DateTime.Today.ToString("dd/MM/yyy");
ARRECMAC1batch.Fields.FieldByName("BATCHDESC").SetValue(description, true);
//new
ARRECMAC1batch.Fields.FieldByName("PROCESSCMD").SetValue(2, true);
ARRECMAC1batch.Update();
int NoBatch = Convert.ToInt32(ARRECMAC1batch.Fields.FieldByName("CNTBTCH").Value);
ARRECMAC1header.Fields.FieldByName("CNTITEM").SetValue(0, false);
ARRECMAC1header.Init();
int NoItem = Convert.ToInt32(ARRECMAC1header.Fields.FieldByName("CNTITEM").Value);
ARRECMAC1header.Fields.FieldByName("RMITTYPE").SetValue(2, true);
ARRECMAC1header.Process();
ARRECMAC1header.Fields.FieldByName("IDCUST").SetValue("99915", true);
ARRECMAC1header.Process();
//ARRECMAC1detail1.RecordClear();
//ARRECMAC1detail1.RecordCreate(ViewRecordCreate.Insert);
ARRECMAC1header.Fields.FieldByName("CODEPAYM").SetValue("MCDWEB", true);
ARRECMAC1header.Fields.FieldByName("DATERMIT").SetValue(DateTime.Today, true);
ARRECMAC1header.Fields.FieldByName("IDRMIT").SetValue("4090test", true);
ARRECMAC1header.Fields.FieldByName("AMTRMIT").SetValue(197.54, true);
//TXTRMITREF
//ARRECMAC1header.Fields.FieldByName("TXTRMITREF").SetValue("testref", true);
ARRECMAC1header.Fields.FieldByName("DOCTYPE").SetValue(4, true);
ARRECMAC1header.Fields.FieldByName("IDINVCMTCH").SetValue("TestFacture", true);
ARRECMAC1header.Fields.FieldByName("IDINVCMTCH").SetValue("TestFacture", true);
//ARRECMAC1detail1.Fields.FieldByName("IDCUST").SetValue("99915", true);
//ARRECMAC1detail1.Fields.FieldByName("AMTPAYM").SetValue(197.54, true);
//ARRECMAC1detail1.Fields.FieldByName("IDDOCMTCH").SetValue("TestFacture", true);
//ARRECMAC1detail1.RecordCreate(ViewRecordCreate.Insert);
ARRECMAC1detail4.Init();
ARRECMAC1detail4.Fields.FieldByName("PAYMTYPE").SetValue("CA", true);
ARRECMAC1detail4.Fields.FieldByName("CNTBTCH").SetValue(NoBatch, true);
ARRECMAC1detail4.Fields.FieldByName("CNTITEM").SetValue(NoItem, true);
ARRECMAC1detail4.Fields.FieldByName("IDCUST").SetValue("99915", true);
ARRECMAC1detail4.Fields.FieldByName("AMTRMIT").SetValue(197.54, true);
//ARRECMAC1detail4.Fields.FieldByName("PAYMAMT").SetValue(197.54, true);
ARRECMAC1detail4.Fields.FieldByName("ORDRNBR").SetValue("TestFacture", true);
ARRECMAC1detail4.Fields.FieldByName("TRXTYPE").SetValue(10, true);
ARRECMAC1detail4.Fields.FieldByName("STDOCDTE").SetValue(DateTime.Today, true);
ARRECMAC1detail4.Process();
//ARRECMAC1detail1.Fields.FieldByName("IDCUST").SetValue("99915", true);
//ARRECMAC1detail1.Fields.FieldByName("AMTPAYM").SetValue(197.54, true);
//ARRECMAC1detail1.Fields.FieldByName("IDDOCMTCH").SetValue("TestFacture", true);
//ARRECMAC1detail1.Fields.FieldByName("CDAPPLYTO").SetValue(4, true);
ARRECMAC1detail4.Insert();
ARRECMAC1header.Insert();
}
catch (Exception ex)
{
for (int i = 0; i < dbLinkMain.Parent.Errors.Count; i++)
{
Console.WriteLine(dbLinkMain.Parent.Errors.Message);
Console.ReadLine();
}
Console.WriteLine(ex.ToString());
}
}
Here my code in C# but when I post this batch, batch error is created.
DBLink dbLinkMain;
//Connection à ACCPAC
ACCPAC.Advantage.Session session = new ACCPAC.Advantage.Session();
session.Init("", "AR", "AR1234", "55A");
session.Open("ADMIN", "ADMIN", "SAMINC", DateTime.Today, 0);
dbLinkMain = session.OpenDBLink(DBLinkType.Company, DBLinkFlags.ReadWrite);
try
{
ACCPAC.Advantage.View ARRECMAC1batch = dbLinkMain.OpenView("AR0041");
ACCPAC.Advantage.ViewFields ARRECMAC1batchFields = ARRECMAC1batch.Fields;
ACCPAC.Advantage.View ARRECMAC1header = dbLinkMain.OpenView("AR0042");
ACCPAC.Advantage.ViewFields ARRECMAC1headerFields = ARRECMAC1header.Fields;
ACCPAC.Advantage.View ARRECMAC1detail1 = dbLinkMain.OpenView("AR0044");
ACCPAC.Advantage.ViewFields ARRECMAC1detail1Fields = ARRECMAC1detail1.Fields;
ACCPAC.Advantage.View ARRECMAC1detail2 = dbLinkMain.OpenView("AR0045");
ACCPAC.Advantage.ViewFields ARRECMAC1detail2Fields = ARRECMAC1detail2.Fields;
ACCPAC.Advantage.View ARRECMAC1detail3 = dbLinkMain.OpenView("AR0043");
ACCPAC.Advantage.ViewFields ARRECMAC1detail3Fields = ARRECMAC1detail3.Fields;
ACCPAC.Advantage.View ARRECMAC1detail4 = dbLinkMain.OpenView("AR0061");
ACCPAC.Advantage.ViewFields ARRECMAC1detail4Fields = ARRECMAC1detail4.Fields;
ACCPAC.Advantage.View ARRECMAC1detail5 = dbLinkMain.OpenView("AR0406");
ACCPAC.Advantage.ViewFields ARRECMAC1detail5Fields = ARRECMAC1detail5.Fields;
ACCPAC.Advantage.View ARRECMAC1detail6 = dbLinkMain.OpenView("AR0170");
ACCPAC.Advantage.ViewFields ARRECMAC1detail6Fields = ARRECMAC1detail6.Fields;
ACCPAC.Advantage.View[] ARRECMAC1batchVArr = { ARRECMAC1header };
ARRECMAC1batch.Compose(ARRECMAC1batchVArr);
ACCPAC.Advantage.View[] ARRECMAC1headerVArr = { ARRECMAC1batch, ARRECMAC1detail3, ARRECMAC1detail1, ARRECMAC1detail5, ARRECMAC1detail6 };
ARRECMAC1header.Compose(ARRECMAC1headerVArr);
ACCPAC.Advantage.View[] ARRECMAC1detail1VArr = { ARRECMAC1header, ARRECMAC1detail2, ARRECMAC1detail4 };
ARRECMAC1detail1.Compose(ARRECMAC1detail1VArr);
ACCPAC.Advantage.View[] ARRECMAC1detail2VArr = { ARRECMAC1detail1 };
ARRECMAC1detail2.Compose(ARRECMAC1detail2VArr);
ACCPAC.Advantage.View[] ARRECMAC1detail3VArr = { ARRECMAC1header };
ARRECMAC1detail3.Compose(ARRECMAC1detail3VArr);
ACCPAC.Advantage.View[] ARRECMAC1detail4VArr = { ARRECMAC1batch, ARRECMAC1header, ARRECMAC1detail3, ARRECMAC1detail1, ARRECMAC1detail2 };
ARRECMAC1detail4.Compose(ARRECMAC1detail4VArr);
ACCPAC.Advantage.View[] ARRECMAC1detail5VArr = { ARRECMAC1header };
ARRECMAC1detail5.Compose(ARRECMAC1detail5VArr);
ACCPAC.Advantage.View[] ARRECMAC1detail6VArr = { ARRECMAC1header };
ARRECMAC1detail6.Compose(ARRECMAC1detail6VArr);
ARRECMAC1batch.Fields.FieldByName("CODEPYMTYP").SetValue("CA", true);
ARRECMAC1batch.Init();
ARRECMAC1header.Fields.FieldByName("CODEPYMTYP").SetValue("CA", true);
ARRECMAC1header.Fields.FieldByName("CNTITEM").SetValue(1, true);
ARRECMAC1batch.Fields.FieldByName("DATEBTCH").SetValue(DateTime.Today, true);
ARRECMAC1batch.Fields.FieldByName("BATCHDESC").SetValue("CVent", true);
ARRECMAC1batch.Fields.FieldByName("IDBANK").SetValue("GENERAL", true);
string description = "Cvent (Test :" + DateTime.Today.ToString("dd/MM/yyy");
ARRECMAC1batch.Fields.FieldByName("BATCHDESC").SetValue(description, true);
//new
ARRECMAC1batch.Fields.FieldByName("PROCESSCMD").SetValue(2, true);
ARRECMAC1batch.Update();
int NoBatch = Convert.ToInt32(ARRECMAC1batch.Fields.FieldByName("CNTBTCH").Value);
ARRECMAC1header.Fields.FieldByName("CNTITEM").SetValue(0, false);
ARRECMAC1header.Init();
int NoItem = Convert.ToInt32(ARRECMAC1header.Fields.FieldByName("CNTITEM").Value);
ARRECMAC1header.Fields.FieldByName("RMITTYPE").SetValue(2, true);
ARRECMAC1header.Process();
ARRECMAC1header.Fields.FieldByName("IDCUST").SetValue("99915", true);
ARRECMAC1header.Process();
//ARRECMAC1detail1.RecordClear();
//ARRECMAC1detail1.RecordCreate(ViewRecordCreate.Insert);
ARRECMAC1header.Fields.FieldByName("CODEPAYM").SetValue("MCDWEB", true);
ARRECMAC1header.Fields.FieldByName("DATERMIT").SetValue(DateTime.Today, true);
ARRECMAC1header.Fields.FieldByName("IDRMIT").SetValue("4090test", true);
ARRECMAC1header.Fields.FieldByName("AMTRMIT").SetValue(197.54, true);
//TXTRMITREF
//ARRECMAC1header.Fields.FieldByName("TXTRMITREF").SetValue("testref", true);
ARRECMAC1header.Fields.FieldByName("DOCTYPE").SetValue(4, true);
ARRECMAC1header.Fields.FieldByName("IDINVCMTCH").SetValue("TestFacture", true);
ARRECMAC1header.Fields.FieldByName("IDINVCMTCH").SetValue("TestFacture", true);
//ARRECMAC1detail1.Fields.FieldByName("IDCUST").SetValue("99915", true);
//ARRECMAC1detail1.Fields.FieldByName("AMTPAYM").SetValue(197.54, true);
//ARRECMAC1detail1.Fields.FieldByName("IDDOCMTCH").SetValue("TestFacture", true);
//ARRECMAC1detail1.RecordCreate(ViewRecordCreate.Insert);
ARRECMAC1detail4.Init();
ARRECMAC1detail4.Fields.FieldByName("PAYMTYPE").SetValue("CA", true);
ARRECMAC1detail4.Fields.FieldByName("CNTBTCH").SetValue(NoBatch, true);
ARRECMAC1detail4.Fields.FieldByName("CNTITEM").SetValue(NoItem, true);
ARRECMAC1detail4.Fields.FieldByName("IDCUST").SetValue("99915", true);
ARRECMAC1detail4.Fields.FieldByName("AMTRMIT").SetValue(197.54, true);
//ARRECMAC1detail4.Fields.FieldByName("PAYMAMT").SetValue(197.54, true);
ARRECMAC1detail4.Fields.FieldByName("ORDRNBR").SetValue("TestFacture", true);
ARRECMAC1detail4.Fields.FieldByName("TRXTYPE").SetValue(10, true);
ARRECMAC1detail4.Fields.FieldByName("STDOCDTE").SetValue(DateTime.Today, true);
ARRECMAC1detail4.Process();
//ARRECMAC1detail1.Fields.FieldByName("IDCUST").SetValue("99915", true);
//ARRECMAC1detail1.Fields.FieldByName("AMTPAYM").SetValue(197.54, true);
//ARRECMAC1detail1.Fields.FieldByName("IDDOCMTCH").SetValue("TestFacture", true);
//ARRECMAC1detail1.Fields.FieldByName("CDAPPLYTO").SetValue(4, true);
ARRECMAC1detail4.Insert();
ARRECMAC1header.Insert();
}
catch (Exception ex)
{
for (int i = 0; i < dbLinkMain.Parent.Errors.Count; i++)
{
Console.WriteLine(dbLinkMain.Parent.Errors.Message);
Console.ReadLine();
}
Console.WriteLine(ex.ToString());
}
}