Mel Charles
This is the Services code I made to work earlier (a few small changes to original in variable/array names).
I added a 5th category of Service and it stopped working entirely with any data from the new category. I realized that it might be because in the Services table, the Category choices were 1,2,3,4,10 and in the Invoice Items they went 1,2,3,4,5. So I switched to doing everything with
text(Category)
and strings like
Category:="Grooming Package"
instead rather than copying the Service.Category to the Invoice Item.Category. It seemed to fix it for the most part.
When I leave the whole thing as run as server, it almost never correctly copies the category from the Tips items though. Basically never. If I run it locally, then it almost always does. Almost.
However, in testing more while waiting for replies here, I found that it's also sometimes not copying other parts of the Service to the Invoice Item in either case. It's strange why it would sometimes and not other times when the data is not being changed at all in-between.
I'm baffled.
"SERVICES TAB - TRIGGER AFTER HIDE";
"Synchronize the Invoice Items to the Services tab";
let t := this;
"Get all the selected Items into separate arrays";
let selectedPackagesArray := for itemID in numbers(Packages) do
record(Services,itemID)
end;
let selectedAddonsArray := for itemID in numbers('Add-ons') do
record(Services,itemID)
end;
let selectedAlaCarteArray := for itemID in numbers('À la Carte') do
record(Services,itemID)
end;
let selectedDiscountsArray := for itemID in numbers(Discounts) do
record(Services,itemID)
end;
let selectedTipsArray := for itemID in numbers(Tips) do
record(Services,itemID)
end;
"Create Invoice Items for Items that ARE checked off in the Services tab";
for packageItem in selectedPackagesArray do
if count(t.'Invoice Items'[Services = packageItem]) = 0 then
let ii := (create 'Invoice Items');
ii.(
Services := packageItem;
Appointments := t;
Quantity := 1;
let i := Services.'* Service';
let p := Services.'* Price';
let s := Services.'* SKU';
let t := Services.'* Taxable';
let ti := Services.'* Tax Included';
'Invoice Item Service' := i;
Price := p;
SKU := s;
Category := "Grooming Package";
Taxable := t;
'Tax Included' := ti
)
end
end;
for addOnItem in selectedAddonsArray do
if count(t.'Invoice Items'[Services = addOnItem]) = 0 then
let ii := (create 'Invoice Items');
ii.(
Services := addOnItem;
Appointments := t;
Quantity := 1;
let i := Services.'* Service';
let p := Services.'* Price';
let s := Services.'* SKU';
let t := Services.'* Taxable';
let ti := Services.'* Tax Included';
'Invoice Item Service' := i;
Price := p;
SKU := s;
Category := "Add-on";
Taxable := t;
'Tax Included' := ti
)
end
end;
for aLaCarteItem in selectedAlaCarteArray do
if count(t.'Invoice Items'[Services = aLaCarteItem]) = 0 then
let ii := (create 'Invoice Items');
ii.(
Services := aLaCarteItem;
Appointments := t;
Quantity := 1;
let i := Services.'* Service';
let p := Services.'* Price';
let s := Services.'* SKU';
let t := Services.'* Taxable';
let ti := Services.'* Tax Included';
'Invoice Item Service' := i;
Price := p;
SKU := s;
Category := "À la Carte";
Taxable := t;
'Tax Included' := ti
)
end
end;
for discountItem in selectedDiscountsArray do
if count(t.'Invoice Items'[Services = discountItem]) = 0 then
let ii := (create 'Invoice Items');
ii.(
Services := discountItem;
Appointments := t;
Quantity := 1;
let i := Services.'* Service';
let p := Services.'* Price';
let s := Services.'* SKU';
let t := Services.'* Taxable';
let ti := Services.'* Tax Included';
'Invoice Item Service' := i;
Price := p;
SKU := s;
Category := "Discount";
Taxable := t;
'Tax Included' := ti
)
end
end;
for tipItem in selectedTipsArray do
if count(t.'Invoice Items'[Services = tipItem]) = 0 then
let ii := (create 'Invoice Items');
ii.(
Services := tipItem;
Appointments := t;
Quantity := 1;
let i := Services.'* Service';
let p := Services.'* Price';
let s := Services.'* SKU';
let t := Services.'* Taxable';
let ti := Services.'* Tax Included';
'Invoice Item Service' := i;
Price := p;
SKU := s;
Category := "Tip";
Taxable := t;
'Tax Included' := ti
)
end
end;
"Remove Invoice Items for Items that are NOT checked off in Services tab";
for invoiceItem in select 'Invoice Items' do
if invoiceItem.Services != null then
let isCheckedOff := false;
for id in selectedPackagesArray do
if invoiceItem.Services = id then
isCheckedOff := true
end
end;
for id in selectedAddonsArray do
if invoiceItem.Services = id then
isCheckedOff := true
end
end;
for id in selectedAlaCarteArray do
if invoiceItem.Services = id then
isCheckedOff := true
end
end;
for id in selectedDiscountsArray do
if invoiceItem.Services = id then
isCheckedOff := true
end
end;
for id in selectedTipsArray do
if invoiceItem.Services = id then
isCheckedOff := true
end
end;
if isCheckedOff = false then delete invoiceItem end
end
end
Here is a link to a video of it in happening:
https://www.dropbox.com/s/ouyt5bwsarz6wlh/do%20as%20server.mov?dl=0