In acest exemplu vom vedea cum sa cream clienti plecand de la rapoartele de interventie. De obicei, aceasta operatiune se face deoarece, tehnicienii introduc un client nou in cadrul raportului fara a-l crea cu ajutorul unui subtabel.
Grup Script
Program
Eveniment
Actiune
O alta situatie este aceea in care rapoartele sunt importate dintr-un fisier Excel creat de un alt program, prin urmare, clientii nu sunt creati. Bineinteles, se presupune ca, pe fiecare rand al raportului ar trebui sa fie datele principale pentru a putea identifica daca, clientul exista deja sau trebuie creat.
table = database.getsql("SELECT * FROM reports WHERE eli=0")
rows = table.getrows()
for i = 1,table.countrows() do
--extrapolate the customer
namecustomer = rows[i].getvalue("namecustomer")
gguid_namecustomer = rows[i].getvalue("gguid_namecustomer")
--if gguid is empty the customer not exist
if gguid_namecustomer = = "" then
--check if customer is already exist
tablecustomer = database.getsql("SELECT * FROM customers WHERE eli=0 and name='" .. utility.convap(namecustomer) .. "'")
if tablecustomer.countrows() == 0 then
--if 0 then customer not exist
--create a head customer
gguid_namecustomer = utility.gguid()
values = "INSERT INTO customers(gguid,tid,eli,arc,ut,uta,exp,gguidp,ind,tap,dsp,dsc,dsq1,dsq2,utc,tidc) VALUES ("
values = values .. "'" .. gguid_namecustomer .. "'," .. tostring(utility.tid()) .. ",0,0,'','','',''," .. tostring(database.getind("customers")) .. ",'','','',0,0,'',0)"
database.setsql(values)
--update data customers
values = " UPDATE customers SET name='" .. utility.convap(namecustomer) .. ",address='" .. utility.convap(rows[i].getvalue("address")) .. " WHERE gguid='" .. gguid_namecustomer .. "'")
database.setsql(values)
database.addsyncbox("customers",gguid_namecustomer)
else
--customer already exist, update the gguid for create relation
rows2 = tablecustomer.getrows()
gguid_namecustomer = rows2[1].getvalue("gguid")
end
--update for syncbox windows
database.setsql("UPDATE report SET tid=" .. tostring(utility.tid()).. ",gguid_namecustomer='" .. gguid_namecustomer .. "'")
--add a syncbox for mobile
database.addsyncbox("reports",gguid_namecustomer)
end
end
program.refreshsection("reports")
In primul rand, cream ciclul de lectura a rapoartelor si, luam in considerare doar pe acelea care nu au un gguid de client valid conectat.
Deoarece, poate, un alt raport a creat deja acest client, mai inai, efectuam o cautare in acesta dupa nume.
Daca nici numele nu a adus nici un rezultat atunci, cream clientul prin recuperarea datelor disponibile din raport.
Mai apoi, actualizam raportul pentru a avea relatia cu clientul prin intermediul gguid-ului sau.