Re: REST API

cambell wrote:
s4m3shms wrote:

I was testing the sales APIs from your latest repository, none of the methods worked for me.

For example:

http://url/modules/api/sales/
or
http://url/modules/api/sales/5

returns nothing.

@s4m3shms The endpoint for the sales url needs to have a transaction type on the end, and its not optional.  So:

http://url/modules/api/sales/10

Have a look at the Sales_Test file to see an example of how to use the api using php.

https://github.com/cambell-prince/FrontAccountingSimpleAPI/blob/master-upstream/tests/Sales_Test.php


would give you all the sales invoices for example.  To get a particular invoice it would be:

http://url/modules/api/sales/5/10

assuming there was an invoice number 5.

Have a look at the Sales_Test.php file to see an example of using the api in php

https://github.com/cambell-prince/FrontAccountingSimpleAPI/blob/master-upstream/tests/Sales_Test.php

Thanks Cambell
In fact I was not aware of the API format, its working now.
I am trying to run your Sales_Test.php page, its not going through due to PHPUnit dependency issue.
Am trying to sort it out and update here.

Thanks again

Re: REST API

Hello Cambell
The error is

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /var/www/fa/fa243/frontaccounting/modules/apitest/tests/Sales_Test.php on line 13

I  have composer.json in the "tests" folder as below and ran composer update

  "require-dev": {
        "phpunit/phpunit": "3.7.*"
     
    }

Is this the correct path, or any specific version should I specify?

Regards

Re: REST API

Dear Cambell

Can you please look at this screenshot?

https://ibb.co/cmmDJ7

I have followed the JSON structure from Sales_Test.php to POST a sale,  but I couldn't add.


