Doctrine subtract on-the-fly two columns as a third - symfony

Expressed in MySQL, what I wish:
SELECT article.sellprice - article.cost AS margin
FROM article
My attempt in DQL (note that margin does not exist in my entity):
SELECT a, a.sellprice - a.cost AS a.margin
FROM ArticleBundle:Article a"
Results in an exception [Syntax Error] line 0, col 47: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '.'. Attempt to get it outside of the entity:
SELECT a, a.sellprice - a.cost AS margin
FROM ArticleBundle:Article a"
And some variations of that code; that messes up with my result, causing a twig error Key "nom" for array with keys "0, margin" does not exist.. In fact, a.nom exists; when reverting to:
SELECT a
FROM ArticleBundle:Article a
No error at all. Any clues to get my calculated on-the-fly result?

Because that value must bubble up to the twig, according to the comment of Yoshi (many thanks by the way), I ended up with the second try:
SELECT a, a.sellprice - a.cost AS margin
FROM ArticleBundle:Article a"
Tuning the twig to parse that mixed content:
{% for mixed_content in pagination %}
<tr>
{% set article = mixed_content|first %}
{% set margin = mixed_content.margin %}
<td>{{ article.nom }}</td>
<td>{{ article.margin}}</td>
Hoping that may help anyone.

Related

How to change filter in date parameter to range in Looker

