Template for Printing multiple records of entity

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • item
    Active Community Member
    • Mar 2017
    • 1476

    #16
    Hello esforim , emillod,
    Yes with espocrm all is possible.. and what emillod ask is possible .. but not out-of-box .. so need code :

    first create a field for entity :
    activityList activityList Json Array
    then services :
    PHP Code:
    <?php
    
    namespace Espo\Custom\Services;
    use \Espo\ORM\Entity as Entity;
    
    class Patient extends \Espo\Core\Templates\Services\Person
    {
    public function loadAdditionalFields(Entity $entity)
    {
    parent::loadAdditionalFields($entity);
    
    $sql = "SELECT id, name, 'Call' as entityType, date_start as dateStart, status, description FROM `call` where parent_type='Patient' AND parent_id='" .$entity->id ."' AND deleted='0'
    UNION
    SELECT id, name, 'Meeting' as entityType, date_start as dateStart, status, description FROM `meeting` where parent_type='Patient' AND parent_id='" .$entity->id ."' AND deleted='0'
    UNION
    SELECT id, name, 'Email' as entityType, date_sent as dateStart, status, body_plain as description FROM `email` where parent_type='Patient' AND parent_id='" .$entity->id ."' AND deleted='0' AND status NOT IN ('Failed', 'Draft')
    ORDER BY dateStart DESC";
    $pdo = $this->getEntityManager()->getPDO();
    //$GLOBALS['log']->warning( $sql);
    $sth = $pdo->prepare($sql);
    $sth->execute();
    $row = $sth->fetchAll(\PDO::FETCH_ASSOC);
    
    foreach ($row as $i => $v) {
    $activityDataList[$i] = (object) $v;
    }
    
    
    $activityList = json_decode(json_encode($activityDataList, true));
    
    $entity->set('activityList',$activityList );
    //$GLOBALS['log']->warning( $entity->get('calls' ) );
    }
    
    public function loadAdditionalFieldsForPdf(Entity $entity)
    {
    $this->loadAdditionalFields($entity);
    
    }
    }

    then on your pdf .. you can loop activityList

    but need code ..of course, this is my solution with my skill ... but for me not complicate for out-of-box code ..
    PrintPdfPerPage
    PrintPdfAsOne .. somethink like this as button

    Regards

    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment


    • esforim
      esforim commented
      Editing a comment
      Awesome. I probably won't be using it but I'm sure it is useful for other. Added to #learning thread
  • emillod
    Active Community Member
    • Apr 2017
    • 1405

    #17
    item hello. thank you very much.
    That's workaround, but if you want to use this in all entities, you'll need to modify all entities..
    It'll be easier if espo devs decide to add this as built-in feature

    Comment

    Working...