- This topic is empty.
-
AuthorPosts
-
February 1, 2023 at 10:42 am #9901mateen-ahmedParticipant
$collection = $this->_itemCollectionFactory->create()->getCollection(); $collection->getSelect()->columns(array('total_orders' => new \Zend_Db_Expr('COUNT(order_id)'))) ->columns(array('total_qty' => new \Zend_Db_Expr('ROUND(SUM(qty_ordered))'))) ->group('sku'); $collection->getSelect()->limit(3); $collection->addFieldToFilter('store_id', 2);
Through this code i can get the total quantity and total number of orders of all sales rep. But i need only those total quantity and total orders which were done by the Sales Rep og Logged in Sale Manager.
February 10, 2023 at 1:38 am #9902bh-biezras—boruch-hashemParticipantAs you mentioned in your question you only want to get the order info based on a certain sales rep. To do that you need to somehow find a unique identify for the currently logged in sales rep and add a filter for that .
For example:
$collection = $this->_itemCollectionFactory->create()->getCollection(); $collection->getSelect()->columns(array('total_orders' => new \Zend_Db_Expr('COUNT(order_id)'))) ->columns(array('total_qty' => new \Zend_Db_Expr('ROUND(SUM(qty_ordered))'))) ->group('sku'); $collection->getSelect()->limit(3); $collection->addFieldToFilter('store_id', 2); $collection->addFieldToFilter('sales_rep_identifier', $loggedInSalesRepIdentifier);
The label
sales_rep_identifier
and the value$loggedInSalesRepIdentifier
are just examples, you may have to adjust the format in which the data is stored if it doesn’t currently have a field to check natively what sales rep did it, and adjust the values there accordinglyIf you’re using some kind of prebuilt system then maybe there are other labels for the identifier you could use, without more information on the specific database structure it’s impossible to answer exactly, but essentially you need to filter by the unique sales rep identifier, and if that doesn’t exist now in the database it should somehow but added
-
AuthorPosts
- You must be logged in to reply to this topic.