I am trying to see if there is a way to have the filter on a date parameter be a date range instead of a single date value. Does anyone have any creative ideas on how to do this.
You probably want to replace your parameter with a templated filter. See the docs for more info, but in short:
In situations where you want to offer users more flexible input (such as with various kinds of date ranges or string searches), try to use templated filters when possible.
Your code will look something like this:
view: customer_facts {
derived_table: {
sql:
SELECT
customer_id,
SUM(sale_price) AS lifetime_spend
FROM
order
WHERE
{% condition order_date %} order.dt {% endcondition %}
GROUP BY 1
;;
}
dimension: order_date {
type: date
sql: ${TABLE}.dt ;;
}

Error : The "defined" test only works with simple variables

I'm trying to display prices in a specific format with twig/symfony.
I would like to consider the null case (there is no price) but I get this Symfony error:
The "defined" test only works with simple variables.
Here is my code in twig :
<td>{{ _self.formatRemuneration(remunerationValues.variable_monthly_remuneration|number_format(2, ',', ' ') ?? null) }}</td>
Without this ?? null part it only works if a price exists in the database. I don't take the null case into account.
I also tried to move the filter (|number_format(2, ',', ' ')) inside the macro but I get errors or 0.00 values instead of nothing.
{% macro formatRemuneration(remuneration) %}
{{ remuneration is not null ? 'profile.remuneration.formated'|trans({'remuneration': remuneration}, 'company_position') : '' }}
{% endmacro %}
Can you help me write this condition?
To start, I'm not sure why you are doing something called formatRemuneration and trying to apply the the filter number_format both at the same time.
If I were you I would move the filter inside your macro, in which you then could test for a null value when the price isn't set and return whatever you want, e.g. Not applicable
To fix the error you would only need to evaluate the variable, not the whole line, see below. This is because the filter number_format return an object of the instance Twig\Markup
<td>{{ _self.formatRemuneration(remunerationValues.variable_monthly_remuneration ?? null) }}</td>
If you can't move the filter number_format for whatever reason, you would need to change the snippet to the following:
<td>{{ _self.formatRemuneration((remunerationValues.variable_monthly_remuneration ?? null)|number_format(2, ',', ' ')) }}</td>
Keep in mind null will get converted to 0.00

Flask: Iterating through a dictionary whose vlaues are lists of tuples

I have a dict whose values are lists of tuples. I want to build a table for every key.
mydict = {'Western Division': [(0, 1, 'Oakland'), (0, 2, 'San Jose')], 'Eastern Division': [(1, 1, 'Boston'), (1, 2, 'Buffalo')]}
My template is:
{% for key, value in mydict %}
<table>
<tr>
<th> {{ key }} </th>
</tr>
{% for team in value %}
<tr>
<td>{{ team[2] }}</td>
</tr>
{% endfor %}
</table>
{% endfor %}
This gives me a ValueError: too many values to unpack (expected 2)
I tried changing the first for-loop to for key, value, team, thinking that I want to call each tuple in each list in each key, but got the same error (expected 3).
Lastly, I tried for key, value in mydict.items and got TypeError: 'builtin_function-or_method' object is not iterable.
It's definitely possible that I made a mistake further upstream in creating the dict, but I suspect I am just not building my template correctly.
#mechanical_meat provided the answer in their comment. items needs parens in jinja2.

Showing PL/SQL ERROR : ORA-00947: not enough values

Please help me, how to fill in the correct values?
Because the value is always less, and showing ERR not enough values the error is in here
Here is my code :
CREATE OR REPLACE TRIGGER REGION_HILMI_TRIGGER_WARNING
AFTER INSERT OR UPDATE OR DELETE ON REGION_HILMI
FOR EACH ROW
DECLARE
warning VARCHAR2(400);
BEGIN
IF INSERTING THEN
warning:='Terjadi penambahan data di tabel regions, dengan
nilai region_id='||:NEW.region_id||' dan
region_name='||:NEW.region_name;
ELSIF UPDATING THEN
warning:='Terjadi perubahan data di tabel regions, dengan
nilai lama region_id='||:OLD.region_id||',
region_name='||:OLD.region_name||' nilai baru
region_id='||:NEW.region_id||', region_name='||:NEW.region_name;
ELSIF DELETING THEN
warning:='Terjadi penghapusan data di tabel regions untuk
region_id='||:OLD.region_id||' dan region_name='||:OLD.region_name;
END IF;
INSERT INTO REGION_HILMI_HISTORY(OLD_REGION_ID,OLD_REGION_NAME,NEW_REGION_ID,NEW_REGION_NAME,CHANGE_TIME,DESCRIPTION)
VALUES(REGION_HILMI_SEQUENCE.NEXTVAL,USER,TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS'),warning);
END;
/
Your INSERT statement shows only 4 items in the VALUES clause but 6 in the column name list. They must both match.
thankss sir, #TenG
solved with adding this scripts :
INSERT INTO REGION_HILMI_HISTORY(OLD_REGION_ID,OLD_REGION_NAME,NEW_REGION_ID,NEW_REGION_NAME,CHANGE_TIME,DESCRIPTION)
VALUES(REGION_HILMI_SEQUENCE.NEXTVAL,:OLD.REGION_NAME,:NEW.REGION_ID,:NEW.REGION_NAME,TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS'),warning);
now then I tried to insert data into my primary table sir,
but it showing error like this appears, after i setting up the trigger
click to show image
now it solved....
problem on trigger,
i change (TO_CHAR) >>> (TO_DATE)
error :
VALUES(REGION_HILMI_SEQUENCE.NEXTVAL,:OLD.REGION_NAME,:NEW.REGION_ID,:NEW.REGION_NAME,TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS'),warning);
work :
VALUES(REGION_HILMI_SEQUENCE.NEXTVAL,:OLD.REGION_NAME,:NEW.REGION_ID,:NEW.REGION_NAME,TO_DATE(SYSDATE,'DD-MON-YYYY HH24:MI:SS'),warning);

Drupal Twig Integer conversion not working

I an trying to loop x times from a integer field value.
But no matter how i format the twig-filter the field value 6 is converted to 1.
The string '6' is converted to int 1.
I have module twig tools enabled.
{{content.body|raw|integer}} // always 1
{% for i in range(1, content.body|raw|integer) %}
{{ i }}
<div class="stars"><i class="fa fa-star"></div>
{% endfor %}
Because the body is a textarea and it's raw version may include HTML, it's probably not returning a simple string value of "6", but likely something like:
<p>6</p>
The integer twig filter uses PHP's intval function, which will return 1 on an object or non-empty array.
I would suggest using an Integer field to store your number instead of the body field.

Resources