AR Debtor v2: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 168:
 
CreateNewDebtor(dbSetting, newDebtor);
}
</syntaxhighlight>
 
==Branch for Debtor==
===Create New Debtor with Branch===
<syntaxhighlight lang="csharp">
public string NewDebtorWithBranch()
{
string debtorControlAccount = "300-0000";
string companyName = "ABC Company";
 
AutoCount.ARAP.Debtor.DebtorDataAccess cmd =
AutoCount.ARAP.Debtor.DebtorDataAccess.Create(myUserSession, myUserSession.DBSetting);
AutoCount.ARAP.Debtor.DebtorEntity debtor = cmd.NewDebtor();
 
string autoNewDebtorCode = GetNewDebtorCode(myUserSession, debtorControlAccount, companyName);
if (autoNewDebtorCode == null)
return null;
 
debtor.ControlAccount = debtorControlAccount;
debtor.AccNo = autoNewDebtorCode;
debtor.CompanyName = companyName;
debtor.Address1 = "<assign address 1>";
debtor.Address2 = "<assign address 2>";
debtor.Address3 = "<assign address 3>";
debtor.Address4 = "<assign address 4>";
debtor.Phone1 = "<assign phone 1>";
debtor.Phone2 = "<assign phone 2>";
debtor.Attention = "<assign attention>";
debtor.EmailAddress = "<assign email address>";
debtor.CurrencyCode = AccountBookLocalCurrency(myUserSession); //Get default account book currency
 
//Create new branch
AddNewBranch(debtor);
 
cmd.SaveDebtor(debtor, myUserSession.LoginUserID);
return debtor.AccNo;
}
 
private void AddNewBranch(AutoCount.ARAP.Debtor.DebtorEntity debtor)
{
AutoCount.ARAP.Debtor.BranchEntity branch = debtor.NewBranch();
branch.BranchCode = "Branch0001"; //Size=20
branch.BranchName = "Branch 0001"; //Size=100
branch.Address1 = null;
branch.Address2 = null;
branch.Address3 = null;
branch.Address4 = null;
branch.PostCode = null;
branch.Mobile = null;
branch.Contact = null;
branch.Phone1 = null;
branch.Phone2 = null;
branch.Fax1 = null;
branch.Fax2 = null;
branch.SalesAgent = null;
branch.AreaCode = null;
branch.EmailAddress = null;
}
</syntaxhighlight>
 
===New or update Debtor with Branch===
<syntaxhighlight lang="csharp">
public string NewUpdateDebtorWithBranch(string debtorAccNo)
{
string debtorControlAccount = "300-0000";
string companyName = "ABC Company";
string branchCode = "Branch01";
 
AutoCount.ARAP.Debtor.DebtorDataAccess cmd = AutoCount.ARAP.Debtor.DebtorDataAccess.Create(myUserSession, myUserSession.DBSetting);
//Load Debtor record
AutoCount.ARAP.Debtor.DebtorEntity debtor = cmd.GetDebtor(debtorAccNo);
//If debtor record is not found
if (debtor == null)
{
string autoNewDebtorCode = GetNewDebtorCode(myUserSession, debtorControlAccount, companyName);
if (autoNewDebtorCode == null)
return null;
 
debtor = cmd.NewDebtor();
//AccNo and CurrencyCode cannot be changed when already has transaction or being referenced in document.
debtor.AccNo = autoNewDebtorCode;
debtor.CurrencyCode = AccountBookLocalCurrency(myUserSession); //Get default account book currency
}
 
debtor.ControlAccount = debtorControlAccount;
debtor.CompanyName = companyName;
debtor.Address1 = "<assign address 1>";
debtor.Address2 = "<assign address 2>";
debtor.Address3 = "<assign address 3>";
debtor.Address4 = "<assign address 4>";
debtor.Phone1 = "<assign phone 1>";
debtor.Phone2 = "<assign phone 2>";
debtor.Attention = "<assign attention>";
debtor.EmailAddress = "<assign email address>";
 
//Create new branch
AddUpdateBranch(debtor, branchCode);
 
cmd.SaveDebtor(debtor, myUserSession.LoginUserID);
return debtor.AccNo;
}
private void AddUpdateBranch(AutoCount.ARAP.Debtor.DebtorEntity debtor, string branchCode)
{
AutoCount.ARAP.Debtor.BranchEntity branch = debtor.GetBranch(branchCode);
if (branch == null)
{
branch = debtor.GetBranch(branchCode);
}
branch.BranchName = "Branch 0001";
branch.Address1 = "address 1";
branch.Address2 = "address 2";
branch.Address3 = "address 3";
branch.Address4 = "address 4";
branch.PostCode = "2100";
branch.Mobile = "099123456";
branch.Contact = "Kenneth";
branch.Phone1 = "099123456";
branch.Phone2 = "099123456";
branch.Fax1 = null;
branch.Fax2 = null;
branch.SalesAgent = null;
branch.AreaCode = null;
branch.EmailAddress = null;
}
</syntaxhighlight>