laravel nova lense raw query - PullRequest
       9

laravel nova lense raw query

0 голосов
/ 08 марта 2019

Я пытаюсь запустить необработанный SQL-запрос на Laravel Nova Lens. Не могли бы вы мне помочь?

Я пытался преобразовать sql в построитель красноречивых запросов. Однако это длинный код ..Также [Оратор] [1] больше не работает.

Также, если кто-то может быть моим онлайн-репетитором по Laravel nova, я был бы благодарен.

Вот сокращенный SQL-запрос:

DECLARE @from_month INT;
DECLARE @to_month INT;
DECLARE @month_range INT;
DECLARE @year_monitor INT;
DECLARE @text_match_on_item_name VARCHAR(50);
DECLARE @Customer_id VARCHAR(50) ;
DECLARE @doc_type VARCHAR(50) ;

SET @from_month =10;
SET @to_month = 12;
SET @month_range = 4;
SET @year_monitor = 2018;
SET @text_match_on_item_name = '%';
SET @Customer_id ='%'; -- in order to select all id's enter '%'
SET @doc_type = '%מס%';



SELECT 
    i.item_num                                                                                                          AS ItemNum, 
    i.item_name                                                                                                         AS ItemName,
    i.itm_qnt                                                                                                           AS Stock,
    sum(d.itm_qnt_out-d.itm_qnt_in)                                                                                     AS QTOUT,

    CASE WHEN i.itm_qnt>0 THEN
    sum(CASE WHEN DatePart(mm,[invdate]) BETWEEN @from_month AND @to_month THEN d.itm_qnt_out-d.itm_qnt_in ELSE 0 END )  -i.itm_qnt
        ELSE
    sum(CASE WHEN DatePart(mm,[invdate]) BETWEEN @from_month AND @to_month THEN d.itm_qnt_out-d.itm_qnt_in ELSE 0 END )
    END
                                                                                                                        AS [PERIODICAL OEDER],

    /* IF stock>0 THEN yearly_order = YearlySales-Stock ELSE yearly_order = YearlySales */
    CASE WHEN i.itm_qnt>0 THEN
    sum(d.itm_qnt_out-d.itm_qnt_in)-i.itm_qnt
        ELSE
    sum(d.itm_qnt_out-d.itm_qnt_in)
    END
                                                                                                                        AS [YEARLY OEDER],



    sum(CASE WHEN DatePart(mm,[invdate]) = '12' THEN d.itm_qnt_out-d.itm_qnt_in ELSE 0 END)                             AS December


/*Repeat for every month*/

FROM 
    turtle.dbo.t_items AS i
FULL OUTER JOIN  
    turtle.dbo.t_items_dtl AS d ON i.item_num = d.item_num
WHERE DatePart(YEAR, [invdate]) = @year_monitor and d.asmachta like @doc_type 
and i.item_name like '%'+@text_match_on_item_name+'%' and cust_id like @Customer_id and 
i.item_num not in (0, 3318,3310,3319,3309,3638,3052) -- מוצרים להשכרה שלא צריכים להופיע

GROUP BY 
    i.item_num, i.item_name, i.itm_qnt
order by
[PERIODICAL OEDER] desc
...