Topic: Textcart module

Hi guys
I've finished my 'textcart' module allowing to copy/paste  orders to external application (text editor, excel) modify them and import them back. It's still a beta version, is anybody interested  ?
here is the doc, so you can see what it's doing.


# Module Textcart
## Introduction
This module provides a quick import/export facility between **orders** (or any other carts) and text via the UI.
This allows, for example :

* copy/paste from a Sales Order to a Purchase Order or another Sales Order
* quick modification of an order
* modifying an Order with Excel
* converting email to order
* bulk import of big order
* variant, made easy via the Line Templating System (LTS)
* and much more

Note that this module doesn't create or save orders in the database. It's just an alternative to the current UI for building an order, which then needs to be saved.
## Why exporting to text?
FA is a web application, therefore you expect to be able to enter an order using the mouse via the user friendly UI, which FA provides.
However, as nice as a mouse interface can be, entering or manipulating a text can be quicker and allows you to use whatever tool you want to modify it.
You might want to copy a sales order to a purchase order whilst modifying the quantity to match the supplier minimum quantities or multiply all the prices by a certain factor. It's not easy with a mouse, but it's easy with Excel or any text editor.

## How does it work?
Just go to any **cart** page (Sale Order, Purchase Order or Item Adjustment/Transfer) and select the *Text* cart next to the *Order* one.
You should then get your order translated in text (if it's not empty).
You can then copy/paste it into excel or anything else, modify it and re inject it in the same cart or another one. You'll then be able to see your **cart** in the normal UI, check it and save the order if needed.
### Syntax overview
The format of a textcart is a bit complicated to explain but it's easy to write and grasp by example.
If you edit an existing order (or add a few items in an empty one) and select the **Text** cart tab, you should have something like this :

      -- some lines starting with '--''
      -- there are comments (so ignored by FA)
      -- they are a quick reminder of the syntax

then the details of the cart like :

      ITEM1 + 10 $ 4.00 5.0 % | "description of item 1"
      ITEM2 +  8 $ 5.00 0.0 % | "description of item 2"
etc ...

This means you have two items in your cart, the first item being :

ITEM1, quantity 10, price 4.00 and a discount of 5%.

***Warning*** : the **$** sign here is not related to your currency, it's just a symbol meaning price.
The format might be a bit alarming, but this one is meant to be exportable to Excel and have all the information without any ambiguity. You don't need to write everything.

The minimum that you need to write is, the item *stock_code*.
Then if you want (in no particular order), the quantity, the price and the discount,
(quantities are preceded by '**+**', prices by '**$**' and discount followed by '**%**' ).
Finally an optional description preceded by a '**|**' enclosed or not with double-quotes.

* fields can be separated by spaces, tabs and/or commas.
* order doesn't matter (for quantity, price and discount)
* field identifiers ('**+**', '**$**', '**%**') can be attached or separated to their value
* '**+**' is optional if the quantity is an integer (like *8*)
* '**$**' is optional if the price is a decimal number (like *5.00*)
* the default quantity is 1

So, the following lines are equivalent (considering that *4.00* is the default price and *"description of item 1"* is the real item description)

      ITEM2 +  8 $ 5.00 0.0 % | "description of item 2"
      ITEM2 +8 $5.00 0.0% | description of item 2
      ITEM2 +8,  $5.00, 0.0%, | description of item 2
      ITEM2 8 5.00
      ITEM2 5.00 8
      ITEM2 8 $5

However

      ITEM2 8 5

is wrong, as *5* will be seen as a quantity, and not a price.

(*Note for Excel users*) If you copy/paste into Excel you should have 8 columns. The separation between the '**$**' sign and the amount is deliberate. Without that, Excel (my version at least) would consider the column as a string, so it's easier that way.

Lines can also contain formulas and default values through a simple but powerful line templating system (see the *Templating System* section).

## Update Modes
Once, you are happy with your text (either entered directly in the text area, or copied from somewhere) you can either replace the whole order, update a part of it or just insert some items.

Let's say your original cart contains :

    ITEM-1 10
    ITEM-2 5

And your textcart is :

    ITEM-2 10

* **Replace** will replace all the items with the ones in the textcart. In this case the resulting cart will be :

    ITEM-2 10
* **Insert** will append the whole textcart to the original order resulting in :


    ITEM-1 10
    ITEM-2 5
    ITEM-2 10

We have 2 lines with ITEM-2.

* **Update** will update the lines of the original cart with the new value.

    ITEM-1 10
    ITEM-2 10
   
    ITEM-2 quantity has change to 10.

Modes an also be overridden for each individual line by starting with either : 

* '**+**' insert the current line
* '**=**' update the current line
* '**-**' delete the current line.
 
## Examples
### Suppress some lines from a cart
You want to suppress ITEM-2 from the following cart:

    ITEM-1 10
    ITEM-2 5

#### 1st method
Delete the line ITEM2 from the text, the textcart will look like this :

    ITEM-1 10

and press *Replace*.
#### 2nd method
Write a text cart to delete ITEM2 with the following :

    -ITEM2

And press *Insert*.

### Update
You want to change the quantity  of ITEM-2 from the following cart to 1:

   ITEM-1 10
   ITEM-2 5

### 1st method
Edit the cart just to change the quantity of ITEM-2 to 1.

   ITEM-1 10
   ITEM-2 1

And press *Replace*.
### 2nd method
Just write the line you want to change :

   ITEM-2 1

and press *Update*.

### Import/Export to Excel
If you need to do some complex modifications via Excel, just copy/paste the textcart to Excel, do your modifications, then copy/paste the desired cart from Excel to the text area and press *Replace*.
### Sales order to purchase order
If you want to create a purchase order from a sales order, do the following :

* just copy the textcart from the sales order
* create a new purchase order, select the text tab from the **Purchase Order** page
* paste the sales order textcart in the textcart area
* at this point, we need to change the sales price by the purchasing price. The quickest to do so is to insert the following line (*Template Line*) at the beginning of the textcart

      :# $(@)

* press *Replace* and save your order.

If you need to do fancy calculations beforehand (like matching the quantity to the minimum quantity required by the supplier), export the cart to Excel (or anything else), make the desired changes to the quantities and prices then import it to the purchase order.

### Transfer all items from one location to another one
For **Transfer** and **Adjusement** items, if the cart is empty, the default textcart, rather than being empty, will be initially filled with all the items present in the specific location.

## Line Templating System
For people who need to write big orders from scratch, the line templating system (LTS) allows orders to be written in a really compact way, without having to repeat what doesn't change from line to line.
Lines sharing the same pattern can be captured to a *line template*.

### Syntax
A Line template is identical to a normal line, except it starts with a ':'. It can contain constants (default values) and/or placeholders ('**#**','**@**').

* '**#**' will be replaced by the value corresponding to the same field of the current line
* '**@**' will be replaced by the default value (from the database)

In the same way, '**#**' can be used on a normal line and will be replaced by the value of the template.

### Examples
Let's say that we have the following cart

      ITEM-1 10
      ITEM-2 10
      ...
      ITEM-5 10

We don't want to write the number 10 each time, so, let's define a template line this way :

      :# 10


'**:**' means the line is a template line.

'**#**' is a placeholder for the stock_code (ignore this for the moment)

*10* is the default quantity.

Each following line would look like the template with the '**#**' expanded (replaced) with the stock code.
So, the line :

      ITEM-1
will be replaced by :

      ITEM-1 10
And the line :

      ITEM-2
will be replaced by :

ITEM-2 10

Therefore, instead of the initial cart, we can write this :

      :# 10
      ITEM-1
      ITEM-2
      ...
      ITEM-5

They are equivalent, but the later one is shorter.

Placeholders can be used in any field and will be replaced by the value of the corresponding field.
In the same way, if the stock codes follow a certain pattern (colour variant) we can use a placeholder to construct the stock_code or the description.

Let's say we want the following order :


      T-Shirt/Blue 5
      T-Shirt/Red 5
      T-Shirt/Black 10

We can write instead :

      :T-Shirt/# 5
      Blue
      Red
      Black 10


`Blue`  will be expanded to `T-Shirt/Blue 5`

`Red` to `T-Shirt/Red 5`

***Note*** The quantity for black : *10* will override the template's one.

If we want to add the colour to the description, we just need to write the bit of the description which differs for each product.

      :T-Shirt/# | this a # t-shirt
      Blue | blue
      Red | red
      Black | black

Is equivalent to :

      T-Shirt/Blue | this a blue t-shirt
      T-Shirt/Red | this a red t-shirt
      T-Shirt/Black | this a black t-shirt


#### Placeholder in a normal line
You can also use a placeholder in a normal line, it will be replaced by the value in the template.

Example :

      :Blue | blue
      T-shirt/# | this a # shirt
      Skirt/#   | this a # skirt

Is equivalent to :

      T-shirt/Blue | this a blue shirt
      Skirt/Blue   | this a blue skirt

### Formula
Formulas between brackets will be evaluated as arithmetical expressions.

Example, to knock down by 10% the price of every item of an existing order.

Current cart :

      ITEM-1 10.0
      ITEM-2 20.0

Desired cart :

      ITEM-1 9.0
      ITEM-2 18.0

You can do :

      :# $( # * 0.90 )
      ITEM-1 10.0
      ITEM-2 20.0

### Raw line
A line starting with a '**!**' will not be expanded :

Example

      :# $( # * 0.90 )
      ITEM-1 10.0
      !ITEM-2 20.0

will give:

      ITEM-1 9.0
      ITEM-2 20.0

Note the quantity of *20* form ITEM-2.

### Forcing value
In the following cart :

      :# 10
      ITEM-1
      ITEM-2 4

The line values have priority over the template values. Therefore this cart is equivalent to

      ITEM-1 10
      ITEM-2 4

The *4* of the 2nd line overwrites the default value of the template.

If you want to force **Textcart** to use the template value, use a **constant formula** (as formulas have priority over constants).

The following cart :

      :# (10)
      ITEM-1
      ITEM-2 4

will be equivalent to :

      ITEM-1 10
      ITEM-2 10

## Installation
The current version of `textcart` needs FA to be patched to display the `Textcart` tab. To patch it simply copy the files in the `patch` directory to their respecive location. You can do this with the following command  (from the FA directory:

    cp -R ./modules/textcart/patch/ .

Re: Textcart module

great work


can you please upload the file

Re: Textcart module

How can I do that ? (Joe ?)

Re: Textcart module

You can either provide a download url here.

Or you can send me a zipped package and I can either ask Janusz to send it to the repository. If it is not written as a normal module we can upload it to the download page on the website.

/Joe

Re: Textcart module

It's not a normal module as it need a patch on some FA bits
I'll email you a zip.

/Elax

Re: Textcart module

The textcart module is now available via FrontAccounting package repositiory.
Thanks elax for your contribution smile
Janusz

Re: Textcart module

Can TextCart Extension be used to import items into item table?

Re: Textcart module

apmuthu wrote:

Can TextCart Extension be used to import items into item table?

No. It only deals with "carts" like order, delivery, purchase order, item transfer, item adjustement etc ...
I use to use the `import items` modules, which once you understood what to put in which columns, work.

Now, I just generate insert SQL queries ...

9 (edited by apmuthu 09/24/2014 08:17:17 pm)

Re: Textcart module

When we import items using the extension import_items, the data goes into the item_codes table and a corresponding entry goes into the stock_master and loc_stock tables

Images of the items can be named as ITEMCODE.jpg and placed in the company/#/images/ folder.

You're right, SQL seems better since the issue of prices and stocks need to be dealt with separately in the extension.

I have now documented it in the Wiki.

Re: Textcart module

Hi, I am using FA 2.3.22 and just activiated the textcart 2.3.9-6 extension. However, then I went to Sales Order Entry or Purchase Order Entry, I got "ERROR 500 - INTERNAL SERVER ERROR".

If I deactivated the textcart extention, the error went away and returned normal. What should I do to solve this? Thanks.

11 (edited by apmuthu 01/19/2015 11:12:08 am)

Re: Textcart module

Compare your module files with those in my GitHub repo. There was a commit I made on 2013-11-08 there that has not yet been assimilated into the official packages. It pertains to the file  modules/textcart/purchasing/po_entry_items.php.

Replace line 532

$textcart_mgr->tab_display('', &$_SESSION['PO'], "display_order_in_tab");

with

$textcart_mgr->tab_display('', $_SESSION['PO'], "display_order_in_tab");

Re: Textcart module

Thanks. I checked the file and line 532 in file modules/textcart/purchasing/po_entry_items.php has always been

$textcart_mgr->tab_display('', $_SESSION['PO'], "display_order_in_tab");

What else should I do to solve the error?

Re: Textcart module

Have you patched FA with the files present in the textcart module ?

Re: Textcart module

Doesn't the pkg install the various files to patch the FA? If so, the textcart documentation in the wiki may need updation.

Re: Textcart module

Files have to be patched manually. FA module system doesn't allow module to overwrite FA files (which is good).
Textcart needs someway of "hooking" into FA, I proposed a patch to FA which will had necessary hooks but it has been
rejected. At the moment the only way to patch those files manually.

I don't know about the wiki, but the installation section of the first post  explain how to patch. However, the path
where patched files are might have been changed.

/Elax

Re: Textcart module

And possibly their content as well. Any reason for rejection of hook patch?

Re: Textcart module

I think the main reason is that nobody's done it (the patch). AFAIR Janusz and I couldn't agree on a design and we had both
other prioriry. However, He might have made some changes to hook the url to call the textcart pages instead of the current FA one but I don't know if it works and if it's been integrated to textcart.

Also, a patched version would be better as it will be easier to keep up to date with any incoming patch on the FA files.
At the moment, for example, any patch on let's say po_entry_items needs to be propagated to the textcart version.
I don't know who is doing it. I'm not sure anyway that it have ever been necessary so far.

/Elax

18 (edited by apmuthu 01/21/2015 01:26:43 pm)

Re: Textcart module

I have patched the files needed to incorporate the latest FA v2.3.22+. Kindly verify the commits in my FA repo.

Synched textcart patched file inventory/transfers.php with core
elax textcart patched files updated to latest in core (sales, inventory, purchasing)

Post's attachments

textcart.zip 37.4 kb, 9 downloads since 2015-01-21 

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

Re: Textcart module

Thanks. I extracted the files in the zip and placed in the textcart folder on server.

After activating textcart, now i can go in Sales Order Entry but received the following error message on the top of the page.


Declaration of ItemsAdjTextCartManager::item_to_text() should be compatible with TextCartManager::item_to_text($item, $user_price_dec) in file: ..../modules/textcart/includes/textcart_manager.inc at line 711
..../modules/textcart/sales/sales_order_entry.php:30:    include_once()


Any steps I have done wrong?

20 (edited by apmuthu 01/21/2015 06:02:30 pm)

Re: Textcart module

Nice catch. When a class extends another and attempts to override a parent method (function), it should maintain the same number of arguments or the parent method should have default values for missing arguments in the overriding methods.

For a start, try the following in the file /modules/textcart/includes/textcart_manager.inc:
Change lines 703 and 733:

  function item_to_text($item) {

to be

  function item_to_text($item, $user_price_dec) {

Re: Textcart module

Thanks. I changed and then now when i go in Sales Order Entry, i only see a blank white page with the following message

Cannot re-assign $this in /home1/dragon/public_html/dragondb/modules/textcart/includes/textcart_manager.inc on line 703

Re: Textcart module

I had made an error in the replacement value and have corrected the post since. Have a go again now.

Re: Textcart module

Is there a version of textcart that will work with 2.4.6 or is there an alternate extension that does the same thing?

I tried the version in this forum thread, as well as the one in github, but neither works with 2.4.6, and I haven't been able to find a newer version.

Thanks for your help.

Re: Textcart module

Textcart author here,

What do you exactly mean by it doesn't work ?
There is no version specific to work with 2.4.x planned, however I don't think there are fundamental changes between 2.3 and 2.4 which will stop it from working.
I don't use FA 2.4.x but a fork of 2.3.x and I have no plan to upgrade at the moment, therefore I am not planning to upgrade textcart to 2.4. However, I'm happy to provide guindance or help to make it work on 2.4.x

/elax

25 (edited by rlhamilton 02/21/2019 12:02:56 am)

Re: Textcart module

Hi elax,

Thanks for the response. At first, the problem was that when I went to a function such as Sales/Direct Invoice, I would get a blank page. I didn't look any further, since I didn't want to waste time if there was a 2.4 version available.

Once I knew there wasn't a formal 2.4+ version, I looked a little closer, tracking things through the error.log file.

There were four easy changes:

1) The contents of includes/manufacturing.inc were moved into inventory.inc in 2.4, so I changed the include call in textcart_manager.inc.

2) There is a call to check_edit_conflicts() in textcart/sales/sales_order_entry.php that had no arguments. That raised a fatal error, which didn't occur in 2.3.6, but I suspect the reason there is that I'm using a newer version of php (7.2), which might be pickier. I changed that call to match the equivalent call in the base version of sales_order_entry.php.

3) The base function get_standard_cost doesn't exist in 2.4.6. It was replaced by get_unit_cost, which appears to do the same thing (or close enough for my purposes). I changed calls to that function in textcart/sales/sales_order_entry.php, textcart/purchasing/po_entry_items.php, and textcart/includes/textcart_manager.inc.

4) I changed the version to 2.4.6 in textcart/_init/config so that FA would allow the extension to be enabled. (I had already done that before I sent my first message).

