Lightweight persist to database

Hello everybody,

today I want to describe following use case. Quite often it is needed to persist to database one or another DAC class, which is filled by some data. 

As usually I see people do this via hard coding of DAC class inside of the Graph. But today I want to share with you a way of persisting DAC class without hardcoding it as a view. 

In order to accomplish this, you can use following graph:

public class ImportEntitiesInsertion : PXGraph<ImportEntitiesInsertion>
{
    public string AddView(Type dacType)
    {
        var viewName = "_DYNAMIC_" + dacType.GetLongName();
        if (!this.Views.ContainsKey(viewName))
        {
            var command = BqlCommand.CreateInstance(typeof(Select<>), dacType);
            var newView = new PXView(thistrue, command);
            Views.Add(viewName, newView);
            Views.Caches.Add(dacType);
        }
        return viewName;
    }
}

 

After that, in some other place of the code, you can use this graph like this:

 

var graphForInsertion = PXGraph.CreateInstance<ImportEntitiesInsertion>();
var dacType = typeof(SOOrder); 
var viewName = graphForInsertion.AddView(dacType);
 
for (int i = 0; i < 10; i++)
{
    var newOrd = new SOOrder();
    graphForInsertion.Views[viewName].Cache.Insert(newOrd);
}
graphForInsertion.Persist();

 

 What I especially like about this approach, is that records will be persisted initially in the cache, and only after you'll call Persist, all bunch of records will be persisted to database.

 

 

How can you explain the role, meaning and substance of ERP in layman's terms?

Well. It depends from what kind of layman is in front of me. I’ll discuss following layman:

  1. my mom
  2. my father
  3. Some abstract CEO

Let’s start from my mom. Last time when she asked me what programs I do make I was puzzled. What should I say her? She knows about Android apps, Windows apps and before retirement she used to be train driver. Be she have no idea what is ERP. As you can guess, I can’t say here standard definition of ERP from wikipedia ( actually I can, but it will not add any knowledge to her ). So I started a conversation with her like this ( Y. will stand for me, and M. for my mom ) .

M. Yuriy, what programs you make?

Y. ERP systems.

M. What is this? Is this like my Angry Birds app?

Y. Hm. Good question.

M. What about good answer?

Y. Instead of giving you definition, I’ll just describe it as game, and you for yourself think about definition. You know, from a bird view prospective you are right. ERP is like Angry Birds game, but just instead of calculating score, tracking at which level you are, how much stars you got I make an app that tracks the following: salaries, warehouse balances, vacations, orders etc. So that’s difference number one between angry birds and ERP system. Difference number two lies in device where ERP is executed. As usually ERP is executed at some powerful computer which is named server and other people use their browser in order to execute it.

M. Wait, you mean that I can open chrome and use your “game”?

Y. Exactly. It can be compared also to how you use google products. You have one log in to your google account, and will get access to your email, drive, youtube, calendar and any other google staff. The same with ERP. If you log in to ERP, you will see there your vacations, how much hours you spent on your job, what salary will expect you and so on. Also you can suppose that your boss would like to see another staff in ERP. He will want to see how much electricity was spent by all trains in his company, which train driver has smallest number of accidents, which train driver has biggest number of accidents, how many items in warehouse for fixing trains, which items are needed to be bought, etc.

M. Cool. And all of that is possible to track ERP system?

Y. Exactly. ERP systems actually dedicated to tracking everything that bring any benefit or expense to company.

Next goes my father. Some background information about him. He used to work as turner. He is very far away from computers. Conversation between him and me could look like this (F. stands for father, Y. stands for Yuriy ).

F. Son, recently friend of mine had asked me what kinds of programs you make. I told him that I will ask you, but for now I’m not sure that I’ll be able to re-tell him your words.

Y. No problem. You can give him answer as an example from your activity as turner.

F. Ok, but just don’t convince me to buy ERP.

Y. Well, you’ve just asked what is this. And I believe just raw definition will bring you no benefit. I’ll describe what it does, and you’ll be able to figure out your own definition. So, lets consider your life as turner. First of all, time from the time you buy some metal staff from three or four suppliers. And time from the time you need to know, do you have already that piece of metal and in which storage. One more point of your frustrations some time is who owns you money because sometime your customers give you full price in advance. Sometime they give you partial payment, and sometime they give you money after acquiring detail from you. And all of that information can be tracked in ERP. And if to be more precise, ERP has a lot of staff, and to track just your business is definitely overkill. And of course ERP producers realize it, so for such people as you they provide choice of which modules from ERP you need, and which options from ERP you don’t need. And of course it have some kind of buttons and menu items that allows you to make analytics. Like to analyze at which months you have more customers, at which months less customers, what is average payment and so on.

F. Cool. Now I know what to say to my friend.

And here is conversation with one good friend of mine that is CEO at company that produces pipes. I’ll mark him as C. and myself as Y.

C. Hi Yuriy, long time no seen.

