PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.1
1.7.1 1.7.0 1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 All 51 releases
← All changes | app/Services/Renderer/Receipt/ReceiptRenderer.php +110 -121 1.5.2 → 1.7.1 View file →
@@ -8,8 +8,9 @@
8 8 use FluentCart\Api\StoreSettings;
9 9 use FluentCart\App\Helpers\AddressHelper;
10 10 use FluentCart\App\Modules\Tax\TaxModule;
11 11 use FluentCart\App\Services\DateTime\DateTime;
12 +use FluentCart\App\Services\DateTime\DateFormatter;
12 13
13 14 class ReceiptRenderer
14 15 {
15 16 protected $config = null;
@@ -23,8 +24,10 @@
23 24 protected $vat_tax_id = null;
24 25
25 26 protected $orderTz;
26 27
28 + private $fctTaxSummaryCache = [];
29 +
27 30 public function __construct($config = [])
28 31 {
29 32 $this->config = $config;
30 33
@@ -35,8 +38,20 @@
35 38
36 39 $this->orderTz = Arr::get($this->config, 'user_tz', 'UTC');
37 40 }
38 41
42 + private function getMemoizedTaxSummary($order)
43 + {
44 + if (!$order) {
45 + return TaxSummaryHelper::computeTaxSummary($order);
46 + }
47 + $id = (int) $order->id;
48 + if (!isset($this->fctTaxSummaryCache[$id])) {
49 + $this->fctTaxSummaryCache[$id] = TaxSummaryHelper::computeTaxSummary($order);
50 + }
51 + return $this->fctTaxSummaryCache[$id];
52 + }
53 +
39 54 public function wrapperStart()
40 55 {
41 56 ?>
42 57 <div
@@ -228,12 +243,14 @@
228 243 <?php echo esc_html__('Order At', 'fluent-cart'); ?>
229 244 </p>
230 245 <p style="white-space: nowrap; font-weight: bold; color: #000; text-align: right; margin: 0;font-size:14px;">
231 246 <?php
232 - $date = wp_date(
233 - get_option('date_format'),
247 + // Through DateFormatter so the store's format and timezone settings
248 + // reach this too; orderTz is only consulted on the Browser source.
249 + $date = DateFormatter::format(
234 250 DateTime::anyTimeToGmt($order->created_at)->getTimestamp(),
235 - new \DateTimeZone($this->orderTz)
251 + false,
252 + $this->orderTz
236 253 );
237 254 echo esc_html(Helper::translateNumber($date));
238 255 ?>
239 256 </p>
@@ -495,8 +512,9 @@
495 512 <?php
496 513 $orderItems = $order->order_items->toArray();
497 514 $isReversed = $order->isReverseChargeTaxOrder();
498 515 $rcMode = $order->getOrderRcMode();
516 + $fctReceiptTaxDisplayMode = TaxSummaryHelper::getTaxDisplayMode();
499 517
500 518 foreach ($orderItems as $item) :
501 519 if (($item['payment_type'] ?? '') === 'fee') {
502 520 continue;
@@ -514,9 +532,9 @@
514 532 <?php endif; ?>
515 533 <?php if (!empty($item['payment_info'])) : ?>
516 534 <small style="font-size: 13px;color: #758195;"><?php echo esc_html($item['payment_info']); ?></small>
517 535 <?php endif; ?>
518 - <?php if (empty($itemRates) && !empty($item['tax_amount'])) : ?>
536 + <?php if ($fctReceiptTaxDisplayMode !== 'simplified' && empty($itemRates) && !empty($item['tax_amount'])) : ?>
519 537 <small style="font-size: 12px; color: #94a3b8; display:block; margin-top:2px;">
520 538 <?php
521 539 /* translators: %1$s: formatted tax amount */
522 540 echo esc_html(sprintf(__('Tax: %1$s', 'fluent-cart'), Helper::toDecimal((int) $item['tax_amount']))); ?>
@@ -538,9 +556,9 @@
538 556 <?php endif; ?>
539 557 <?php echo esc_html($item['formatted_total']); ?>
540 558 </td>
541 559 </tr>
542 - <?php if (!empty($itemRates)) : ?>
560 + <?php if ($fctReceiptTaxDisplayMode !== 'simplified' && !empty($itemRates)) : ?>
543 561 <tr>
544 562 <td colspan="4" style="padding:0 8px 8px 8px;border:none;border-bottom:1px solid #dee2e6;">
545 563 <?php echo $this->renderTaxRatePills($itemRates, $isReversed, $rcMode); ?>
546 564 </td>
@@ -647,17 +665,23 @@
647 665 return;
648 666 }
649 667 $displayShipping = (int) $order->shipping_total;
650 668 if ($order->isReverseChargeTaxOrder()) {
651 - $rcAdj = (int) Arr::get(\FluentCart\App\Services\Renderer\Receipt\TaxSummaryHelper::computeTaxSummary($order), 'rcShippingAdjustment', 0);
669 + $rcAdj = (int) Arr::get($this->getMemoizedTaxSummary($order), 'rcShippingAdjustment', 0);
652 670 if ($rcAdj > 0) {
653 671 $displayShipping = max(0, $displayShipping - $rcAdj);
654 672 }
655 673 }
674 + $shippingMethodTitle = (string) Arr::get($order->config, 'shipping_method_title', '');
656 675 ?>
657 676 <tr>
658 677 <td style="padding: 8px 20px 8px 0;text-align: right;border: none;">
659 678 <?php echo esc_html__('Shipping', 'fluent-cart'); ?>
679 + <?php if ($shippingMethodTitle): ?>
680 + <span style="display:block;font-size:12px;color:rgb(107,114,128);line-height:18px;">
681 + <?php echo esc_html($shippingMethodTitle); ?>
682 + </span>
683 + <?php endif; ?>
660 684 </td>
661 685 <td style="padding: 8px 8px 8px 0;width: 100px;text-align: right;border: none;">
662 686 <?php echo esc_html(\FluentCart\App\Helpers\Helper::toDecimal($displayShipping)); ?>
663 687 </td>
@@ -683,66 +707,8 @@
683 707 </tr>
684 708 <?php endforeach;
685 709 }
686 710
687 - public function renderTaxTotal()
688 - {
689 - $order = Arr::get($this->config, 'order', null);
690 -
691 - if ($order->isReverseChargeTaxOrder()): ?>
692 - <?php
693 - $rcReversedTotal = $order->getReversedTaxTotal();
694 - $rcChargeLabel = $rcReversedTotal > 0
695 - ? sprintf(
696 - /* translators: %1$s: formatted reversed tax amount */
697 - __('Tax reversed: %1$s', 'fluent-cart'),
698 - Helper::toDecimal($rcReversedTotal)
699 - )
700 - : __('Charge reversed', 'fluent-cart');
701 - ?>
702 - <tr>
703 - <td style="padding: 8px 20px 8px 0;text-align: right;border: none;">
704 - <?php echo esc_html__('Tax', 'fluent-cart'); ?>
705 - </td>
706 - <td style="padding: 8px 8px 8px 0;width: 100px;text-align: right;border: none;">
707 - <?php echo esc_html($rcChargeLabel); ?>
708 - </td>
709 - </tr>
710 - <?php elseif ($order->tax_total > 0): ?>
711 - <tr>
712 - <td style="padding: 8px 20px 8px 0;text-align: right;border: none;">
713 - <?php echo esc_html__('Tax', 'fluent-cart');
714 - echo esc_html(\FluentCart\App\Helpers\Helper::getOrderTaxLabel($order));
715 - ?>
716 - </td>
717 - <td style="padding: 8px 8px 8px 0;width: 100px;text-align: right;border: none;">
718 - <?php echo esc_html(\FluentCart\App\Helpers\Helper::toDecimal($order->tax_total)); ?>
719 - </td>
720 - </tr>
721 - <?php endif;
722 - }
723 -
724 - public function renderShippingTax()
725 - {
726 - $order = Arr::get($this->config, 'order', null);
727 -
728 - if ($order->shipping_tax <= 0) {
729 - return;
730 - }
731 - ?>
732 - <tr>
733 - <td style="padding: 8px 20px 8px 0;text-align: right;border: none;">
734 - <?php echo esc_html__('Shipping Tax', 'fluent-cart');
735 - echo esc_html(\FluentCart\App\Helpers\Helper::getOrderTaxLabel($order));
736 - ?>
737 - </td>
738 - <td style="padding: 8px 8px 8px 0;width: 100px;text-align: right;border: none;">
739 - <?php echo esc_html(\FluentCart\App\Helpers\Helper::toDecimal($order->shipping_tax)); ?>
740 - </td>
741 - </tr>
742 - <?php
743 - }
744 -
745 711 public function renderRefund()
746 712 {
747 713 $order = Arr::get($this->config, 'order', null);
748 714 if ($order->total_refund > 0): ?>
@@ -761,9 +727,9 @@
761 727 {
762 728 $order = Arr::get($this->config, 'order', null);
763 729 $displayTotal = (int) $order->total_amount - (int) $order->total_refund;
764 730 if ($order->isReverseChargeTaxOrder()) {
765 - $rcAdj = (int) Arr::get(\FluentCart\App\Services\Renderer\Receipt\TaxSummaryHelper::computeTaxSummary($order), 'rcTotalAdjustment', 0);
731 + $rcAdj = (int) Arr::get($this->getMemoizedTaxSummary($order), 'rcTotalAdjustment', 0);
766 732 if ($rcAdj > 0) {
767 733 $displayTotal = max(0, $displayTotal - $rcAdj);
768 734 }
769 735 }
@@ -799,9 +765,9 @@
799 765 $order = Arr::get($this->config, 'order', null);
800 766 if ($order->isReverseChargeTaxOrder()): ?>
801 767
802 768 <div style="text-align: right; font-size: 14px; margin-top: 10px;">
803 - <?php echo esc_html__('* Tax to be paid on reverse charge basis', 'fluent-cart'); ?>
769 + <?php echo '*' . esc_html(TaxModule::getReverseChargeNoticeText()); ?>
804 770 </div>
805 771
806 772 <?php endif;
807 773 }
@@ -846,12 +812,14 @@
846 812 <?php echo esc_html($transaction->getPaymentMethodText()); ?>
847 813 </td>
848 814 <td style="padding: 10px;border:none;border-bottom: 1px solid #dee2e6;text-align: center;">
849 815 <?php
850 - $date = wp_date(
851 - get_option('date_format'),
816 + // Same route as the Order At header above, or
817 + // one receipt renders two different formats.
818 + $date = DateFormatter::format(
852 819 DateTime::anyTimeToGmt($transaction->created_at)->getTimestamp(),
853 - new \DateTimeZone($this->orderTz)
820 + false,
821 + $this->orderTz
854 822 );
855 823 echo esc_html(Helper::translateNumber($date));
856 824 ?>
857 825 </td>
@@ -922,9 +890,9 @@
922 890
923 891 public function renderTaxSummaryBox()
924 892 {
925 893 $order = Arr::get($this->config, 'order', null);
926 - $summary = TaxSummaryHelper::computeTaxSummary($order);
894 + $summary = $this->getMemoizedTaxSummary($order);
927 895 if (!$summary['shouldRender']) {
928 896 return;
929 897 }
930 898 ?>
@@ -933,63 +901,41 @@
933 901 <table width="100%" cellpadding="0" cellspacing="0" style="border:1px solid #e2e8f0; border-radius:6px; border-collapse:separate; background:#ffffff; -webkit-print-color-adjust:exact; print-color-adjust:exact;">
934 902 <tr>
935 903 <td style="padding:6px 8px 6px 0;">
936 904 <table width="100%" cellpadding="0" cellspacing="0" style="border:none;border-collapse:collapse;">
905 + <?php if (($summary['displayMode'] ?? '') === 'simplified' && !empty($summary['simpleLine'])): ?>
937 906 <tr>
907 + <td style="padding:4px 0 3px 8px; font-size:11px; font-weight:600; color:#1e293b; text-align:left;">
908 + <?php echo esc_html($summary['simpleLine']['label']); ?>
909 + </td>
910 + <td style="padding:4px 0 3px; font-size:11px; font-weight:600; color:#1e293b; text-align:right;">
911 + <?php echo esc_html($summary['simpleLine']['value']); ?>
912 + </td>
913 + </tr>
914 + <?php endif; ?>
915 + <?php if (($summary['displayMode'] ?? '') !== 'simplified'): ?>
916 + <tr>
938 917 <td colspan="2" style="padding:0 0 3px 0; font-size:10px; font-weight:600;
939 918 text-transform:uppercase; letter-spacing:0.06em; color:#64748b;">
940 - <?php echo esc_html__('TAX SUMMARY', 'fluent-cart'); ?>
919 + <?php if (!empty(Arr::get($summary, 'foldedRateLines', []))): ?>
920 + <?php echo esc_html__('Tax breakdown by rate', 'fluent-cart'); ?>
921 + <?php else: ?>
922 + <?php echo esc_html__('TAX SUMMARY', 'fluent-cart'); ?>
923 + <?php endif; ?>
941 924 </td>
942 925 </tr>
943 - <?php if ($summary['isReverseCharge']): ?>
944 - <?php
945 - $rcReversedTotal = (int) Arr::get($summary, 'reversedTaxTotal', 0);
946 - $rcReversedShipping = (int) Arr::get($summary, 'reversedShippingTax', 0);
947 - $rcReversedValue = $rcReversedTotal > 0
948 - ? Helper::toDecimal($rcReversedTotal)
949 - : __('Charge reversed', 'fluent-cart');
950 - ?>
951 - <?php if ($summary['showRcShippingRow'] && $rcReversedShipping > 0): ?>
952 - <tr>
953 - <td style="padding:3px 0 3px 8px; font-size:11px; color:#94a3b8;">
954 - <?php echo esc_html__('Added on shipping', 'fluent-cart'); ?>
955 - </td>
956 - <td style="padding:3px 0 3px; font-size:11px; text-align:right; color:#94a3b8;">
957 - <span style="text-decoration:line-through;opacity:0.6;"><?php echo esc_html(Helper::toDecimal($rcReversedShipping)); ?></span>
958 - </td>
959 - </tr>
960 - <?php endif; ?>
961 - <tr>
962 - <td style="padding:3px 0 4px 8px; font-size:11px; font-weight:600; color:#1e293b; text-align: left;">
963 - <?php echo esc_html__('Tax reversed', 'fluent-cart'); ?>
964 - </td>
965 - <td style="padding:3px 0 4px; font-size:11px; text-align:right; font-weight:600; color:#1e293b;">
966 - <?php echo esc_html($rcReversedValue); ?>
967 - </td>
968 - </tr>
969 - <?php else: ?>
970 - <?php
971 - $foldedRateLines = Arr::get($summary, 'foldedRateLines', []);
972 - $includedInPrices = (int) Arr::get($summary, 'includedInPrices', 0);
973 - $rcFeeRows = Arr::get($summary, 'feeTaxLineRows', []);
974 - $taxRateLines = Arr::get($summary, 'taxRateLines', []);
975 - $productTaxRowCount = !empty($taxRateLines)
976 - ? count($taxRateLines)
977 - : (int) ($summary['inclusiveTax'] > 0) + (int) ($summary['exclusiveTax'] > 0);
978 - $rowCount = $productTaxRowCount + count($rcFeeRows) + (int) ($summary['shippingTax'] > 0);
979 - $shippingTaxLines = Arr::get($summary, 'shippingTaxLines', []);
980 - $shouldShowBreakdown = !empty($taxRateLines)
981 - || !empty($shippingTaxLines)
982 - || $rowCount >= 2
983 - || ($rowCount === 1 && !($summary['payableTax'] > 0 || $summary['inclusiveTax'] > 0 || (int) Arr::get($summary, 'inclusiveFeeTax', 0) > 0));
984 - ?>
985 - <?php if (!empty($foldedRateLines)): ?>
926 + <?php
927 + $foldedRateLines = Arr::get($summary, 'foldedRateLines', []);
928 + $rcIsReverseCharge = !empty($summary['isReverseCharge']);
929 + $rcReversedTotal = (int) Arr::get($summary, 'reversedTaxTotal', 0);
930 + $rcReversedShipping = (int) Arr::get($summary, 'reversedShippingTax', 0);
931 + $rcReversedValue = $rcReversedTotal > 0
932 + ? Helper::toDecimal($rcReversedTotal)
933 + : __('Charge reversed', 'fluent-cart');
934 + $includedInPrices = (int) Arr::get($summary, 'includedInPrices', 0);
935 + ?>
936 + <?php if (!empty($foldedRateLines)): ?>
986 937 <tr>
987 - <td colspan="2" style="padding:5px 0 2px 8px; font-size:10px; font-weight:600; text-transform:uppercase; letter-spacing:0.06em; color:#64748b;">
988 - <?php echo esc_html__('Tax breakdown by rate', 'fluent-cart'); ?>
989 - </td>
990 - </tr>
991 - <tr>
992 938 <td colspan="2" style="padding:2px 0 0 0;">
993 939 <table width="100%" cellpadding="0" cellspacing="0" style="border:none;border-collapse:collapse;table-layout:fixed;">
994 940 <tr>
995 941 <td style="width:58%;padding:3px 8px 3px 8px; font-size:10px; font-weight:600; text-transform:uppercase; letter-spacing:0.06em; color:#64748b; vertical-align:top;">
@@ -1018,9 +964,19 @@
1018 964 <?php endforeach; ?>
1019 965 </table>
1020 966 </td>
1021 967 </tr>
968 + <?php if ($rcIsReverseCharge): ?>
1022 969 <tr>
970 + <td style="padding:3px 0 4px 8px; font-size:11px; font-weight:600; color:#1e293b; text-align: left;">
971 + <?php echo esc_html__('VAT reversed', 'fluent-cart'); ?>
972 + </td>
973 + <td style="padding:3px 0 4px; font-size:11px; text-align:right; font-weight:600; color:#1e293b;">
974 + <?php echo esc_html($rcReversedValue); ?>
975 + </td>
976 + </tr>
977 + <?php else: ?>
978 + <tr>
1023 979 <td style="padding:4px 0 3px 8px; font-size:11px; font-weight:600; color:#1e293b; border-top:1px solid #e2e8f0; text-align:left;">
1024 980 <?php echo esc_html__('Total tax', 'fluent-cart'); ?>
1025 981 </td>
1026 982 <td style="padding:4px 0 3px; font-size:11px; font-weight:600; color:#1e293b; border-top:1px solid #e2e8f0; text-align:right;">
@@ -1046,9 +1002,42 @@
1046 1002 <?php echo esc_html(Helper::toDecimal((int) $summary['payableTax'])); ?>
1047 1003 </td>
1048 1004 </tr>
1049 1005 <?php endif; ?>
1050 - <?php else: ?>
1006 + <?php endif; ?>
1007 + <?php elseif ($rcIsReverseCharge): ?>
1008 + <?php if ($summary['showRcShippingRow'] && $rcReversedShipping > 0): ?>
1009 + <tr>
1010 + <td style="padding:3px 0 3px 8px; font-size:11px; color:#94a3b8;">
1011 + <?php echo esc_html__('Added on shipping', 'fluent-cart'); ?>
1012 + </td>
1013 + <td style="padding:3px 0 3px; font-size:11px; text-align:right; color:#94a3b8;">
1014 + <span style="text-decoration:line-through;opacity:0.6;"><?php echo esc_html(Helper::toDecimal($rcReversedShipping)); ?></span>
1015 + </td>
1016 + </tr>
1017 + <?php endif; ?>
1018 + <tr>
1019 + <td style="padding:3px 0 4px 8px; font-size:11px; font-weight:600; color:#1e293b; text-align: left;">
1020 + <?php echo esc_html__('Tax reversed', 'fluent-cart'); ?>
1021 + </td>
1022 + <td style="padding:3px 0 4px; font-size:11px; text-align:right; font-weight:600; color:#1e293b;">
1023 + <?php echo esc_html($rcReversedValue); ?>
1024 + </td>
1025 + </tr>
1026 + <?php else: ?>
1027 + <?php
1028 + $rcFeeRows = Arr::get($summary, 'feeTaxLineRows', []);
1029 + $taxRateLines = Arr::get($summary, 'taxRateLines', []);
1030 + $productTaxRowCount = !empty($taxRateLines)
1031 + ? count($taxRateLines)
1032 + : (int) ($summary['inclusiveTax'] > 0) + (int) ($summary['exclusiveTax'] > 0);
1033 + $rowCount = $productTaxRowCount + count($rcFeeRows) + (int) ($summary['shippingTax'] > 0);
1034 + $shippingTaxLines = Arr::get($summary, 'shippingTaxLines', []);
1035 + $shouldShowBreakdown = !empty($taxRateLines)
1036 + || !empty($shippingTaxLines)
1037 + || $rowCount >= 2
1038 + || ($rowCount === 1 && !($summary['payableTax'] > 0 || $summary['inclusiveTax'] > 0 || (int) Arr::get($summary, 'inclusiveFeeTax', 0) > 0));
1039 + ?>
1051 1040 <?php if (!empty($taxRateLines) && $shouldShowBreakdown): ?>
1052 1041 <?php foreach ($taxRateLines as $taxLine):
1053 1042 $taxLineColor = !empty($taxLine['inclusive']) ? '#94a3b8' : '#334155'; ?>
1054 1043 <tr>
@@ -1140,9 +1129,9 @@
1140 1129 <?php echo esc_html(Helper::toDecimal($summary['totalOrderTax'])); ?>
1141 1130 </td>
1142 1131 </tr>
1143 1132 <?php endif; ?>
1144 - <?php endif; ?>
1133 + <?php endif; ?>
1145 1134 <?php endif; ?>
1146 1135 </table>
1147 1136 </td>
1148 1137 </tr>