Complex Netsuite Nest Case WHEN Query - case

I am trying to build a complex CASE WHEN statement for a Saved Search in NetSuite.
This is the "LONG" version, but obviously it has too many characters and I know it can be simplified, but I'm not sure how.
CASE WHEN {status} = 'Cancelled' THEN 0
WHEN {subsidiary} = 'Ciatti Australia'
AND {status} = 'Billed'
AND {applyingtransaction.custbody_shared_comm_type} = 'Ciatti Internal - 50/50 share between Selling/Buying office'
THEN {applyingtransaction.fxamount}/2
WHEN {subsidiary} = 'Ciatti Australia'
AND {status} = 'Billed'
AND {applyingtransaction.custbody_shared_comm_type} = 'Ciatti/iDeal - 1/3 share between Selling office, iDeal & Mr Li etc. (2/3 to iDeal)'
THEN {applyingtransaction.fxamount}/3
WHEN {subsidiary} = 'Ciatti Australia'
AND {status} = 'Billed'
AND {applyingtransaction.custbody_shared_comm_type} = 'Ciatti/iDeal - Existing Supplier/Existing Buyer - 1/3 to iDeal'
THEN {applyingtransaction.fxamount}/3*2
WHEN {subsidiary} = 'Ciatti Australia'
AND {status} = 'Billed'
AND {applyingtransaction.custbody_shared_comm_type} = 'Ciatti/iDeal - Existing Supplier/New Buyer - 50/50 share between Selling office and iDeal'
THEN {applyingtransaction.fxamount}/2
WHEN {subsidiary} = 'Ciatti Australia'
AND {status} = 'Billed'
AND {applyingtransaction.custbody_shared_comm_type} = 'Ciatti/iDeal - New Suppler/Existing Buyer - 1/3 share between Selling office, AU office and iDeal'
THEN {applyingtransaction.fxamount}/3*2
WHEN {subsidiary} = 'Ciatti Australia'
AND {status} = 'Billed'
AND {applyingtransaction.custbody_shared_comm_type} = 'Ciatti/iDeal - New Supplier/New Buyer - 50/50 share between Selling office and iDeal'
THEN {applyingtransaction.fxamount}/2
WHEN {subsidiary} = 'Ciatti Australia'
AND {status} = 'Billed'
AND {applyingtransaction.custbody_shared_comm_type} = 'Not to be shared'
THEN {applyingtransaction.fxamount}
WHEN {subsidiary} = 'Ciatti Australia'
AND {custbody_shared_comm_type} = 'Ciatti Internal - 50/50 share between Selling/Buying office'
THEN {fxamount}/2
WHEN {subsidiary} = 'Ciatti Australia'
AND {custbody_shared_comm_type} = 'Ciatti/iDeal - 1/3 share between Selling office, iDeal & Mr Li etc. (2/3 to iDeal)'
THEN {fxamount}/3
WHEN {subsidiary} = 'Ciatti Australia'
AND {custbody_shared_comm_type} = 'Ciatti/iDeal - Existing Supplier/Existing Buyer - 1/3 to iDeal'
THEN {fxamount}/3
WHEN {subsidiary} = 'Ciatti Australia'
AND {custbody_shared_comm_type} = 'Ciatti/iDeal - Existing Supplier/New Buyer - 50/50 share between Selling office and iDeal'
THEN {fxamount}/2
WHEN {subsidiary} = 'Ciatti Australia'
AND {custbody_shared_comm_type} = 'Ciatti/iDeal - New Suppler/Existing Buyer - 1/3 share between Selling office, AU office and iDeal'
THEN {fxamount}/3
WHEN {subsidiary} = 'Ciatti Australia'
AND {custbody_shared_comm_type} = 'Ciatti/iDeal - New Supplier/New Buyer - 50/50 share between Selling office and iDeal'
THEN {fxamount}/2
WHEN {subsidiary} = 'Ciatti Australia'
AND {custbody_shared_comm_type} = 'Not to be shared'
THEN {fxamount}/2
__
Then the same as above when the Subsidiary is NOT 'Ciatti Australia'.

