Implementation of the Madics Web Sales Order creation API 


Now part of the Madics Web API is the ability to create Sales Order,  this takes a JSON formatted order and when posted to the Madics API creates a Madics Sales Order.



The API call format is: 

http://xxx.xxx.xxx.xxx:port/neworder and including the JSON file/string.  (example at the bottom of this page)

the return string will be:  

{"errstring":"PENDING"}    (successful)

or 

{"errstring":"ERRORS"}




With in Madics


Theses orders are then queued up in the Madics eCommerce holding area awaiting manual review and acceptance. 


If no customer code is supplied then the routine will try to automatically match the incoming customer with an existing customer by:

1) matching email address

2) matching phone number

3) matching a postcode 


If no match then it will auto generate the next customer code with a 4 character prefix based on the "invoice name" and then a plus sign.  when the Madics order is actually created the + will be used to decide the next rolling number, eg. FRED01, FRED02, FRED03 etc.


The holding area will let users  manually edit or choose an existing customer code by pressing one of the following buttons:

C=Select a Customer  or E=Customer Edit


If there are sales order item or location errors theses can also be changed via the I=Item and L=Location buttons.


If there are no errors then highlight the order (header line) and press the F1=Create Order button, this will take you to the Madics sales order (ECOM01) creation routine and display the sales order report,  then returning back to data-grid populating the sales order number column it created.


Once created the E=Edit Order button will take you straight into sales order desk to review, amend etc and then return back to this data-grid.



Other options:


F5 Will allow you to manually import a JSON file and not needing to process the file via the API.

F6 Will show all the order files processed/complete.



The F5 Manual JSON will open a file select dialog box:




Under the bonnet


The API executes the MADWEB.RUN routine,  if the NEWORDER parameter is found on the incoming request then it spawns ECOMJS.RUN this routine reads in, processes, error checks the JSON and creates individual sales order pending files, an email can be fire off to let users know a new order has arrived and needs inspecting/accepting. 


Running ECOMVW (as per screen shot above) shows all the pending orders and are accepted win in here.


On DSK89: (or where ever the ECOMJ.INI point to) your find all the JSON and EORDER files, pending and processed.


The long file names with a running number followed by date-time are the incoming JSON files, for example:

000039-201029114504

Theses will have a file extension of .OK if processed or .ERR if it failed to import.


The shorter 6 character files starting with E are the pending/processed sales orders (created from the JSON file) for example:

e00037.ord       - .ORD extension are orders pending creation. 

e00035.ok        -  .OK extension means Sales Order created with NO errors.

e00032.oke      -  .OKE extension means Sales Order created but with some errors, See ECOM01 report.

e00033.err       -  .ERR an error occurred creating the sames order.

e00038.del       -  .DEL are deleted orders that were never processed.


Please note the running number sequence between the E order and JSON files are independent of each other, to tie the two together look at the ECOMJS.LOG file. 


Recommend also looking in the following log files:

OPR:MADWEB.LOG - For incoming API activity

ECOMJS.LOG - For JSON order processing.

ECOMVW.LOG - For order user processing and manual changes.

ECOM01.LOG - Created sales orders


An overnight routine called ECOMIX.RUN  that should run in the tasks manager (or hourly in cron) automatically creates customer indexes for email, phone and postcode from customers and contacts, theses are used for the customer/order.


Ashell/Linux Version 6.5.1688.1 or later is also required.



Setup


Recommend creating a new Madics disk thats not used for anything else, for example DSK89:  this is to store all the incoming / created JSON and EORDER files.


Create a ECMOJS.INI in DSK0:[241,1]


[SETTINGS]

DEBUG MODE=N

ECOMJS TEMP DISK=DSK98

CREATE SALES ORDER=N

VALIDATE CUSTOMER=N

DESPATCH METHOD=4

ORDER SOURCE=A

PART DESPATCH=N

HOLD FLAG=8

DEFAULT CUSTOMER CODE=

DEFAULT LOCATION=CW

RECIPIENT EMAIL ADDRESS=some@one.com

ADMIN EMAIL ADDRESS=some@one.com

