Example #1
0
 public void SetField(ApplicationObject appObject, string fieldName, object value)
 {
     // Actually update the object....obviously in the simple example there's an actual 'SetFieldValue'
     // method. If however, you may need to set Properties on the object itself, we have a set of helper
     // routines in our Reflection library that allows you to set a property efficiently using reflection.
     // Contact Realisable to discuss.
     appObject.SetFieldValue(fieldName, value);
 }
Example #2
0
        public void SetFieldDecimal(ApplicationObject appObject, string fieldName, object value, int decimalPlaces)
        {
            if (value != null)
            {
                Decimal val = Decimal.Round(Convert.ToDecimal(value), decimalPlaces);

                SetField(appObject, fieldName, value);
            }
        }
Example #3
0
        public void SetField(ApplicationObject appObject, string fieldName, Transaction transaction, string tranFieldName)
        {
            try
            {
                _currentTran = transaction;

                if (CanFieldBeSet(transaction, tranFieldName))
                {
                    SetField(appObject, fieldName, transaction.GetValue(tranFieldName));
                }
            }
            finally
            {
                _currentTran = null;
            }
        }
Example #4
0
        /// <summary>
        /// Decimal fields sometimes need to be handled differently. The two SetFieldDecimals provide the specialist implementation.
        /// </summary>
        /// <param name="appObject"></param>
        /// <param name="fieldName"></param>
        /// <param name="transaction"></param>
        /// <param name="decimalPlaces"></param>
        public void SetFieldDecimal(ApplicationObject appObject, string fieldName, Transaction transaction, int decimalPlaces)
        {
            try
            {
                _currentTran = transaction;

                if (CanFieldBeSet(transaction, fieldName))
                {
                    object val = transaction.GetValue(fieldName);

                    SetFieldDecimal(appObject, fieldName, val, decimalPlaces);
                }
            }
            finally
            {
                _currentTran = null;
            }
        }
        private void CreateDetailEntry(ApplicationObject salesInvoice, Transaction transaction)
        {
            ApplicationObject detailItem = ApplicationObject.Create();

            _wrapper.AuditController.OnProcess(_transformId, transaction);

            try
            {
                _wrapper.SetField(detailItem, "NominalSpecification", transaction);
                _wrapper.SetField(detailItem, "Narrative", transaction);
                _wrapper.SetFieldDecimal(detailItem, "Amount", transaction, 2);
                _wrapper.SetField(detailItem, "TransactionAnalysisCode", transaction);

                _wrapper.AuditController.OnInsert(_transformId, transaction);
            }
            catch (Exception ex)
            {
                string errorText = string.Format("Error whilst processing {0} record.", ENTITY_DETAIL_DESC);

                _wrapper.LogError(transaction, ex, string.Format("{0}  The detail record will be discarded.", errorText));

                switch (_errAction)
                {
                case eTransformErrorAction.eTransformErrorActionRejectRecord:
                case eTransformErrorAction.eTransformErrorActionAbort:
                {
                    throw;
                }

                case eTransformErrorAction.eTransformErrorActionContinue:
                {
                    break;
                }
                }
            }
        }
        private void CreateEntry(Transaction transaction)
        {
            ApplicationObject salesInvoice = ApplicationObject.Create();

            try
            {
                // Set the customer for the Sales Invoice
                string customerId = transaction.GetValueNullReturn("Customer") as string;
                if (!_wrapper.IsExistingCustomer(customerId))
                {
                    throw new Exception(string.Format("The customer [{0}] is invalid", customerId), null);
                }

                _wrapper.SetField(salesInvoice, "Customer", transaction);
                _wrapper.SetField(salesInvoice, "InstrumentNo", transaction);
                _wrapper.SetField(salesInvoice, "SecondReference", transaction);
                _wrapper.SetField(salesInvoice, "InstrumentDate", transaction);
                _wrapper.SetField(salesInvoice, "DueDate", transaction);

                // In this section the detail lines of the invoice are iterated.
                // Firstly check the iterator contains any child records.
                if (_iterator.HasChild(ENTITY_DETAIL))
                {
                    // Now move to the child record.
                    if (_iterator.MoveChild(ENTITY_DETAIL))
                    {
                        int detailCnt = 0;

                        // The iterator is now positioned on the child record.
                        // Create a detail record for each of the child records.
                        while (_iterator.Read())
                        {
                            detailCnt++;
                            CreateDetailEntry(salesInvoice, _iterator.Item());
                        }

                        // Now move back to the parent.
                        _iterator.MoveParent();
                    }
                }

                // Set any remaing fields that may need to be set after the detail records.
                _wrapper.SetFieldDecimal(salesInvoice, "DicountPercent", transaction, 2);
                _wrapper.SetField(salesInvoice, "DiscountDays", transaction);

                // Update the invoice.
                salesInvoice.Update();

                _wrapper.AuditController.OnInsert(_transformId, transaction);

                // Post update we may need to update the recordset with a number of fields.
                if (_tranHasURNFld)
                {
                    transaction.SetFieldValue("PostingReference", salesInvoice.GetFieldValue("PostRef"), true);
                }

                // Write the posted document total onto the transaction.
                if (_tranHasPostedDocTotalFld)
                {
                    transaction.SetFieldValue("DocumentTotal", salesInvoice.GetFieldValue("DocTotal"), true);
                }
            }
            catch (Exception ex)
            {
                string errorText = string.Format("Error whilst processing {0} record.", ENTITY_DESC);

                // There's an error based on the error action.
                switch (_errAction)
                {
                // If the error action is set to Abort: Log the error and re-raise the exception.
                case eTransformErrorAction.eTransformErrorActionAbort:
                {
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will be discarded.", errorText));

                    throw;
                }

                // If the error action is set to Continue: CHAOS mode.
                // Try to save/update again and see what happens.
                // An exception will probably be generated, causing the transform to terminate unexpectedly.
                case eTransformErrorAction.eTransformErrorActionContinue:
                {
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will attempt to re-save.", errorText));
                    salesInvoice.Update();

                    // Post update we may need to update the recordset with a number of fields.
                    if (_tranHasURNFld)
                    {
                        transaction.SetFieldValue("PostingReference", salesInvoice.GetFieldValue("PostRef"), true);
                    }

                    //Write the posted document total onto the transaction.
                    if (_tranHasPostedDocTotalFld)
                    {
                        transaction.SetFieldValue("DocumentTotal", salesInvoice.GetFieldValue("DocTotal"), true);
                    }

                    _wrapper.AuditController.OnInsert(_transformId, transaction);

                    break;
                }

                // If the error action is Reject Record: Log the error and no update will occur.
                // Exit the method gracefully so the next record can be processed.
                case eTransformErrorAction.eTransformErrorActionRejectRecord:
                {
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will be discarded.", errorText));

                    break;
                }
                }
            }
            finally
            {
                // Check the iterator is back at the header; move the parent if it is not.
                if (_iterator.Item().TransactionId != ENTITY)
                {
                    _iterator.MoveParent();
                }
            }
        }
