Getting exception error while creating sale invoice using sample sdk code of Sage50 Canada 2019

199 views Asked by At

Getting the error : SimplySDK.SimplyErrorMessageException: 'Your chequing account is overdrawn. See the Advice topic "Managing Your Cash Flow" for suggestions.' I am using the following SDK sample code for invoice create:

// Sales Invoice Example
SalesJournal salJourn = SDKInstanceManager.Instance.OpenSalesJournal();

// Cash
salJourn.SelectTransType(0);  // invoice
salJourn.InvoiceNumber = orderNumber;
salJourn.SelectAPARLedger("harish");
salJourn.SelectPaidByType("Cash");
salJourn.SelectPaidDepositAccount(MakeAccountNumber(1060).ToString());
salJourn.SetItemNumber("CR-10", 1);
salJourn.SetQuantity(1, 1);
salJourn.SetUnit("Hour", 1);
salJourn.SetDescription("Computer Repair - No Warranty", 1);
salJourn.SetPrice(90.00, 1);
salJourn.SetLineAmount(90.00, 1);
salJourn.SetLineAccount(MakeAccountNumber(SDK_ACCTINVREV).ToString(), 1);

salJourn.SetDescription("Item #2", 2);
salJourn.SetQuantity(2, 2);
salJourn.SetUnit("Each", 2);
salJourn.SetPrice(0.99, 2);

salJourn.SetLineAccount(MakeAccountNumber(SDK_ACCTINVREV).ToString(), 2);
// allocate projects
ProjectAllocation projAlloc = salJourn.AllocateLine(2);
projAlloc.SetProject("Sage Project", 1);
try
{
   projAlloc.SetPercent(50.0, 1);
}
catch (SimplyNoAccessException)
{
   // can't allocate by percent, allocation by amount
   projAlloc.SetAmount(0.99, 1);
}
projAlloc.Save();
salJourn.SetComment("Paid by cash");
var salecreateRes = salJourn.Post();
if (salecreateRes)
{
    Console.WriteLine("Sales invoice 'SJ 1' posting succeeded");
}
else
{
     Console.WriteLine("Sales invoice 'SJ 1' posting failed");
}

Don't understand why its throwing chequing account error on creating a simple invoice. I am using this SDK with a trial software with single account is that could be the reason for this?

1

There are 1 answers

0
Harish Kumar On

well i have replaced the account in this line salJourn.SelectPaidDepositAccount(MakeAccountNumber(1060).ToString())

changed 1060 to 1020 which is an cash account ("Cash to be deposited") after that i am getting success message. and removed the following code, i don't need that

// allocate projects
ProjectAllocation projAlloc = salJourn.AllocateLine(2);
projAlloc.SetProject("Sage Project", 1);
try
{
   projAlloc.SetPercent(50.0, 1);
}
catch (SimplyNoAccessException)
{
   // can't allocate by percent, allocation by amount
   projAlloc.SetAmount(0.99, 1);
}
projAlloc.Save();