Enhanced Ecommerce Product Price, Shipping and TAX - enhanced-ecommerce

I don't understand which value of product price and value of tax is right.
I have product
ga('ec:addProduct', { // Provide product details in an productFieldObject.
'id': 'P12345', // Product ID (string).
'name': 'Android Warhol T-Shirt', // Product name (string).
'category': 'Apparel', // Product category (string).
'brand': 'Google', // Product brand (string).
'variant': 'black', // Product variant (string).
'price': '29.20', // Product price (currency).
=> Product price without tax????
'coupon': 'APPARELSALE', // Product coupon (string).
'quantity': 1 // Product quantity (number).
});
Q.: The Product price is price with tax or not?
I have shipping (1.48 without tax and 1.8 with tax)
ga('ec:setAction', 'purchase', { // Transaction details are provided in an actionFieldObject.
'id': 'T12345', // (Required) Transaction id (string).
'affiliation': 'Google Store - Online', // Affiliation (string).
'revenue': '33.85', // Revenue (currency).
'tax': '2.85', // Tax (currency).
=> Tax is total tax of products tax and shipping tax (or payment tax if I have) or not?
'shipping': '1.8', // Shipping (currency).
=> Shipping price is price with tax or not?
'coupon': 'SUMMER2013' // Transaction coupon (string).
});
Q.: Tax is total tax of products tax and shipping tax (or payment tax if I have) or not?
Q.: Shipping price is price with tax or not?
Thanks
Rudolf

