mirror of https://github.com/jeecgboot/jeecg-boot
feature : transaction.sql updated
parent
67cb86e25b
commit
b59b2ba00c
|
@ -1,54 +1,71 @@
|
||||||
CREATE VIEW transaction as
|
CREATE VIEW transaction as
|
||||||
SELECT id, create_by, create_time, update_by, update_time,
|
SELECT id AS id,
|
||||||
type, client_id, payment_proof, invoice_number, shipping_fee, purchase_fee, amount, currency
|
create_by AS create_by,
|
||||||
FROM
|
create_time AS create_time,
|
||||||
(
|
update_by AS update_by,
|
||||||
SELECT id as id,
|
update_time AS update_time,
|
||||||
create_by,
|
type AS type,
|
||||||
create_time,
|
client_id AS client_id,
|
||||||
update_by,
|
payment_proof AS payment_proof,
|
||||||
update_time,
|
invoice_number AS invoice_number,
|
||||||
'Credit' as type,
|
shipping_fee AS shipping_fee,
|
||||||
client_id,
|
purchase_fee AS purchase_fee,
|
||||||
payment_proof,
|
amount AS amount,
|
||||||
NULL as invoice_number,
|
currency AS currency
|
||||||
NULL as shipping_fee,
|
FROM (
|
||||||
NULL as purchase_fee,
|
SELECT id AS id,
|
||||||
amount as amount,
|
create_by AS create_by,
|
||||||
(SELECT code FROM currency WHERE credit.currency_id = id) as currency
|
create_time AS create_time,
|
||||||
FROM credit
|
update_by AS update_by,
|
||||||
UNION ALL
|
update_time AS update_time,
|
||||||
SELECT id as id,
|
'Credit' AS type,
|
||||||
create_by,
|
client_id AS client_id,
|
||||||
create_time,
|
payment_proof AS payment_proof,
|
||||||
update_by,
|
NULL AS invoice_number,
|
||||||
update_time,
|
NULL AS shipping_fee,
|
||||||
'Debit' as type,
|
NULL AS purchase_fee,
|
||||||
client_id,
|
amount AS amount,
|
||||||
NULL as payment_proof,
|
(SELECT code FROM currency WHERE credit.currency_id = id) AS currency
|
||||||
invoice_number,
|
FROM credit
|
||||||
total_amount as shipping_fee,
|
UNION ALL
|
||||||
IF(invoice_number LIKE '%%%%-%%-7%%%',
|
SELECT id AS id,
|
||||||
purchase_total(invoice_number),
|
create_by AS create_by,
|
||||||
NULL) as purchase_fee,
|
create_time AS create_time,
|
||||||
IF(invoice_number LIKE '%%%%-%%-7%%%',
|
update_by AS update_by,
|
||||||
total_amount + (purchase_total(invoice_number)),
|
update_time AS update_time,
|
||||||
total_amount) as amount,
|
'Debit' AS type,
|
||||||
(SELECT code FROM currency WHERE shipping_invoice.currency_id = id) as currency
|
client_id AS client_id,
|
||||||
FROM shipping_invoice
|
NULL AS payment_proof,
|
||||||
WHERE client_id IS NOT NULL
|
invoice_number AS invoice_number,
|
||||||
AND shipping_invoice.currency_id IS NOT NULL
|
total_amount AS shipping_fee,
|
||||||
AND shipping_invoice.currency_id <> ''
|
if((invoice_number like '%%%%-%%-7%%%'),
|
||||||
) as id;
|
purchase_total(invoice_number), NULL) AS purchase_fee,
|
||||||
|
if((invoice_number like '%%%%-%%-7%%%'),
|
||||||
-- Function that computes the total of purchase by order
|
(total_amount +
|
||||||
CREATE FUNCTION purchase_total( invoice_number varchar(12)) RETURNS decimal(10, 2)
|
purchase_total(invoice_number)),
|
||||||
BEGIN
|
total_amount) AS amount,
|
||||||
RETURN (
|
(SELECT code FROM currency WHERE shipping_invoice.currency_id = id) AS currency
|
||||||
SELECT SUM(poc.purchase_fee) as total
|
FROM shipping_invoice
|
||||||
FROM platform_order_content as poc
|
WHERE client_id IS NOT NULL
|
||||||
JOIN platform_order po
|
AND currency_id IS NOT NULL
|
||||||
ON po.id = poc.platform_order_id
|
AND currency_id <> ''
|
||||||
WHERE po.shipping_invoice_number = invoice_number
|
UNION ALL
|
||||||
);
|
SELECT id AS id,
|
||||||
END;
|
create_by as create_by,
|
||||||
|
create_time as create_time,
|
||||||
|
update_by as update_by,
|
||||||
|
update_time as update_time,
|
||||||
|
'Debit' AS type,
|
||||||
|
client_id AS client_id,
|
||||||
|
payment_document AS payment_proof,
|
||||||
|
invoice_number AS invoice_number,
|
||||||
|
NULL AS shipping_fee,
|
||||||
|
final_amount AS purchase_fee,
|
||||||
|
final_amount AS amount,
|
||||||
|
(SELECT code FROM currency WHERE purchase_order.currency_id = id) AS currency
|
||||||
|
FROM purchase_order
|
||||||
|
WHERE invoice_number LIKE '%%%%-%%-1%%%'
|
||||||
|
AND client_id IS NOT NULL
|
||||||
|
AND currency_id IS NOT NULL
|
||||||
|
AND currency_id <> ''
|
||||||
|
) as id;
|
Loading…
Reference in New Issue