Eg: When an online order is placed, the order is delivered to the customer in some days. For example an order is taking 10 days to deliver to the customer.
Order placed date: Dec 1, 2013
Order shipped/complete date: Dec 5,2013
Delivered Date: Dec 11, 2013
For the order to complete, it will travel through many departments.
Dept 1: Invoice
Dept 2: Billing
Dept 3: Process
Dept 4: Shipment
Data is stored in table as follows
DB Table: | ||||
Date | Order # | Next_loc | Previous_loc | User |
12/1/2013 | AAP1 | Dept1 | null | User1 |
12/1/2013 | AAP1 | Dept 2 | Dept1 | User1 |
12/2/2013 | AAP1 | Dept 2 | Dept2 | User1 |
12/2/2013 | AAP1 | Dept1 | Dept2 | User2 |
12/3/2013 | AAP1 | Dept3 | Dept1 | User1 |
12/3/2013 | AAP1 | Dept 2 | Dept 3 | User2 |
12/3/2013 | AAP1 | Dept3 | Dept2 | User2 |
12/4/2013 | AAP1 | Dept4 | Dept3 | User2 |
12/5/2013 | AAP1 | Complete | Dept4 | User2 |
When an order is placed the order goes through each department. Sometimes, it might go to and fro to the same department.
I have an order placed on Dec 1, 2013. I have following details for the order.
So I have to calculate the number of days the order is open, number of days in each dept and also the number of times it is routed to each dept.
If the order is going to the same dept more than one time a day, it is given a count of 1 (In above example on 12/3/2013 order id going to Dept 3 twice but is given a count of 1). For each dept it is going, it will get a count of 1 (On 12/3/2013 order is going to dept 2 and dept 3. So both the depts. Get a count of 1 each for that day).
My report should look like this:
Report: | ||||||||||||
User | Order # | Order Create Date | Days Open | Days in Dept 1 | Days in Dept 2 | Days in Dept 3 | Day sin Dept 4 | Routed to Dept 1 | Routed to Dept 2 | Routed to Dept 3 | Routed to Dept 4 | Order Complete Date |
User 2 | AAP1 | 12/1/2013 | 4 | 2 | 3 | 1 | 1 | 2 | 3 | 2 | 1 | 12/5/2013 |
explanation for the count: | order # | date placed | Diff of (12/5/2013, 12/1/2013) | 12/1/2013, 12/2/2013 | 12/1/2013, 12/3/2013 | 12/3/2013 | 12/4/2013 | 12/1/2013, 12/2/2013 | 12/1/2013, 12/2/2013, 12/3/2013 | 12/3/2013, 12/3/2013 | 12/4/2013 |
Can someone please help me in calculating - Days in each dept as well as Routed to each dept.
Appreciate your help.
Thanks
Tulasi