diff --git a/db/util.sql b/db/util.sql new file mode 100644 index 000000000..46b05060f --- /dev/null +++ b/db/util.sql @@ -0,0 +1,76 @@ +SELECT DISTINCT sku_id FROM platform_order_content WHERE sku_id not LIKE '1%'; + +UPDATE platform_order +SET fret_fee = NULL, + shipping_invoice_number = NULL +WHERE shipping_invoice_number IS NOT NULL; +UPDATE platform_order_content +SET shipping_fee = NULL, + service_fee = NULL, + vat = NULL +WHERE vat IS NOT NULL; + +DELETE from platform_order_content WHERE sku_id is NULL; + + +SELECT @@character_set_database, @@collation_database; +SHOW VARIABLES LIKE 'collation%'; +SHOW TABLE STATUS LIKE 'sen%'; +ALTER DATABASE wia_app COLLATE utf8mb4_general_ci; + +SELECT c.internal_code AS '客户', + s.erp_code AS SKU, + p.zh_name AS '中文名', + p.weight AS '重量', + ROUND(calculate_shipping_fees(IF(sa.zh_name = '普货', '联邮通优先挂号-普货', '联邮通优先挂号-带电'), 'FR', '2021-06-24', + p.weight), 2) AS '运费', + get_registration_fees(IF(sa.zh_name = '普货', '联邮通优先挂号-普货', '联邮通优先挂号-带电'), 'FR', '2021-06-24', + p.weight) AS '挂号费' +FROM sku s + LEFT JOIN client_sku ON s.id = client_sku.sku_id + LEFT JOIN client c ON client_sku.client_id = c.id + JOIN product p ON p.id = s.product_id + JOIN sensitive_attribute sa ON p.sensitive_attribute_id = sa.id; + +SELECT c.internal_code AS 'Client', + po.platform_order_id AS 'Order ID', + po.logistic_channel_name AS 'Logistic Channel', + po.platform_order_number AS 'Order Number', + po.order_time AS 'Order Time', + po.shipping_time AS 'Shipping Time', + po.country AS 'Country', + IF(s.erp_code IS NULL, poc.sku_id, s.erp_code) AS 'SKU', + poc.quantity AS 'Quantity', + po.fret_fee AS 'Fret Fee', + (SELECT SUM(poc.shipping_fee) +WHERE poc.platform_order_id = po.id) AS 'Shipping Fee', + poc.service_fee AS 'Service Fee', + po.status AS 'Status' +FROM platform_order po + JOIN platform_order_content poc ON po.id = poc.platform_order_id + LEFT JOIN shop ON po.shop_id = shop.id + LEFT JOIN client c ON shop.owner_id = c.id + LEFT JOIN sku s ON poc.sku_id = s.id +WHERE po.erp_status = 3 +ORDER BY Client; + +SELECT json_array(poc.shipping_fee) +from platform_order_content poc JOIN platform_order po ON po.id = poc.platform_order_id +WHERE poc.platform_order_id = po.id; + +SELECT s.erp_code, count(DISTINCT po.id), sum(poc.quantity) +FROM platform_order po + JOIN platform_order_content poc ON po.id = poc.platform_order_id + JOIN shop s ON po.shop_id = s.id +WHERE shipping_invoice_number IS not NULL + AND po.erp_status = '3' +GROUP BY erp_code +ORDER BY erp_code; + +SELECT s.erp_code, po.* +FROM platform_order po + JOIN platform_order_content poc ON po.id = poc.platform_order_id + JOIN shop s ON po.shop_id = s.id +WHERE shipping_invoice_number IS NULL + AND po.erp_status = '3' and (erp_code = 'EP5' OR erp_code ='EP6') +ORDER BY erp_code; \ No newline at end of file diff --git a/db/views/api_view.sql b/db/views/api_view.sql new file mode 100644 index 000000000..7ad164983 --- /dev/null +++ b/db/views/api_view.sql @@ -0,0 +1,13 @@ +CREATE OR REPLACE VIEW api_view AS +SELECT p.country, p.third_bill_code as trackingNumber, + (SELECT JSON_ARRAYAGG( + JSON_OBJECT( + 'scanType', scan_type, + 'scanTime', scan_time, + 'description', IF(description_en IS NOT NULL, description_en, description) + )) + FROM parcel_trace pt + WHERE p.id = pt.parcel_id + ORDER BY scan_time DESC + ) AS traces +FROM parcel p; \ No newline at end of file diff --git a/db/views/calculate_shipping_fees.sql b/db/views/calculate_shipping_fees.sql new file mode 100644 index 000000000..ae27b9966 --- /dev/null +++ b/db/views/calculate_shipping_fees.sql @@ -0,0 +1,41 @@ +CREATE FUNCTION calculate_shipping_fees(logistic_channel varchar(50), country varchar(2), shipping_date date, + weight int) RETURNS DOUBLE +BEGIN + DECLARE minimum_weight INT; + DECLARE minimum_weight_price double; + DECLARE cal_unit INT; + DECLARE cal_unit_price double; + DECLARE additional_cost double; + DECLARE shipping_fee double; + + SELECT lcp.minimum_weight, + lcp.minimum_weight_price, + lcp.cal_unit, + lcp.cal_unit_price, + lcp.additional_cost + INTO minimum_weight, + minimum_weight_price, + cal_unit, + cal_unit_price, + additional_cost + FROM logistic_channel_price lcp + JOIN logistic_channel lc ON lc.id = lcp.channel_id + WHERE lc.zh_name = logistic_channel + AND weight_range_start <= weight + AND weight_range_end >= weight + AND effective_country = country + AND effective_date <= shipping_date + ORDER BY effective_date + DESC + LIMIT 1; + + IF weight = 0 THEN + SET shipping_fee = 0; + ELSEIF weight < minimum_weight THEN + SET shipping_fee = minimum_weight_price; + ELSE + SET shipping_fee = ((weight - minimum_weight) / cal_unit) * cal_unit_price + minimum_weight_price; + END IF; + + RETURN shipping_fee; +END; \ No newline at end of file diff --git a/db/views/detail_de_facture.sql b/db/views/detail_de_facture.sql new file mode 100644 index 000000000..b3ba2ceae --- /dev/null +++ b/db/views/detail_de_facture.sql @@ -0,0 +1,30 @@ +CREATE OR REPLACE VIEW detail_de_facture AS +SELECT s.name AS 'Boutique', + po.platform_order_id AS 'N° de Mabang', + po.platform_order_number AS 'N° de commande', + po.tracking_number AS 'N° de suivi', + po.order_time AS 'Date de commande', + po.shipping_time AS 'Date d\'expédition', + po.recipient AS 'Nom de client', + po.country AS 'Pays', + po.postcode AS 'Code postal', + JSON_ARRAYAGG(sku.erp_code) AS 'SKU', + JSON_ARRAYAGG(p.en_name) AS 'Nom produits', + JSON_ARRAYAGG(poc.quantity) AS 'Quantité', + SUM(poc.purchase_fee) AS 'Frais d\'achat', + po.fret_fee AS 'Frais de FRET', + SUM(poc.shipping_fee) AS 'Frais de livraison', + po.order_service_fee + SUM(poc.service_fee) AS 'Frais de service', + po.picking_fee + SUM(poc.picking_fee) AS 'Frais de préparation', + po.packaging_material_fee AS 'Frais de matériel d\'emballage', + SUM(poc.vat) AS 'TVA', + po.shipping_invoice_number AS 'N° de facture' +FROM platform_order po + JOIN shop s ON po.shop_id = s.id + RIGHT JOIN platform_order_content poc ON po.id = poc.platform_order_id + JOIN sku ON poc.sku_id = sku.id + JOIN product p ON sku.product_id = p.id +WHERE shipping_invoice_number IS NOT NULL + AND poc.erp_status <> 5 +GROUP BY po.id, s.name, po.order_time +ORDER BY s.name, po.order_time; \ No newline at end of file diff --git a/db/views/full_logistic_expense_detail.sql b/db/views/full_logistic_expense_detail.sql new file mode 100644 index 000000000..0322baa73 --- /dev/null +++ b/db/views/full_logistic_expense_detail.sql @@ -0,0 +1,51 @@ +CREATE OR REPLACE VIEW full_logistic_expense_detail AS +SELECT led.tracking_number AS 'trackingNumber', + led.real_weight, + led.volumetric_weight, + led.charging_weight, + led.discount, + led.shipping_fee, + led.fuel_surcharge, + led.registration_fee, + led.second_delivery_fee, + led.vat, + led.vat_service_fee, + led.total_fee, + led.logistic_company_id, + led.additional_fee +FROM logistic_expense_detail led +WHERE tracking_number = logistic_internal_number +UNION +SELECT led.logistic_internal_number AS 'trackingNumber', + led.real_weight, + led.volumetric_weight, + led.charging_weight, + led.discount, + led.shipping_fee, + led.fuel_surcharge, + led.registration_fee, + led.second_delivery_fee, + led.vat, + led.vat_service_fee, + led.total_fee, + led.logistic_company_id, + led.additional_fee +FROM logistic_expense_detail led +WHERE tracking_number <> logistic_internal_number +UNION +SELECT led.tracking_number AS 'trackingNumber', + led.real_weight, + led.volumetric_weight, + led.charging_weight, + led.discount, + led.shipping_fee, + led.fuel_surcharge, + led.registration_fee, + led.second_delivery_fee, + led.vat, + led.vat_service_fee, + led.total_fee, + led.logistic_company_id, + led.additional_fee +FROM logistic_expense_detail led +WHERE tracking_number <> logistic_internal_number; \ No newline at end of file diff --git a/db/views/get_registration_fees.sql b/db/views/get_registration_fees.sql new file mode 100644 index 000000000..4f0f5ee85 --- /dev/null +++ b/db/views/get_registration_fees.sql @@ -0,0 +1,24 @@ +CREATE FUNCTION get_registration_fees(logistic_channel varchar(50), country varchar(2), shipping_date date, + weight int) RETURNS DOUBLE +BEGIN + DECLARE registration_fee double; + + SELECT lcp.registration_fee + INTO registration_fee + FROM logistic_channel_price lcp + JOIN logistic_channel lc ON lc.id = lcp.channel_id + WHERE lc.zh_name = logistic_channel + AND weight_range_start <= weight + AND weight_range_end >= weight + AND effective_country = country + AND effective_date <= shipping_date + ORDER BY effective_date + DESC + LIMIT 1; + + IF weight = 0 THEN + RETURN 0; + ELSE + RETURN registration_fee; + END IF; +END; \ No newline at end of file diff --git a/db/views/inventory_record.sql b/db/views/inventory_record.sql new file mode 100644 index 000000000..42d2d9b6a --- /dev/null +++ b/db/views/inventory_record.sql @@ -0,0 +1,25 @@ +CREATE OR REPLACE VIEW inventory_record AS +SELECT sku.id AS id, + cs.client_id AS client_id, + sku.product_id AS product_id, + sku.erp_code AS erp_code, + sku.image_source AS image_source, + sku.available_amount AS available_amount, + p.moq AS moq, + rs.quantity AS red_quantity, + gs.quantity AS green_quantity, + sales_7.quantity AS sales_7, + sales_14.quantity AS sales_14, + sales_28.quantity AS sales_28, + sipo.quantity AS platform_order_quantity +FROM sku + JOIN product p ON sku.product_id = p.id + JOIN client_sku cs ON sku.id = cs.sku_id + LEFT JOIN sales_7 ON sku.id = sales_7.sku_id + LEFT JOIN sales_14 ON sku.id = sales_14.sku_id + LEFT JOIN sales_28 ON sku.id = sales_28.sku_id + LEFT JOIN red_sku rs ON sku.id = rs.sku_id + LEFT JOIN green_sku gs ON sku.id = gs.sku_id + LEFT JOIN sku_in_platform_order sipo ON sku.id = sipo.sku_id +ORDER BY platform_order_quantity DESC; + diff --git a/db/views/logistic_fees_by_country.sql b/db/views/logistic_fees_by_country.sql new file mode 100644 index 000000000..313524f57 --- /dev/null +++ b/db/views/logistic_fees_by_country.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE VIEW logistic_fees_by_country AS +SELECT s.name AS '店铺', + po.country AS '国家', + SUM(po.fret_fee) AS '收取挂号费', + SUM(led.registration_fee) AS '实际支付挂号费', + SUM(poc.shipping_fee) AS '收取运费', + SUM(led.total_fee) - SUM(registration_fee) AS '实际支付运费', + SUM(poc.vat) AS '收取TVA', + SUM(led.vat) + SUM(led.vat_service_fee) AS '实际支付TVA' +FROM platform_order po + JOIN shop s ON po.shop_id = s.id + RIGHT JOIN platform_order_content poc ON po.id = poc.platform_order_id + JOIN logistic_expense_detail led ON po.tracking_number = led.tracking_number +WHERE shipping_invoice_number IS NOT NULL +GROUP BY s.name, po.country +ORDER BY s.name \ No newline at end of file diff --git a/db/views/logistic_profit_analyze.sql b/db/views/logistic_profit_analyze.sql new file mode 100644 index 000000000..bff9ffc81 --- /dev/null +++ b/db/views/logistic_profit_analyze.sql @@ -0,0 +1,29 @@ +CREATE OR REPLACE VIEW logistic_profit_analyze AS +SELECT c.internal_code AS '客户', + shopErpCode AS '店铺', + lc.name AS '物流公司', + logisticChannelName AS '物流路线', + platformOrderId AS '订单号', + platformOrderNumber AS '交易号', + orderTime AS '交易时间', + shippingTime AS '发货时间', + poled.country AS '国家', + fretFee AS '应收挂号费(欧元)', + registration_fee AS '实付挂号费(人民币)', + (fretFee * 7.6 - registration_fee) AS '挂号费利润(人民币)', + shippingFee AS '应收运费(欧元)', + realShippingFee AS '实付运费(人民币)', + (shippingFee * 7.6 - realShippingFee) AS '运费利润(人民币)', + vatFee AS '应收增值税(欧元)', + (vat + vat_service_fee) AS '实付增值税(人民币)', + (vatFee * 7.6 - vat - vat_service_fee) AS '增值税利润(人民币)', + serviceFee AS '服务费(欧元)', + serviceFee * 7.6 AS '服务费(人民币)', + (fretFee * 7.6 - registration_fee + shippingFee * 7.6 - + realShippingFee + vat * 7.6 - vat - vat_service_fee) AS '服务费外总利润(人民币)' + +FROM platform_order_logistic_expense_detail poled + JOIN shop s + ON shop_id = s.id + JOIN CLIENT c ON s.owner_id = c.id + JOIN logistic_company lc ON poled.logistic_company_id = lc.id; \ No newline at end of file diff --git a/db/views/platform_order_logistic_expense_detail.sql b/db/views/platform_order_logistic_expense_detail.sql new file mode 100644 index 000000000..8987f6100 --- /dev/null +++ b/db/views/platform_order_logistic_expense_detail.sql @@ -0,0 +1,35 @@ +CREATE OR REPLACE VIEW platform_order_logistic_expense_detail AS +SELECT s.erp_code AS 'shopErpCode', + po.tracking_number AS 'trackingNumber', + po.shop_id, + po.logistic_channel_name AS 'logisticChannelName', + po.platform_order_id AS 'platformOrderId', + po.platform_order_number AS 'platformOrderNumber', + po.order_time AS 'orderTime', + po.shipping_time AS 'shippingTime', + po.country, + po.fret_fee AS 'fretFee', + SUM(poc.shipping_fee) AS 'shippingFee', + SUM(poc.vat) AS 'vatFee', + po.order_service_fee + SUM(poc.service_fee) AS 'serviceFee', + po.shipping_invoice_number AS 'shippingInvoiceNumber', + fled.real_weight, + fled.volumetric_weight, + fled.charging_weight, + fled.discount, + fled.shipping_fee AS 'realShippingFee', + fled.fuel_surcharge, + fled.registration_fee, + fled.second_delivery_fee, + fled.vat, + fled.vat_service_fee, + fled.total_fee, + fled.logistic_company_id, + fled.additional_fee +FROM full_logistic_expense_detail fled + RIGHT JOIN platform_order po ON fled.trackingNumber = po.tracking_number + JOIN shop s ON po.shop_id = s.id + JOIN platform_order_content poc ON po.id = poc.platform_order_id +WHERE po.erp_status IN (3, 4) +GROUP BY po.id, s.erp_code +ORDER BY s.erp_code; \ No newline at end of file diff --git a/db/views/sales.sql b/db/views/sales.sql new file mode 100644 index 000000000..852a2ca21 --- /dev/null +++ b/db/views/sales.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE VIEW sales_7 AS +SELECT poc.sku_id AS sku_id, SUM(poc.quantity) AS quantity +FROM platform_order_content poc + JOIN platform_order po ON poc.platform_order_id = po.id +WHERE po.order_time BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE() +GROUP BY poc.sku_id; + +CREATE OR REPLACE VIEW sales_14 AS +SELECT poc.sku_id AS sku_id, SUM(poc.quantity) AS quantity +FROM platform_order_content poc + JOIN platform_order po ON poc.platform_order_id = po.id +WHERE po.order_time BETWEEN DATE_SUB(CURDATE(), INTERVAL 14 DAY) AND CURDATE() +GROUP BY poc.sku_id; + +CREATE OR REPLACE VIEW sales_28 AS +SELECT poc.sku_id AS sku_id, SUM(poc.quantity) AS quantity +FROM platform_order_content poc + JOIN platform_order po ON poc.platform_order_id = po.id +WHERE po.order_time BETWEEN DATE_SUB(CURDATE(), INTERVAL 28 DAY) AND CURDATE() +GROUP BY poc.sku_id; \ No newline at end of file diff --git a/db/views/sales_analyze.sql b/db/views/sales_analyze.sql new file mode 100644 index 000000000..07a5b21c4 --- /dev/null +++ b/db/views/sales_analyze.sql @@ -0,0 +1,42 @@ +CREATE OR REPLACE VIEW sales_analyze AS +SELECT c.internal_code AS '客户代码', + s.name AS '店铺名', + s.erp_code AS '店铺代码', + po.platform_order_number AS '订单交易号', + po.country AS '国家', + po.order_time AS '订单交易时间', + CAST(po.order_time AS DATE) AS '订单交易日期', + CASE + WHEN + s2.erp_code IS NULL + THEN poc.sku_id + WHEN s2.erp_code IS NOT NULL + THEN s2.erp_code + END AS 'SKU', + p.zh_name AS '产品中文名', + poc.quantity AS '产品数量', + p.weight AS '商品收费重', + poc.purchase_fee AS '商品采购费', + poc.service_fee AS '商品服务费', + poc.shipping_fee AS '商品运费', + po.fret_fee AS '包裹挂号费', + CASE + WHEN po.erp_status = '1' + THEN '待处理' + WHEN po.erp_status = '2' + THEN '配货中' + WHEN po.erp_status = '3' + THEN '已发货' + WHEN po.erp_status = '4' + THEN '已完成' + WHEN po.erp_status = '5' + THEN '已作废' + END AS '订单状态', + po.logistic_channel_name AS '物流渠道' +FROM platform_order_content poc + LEFT JOIN sku s2 ON poc.sku_id = s2.id + LEFT JOIN product p ON s2.product_id = p.id + JOIN platform_order po ON poc.platform_order_id = po.id + JOIN shop s ON po.shop_id = s.id + JOIN client c ON s.owner_id = c.id +ORDER BY order_time; \ No newline at end of file diff --git a/db/views/sav_refund_with_detail.sql b/db/views/sav_refund_with_detail.sql new file mode 100644 index 000000000..140276692 --- /dev/null +++ b/db/views/sav_refund_with_detail.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE VIEW sav_refund_with_detail +AS +SELECT sr.*, + po.platform_order_id AS mabang_id, + s.erp_code, + s.name as shop_name, + po.platform_order_number, + po.fret_fee, + SUM(poc.shipping_fee) AS shipping_fee, + SUM(poc.vat) AS vat, + po.order_service_fee + SUM(poc.service_fee) AS service_fee +FROM sav_refund sr + JOIN platform_order po ON sr.platform_order_id = po.id + JOIN platform_order_content poc ON po.id = poc.platform_order_id + JOIN shop s ON po.shop_id = s.id +GROUP BY po.id; \ No newline at end of file diff --git a/db/views/sku_country_channel_choice.sql b/db/views/sku_country_channel_choice.sql new file mode 100644 index 000000000..7fbb17826 --- /dev/null +++ b/db/views/sku_country_channel_choice.sql @@ -0,0 +1,25 @@ +CREATE OR REPLACE VIEW sku_country_channel_choice AS +SELECT sku.id AS id, + cs.client_id AS client_id, + sku.product_id AS product_id, + sku.erp_code AS erp_code, + sku.image_source AS image_source, + sku.available_amount AS available_amount, + p.moq AS moq, + rs.quantity AS red_quantity, + gs.quantity AS green_quantity, + sales_7.quantity AS sales_7, + sales_14.quantity AS sales_14, + sales_28.quantity AS sales_28, + sipo.quantity AS platform_order_quantity +FROM sku + JOIN product p ON sku.product_id = p.id + JOIN client_sku cs ON sku.id = cs.sku_id + LEFT JOIN sales_7 ON sku.id = sales_7.sku_id + LEFT JOIN sales_14 ON sku.id = sales_14.sku_id + LEFT JOIN sales_28 ON sku.id = sales_28.sku_id + LEFT JOIN red_sku rs ON sku.id = rs.sku_id + LEFT JOIN green_sku gs ON sku.id = gs.sku_id + LEFT JOIN sku_in_platform_order sipo ON sku.id = sipo.sku_id +ORDER BY platform_order_quantity DESC; + diff --git a/db/views/sku_current_price.sql b/db/views/sku_current_price.sql new file mode 100644 index 000000000..4a4728e91 --- /dev/null +++ b/db/views/sku_current_price.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE VIEW sku_current_price AS +SELECT id AS price_id, + sp.sku_id AS sku_id, + price AS price, + threshold AS threshold, + discounted_price AS discounted_price, + price_rmb AS price_rmb, + discounted_price_rmb AS discounted_price_rmb, + date AS date +FROM sku_price sp + INNER JOIN (SELECT sku_id, MAX(date) max_date FROM sku_price GROUP BY sku_id) sp2 + ON sp.sku_id = sp2.sku_id AND sp.date = sp2.max_date \ No newline at end of file diff --git a/db/views/sku_in_platform_order.sql b/db/views/sku_in_platform_order.sql new file mode 100644 index 000000000..c5bc677a8 --- /dev/null +++ b/db/views/sku_in_platform_order.sql @@ -0,0 +1,5 @@ +CREATE OR REPLACE VIEW sku_in_platform_order AS +SELECT poc.sku_id AS sku_id, SUM(poc.quantity) AS quantity +FROM platform_order_content poc join platform_order po ON poc.platform_order_id = po.id +WHERE po.status = 2 +GROUP BY poc.sku_id; \ No newline at end of file diff --git a/db/views/sku_price_promotion.sql b/db/views/sku_price_promotion.sql new file mode 100644 index 000000000..60d2816c8 --- /dev/null +++ b/db/views/sku_price_promotion.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE VIEW sku_price_promotion AS +SELECT s.id AS sku_id, + p.en_name AS name_en, + p.zh_name AS name_zh, + s.erp_code AS erp_code, + s.image_source AS image_source, + spr.promotion_id AS promotion_id, + spr.promo_milestone AS promo_milestone, + spr.quantity_purchased AS quantity_purchased, + spr.discount AS discount, + scp.price_id AS price_id, + scp.price AS price, + scp.threshold AS threshold, + scp.discounted_price AS discounted_price, + scp.price_rmb AS price_rmb, + scp.discounted_price_rmb AS discounted_price_rmb +FROM sku s + LEFT JOIN sku_promotion_relation spr ON s.id = spr.sku_id + LEFT JOIN sku_current_price scp ON s.id = scp.sku_id + JOIN product p ON s.product_id = p.id + LEFT JOIN sku_in_platform_order sipo ON s.id = sipo.sku_id +ORDER BY sipo.quantity DESC; \ No newline at end of file diff --git a/db/views/sku_weight_discount.sql b/db/views/sku_weight_discount.sql new file mode 100644 index 000000000..44db099d2 --- /dev/null +++ b/db/views/sku_weight_discount.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE VIEW sku_weight_discount_service_fees AS +SELECT s.id, + s.erp_code, + p.weight, + s.shipping_discount, + s.service_fee +FROM sku s JOIN product p ON p.id = s.product_id; \ No newline at end of file diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java index 8d02eed09..b11c890bb 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java @@ -55,6 +55,8 @@ public class InvoiceController { @Autowired private ISavRefundService iSavRefundService; @Autowired + private ISavRefundWithDetailService savRefundWithDetailService; + @Autowired private IExchangeRatesService iExchangeRatesService; @Autowired private IQuartzJobService quartzJobService; @@ -76,7 +78,7 @@ public class InvoiceController { Set skuIds = orderContents.stream().map(PlatformOrderContent::getSkuId).collect(Collectors.toSet()); List skusWithoutPrice = platformOrderContentMap.searchSkuDetail(new ArrayList<>(skuIds)) .stream() - .filter(skuDetail -> skuDetail.getPrice().getPrice() == null) + .filter(skuDetail -> skuDetail.getPrice().getPrice() == null && skuDetail.getPrice().getPriceRmb() == null) .map(SkuDetail::getErpCode) .collect(Collectors.toList()); if (skusWithoutPrice.isEmpty()) { @@ -98,14 +100,19 @@ public class InvoiceController { String warehouseString = String.join(",", warehouses); QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(platformOrder, req.getParameterMap()); LambdaQueryWrapper lambdaQueryWrapper = queryWrapper.lambda(); - if(type.equals("shipping")) - lambdaQueryWrapper.in(PlatformOrder::getErpStatus, OrderStatus.Shipped.getCode()); - else if(type.equals("pre-shipping")) - lambdaQueryWrapper.in(PlatformOrder::getErpStatus, Arrays.asList(OrderStatus.Pending.getCode(), OrderStatus.Preparing.getCode())); - else if(type.equals("all")) - lambdaQueryWrapper.in(PlatformOrder::getErpStatus, Arrays.asList(OrderStatus.Pending.getCode(), OrderStatus.Preparing.getCode(), OrderStatus.Shipped.getCode())); - else - return Result.error("Error 404 : page not found."); + switch (type) { + case "shipping": + lambdaQueryWrapper.in(PlatformOrder::getErpStatus, OrderStatus.Shipped.getCode()); + break; + case "pre-shipping": + lambdaQueryWrapper.in(PlatformOrder::getErpStatus, Arrays.asList(OrderStatus.Pending.getCode(), OrderStatus.Preparing.getCode())); + break; + case "all": + lambdaQueryWrapper.in(PlatformOrder::getErpStatus, Arrays.asList(OrderStatus.Pending.getCode(), OrderStatus.Preparing.getCode(), OrderStatus.Shipped.getCode())); + break; + default: + return Result.error("Error 404 : page not found."); + } lambdaQueryWrapper.isNull(PlatformOrder::getShippingInvoiceNumber); Page page = new Page<>(pageNo, pageSize); IPage pageList; @@ -262,6 +269,7 @@ public class InvoiceController { } else { log.info("Specified shop IDs : " + param.shopIDs()); lambdaQueryWrapper.in(PlatformOrder::getShopId, param.shopIDs()); + lambdaQueryWrapper.isNull(PlatformOrder::getShippingInvoiceNumber); if(param.getErpStatuses() != null) { log.info("Specified erpStatuses : " + param.getErpStatuses()); lambdaQueryWrapper.in(PlatformOrder::getErpStatus, param.getErpStatuses()); @@ -294,6 +302,7 @@ public class InvoiceController { } else { log.info("Specified shop IDs : " + param.shopIDs()); lambdaQueryWrapper.in(PlatformOrder::getShopId, param.shopIDs()); + lambdaQueryWrapper.isNull(PlatformOrder::getShippingInvoiceNumber); lambdaQueryWrapper.inSql(PlatformOrder::getId, "SELECT id FROM platform_order po WHERE po.erp_status = '3' AND po.shipping_time between '" + param.getStart() + "' AND '" + param.getEnd() + "'" ); // on récupère les résultats de la requete List orderID = platformOrderMapper.selectList(lambdaQueryWrapper); @@ -324,8 +333,9 @@ public class InvoiceController { @GetMapping(value = "/downloadInvoiceDetail") public byte[] downloadInvoiceDetail(@RequestParam("invoiceNumber") String invoiceNumber, @RequestParam("invoiceEntity") String invoiceEntity) throws IOException { - List res = shippingInvoiceService.getInvoiceDetail(invoiceNumber); - return shippingInvoiceService.exportToExcel(res, invoiceNumber, invoiceEntity); + List factureDetails = shippingInvoiceService.getInvoiceDetail(invoiceNumber); + List refunds = savRefundWithDetailService.getRefundsByInvoiceNumber(invoiceNumber); + return shippingInvoiceService.exportToExcel(factureDetails, refunds, invoiceNumber, invoiceEntity); } @GetMapping(value = "/breakdown/byShop") diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/api/shopify/CreateFulfillmentRequest.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/api/shopify/CreateFulfillmentRequest.java index 93252f5c6..1494ba457 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/api/shopify/CreateFulfillmentRequest.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/api/shopify/CreateFulfillmentRequest.java @@ -42,6 +42,7 @@ public class CreateFulfillmentRequest extends ShopifyRequest { UK_ROYAL_MAIL("https://www.royalmail.com/track-your-item#/tracking-results/%s", "Royal Mail", "(FJ002|WB788)[0-9]{6}GB"), POST_NL("https://postnl.post/", "PostNL International Mail", "LS[0-9]{9}NL"), COLI_COLI("https://www.colicoli.fr/trackings?id=%s", "Coli Coli", "CC[0-9]{14}[A-Z]*"), + LUXEMBOURG_POST("https://www.post.lu/particuliers/colis-courrier/track-and-trace#/search", "Luxembourg Post", "LL[0-9]{9}LU"), ; private final String trackingUrl; diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/excel/SheetManager.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/excel/SheetManager.java index edb934c69..8cd38daca 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/excel/SheetManager.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/excel/SheetManager.java @@ -1,6 +1,6 @@ package org.jeecg.modules.business.domain.excel; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import lombok.Data; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -12,32 +12,35 @@ import java.nio.file.Path; import java.util.Date; /** - * Provide operation that manipulate Excel sheet driven by cursor. + * Provide operation that manipulates Excel sheet driven by cursor. * The cursor's position is in the (0, 0) at the beginning. */ +@Data public class SheetManager { + private final Workbook workbook; - private final Sheet sheet; + private final Sheet detailSheet; - private int row; + private final Sheet savSheet; - private int col; + private Sheet currentSheet; + + private int currentRow; + + private int currentCol; private int max_col; - private SheetManager(Workbook workbook, Sheet sheet) { + private SheetManager(Workbook workbook, Sheet detailSheet, Sheet savSheet) { this.workbook = workbook; - this.sheet = sheet; - row = 0; - col = 0; + this.detailSheet = detailSheet; + this.savSheet = savSheet; + this.currentRow = 0; + this.currentCol = 0; max_col = 10; } - public Workbook getWorkbook() { - return workbook; - } - /** * Create a manager for the first worksheet of an empty ".xlsx" Excel file. * The created worksheet named "sheet1". @@ -45,47 +48,44 @@ public class SheetManager { * @return the sheetManager instance. */ public static SheetManager createXLSX() { - return createXLSX("sheet1"); + return createXLSX("Détails", "SAV"); } /** * Same as {@code createXLSX()}, with customer sheet name. * - * @param name the customer sheet name + * @param detailSheetName Details sheet name + * @param savSheetName SAV sheet name * @return the sheetManager object. */ - public static SheetManager createXLSX(String name) { + public static SheetManager createXLSX(String detailSheetName, String savSheetName) { Workbook workbook = new XSSFWorkbook(); - Sheet sheet = workbook.createSheet(name); - return new SheetManager(workbook, sheet); + Sheet detailSheet = workbook.createSheet(detailSheetName); + Sheet savSheet = workbook.createSheet(savSheetName); + return new SheetManager(workbook, detailSheet, savSheet); } - /** - * Create a sheet manager for a sheet of a ".xls" Excel workbook. - * - * @param path path of the workbook. - * @param sheetIndex index of the sheet, begin from 0 - * @return the sheet manager object - * @throws IOException any error while opening the workbook. - */ - public static SheetManager readXLS(Path path, int sheetIndex) throws IOException { - FileInputStream fis = new FileInputStream(path.toFile()); - Workbook workbook = new HSSFWorkbook(fis); - return new SheetManager(workbook, workbook.getSheetAt(sheetIndex)); + public void startDetailsSheet() { + this.currentSheet = detailSheet; + } + + public void startSavSheet() { + this.currentSheet = savSheet; + this.currentRow = 0; + this.currentCol = 0; } /** * Same as {@code readXLS} but for ".xlsx" Excel workbook. * * @param path path of the workbook. - * @param sheetIndex index of the sheet, begin from 0 * @return the sheet manager object * @throws IOException any error while opening the workbook. */ - public static SheetManager readXLSX(Path path, int sheetIndex) throws IOException { + public static SheetManager readXLSX(Path path) throws IOException { FileInputStream fis = new FileInputStream(path.toFile()); Workbook workbook = new XSSFWorkbook(fis); - return new SheetManager(workbook, workbook.getSheetAt(sheetIndex)); + return new SheetManager(workbook, workbook.getSheetAt(0), workbook.getSheetAt(1)); } /** @@ -96,12 +96,12 @@ public class SheetManager { * @param col col index of the location */ public void go(int row, int col) { - this.row = row; + this.currentRow = row; _moveCol(col); } public void moveRow(int row) { - this.row = row; + this.currentRow = row; } public void moveCol(int col) { @@ -109,31 +109,31 @@ public class SheetManager { } public int row() { - return row; + return currentRow; } public int col() { - return col; + return currentCol; } /** - * Move cursor to the bottom cell. + * Move the cursor to the bottom cell. */ public void nextRow() { - this.row += 1; + this.currentRow += 1; } /** - * Move cursor to the left cell. + * Move the cursor to the left cell. */ public void nextCol() { - _moveCol(this.col + 1); + _moveCol(this.currentCol + 1); } /** * Write a value to the cell pointed by cursor. * - * @param value the value to be wrote, if value is null then we will change the cell to a Blank cell. + * @param value the value to be written, if value is null then we will change the cell to a Blank cell. */ public void write(String value) { cell().setCellValue(value); @@ -142,7 +142,7 @@ public class SheetManager { /** * Write a value to the cell pointed by cursor. * - * @param value the value to be wrote, if value is null then we will change the cell to a Blank cell. + * @param value the value to be written, if value is null then we will change the cell to a Blank cell. */ public void write(int value) { cell().setCellValue(value); @@ -151,7 +151,7 @@ public class SheetManager { /** * Write a value to the cell pointed by cursor. * - * @param value the value to be wrote, if value is null then we will change the cell to a Blank cell. + * @param value the value to be written, if value is null then we will change the cell to a Blank cell. */ public void write(BigDecimal value) { cell().setCellValue(value.doubleValue()); @@ -160,7 +160,7 @@ public class SheetManager { /** * Write a value to the cell pointed by cursor. * - * @param value the value to be wrote + * @param value the value to be written */ public void write(Date value) { cell().setCellValue(value); @@ -202,7 +202,8 @@ public class SheetManager { public void export(Path target) throws IOException { /* adjust all cols' width before export */ for (int i = 0; i < max_col; i++) { - sheet.autoSizeColumn(i); + detailSheet.autoSizeColumn(i); + savSheet.autoSizeColumn(i); } FileOutputStream fos = new FileOutputStream(target.toFile()); workbook.write(fos); @@ -211,13 +212,13 @@ public class SheetManager { private Cell cell() { - Row row = sheet.getRow(this.row); + Row row = currentSheet.getRow(this.currentRow); if (row == null) { - row = sheet.createRow(this.row); + row = currentSheet.createRow(this.currentRow); } - Cell cell = row.getCell(col); + Cell cell = row.getCell(currentCol); if (cell == null) { - cell = row.createCell(col); + cell = row.createCell(currentCol); } return cell; } @@ -226,7 +227,7 @@ public class SheetManager { if (dst > max_col) { max_col = dst + 5; } - col = dst; + currentCol = dst; } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/CompleteInvoice.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/CompleteInvoice.java index 8d00bfb1d..b7d50b9be 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/CompleteInvoice.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/CompleteInvoice.java @@ -1,11 +1,11 @@ package org.jeecg.modules.business.domain.shippingInvoice; -import org.jeecg.modules.business.domain.invoice.InvoiceStyleFactory; import org.jeecg.modules.business.domain.invoice.Row; import org.jeecg.modules.business.domain.purchase.invoice.PurchaseInvoiceEntry; import org.jeecg.modules.business.entity.Client; import org.jeecg.modules.business.entity.PlatformOrder; import org.jeecg.modules.business.entity.PlatformOrderContent; +import org.jeecg.modules.business.entity.SavRefundWithDetail; import org.jeecg.modules.business.vo.PromotionDetail; import java.math.BigDecimal; @@ -22,11 +22,11 @@ public class CompleteInvoice extends ShippingInvoice { private final List promotions; - public CompleteInvoice(Client targetClient, String code, - String subject, + public CompleteInvoice(Client targetClient, String code, String subject, Map> ordersToContent, - List purchaseInvoiceEntries, List promotions, BigDecimal exchangeRate) { - super(targetClient, code, subject, ordersToContent, null, exchangeRate); + List savRefunds, List purchaseInvoiceEntries, + List promotions, BigDecimal exchangeRate) { + super(targetClient, code, subject, ordersToContent, savRefunds, exchangeRate); this.purchaseInvoiceEntries = purchaseInvoiceEntries; this.promotions = promotions; } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/ShippingInvoiceFactory.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/ShippingInvoiceFactory.java index 08c81e0d8..08565a398 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/ShippingInvoiceFactory.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/ShippingInvoiceFactory.java @@ -109,17 +109,18 @@ public class ShippingInvoiceFactory { * * * @param customerId the customer id - * @param ordersIds the list of order IDs + * @param orderIds the list of order IDs * @return the generated invoice * @throws UserException if package used by the invoice can not or find more than 1 logistic * channel price, this exception will be thrown. */ @Transactional - public ShippingInvoice createShippingInvoice(String customerId, List ordersIds, String type, String start, String end) throws UserException { - log.info("Creating an invoice with arguments:\n client ID: {}, order IDs: {}]", customerId, ordersIds); + public ShippingInvoice createShippingInvoice(String customerId, List orderIds, String type, String start, String end) throws UserException { + log.info("Creating an invoice with arguments:\n client ID: {}, order IDs: {}]", customerId, orderIds); // find orders and their contents of the invoice - Map> uninvoicedOrderToContent = platformOrderService.fetchOrderData(ordersIds); + Map> uninvoicedOrderToContent = platformOrderService.fetchOrderData(orderIds); Set platformOrders = uninvoicedOrderToContent.keySet(); + List savRefunds = savRefundWithDetailService.findUnprocessedRefundsByClient(customerId); List shopIds = platformOrders.stream() .map(PlatformOrder::getShopId) .distinct() @@ -134,7 +135,7 @@ public class ShippingInvoiceFactory { subject = String.format("Shipping fees, order time from %s to %s", start, end); else throw new UserException("Couldn't create shipping invoice of unknown type."); - return createInvoice(customerId, shopIds, uninvoicedOrderToContent, null, subject, true); + return createInvoice(customerId, shopIds, uninvoicedOrderToContent, savRefunds, subject, true); } /** @@ -152,18 +153,19 @@ public class ShippingInvoiceFactory { * * @param username current username * @param customerId the customer id - * @param ordersIds the list of order IDs + * @param orderIds the list of order IDs * @param shippingMethod "post" = postShipping, "pre" = preShipping, "all" = all shipping methods * @return the generated invoice * @throws UserException if package used by the invoice can not or find more than 1 logistic * channel price, this exception will be thrown. */ @Transactional - public CompleteInvoice createCompleteShippingInvoice(String username, String customerId, List ordersIds, String shippingMethod, String start, String end) throws UserException { - log.info("Creating a complete invoice for \n client ID: {}, order IDs: {}]", customerId, ordersIds); + public CompleteInvoice createCompleteShippingInvoice(String username, String customerId, List orderIds, String shippingMethod, String start, String end) throws UserException { + log.info("Creating a complete invoice for \n client ID: {}, order IDs: {}]", customerId, orderIds); // find orders and their contents of the invoice - Map> uninvoicedOrderToContent = platformOrderService.fetchOrderData(ordersIds); + Map> uninvoicedOrderToContent = platformOrderService.fetchOrderData(orderIds); Set platformOrders = uninvoicedOrderToContent.keySet(); + List savRefunds = savRefundWithDetailService.findUnprocessedRefundsByClient(customerId); List shopIds = platformOrders.stream() .map(PlatformOrder::getShopId) .distinct() @@ -180,7 +182,7 @@ public class ShippingInvoiceFactory { subject = String.format("Purchase and Shipping fees, order time from %s to %s", start, end); else throw new UserException("Couldn't create complete invoice for unknown shipping method"); - return createInvoice(username, customerId, shopIds, uninvoicedOrderToContent, subject); + return createInvoice(username, customerId, shopIds, uninvoicedOrderToContent, savRefunds, subject); } @@ -200,6 +202,7 @@ public class ShippingInvoiceFactory { * @param username Current username * @param customerId Customer ID * @param shopIds Shop IDs + * @param savRefunds List of SAV refunds * @param subject Invoice subject * @return the generated invoice * @throws UserException if package used by the invoice can not or find more than 1 logistic @@ -208,7 +211,7 @@ public class ShippingInvoiceFactory { @Transactional public CompleteInvoice createInvoice(String username, String customerId, List shopIds, Map> orderAndContent, - String subject) throws UserException { + List savRefunds, String subject) throws UserException { Client client = clientMapper.selectById(customerId); log.info("User {} is creating a complete invoice for customer {}", username, client.getInternalCode()); @@ -243,10 +246,13 @@ public class ShippingInvoiceFactory { List purchaseOrderSkuList = purchaseOrderContentMapper.selectInvoiceDataByID(purchaseID); List promotionDetails = skuPromotionHistoryMapper.selectPromotionByPurchase(purchaseID); + if (savRefunds != null) { + updateSavRefundsInDb(savRefunds, invoiceCode); + } updateOrdersAndContentsInDb(orderAndContent); - return new CompleteInvoice(client, invoiceCode, subject, orderAndContent, + return new CompleteInvoice(client, invoiceCode, subject, orderAndContent, savRefunds, purchaseOrderSkuList, promotionDetails, eurToUsd); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/OrderContentDetail.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/OrderContentDetail.java index 74dca9f9a..783a70c40 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/OrderContentDetail.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/OrderContentDetail.java @@ -8,7 +8,7 @@ import java.math.BigDecimal; /** - * This class describe the relation among a sku identified by its id, its quantity, + * This class describes the relation among a sku identified by its id, its quantity, * and its correspondent price and promotion. */ @Data @@ -19,6 +19,8 @@ public class OrderContentDetail { private final Integer quantity; + private final BigDecimal exchangeRate; + /** * Calculate the reduced amount by applying the promotion to the sku. * @@ -35,7 +37,7 @@ public class OrderContentDetail { * @return the total price (price * quantity) */ public BigDecimal totalPrice() { - BigDecimal unit = skuDetail.getPrice().getPrice(quantity); + BigDecimal unit = skuDetail.getPrice().getPrice(quantity, exchangeRate); BigDecimal total = unit.multiply(new BigDecimal(quantity)); log.info("unit: {}", unit); log.info("total: {}", total); @@ -43,7 +45,7 @@ public class OrderContentDetail { } public BigDecimal unitPrice(){ - return skuDetail.getPrice().getPrice(quantity); + return skuDetail.getPrice().getPrice(quantity, exchangeRate); } public int promotionCount() { diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/SavRefundWithDetail.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/SavRefundWithDetail.java index dfb271d07..e135e1a72 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/SavRefundWithDetail.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/SavRefundWithDetail.java @@ -21,7 +21,7 @@ import java.util.Date; * @Description: 售后退款 * @Author: jeecg-boot * @Date: 2022-08-19 - * @Version: V1.2 + * @Version: V1.3 */ @Data @TableName("sav_refund_with_detail") @@ -116,10 +116,18 @@ public class SavRefundWithDetail implements Serializable { * 店铺代码 */ private String erpCode; + /** + * 店铺名称 + */ + private String shopName; /** * 订单交易号 */ private String platformOrderNumber; + /** + * 订单序列号 + */ + private String mabangId; /** * 挂号费 */ diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/SkuPrice.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/SkuPrice.java index 4a9a3eb96..55afc3e63 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/SkuPrice.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/SkuPrice.java @@ -13,13 +13,14 @@ import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.Date; /** - * @Description: The price of a sku + * @Description: SKU价格表 * @Author: jeecg-boot - * @Date: 2021-04-16 - * @Version: V1.0 + * @Date: 2023-05-10 + * @Version: V1.1 */ @ApiModel(value = "sku对象", description = "SKU表") @Setter @@ -30,21 +31,36 @@ public class SkuPrice implements Serializable { private static final long serialVersionUID = 1L; /** - * id in the DB + * 主键 */ @TableId(type = IdType.ASSIGN_ID) @ApiModelProperty(value = "主键") @Getter private String id; + /** + * 创建人 + */ + @ApiModelProperty(value = "创建人") + private java.lang.String createBy; + /** + * 创建日期 + */ + @JsonFormat(timezone = "GMT+2", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "创建日期") + private java.util.Date createTime; + /** + * 更新人 + */ + @ApiModelProperty(value = "更新人") + private java.lang.String updateBy; /** * SKU ID */ @Dict(dictTable = "sku", dicText = "erp_code", dicCode = "id") @ApiModelProperty(value = "SKU ID") - @Getter private String skuId; - /** * 价格 */ @@ -60,59 +76,57 @@ public class SkuPrice implements Serializable { @ApiModelProperty(value = "优惠价起订量") @Getter private Integer threshold; - /** - * 优惠价, maybe null from DB which stands for no discount price + * 优惠价 */ @Excel(name = "优惠价", width = 15) @ApiModelProperty(value = "优惠价") @Getter - private BigDecimal discountedPrice; - + private java.math.BigDecimal discountedPrice; /** * 生效日期 */ @Excel(name = "生效日期", width = 15, format = "yyyy-MM-dd") - @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd") + @JsonFormat(timezone = "GMT+2", pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd") @ApiModelProperty(value = "生效日期") - @Getter private Date date; - - /**创建人*/ - @ApiModelProperty(value = "创建人") - private String createBy; - - /**创建日期*/ - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") - @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") - @ApiModelProperty(value = "创建日期") - private Date createTime; - - /**更新日期*/ - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") - @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") - @ApiModelProperty(value = "更新日期") - private Date updateTime; - - /**更新人*/ - @ApiModelProperty(value = "更新人") - private String updateBy; + /** + * 人民币价格 + */ + @Excel(name = "人民币价格", width = 15) + @ApiModelProperty(value = "人民币价格") + @Getter + private java.math.BigDecimal priceRmb; + /** + * 人民币优惠价 + */ + @Excel(name = "人民币优惠价", width = 15) + @ApiModelProperty(value = "人民币优惠价") + @Getter + private java.math.BigDecimal discountedPriceRmb; /** * The price of a sku depends on its quantity, Given a quantity here, return the correspondent price. * * @param quantity a quantity + * @param eurToRmb Exchange rate from EUR to RMB * @return the price correspondent to the quantity */ - public BigDecimal getPrice(int quantity) { - if (quantity >= threshold) { - return discountedPrice == null ? price : discountedPrice; + public BigDecimal getPrice(int quantity, BigDecimal eurToRmb) { + BigDecimal priceCandidate = price; + BigDecimal discountedPriceCandidate = discountedPrice == null ? price : discountedPrice; + if (priceRmb != null) { + priceCandidate = priceRmb.divide(eurToRmb, RoundingMode.HALF_UP); + discountedPriceCandidate = discountedPriceRmb == null ? priceCandidate : discountedPriceRmb.divide(eurToRmb, RoundingMode.HALF_UP); } - return price; + if (quantity >= threshold) { + return discountedPriceCandidate; + } + return priceCandidate; } public String toString() { - return String.format("%s, %s[%d]", price, discountedPrice, threshold); + return String.format("%s, %s[%d], %s(RMB), %s[%d](RMB)", price, discountedPrice, threshold, priceRmb, discountedPriceRmb, threshold); } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/SavRefundWithDetailMapper.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/SavRefundWithDetailMapper.java index 1bc4a4033..cccdbf203 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/SavRefundWithDetailMapper.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/SavRefundWithDetailMapper.java @@ -18,4 +18,5 @@ import java.util.List; public interface SavRefundWithDetailMapper extends BaseMapper { List findUnprocessedRefundsByClient(@Param("clientId") String clientId); List fetchRefundsWhere(@Param("shop") String shop, @Param("orderID") String orderID, @Param("column") String column, @Param("order") String order); + List getRefundsByInvoiceNumber(@Param("invoiceNumber") String invoiceNumber); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/PlatformOrderContentMapper.xml b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/PlatformOrderContentMapper.xml index 143bb48c4..d6b4fc0ef 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/PlatformOrderContentMapper.xml +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/PlatformOrderContentMapper.xml @@ -96,6 +96,8 @@ + + diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/SavRefundWithDetailMapper.xml b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/SavRefundWithDetailMapper.xml index 681018a9b..863efcb2b 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/SavRefundWithDetailMapper.xml +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/SavRefundWithDetailMapper.xml @@ -8,6 +8,7 @@ JOIN platform_order po ON sr.platform_order_id = po.id JOIN shop s ON po.shop_id = s.id WHERE invoice_number IS NULL + AND sr.fret_fee IS NOT NULL AND s.owner_id = #{clientId} + + \ No newline at end of file diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/ISavRefundWithDetailService.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/ISavRefundWithDetailService.java index e29a9e8e1..153b2f9d3 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/ISavRefundWithDetailService.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/ISavRefundWithDetailService.java @@ -14,4 +14,5 @@ import java.util.List; public interface ISavRefundWithDetailService extends IService { List findUnprocessedRefundsByClient(String clientId); List fetchRefundsWhere(String shop, String orderID, String column, String order); + List getRefundsByInvoiceNumber(String invoiceNumber); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java index 18878d0ec..3e788e6b6 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java @@ -9,6 +9,7 @@ import org.jeecg.modules.business.domain.shippingInvoice.CompleteInvoice; import org.jeecg.modules.business.domain.shippingInvoice.ShippingInvoice; import org.jeecg.modules.business.domain.shippingInvoice.ShippingInvoiceFactory; import org.jeecg.modules.business.entity.PlatformOrder; +import org.jeecg.modules.business.entity.SavRefundWithDetail; import org.jeecg.modules.business.mapper.*; import org.jeecg.modules.business.vo.*; import org.jetbrains.annotations.NotNull; @@ -23,6 +24,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.text.ParseException; +import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; @@ -85,7 +87,7 @@ public class PlatformOrderShippingInvoiceService { @Value("${jeecg.path.shippingInvoiceDetailDir}") private String INVOICE_DETAIL_DIR; - private final static String[] titles = { + private final static String[] DETAILS_TITLES = { "Boutique", "N° de Mabang", "N° de commande", @@ -107,6 +109,16 @@ public class PlatformOrderShippingInvoiceService { "TVA", "N° de facture" }; + private final static String[] SAV_TITLES = { + "Boutique", + "N° de Mabang", + "N° de commande", + "Date du remboursement", + "Montant d'achat remboursé", + "Montant de livraison remboursé", + "Montant total du remboursement", + "N° de facture" + }; public Period getValidPeriod(List shopIDs) { Date begin = platformOrderMapper.findEarliestUninvoicedPlatformOrder(shopIDs); @@ -318,9 +330,10 @@ public class PlatformOrderShippingInvoiceService { return factureDetailMapper.selectList(queryWrapper); } - public byte[] exportToExcel(List details, String invoiceNumber, String invoiceEntity) throws IOException { + public byte[] exportToExcel(List details, List refunds, String invoiceNumber, String invoiceEntity) throws IOException { SheetManager sheetManager = SheetManager.createXLSX(); - for (String title : titles) { + sheetManager.startDetailsSheet(); + for (String title : DETAILS_TITLES) { sheetManager.write(title); sheetManager.nextCol(); } @@ -370,6 +383,37 @@ public class PlatformOrderShippingInvoiceService { sheetManager.moveCol(0); sheetManager.nextRow(); } + sheetManager.startSavSheet(); + for (String title : SAV_TITLES) { + sheetManager.write(title); + sheetManager.nextCol(); + } + sheetManager.moveCol(0); + sheetManager.nextRow(); + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + for (SavRefundWithDetail refund : refunds) { + sheetManager.write(refund.getShopName()); + sheetManager.nextCol(); + sheetManager.write(refund.getMabangId()); + sheetManager.nextCol(); + sheetManager.write(refund.getPlatformOrderNumber()); + sheetManager.nextCol(); + sheetManager.write(sdf.format(refund.getRefundDate())); + sheetManager.nextCol(); + sheetManager.write(refund.getPurchaseRefundAmount()); + sheetManager.nextCol(); + sheetManager.write(refund.getShippingFee() + .add(refund.getFretFee()) + .add(refund.getVat()) + .add(refund.getServiceFee())); + sheetManager.nextCol(); + sheetManager.write(refund.getTotalRefundAmount()); + sheetManager.nextCol(); + sheetManager.write(refund.getInvoiceNumber()); + sheetManager.moveCol(0); + sheetManager.nextRow(); + } Path target = Paths.get(INVOICE_DETAIL_DIR, "Détail_calcul_de_facture_" + invoiceNumber + "_(" + invoiceEntity + ").xlsx"); int i = 2; diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/PlatformOrderServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/PlatformOrderServiceImpl.java index 38b9c84e3..a8557c91d 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/PlatformOrderServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/PlatformOrderServiceImpl.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; import lombok.extern.slf4j.Slf4j; import org.jeecg.modules.business.entity.*; +import org.jeecg.modules.business.mapper.ExchangeRatesMapper; import org.jeecg.modules.business.mapper.PlatformOrderContentMapper; import org.jeecg.modules.business.mapper.PlatformOrderMapper; import org.jeecg.modules.business.service.IClientService; @@ -24,6 +25,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.Serializable; +import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; @@ -48,14 +50,17 @@ public class PlatformOrderServiceImpl extends ServiceImpl searchPurchaseOrderDetail(List skuQuantities) { + BigDecimal eurToRmb = exchangeRatesMapper.getLatestExchangeRate("EUR", "RMB"); // convert list of (ID, quantity) to map between ID and quantity Map skuQuantity = skuQuantities.stream() @@ -234,7 +240,8 @@ public class PlatformOrderServiceImpl extends ServiceImpl new OrderContentDetail( skuDetail, - skuQuantity.get(skuDetail.getSkuId()) + skuQuantity.get(skuDetail.getSkuId()), + eurToRmb ) ) .collect(toList()); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/SavRefundWithDetailServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/SavRefundWithDetailServiceImpl.java index c49232be1..48cc6d8bf 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/SavRefundWithDetailServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/SavRefundWithDetailServiceImpl.java @@ -31,4 +31,9 @@ public class SavRefundWithDetailServiceImpl extends ServiceImpl fetchRefundsWhere(String shop, String orderID, String column, String order) { return savRefundMapper.fetchRefundsWhere(shop, orderID, column, order); } + + @Override + public List getRefundsByInvoiceNumber(String invoiceNumber) { + return savRefundMapper.getRefundsByInvoiceNumber(invoiceNumber); + } }