FROM EMAIL ADDRESS=some@one.com


[CUSTOMER TEMPLATE]

1=WEBTPL

4=WEBTPJ

6=WEBTPM



Setting up the Linux server end API  


Install Python 3 if not already there

Install cherrypy into the python3 installation (pip install cherrypy is the easiest way)


Create a directory for the api. copy madservice2.py into it. Create a directory "logs" in it


create a CMD file like this (e.g. MADWEB.CMD or MADAPI.CMD)


:R
LOG OPR:
RUN USERON API001/FORCE/NOAUDIT/EXIT
LOG DSK0:[241,1] <-----------Set to the correct PPN for SOM in the company you want the order to be created in.
RUN MADWEB


Make sure that "madservice2.py" has the name of the command file correct, usually MADWEB.




Example JSON file


{

   "OrderHead": {

      "OrderType": "PUO",

      "FuncCode": "FIO",

      "OrderDesc": "Purchase Order",

      "FuncDesc": "Firm Order",

      "Currency": {

         "CurrType": "ORD",

         "CurrCode": "GBP",

         "CurrTypeDesc": "Order Currency",

         "CurrCodesc": "Pounds Sterling",

         "CurRate": "1",

         "CurrCalc": "M"

      },

      "IntRep": "STEVE",

      "ExtRep": "002",

      "Segment": "025",

      "Admin": "CB",

      "Area": "123",

      "Marketing1": "Y",

      "Marketing2": "N",

      "Marketing3": "Y",

      "Marketing4": "N",

      "Marketing5": "Y",

      "Marketing6": "N",

      "CompanyNumber": "6",

      "LtdCompany": "Y"

   },

   "Reference": {

      "RefType": "CUR",

      "RefDesc": "Customers Reference Number",

      "RefCode": "CusRefCode",

      "RefContact": "Mr Contact Name"

   },

   "DateInfo": {

      "DateType": "ORD",

      "DateDesc": "Purchase Order Date",

      "Date": "2020-10-29"

   },

   "Buyer": {

      "PartyCode": {

         "IDType": "BUY",

         "IDDesc": "Customer Code",

         "IDCode": "s"

      },

      "Contact": [

         {

            "CommNumb": {

               "ConumType": "EML",

               "ConumDesc": "Email Address",

               "ContactNo": "someone@new.com"

            }

         },

         {

            "CommNumb": {

               "ConumType": "FAX",

               "ConumDesc": "FaX Number",

               "ContactNo": []

            }

         },

         {

            "CommNumb": {

               "ConumType": "TEL",

               "ConumDesc": "Telephone Number",

               "ContactNo": "6543320111"

            }

         }

      ]

   },

   "InvoiceTo": {

      "BranchCode": "",

      "Method": "4",

    "Address": {

      "Name": "Mr Dougal Zebedee",

      "Street": [

        "Magic Roundabout",

        []

      ],

      "City": "Derby",

      "State": "Derbyshire",

      "PostCode": "DE99 822",

      "Country": "GB"

    }

   },

   "Delivery": {

      "BranchCode": "",

      "Method": null,

      "Address": {

         "Name": "Rod, Jane & Freddy",

         "Street": [

            "Unit 28, Robinson Business Park",

            []

         ],

         "City": "NoWhere",

         "State": "Derbyshire",

         "PostCode": "PE22 ABC",

         "Country": "GB"

      }

   },

   "OrderLine": [

      {

         "LineNo": "1",

         "LineTotal": "229",

         "Product": {

            "ProdCodeType": "SPC",

            "ProdCodeDesc": "Suppliers Code",

            "ProdNum": "STEVETEST",

            "Description": [],

            "Location": "01"

         },

         "Quantity": {

            "QtyCode": "ORD",

            "QuantityAmount": "1"

         },

         "Price": {

            "PriceType": "SEL",

            "PriceDesc": "Selling Price",

            "PriceAmount": "229"

         },

         "DateInfo": {

            "DateType": "DED",

            "DateDesc": "Delivery Date",

            "Date": "2020-10-20"

         },

         "LineTax": {

            "TaxCode": [],

            "TaxRate": "0.2",

            "TaxValue": "45.8"

         }

      },

      {

         "LineNo": "2",

         "LineTotal": "99",

         "Product": {

            "ProdCodeType": "SPC",

            "ProdCodeDesc": "Suppliers Code",

            "ProdNum": "BIKE",

            "Description": [],

            "Location": "01"

         },

         "Quantity": {

            "QtyCode": "ORD",

            "QuantityAmount": "1"

         },

         "Price": {

            "PriceType": "SEL",

            "PriceDesc": "Selling Price",

            "PriceAmount": "99"

         },

         "DateInfo": {

            "DateType": "DED",

            "DateDesc": "Delivery Date",

            "Date": "2020-10-16"

         },

         "LineTax": {

            "TaxCode": [],

            "TaxRate": "0.2",

            "TaxValue": "19.8"

         }

      },

      {

         "LineNo": "3",

         "LineTotal": "99",

         "Product": {

            "ProdCodeType": "SPC",

            "ProdCodeDesc": "Suppliers Code",

            "ProdNum": "342X1/2TC",

            "Description": [],

            "Location": "01"

         },

         "Quantity": {

            "QtyCode": "ORD",

            "QuantityAmount": "1"

         },

         "Price": {

            "PriceType": "SEL",

            "PriceDesc": "Selling Price",

            "PriceAmount": "99"

         },

         "DateInfo": {

            "DateType": "DED",

            "DateDesc": "Delivery Date",

            "Date": "2020-10-16"

         },

         "LineTax": {

            "TaxCode": [],

            "TaxRate": "0.2",

            "TaxValue": "19.8"

         }

      },

      {

         "LineNo": "4",

         "LineTotal": "429",

         "Product": {

            "ProdCodeType": "SPC",

            "ProdCodeDesc": "Suppliers Code",

            "ProdNum": "FA10080",

            "Description": [],

            "Location": "02"

         },

         "Quantity": {

            "QtyCode": "ORD",

            "QuantityAmount": "1"

         },

         "Price": {

            "PriceType": "SEL",

            "PriceDesc": "Selling Price",

            "PriceAmount": "429"

         },

         "DateInfo": {

            "DateType": "DED",

            "DateDesc": "Delivery Date",

            "Date": "2020-10-16"

         },

         "LineTax": {

            "TaxCode": [],

            "TaxRate": "0.2",

            "TaxValue": "85.8"

         }

      },

      {

         "LineNo": "5",

         "LineTotal": "249",

         "Product": {

            "ProdCodeType": "SPC",

            "ProdCodeDesc": "Suppliers Code",

            "ProdNum": "STEVE54321",

            "Description": [],

            "Location": "01"

         },

         "Quantity": {

            "QtyCode": "ORD",

            "QuantityAmount": "2"

         },

         "Price": {

            "PriceType": "SEL",

            "PriceDesc": "Selling Price",

            "PriceAmount": "249"

         },

         "DateInfo": {

            "DateType": "DED",

            "DateDesc": "Delivery Date",

            "Date": "2020-10-16"

         },

         "LineTax": {

            "TaxCode": [],

            "TaxRate": "0.2",

            "TaxValue": "49.8"

         }

      }

   ],

   "Narrative": {

      "NarrType": "SPI",

      "NarrDesc": "Special Instructions",

      "Text": "THIS IS SPECIAL INSTR"

   },

   "Settlement": {

      "PaymentType": "1",

      "CardDetails": {

         "CardType": "Visa",

         "Issuer": [],

         "Party": [],

         "IssueDate": [],

         "ExpiryDate": "0123",

         "CardNumber": "XXXX-XXXX-XXXX-9876",

         "CardCCV": "XXX",

         "CardPostCode": "SG8 6HW",

         "CardBuildingNumber": "15",

         "IssueNumber": [],

         "AuthorisationCode": "123456"

      }

   },

   "OrderTotal": {

      "OrdNoLines": "5",

      "TotalLines": "5",

      "OrdLineTot": "1354.00",

      "OrdTaxTot": "221",

      "OrdGrossPay": "1575.00"

   }

}