Correct Schema design for following application - mongodb

I am learning MongoDB, Express, React etc and am putting together a simple application to do so but am stuck on the schema design.
The application will be a money manager where users will be able to sign up, then fill in their monthly income (salary and any other income), and regular expenditure. This will provide an amount they are able to spend each month.
The user can then enter transactions throughout the month, the application will log these, which will deplete the monthly allowance to provide the user with a snapshot of their funds available to spend.
I am just stuck on how to structure the schema.
Do I have a separate database for users, expenditure and income, and associate the expenditure and income with the user via the user's _id value?
Or should the expenditure and income be tracked in the same database as the user?

Related

Database design for storing users log data in mongodb on daily, weekly basis

I am making a live tracking application which tracks the data of the application and the websites using by the user and stores the activity data of the user in the mongodb database. It stores the data of the user like which application or website is being used by the user and how much time they have used that application in their computer.
My current database document looks like this.
Database image
I want to store the logs of the user according to the Daily, Weekly and Monthly basis in mongodb. I want to have the database architecture to use for storing these logs on daily or weekly basis according to the user. I want to know how can I do this.

notifying users of backend changes via subscription

My mobile app has users who are clients, business owners, and employees.
Each business owner can have multiple businesses.
Clients can create an order with one of the businesses. When they do, the business owner and employees who are linked with the business should be notified.
I have an orders collection where I create the order and I add the order doc id to an array of pending orders on the business record.
Notifying new order is mission critical, so I cannot depend only on push notifications. So I decided I’ll update the app via a db subscription to the user collection.
Sure, I can update an array of orders on records of the owner and employees linked with the business once the order is placed, but it becomes hard to manage when the owner may remove an employee from a business. It's repetitive when storing the order IDs in each employee’s record. It’s also expensive to keep updating these records when orders are processed.
How would you approach this?
UPDATE
I'm using Firebase
Another approach could be storing each order under the business ID, and then have each connected employee and owner listen to changes to that doc. However, it is possible that it will be more expensive as users will need to be listening to more documents than just their own user record.

Xero and Filemaker Inventory and PO Integration

The company I work for in the the process of converting to Xero from MYOB. I'm currently developing a Filemaker database that will handle Estimates, Jobs, Inventory, Purchase Orders, and several other entities. I'm trying to work out the best way to sync Inventory items. We will have multiple stock locations, and product categories, in the Filemaker database, so according to https://developer.xero.com/documentation/api-guides/inventory-integration-options we should only sync inventory transactions, not inventory items.
The issue with this is that for the foreseeable future we will still be using ServiceM8 for the service side of the business. Filemaker is only used for estimates and jobs for the install side of the business, as well as purchase orders and inventory. ServiceM8 will still need to push invoices to Xero and adjust stock quantities accordingly. Is it a viable option to sync inventory items but just have an QuantityOnHand field in the filemaker database that is a sum of all the stock location quantities, and sync that with the Xero QuantityOnHand field?
Likewise there will be category fields in the filemaker product table that will not be seen in the Xero product table, but all product record creation will be done in Filemaker. Worst case I can periodically find any product records that do not have categories and enter them.
One other thing, I hope it's OK to put it in the same topic as it's related.:
Filemaker will handle purchase orders including Receiving multiple shipments. Would best practice be to POST the purchase order record to Xero when it's created and update the Status as necessary, or should I not use purchase orders in Xero at all and just do stock transactions?
Thanks,
Stew.

How to model users in the system?

I am working on system that will manage orders. Orders can be created via admin or via customer. Employee can take orders and change it's status.
My system should have three global types of users:
Admin - this type of users mostly uses WEB interface. Admins have different access levels, so some of them can only create orders, and others - edit core info about pricing and so on.
Customer - this type of users uses customer's mobile app. Main action is to add and cancel orders.
Employee - this type of users uses employee's mobile app. Employees can see open orders, assign themselves to orders and change order statuses.
Also, Customer and Employee can be authorised with phone number, that can be changed at some time (independently of each other). Admins can be authorised with uname + pword.
Current solution has one table for Admins, one for Customers and one for Employees.
So first part of question is how to structure database properly?
The second part is about authorising in REST api. In current solution I have three endpoints, that are authireses usertype independently.
admins/auth
customers/auth
employees/auth
And my thoughts is to keep three tables as is, because each usertype is slightly different concept and really independent. And keep authorisation as is, but add something like roles and privileges to auth token to restrict access for some resources.

How to get customer id KUNNR of current Launchpad user?