One way to reduce the formula is to use the internal id of the field instead of the text value. This can be done by adding ".id" to the field, i.e.
{custbody_shared_comm_type}
to
{custbody_shared_comm_type.id}
and the case will change from
WHEN {subsidiary.id} = 1
AND {custbody_shared_comm_type} = 'Ciatti/iDeal - 1/3 share between Selling office, iDeal & Mr Li etc. (2/3 to iDeal)'
THEN {fxamount}/3
to
WHEN {subsidiary.id} = 1
AND {custbody_shared_comm_type.id} = 4
THEN {fxamount}/3
Another is to create embedded case clauses to remove the repetition of lines like
WHEN {subsidiary} = 'Ciatti Australia'
AND {status} = 'Billed'
i.e.
CASE WHEN {status} = 'Cancelled' THEN 0
WHEN {subsidiary} = 'Ciatti Australia'
AND {status} = 'Billed'
THEN
CASE WHEN
{applyingtransaction.custbody_shared_comm_type} = 'Ciatti Internal - 50/50 share between Selling/Buying office' THEN {applyingtransaction.fxamount}/2
CASE WHEN {applyingtransaction.custbody_shared_comm_type} = 'Ciatti/iDeal - 1/3 share between Selling office, iDeal & Mr Li etc. (2/3 to iDeal)' THEN {applyingtransaction.fxamount}/3
CASE WHEN {applyingtransaction.custbody_shared_comm_type} = 'Ciatti/iDeal - Existing Supplier/Existing Buyer - 1/3 to iDeal' THEN {applyingtransaction.fxamount}/3*2
.
.
.
ELSE 0
END
WHEN {subsidiary} = 'Ciatti Australia'
AND NOT {status} = 'Billed' THEN
.
.
.
WHEN NOT {subsidiary} = 'Ciatti Australia'
AND {status} = 'Billed'
THEN
CASE WHEN ...
CASE WHEN ...
CASE WHEN ...
.
.
.
ELSE 0
END
WHEN NOT {subsidiary} = 'Ciatti Australia'
AND NOT {status} = 'Billed'
THEN
CASE WHEN ...
CASE WHEN ...
CASE WHEN ...
.
.
.
ELSE 0
END
When the two are combined, the result would be something like :
CASE WHEN {status} = 'Cancelled' THEN 0
WHEN {subsidiary.id} = 1
AND {status} = 'Billed'
THEN
CASE WHEN {applyingtransaction.custbody_shared_comm_type.id} = 1 THEN {applyingtransaction.fxamount}/2
CASE WHEN {applyingtransaction.custbody_shared_comm_type.id} = 2 THEN {applyingtransaction.fxamount}/3
CASE WHEN {applyingtransaction.custbody_shared_comm_type.id} = 3 THEN {applyingtransaction.fxamount}/3*2
.
.
.
ELSE 0
END
WHEN {subsidiary.id} = 1
AND NOT {status} = 'Billed' THEN
.
.
.
WHEN NOT {subsidiary.id} = 1
AND {status} = 'Billed'
THEN
CASE WHEN ...
CASE WHEN ...
CASE WHEN ...
.
.
.
ELSE 0
END
WHEN NOT {subsidiary.id} = 1
AND NOT {status} = 'Billed'
THEN
CASE WHEN ...
CASE WHEN ...
CASE WHEN ...
.
.
.
ELSE 0
END
Obviously replacing the actual subsidiary ids and correct ids for string representations in your examples.

Related

Creating advance lua array table from list view and call the array elements