Example #7
0
 /// <summary>
 /// This function sets any user-defined values from the transaction to the Application object.
 /// </summary>
 /// <param name="appObject">The application object.</param>
 /// <param name="transaction">The transaction.</param>
 public void SetUserDefinedFields(ApplicationObject appObject, Transaction transaction)
 {
     // Logic to be implemented.
 }
Example #8
0
        /// <summary>
        /// Updates/Inserts the customer record
        /// </summary>
        /// <param name="transaction">The transaction being processed.</param>
        private void CreateEntry(Transaction transaction)
        {
            bool isNew = false;

            // A mock call to whatever API.
            // Essentially get an object so the values of the dataset can be set to it.
            ApplicationObject customer = ApplicationObject.Create();

            try
            {
                // Use a common function in your wrapper/helper class to determine if a customer exists or not.
                isNew = !_wrapper.IsExistingCustomer(transaction.GetValueNullReturn("Reference") as string);

                // Now check/compare the updateflags, if the relevant flag is not set, return.
                if (isNew)
                {
                    if ((_updateOp & eERPUpdateOperation.eInsert) != eERPUpdateOperation.eInsert)
                    {
                        return;
                    }
                }
                else
                {
                    if ((_updateOp & eERPUpdateOperation.eUpdate) != eERPUpdateOperation.eUpdate)
                    {
                        return;
                    }
                }

                // Set the fields from the transaction onto the customer/application object.
                _wrapper.SetField(customer, "Name", transaction);
                _wrapper.SetField(customer, "ShortName", transaction);
                _wrapper.SetFieldDecimal(customer, "CreditLimit", transaction, 2);
                _wrapper.SetField(customer, "PaymentTermsDays", transaction);
                _wrapper.SetField(customer, "PaymentTermsBasis", transaction);
                _wrapper.SetField(customer, "CountryCode", transaction);
                _wrapper.SetField(customer, "AddressLine1", transaction);
                _wrapper.SetField(customer, "AddressLine2", transaction);
                _wrapper.SetField(customer, "AddressLine3", transaction);
                _wrapper.SetField(customer, "AddressLine4", transaction);
                _wrapper.SetField(customer, "City", transaction);
                _wrapper.SetField(customer, "County", transaction);
                _wrapper.SetField(customer, "Postcode", transaction);
                // Continue for each field until done.

                // Use the wrapper/helper class to set user defined/dynamic fields.
                _wrapper.SetUserDefinedFields(customer, transaction);

                // Now update the record...obviously it's going to be more compex than this.
                customer.Update();

                // In this example the customer reference is generated by the application...we may want to allow
                // this auto-generated reference to be recorded back onto the dataset to allow either:
                // a. Further processing i.e. updating a system with a foreign reference or;
                // b. Allow the value to be put onto the audit report.
                //
                // So, if the transaction object has a Reference field update the field with the value.
                // Note, if you attempt to set a field which is not defined an exception is generated.
                if (_tranHasReferenceFld)
                {
                    transaction.SetFieldValue("Reference", customer.GetFieldValue("Reference"), true);
                }

                // Now update the AuditController
                if (isNew)
                {
                    _wrapper.AuditController.OnInsert(_transformId, transaction);
                }
                else
                {
                    _wrapper.AuditController.OnUpdate(_transformId, transaction);
                }
            }
            catch (Exception ex)
            {
                string errorText = string.Format("Error whilst processing {0} record.", ENTITY_DESC);

                // There's an error based on the error action.
                switch (_errAction)
                {
                // If the error action is set to Abort: Log the error and re-raise the exception.
                case eTransformErrorAction.eTransformErrorActionAbort:
                {
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will be discarded.", errorText));

                    throw;
                }

                // If the error action is set to Continue: CHAOS mode.
                // Try to save/update again and see what happens.
                // An exception will probably be generated, causing the transform to terminate unexpectedly.
                case eTransformErrorAction.eTransformErrorActionContinue:
                {
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will attempt to re-save.", errorText));
                    //customer.Update();

                    if (isNew)
                    {
                        _wrapper.AuditController.OnInsert(_transformId, transaction);
                    }
                    else
                    {
                        _wrapper.AuditController.OnUpdate(_transformId, transaction);
                    }

                    break;
                }

                // If the error action is Reject Record: Log the error and no update will occur.
                // Exit the method gracefully so the next record can be processed.
                case eTransformErrorAction.eTransformErrorActionRejectRecord:
                {
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will be discarded.", errorText));

                    break;
                }
                }
            }
        }
        private void CreateEntry(Realisable.Data.Transform.Transaction transaction)
        {
            ApplicationObject auth = ApplicationObject.Create();

            try
            {
                if (TransactionHasStatusUpdateFields(transaction))
                {
                    string ApiLoginID        = _client._APILoginKey;
                    string ApiTransactionKey = _client._ApiTransactionKey;
                    bool   sandbox           = _client._Sandbox;

                    string  _transactionAmount = transaction.GetValue("TransactionAmount").ToString();
                    decimal transactionAmount  = 0.00M;
                    if (!decimal.TryParse(_transactionAmount, out transactionAmount))
                    {
                        throw new Exception(string.Format("Unable to parse transaction amount [{0}]", _transactionAmount));
                    }

                    string TransactionID = transaction.GetValue("TransactionID").ToString();

                    Capture response = Client.Capture(ApiLoginID, ApiTransactionKey, transactionAmount, TransactionID, sandbox);

                    if (response != null)
                    {
                        TraceWriter.Write("Authorize.Net capture response:\n" + response.ToTraceOutput());
                        if (transaction.HasField(nameof(Capture.ResponseCode)))
                        {
                            transaction.SetFieldValue(nameof(Capture.ResponseCode), response.ResponseCode, true);
                        }
                        if (transaction.HasField(nameof(Capture.MessageCode)))
                        {
                            transaction.SetFieldValue(nameof(Capture.MessageCode), response.MessageCode, true);
                        }
                        if (transaction.HasField(nameof(Capture.Description)))
                        {
                            transaction.SetFieldValue(nameof(Capture.Description), response.Description, true);
                        }
                        if (transaction.HasField(nameof(Capture.AuthCode)))
                        {
                            transaction.SetFieldValue(nameof(Capture.AuthCode), response.AuthCode, true);
                        }
                        if (transaction.HasField(nameof(Capture.ErrorCode)))
                        {
                            transaction.SetFieldValue(nameof(Capture.ErrorCode), response.ErrorCode, true);
                        }
                        if (transaction.HasField(nameof(Capture.CaptureErrorMessage)))
                        {
                            transaction.SetFieldValue(nameof(Capture.CaptureErrorMessage), response.CaptureErrorMessage, true);
                        }
                    }
                    else
                    {
                        TraceWriter.Write("Authorize.Net capture response is NULL.");
                    }

                    // Being a good citizen.
                    _auditController.OnUpdate(_transformId, transaction);
                }
                else
                {
                    throw new Exception("'Id' and 'OrderStatus' must both be set.");
                }

                _wrapper.AuditController.OnInsert(_transformId, transaction);
            }
            catch (Exception ex)
            {
                string errorText = string.Format("Error while processing {0} record.", ENTITY_DESC);

                // There's an error based on the error action.
                switch (_errAction)
                {
                // If the error action is set to Abort: Log the error and re-raise the exception.
                case eTransformErrorAction.eTransformErrorActionAbort:
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will be discarded.", errorText));

                    throw;

                // If the error action is set to Continue: CHAOS mode.
                // Try to save/update again and see what happens.
                // An exception will probably be generated, causing the transform to terminate unexpectedly.
                case eTransformErrorAction.eTransformErrorActionContinue:
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will attempt to re-save.", errorText));
                    //auth.Update();

                    _wrapper.AuditController.OnInsert(_transformId, transaction);

                    break;

                // If the error action is Reject Record: Log the error and no update will occur.
                // Exit the method gracefully so the next record can be processed.
                case eTransformErrorAction.eTransformErrorActionRejectRecord:
                    _wrapper.LogError(transaction, ex, string.Format("{0}  The entry will be discarded.", errorText));

                    break;
                }
            }
            finally
            {
                // Check the iterator is back at the header; move the parent if it is not.
                if (_iterator.Item().TransactionId != ENTITY)
                {
                    _iterator.MoveParent();
                }
            }
        }