Change status via link, is that possible?

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • ChrisSka83
    replied
    I have made some changes to the design so that it fits better with our portal.

    Thanks again to Kharg who also gave me tips on how I can read out more data and use it further.


    Code:
    <?php
    
    namespace Espo\Custom\EntryPoints;
    
    use Espo\Core\Exceptions\NotFound;
    
    class ConfirmOrder extends \Espo\Core\EntryPoints\Base
    {
        public static $authRequired = false; // This requires the user to be authenticated.
    
        public function run()
        {
            $entityManager = $this->getContainer()->get('entityManager');
    
            $id = $_GET['id'] ?? null;
    
            if (!$id) {
               $this->displayMessage('fehlende Bestell-ID.');
                exit;
            }
    
            $shoppingList = $entityManager->getEntity('Einkaufsliste', $id);
            
            if (!$shoppingList) {
                $this->displayMessage('Bestellung nicht gefunden.');
                exit;
            }
    
            $status = $shoppingList->get('status');
            $eDatum = $shoppingList->get('einkaufsdatum');
            $lDatum = $shoppingList->get('lieferdatum');
            $lieferant = $shoppingList->get('lieferantenName');
            $aktualisierung = $shoppingList->get('modifiedAt');
    
            // Format the dates
            if ($eDatum) {
                $eDatumObj = new \DateTime($eDatum);
                $eDatum = $eDatumObj->format('d.m.Y');
            }
    
            if ($lDatum) {
                $lDatumObj = new \DateTime($lDatum);
                $lDatum = $lDatumObj->format('d.m.Y');
            }
    
            if ($aktualisierung) {
                $aktualisierungObj = new \DateTime($aktualisierung, new \DateTimeZone('UTC'));
                $aktualisierungObj->setTimezone(new \DateTimeZone('Europe/Berlin'));
                $aktualisierung = $aktualisierungObj->format('d.m.Y H:i:s');
            }
    
            // Set the message
            $message = "";
    
            if ($status === 'Bestellt') {
                $shoppingList->set('status', 'Bestätigt');
                $entityManager->saveEntity($shoppingList);
                $message = "<i class='bi bi-check2-circle' style='font-size:54px;color:green'></i><br><font color='green'>Deine Bestellung wurde bestätigt.</font>";
            } elseif ($status === 'Bestätigt') {
                $message = "<i class='bi bi-info-circle-fill' style='font-size:54px;color:red;'></i><br><font color='red'>Diese Bestellung wurde bereits bestätigt.</font>";
            } elseif ($status === 'Geliefert') {
                $message = "<i class='bi bi-truck' style='font-size:54px;color:blue'></i><br><font color='blue'>Diese Bestellung wurde bereits geliefert.</font>";
            } elseif ($status === 'offen') {
                $message = "<i class='bi bi-bag-x' style='font-size:54px;color:red;'></i><br><font color='red'>Diese Bestellung wurde noch nicht freigegeben!</font>";
            }else {
               $message = "<i class='bi bi-bag-x' style='font-size:54px;color:red;'></i><br><font color='red'>Bestellung wurde nicht gefunden!</font>";
            }
    
            $this->displayMessage($status,$message, $eDatum, $lDatum, $lieferant, $aktualisierung);
    
        }
    
        private function displayMessage($status,$message, $eDatum, $lDatum, $lieferant = '', $aktualisierung)
    {
        echo <<<HTML
    <!DOCTYPE html>
    <html lang="de">
    <head>
        <meta charset="UTF-8">
        <title>{$lieferant} - Bestellbestätigung</title>
        <link href="https://icons.getbootstrap.com/assets/font/bootstrap-icons.min.css" rel="stylesheet">
        <link rel="stylesheet" href="client/css/espo/espo.css">
        <link rel="stylesheet" href="client/modules/KurtTheme/css/espo/modern.css?r=1696956647" id='main-stylesheet'>
        <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.min.js" integrity="sha384-BBtl+eGJRgqQAUMxJ7pMwbEyER4l1g+O15P+16Ep7Q9Q+zqX6gSbd85u4mG4QzX+" crossorigin="anonymous"></script>
        <script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
    
    </head>
    <body background-color="#A4876A">
    <style>
    .box {
      position: relative;
      width: 600px;
      height: 600px;
      background: #fff;
      box-shadow: 0 0 15px rgba(0,0,0,.1);
    }
    
    /* common */
    .ribbon {
      width: 150px;
      height: 150px;
      overflow: hidden;
      position: absolute;
    }
    .ribbon::before,
    .ribbon::after {
      position: absolute;
      z-index: -1;
      content: '';
      display: block;
      border: 5px solid #A4876A;
    }
    .ribbon span {
      position: absolute;
      display: block;
      width: 225px;
      padding: 15px 0;
      background-color: #A4876A;
      box-shadow: 0 5px 10px rgba(0,0,0,.1);
      color: #fff;
      font: 700 18px/1 'Lato', sans-serif;
      text-shadow: 0 1px 1px rgba(0,0,0,.2);
      text-transform: uppercase;
      text-align: center;
    }
    
    /* top right*/
    .ribbon-top-right {
      top: -10px;
      right: -10px;
    }
    .ribbon-top-right::before,
    .ribbon-top-right::after {
      border-top-color: transparent;
      border-right-color: transparent;
    }
    .ribbon-top-right::before {
      top: 0;
      left: 0;
    }
    .ribbon-top-right::after {
      bottom: 0;
      right: 0;
    }
    .ribbon-top-right span {
      left: -25px;
      top: 30px;
      transform: rotate(45deg);
    }
    
    .panel {
     box-shadow: none !important;
    }
    
    </style>
    <div class="container box">
        <div class="ribbon ribbon-top-right"><span>{$status}</span></div>
        <div class="panel panel-default block-center-md margin-top-2x">
            <div class="panel-body">
                <center><img src="Path to the image file" width="50%"></center>
                <h1 class="text-3em text-soft margin-bottom-4x" align="center" style="text-shadow: #FC0 1px 0 10px;">Bestell-Status</h1>
                <p class="text-large" align="center">{$message}</p>
                <br>
                <table align="center" border="0" width="75%" style="box-shadow: 0px 0px 12px 7px rgba(164, 135, 106, 1);padding:5px;">
                    <tr>
                        <td colspan="3" align="center"><h4><u>Bestelldetails</u></h4></td>
                    </tr>
                    <tr>
                        <td width="50%" align="right"><b>Bestelldatum:</b></td>
                        <td>&nbsp;</td>
                        <td>{$eDatum}</td>
                    </tr>
                    <tr>
                        <td align="right"><b>Lieferdatum:</b></td>
                        <td>&nbsp;</td>
                        <td>{$lDatum}</td>
                    </tr>
                    <tr>
                        <td align="right"><b>Lieferant:</b></td>
                        <td>&nbsp;</td>
                        <td>{$lieferant}</td>
                    </tr>
                    <tr>
                        <td align="right"><b>letzte Aktualiserung:</b></td>
                        <td>&nbsp;</td>
                        <td>{$aktualisierung}</td>
                    </tr>
                    <tr>
                        <td colspan="3">&nbsp;</td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    </body>
    </html>​
    Click image for larger version

Name:	Screenshot 2023-10-29 22.08.07.png
Views:	308
Size:	84.4 KB
ID:	99191

    Leave a comment:


  • Kharg
    replied
    Created an EntryPoint for ChrisSka83

    custom/Espo/Custom/EntryPoints​



    ?entryPoint=ConfirmOrder&id={id}

    ConfirmOrder.php
    PHP Code:
    <?php
    namespace Espo\Custom\EntryPoints;
    class ConfirmOrder extends \Espo\Core\EntryPoints\Base
    {
        public static $authRequired = false; // This requires the user to be authenticated.
        public function run()
        {
            $entityManager = $this->getContainer()->get('entityManager');
            $id = $_GET['id'] ?? null;
            if (!$id) {
               $this->displayMessage('Missing Order ID.');
                exit;
            }
            $shoppingList = $entityManager->getEntity('ShoppingList', $id);
            if (!$shoppingList) {
                $this->displayMessage('Order not found.');
                exit;
            }
            $status = $shoppingList->get('status');
            $message = "";
            if ($status === 'Ordered') {
                $shoppingList->set('status', 'Confirmed');
                $entityManager->saveEntity($shoppingList);
                $message = "Your Order has been confirmed.";
            } elseif ($status === 'Confirmed') {
                $message = "This order has already been confirmed.";
            } elseif ($status === 'Delivered') {
                $message = "Order Delivered";
            } else {
               $message = "Order not found.";
            }​
            $this->displayMessage($message);
        }
    private function displayMessage($message)
    {
        echo <<<HTML
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Order Confirmation</title>
        <link rel="stylesheet" href="client/css/espo/espo.css">
    </head>
    <body>
    <div class="container">
        <div class="panel panel-default block-center-md margin-top-2x">
            <div class="panel-body">
                <h1 class="text-5em text-soft margin-bottom-4x">Status</h1>
                <p class="text-large">{$message}</p>
            </div>
        </div>
    </div>
    </body>
    </html>
    HTML;
    }
    }​​

    Result:

    Click image for larger version  Name:	image.png Views:	0 Size:	11.7 KB ID:	98476
    Last edited by Kharg; 10-10-2023, 05:25 PM.

    Leave a comment:


  • lazovic
    replied
    If you have the Advanced Pack extension installed, no changes to the code are needed; you can use Tracking URLs with BPM: https://docs.espocrm.com/administrat...-tracking-urls.

    Leave a comment:


  • Kharg
    commented on 's reply
    I will PM you

  • ChrisSka83
    replied
    Thank you very much for your help.
    The entity is called : Shopping list
    Status: Open, Ordered, Confirmed, Delivered
    This is now in english, but I can change it to german?

    Which folder do you need exactly?​

    Leave a comment:


  • Kharg
    replied
    I can see if I find some time to help you,

    what’s the entity name?
    status value?

    can you share the custom folder?

    Leave a comment:


  • ChrisSka83
    replied
    Kharg, thanks for your quick reply. Unfortunately, my programming skills are not sufficient so far.

    Leave a comment:


  • Kharg
    replied
    Yes, possible with both a controller or an entrypoint, If your programming skills are good enough you can ask ChatGPT to write the code for you and then you fix the bugs manually.

    should’t be that hard.

    Leave a comment:


  • ChrisSka83
    started a topic Change status via link, is that possible?

    Change status via link, is that possible?

    Hello all.
    I have a special question for the professionals.

    Is it possible to change a status via a link?
    In the way as with the appointments (Accept/Reject).

    My thought:
    We create our orders via Espo, write a mail to the supplier and set the status to "Ordered".
    Now there should be a link in the mail with "Confirm" and the status changes to "Confirmed" instead of waiting for his reply and changing it manually.

    Would something like this be possible? If not, also not bad.​
Working...