{
"trans_type":"10",
"ref":"005/2016",
"comments":"REST POST",
"order_date":"12/31/2016",
"delivery_date":"12/31/2016",
"cust_ref":"TPS",
"deliver_to":"QQ-1",
"delivery_address":"QQ-1",
"phone":"36390908",
"ship_via":"1",
"location":"DEF",
"freight_cost":"0",
"customer_id":"1",
"branch_id":"1",
"sales_type":"1",
"dimension_id":"0",
"dimension2_id":"0",
"items":[{"stock_id":"102","qty":"2","price":"250","discount":"0","description":"iPhone 6 64GB"}]

Message as I got as

{
    "success": 0,
    "msg": "Could Not Save to Database"
}

Regards

Post's attachments

api.jpg 48.3 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Re: REST API

Hello Cambell

Finally I got it working

Sorry to say it was because of duplicate "ref"  element in the entry.

Another question is : when I GET the following  I expected to get all the sales transactions I have done including the sales I have entered through API.

http://URL/modules/api/sales/10/

But I always get two transactions only:
[{"trans_no":"1","type":"10",.................................

{"trans_no":"2","type":"10",..................................
]

Any hints on this?

Regards
Sume

Re: REST API

Hello @apmuthu

Does your version have the same result on returning "sales"?

Regards
Sume

Re: REST API

Look at overwritten Lines 109,110 in api24/sales.inc:

$info[$sale_index]['ov_discount'] = $trans['ov_discount'];
$info[$sale_index]['ov_discount'] = $trans['Total'];

The above has been corrected and committed in my repo.

Also the VARLIB commit in the core has not been updated as yet in this module but committed in my repo.

The URLs for sales (TRANS_TYPE = 10 for Sales Invoices) are like:

http://www.example.com/frontac24/modules/api24/sales/<TRANS_TYPE>
http:// www.example.com/frontac24/modules/api24/sales/<TRANS_NO>/<TRANS_TYPE>
http:// www.example.com/frontac24/modules/api24/sales/<TRANS_NO>/<TRANS_TYPE>?page=<PAGE_NO>

Note the order of the attributes in the last 2 URLs above.
The api24/config_api.inc has the constant RESULTS_PER_PAGE defined in it.

Both work okay in my version. For Transaction Number 2 in Transaction Type Sales Invoice (10) the output is:

{
 "ref":"002\/2017"
,"comments":""
,"order_date":"05\/07\/2017"
,"payment":"4"
,"payment_terms":{
    "0":"4"
   ,"terms_indicator":"4"
   ,"1":"Cash Only"
   ,"terms":"Cash Only"
   ,"2":"0"
   ,"days_before_due":"0"
   ,"3":"0"
   ,"day_in_following_month":"0"
   ,"4":"0"
   ,"inactive":"0"
   ,"5":"1"
   ,"cash_sale":"1"
 }
,"due_date":"05\/07\/2017"
,"phone":""
,"cust_ref":""
,"delivery_address":"N\/A"
,"ship_via":"1"
,"deliver_to":"Donald Easter LLC"
,"delivery_date":"05\/07\/2017"
,"location":"DEF"
,"freight_cost":"0"
,"email":""
,"customer_id":"1"
,"branch_id":"1"
,"sales_type":"1"
,"dimension_id":"0"
,"dimension2_id":"0"
,"line_items":
 [
  {
     "id":"6"
    ,"stock_id":"101"
    ,"qty":1
    ,"units":"each"
    ,"price":"300"
    ,"discount":"0"
    ,"description":"iPad Air 2 16GB"
  }
 ]
,"sub_total":300
,"display_total":300
}

Re: REST API

Hello @apmuthu

Excellent reply, it is clear now.

Thanks very much.

Regards
Sume

58 (edited by s4m3shms 02/19/2018 08:23:53 am)

Re: REST API

Hello Apmuthu

I have retrieved one inventory item using API

{"stock_id":"101","category_id":"1","tax_type_id":"1","description":"iPad Air 2 16GB","long_description":"","units":"each","mb_flag":"B","sales_account":"4010","cogs_account":"5010","inventory_account":"1510","adjustment_account":"5040","wip_account":"1530","purchase_cost":"0","last_cost":null,"material_cost":"200","labour_cost":"0","overhead_cost":"0","inactive":"0","no_sale":"0","no_purchase":"0"}

I need to calculate the "Price after Tax " same as in the  Direct invoice( that is 300 for stock_id 101) in my custom program for POSTing the sales using API. How can I calculate the "Price after Tax" value?

I need to POST something like this

{"stock_id":"101","qty":1,"price":"300","discount":"0","description":"iPad Air 2 16GB"}

Help much appreciated

Regards
Sume

Re: REST API

You cannot get the price and price after tax from the inventory item call.
You need to make a tax call and some other calls - check out the various API constructs as to what will get you what you want. If there is a value in some table's field that is not there in the standard API calls, let us know.

Re: REST API

apmuthu wrote:

You cannot get the price and price after tax from the inventory item call.
You need to make a tax call and some other calls - check out the various API constructs as to what will get you what you want. If there is a value in some table's field that is not there in the standard API calls, let us know.

I have found some API which returns unit cost ,tax types and tax  groups with the below results

{"stock_id":"102","unit_cost":"150"}
[{"id":"1","name":"Regular","exempt":"0"}]
[{"id":"1","name":"Tax","inactive":"0"},{"id":"2","name":"Tax Exempt","inactive":"0"}]

I could not relate these to the sales price.
Also in FA sales pricing, I see the manual entry for sales price!! Is sales price auto calculated from unit_price with taxes??

Sorry for the basic questions. I am trying to do a POS demo for the FA and stuck with this.

Thanks

Re: REST API

Use the normal Web UI for FA and navigate to the screen that provides for the sales price and taxes you want. Study the code behind it and see what functions provide them and use those functions by extending the API to do what you need. Also study the ERDs in the Wiki at:
http://frontaccounting.com/fawiki/index.php?n=Devel.ERDiagram23
http://frontaccounting.com/fawiki/index.php?n=Devel.ERDiagram24

Re: REST API

Thanks @apmuthu. I will go through the code and try my best.

Regards
Sume