Where could i find table details on sap business one forms? - sap

I hope you could help me find where could i found the table name and location as it only shows as a form..
i hope you could help..

That field comes from table ITM1 and the field is named "Price".
You should consider pricelists per business partner in fetching this. Look at query below.
// Default price
listNum = _db.OCRDs.Where(x => x.CardCode == _cCode.ValueEx).Select(y => y.ListNum).FirstOrDefault();
if (listNum != null)
{
defaultPrice = (from oi in _db.OITMs
join it in _db.ITM1 on oi.ItemCode equals it.ItemCode
join op in _db.OPLNs on it.PriceList equals op.ListNum
where (oi.ItemCode == _itemNo.ValueEx
&& op.ListNum == listNum)
select it.Price).FirstOrDefault();
}

Related

Prestashop module SQL Query to get id_products from a specific feature value

I'm currently working with a module called "Leo Parts Filter" on prestashop, which sort id_products by make, model, year and device in a database "ps_leopartsfilter_product".
When i call a make, model, year a device that have an id_product in this table, prestashop show this id_product.
public static $definition = array(
'table' => 'leopartsfilter_product',
'primary' => 'id_product',
'multilang' => false,
$sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'leopartsfilter_product` WHERE 1=1 ';
if ($id_product != null && (int) $id_product) {
$sql .= ' AND id_product =' . (int) id_product;
}
I would like to change the way id_product is called, instead of calling only this id_product according this way :
I would like to query all products where the feature_id = 212 and where the feature_value_lang = id_product.
I tried to adapt this query but i can't make it work correctly (no data showing)
SELECT id_product, fl.name, value, pf.id_feature
FROM '._DB_PREFIX_.'feature_product pf
LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature =212 AND fl.id_lang = '.(int)$context->language->id.')
LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$context->language->id.')
LEFT JOIN '._DB_PREFIX_.'feature f ON (f.id_feature = pf.id_feature)
'.Shop::addSqlAssociation('feature', 'f').'
WHERE fvl.`value` = '['id_product']'
GROUP BY id_product
ORDER BY f.position ASC
';
I'm not good at SQL so don't blame me, i learned everything by my way and i try to build my own company website, this module is all i need to finish.
If someone want some money for help, i'm open to give rewards to make it work.
Thanks
Your second query has nothing to do with the Leo Parts Filter module, since it only queries native Prestashop feature tables and not those of the Leo module itself, so your request is not very clear.
If you need to rely on basic features, it must be clear to you that the relationship between id features / id feature values and id products is all in the ps_feature_product table, so if you want products that have id_feature_value = 212 you just need a simple
SELECT id_product FROM ps_feature_product WHERE id_feature_value = 212;

MVC update the database based on a non primary key value

I have a database table that looks like this:
My goal is to update my "unavail" table based on the ID of either the component, part, or item depending on which one is relevant in my situation.
For example, if the partID = 43 I want to add to the 'unavail' column
I first started working on this by trying this
db.OffSiteItemDetails.Find(sod.PartID).unavail += sod.comp_returned;
(Where sod.PartId = 43)
But I quickly realized it was just checking for where the "ID" was equal to 43 which isn't what I want. After some investigation I saw people suggesting using
db.Where(x => x.non-pk == value)
So I created this
db.OffSiteItemDetails.Where(x => x.componentID == sod.ComponentID);
But from here I don't know how to change my unavail table values.
This was a tough question to type so if you need more clarity just ask
foreach(var item in db.OffSiteItemDetails.Where(x => x.componentID == sod.ComponentID))
{
// item.unavail = [new value]
// db.Update(item);
// ...I don't know how you update the data in your database
}
Something like that?

Convert MS SQL to Entity Framework

