AOTG API: Create Cash Sale

From AutoCount Resource Center
Jump to navigation Jump to search
[DRAFT]

Create Cash Sale

Create a new Cash Sale.

API Method

Http Method: POST
Method: /api/public/v1/CashSale
Content-Type: application/json
Parameters: None


Code Snippets

<?php

$request = new HttpRequest();
$request->setUrl('http://aotg.cloud:8080/api/public/v1/CashSale/');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'SOTC_AUTH' => 'SAMs1a36d2-a139-e911-b8b3-000aa03t3d',
  'Content-Type' => 'application/json'
));

$request->setBody('{
  "Debtor": "300-C007",
  "DocumentDate": "2019-03-28T09:51:19.349Z",
  "Agent": null,
  "SalesLocation": "HQ",
  "DebtorName": "Cash Sale",
  "Description": "string",
  "InclusiveTax": false,
  "DetailsLine": [
    {
      "Item": "FG00001",
      "UOM": "UNIT",
      "Qty": 2,
      "UnitPrice": 50,
      "Description": "Finished Goods 001",
      "Location": "HQ",
      "AccNo": "500-0000",
      "DeliveryDate": "2019-03-28T09:51:19.349Z",
      "Tax": "S-10",
      "Discount": "10%+5%",
      "RowState": 0
    }
  ],
  "Payment": {
    "CCApprovalCode": "A498558",
    "PaymentAmount": 94.05,
    "CurrencyCode": "MYR",
    "CurrencySymbol": "MYR",
    "ToLocalCurrencyRate": 1,
    "ToDebtorCurrencyRate": 1,
    "Date": "2019-03-28T09:51:19.349Z",
    "ReceiptReferenceNo": null,
    "ProjNo": null,
    "DeptNo": null,
    "DetailsLine": [
      {
        "PaymentMethod": "CASH",
        "Amount": 94.05,
        "ChequeNo": null,
        "BankCharge": 0,
        "BankChargeTaxType": null,
        "BankChargeTax": null,
        "BankChargeTaxRefNo": null,
        "PaymentBy": "Cash",
        "IsRCHQ": false,
        "RCHQDate": null,
        "RowState": 0
      }
    ]
  },
  "PaymentMode": 1,
  "CurrencyCode": "MYR",
  "CurrencyRate": 1,
  "UnPostToGL": false,
  "UnPostToStock": false
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

var client = new RestClient("http://aotg.cloud:8080/api/public/v1/CashSale/");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("SOTC_AUTH", "SAMs1a36d2-a139-e911-b8b3-000aa03t3d");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("undefined", "{\n  \"Debtor\": \"300-C007\",\n  \"DocumentDate\": \"2019-03-28T09:51:19.349Z\",\n  \"Agent\": null,\n  \"SalesLocation\": \"HQ\",\n  \"DebtorName\": \"Cash Sale\",\n  \"Description\": \"string\",\n  \"InclusiveTax\": false,\n  \"DetailsLine\": [\n    {\n      \"Item\": \"FG00001\",\n      \"UOM\": \"UNIT\",\n      \"Qty\": 2,\n      \"UnitPrice\": 50,\n      \"Description\": \"Finished Goods 001\",\n      \"Location\": \"HQ\",\n      \"AccNo\": \"500-0000\",\n      \"DeliveryDate\": \"2019-03-28T09:51:19.349Z\",\n      \"Tax\": \"S-10\",\n      \"Discount\": \"10%+5%\",\n      \"RowState\": 0\n    }\n  ],\n  \"Payment\": {\n    \"CCApprovalCode\": \"A498558\",\n    \"PaymentAmount\": 94.05,\n    \"CurrencyCode\": \"MYR\",\n    \"CurrencySymbol\": \"MYR\",\n    \"ToLocalCurrencyRate\": 1,\n    \"ToDebtorCurrencyRate\": 1,\n    \"Date\": \"2019-03-28T09:51:19.349Z\",\n    \"ReceiptReferenceNo\": null,\n    \"ProjNo\": null,\n    \"DeptNo\": null,\n    \"DetailsLine\": [\n      {\n        \"PaymentMethod\": \"CASH\",\n        \"Amount\": 94.05,\n        \"ChequeNo\": null,\n        \"BankCharge\": 0,\n        \"BankChargeTaxType\": null,\n        \"BankChargeTax\": null,\n        \"BankChargeTaxRefNo\": null,\n        \"PaymentBy\": \"Cash\",\n        \"IsRCHQ\": false,\n        \"RCHQDate\": null,\n        \"RowState\": 0\n      }\n    ]\n  },\n  \"PaymentMode\": 1,\n  \"CurrencyCode\": \"MYR\",\n  \"CurrencyRate\": 1,\n  \"UnPostToGL\": false,\n  \"UnPostToStock\": false\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_PORT => "8080",
  CURLOPT_URL => "http://aotg.cloud:8080/api/public/v1/CashSale/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\n  \"Debtor\": \"300-C007\",\n  \"DocumentDate\": \"2019-03-28T09:51:19.349Z\",\n  \"Agent\": null,\n  \"SalesLocation\": \"HQ\",\n  \"DebtorName\": \"Cash Sale\",\n  \"Description\": \"string\",\n  \"InclusiveTax\": false,\n  \"DetailsLine\": [\n    {\n      \"Item\": \"FG00001\",\n      \"UOM\": \"UNIT\",\n      \"Qty\": 2,\n      \"UnitPrice\": 50,\n      \"Description\": \"Finished Goods 001\",\n      \"Location\": \"HQ\",\n      \"AccNo\": \"500-0000\",\n      \"DeliveryDate\": \"2019-03-28T09:51:19.349Z\",\n      \"Tax\": \"S-10\",\n      \"Discount\": \"10%+5%\",\n      \"RowState\": 0\n    }\n  ],\n  \"Payment\": {\n    \"CCApprovalCode\": \"A498558\",\n    \"PaymentAmount\": 94.05,\n    \"CurrencyCode\": \"MYR\",\n    \"CurrencySymbol\": \"MYR\",\n    \"ToLocalCurrencyRate\": 1,\n    \"ToDebtorCurrencyRate\": 1,\n    \"Date\": \"2019-03-28T09:51:19.349Z\",\n    \"ReceiptReferenceNo\": null,\n    \"ProjNo\": null,\n    \"DeptNo\": null,\n    \"DetailsLine\": [\n      {\n        \"PaymentMethod\": \"CASH\",\n        \"Amount\": 94.05,\n        \"ChequeNo\": null,\n        \"BankCharge\": 0,\n        \"BankChargeTaxType\": null,\n        \"BankChargeTax\": null,\n        \"BankChargeTaxRefNo\": null,\n        \"PaymentBy\": \"Cash\",\n        \"IsRCHQ\": false,\n        \"RCHQDate\": null,\n        \"RowState\": 0\n      }\n    ]\n  },\n  \"PaymentMode\": 1,\n  \"CurrencyCode\": \"MYR\",\n  \"CurrencyRate\": 1,\n  \"UnPostToGL\": false,\n  \"UnPostToStock\": false\n}",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/json",
    "SOTC_AUTH: SAMs1a36d2-a139-e911-b8b3-000aa03t3d",
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

import requests

url = "http://aotg.cloud:8080/api/public/v1/CashSale/"

payload = "{\n  \"Debtor\": \"300-C007\",\n  \"DocumentDate\": \"2019-03-28T09:51:19.349Z\",\n  \"Agent\": null,\n  \"SalesLocation\": \"HQ\",\n  \"DebtorName\": \"Cash Sale\",\n  \"Description\": \"string\",\n  \"InclusiveTax\": false,\n  \"DetailsLine\": [\n    {\n      \"Item\": \"FG00001\",\n      \"UOM\": \"UNIT\",\n      \"Qty\": 2,\n      \"UnitPrice\": 50,\n      \"Description\": \"Finished Goods 001\",\n      \"Location\": \"HQ\",\n      \"AccNo\": \"500-0000\",\n      \"DeliveryDate\": \"2019-03-28T09:51:19.349Z\",\n      \"Tax\": \"S-10\",\n      \"Discount\": \"10%+5%\",\n      \"RowState\": 0\n    }\n  ],\n  \"Payment\": {\n    \"CCApprovalCode\": \"A498558\",\n    \"PaymentAmount\": 94.05,\n    \"CurrencyCode\": \"MYR\",\n    \"CurrencySymbol\": \"MYR\",\n    \"ToLocalCurrencyRate\": 1,\n    \"ToDebtorCurrencyRate\": 1,\n    \"Date\": \"2019-03-28T09:51:19.349Z\",\n    \"ReceiptReferenceNo\": null,\n    \"ProjNo\": null,\n    \"DeptNo\": null,\n    \"DetailsLine\": [\n      {\n        \"PaymentMethod\": \"CASH\",\n        \"Amount\": 94.05,\n        \"ChequeNo\": null,\n        \"BankCharge\": 0,\n        \"BankChargeTaxType\": null,\n        \"BankChargeTax\": null,\n        \"BankChargeTaxRefNo\": null,\n        \"PaymentBy\": \"Cash\",\n        \"IsRCHQ\": false,\n        \"RCHQDate\": null,\n        \"RowState\": 0\n      }\n    ]\n  },\n  \"PaymentMode\": 1,\n  \"CurrencyCode\": \"MYR\",\n  \"CurrencyRate\": 1,\n  \"UnPostToGL\": false,\n  \"UnPostToStock\": false\n}"
headers = {
    'Content-Type': "application/json",
    'SOTC_AUTH': "SAMs1a36d2-a139-e911-b8b3-000aa03t3d",
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)




Check Status

Code Snippets

<?php

$request = new HttpRequest();
$request->setUrl('http://aotg.cloud:8080/api/public/v1/Result/161bab79-29d7-44e3-8e06-838c3fadc5f0');
$request->setMethod(HTTP_METH_GET);

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'SOTC_AUTH' => 'SAMs1a36d2-a139-e911-b8b3-000aa03t3d'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

var client = new RestClient("http://aotg.cloud:8080/api/public/v1/Result/161bab79-29d7-44e3-8e06-838c3fadc5f0");
var request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("SOTC_AUTH", "SAMs1a36d2-a139-e911-b8b3-000aa03t3d");
IRestResponse response = client.Execute(request);

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_PORT => "8080",
  CURLOPT_URL => "http://aotg.cloud:8080/api/public/v1/Result/161bab79-29d7-44e3-8e06-838c3fadc5f0",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => array(
    "SOTC_AUTH: SAMs1a36d2-a139-e911-b8b3-000aa03t3d",
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

import requests

url = "http://aotg.cloud:8080/api/public/v1/Result/161bab79-29d7-44e3-8e06-838c3fadc5f0"

payload = ""
headers = {
    'SOTC_AUTH': "SAMs1a36d2-a139-e911-b8b3-000aa03t3d",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, data=payload, headers=headers)

print(response.text)

Response Status

Response Successful HTTP Request

200 OK


4 possible response body of the process status.

InQueue status
  • InQueue status Indicates that the requests to AOTG Server is waiting to be processed.
  • Usually this happen when many requests are called to AOTG Web API in within a second.
    Make sure the request in the loop has pause time,
    or use 'batch' method to process multiple records in single request if applicable.
"RequestId": 161bab79-29d7-44e3-8e06-838c3fadc5f0,
"Status": "InQueue"
Processing status
  • Processing status indicates that the request is not complete.
"RequestId": 161bab79-29d7-44e3-8e06-838c3fadc5f0,
"Status": "Processing"
Completed status
  • Completed status Indicates that the request has been performed and succeeded.
"RequestId": 161bab79-29d7-44e3-8e06-838c3fadc5f0,
"Status": "Completed"
Failed status
  • Failed status indicates that the request has been performed but has error.
"RequestId": 161bab79-29d7-44e3-8e06-838c3fadc5f0,
"Status": "Failed"


Get Result

<?php

$request = new HttpRequest();
$request->setUrl('http://aotg.cloud:8080/api/public/v1/Result/CreateCashSales/161bab79-29d7-44e3-8e06-838c3fadc5f0/result');
$request->setMethod(HTTP_METH_GET);

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'SOTC_AUTH' => 'SAMs1a36d2-a139-e911-b8b3-000aa03t3d'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

var client = new RestClient("http://aotg.cloud:8080/api/public/v1/Result/CreateCashSales/161bab79-29d7-44e3-8e06-838c3fadc5f0/result");
var request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("SOTC_AUTH", "SAMs1a36d2-a139-e911-b8b3-000aa03t3d");
IRestResponse response = client.Execute(request);

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_PORT => "8080",
  CURLOPT_URL => "http://aotg.cloud:8080/api/public/v1/Result/CreateCashSales/161bab79-29d7-44e3-8e06-838c3fadc5f0/result",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => array(
    "SOTC_AUTH: SAMs1a36d2-a139-e911-b8b3-000aa03t3d",
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

import requests

url = "http://aotg.cloud:8080/api/public/v1/Result/CreateCashSales/161bab79-29d7-44e3-8e06-838c3fadc5f0/result"

payload = ""
headers = {
    'SOTC_AUTH': "SAMs1a36d2-a139-e911-b8b3-000aa03t3d",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, data=payload, headers=headers)

print(response.text)


{

   "RequestId": "161bab79-29d7-44e3-8e06-838c3fadc5f0",
   "RequestName": "CreateCashSales",
   "HostName": "---",
   "IPAddress": "---",
   "RequestTypeName": "CashSale",
   "ResultJson": "{\"Id\":\"1544\",\"Number\":\"CS-000008\",\"Agent\":\"\",\"SalesLocation\":\"HQ\",\"DocumentDate\":\"2019-03-28T00:00:00\",\"Debtor\":\"300-C007\",\"DebtorName\":\"Cash Sale\",\"Contact\":null,\"Fax\":null,\"Phone\":null,\"DeliverAddress\":{\"Contact\":\"\",\"Fax\":\"\",\"Phone\":\"\",\"Address1\":\"\",\"Address2\":\"\",\"Address3\":\"\",\"Address4\":\"\"},\"Description\":\"string\",\"Ref\":\"\",\"RefDocNo\":\"\",\"Note\":\"\",\"Outstanding\":94.05,\"Total\":94.05,\"NetTotal\":94.05,\"TaxAmount\":8.55,\"InclusiveTax\":false,\"DetailsLine\":[{\"Item\":\"FG00001\",\"UOM\":\"UNIT\",\"IsGoodsReturn\":false,\"TransferedQty\":0.00000000,\"IsTransferred\":false,\"UDFLineDatas\":null,\"Qty\":2.00000000,\"UnitPrice\":50.00000000,\"Tax\":\"S-10\",\"TaxRate\":10.000000,\"TaxAmount\":8.55,\"SubTotal\":94.05,\"SubTotalExTax\":85.50,\"TaxableAmount\":85.50,\"Discount\":\"10%+5%\",\"DiscountAmount\":14.50,\"SmallestQty\":2.00000000,\"SmallestUnitPrice\":50.00000000,\"LocalTaxAmount\":8.55,\"LocalSubTotal\":85.50,\"LocalSubTotalExTax\":85.50,\"LocalTaxableAmount\":85.50,\"Id\":\"1546\",\"Description\":\"Finished Goods 001\",\"FurtherDescription\":\"\",\"Location\":\"HQ\",\"RowState\":0,\"FromDocType\":\"\",\"FromDocNo\":\"\",\"FromDocDtlKey\":\"\",\"FullTransferFromDocList\":\"\",\"AccNo\":\"500-0000\",\"IsFromFullTransferredLine\":false,\"IsFromPartialTransferredLine\":false,\"TransferFromDocumentType\":0,\"IsTempTransferLine\":false,\"LineIndex\":16,\"Project\":\"\",\"Dept\":\"\",\"DeliveryDate\":\"2019-03-28T00:00:00\",\"SalesTaxExemptionNo\":\"\",\"TariffCode\":\"\"}],\"PaymentMode\":1,\"Payment\":{\"Id\":null,\"DocumentId\":null,\"DebtorCode\":null,\"ProjNo\":null,\"DeptNo\":null,\"Date\":\"0001-01-01T00:00:00\",\"Description\":null,\"ReceiptNo\":null,\"ReceiptReferenceNo\":null,\"CCApprovalCode\":null,\"PaymentAmount\":0.00,\"DetailsLine\":[{\"PaymentMethod\":null,\"ChequeNo\":null,\"Amount\":0.00,\"BankCharge\":0.0,\"BankChargeTaxType\":null,\"BankChargeTax\":0.0,\"BankChargeTaxRate\":0.0,\"BankChargeTaxRefNo\":null,\"PaymentBy\":null,\"IsRCHQ\":false,\"RCHQDate\":null,\"RowState\":\"Unchanged\",\"Id\":null,\"ToBankRate\":0.0}],\"CurrencyCode\":\"MYR\",\"CurrencySymbol\":\"RM\",\"ToLocalCurrencyRate\":1.0,\"ToDebtorCurrencyRate\":1.0},\"IsRoundAdj\":false,\"RoundingMethod\":4,\"RoundAdj\":0.00,\"IsCancelled\":false,\"ToDocType\":\"\",\"ToDocKey\":\"\",\"IsTransferred\":false,\"TransferFromQuotationDocument\":{\"FullTransferFromSalesDocument\":[],\"PartialTransferFromSalesDocument\":[]},\"TransferFromSalesOrderDocument\":{\"FullTransferFromSalesDocument\":[],\"PartialTransferFromSalesDocument\":[]},\"TransferFromDeliveryOrderDocument\":{\"FullTransferFromSalesDocument\":[],\"PartialTransferFromSalesDocument\":[]},\"CurrencyCode\":\"MYR\",\"CurrencySymbol\":\"RM\",\"CurrencyRate\":1.000000,\"LocalNetTotal\":94.05,\"LocalTaxAmount\":8.55,\"UnPostToGL\":false,\"UnPostToStock\":false,\"Branch\":\"\",\"SalesTaxExemptionNo\":\"\",\"SalesTaxExemptionExpiryDate\":null,\"EnableBranch\":false,\"ValidateBackOrder\":false,\"ValidateMinMaxPrice\":false}",
   "RequestParamJson": null,
   "ResultStream": null,
   "ResultTypeName": "PSW.SOTC.Accounting.Provider.Models.CashSaleEntity",
   "Status": "Completed",
   "Version": "1.2.19080.12001",
   "AccountBookInfo": "Plug-In 1.9 Test;1.0.9.77",
   "AccountBookDBInfo": "1.0.9.77",
   "Timestamp": "2019-03-28T10:15:47.5933448Z",
   "ResultedTimestamp": "2019-03-28T10:15:47.6780636Z",
   "ProcessingInterval": 4.5932962999999996,
   "InQueueInterval": 1.2547191,
   "ResultFileURL": null

}




Example of error {

   "RequestId": "99829210-a812-4fd6-8d91-4b32401030d4",
   "Status": "Failed"

}

{

   "RequestId": "99829210-a812-4fd6-8d91-4b32401030d4",
   "RequestName": "CreateCashSales",
   "HostName": "---",
   "IPAddress": "---",
   "RequestTypeName": null,
   "ResultJson": "{\"Message\":\"Debtor record not found (AccNo=300-B001).\",\"StackTrace\":\"   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)\\r\\n   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)\\r\\n   at System.Threading.Tasks.Task`1.get_Result()\\r\\n   at PSW.SOTC.Accounting.InProcess.AppServiceDispatcher.<DispatchRequest>d__13.MoveNext()\",\"Source\":\"PSW.SOTC.Accounting.Provider.Autocount\"}",
   "RequestParamJson": null,
   "ResultStream": null,
   "ResultTypeName": "PSW.SOTC.Accounting.Provider.Models.ExceptionEntity",
   "Status": "Failed",
   "Version": "1.2.19080.12001",
   "AccountBookInfo": "Plug-In 1.9 Test-1.0.9.77",
   "AccountBookDBInfo": "1.0.9.77",
   "Timestamp": "2019-03-28T10:06:51.8595839Z",
   "ResultedTimestamp": null,
   "ProcessingInterval": 0.9720572999999999,
   "InQueueInterval": null,
   "ResultFileURL": null

}

See Also AOTG API


Go to menu

IconAC81.png Go to top
ProgrammerGo.jpg Resources For AutoCount Software Developers