AR Deposit - Create New or Update with Refund & Forfeit

From AutoCount Resource Center
Revision as of 02:03, 20 December 2017 by DanielY (talk | contribs) (Created page with "==(Not Complete)== ===Rules in AR Deposit Refund & Forfeit=== # One AR Deposit allows only one Refund # One AR Deposit allows only one Forfeit ===Assemblies version 1.8=== <...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

(Not Complete)

Rules in AR Deposit Refund & Forfeit

  1. One AR Deposit allows only one Refund
  2. One AR Deposit allows only one Forfeit

Assemblies version 1.8

BCE.AutoCount.ARAP.dll

Add New or Edit Existing AR Deposit with Deposit Refund and Forfeit

public void AddUpdateDepositWithRefundForfeit(ARDepositSource source, BCE.Data.DBSetting dbSetting)
{
    BCE.AutoCount.ARAP.ARDeposit.ARDepositCommand cmd = BCE.AutoCount.ARAP.ARDeposit.ARDepositCommand.Create(dbSetting);
    BCE.AutoCount.ARAP.ARDeposit.ARDeposit doc = cmd.Edit(source.DocumentNo);

    if (doc == null)
    {
        //Add New ARDeposit
        doc = cmd.AddNew();
        UpdateARDeposit(doc, source, dbSetting);
    }
    else
    {
        //Edit existing ARDeposit
        doc.ClearDetails();
        UpdateARDeposit(doc, source, dbSetting);
    }
}
private void UpdateARDeposit(BCE.AutoCount.ARAP.ARDeposit.ARDeposit doc, ARDepositSource source, BCE.Data.DBSetting dbSetting)
{
    if (IsValidDepositMethod(source.DepositMethod, dbSetting))
    {
        if (doc.DepositPaymentMethod != source.DepositMethod)
            doc.DepositPaymentMethod = source.DepositMethod;
    }
    else
    {
        BCE.Application.AppMessage.ShowErrorMessage(string.Format("Invalid Deposit Payment Method of \"{0}\"", source.DepositMethod));
        //log error on Deposit Payment Method error
        return;
    }

    if (doc.DocNo != source.DocumentNo)
        doc.DocNo = source.DocumentNo ?? doc.DocNo;
    if (doc.DocDate != source.DocumentDate)
        doc.DocDate = source.DocumentDate;

    doc.Description = source.Description ?? doc.Description;
    doc.CurrencyCode = source.CurrencyCode ?? doc.CurrencyCode;
    doc.DebtorCode = source.CustomerAccount;
    doc.DebtorName = source.CustomerName;
    doc.Attention = source.Attention;
    doc.Phone1 = source.Phone;
    doc.Fax1 = source.Fax;
    doc.ProjNo = source.Project;
    doc.DeptNo = source.Department;

    source.Detail.ForEach(s => AddARDepositDetail(s, doc.AddDetail));

    try
    {
        doc.Save();
        BCE.Application.AppMessage.ShowMessage(string.Format("{0} is Created.", doc.DocNo));
        //Log Success created
    }
    catch (BCE.Application.AppException ex)
    {
        BCE.Application.AppMessage.ShowErrorMessage(ex.Message);
        //Log Error saving
    }
}

private void AddARDepositDetail(ARDepositDetailSource source, Func<BCE.AutoCount.ARAP.ARDeposit.ARDepositDetail> addDepositDetail)
{
    BCE.AutoCount.ARAP.ARDeposit.ARDepositDetail dtl = addDepositDetail();
    dtl.PaymentMethod = source.PaymentMethod;
    dtl.ChequeNo = source.ChequeNo;
    dtl.PaymentAmt = source.DepositAmount;
    dtl.BankCharge = source.BankCharge;
    dtl.BankChargeTaxType = source.BankChargeTaxCode;
    dtl.BankChargeTaxRefNo = source.BankChargeBillNoForGst;
    dtl.PaymentBy = source.PaymentBy;

    //Returned Cheque
    if (source.ReturnChequeDate.HasValue)
    {
        dtl.IsRCHQ = true;
        dtl.RCHQDate = source.ReturnChequeDate.Value;
    }
    else
    {
        dtl.IsRCHQ = false;
    }
}
private bool IsValidDepositMethod(string depositMethod, BCE.Data.DBSetting dbSetting)
{
    return GetDepositPaymentMethod(dbSetting).AsEnumerable()
        .Count(r => r.Field<string>("PaymentMethod") == depositMethod) > 0;
}

private DataTable GetDepositPaymentMethod(BCE.Data.DBSetting dbSetting)
{
    BCE.AutoCount.XtraUtils.LookupEditBuilder.DepositPaymentMethodLookupEditBuilder depositBuilder =
        new BCE.AutoCount.XtraUtils.LookupEditBuilder.DepositPaymentMethodLookupEditBuilder();

    //The return table contains of 3 columns: (1) PaymentMethod, (2) BankAccount, (3) CurrencyCode (in version 1.8.28.184)
    return depositBuilder.BuildDataTable(dbSetting);
}

See Also