How yo use MYOB in RAILS Application - ruby-on-rails

Can anyone explain to integrate the MYOB in rails application

Integration to MYOB is not as simple as it might look.
In order to integrate to MYOB, you have to install the ODBC drivers, have the MYOB application installed and have direct access to the MYOB company file.
what is your integration requirements and purpose?
the solution we choose to go for is to build a desktop app that will facilitate the integration between the web app and MYOB.
hope this helps.

You can, however the only way to really do this is with the MYOB ODBC driver. The way this driver works is that it uses the Myobp.exe as a middle man between ODBC and the .MYO file.
The MYOB ODBC driver presents a SQL interface to MYOB, however there are some caveats. It's not a real SQL interface to MYOB. The data you can get in and out is closely matched by the Import and Export functions that MYOB presents in the program itself.
For getting data out, with the ODBC interface you can write SQL queries, and even some SQL type functions can be in these queries, but you may occasionally come across some things that will catch you out.
For getting data in, the ODBC driver presents uses a schema of tables with the prefix "Import_", with these tables all you can do is import data and they will not return things like the invoice number you just imported. This also means you cannot update existing entries the same way you would expect with a real SQL interface.
However, some data imports will result in an update of existing data if some of the fields match. My experience with MYOB and it's ODBC interface primarily deals with getting sales orders from a system I wrote entered into MYOB, so certain things can be done.
I did write my first version of this system in Rails, however you can't use the standard Rails models without adjusting the way they work because Rails is very opinionated on how it expects the database to act.
More recently I re-wrote it in Clojure and used handwritten queries.
For multiline inserts (for example the lines of an invoice) MYOB uses a transaction as a wrapper to indicate what lines should be on the one invoice.
So your best bet if you want to use Rails, would be to avoid using the Rails models, and perhaps write direct SQL queries and interface to that with your controllers and views.
I can't get to my old code right now, but it's something along the lines of this:
def create_myob_invoice( iso )
# We can assume we have the job
# Now, for each iso line, we add an invoice
latest_invoice_number = Sale.find( :first, :order => 'InvoiceNumber DESC' ).InvoiceNumber.to_i
if latest_invoice_number
# We need to wrap it all in a transaction so MYOB knows they're all the one invoice
MyobDatabase.transaction do
iso.lines.each do |line|
new_service_line = ImportServiceSale.new
# Map iso fields to MYOB service sale fields
# e.g. suff like:
new_service_line.Description = "#{line.sDescription}"
new_service_line.save
end
end
end
end
You may also be able to find something to help over at: http://freelancing-gods.com/posts/talking_to_myob_with_ruby

Related

How do I know if a ruby on rails application use database partitioning?