I am writing a custom Fiori to access sales data from an SAP ERP backend system using a Gateway.
The use case is "customer logs in launchpad, opens Fiori app and sees all his/hers sales items based on the customer id". The customer id is stored in kna1-kunnr and has to be included in a select on the vbak table in SAP. Nothing fancy.
Now I ask myself: how do I get the customer id / kunnr? What do I get at all from the currently logged in user? When debugging my Gateway project code, is it actually the name stored in sy-uname or can I get something better?
How should I continue to get the customer id / kunnr? Are there some function modules like GET_CUSTOMER_ID_OF_USER to call in the SAP ERP?
Or are the actually other / better ways to get the sales documets for one user?
Update
Thank you for your answers so far. I am going to check the default Fiori implementations to get some inside. But, since we are already here, I want to specify my question a little bit more:
Giving I create an OData model in my Component.js like that:
var oModel = new sap.ui.model.odata.ODataModel("[...]/sap/opu/odata/sap/Z_MYODATA_SRV/",
false, "user", "password" );
user and password are supposed to be the ones currently entered as user credentials in the Fiori Launchpad. How can I access those? Are there some SAPUI5 api like getCurrentUser or getCurrentSession ? Do I actually have to do this user check?
You are correct that to identify all of the sales orders for a customer you need to read them from VBAK (or use BAPI_SALESORDER_GETLIST, etc).
The relationship between logged in user and customer is not something that's the same in every SAP ECC system. You may find that the logged in user is the same as the customer number, but with a prefix - for example, logged in user C12345678 for customer 0012345678. Or there may be some other type of relationship that's store in a custom field on the customer master itself. The best option is to check with the person responsible for the configuration in Sales and Distribution. Only then can you know how to determine the customer for a logged in customer user.
Answering your question
Now I ask myself: how do I get the customer id / kunnr? What do I get at all from the currently logged in user?
It is done on backend with standard customizing, not via OData methods like you intend to do it.
Mikael gave you the rough idea, but didn't finished it so I will give a more comprehensive answer.
We need to differentiate between front-end and back-end authorizations, for Fiori app functioning you need to types of roles/authorizations:
The SAP Fiori roles that define which Fiori apps are displayed to the user
Launchpad authorizations
General OData authorizations
Trusted RFC back-end connectivity authorizations
Back-end authorizations and roles which contain authorizations to display the related business data
This concept is depicted on this figure:
The assignment of the front-end is described here and is out of scope now. Now we are focusing on bullet 2.
Every Fiori app has its role model and one should follow the implementation given in app description. Let's consider how it is done based on Sales Order creation app (F0018) sample:
OData service that returns business-data is SRA017_SALESORDER_CREATE_SRV, so to run it one needs frontend role SAP_SD_BCR_FIELDSALESREP_X1 and backend role SAP_SD_SO_CRE_APP
Also app description give us the following prerequisits:
Before implementing the Create Sales Order app, you must ensure the following:
That an employee master record is created with the following attributes:
If you have implemented SAP ERP HCM and maintained employees in the HCM personnel records, ensure that the employee personnel record has the infotype Communication, with a subtype of System User Name (SY-UNAME) (Infotype 0105, Subtype 0001).
If you have not implemented SAP ERP HCM, implement the Sales and Distribution configuration around Use Sales Employees with HR (Tcode: PULT). This IMG setting copies the appropriate HCM tables from the 000 Client and allows the setup of the employee record with the Infotype Communication and a Subtype of System User Name (SY-UNAME) (Infotype 0105, Subtype 0001).
It associates the USERID of the employee with the personnel number assigned as a partner function sales employee in the customer master.
After implementing the above customer SAP user id will be bound to his employee ID (PERNR), and his employee ID consequently will be bound to partner function in XD02.
And that's not all, what comes next?
THe following order parameters should be maintained in in SIMGH tcode in order customer to see his orders and can create the new ones.
Call transaction SIMGH to open the Create Sales Orders node and configure user information in Customizing activity Define Configuration Parameters using the parameters listed below. For more information, see the documentation available for the Customizing activity.
Document Type (DOCTYPE)
By default, the app uses the standard order document type (technical key TA resp. OR). Changing this to something other than a sales order may significantly impact the functionality of the application.
Order Period (ORDPERIOD)
This defines how many days into the past sales orders are retrieved. The suggested value is 30 days.
Search Period (SEAPERIOD)
This defines how many days into the past a search must look for sales orders that match the search criteria. The suggested value is 90 days.
Ship To Party (SHIP_TO/PARTNER_ROLE)
This defines which partner role in the customer master is used for the ship-to party. The suggested value is WE.
Forwarding Agent (FORWARDING_AGENT/PARTNER_ROLE)
This defines which partner role in the customer master is used for the forwarding agent. The suggested value is SP.
and even that's not all
App description gives the following BADIs to implement in order to enable such linking
Implement the following BAdIs:
Customer Association to Employee
You can use this BAdI to associate employees with specific customers.
Only after all the above steps the customer will be able to order and/or view his sales items.
The moral: always check the app description thoroughly because the role model varies per-app.
Have a look at the standard Fiori applications. For example, in Create Sales Order, there is a BADI provided to implement the relation you are looking for (but for an employee to a customer). In the standard setup, the partner functions of the customer master is used to map what customers are visible to an employee.
Most likely, you have a similar setup already in place if your customers actually have user accounts in your system. If could be as a parameter of the user or as a (custom?) partner role.
http://help.sap.com/saphelp_fiorierpx1_100/helpdata/en/6d/135652f9c21457e10000000a445394/content.htm