Say I have a CE Lua form and some variables:
form.Show()
list = form.CEListView1
tab_player = {}
p_name = 'Joe'
p_gen = 'Male'
table.insert(tab_player,{player_name = p_name, player_gen = p_gen})
-- and then add some elements from List View to same record index
for idx = list.ItemIndex + 1, list.Items.Count-1 do
mtrl_name = list.Items[idx].Caption
mtrl_qty = list.Items[idx].SubItems[0]
mtrl_unit = list.Items[idx].SubItems[1]
mtrl_price = list.Items[idx].SubItems[2]
mtrl_tprice = list.Items[idx].SubItems[3]
table.insert(tab_player, {v_itemname = mtrl_name, v_itemqty = mtrl_qty,
v_itemunit = mtrl_unit, v_itemprice = mtrl_price, v_itemttlprice = mtrl_tprice})
end
-- check
for index, data in ipairs(tab_player) do
print(index)
for key, value in pairs(data) do
print('\t', key, value)
end
end
Result, it's created 9 tab_player record indexes (depending how many items on list view).
What I want is like this structure for one record index:
tab_player =
{
player_name = p_name,
player_gen = p_gen,
{
v_itemname = mtrl_name,
v_itemqty = mtrl_qty,
v_itemunit = mtrl_unit,
v_itemprice = mtrl_price,
v_itemttlprice = mtrl_tprice},
{
v_itemname = mtrl_name,
v_itemqty = mtrl_qty,
v_itemunit = mtrl_unit,
v_itemprice = mtrl_price,
v_itemttlprice = mtrl_tprice},
{
v_itemname = mtrl_name,
v_itemqty = mtrl_qty,
v_itemunit = mtrl_unit,
v_itemprice = mtrl_price,
v_itemttlprice = mtrl_tprice}
-- and so on
}
How CE Lua script to get the structure as I want?
If done, then how CE Lua script call the data from tab_player to fill player name editbox, player gen editbox and fill the items to CE List View?
EDIT:
What I want to be produce an array table with structure below:
list = UDF1.CEListView1
tab_player = {}
player_name = 'Joe'
player_gen = 'Male'
-- this is list view items contain:
--- row 1, column 1 to 5
mtrl_name = list.Items[1].Caption -- Milk
mtrl_qty = list.Items[1].SubItems[0] -- 300
mtrl_unit = list.Items[1].SubItems[1] -- ml
mtrl_price = list.Items[1].SubItems[2] -- 3975
mtrl_tprice = list.Items[1].SubItems[3] -- 3975
--- row 2, column 1 to 5
mtrl_name = list.Items[2].Caption -- Sugar
mtrl_qty = list.Items[2].SubItems[0] -- 1
mtrl_unit = list.Items[2].SubItems[1] -- Kg
mtrl_price = list.Items[2].SubItems[2] -- 18000
mtrl_tprice = list.Items[2].SubItems[3] -- 18000
--- row 3, column 1 to 5 and so om
the tab_player should be:
tab_player = {
-- index 0 or record 1
{player_name = 'Joe', player_gen = 'Male',
-- row 1, column 1 to 5
{
item_name = 'Milk',
item_qty = 300,
item_unit = 'ml',
item_price = 3975,
item_tprice = 3975
},
-- row 2, column 1 to 5
{
item_name = 'Sugar',
item_qty = 2,
item_unit = 'Kg',
item_price = 9000
item_tprice = 18000
},
-- row 3, column 1 to 5
{
item_name = 'bla bla bla',
item_qty = 1,
item_unit = 'bla',
item_price = 1000000
item_tprice = 1000000
}
-- and so on
}
How to create, print multidimensional and call back the item from the array table as above?.

Shopping cart quantity not updating

I have a basic shopping cart. I thought it was working but I have since discovered that even though it runs error free it is not doing one thing I thought it should and I am having trouble resolving the issue.
If I instantiate an item a second time, like this:
item1 = Item(1, "Cucumbers", 1., 1, 'kg')
item2 = Item(2, "Tissues", 2., 2, 'dozen')
item3 = Item(3, "Tomatoes", 3., 5, 'pound')
# item4 = Item(4, "Toothpaste", 1., 5, 'box')
item4 = Item(4, "Cucumbers", 1., 2, 'kg')
What I want is for the quantity of cucumbers in item 1 to increase to '3'
and for item 4 to be auto-deleted.
I thought this was doing what I intended, but it's not:
elif k == 'name':
total_qty = v.qty + item.qty
if total_qty:
v.qty = total_qty
continue
self.remove_item(k)
else:
v[k] = item[k]
The code runs error free but I end up with two separate instances of cucumber.
Full code:
class Item(object):
def __init__(self, unq_id, name, price, qty, measure):
self.unq_id = unq_id
self.product_name = name
self.price = price
self.qty = qty
self.measure = measure
class Cart(object):
def __init__(self):
self.content = dict()
def __format__(self, format_type):
if format_type == 'short':
return ', '.join(item.product_name for item in self.content.values())
elif format_type == 'long':
return '\n'.join(f'\t\t{item.qty:2} {item.measure:7} {item.product_name:12} # '
f'${item.price:1.2f} ... ${item.qty * item.price:1.2f}'
for item in self.content.values())
def add(self, item):
if item.unq_id not in self.content:
self.content.update({item.unq_id: item})
return
for k, v in self.content.get(item.unq_id).items():
if k == 'unq_id':
continue
elif k == 'name':
total_qty = v.qty + item.qty
if total_qty:
v.qty = total_qty
continue
self.remove_item(k)
else:
v[k] = item[k]
def get_total(self):
return sum([v.price * v.qty for _, v in self.content.items()])
def get_num_items(self):
return sum([v.qty for _, v in self.content.items()])
def remove_item(self, key):
self.content.pop(key)
if __name__ == '__main__':
item1 = Item(1, "Cucumbers", 1., 1, 'kg')
item2 = Item(2, "Tissues", 2., 2, 'dozen')
item3 = Item(3, "Tomatoes", 3., 5, 'pound')
# item4 = Item(4, "Toothpaste", 1., 5, 'box')
item4 = Item(4, "Cucumbers", 1., 2, 'kg')
cart = Cart()
cart.add(item1)
cart.add(item2)
cart.add(item3)
cart.add(item4)
print("Your cart contains: {0:short}".format(cart))
# cart.remove_item(1)
print()
print("Your cart contains: \n {0:long}".format(cart))
print()
print("The total number of items in your cart is: ", cart.get_num_items())
print()
print("The total cost of the items in your cart is: ", cart.get_total())
print()
cart.remove_item(3)
print("Your cart contains: {0:short}".format(cart))
print()
print("Your cart contains: \n {0:long}".format(cart))
print()
print("The total number of items in your cart is: ", cart.get_num_items())
print()
print("The total cost of the items in your cart is: ", cart.get_total())
The fix is:
def add(self, item):
if item.unq_id not in self.content:
self.content.update({item.unq_id: item})
return
else:
self.content[item.unq_id].qty = self.content[item.unq_id].qty + item.qty

Exclude the Predefined keywords from Word (alphanums+'_.') in pyparsing python

selectStmt=(select +
('*' |delimitedList(functionbody|column)).setResultsName("Columns") + Optional((_as+table.setResultsName("Aliases"))|table.setResultsName("**Aliases1**"),'')+
Optional(_into+('*' |columns).setResultsName("Columns"),'')+
_from +
table.setResultsName("Tables",listAllMatches=True)+Optional((_as+table.setResultsName("Aliases"))|table.setResultsName(**Aliases2**),'')+
Optional(where + Group(whereExpr), '').setResultsName("where") +
Each([Optional(groupby + columns("groupby")+Optional(_asc|_desc,''),'').setDebug(False),
Optional(orderby + columns("orderby"),'').setDebug(False),Optional(_limit+columnVal,'')
])).setResultsName("Select",listAllMatches=True)+Optional((_union_all|_union)+selectStmt,'').setResultsName("Union")
so if i am matching query like
select count(id) sellercount
into v_photocount
from carphotos photos
where inquiryid = v_inquiryid
and isdealer = (
case
when v_sellertype = 1 then 1
else 0
end
)
and isactive = 1
and isapproved = 1;
Then sellercount is matching with _into and photos with where.
How can I avoid This

Remove Optional("string") in Swift 2

I have a problem for concatenate different String in one String. The code works, but I have a word that is inserted between each of my Strings. Thank you in advance for your response.
let locality = String(self.locality)
let postalCode = String(self.postalCode)
let administrativeArea = String(self.administrativeArea)
let country = String(self.country)
let addressFull = locality + ", " + postalCode + " " + administrativeArea + ", " + country
print(addressFull)
Output
Optional("..."), Optional("...") Optional("..."), Optional("...")
self.locality and your other properties are Optional strings, so you have to safely unwrap them before using them.
Example with if let:
if let locality = String(self.locality), let postalCode = String(self.postalCode), let administrativeArea = String(self.administrativeArea), let country = String(self.country) {
let addressFull = locality + ", " + postalCode + " " + administrativeArea + ", " + country
print(addressFull)
}
You should study the documentation about Optionals, it's a very important concept in Swift.

Problems using Select query in sql server & asp.net

SELECT *
FROM [productDetail]
WHERE
Price BETWEEN 0 AND 2000
OR Price BETWEEN 2000 AND 12000
AND CategoryID = 2
AND caravanOffline = 0
ORDER BY
price
The query doesn't produce the desired output, it also shows the products whose categoryID is 3,1 etc.
Can any one spot the problem in the query.
Updated code:
static public DataTable GetSelectedFilterMotorhomes(ArrayList caravans)
{
string sqldefault = "Select * from productDetail Where";
string sqlBuilder = "";
int starter = 0;
int count = caravans.Count;
string sqlOperator = "OR";
if (caravans.Count > 0)
{
while (count > starter) //build the query depending on the number of caravans.selected.count
{
sqlBuilder += "((Price between " + caravans[count - 1] + "))" + sqlOperator;
count--;
}
string addQuery = sqldefault + sqlBuilder;
string removeOR = addQuery.Substring(0, addQuery.Length - 2); //remove OR
string finalQuery = removeOR + "AND (CategoryID = 2) AND (caravanOffline = 0) order by Price"; //Display caravans in ascending order
SqlDataAdapter da = new SqlDataAdapter(finalQuery, ConnectionString);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
else
{
string returnAllCaravans = "Select * from productDetail WHERE CategoryID = 2 AND caravanOffline = 0";
SqlDataAdapter da = new SqlDataAdapter(returnAllCaravans, ConnectionString);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
You may need some parenthesis? I'd need to know exactly what you were trying to pull back with your query but likely you need a parenthesis after the OR and then again either after the CategoryID = 2 or after the caravanOffline = 0. See if either of the following queries returns what you're looking for.
Select
*
from [productDetail]
WHERE
Price between 0 AND 2000
OR (Price between 2000 AND 12000 AND CategoryID = 2) AND caravanOffline = 0
order by price
Select
*
from [productDetail]
WHERE
Price between 0 AND 2000
OR (Price between 2000 AND 12000 AND CategoryID = 2 AND caravanOffline = 0)
order by price
What do you really want to do with your WHERE clause?? Without any parenthesis, it's not clear at all what you're trying to select
DO you really mean:
WHERE
(Price BETWEEN 0 AND 2000 OR Price BETWEEN 2000 AND 12000)
AND CategoryID = 2
AND caravanOffline = 0
Price is between 0 and 2000, or between 2000 and 12000 (doesn't really make sense), AND in any case, the CategoryID is 2 ?
Or do you mean:
WHERE
Price BETWEEN 0 AND 2000
OR
(Price BETWEEN 2000 AND 12000 AND CategoryID = 2 AND caravanOffline = 0)
The price is either between 0 and 2000 (with no other restriction) OR the price is between 2000 and 12000, but only if the CategoryID = 2 and CaravanOffline = 0 are true at the same time) ??
Or are you looking for something else than these two options??
I think it might need some brackets...
SELECT * FROM productDetail
WHERE Price BETWEEN 0 AND 2000
OR (Price BETWEEN 2000 AND 12000
AND CategoryId = 2
AND caravanOffline = 0)
ORDER BY price
Assuming that's the logic you want! Your question is rather vague, I'm assuming that you want caravans under 2000 regardless of category and caravanOffline, or caravans between 2000 and 12000 with a categoryid of 2 and caravanOffline of 0.

Resources