Running in real troubles with our products? Get in touch with our Support Team 👉

0
No products in the cart.
  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #9901
    mateen-ahmed
    Participant
    $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.

    #9902

    As 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 accordingly

    If 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

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.