1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-26 20:54:21 +01:00

rename order amount to total

This commit is contained in:
Du Peng 2022-08-26 10:46:30 +02:00
parent 885db68b51
commit 97ee15cf78
18 changed files with 23 additions and 48 deletions

View File

@ -9,9 +9,7 @@ class API::CartController < API::ApiController
def create
authorize :cart, :create?
p '-----------------'
p current_user
@order = Order.find_by(token: order_token)
@order = Order.find_by(token: order_token, state: 'cart')
if @order.nil?
if current_user&.member?
@order = Order.where(statistic_profile_id: current_user.statistic_profile.id,

View File

@ -9,7 +9,7 @@ module API::OrderConcern
end
def current_order
@current_order = Order.find_by(token: order_token)
@current_order = Order.find_by(token: order_token, state: 'cart')
end
def ensure_order

View File

@ -72,8 +72,8 @@ const StoreCart: React.FC<StoreCartProps> = ({ onError, currentUser }) => {
* Open/closes the payment modal
*/
const handlePaymentSuccess = (data: Order): void => {
console.log(data);
setPaymentModal(false);
window.location.href = '/#!/store';
};
/**
@ -118,8 +118,8 @@ const StoreCart: React.FC<StoreCartProps> = ({ onError, currentUser }) => {
</FabButton>
</div>
))}
{cart && !cartIsEmpty() && <CouponInput user={cart.user} amount={cart.amount} />}
{cart && !cartIsEmpty() && <p>Totale: {FormatLib.price(cart.amount)}</p>}
{cart && !cartIsEmpty() && <CouponInput user={cart.user} amount={cart.total} />}
{cart && !cartIsEmpty() && <p>Totale: {FormatLib.price(cart.total)}</p>}
{cart && !cartIsEmpty() && isPrivileged() && <MemberSelect defaultUser={cart.user} onSelected={handleChangeMember} />}
{cart && !cartIsEmpty() &&
<FabButton className="checkout-btn" onClick={checkout} disabled={!cart.user || cart.order_items_attributes.length === 0}>

View File

@ -114,7 +114,7 @@ export const AbstractPaymentModal: React.FC<AbstractPaymentModalProps> = ({ isOp
if (order && order?.user?.id) {
WalletAPI.getByUser(order.user.id).then((wallet) => {
setWallet(wallet);
const p = { price: order.amount, price_without_coupon: order.amount };
const p = { price: order.total, price_without_coupon: order.total };
setPrice(p);
setRemainingPrice(new WalletLib(wallet).computeRemainingPrice(p.price));
setReady(true);

View File

@ -47,7 +47,7 @@ export const PaymentModal: React.FC<PaymentModalProps> = ({ isOpen, toggleModal,
// refresh the price when the cart changes
useEffect(() => {
if (order) {
setPrice({ price: order.amount, price_without_coupon: order.amount });
setPrice({ price: order.total, price_without_coupon: order.total });
} else {
PriceAPI.compute(cart).then(price => {
setPrice(price);

View File

@ -48,7 +48,6 @@ export const StripeForm: React.FC<GatewayFormProps> = ({ onSubmit, onSuccess, on
if (res.payment) {
await handleServerConfirmation(res.payment as PaymentConfirmation);
} else {
res.order.total = res.order.amount;
await handleServerConfirmation(res.order);
}
} else {
@ -92,7 +91,6 @@ export const StripeForm: React.FC<GatewayFormProps> = ({ onSubmit, onSuccess, on
try {
if (order) {
const confirmation = await CheckoutAPI.confirmPayment(order.token, result.paymentIntent.id);
confirmation.order.total = confirmation.order.amount;
await handleServerConfirmation(confirmation.order);
} else {
const confirmation = await StripeAPI.confirmIntent(result.paymentIntent.id, cart);

View File

@ -11,7 +11,6 @@ export interface Order {
operator_id?: number,
reference?: string,
state?: string,
amount?: number,
total?: number,
created_at?: TDateISO,
order_items_attributes: Array<{

View File

@ -15,7 +15,7 @@ class Cart::AddItemService
else
item.quantity += quantity.to_i
end
order.amount += (orderable.amount * quantity.to_i)
order.total += (orderable.amount * quantity.to_i)
ActiveRecord::Base.transaction do
item.save
order.save

View File

@ -7,7 +7,7 @@ class Cart::CreateService
order_param = {
token: token,
state: 'cart',
amount: 0
total: 0
}
if user
order_param[:statistic_profile_id] = user.statistic_profile.id if user.member?

View File

@ -7,7 +7,7 @@ class Cart::RemoveItemService
raise ActiveRecord::RecordNotFound if item.nil?
order.amount -= (item.amount * item.quantity.to_i)
order.total -= (item.amount * item.quantity.to_i)
ActiveRecord::Base.transaction do
item.destroy!
order.save

View File

@ -12,7 +12,7 @@ class Cart::SetQuantityService
raise ActiveRecord::RecordNotFound if item.nil?
different_quantity = quantity.to_i - item.quantity
order.amount += (orderable.amount * different_quantity)
order.total += (orderable.amount * different_quantity)
ActiveRecord::Base.transaction do
item.update(quantity: quantity.to_i)
order.save

View File

@ -8,7 +8,7 @@ class Checkout::PaymentService
def payment(order, operator, payment_id = '')
raise Cart::OutStockError unless Orders::OrderService.new.in_stock?(order, 'external')
raise Cart::InactiveProductError unless Orders::OrderService.new.all_products_is_active?
raise Cart::InactiveProductError unless Orders::OrderService.new.all_products_is_active?(order)
if operator.member?
if Stripe::Helper.enabled?

View File

@ -1,23 +0,0 @@
# frozen_string_literal: true
# Provides methods for Check if the product is in stock
class Cart::SetQuantityService
def call(order)
return order if quantity.to_i.zero?
raise Cart::OutStockError if quantity.to_i > orderable.stock['external']
item = order.order_items.find_by(orderable: orderable)
raise ActiveRecord::RecordNotFound if item.nil?
different_quantity = quantity.to_i - item.quantity
order.amount += (orderable.amount * different_quantity)
ActiveRecord::Base.transaction do
item.update(quantity: quantity.to_i)
order.save
end
order.reload
end
end

View File

@ -10,7 +10,7 @@ module Payments::PaymentConcern
end
def debit_amount(order)
total = order.amount
total = order.total
wallet_debit = get_wallet_debit(order.statistic_profile.user, total)
total - wallet_debit
end

View File

@ -75,15 +75,13 @@ class WalletService
##
# Compute the amount decreased from the user's wallet, if applicable
# @param payment {Invoice|PaymentSchedule}
# @param payment {Invoice|PaymentSchedule|Order}
# @param user {User} the customer
# @param coupon {Coupon|String} Coupon object or code
##
def self.wallet_amount_debit(payment, user, coupon = nil)
total = if payment.is_a? PaymentSchedule
payment.payment_schedule_items.first.amount
elsif payment.is_a? Order
payment.amount
else
payment.total
end
@ -95,7 +93,7 @@ class WalletService
end
##
# Subtract the amount of the payment document (Invoice|PaymentSchedule) from the customer's wallet
# Subtract the amount of the payment document (Invoice|PaymentSchedule|Order) from the customer's wallet
# @param transaction, if false: the wallet is not debited, the transaction is only simulated on the payment document
##
def self.debit_user_wallet(payment, user, transaction: true)

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
json.extract! order, :id, :token, :statistic_profile_id, :operator_id, :reference, :state, :created_at
json.amount order.amount / 100.0 if order.amount.present?
json.total order.total / 100.0 if order.total.present?
if order&.statistic_profile&.user
json.user do
json.id order.statistic_profile.user.id

View File

@ -0,0 +1,5 @@
class RenameAmountToTotalInOrder < ActiveRecord::Migration[5.2]
def change
rename_column :orders, :amount, :total
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_08_22_081222) do
ActiveRecord::Schema.define(version: 2022_08_26_074619) do
# These are extensions that must be enabled in order to support this database
enable_extension "fuzzystrmatch"
@ -464,7 +464,7 @@ ActiveRecord::Schema.define(version: 2022_08_22_081222) do
t.string "token"
t.string "reference"
t.string "state"
t.integer "amount"
t.integer "total"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "payment_state"