public object getCreditorPayment(int id)
        {
            db.Configuration.ProxyCreationEnabled = false;

            Creditor_Payment objectCreditorPayment = new Creditor_Payment();
            dynamic          toReturn = new ExpandoObject();

            try
            {
                objectCreditorPayment = db.Creditor_Payment.Find(id);

                if (objectCreditorPayment == null)
                {
                    toReturn.Message = "Creditor Payment Not Found";
                }
                else
                {
                    toReturn = objectCreditorPayment;
                }
            }
            catch
            {
                toReturn.Message = "Search Interrupted.Retry";
            }

            return(toReturn);
        }
        public object addCreditorPayment(Creditor_Payment newCreditorPayment)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                db.Creditor_Payment.Add(newCreditorPayment);
                Creditor creditor = db.Creditors.Where(x => x.SupplierID == newCreditorPayment.SupplierID).FirstOrDefault();
                creditor.CredAccountBalance = creditor.CredAccountBalance - newCreditorPayment.CredPaymentAmount;
                if (creditor.CredAccountBalance < newCreditorPayment.CredPaymentAmount)
                {
                    float amount = (float)(creditor.CredAccountBalance + newCreditorPayment.CredPaymentAmount);
                    toReturn.Message = "Payment is greater than the Creditor's Balance. Balance for this Creditor is R" + amount;
                }
                else
                {
                    db.SaveChanges();
                    toReturn.Message = "Creditor payment has been added successfully. Balance = R" + creditor.CredAccountBalance;
                }
            }
            catch (Exception)
            {
                toReturn.Message = "Payment not added. The selected supplier is not a creditor for ORDRA.";
            }

            return(toReturn);
        }