1

(3 replies, posted in Items and Inventory)

I am having the same problem with the user in this post: https://frontaccounting.com/punbb/viewtopic.php?id=4935

Instead of doing what is in the post, I added this line as the first line inside function update_average_material_cost

return $price;

I wanted to nullify the whole process inside the function.

Will there be any other effect by doing this?

2

(20 replies, posted in Items and Inventory)

The second snippet is from the above transfer.inc , line 59.

I think I broke functionality for single addition, I will try to fix it and update the example later on.

3

(20 replies, posted in Items and Inventory)

I bring good news. I managed to modify it so it can handle multiple items entry.
POST the stock_id, qty, as arrays ex:

stock_id[0]
stock_id[1]
stock_id[2]
quantity[0]
quantity[1]
quantity[2]

Here is the new transfer.inc

<?php
/**********************************************
Author: Andres Amaya
Name: Inventory REST API
Free software under GNU GPL
***********************************************/
$path_to_root = "../..";
include_once ($path_to_root . "/inventory/includes/inventory_db.inc");
include_once ($path_to_root . "/inventory/includes/db/items_codes_db.inc");
include_once ($path_to_root . "/inventory/includes/db/items_locations_db.inc");
include_once ($path_to_root . "/inventory/includes/db/items_transfer_db.inc");
include_once ($path_to_root . "/gl/includes/gl_db.inc");
include_once ($path_to_root . "/includes/ui/items_cart.inc");
function stock_transfer_add()
{
    $app = \Slim\Slim::getInstance('SASYS');
    $req = $app->request();
    $info = $req->post();
    // Example
    // $ex = array('stock_id' => 'PLUMA', 'location_from' => 'DEF', 'location_to' => 'XXX', 'date' => today(), 'reference' =>
    // '123qwe', 'quantity' => 555, 'standard_cost' => 10, 'memo' => 'Proof of API 2');
    // echo base64_encode(json_encode($ex));
    // print_r($info);
    // Validate Required Fields
    if (! isset($info['stock_id'])) {
        api_error(412, 'Stock Id is required aieu');
    }
    if (! isset($info['location_from'])) {
        api_error(412, 'Location from is required');
    }
    if (! isset($info['location_to'])) {
        api_error(412, 'Location to is required');
    }
    if (! isset($info['date'])) {
        api_error(412, 'Date is required');
    }
    if (! isset($info['reference'])) {
        api_error(412, 'Reference is required');
    }
    if (! isset($info['quantity'])) {
        api_error(412, 'Quantity is required');
    }
    if (! isset($info['standard_cost'])) {
        $info['standard_cost'] = 0;
    }
    if (! isset($info['memo'])) {
        api_error(412, 'Memo is required');
    }
    // Create Adjustment Order
    unset($_SESSION['transfer_items']);
    $_SESSION['transfer_items'] = new items_cart(ST_LOCTRANSFER);
    $_SESSION['gl_items'] = new items_cart(0);
    $info['date'] = today();
    if (! is_date_in_fiscalyear($info['date']))
        $info['date'] = end_fiscalyear();
    $_SESSION['transfer_items']->tran_date = $info['date'];
    $_SESSION['gl_items']->tran_date = $info['date'];
    // This should never happen
    if ($_SESSION['transfer_items']->find_cart_item($info['stock_id']))
        api_error(500, 'Item Already Exists In Cart');
    else {
        for($i = 0; $i < count($info['stock_id']); $i++) {
        $_SESSION['transfer_items']->add_to_cart($i, $info['stock_id'][$i], $info['quantity'][$i], 0);
        // $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null
        // TODO Obtain accounts against which to make seats
        // Product Inventory
        $_SESSION['gl_items']->add_gl_item('1510', 0, 0, ($info['quantity'][$i] * $info['standard_cost'][$i] * - 1), $info['memo']);
        // Configured for Absolute, Own
        $_SESSION['gl_items']->add_gl_item('4010', 0, 0, ($info['quantity'][$i] * $info['standard_cost'][$i]), $info['memo']);
        $_SESSION['gl_items']->order_id = 0;
        $_SESSION['gl_items']->reference = 666;
        }
    }
    /*
     * print_r($_SESSION['transfer_items']); echo "----------- GL -------"; print_r($_SESSION['gl_items']); echo "------
     * DEBIT: " . $_SESSION['gl_items']->gl_items_total_debit(); echo "------ CREDIT: " .
     * $_SESSION['gl_items']->gl_items_total_credit();
     */
    // Process Order
    $trans_no = add_stock_transfer($_SESSION['transfer_items']->line_items, $info['location_from'], $info['location_to'], $info['date'], $info['reference'], $info['memo']);
    $gl_trans_no = write_journal_entries($_SESSION['gl_items'], false);
    new_doc_date($info['date']);
    $_SESSION['transfer_items']->clear_items();
    unset($_SESSION['transfer_items']);
    $_SESSION['gl_items']->clear_items();
    unset($_SESSION['gl_items']);
    api_create_response("Stock Transfer has been added");
}
?>

