AR Debtor v2: Difference between revisions

mNo edit summary
 
(10 intermediate revisions by the same user not shown)
Line 1:
===References of AutoCount Accounting version 2.0===
{{BaseReferenceAC20}}
'''AutoCount.ARAP.dll'''
 
==Load Data with API==
===Single Record===
Load one debtor by specifying the DebtorCode (AccNo).
<syntaxhighlight lang="csharp">
public void ExampleOfSingleDebtorRecord(string accNo, AutoCount.Data.DBSetting dbset)
{
AutoCount.Data.DebtorRecord debtorRec = AutoCount.Data.RecordUtils.GetDebtor(dbset, accNo);
if (debtorRec != null)
{
string companyName = debtorRec.CompanyName;
string addr1 = debtorRec.Address1;
string addr2 = debtorRec.Address2;
string addr3 = debtorRec.Address3;
string addr4 = debtorRec.Address4;
string attention = debtorRec.Attention;
string phone = debtorRec.Phone1;
decimal? creditLimit = debtorRec.CreditLimit;
decimal? overdueLimit = debtorRec.OverdueLimit;
}
}
</syntaxhighlight>
===Multiple Records with Filter===
Load more than one debtor.<br/>
Programmer can specify which columns to load, while defining the filter of which debtor to be loaded.<br/>
This example shows how to load debtor that was modified since a specific date.
<syntaxhighlight lang="csharp">
public System.Data.DataTable GetModifiedDebtorData(DateTime filterFromDate, AutoCount.Authentication.UserSession userSession)
{
//Create a DataAccess object of Debtor
AutoCount.ARAP.Debtor.DebtorDataAccess cmd =
AutoCount.ARAP.Debtor.DebtorDataAccess.Create(userSession, userSession.DBSetting);
 
//Create debtor data loading criteria
AutoCount.SearchFilter.SearchCriteria loadDebtorCriteria =
new AutoCount.SearchFilter.SearchCriteria();
 
//SearchCriteria requires a SearchFilter
//Create the SearchFilter by Range
AutoCount.SearchFilter.Filter filterLastModified =
new AutoCount.SearchFilter.Filter("a", "LastModified");
filterLastModified.Type = AutoCount.SearchFilter.FilterType.ByRange;
 
//When .To is not define, the filter is from the lastModifiedDate onwards
filterLastModified.From = filterFromDate;
//When a range of date that requires "to date", assign .To to implement from...to.
//filterLastModified.To = new DateTime(2018, 12, 31);
 
//Add the Filter to Criteria
//Can support more than one filter
loadDebtorCriteria.AddFilter(filterLastModified);
 
//fields to be loaded into DataTable
string[] columns = { "AccNo", "CompanyName", "Address1", "Address2",
"DeliverAddr1", "DeliverAddr2", "Attention", "Phone1", "AreaCode", "SalesAgent", "EmailAddress", "CreditLimit", "LastModified"};
 
return cmd.LoadDebtorData(columns, loadDebtorCriteria);
}
</syntaxhighlight>
 
==Sample with Data Model==
===Create new AR Debtor===
<syntaxhighlight lang="csharp">
Line 111 ⟶ 171:
</syntaxhighlight>
 
==Branch for Debtor==
{{SeeAlsoAPIAR}}
===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.NewBranch();
branch.BranchCode = 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>
 
==Inactivate Debtor/Activate Debtor==
*Inactivated debtor will not be shown in lookup selection at AR and Sales.
<syntaxhighlight lang="csharp">
public void InactivateDebtor(string accNo, AutoCount.Authentication.UserSession userSession)
{
AutoCount.ARAP.Debtor.DebtorDataAccess cmd =
AutoCount.ARAP.Debtor.DebtorDataAccess.Create(userSession, userSession.DBSetting);
AutoCount.ARAP.Debtor.DebtorEntity debtor = cmd.GetDebtor(accNo);
debtor.IsActive = false;
cmd.SaveDebtor(debtor, userSession.LoginUserID);
}
 
public void AactivateDebtor(string accNo, AutoCount.Authentication.UserSession userSession)
{
AutoCount.ARAP.Debtor.DebtorDataAccess cmd =
AutoCount.ARAP.Debtor.DebtorDataAccess.Create(userSession, userSession.DBSetting);
AutoCount.ARAP.Debtor.DebtorEntity debtor = cmd.GetDebtor(accNo);
debtor.IsActive = true;
cmd.SaveDebtor(debtor, userSession.LoginUserID);
}
</syntaxhighlight>
 
{{SeeAlsoAPIAccount}}
[[Category:Programmer]]
[[Category:API]]