Laravel keep track of quantity for different models - laravel

I'm building a farm management application with Laravel with the following tables
products
id
trade_name
state
category_id
equipment
id
name
type
Product is a chemical product and Equipment can either be a tractor or an implement
I want to keep track of quantity in both products and tractors
For products, quantity can be in litres or kilograms (depends on the state of the product)
For tractors I want to keep track of quantity of fuel
For that I'm thinking of creating a new stocks table with the following columns
stocks
id
stockable_id
stockable_type
quantity
The thing is I only have one warehouse which means creating a stocks tables doesn't really make sense but if I choose not to do it I'll have to add a quantity columns for both products and equipment
I'm lost with which approach I'd go with and I'd be happy to hear more from you guys

Related

Is there any function in Quicksight where I can count different customers who have purchased in various categories?

I have customers who paid in different categories, for example, SHOPPING, BEAUTY, FOOD etc.
And I'd like to count the number of customers who bought in two different categories, for example, SHOPPING and FOOD in a KPI visual
Quicksight does not allow the use of calculated fields with other calculated fields.If it could be possible I could calculate with a distinct_countIf.
The only way that I got is showing in a pivot table, and summarizing.
Can you think of any other more elegant way?

Libreoffice-base subform_sales_desc inside form_order . first form cannot enter items as number and show as names and not gst,unit etc automatically

I am creating free accounting package in libreoffice-base to compete already available ones your contribution is appreciated. the package include tables:
items
item_groups
order_details
sales_bill_desc
cash
units
companyinfo
bill sales
Customer_ledger
etc.
and created two forms
first to enter items in items table with following fields:
id
List item
particulars
units from units table linked with id gst chooses from
tax table related as id basic price basic stock, barcode, group,
subgroup,
second form is sales bill entry form
it contains a form which relates to order_details table selects customers name from ledger where its state code is also defined e.g. for punjab its 03 basically it is picked from customer's GSTIN number
a subform which is connected to sales_bill_desc table related to order_details table with bill number in both tables.
now in subform when we enter one item, its name is displayed which is same entered in sales_desc table additionally it also need automatically display item units, gst, price(editable field but basic price must be displayed there).but it does not. how to do that i have studied books but am lacking i created same in access 2016 somewhere which worked fine (full working package accounts with inventory).At this time,I am trying to use same database but advanced with features such as barcode. Of course the issue is to be resolved if someone can help. I am loading code of the package.Please rectify and update.

Laravel 5.6:How to create db query inside a foreach loop and display the result in a view corresponding to the product id

I'am a laravel newbie. I'am trying to create a point of sale system: It has a sales area where the users can search for product and click on the product they need to sell. Once clicked the product is added to the cart together with its serials.I have three tables involved:
1ST TABLE
Items_master: this table stores the product names, buying and selling price
2ND TABLE
Stock_quantities: this table stores the product quantities according to the shop by product_id and shop_id.
3RD TABLE
Stock_serials: this table stores the serials of all products by product_id and shop_id.
Here is the code
MAIN QUERY
Products query
SERIALS QUERY
Serials query
VIEW
PRODUCTS VIEW
The problem is, if more than one product is selected,it displays the serials of only one product.I would like each product selected to be accompanied by its serials in a dropdown.

How to model this mysql table relationship in elastic search

I have a large amount of shop items imported into elastic search and I can query them.
I am wondering how best to model the following mysql table relationship into elastic search:
Shop items can have different offers. There are different offer types. And in some shops an item may be on offer, in other shops the item may not be on offer or have a different offer type. Items don't have to have offers. I model this below:
Items table
item_id
Offers table
shop_id, item_id, offer_type, user_id
Where user_id is the id of the user who created the offer.
So as an example, item_id 1 and shop_id's 1,2 and offer_types premium and featured.
Then the offers table could look like:
shop_id, item_id, offer_type, user_id
1,1,featured,45
2,1,premium,33
2,1,featured,45
But it's not the case that every item is on offer. And even if item_id 1 is on offer in shops 1 and 2, it might not be on offer in other shops.
I want to be able to query my /items type and it will only be for one shop at a time but for that shop I want to get all the items in e.g. a certain price range and of a certain category (that i can do all ready), but I need to know for each item in the results what offer they have if any (e.g. if featured, premium or whatever offer_type).
How can I best model this behaviour in elastic search?
One approach is Nested Object relationship - Shop contains set of items with id as your shop id
For your cases
1) Get all items of a shop - GET: http://host/your_index/shops_type/shopid
This will give you all items in a shop along with offer_type. you can filter in your program logic

what is the best way to model sales taxes in rails ordering system

I'm programming a simple invoice system.
Products have the usual: name and cost, has many Line Items.
LineItem is a Product inside an Invoice (belongs to Product, belongs to Invoice).
Invoice has many Line Items.
Taxes have: name and rate (ex 8.25%).
Here is the dilemma: How to setup the Taxes on the Products, the Line Items and the Invoice?
A Product can have one or more Taxes.
Therefore, a Line Item can have one or more Taxes.
Should I create two tables: products_taxes and line_items_taxes and create two has_and_belongs_to_many_association?
Taxes are generally region-specific, and as such, tax rates really should be their own thing. There's no direct relationship between the taxes and the product, it's about a relationship between the tax rate and the place the item is being shipped/billed.
So, I wouldn't make any relationship between products and taxes. I would create a tax_rates table, and then define a method on the invoice model (or on the product model, if you need to do per-product taxes, which is very likely) that calculates the final price. Something like:
On the product model...
def calculate_final_price(tax_rate)
price*(1+tax_rate.tax_percentage)
end

Resources