I didn't merge the code with inventory.inc out of fear messing the original entry.

Here is where some changes is made:

if ($_SESSION['transfer_items']->find_cart_item($info['stock_id']))
        api_error(500, 'Item Already Exists In Cart');
    else {
        for($i = 0; $i < count($info['stock_id']); $i++) {
        $_SESSION['transfer_items']->add_to_cart($i, $info['stock_id'][$i], $info['quantity'][$i], 0);
        // $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null
        // TODO Obtain accounts against which to make seats
        // Product Inventory
        $_SESSION['gl_items']->add_gl_item('1510', 0, 0, ($info['quantity'][$i] * $info['standard_cost'][$i] * - 1), $info['memo']);
        // Configured for Absolute, Own
        $_SESSION['gl_items']->add_gl_item('4010', 0, 0, ($info['quantity'][$i] * $info['standard_cost'][$i]), $info['memo']);
        $_SESSION['gl_items']->order_id = 0;
        $_SESSION['gl_items']->reference = 666;
        }
    }

Now, I MacGyvered (figured out) most of my way into the code to make it work. I have zero clue in some areas of the code, example is the 'gl_items' entries. I have zero idea what it does in the system and my code may mess something up. I hope someone knowledgeable on it could help me on this.

4

(20 replies, posted in Items and Inventory)

I finally get the stock transfer API to work.

For anyone interested,

create a new transfer.inc file at the main api directory:

<?php
/**********************************************
Author: Andres Amaya
Name: Inventory REST API
Free software under GNU GPL
***********************************************/
$path_to_root = "../..";
include_once ($path_to_root . "/inventory/includes/inventory_db.inc");
include_once ($path_to_root . "/inventory/includes/db/items_codes_db.inc");
include_once ($path_to_root . "/inventory/includes/db/items_locations_db.inc");
include_once ($path_to_root . "/inventory/includes/db/items_transfer_db.inc");
include_once ($path_to_root . "/gl/includes/gl_db.inc");
include_once ($path_to_root . "/includes/ui/items_cart.inc");
function stock_transfer_add()
{
    $app = \Slim\Slim::getInstance('SASYS');
    $req = $app->request();
    $info = $req->post();
    // Example
    // $ex = array('stock_id' => 'PLUMA', 'location_from' => 'DEF', 'location_to' => 'XXX', 'date' => today(), 'reference' =>
    // '123qwe', 'quantity' => 555, 'standard_cost' => 10, 'memo' => 'Proof of API 2');
    // echo base64_encode(json_encode($ex));
    // print_r($info);
    // Validate Required Fields
    if (! isset($info['stock_id'])) {
        api_error(412, 'Stock Id is required aieu');
    }
    if (! isset($info['location_from'])) {
        api_error(412, 'Location from is required');
    }
    if (! isset($info['location_to'])) {
        api_error(412, 'Location to is required');
    }
    if (! isset($info['date'])) {
        api_error(412, 'Date is required');
    }
    if (! isset($info['reference'])) {
        api_error(412, 'Reference is required');
    }
    if (! isset($info['quantity'])) {
        api_error(412, 'Quantity is required');
    }
    if (! isset($info['standard_cost'])) {
        $info['standard_cost'] = 0;
    }
    if (! isset($info['memo'])) {
        api_error(412, 'Memo is required');
    }
    // Create Adjustment Order
    unset($_SESSION['adj_items']);
    $_SESSION['adj_items'] = new items_cart(ST_LOCTRANSFER);
    $_SESSION['gl_items'] = new items_cart(0);
    $info['date'] = today();
    if (! is_date_in_fiscalyear($info['date']))
        $info['date'] = end_fiscalyear();
    $_SESSION['adj_items']->tran_date = $info['date'];
    $_SESSION['gl_items']->tran_date = $info['date'];
    // This should never happen
    if ($_SESSION['adj_items']->find_cart_item($info['stock_id']))
        api_error(500, 'Item Already Exists In Cart');
    else {
        $_SESSION['adj_items']->add_to_cart(count($_SESSION['adj_items']->line_items), $info['stock_id'], $info['quantity'], $info['standard_cost']);
        // $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null
        // TODO Obtain accounts against which to make seats
        // Product Inventory
        $_SESSION['gl_items']->add_gl_item('1510', 0, 0, ($info['quantity'] * $info['standard_cost'] * - 1), $info['memo']);
        // Configured for Absolute, Own
        $_SESSION['gl_items']->add_gl_item('4010', 0, 0, ($info['quantity'] * $info['standard_cost']), $info['memo']);
        $_SESSION['gl_items']->order_id = 0;
        $_SESSION['gl_items']->reference = 666;
    }
    /*
     * print_r($_SESSION['adj_items']); echo "----------- GL -------"; print_r($_SESSION['gl_items']); echo "------
     * DEBIT: " . $_SESSION['gl_items']->gl_items_total_debit(); echo "------ CREDIT: " .
     * $_SESSION['gl_items']->gl_items_total_credit();
     */
    // Process Order
    $trans_no = add_stock_transfer($_SESSION['adj_items']->line_items, $info['location_from'], $info['location_to'], $info['date'], $info['reference'], $info['memo']);
    $gl_trans_no = write_journal_entries($_SESSION['gl_items'], false);
    new_doc_date($info['date']);
    $_SESSION['adj_items']->clear_items();
    unset($_SESSION['adj_items']);
    $_SESSION['gl_items']->clear_items();
    unset($_SESSION['gl_items']);
    api_create_response("Stock Transfer has been added");
}
?>