I trying to learn MVC, but while I try search customers purchased products I can't write with Entity Framework. I can search with MS SQL query, but I can't convert to Entity Framework.My codes;
Controller:
public ActionResult Orders()
{
Customer c = db.Customers.Find(Session["UserID"]);
List<Order> userorders= db.Orders.Where(x => x.CustomerID == c.ID).ToList();
List<OrderProduct> orderproducts = db.OrderProducts.Where(x => x.OrderID = userorders.ID); //This code not work
return View();
}
Database:
I try to convert this MS SQL code to Entity Framework;
"select ID from Products where ID IN (select ProductID from OrderProduct where OrderID IN (select ID from Orders where CustomerID = 1))"
If you can convert this MS SQL code to Entity Framework thats enough for me.
Thanks for anyone help and so sorry my bad English.
To retrieve all OrderProducts of the customer with ID 1, try this:
var orderProducts = db.OrderProduct
.Where(p => p.Orders.Any(o => o.Customers.Any(c => c.Id == 1)))
.ToList();
To retrieve the ID only, you can do it this way:
var productIds = db.OrderProduct
.Where(p => p.Orders.Any(o => o.Customers.Any(c => c.Id == 1)))
.Select(p => p.ProductId)
.ToList();
thanks for help but this is only orderproduct list. I need order list. I try this code (I edited JanneP's code. Thanks so much JanneP):
List<Product> products = (from co in db.Customers
join o in db.Orders on co.ID equals o.CustomerID
join op in db.OrderProducts on o.ID equals op.OrderID
join p in db.Products on op.ProductID equals p.ID
where co.ID == c.ID
select p).ToList();
This code find one customers ordered products. And it works.
Thanks everyone for help.
You could create a join condition. Also, where conditions need to be presented with two equal signs, not one. This should work:
List<OrderProduct> ürünler = (from c in db.Customers
join o in db.Orders on c.ID equals o.CustomerID
join op in db.OrderProducts on o.ID equals op.OrderID
where c.ID == 1
select op).ToList();
Since your database has been set up properly with Foreign Keys constraints, Entity Framework will be able to use 'navigation properties'. This allows you to write your query very easily as follows.
List<Product> products = db.Products.Where(e => e.OrderProduct.Orders.CustomerID == 1).ToList();
In your original SQL you only wanted the product IDs. Here's how you would do that.
List<int> productIds = db.Products.Where(e => e.OrderProduct.Orders.CustomerID == 1).Select(e => e.ID).ToList();
For people who have a sound grip on SQL but are new to Entity Framework and Linq, a useful search term is '101 LINQ samples'.
Just use the Include to retrieve the product with each order.
List<Order> userorders= db.Orders.Include(a=>a.Product).Where(x => x.CustomerID == c.ID).ToList();
This will retrieve the orders and with each order the product.
You can change the Include to add more navigation properties, I am assuming you have a Product property inside the Order class, you can change the name ift was wrong

Magento SQL Query to show product manufacturer

I am trying to query the Product Manufacturer in Magento 1.7.0.2 . I browse again and again all the table to where I can get the manufacturer table and connect it with product SKU.
I try this query to hope that I can get the manufacturers of the product:
SELECT
eav_attribute_option_value.value FROM
eav_attribute,
eav_attribute_option,
eav_attribute_option_value
WHERE
eav_attribute.attribute_code = 'manufacturer' AND
eav_attribute_option.attribute_id = eav_attribute.attribute_id AND
eav_attribute_option_value.option_id = eav_attribute_option.option_id
but it is not equal to the product manufacturer when I compare the result to my magento admin product manufacturer.
My question is that what should I do to query so that I can get the list of manufacturers of the product so that I can sql join in with catalog_product_enity's SKU.
Does anyone has an idea about my case? I am new with magento so please be gentle with me.
Any help will be appreciated, Thanks in advance
I hope I understood correctly.
If you want to get the manufacturer for a product, you don't need any query.
This should work. Let's assume that you already have the product in var $_product;
$_product->getAttributeText('manufacturer');//this gets you the label
$_product->getManufacturer(); //gets the manufacturer id
[EDIT]
To get this for all the products do this:
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('manufacturer');
$collection->addAttributeToFilter('status', 1);//optional for only enabled products
$collection->addAttributeToFilter('visibility', 4);//optional for products only visible in catalog and search
foreach ($collection as $product) {
$sku = $product->getSku();
$manufacturerId = $product->getManufacturer();
$manufacturerLabel = $product->getAttributeText('manufacturer');
//do something with the values above - like write them in a csv or excel
}
Little late, but this is what I came up with. Works like a charm.
SELECT cpe.sku, cpev.value, cpf1.manufacturer_value
FROM catalog_product_entity cpe
JOIN catalog_product_entity_varchar cpev ON cpev.entity_id = cpe.entity_id
JOIN catalog_product_flat_1 cpf1 ON cpf1.entity_id = cpe.entity_id
WHERE cpev.attribute_id = 191

Are those two queries the same in rails 3.2.12?

We need to retrieve logs for customer comm record in our rails app. The condition in plain english is logs for customer_comm_record based on:
#1. the sales_id in customer comm record's customers is equal to current user id
#2. the sales_id in customer comm record's customer's project is equal to the current user id.
The SQL code for #1 could be (SQL#1):
Log.joins(:customer_comm_record =>:customer).where('customers.sales_id = ?', session[:user_id])
SQL code for #2 could be (SQL#2):
Log.joins(:customer_comm_record =>{ :customer => :projects}).where('projects.sales_id = ?', session[:user_id])
Here is what we come up (SQL#3) in one line:
Log.joins(:customer_comm_record =>{ :customer => :projects}).where('customers.sales_id = ? OR projects.sales_id = ?', session[:user_id], session[:user_id])
The SQL code returned by above in rails console is (replacing session[:user_id] with 1) :
SELECT "logs".* FROM "logs" INNER JOIN "customer_comm_records" ON "customer_comm_records"."id" = "logs"."customer_comm_record_id" INNER JOIN "customers" ON "customers"."id" = "customer_comm_records"."customer_id" INNER JOIN "projects" ON "projects"."customer_id" = "customers"."id" WHERE (customers.sales_id = 1 OR projects.sales_id = 1)
The question is weather SQL#3 == SQL#1 UNION SQL#2. Can someone answer the question? If it is not, what's the right one? Thanks.
The only differences are:
The first method will return duplicate entries where the sales_id for the customer and project both match the users id.
The second method might not return records where a customer with a matching sales_id does not have a project (no projects.customer_id for that customer).
The last difference only matters if a customer does not necessarily have any projects. Otherwise, the second method is better because it avoids dealing with duplicates.
If a customer does not always have a project, a simple workaround would be to use includes instead of joins:
Log.includes(:customer_comm_record =>{ :customer => :projects}).
where('customers.sales_id = :id OR projects.sales_id = :id', id: session[:user_id])
This will force a LEFT JOIN and will return customers regardless of whether they are associated with a project.