Setting up GST invoice application report differs for item wise sales against total sales - sql

We have set up GST application where I am getting difference between reports like monthly item wise sales report against monthly total sales report.
Please suggest me any changes I need to make for following rules:
We have 3 tables
A. Order master - single line for every order is stored with summarized values
B. Order product details - Each line item stored with respective qty, price etc.
C. Order tax details - line item wise tax details having separate row for CGST, SGST etc.
Here is how I am storing the data:
Tax is applicable on every line item [To generate final invoice all items in order group, we create some of all line items and storing value in Order Master.]
We are rounding 2 decimal value for 3 precision [eg. 4.657 = 4.66, 4.643 = 4.64] as per GST council
Rounding value is stored in Order Master table
For discount there are 2 cases
Percent based discount - Let's say if discount is 10% then from every individual line item 10% discount gets deducted than tax will be applicable for each line item
Flat discount - Let's say for 1000/- Rs order somebody wants to give 80/- Rs. discount than from each line item 8% is deducted and than tax will be applied, off course customer may not pay exact 920/- Rs. amount due to reversal of tax amount.
Now when I am generating following reports:
Monthly item wise sales report [Product wise sales report]
Monthly total sales report [Total sales]
Monthly payment type wise report [Bank, Cheque, Cash]
I am getting difference due to rounding of values. Can anyone suggest me which is the best way to set up rounding formula and up to which decimal point should I go to round the values.
I am using SQL server as backend and .net as front end technology.

Related

Sum of 2 level discount

I am using SQL Server 2008 R2. I need to calculate sum 2 of levels discount. 1st one is item level, like 10% discount on any item. After offering this discount there is amount to receive is for example Rs.510. But shop keeper will get 500 and give him another discount Rs.10.
Now the second level discount is in main table and item wise discount is in child table. How I can calculate the sum of discount daily or monthly etc. and how I will get the following output. As when I am using inner join the discount in main table will be repeat for N number of items. Sum of discount on item wise is not an issue, but the invoice level is. Please help.
--------------------------------------------------------------
Invoice No. Date Total Discount Invoice Amount
--------------------------------------------------------------
INV-00001 01/01/2020 12 500
INV-00002 01/01/2020 10000
INV-00003 01/01/2020 30 900
--------------------------------------------------------------

MDX - Calculations of Daily Stock (Financial Instrument) Values

How do I calculate the daily values of a Persons Stock (Financial Instrument) using MDX.
A person buys Microsoft Shares/Stock like in the example below. I already have a SSAS MD Cube with this Information (DimDate, DimShare, FactInvestment, DimClient).Fund Units
Can easily calculate the Daily Balance of Units (Unit Balance) using MDX (sum(NULL:[Date].[Calendar].CurrentMember,[Measures].[Units]) to give me daily Balance of Units.[Daily Stock Value][2]
I have a Daily Share price Measure Group with a "Share Price" with Aggregation Usage Last non-empty value. This will give me the daily Stock price.[Daily Stock Price]. The Measure group DOES NOT have a Client dimension.[Daily Stock Price][3]
Would like to calculate the daily value of stock [Unit Balance]*[Share Price] = [Share Values] for each clientDaily Stock Values. See manual calculations in yellow on Pivot Table.

Powerpivot DAX - I need a way to show a value for Revenue in my profit & loss statement even if there is no Revenue

I am having an issue with a consolidated profit and loss statement using calculated fields. There is a column for GL Group, which is either Revenue or Expense. The calculated field asks "if the value of the row is Revenue then flip the sign of the number", and "if it is expense to leave it as is". And for the net income it takes the sum of both and flips the sign to give you a net profit. My issue is that if there is NO revenue then its BLANK and then expenses, which come through naturally as a positive number, remains a positive number on the net income but should rather be a negative. This is what I am looking to achieve: Revenue should be ZERO if its blank, minus expenses, the result of this will always be a negative number (remember the expenses show as positive). Looking to improve this code:
IF(HASONEVALUE(ActualsBudgetsOB[GL_GROUP]),IF(VALUES(ActualsBudgetsOB[GL_GROUP])="Revenue",CALCULATE(SUM(ActualsBudgetsOB[AMT_ACTUAL])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[FISCAL_YR]=[Max Year])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[PERIOD]<=[Max Period]))*-1,CALCULATE(SUM(ActualsBudgetsOB[AMT_ACTUAL])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[FISCAL_YR]=[Max Year])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[PERIOD]<=[Max Period]))),CALCULATE(SUM(ActualsBudgetsOB[AMT_ACTUAL])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[FISCAL_YR]=[Max Year])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[PERIOD]<=[Max Period]))*-1)

Merging two SQL tables

I have a table called Store Sales with the following columns
Date
Total Qty Sold
RRP
Total Value Sold
Branch No.
Barcodes
Unit Cost
Then I have another table called ESales that contains this
Inv Date
Our Ship Qty
Unit Price (RRP Inc VAT)
Line Total
Invoice
Order
Line
Brand
Part
Description
Our Order Qty
Unit Price (Exc VAT)
Discount %
Discount Amt (Inc VAT)
Discount Amount (Exc VAT)
Tax Category
Tax Exempt
Group
Sales Cat
Cust. ID
Title
Customer
Name
Tax ID
Rep. ID
Credit Memo
Unit Price
Amount
Category ID
Cust. Amount
Number01
ShortChar01
ShortChar02
Clubcard
There are matching fields but none with the same name. They are
Inv Date = Date
Our Ship Qty = Total Qty Sold
Unit Price (RRP Inc VAT) = RRP
Line Total = Total Value Sold
What I want to do in merge the values in StoreSales to ESales and create additional columns for the data that is not there, these are
Branch No
Barcodes
Unit Cost
Any ideas how to insert the matching values and create the three new ones?
Instead of creating a new table, I would just start with a query that shows you all the data you are describing. The way you merge data from multiple tables together is by using a JOIN command. Here is a example query that shows everything from the ESales table and the additional columns from the StoreSales table you described:
SELECT e.*, s.[Branch No], s.[Barcodes], s.[Unit Cost]
FROM StoreSales s
INNER JOIN ESales e ON
e.[Inv Date] = s.[Date] AND
e.[Our Ship Qty] = s.[Total Qty Sold] AND
e.[Unit Price (RRP Inc VAT)] = s.[RRP] AND
e.[Line Total] = s.[Total Value Sold]
Once you get a query you like, you can save it as a VIEW which essentially lets you interact with the result of this query as if it were a separate table.
I will caution you that you have to be very careful doing this. Usually, data will have some kind of common field like a Order ID or a product SKU that makes it very clear what unique item you are referencing in the database. Joining by things like date, order total, price, etc is bad practice. This is because there is no way to guarantee that there aren't two orders with the same date or the same order total. Those things are not unique to any one particular order.

FIFO Allocation between Sales and Sales Order Table based on Schedule

It's a an Order Processing related query. There is a sales order which will have different products with some specific quantity. Each qty will have schedule for delivery. In this case, for 55 nos it has the schedule as 10, 15, 30. same way it has once more set of schedule. In Sales details table you get detail of the material sold against each item. You will get details like sale order no and item line no. We need to take schedule qty in FIFO basis and allocate the required qty. I need to get a result set as shown and have to update the sales order detail table. Please help me Screenshot
Resolved Myself. Need to make use of Loops and allocate the quantities to the Delivery schedules.