|
|
@@ -2392,328 +2392,352 @@ ORDER BY
|
|
|
FROM
|
|
|
business_order BO
|
|
|
LEFT JOIN (
|
|
|
- SELECT
|
|
|
- b.id,
|
|
|
- bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
- FROM
|
|
|
- business_order b
|
|
|
- LEFT JOIN (
|
|
|
- SELECT
|
|
|
- pid,
|
|
|
- item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
- FROM
|
|
|
- business_order_items
|
|
|
- WHERE
|
|
|
- is_deleted = 0
|
|
|
- GROUP BY
|
|
|
- pid
|
|
|
- ) bt ON bt.pid = b.id
|
|
|
- WHERE
|
|
|
- IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 1, MONTH ( create_time ) = 1 )
|
|
|
- GROUP BY
|
|
|
- b.id
|
|
|
+ SELECT
|
|
|
+ b.id,
|
|
|
+ bt.id as btid,
|
|
|
+ bt.item_id,
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
+ FROM
|
|
|
+ business_order b
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ id,
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ id
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
+ WHERE
|
|
|
+ IF
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 1, MONTH ( b.create_time ) = 1 )
|
|
|
+ GROUP BY
|
|
|
+ btid
|
|
|
) BOI1 ON BOI1.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 2, MONTH ( create_time ) = 2 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 2, MONTH ( b.create_time ) = 2 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI2 ON BOI2.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 3, MONTH ( create_time ) = 3 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 3, MONTH ( b.create_time ) = 3 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI3 ON BOI3.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 4, MONTH ( create_time ) = 4 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 4, MONTH ( b.create_time ) = 4 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI4 ON BOI4.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 5, MONTH ( create_time ) = 5 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 5, MONTH ( b.create_time ) = 5 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI5 ON BOI5.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 6, MONTH ( create_time ) = 6 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 6, MONTH ( b.create_time ) = 6 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI6 ON BOI6.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 7, MONTH ( create_time ) = 7 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 7, MONTH ( b.create_time ) = 7 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI7 ON BOI7.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 8, MONTH ( create_time ) = 8 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 8, MONTH ( b.create_time ) = 8 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI8 ON BOI8.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 9, MONTH ( create_time ) = 9 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 9, MONTH ( b.create_time ) = 9 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI9 ON BOI9.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 10, MONTH ( create_time ) = 10 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 10, MONTH ( b.create_time ) = 10 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI10 ON BOI10.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 11, MONTH ( create_time ) = 11 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 11, MONTH ( b.create_time ) = 11 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI11 ON BOI11.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 12, MONTH ( create_time ) = 12 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 12, MONTH ( b.create_time ) = 12 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI12 ON BOI12.id = BO.id
|
|
|
LEFT JOIN basic_goods_desc BGD ON BOI1.Item_id = BGD.id
|
|
|
OR BOI2.Item_id = BGD.id
|
|
|
@@ -2840,326 +2864,350 @@ ORDER BY
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 1, MONTH ( create_time ) = 1 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 1, MONTH ( b.create_time ) = 1 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI1 ON BOI1.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 2, MONTH ( create_time ) = 2 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 2, MONTH ( b.create_time ) = 2 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI2 ON BOI2.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 3, MONTH ( create_time ) = 3 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 3, MONTH ( b.create_time ) = 3 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI3 ON BOI3.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 4, MONTH ( create_time ) = 4 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 4, MONTH ( b.create_time ) = 4 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI4 ON BOI4.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 5, MONTH ( create_time ) = 5 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 5, MONTH ( b.create_time ) = 5 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI5 ON BOI5.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 6, MONTH ( create_time ) = 6 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 6, MONTH ( b.create_time ) = 6 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI6 ON BOI6.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 7, MONTH ( create_time ) = 7 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 7, MONTH ( b.create_time ) = 7 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI7 ON BOI7.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 8, MONTH ( create_time ) = 8 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 8, MONTH ( b.create_time ) = 8 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI8 ON BOI8.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 9, MONTH ( create_time ) = 9 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 9, MONTH ( b.create_time ) = 9 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI9 ON BOI9.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 10, MONTH ( create_time ) = 10 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 10, MONTH ( b.create_time ) = 10 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI10 ON BOI10.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 11, MONTH ( create_time ) = 11 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 11, MONTH ( b.create_time ) = 11 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI11 ON BOI11.id = BO.id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
b.id,
|
|
|
+ bt.id as btid,
|
|
|
bt.item_id,
|
|
|
- sum( b.debit_amount ) AS amount,
|
|
|
- sum( bt.quantity ) AS quantity
|
|
|
+ bt.amount AS amount,
|
|
|
+ bt.quantity AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
+ id,
|
|
|
pid,
|
|
|
item_id,
|
|
|
- IF
|
|
|
- ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ actual_quantity AS quantity,
|
|
|
+ Round(actual_quantity * price, 2) AS amount
|
|
|
FROM
|
|
|
business_order_items
|
|
|
WHERE
|
|
|
is_deleted = 0
|
|
|
GROUP BY
|
|
|
- pid
|
|
|
+ id
|
|
|
) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
IF
|
|
|
- ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 12, MONTH ( create_time ) = 12 )
|
|
|
+ ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 12, MONTH ( b.create_time ) = 12 )
|
|
|
GROUP BY
|
|
|
- b.id
|
|
|
+ btid
|
|
|
) BOI12 ON BOI12.id = BO.id
|
|
|
LEFT JOIN basic_goods_desc BGD ON BOI1.Item_id = BGD.id
|
|
|
OR BOI2.Item_id = BGD.id
|