I would like to disable my rails application's oracle database partitioning, but :
I don't know how to tell whether my app is using database partitioning
I don't know how to find the place my app use partitioning, since I didn't write most of the application's code myself
Can I just system search the code base for the keyword 'Partition' and look for any result that has the key word partition in raw SQL statement?
How should I go about this?
Thanks!
Update:
I have 2 answers below and they seem to understand my question differently
I am confused now as well. I want to disable the partition feature of my Oracle Database (https://www.oracle.com/technetwork/database/options/partitioning/overview/index.html), does that means I cannot use the 'partition by' keyword (Oracle "Partition By" Keyword) anymore?
Partitioning is done at the schema level declaratively. Usually, one would not expect the application code to directly need anything specific to use partitioning since it is done at the data definition level. You can connect to the schema owner account and check the data dictionary views USER_PART_TABLES for partitioned tables owned by the user and USER_PART_INDEXES for the indexes.

Advantage Database Server: Change User Password/Add User

I was introduced recently to the Advantage Database technology, and I now have to use it to interface with a legacy software on Win 7. I have successfully followed the advantagezone development help files in order to install both the ADS and the ODBC driver. A few questions remain, the first of which being the following: How does one change the password of a user/add a user?
I was unable to find any documentation regarding this matter. Could you point me to the relevant documentation or provide me with the command necessary to do so via command line?
Also I was wondering if there were any sort of GUI to manage the ADS, like MySQL has with PHPMyAdmin or the MySQL workbench.
Thanks for your help!
Advantage Database Server (ADS) uses a somewhat strange concept they've confusingly called a Data Dictionary (DD), which when used as designed controls users, rights, security, and access similar to what most DBMSs offer in the database itself.
Basically the only way to work with the ADS DD is through their GUI, known as the Advantage Data Architect (ARC32), which is available for download from the ADS Developer Zone. (You can do it via code, but for the types of things a DBA would do it's much easier to do things via ARC32.) Using it, you can create most of the types of things you'd typically use in a DBMS.
ARC32 also allows you to design your tables and indexes, as well as running SQL DDL and DML statements. The supported SQL grammar is also available in the documentation and covered in the book mentioned below.
You can find the documentation in ARC32 itself (using the Help menu or the ? on the toolbar), or via their Online Help FIles. The best place to start is in the topic The Advantage Developer's Guide, which is actually the entire contents of the book Advantage Database Server: A Developer's Guide. The book contains pretty good documentation on all of the aspects of both ARC32 and ADS itself, including use of the DD. Part 1, Chapter 4 has an entire section on adding users.

Extensible Rails application that connects to several databases

I am implementing a Rails application that needs to aggregate search results from N independent heterogeneous databases. An example use case would be:
User queries "xpto"
The query is submitted to all the databases registered on the system
The results are transformed and combined in a predefined format
User gets the results
The application needs to provide an extensibility point for the introduction of new databases in the system. A database here can be of different kinds - a flat file, SQL database, REST interface to an SQL database, etc.
If I was working in C#/Java, ignoring speed issues, I would define a plug-in management system where each host would have a plug-in that would know how to query and transform the results of the host. New hosts would be easily introduced by defining a new plug-in and configuring the host in the system.
I am new comer to rails and I am looking for either ideas, tools or design patterns that can help me to solve this problem.
My best guess wolud be to write a custom ActiveRecord Adapter that would query all your databases and combine the results.
From the API reference:
Connections are usually created through ActiveRecord::Base.establish_connection and retrieved by ActiveRecord::Base.connection. All classes inheriting from ActiveRecord::Base will use this connection. But you can also set a class-specific connection. For example, if Course is an ActiveRecord::Base, but resides in a different database, you can just say Course.establish_connection and Course and all of its subclasses will use this connection instead.

Should I use multiple databases?

I am about to create an application with Ruby on Rails and I would like to use multiple databases, basically is an accounting app that will have multiple companies for each user. I would like to create a database for each company
I found this post http://programmerassist.com/article/302
But I would like to read more thoughts about this issue.
I have to decide between MySQL and PosgreSQL, which database might fit better my problem.
There are several options for handling a multi-tenant app.
Firstly, you can add a scope to your tables (as suggested by Chad Birch - using a company_id). For most use-cases this is fine. If you are handling data that is secure/private (such as accounting information) you need to be very careful about your testing to ensure data remains private.
You can run your system using multiple databases. You can have a single app that uses a database for each client, or you can have actually have a seperate app for each client. Running a database for each client cuts a little against the grain in rails, but it is doable. Depending on the number of clients you have, and the load expectations, I would actually suggest having a look at running individual apps. With some work on your deployment setup (capistrano, chef, puppet, etc) you can make this a very streamlined process. Each client runs in a completely unique environment, and if a particular client has high loads you can spin them out to their own server.
If using PostgreSQL, you can do something similar using schemas.
PostgresQL schemas provide a very handy way of islolating your data from different clients. A database contains one or more named schemas, which in turn contain tables. You need to add some smarts to your migrations and deployments, but it works really well.
Inside your Rails application, you attach filters to the request that switch the current user's schema on or off.
Something like:
before_filter :set_app
def set_app
current_app = App.find_by_subdomain(...)
schema = current_app.schema
set_schema_path(schema)
end
def set_schema_path(schema)
connection = ActiveRecord::Base.connection
connection.execute("SET search_path TO #{schema}, #{connection.schema_search_path}")
end
def reset_schema_path
connection = ActiveRecord::Base.connection
connection.execute("SET search_path TO #{connection.schema_search_path}")
end
The problem with answers about multiple databases is when they come from people who don't have a need or experience with multiple databases. The second problem is that some databases just don't allow for switching between multiple databases, including allowing users to do their own backup and recovery and including scaling to point some users to a different data server. Here is a link to a useful video
http://aac2009.confreaks.com/06-feb-2009-14-30-writing-multi-tenant-applications-in-rails-guy-naor.html
This link will help with Ruby on Rails with Postgresql.
I currently have a multi-tenant, multi-database, multi-user (many logons to the same tenant with different levels of access), and being an online SaaS application. There are actually two applications one is in the accounting category and the other is banking. Both Apps are built on the same structure and methods. A client-user (tenant) can switch databases under that user's logon. An agent-user such as a tax accountant can switch between databases for his clients only. A super-user can switch to any database. There is one data dictionary i.e. only one place where tables and columns are defined. There is global data and local data. Global data such as a master chart-of-accounts which is available to everyone (read only). Local data is the user's database. A new user can get a clone of a master database. There are multiple clones to choose from. A super-user can maintain the clone databases.
The problem is that it is in COBOL and uses ISAM files and uses the CGI method. The problem with this is a) there is a perception that COBOL is outdated, b) getting trained people, c) price and d) online help. Otherwise it works and I'm happy with it.
So I'm researching what to replace it with and what a minefield that is.
It has past time and the decission for this has been to use PostgreSQL schemas, making multitenant applications, I have a schema called common where related data is stored.
# app/models/organisation.rb
class Organisation < ActiveRecord::Base
self.table_name = 'common.organisations'
# set relationships as usual
end
# app/models/user.rb
class User < ActiveRecord::Base
self.table_name = 'common.users'
# set relationships as usual
end
Then for migrations I have done that with this excellent tutorial. http://timnew.github.com/blog/2012/07/17/use-postgres-multiple-schema-database-in-rails/ use this, this is way better than what I saw in other places even the way Ryan Bates did on railscasts.
When a new organisation is created then a new schema is created with the name of the subdomain the organisation. I have read in the past that it's not a good idea to use different schemas but it depends on the job you are doing, this app has almost no soccial component so it's a good fit.
No, you shouldn't use multiple databases.
I'm not really sure what advice to give you though, it seems like you have some very basic misunderstandings about database design, you may want to educate yourself on the basics of databases first, before going further.
You most likely just want to add a "company id" type column to your tables to identify which company a particular record belongs to.

