public void CreateNewCreditor(BCE.Data.DBSetting dbSetting, CreditorSource source)
{
string newCreditorCode = GetNewCreditorCode(dbSetting, source.ControlAccount, source.CompanyName);
if (newCreditorCode == null)
return;
string userId = BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(dbSetting).LoginUserID;
BCE.AutoCount.ARAP.Creditor.CreditorDataAccess cmd = BCE.AutoCount.ARAP.Creditor.CreditorDataAccess.Create(dbSetting);
BCE.AutoCount.ARAP.Creditor.CreditorEntity creditor = cmd.NewCreditor();
creditor.ControlAccount = source.ControlAccount;
creditor.AccNo = newCreditorCode;
creditor.CompanyName = source.CompanyName;
creditor.Address1 = source.Addr1;
creditor.Address2 = source.Addr2;
creditor.Address3 = source.Addr3;
creditor.Address4 = source.Addr4;
creditor.Phone1 = source.Phone;
creditor.Phone2 = source.Mobile;
creditor.Attention = source.ContactPerson;
creditor.EmailAddress = source.Email;
creditor.CurrencyCode = AccountBookLocalCurrency(dbSetting);
try
{
cmd.SaveCreditor(creditor, userId);
//Log Success
}
catch (BCE.Application.AppException ex)
{
//Log fail
}
}
public string GetNewCreditorCode(BCE.Data.DBSetting dbSetting, string controlAccNo, string companyName)
{
try
{
return BCE.AutoCount.Common.AccountCodeHelper.Create(dbSetting)
.GetNextCreditorCode(controlAccNo, companyName);
}
catch (BCE.AutoCount.Common.InvalidAutoDebtorCodeFormatException ex)
{
//Log error ex.Message;
}
catch (BCE.Data.DataAccessException ex)
{
//Log error ex.Message;
}
//If the catch throw out exception, then return null is not necessary.
return null;
}
public string AccountBookLocalCurrency(BCE.Data.DBSetting dbSetting)
{
return BCE.Data.DBRegistry.Create(dbSetting).GetString(new BCE.AutoCount.RegistryID.LocalCurrencyCode());
}
public class CreditorSource
{
public string ControlAccount { get; set; }
public string CreditorCode { get; set; }
public string CompanyName { get; set; }
public string Addr1 { get; set; }
public string Addr2 { get; set; }
public string Addr3 { get; set; }
public string Addr4 { get; set; }
public string Phone { get; set; }
public string Mobile { get; set; }
public string ContactPerson { get; set; }
public string Email { get; set; }
}
public void TesterMain(BCE.Data.DBSetting dbSetting)
{
CreditorSource newCreditor = new CreditorSource()
{
ControlAccount = "400-0000",
//CreditorCode = "410C001", //Ignore CreditorCode, if let system auto assign
CompanyName = "CALIFORNIA SB",
Addr1 = "1, Jalan SS 1/1,",
Addr2 = "Taman Gembira,",
Addr3 = "Selangor Darah Ehsan,",
Addr4 = "41300 Malaysia.",
Phone = "603-719 1992",
Mobile = "016-221 2222",
ContactPerson = "Ben",
Email = "ben@calimail.com",
};
CreateNewCreditor(dbSetting, newCreditor);
}