AR Debtor v2

From AutoCount Resource Center
Jump to navigation Jump to search

References of AutoCount Accounting version 2.0

AutoCount.Accounting.dll
AutoCount.Accounting.UI.dll
AutoCount.dll
AutoCount.MainEntry.dll
AutoCount.UI.dll
AutoCount.ARAP.dll

Load Data with API

Single Record

Load one debtor by specifying the DebtorCode (AccNo).

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;
    }
}

Multiple Records with Filter

Load more than one debtor.
Programmer can specify which columns to load, while defining the filter of which debtor to be loaded.
This example shows how to load debtor that was modified since a specific date.

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);
}

Sample with Data Model

Create new AR Debtor

public void CreateNewDebtor(AutoCount.Authentication.UserSession userSession, DebtorSource source)
{
    string newDebtorCode = GetNewDebtorCode(userSession, source.ControlAccount, source.CompanyName);
    if (newDebtorCode == null)
        return;

    string userId = userSession.LoginUserID;
    AutoCount.ARAP.Debtor.DebtorDataAccess cmd = AutoCount.ARAP.Debtor.DebtorDataAccess.Create(userSession, userSession.DBSetting);
    AutoCount.ARAP.Debtor.DebtorEntity debtor = cmd.NewDebtor();

    debtor.ControlAccount = source.ControlAccount;
    debtor.AccNo = newDebtorCode;
    debtor.CompanyName = source.CompanyName;
    debtor.Address1 = source.Addr1;
    debtor.Address2 = source.Addr2;
    debtor.Address3 = source.Addr3;
    debtor.Address4 = source.Addr4;
    debtor.Phone1 = source.Phone;
    debtor.Phone2 = source.Mobile;
    debtor.Attention = source.ContactPerson;
    debtor.EmailAddress = source.Email;
    debtor.CurrencyCode = AccountBookLocalCurrency(userSession);

    try
    {
        cmd.SaveDebtor(debtor, userId);
        //Log Success
    }
    catch (AutoCount.AppException ex)
    {
        //Log fail
    }
}

Get Next Debtor Code

public string GetNewDebtorCode(AutoCount.Authentication.UserSession userSession, string controlAccNo, string companyName)
{
    try
    {
        return AutoCount.GL.AccountCodeHelper.Create(userSession.DBSetting)
            .GetNextDebtorCode(controlAccNo, companyName);
    }
    catch (AutoCount.GL.InvalidAutoDebtorCodeFormatException ex)
    {
        //Log error ex.Message;
    }
    catch (AutoCount.Data.DataAccessException ex)
    {
        //Log error ex.Message;
    }

    //If the catch throw out exception, then return null is not necessary.
    return null;
}

Get Local Currency Code

public string AccountBookLocalCurrency(AutoCount.Authentication.UserSession userSession)
{
    return AutoCount.Data.DBRegistry.Create(userSession.DBSetting)
        .GetString(new AutoCount.RegistryID.LocalCurrencyCode());
}

Class of source data

public class DebtorSource
{
    public string ControlAccount { 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; }
}

Implementation

public MainEntry(BCE.Data.DBSetting dbSetting)
{
    DebtorSource newDebtor = new DebtorSource()
    {
        ControlAccount = "300-0000",
        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",
    };

    CreateNewDebtor(dbSetting, newDebtor);
}

See Also

AutoCount Accounting Account API
AR AP
Transactions Version Transactions Version
AR Debtor (Customer) 1.8, 1.9
2.0
AP Creditor (Supplier) 1.8, 1.9
2.0
AR Invoice 1.8, 1.9
2.0
AP Invoice 1.8, 1.9
2.0
AR Received Payment 1.8, 1.9
2.0
AP Payment 1.8, 1.9
2.0
AR Debit Note 1.8, 1.9
2.0
AP Debit Note 1.8, 1.9
2.0
AR Credit Note 1.8, 1.9
2.0
AP Credit Note 1.8, 1.9
2.0
AR Refund 1.8, 1.9
2.0
AP Refund 1.8, 1.9
2.0
AR Deposit 1.8, 1.9
2.0
AP Deposit 1.8, 1.9
2.0
AR Deposit - Create New or Update
with Refund & Forfeit
1.8, 1.9
2.0
A/R and A/P Contra Entry 1.8, 1.9
2.0

Go to menu

IconAC81.png Go to top
ProgrammerGo.jpg Resources For AutoCount Software Developers