That got things running, with one exception.

The one problem I ran into (and which still exists), is with the update option on the text tab. In sales it works fine, but in purchasing, it doesn't. Here is how to duplicate the problem:

- Open a Purchase Order Entry or Direct Supplier Invoice
- Add a couple of items to the invoice normally
- Select the text tab, and you will see lines for the items you added:
9780982219102    + 1    $ 5.66    ^ 03/03/2019    | "Managing Writers First Edition"
9780982219119    + 1    $ 5.44    ^ 03/03/2019    | "Conversation and Community First Edition"
- Click update.
- The date moves to the item description, and the date is replaced with 0. If you select the text tab again, you will see the following:
9780982219102    + 1    $ 5.66    ^ 0    | "03/03/2019"
9780982219119    + 1    $ 5.44    ^ 0    | "03/03/2019"

I don't use update, in fact, I'm not sure what it does that can't be done with replace. Fortunately, both replace and insert appear to work fine.

I am now going another step further, merging your versions of the files under sales, purchasing, and inventory with the 2.4.6 files to see if I can come up with a version of textcart that will more closely match 2.4.6. I'm glad to share those changes with you if they work, and if you'd like to have them.

So, the bottom line is that with the changes described above, textcart works with the only exception (so far) being the update issue, which I'm able to work around.

Thanks for your help.
Richard