Y. Yeah, programmers and CEO’s are busy people as usually.

C. Yep. I have a question for you. What is ERP system. I know that you program some parts of it.

Y. Well. If to put simply ERP is some kind of web site, that allows you to have all information about your company in easy digestible manner. For example as far as I know you have some information in your CRM, some information in your google drive documents, and some information in your accountancy system, and some information you have in your tracking system and so on. So you have some kind of pretty big zoo in your company. Have you ever wanted to merge all of it in one place and track what’s going on in your company with flexible analytics?

C. Yes, but that is expensive!!!

Y. Well I suppose it depends. For example, if you want to know what is profit of your company in one month you need to spend few hours of your time watching in different parts of your zoo and figure out what is your income. Or for example if you want to know, did your investment in sales manager improved loading of your employees you again need to look in different systems in order to figure out what is going on. So, I have a question. Is your time cheap?

C. Don’t tease with me. You know that my time is more expensive then yours! Of course I appreciate my time.

Y. That is actually purpose of existence of ERP systems. They allow for such busy people as you to quickly see reports of your company functionality and quickly make next decision. For example like this. You can see that investment in sales gave you only 2 % increase in sales. And then you can make decision about should you fire them and hire another or give them bonus.

C. You almost convinced me to buy it!

Y. Well, I can organize it for you of course, but that’s another question.

Copy entry types via web services in Acumatica from one instance into another

Hello everybody.

Today I want to share how to copy Entty Types items in acumaticca from one instance into another instance.

The first step was to create import export settings in both instances of acumatica as described in acumatica manual similar to this screenshot:

The second step was to create project, which I decided to make as windows forms application with the following input fields:

For the button click at entry types write the following:

           var context = new ImportEt.Screen
                {
                    CookieContainer = new CookieContainer(), AllowAutoRedirect = true, EnableDecompression = true, Timeout = 1000000, Url = txtFrom.Text
                };

           var lgRes = context.Login(txtUserName.Text, txtPassword.Text);
           if (lgRes.Code == ErrorCode.OK)
           {
                var ca203000 = context.CA203000GetSchema();
                context.CA203000Clear();


                var export = context.CA203000Export(
                    new Command[]
                        {
                            ca203000.EntryType.EntryTypeID, ca203000.EntryType.DisbReceipt, ca203000.EntryType.EntryTypeDescription, ca203000.EntryType.Module, 
ca203000.EntryType.BusinessAccount, ca203000.EntryType.DefaultOffsetAccount, ca203000.EntryType.UseForPaymentsReclassification,
ca203000.EntryType.ReclassificationAccount, ca203000.EntryType.DeductFromPayment }, null, 0, false, false); context.Url = txtTo.Text; var lgRes2 = context.Login(txtUserName.Text, txtPassword.Text); if (lgRes2.Code == ErrorCode.OK) { ca203000 = context.CA203000GetSchema(); context.CA203000Clear(); foreach (var et in export) { var ca203000ImportResults = context.CA203000Submit( new Command[] { new Value { Value = et[0], LinkedCommand = ca203000.EntryType.EntryTypeID}, new Value { Value = et[1], LinkedCommand = ca203000.EntryType.DisbReceipt }, new Value { Value = et[2], LinkedCommand = ca203000.EntryType.EntryTypeDescription }, new Value { Value = et[3], LinkedCommand = ca203000.EntryType.Module }, new Value { Value = et[4], LinkedCommand = ca203000.EntryType.BusinessAccount }, new Value { Value = et[5], LinkedCommand = ca203000.EntryType.DefaultOffsetAccount }, new Value { Value = et[6], LinkedCommand = ca203000.EntryType.UseForPaymentsReclassification }, new Value { Value = et[7], LinkedCommand = ca203000.EntryType.ReclassificationAccount }, new Value { Value = et[8], LinkedCommand = ca203000.EntryType.DeductFromPayment }, ca203000.Actions.Save }); } } }

 

All activities in Acumatica are done via interface context, whic is of type screen. 

As for me, the easiest way to get some data is via command "screenID" + export. In my code you can see construction CA203000Export. Inside of it you can point to id of screen, data of which you want to receive. For example CA203000Export.

The simplest way to send something to acumatica another instance is function "screen id" + "Submit". In my code you can see method CA203000Submit. Fields Value is self-explanatory as for me. The most important and hard to understand for me was LinkedCommand. It can be name of the field. That means values has to be putted into a field. It can be action name to push on and etc. 

Another important facet of mentioned code is Actions.Save. If it is not mentioned, than code will post data to web services, but they wil not be saved.

 

P.S.    source code

 

Acumatica

Here is just to anounce that the first post in my blog will be about acumatica. If to speak in general acumatica is ERP which from programmers viewpoint is like CMS which is intended for management of the resources at company. It is much cheaper then SAP and it also tries to become competitor of AXAPTA. So, lets see what will be the outcome.