Announcement

Collapse
No announcement yet.

new formula dateTime->modify

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • new formula dateTime->modify

    Hello,
    we have outOfBox : addMonths, addYears, .. .

    is not better so : .. so we can add and substract . like ModifyMonth(createAt, 3) . or ModifyMonth(createAt, -3)

    Regards


    PHP Code:
    namespace Espo\Custom\Core\Formula\Functions\DatetimeGroup;

    use 
    \Espo\Core\Exceptions\Error;

    class 
    ModifyMonth extends \Espo\Core\Formula\Functions\Base
    {
        public function 
    process(\StdClass $item)
        {
            if (!
    property_exists($item'value')) {
                return 
    true;
            }

            if (!
    is_array($item->value)) {
                throw new 
    Error();
            }

            if (
    count($item->value) < 2) {
                 throw new 
    Error();
            }

            
    $dateValue $this->evaluate($item->value[0]);
            
    $modifyValue $this->evaluate($item->value[1]);

            
    $date = new \DateTime($dateValue);
            
    $date->modify$modifyValue .' month'); 
            return 
    $date->format('Y-m-d');
        }


  • #2
    item the god, the myth, the legend! Life saver!!!
    I'm trying to do something like this from one hour

    You should release an extension I don't know why Espo devs didn't add this formulas..

    Comment


    • item
      item commented
      Editing a comment
      Lol... the god, the legend, the myth is Yuri !
      maybe you need adapt to v6.. see espo/core/formula for sample.

      i will use a expression of telecastg : you are welcome

  • #3
    item yes, you're right, but today you've maid my day, because I was working on something from 6 months and I couldn't complete that without your idea to create own formula!
    I've already created extension with custom formula which allow me to subtract days compatible with 6+.
    But I don't want to publish because it was your idea

    Thanks again

    Comment


    • #4
      Hello emillod
      i think the big problem is :
      formula in entity manager is and must be used by "non developper skill" ...
      i think it's why some formula is not like php...and i understand this.

      else.. you can write all in formula .. this espoCRM is incredible

      i think.. my idea is nothing... you are free ... but ...i have no skill for make extension..
      why not make some place .. where we push (i have not skill for github).. and make a big extension ? with many formula ?


      next step will be action for workflows

      Regards

      Comment


      • #5
        item i've made repo public on github to show you how i adjusted formular to the newest version. And it's working, i even installed that on production.. :P
        https://github.com/dubas-pro/ext-cus...CustomFormulas

        I have nothing against creating one extension with many formulas, as you can see here in formula.json we can set many formulas.
        I've changed few things in code to make it more universal. Now you can add, you can substract, you can operate on days, months, years, whatever you want.

        If you have any ideas for formulas i'll be more than happy to collaborate and publish somewhere, even here. Github is simple, transparent, that's why we're using it for public projects

        Comment


        • #6
          Hello,
          this i find it very util but need "google search" for find the good "patern"

          PHP Code:
          use \Espo\Core\Exceptions\Error;

          class 
          PregReplace extends \Espo\Core\Formula\Functions\Base
          {
          public function 
          process(\StdClass $item)
          {
          if (!
          property_exists($item'value')) {
          throw new 
          Error();
          }

          if (!
          is_array($item->value)) {
          throw new 
          Error();
          }

          if (
          count($item->value) < 2) {
          throw new 
          Error();
          }

          $pattern $this->evaluate($item->value[0]);
          $replacement $this->evaluate($item->value[1]);
          $string $this->evaluate($item->value[2]);
          // "/[^0-9]/"
          return preg_replace$pattern $replacement$string);
          }

          Comment


          • #7
            I have this too but need a api ..
            for longitude : same but juste change latitute to longitude word
            i have make something with openstreetMap .. but can't integrate with my skill in espo. if i find it .. (i have changed computer).. i will post .. but i think i have posted on forum.
            edit : find-it : https://forum.espocrm.com/forum/exte...-click-to-view

            Why i put lat/lon in database : because one call ! so after map are rendered with data in database, no need to call external API.

            PHP Code:

            class Latitude extends \Espo\Core\Formula\Functions\Base
            {
            public function 
            process(\StdClass $item)
            {
            if (!
            property_exists($item'value')) {
            throw new 
            Error();
            }

            if (!
            $item->value[0]) {
            throw new 
            Error();
            }

            $opts = [
            'http' => [
            'method'=>"GET",
            'header'=>"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) \r\n"
            ]
            ];
            $street str_replace (' ''+',$this->evaluate($item->value[0]));
            $postalCode str_replace (' ''+',$this->evaluate($item->value[1]));
            $city str_replace (' ''+',$this->evaluate($item->value[2]));
            $state str_replace (' ''+',$this->evaluate($item->value[3]));
            $address $street .'+' .$postalCode .'+' .$city .'+' .$state;
            $url "https://geocoder.api.here.com/6.2/geocode.json?".urlencode("app_id=YOUR_API&app_code=YOUR_APP_CODE&searchtext={$address}");
            $context stream_context_create($opts);
            $jsonfile file_get_contents($urlfalse$context);
            $result json_decode($jsonfiletrue);
            return 
            $result['Response']['View'][0]['Result'][0]['Location']['DisplayPosition']['Latitude'] ;
            }

            Last edited by item; 02-07-2021, 10:45 PM.

            Comment


            • #8
              item if there is required API, i could prepare integration screen where user will be able to enter API key and without that formula will throw an error
              Here you have screenshot from my current project: https://i.imgur.com/og8Rcyo.png

              Comment


              • item
                item commented
                Editing a comment
                Hello emillod,
                the problem with this "openStreetMap" .. is not upgrade safe.. and the problem is front-end.

                i have not understand .. how googleMap integration work.. so the problem is say to espoCrm : map is rendered by openStreetMap.

                So when you add "Map" on detailView.. somewhere need to say : this map come from googleMap or openStreetMap..


              • emillod
                emillod commented
                Editing a comment
                item i believe we could just create different type of field?

              • item
                item commented
                Editing a comment
                @emillod,

                maybe is the solution.. really not understand front-end of "map field"..
                the map appear only if .. (in my memory when we active googleApi in setting)

                As i see, Yuri make refactoring for all and now we still use TCPDF as engine.. but we can change-it (if someone create new pdf engine) .. so i imagine is same with googleMap.

                Maybe solution is make new Field Type ..but i think is more better to ask to Yuri to how use alternative map engine

                I think this is the key .. and it's out of my knowledge... the mythe is dead
                Last edited by item; 02-09-2021, 07:10 PM.
            Working...
            X