When a client is selected (while issuing a document), it is possible to execute SQL code.
This is set in Settings-> Purchases / Sales-> Customer’s, run SQL.
| 
					 1 2 3 4 5  | 
						-- client -- sql -- client-eof --  | 
					
After selected by the client user, the variables sent by emdi to the sql code
| :cd | Line number of document type “eidhpar”.”Aa” | 
| :rd | Related document “eidhpar”.”parallhlo” | 
| :pd | Parent document “eidhpar”.”Koino” | 
| :cl | Customer Line Number “pelates”.”Aa” or “pvlhseis”.”Kvdikospelath” | 
EMDI accepts the content from the variables and defines it corresponding
| im_documentseries | Document series “pvlhseis”.”Seira” | 
| im_related | Related documents “pvlhseis”.”Sxetika” | 
| im_notes | Notes “pvlhseis”.”Sxolio” | 
| im_shippingaddress | Place of shipment “pvlhseis”.”Apostolh” | 
| im_loadingplace | Place of loading “pvlhseis”.”Fortvsh” | 
| im_sign | Signature “pvlhseis”.”ypografh” | 
| im_devicessentlist | List of items sent to the documents “pvlhseis”.”devicessentlist” | 
| im_shipping | Shipping method “pvlhseis”.”Tropos” | 
| im_handling | Purpose of handling “pvlhseis”.”Skopos” | 
| im_custom | Field used for rewards (If the fifth part contains the product code that is pasted on the virtual keyboard then it is ignored) “pvlhseis”.”custom”| | 
| im_cust1 | General scope field 1 | 
| im_cust2 | General scope field 2 | 
| im_cust3 | General scope field 3 | 
| im_cust4 | General scope field 4 | 
| im_cust5 | General scope field 5 | 
| im_message | Open informative message | 
| im_messagw | Open a warning message | 
The following example puts the loyalties total points in the sales comment and compares it with the product custom field “points”.
If it is larger than the custom field then a message is displayed.
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78  | 
						select    -- SEND MESSAGE    coalesce((case when                                             cast(case when position('points:', "apouhkh"."Shmeivseis") >0 then substring("apouhkh"."Shmeivseis" from position('points:', "apouhkh"."Shmeivseis") + char_length('points:') for position(ascii_char(13), substring("apouhkh"."Shmeivseis" from position('points:', "apouhkh"."Shmeivseis"))) - char_length('points:')-1) else null end as float) <                 cast((select sum( "Posothta")  from "pelates", "pvlhseis", "grammes", "eidhpar" where "pelates"."Aa" = "pvlhseis"."Kvdikospelath"       and "pelates"."active"=1       and "pvlhseis"."Aa" = "grammes"."Aapar"                                       and "pvlhseis"."Parastatiko" = "eidhpar"."Aa"                                                    and "pvlhseis"."Parastatiko"=57 and "pvlhseis"."Kvdikospelath"=:cl group by "pelates"."Kvdikos", "pelates"."Onoma", "pelates"."Epiueto", "pelates"."Epvnymia" ,"pelates"."Aa" ) as float)   then 'Ο ΠΕΛΑΤΗΣ ΔΙΚΑΙΟΥΤΑΙ ΔΩΡΟ'|| ascii_char(13) end),'') ||                       'ΠΟΝΤΟΙ:'|| round(cast((select sum( "Posothta")        from "pelates", "pvlhseis", "grammes", "eidhpar" where "pelates"."Aa" = "pvlhseis"."Kvdikospelath"       and "pelates"."active"=1       and "pvlhseis"."Aa" = "grammes"."Aapar"       and "pvlhseis"."Parastatiko" = "eidhpar"."Aa" and "pvlhseis"."Parastatiko"=57 and "pvlhseis"."Kvdikospelath"=:cl group by "pelates"."Kvdikos", "pelates"."Onoma", "pelates"."Epiueto", "pelates"."Epvnymia" ,"pelates"."Aa") as float)) "im_notes",    -- SEND PRODUCT ID    coalesce((case when                                             cast(case when position('points:', "apouhkh"."Shmeivseis") >0 then substring("apouhkh"."Shmeivseis" from position('points:', "apouhkh"."Shmeivseis") + char_length('points:') for position(ascii_char(13), substring("apouhkh"."Shmeivseis" from position('points:', "apouhkh"."Shmeivseis"))) - char_length('points:')-1) else null end as float) <                cast((select sum( "Posothta")  from "pelates", "pvlhseis", "grammes", "eidhpar" where "pelates"."Aa" = "pvlhseis"."Kvdikospelath"       and "pelates"."active"=1       and "pvlhseis"."Aa" = "grammes"."Aapar"                                       and "pvlhseis"."Parastatiko" = "eidhpar"."Aa"                                                    and "pvlhseis"."Parastatiko"=57 and "pvlhseis"."Kvdikospelath"=:cl group by "pelates"."Kvdikos", "pelates"."Onoma", "pelates"."Epiueto", "pelates"."Epvnymia" ,"pelates"."Aa" ) as float)   then '' else '||||LOYPAY,DI2621' end),'') "im_custom" from "apouhkh" where "apouhkh"."Kvdikos"='LOYPAY'  | 
					