Add this to index.php just below line 131:

// ------------------------------- Stock Transfers -------------------------------
// Add Stock Adjustment
$rest->post('/stocktransfer/', function () use($rest)
{
    include_once (API_ROOT . "/transfer.inc");
    stock_transfer_add();
});
// ------------------------------- Stock Transfers -------------------------------

The API post path is /stocktransfer/

I tested it and so far it works as I needed it and no problems found so far.

Thank you apmuthu for all the assistance!

5

(20 replies, posted in Items and Inventory)

I am still trying the functionality of the /stock/ or stock adjustment api to ensure that it has no problem. Apparently it has.

I think i also found the problem.

Inventory.inc line 15:

  
function stock_adjustment_add($info) 

index.php line 129:

stock_adjustment_add();

The inventory adjustment api code part in the index.php has different syntax from the rest (it does not use the FAAPI php path). I am currently clueless about this.

I dont know if omitting the $info argument from the function inside inventory.inc would work, I can only test it tomorrow.

6

(20 replies, posted in Items and Inventory)

My api returned this error:

Slim Application Error

The application could not run because of the following error:
Details
Type: ErrorException
Code: 2
Message: Missing argument 1 for stock_adjustment_add(), called in C:\xampp\htdocs\fa\modules\api24\index.php on line 129 and defined
File: C:\xampp\htdocs\fa\modules\api24\inventory.inc
Line: 15
Trace

#0 C:\xampp\htdocs\fa\modules\api24\inventory.inc(15): Slim\Slim::handleErrors(2, 'Missing argumen...', 'C:\\xampp\\htdocs...', 15, Array)
#1 C:\xampp\htdocs\fa\modules\api24\index.php(129): stock_adjustment_add()
#2 [internal function]: {closure}()
#3 C:\xampp\htdocs\fa\modules\api24\Slim\Route.php(468): call_user_func_array(Object(Closure), Array)
#4 C:\xampp\htdocs\fa\modules\api24\Slim\Slim.php(1355): Slim\Route->dispatch()
#5 C:\xampp\htdocs\fa\modules\api24\Slim\Middleware\Flash.php(85): Slim\Slim->call()
#6 C:\xampp\htdocs\fa\modules\api24\Slim\Middleware\MethodOverride.php(92): Slim\Middleware\Flash->call()
#7 C:\xampp\htdocs\fa\modules\api24\index.php(59): Slim\Middleware\MethodOverride->call()
#8 C:\xampp\htdocs\fa\modules\api24\Slim\Middleware\ContentTypes.php(81): JsonToFormData->call()
#9 C:\xampp\htdocs\fa\modules\api24\Slim\Middleware\PrettyExceptions.php(67): Slim\Middleware\ContentTypes->call()
#10 C:\xampp\htdocs\fa\modules\api24\Slim\Slim.php(1300): Slim\Middleware\PrettyExceptions->call()
#11 C:\xampp\htdocs\fa\modules\api24\index.php(447): Slim\Slim->run()
#12 {main}

Do you have any idea what went wrong?

7

(20 replies, posted in Items and Inventory)

Also:

add_stock_transfer method is not implemented yet in the API.

Is is possible if I just duplicate and modify the inventory.inc file for it to accept another argument (location to be transferred to) so it can handle inventory transfers ?

8

(20 replies, posted in Items and Inventory)

Does the field validation also needs to be removed?
Line 37-39 and 49-51

    if (! isset($info['type'])) {
        api_error(412, 'Movement Type is required');
    }
    if (! isset($info['increase'])) {
        api_error(412, 'Increase is required. (1 = true, 0 = false)');
    }

I don't quite understand how the api $req and $info parses the arguments.

9

(20 replies, posted in Items and Inventory)

I did access the link you provided for, apmuthu. It seems that the inventory.inc hasnt updated yet for 2.4 usage.

Take a look here: https://github.com/apmuthu/FA24extensions/blob/master/Extensions/api24/inventory.inc

