Skip to Content
0
Jun 09, 2020 at 04:07 PM

Adding Credit Card Deposits using DI-API

411 Views Last edit Jun 10, 2020 at 04:41 PM 2 rev

Hi.

I am trying to add credit card deposits using DI-API in SAP B1. I have a problem when adding multiple rows. What happens when I use my code is that it creates 2 deposits separately when I want to add 2 rows. If I have 3 rows, it adds 3 separate deposits of 1 row each.

How do I amend my code to fix this?

#region Use DIAPI to SAP
SAPbobsCOM.CompanyService oService = SboConnection.Company.GetCompanyService();
SAPbobsCOM.DepositsService dpService = (SAPbobsCOM.DepositsService)oService.GetBusinessService(SAPbobsCOM.ServiceTypes.DepositsService);
SAPbobsCOM.Deposit dpsAddMpesa = (SAPbobsCOM.Deposit)dpService.GetDataInterface(SAPbobsCOM.DepositsServiceDataInterfaces.dsDeposit);
dpsAddMpesa.DepositType = SAPbobsCOM.BoDepositTypeEnum.dtCredit;

SAPbobsCOM.DepositParams dpsParamAddMpesa;
SAPbobsCOM.CreditLines credits = dpsAddMpesa.Credits;
SAPbobsCOM.CreditLine credit;

dpsAddMpesa.DepositDate = DateTime.Now;
dpsAddMpesa.DepositAccountType = SAPbobsCOM.BoDepositAccountTypeEnum.datBankAccount;
dpsAddMpesa.DepositAccount = depositAcct;
dpsAddMpesa.VoucherAccount = deferredPmtAcct;
dpsAddMpesa.CommissionAccount = "SDR-06";
dpsAddMpesa.Commission = commission;
dpsAddMpesa.CommissionDate = DateTime.Now;
dpsAddMpesa.TaxCode = "X1";
dpsAddMpesa.DepositCurrency = "KES";
dpsAddMpesa.Project = "RETAIL";
dpsAddMpesa.DistributionRule = "GXD";
dpsAddMpesa.DistributionRule2 = "RETAIL";
dpsAddMpesa.JournalRemarks = "Added Mpesa Deposits with SAP B1 AddOn";
dpsAddMpesa.ReconcileAfterDeposit = SAPbobsCOM.BoYesNoEnum.tYES;

credit = credits.Add();

// Declare record set
SAPbobsCOM.Recordset rs = SboConnection.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

// Get AbsId
for (int i = 1; i <= oMatrix.VisualRowCount; i++)
{
string voucherNo = "";
int absId = 0;
// Get matrix voucher number
if (oMatrix.IsRowSelected(i) == true)
{
voucherNo = oMatrix.Columns.Item("1").Cells.Item(i).Specific.Value;

// Get absId
rs.DoQuery("SELECT T0.\"AbsId\" FROM OCRH T0 WHERE T0.\"VoucherNum\" = '" + voucherNo + "' AND T0.\"VoucherNum\" != 'No Ref Code'");
rs.MoveFirst();

int count = rs.RecordCount;

if (count > 0)
{
while (!rs.EoF)
{
absId = rs.Fields.Item("AbsId").Value;
rs.MoveNext();
}
}

credit.AbsId = absId;
dpsParamAddMpesa = dpService.AddDeposit(dpsAddMpesa);
}
}
#endregion