How do I add a condition to an existing conditional expression? - perl

I had a programmer write a Perl script for my site.
One of the functions is to update price/stock when a certain condition is met.
# update when price/stock conditions met
if ( ($force_price_updates == 1) ||
($data->{'price'} <= $product_price && $data->{'quantity'} > 0) ||
($product_quantity == 0 && $data->{'quantity'} > 0) ) {
What the above is not doing is not updating the price if the new price is higher. It updates the stock value, but if the new stock comes at a higher price, I lose out. Stock gets updated and but the price is not.
The script goes through a number of feeds and if the same product is found in any of the feeds, the script should amend price/stock change according to the rule above.
I can't find the programmer and my Perl knowledge is limited. I understand what the code is doing, but don't know what it should do if the price is higher and stock is greater than zero.

You can add the extra condition you're looking for to that statement.
The condition you're looking to match is:
$data->{'price'} > $product_price && $product_quantity > 0
So the final version would look like this:
if (($force_price_updates == 1) || ($data->{'price'} <= $product_price && $data->{'quantity'} > 0) || ($product_quantity == 0 && $data->{'quantity'} > 0) || ($data->{'price'} > $product_price && $product_quantity > 0)) {

Related

Drools rule with not condition with multiple condition causing error

When i use below condition with 'not' I am getting an error.
not(Obj1(value == 0) && Obj2(value <= 3))
However if i replace above condition as below I am not getting any casting exception
Obj1(value != 0) or Obj2(value > 3)
The rule looks like this:
rule "test_6"
salience 10
when
not(Obj1(value == 0) && Obj2(value <= 3))
then
.....
end
And this is the error I'm getting:
throwing error Error Message: org.drools.core.rule.GroupElement cannot be cast to org.drools.core.rule.Pattern
The && and || operators can only be used inside a single pattern. For example: Obj1( value > 3 && value < 10 || value == 0). According to the documentation, to separate Patterns, you have to use the and and or operators.
So, in your case, your rule should be:
rule "test_6"
salience 10
when
not(Obj1(value == 0) and Obj2(value <= 3))
then
.....
end
Note that it was not failing when you were using or because that was the right operator to use instead of ||.
Hope it helps,

Date range in query Dynamics AX

I would like to build query Range, where
ActiveTo < today || ActiveFrom > today.
Is it possible, I tried something like that but it's not working.
qbdsDimAttrValue = ds.addDataSource(tableNum(DimensionAttributeValue));
qbrMainAccountActiveFrom = qbdsDimAttrValue.addRange(fieldnum(DimensionAttributeValue,ActiveFrom));
qbrMainAccountActiveFrom.value(strFmt('(((%1.%2 != 0) || (%1.%3 != 0)) && ((%1.%2 > %4) || (%1.%3 < %4)))',
qbdsDimAttrValue.name(),
fieldStr(DimensionAttributeValue,ActiveFrom),
fieldStr(DimensionAttributeValue,ActiveTo),
today(),
));
I write 0, because in table DimensionAttributeValue if field ActiveFrom, ActiveTo is null it has value 0, not dateNull(), dateMax()
Date values used in such queries must be in the dd\MM\yyyy format - you can use function date2StrXpp() for this purpose.
Try using the following range:
qbrMainAccountActiveFrom.value(
strFmt('((%1.%2 > %4) || ((%1.%3 < %4) && (%1.%3 != %5)))',
qbdsDimAttrValue.name(),
fieldStr(DimensionAttributeValue, ActiveFrom),
fieldStr(DimensionAttributeValue, ActiveTo),
date2StrXpp(systemDateGet()),
date2StrXpp(dateNull())
));
If you check Global::dateNull() you will see that it returns '01\01\1900', also you can see that database doesn't store 0 in these fields:
Yo can find more details here
So you can simplify your extended range as follows
qbrMainAccountActiveFrom.value(strFmt('((%1.%2 > %4) || (%1.%3 < %4))',
qbds.name(),
fieldStr(DimensionAttributeValue, ActiveFrom),
fieldStr(DimensionAttributeValue, ActiveTo),
today()
));

Group typo3 condition

I need such a condition in ts:
([treeLevel = 0] && [globalVar = GP:R > 0]) || [PIDinRootline = {$pages.2018}]
I wanna show block if page has treelevel=0 and the get var R > 0, or if page id = $pages.2018
It looks like the similar code in php:
if(($treeLevel == 0 && $r > 0) || (pid == number))
The all expression in first brackets should be right, or in second.
Is it exist the method to group it like the previous record or I can only use userfunc?
There is no grouping in TS conditions, but if you need this particular condition from your post I think it is not needed because brackets around && are useless in this case.
(p && q) || r
is exactly the same as
p && q || r
Did you tested it?

Multiple statements in where clause

I have this strange problem. I have a simple search requirements where a user can search a given entitiy (Say customer) based on several search criterias. User may choose to use a criteria or not. The search conditions need to 'AND' all the criteria. So I write code like this (which works)
IQueryable _customer;
_customer = from c in DS.properties
where
(txtCustomerName.Text.Length == 0 || c.name == txtCustomerName.Text)
&& (txtpropcust1.Text.Length == 0 || c.customfield1 == txtpropcust1.Text)
&& (txtpropcust2.Text.Length == 0 || c.customfield2 == txtpropcust2.Text)
&& (txtpropcust3.Text.Length == 0 || c.customfield3 == txtpropcust3.Text)
&& (txtpropcust4.Text.Length == 0 || c.customfield4 == txtpropcust4.Text)
&& (txtpropcust13.Text.Length == 0 || c.customfield13 == txtpropcust13.Text)
select c;
GridView1.DataContext = _customer;
The problem is that if I have 14 where clauses, the EF throws an error- 13 works - 14 does not.
I am using EF+WCF data service in a WPF application. Is there a setting somewhere which limits the number of where clauses?
Thanks
To simplify the resulting query, you could use:
var customers = DS.properties;
if (txtCustomerName.Text.Length > 0)
customers = customers.Where(x => x.name == txtCustomerName.Text);
if (txtpropcust1.Text.Length > 0)
customers = customers.Where(x => x.customfield1 == txtpropcust1.Text);
// etc
_customer = customers;
GridView1.DataContext = _customer;
Note that this will only add SQL where clauses when there's a need for it.

multiple instance if statement in xcode (iphone)

what is the proper way to do If statement with two variable in Xcode for Iphone
currently I have
if (minute >0) && (second == 0) {
minute = minute - 1;
second = 59;
}
The same was you would do it in any C/C++/Objective-C compiler, and most Algol derived languages, and extra set of parenthesis in order to turn to seperate boolean statements and an operator into a single compound statement:
if ((minute > 0) && (second == 0)) {
minute = minute - 1;
second = 59;
}
You'll need another set of parenthesis:
if ((minute >0) && (second == 0)) {
minute = minute - 1;
second = 59;
}
Or you could also write:
if (minute > 0 && second == 0)
Which is what you'll start doing eventually anyway, and I think (subjective) is easier to read. Operator precedence insures this works...