Line 88:

    $trans_no = add_stock_adjustment($_SESSION['adj_items']->line_items, $info['location'], $info['date'], $info['type'], $info['increase'], $info['reference'], $info['memo']);

It is still using add_stock_adjustment method for 2.3

The attachment you provided is also the same.

10

(20 replies, posted in Items and Inventory)

Okay I figured out what went wrong.

The API is still using a method from frontaccounting 2.3.x

This is it from items_adjust_db.inc 2.3.26:

function add_stock_adjustment($items, $location, $date_, $type, $increase, $reference, $memo_)

And the one which decided the type is from inside add_stock_adjustment_item (items_adjust_db.inc):

    add_stock_move(ST_INVADJUST, $stock_id, $adj_id, $location,
        $date_, $reference, $quantity, $standard_cost);

It is ST_LOCTRANSFER / ST_INVADJUST that I am looking for. Stock moves need to be passed as ST_LOCTRANSFER.

The $type arguments in 2.3.26 is never resolved.

Do have any idea for a fix? Or should I make a new API that implements add_stock_transfer (from items_transfer_db.inc) maybe naming it /stockmove/ ?

11

(20 replies, posted in Items and Inventory)

Thank you for pointing me out on new information, apmuthu.

After looking at the inventory API, it seems that it is modified so we can pass 'type' argument. I believe this is done using the /stock/ API.

I am getting more confused tho:
This line in inventory.inc API

    $trans_no = add_stock_adjustment($_SESSION['adj_items']->line_items, $info['location'], $info['date'], $info['type'], $info['increase'], $info['reference'], $info['memo']);

Have extra arguments on type (this is the one needed to differentiate on move/adjust) and increase (I don't know what is this used for).

While the method in /inventory/includes/db/items_adjust_db.inc is

add_stock_adjustment($items, $location, $date_, $reference, $memo_)

Shouldn't this return an error? I haven't tested it live yet. I tried to look at the items_adjust_db.inc in newest 2.4.4 release.

12

(20 replies, posted in Items and Inventory)

I am directly accessing the database and inserting from another application as I could not find any documentation of API that supports inventory moves. The API that I found only supports inventory adjustments. It is not possible to use adjustments API to do stock moves as they use different types.

13

(20 replies, posted in Items and Inventory)

I am getting headache trying to figure out the relationships for the `refs` table.

References code does not query this table at all. From sql_trail I am only able to see one REPLACE syntax that I'm still searching coming from which part of code.

references.inc says that refs table is to be deprecated.

I am trying to insert records (for inventory moves/adjustment) from other application and is it safe for me to simply ignore inserting records to the `refs` table?

Using 2.4RC1

is it possible for you to help us elaborate the anatomy of inventory transfers/adjustments?

apmuthu wrote:

In PHP v5.6 onwards this behavior is so. Restart the webserver after including the following line in the php.ini file:

always_populate_raw_post_data = -1

The caveat for the above would be an inability to upload files as discussed here. The newer recommended construct for Ajax is to use php://input stream that does not have the above issue.

So, does the main problem lie in fa using deprecated ajax constructs?

Is the best solution to use PHP <5.6 if I am using fa for commercial deployment?

I'm running fa under xampp. Some ajax functionality is broken (always result in timeouts) when used in newer php environments. Most problems are from form data editing or submitting new data.

Here is a little data on such error

error
[Thu Sep 01 19:13:58.342566 2016] [:error] [pid 14080:tid 1632] [client 127.0.0.1:56914] PHP Deprecated:  Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0, referer: http://127.0.0.1/fa/inventory/manage/locations.php?
[Thu Sep 01 19:13:58.342566 2016] [:error] [pid 14080:tid 1632] [client 127.0.0.1:56914] PHP Warning:  Cannot modify header information - headers already sent in Unknown on line 0, referer: http://127.0.0.1/fa/inventory/manage/locations.php?
[Thu Sep 01 19:13:58.364568 2016] [:error] [pid 14080:tid 1632] [client 127.0.0.1:56914] PHP Notice:  Trying to get property of non-object in C:\\xampp\\htdocs\\fa\\includes\\errors.inc on line 74, referer: http://127.0.0.1/fa/inventory/manage/locations.php?

access
127.0.0.1 - - [01/Sep/2016:19:13:58 +0700] "POST /fa/inventory/manage/locations.php?JsHttpRequest=0-xml HTTP/1.1" 200 570 "http://127.0.0.1/fa/inventory/manage/locations.php?" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0"

Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.15

Current database version Required  2.4.1 

Fa doesn't return any error if I turn off javascript.


Tested with older deployment of xampp using php 5.3.1 and ajax works fine without timeouts.

Any idea to what I can do to fix the ajax timeout error?

EDIT: tested with php 5.4.31 and also no errors