the numbers in the documentation (https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#transaction) suggest that the 'ec:addProduct' items are net. The revenue in the purchase action seems to include tax and shipping.
It's unclear if the shipping is net (but if it's consistent, it's net and shipping tax is included in the total tax).
Also unclear if the 'ec:addProduct' item prices are per item or total given the quantity. But most likely it is the total (qty 2, item price 10$ => price in tracking is 20$).
I get a sense that GA leaves it to the company using the tracking to choose what counts as revenue - but hell, a recommendation would be nice so 3rd party vendors have some commonly agreed upon practice.

Related

discount entity for ERD- onine shopping

I'm currently making an ER diagram for my product model. But I'm confused that the DISCOUNT needs an entity to connect with the product module or it can just be an attributes of the product?
my current product module:
the
PRODUCT
PRODUCT_ID(PK)
PRODUCT_NAME
PRODUCT_PRICE
PRODUCT_TYPE
PRODUCT_COLOUR
PRODUCT_SIZE
STOCK_UNIT (FK)
this is the entity i try to make for DISCOUNT
PRODUCT_ID (PK,FK)
ADMIN_ID(FK)
DISCOUNT_DATE
DISCOUNTED_PRICE
In my scenario, some of the specific product prices can be discounted with value/ per centage. But I am confused that do i need to put the discount value/percentage as an attribute or an entity in the product module because there are only some products that have the discounted price.
I hope that my explanation is clear enough ><
Based on question and comments, I suggest:
Discount Table
--------------
DISCOUNT_ID (PrimaryKey)
PRODUCT_ID (ForeignKey)
IsPERCENT (Bool)
DISCOUNT (Float|Double)
FROM_DATE (DateTime)
TILL_DATE (DateTime)
IsPercent should be True if discount is to calculated using Percentage.
Discount should be value (treated as percent or Currency depending on IsPercent)
Also in your program, validate that Discount value doesn't go above 100 if IsPercent is TRUE

Laravel calculate Total balance by rates

I have an ecommerce site with 4 tables
(Users, Vendors, Products and Orders).
Vendor here means a shop.
A User is a person and can own many different Vendors.
These Vendors can have many different products (Vendor hasMany Product relationship and a Product belongsTo Vendor relationship).
The orders table saves all transaction information when a customer buys.
Now we make our money via commission for each sale that happens on the eCommerce site.
The commission is calculated for each product based on the percentage rate of the Vendor(Shop) it is found under. These rates are stored in the Vendors table.
In my products table I have
id
product_name
product_price
product_image
product_file
product_description
product_level
vendor_id
In my Vendors table I have:
id
user_name
vendor_email
vendor_name
rate
And in my orders table I have:
id
customer_name
customer_tel
product_name
product_price
product_id
vendor_email
transaction_id
payment_status
Key things to note: Vendor Email is unique. vendor_id in the products table is the id field in the vendors table etc.
Now, let's take a user John who has 3 Vendors (A, B and C) and 5 products each under these vendors.
For Vendor A, we have products A1, A2, A3 etc same for Vendor B (B1, B2 ..) and Vendor C (C1, C2 etc).
Let's say John has a 5% commission rate to shop A, a 10% rate to shop B and 0% rate to shop C.
Vendor A: rate = 5%.
Products = [A1, A2, A3, A4, A5]
Vendor B: rate = 10%.
Products = [B1, B2, B3, B4, B5]
Vendor C: rate = 0%.
Products = [C1, C2, C3, C4, C5]
This means if product A1 (found in Shop A) cost $10 and it is bought we get 5% of the sale:
5/100 * $10 = $0.5
and John gets 95% which is
$10 - $0.5 = 9.5$.
Let's take another product B2 (found in Shop B with a rate of 10%) and cost $100. this means we get %10 of each sale and John gets 90%.
that is: 10/100 * $100 = $10 for us and John gets $100 - $10 = $90.
Let's take a final product c1 (found in shop C with a rate of 0%) and cost $200. This means when this product is bought, John gets all of the money.
Now for this three products, if John was to calculate his total income, this will be:
$9.5 + $90 + $200 = $299.5
and our total commision will be:
$0.5 + $10 + $0 = $10.5
I want to be able to display this data to the user. So fat, I am able to get the collection using eloquent in my controller and display the data to the user.
In my controller I have:
public function index()
{
$myOrders = ['vendor_email' => Auth()->User()->email, 'payment_status' => 'SUCCESSFUL'];
$orders = Order::where($myOrders)->orderBy('created_at', 'desc')->paginate(10);
$products = Product::with('vendor')->get();
$totalOrders = Order::where($myOrders)->count();
return view('admin.orders', compact('orders', 'products', 'totalOrders'));
}
And in my view, to get the amount John makes for each product, I use a Foreach loop in my blade:
Total: {{totalOrders}}
#foreach($orders as $order)
#if(Auth()->User()->email == $order->vendor_email)
Product Name: {{$order->product_name}}
Product Price: {{$order->product_price}}
#foreach($products as $product)
#if($order->product_id == $product->id)
Rate: {{$product->vendor->rate}}
Income: {{$order->product_price * $product->vendor->rate}}
Vendor: {{$product->vendor->vendor_name}}
#endif
#endforeach
#endif
#endforeach
This works perfectly as it returns the correct figures for each product which has been bought. If we take our example above, it will return
Total: 3
Product | Price |Rate |Income |Vendor
A1 | $10 |5% |$9.5 |A
B2 | $100 |10% |$90 |B
C1 | $200 |0% |$200 |C
My biggest problem is how to dynamically get the total of the income from the controller and displaying it as a variable in the Blade View. I want to be able to get this value in the controller so I can do calculations on it, say the User wants to withdraw part of his income, I should be able to deduct the withdrawal amount from the total income and display what's left etc.
I've been stuck with this problem and I have done a lot of googling but can't seem to find any solution. I got the total count of the products of each user by:
$totalOrders = Order::where('vendor_email', Auth()->User()->email)->where('payment_status', 'SUCCESSFUL')->count();
From that I can display this total orders of each user by simply calling this variable in blade:
Total: {{$totalOrders}}
My question now is how do I calculate the total income of the user: that is taking the price of each product sold and multiplying it by the commision rate of the Vendor shop so I can have some variable such as:
Total Income: {{some Variable}}
I really need help with this.
Order Model
public function product(){
return $this->belongsTo(App\Product::class, 'product_id', 'id');
}
Product Model
public function orders(){
return $this->hasMany(App\Order::class, 'order_id', 'id');
}
public function vendor(){
return $this->belongsTo(App\Vendor::class, 'vendor_id', 'id');
}
Controller
// These are orders for the logged in user.
$orders = Order::with('product.vendor')->where([
'vendor_email' => Auth()->User()->email, 'payment_status' => 'SUCCESSFUL'])
->get();
// Their income should be (100 - rate)% since the rate is the commission you get // as you stated in your post.
$totalIncome = $orders->sum(function ($order) {
return ($order->product->product_price * (100 - $order->product->vendor->rate);
});
$totalOrders = sizeof($orders);
return view('admin.orders', compact('orders', 'totalIncome', 'totalOrders'));
Blade
Total Orders: {{totalOrders}}
#foreach($orders as $order)
Product Name: {{$order->product->name}}
Product Price: {{$order->product->product_price}}
Rate: {{$order->product->vendor->rate}}
Income: {{$order->product->product_price * (100 - $order->product->vendor->rate)}}
Vendor: {{$order->product->vendor->vendor_name}}
#endforeach
Total Income: {{totalIncome}}

multiple currencies in a single table

How to make a MySQL table that could contain multiple type of currencies ($, Euros, ...) ? And if I want to make a final report is their a way to make a sum of those currencies other than adding multiple if statements to the sum ?
There may be several aspects involved. So here is some brainstorming:
You offer the same product in different currencies, e.g. a toy for 10 EUR or 11 USD. So you'd probably have an item table plus an item_price table, where the latter has product number, currency and price. (An alternative would be to have just one price, e.g. in USD and a currency table with conversion rates and you'd calculate the foreign price. But then you'd get "ugly" prices, e.g. 10.57, rather than typical prices like 10.50, 10.90 or 10.99. But well, you could have a price adjustment funtion for that, too. And you'd have to keep your conversion tables up-to-date or live with possible losses.)
A customer buys products and pays the bill. The bill is in one currency (store price and currency in the bill), but you also get your money in your currency, as PayPal or the bank convert it at a daily rate. Do you need to store this real amount, too? Then that would be another column in your bill.
I don't know how it is about taxes. Different currencies sounds like different countries. Maybe you'd have to deal with these in your database, too. I just don't know. The prices you show and store are usually gross prices (the price a customer actually pays) and the taxes (could be different VAT percentages with different products in one single bill) would have to be calculated.
As to getting sums: with all the information stored you'd get them with joins from the tables. No if-then-else in my opinion.
As per my opinion you can create a Country Table which contains
CountryID, CountryName, CurrencyCode, ExchangeRate. Now In that
country table you have to add all countries which you want to add but
you have to keep one thing in mind that you have to decide 1 currency
as base currency and put exchangeRate as 1 for that currency and
convert all other currencies exchangeRate based on the base currency
and insert into that table. i.e. Keep base currency as USD so insert
1 record with USD and exchangeRate must be 1 for that currency.
Suppose I am adding India as country than exchangeRate for that
country is based on USD as 66.40 Rs. insert all other countries
according to this entries.
Now when you want to add any transaction related to money in any
table then keep exchangeRate column with that amount column. ind
insert the exchangeRate and amount same as user's currency. i.e. If
my user is in India country, so it's currency is INR. Now that user
wants to add 1000 Rs. then you have to enter that 1000 Rs amount in
transaction table as it is without any conversion with exchange Rate
of 66.40 (fetch from country table). Same way If user currency is USD
and he wants to add a transaction of 100$ than store 100 as Amount
and exchangeRate as 1.
Now when you want to create any reports then just divide exchangeRate
with Amount, so you will get report in your base currency and after
conversion in base currency you can generate each report in any
currency as per your requirement.

MySQL storing VAT rates and amounts for each invoice

I have the tables invoice_header, invoice_rows and vat_codes from the billing software based on a MySQL database. I need to add my own table invoice_vat.
For each new invoice (or updated invoice) I need to store (or update) VAT rates, net amounts and VAT amounts into the table invoice_vat, groupped by the vat code.
I have several vate codes and rates. For example I have:
ABC tax rate 5%
DEF tax rate 10%
GHI tax rate 22% etc.
For each invoice I can sell together some products with ABC vat, some products with DEF vat and some other products with GHI vat. Usually we do not use more than 5 different vat rates in one invoice.
For example one of my invoice looks like:
product1, quantity 2pcs, unit_net_price 100.00, row_net_amount 200.00, vat ABC.
product2, quantity 3pcs, unit_net_price 50.00, row_net_amount 150.00, vat ABC.
product3, quantity 1pcs, unit_net_price 90.00, row_net_amount 90.00, vat DEF.
product4, quantity 4pcs, unit_net_price 25.00, row_net_amount 100.00, vat GHI.
For this invoice I need to store the values into the tables invoice_vat:
vat1_code ABC, vat1_rate 5, vat1_net_total_amount 350.00
vat2_code DEF, vat2_rate 10, vat2_net_total_amount 90.00
vat3_code GHI, vat3_rate 22, vat3_net_total_amount 100.00
vat4_code NIL, vat4_rate 0, vat4_net_total_amount 0.00
vat5_code NIL, vat5_rate 0, vat5_net_total_amount 0.00
I can do the following query:
SELECT invoice_rows.vat, sum(invoice_rows.row_net_amount) AS mysum
WHERE invoice_rows.id=655
group by invoice_rows.vat;
Now I need to store the values I get from the query, every time I make a new invoice or I revise/update an old invoice.
Should I use a trigger? How should look the trigger?
Giuseppe
Have table(s) that itemize the components of an invoice. Have another table that shows the invoice amounts as sent to the customer. For accounting and business and maybe legal reasons, this table should be "write once". That is, you should never change it, once it is finalized. At this point you are recording what you sent to the customer; it is not some scratch pad where things can be added/changed/deleted.
Note, in particular, if a item's price changes, or a VAT amount changes, then new computations would lead to an invoice that disagrees with what you sent the customer. Not good.

How do we store cascading taxes in a database? or database structure for storing taxes

Hi i have to create a database structure for storing tax details.
I have an itemDetails table which has the details of the item like name and price.
The problem is for each item there are two taxes service charge (10%) and VAT (4%)
but the taxes are cascaded i.e after I apply servicecharge, then on the new total I have to apply I apply vat.
I want to store this in a database; I can acheive this with hard coding it but I want it in a database so that in the future if the customer wants he can store more taxes by specifying which order the taxes apply and weather they cascade or not. And each item may have a different tax structure.. (Ex. one item may have the above mentioned tax structure, another item has only vat, another item has a completely diffenet structure etc)
I have a tax category table where the user can store a tax structure and each item will belong to a tax category i.e the itemDetailsTable has TaxCategory_id in it. I need your help figuring it out from there.
You could add another table that has a many-to-one relationship with TaxCategory that uses a ranking column to define what order the taxes are applied in.
TaxCategoryRates
taxCategoryId taxRate taxRank taxDescription
------------- ------- ------- --------------
1 10 1 Service Charge
1 4 2 VAT
2 3 NULL Local Sales Tax
2 4.5 NULL State Sales Tax
Your logic then applies the taxes in order of taxRank. If you have other tax categories where order doesn't matter (as in taxCategoryId 2), you can just leave the rank NULL and have your logic sum the tax rates and apply them.