Any tips on getting Rails to run with an Access back-end?

I shudder to ask, but my client might offer no other SQL (or SQL-like) solution. I know Access has some SQL hooks; are they enough for basic ActiveRecord?
Later:
I appreciate all the suggestions to use other databases, but trust me: I've tried convincing them. There is an "approved" list, and no SQL databases are on it. Getting something onto the list could take more than a year, and this project will be done in three weeks.
It's a long shot but there's an ODBC adapter for ActiveRecord that might work.
There seems to be something of an Access connection adapter here: http://svn.behindlogic.com/public/rails/activerecord/lib/active_record/connection_adapters/msaccess_adapter.rb
The database.yml file would look like this:
development:
adapter: msaccess
database: C:\path\to\access_file.mdb
I'll post more after I've tried it out with Rails 2.1
Another option that is more complicated but could work if you were forced to do it, is to write a layer of RESTful web services that will expose Access to rails. If you are careful in your design, those RESTful web services can be consumed directly by ActiveResoure which will give you a lot of the functionality of ActiveRecord.
There are some wierd things in Access that might cause issues and I don't know if ODBC takes care of it. If it does #John Topley is right, ODBC would be your only cance.
True in access = -1 not 1
Access treats dates differently than regular TSQL.
You might run into trouble creating relations.
If you go with access, will probably learn more about debuging AcriveRecord then you ever cared to ( which might not be a bad thing)
Maudite wrote:
True in access = -1 not 1
Not correct. True is defined as not being false. So, if you want to use True in a WHERE clause, use Not False instead. This will provide complete cross-platform compatibility with all SQL engines.
All that said, it's hardly an issue, since whatever driver you're using to connect to your back end will properly translate True in WHERE clauses to the appropriate value. The only exception might be in passthrough queries, but in that case, you should be writing the SQL outside Access and testing it against your back end and just pasting the working SQL into the SQL view of your passthrough query in Access.
Maudite wrote:
Access treats dates differently than regular TSQL.
Again, this is only going to be an issue if you don't go through the ODBC or OLEDB drivers, which will take care of translating Jet SQL into TSQL for you.
Maudite wrote:
You might run into trouble creating relations.
I'm not sure why you'd want an Access application to be altering the schema of your back end, so this seems to me like a non-issue.
You should really talk them into allowing SQLite. It is super-simple to setup, and operates like Access would (as a file sitting next to the app on the same server).
Firstly, you really want to be using sqlite.
In my experience Access itself is a pile of [redacted], but the Jet database engine it uses is actually pretty fast and can handle some pretty complex SQL queries. If you can find a rails adapter that actually works I'd say you'll be fine. Just don't open the DB with the access frontend while your rails app is running :-)
If your client is anal enough to only allow you to develop with an approved list of databases, they may be more concerned by the fact that Jet is deprectated and will get no more support from MS.
This might give you some ammunition in your quest to use a real database. Good luck

Resources