Announcement

Collapse
No announcement yet.

Learning EspoCRM and Design

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

  • #91
    So, today I want to create a PDF Template that list all the people face and their name and came up with this formula after a while, feel free to use.

    nameAlt is a custom field, I use this field as the nickname or main name. Sometime legal name is not the wanted name so we create this field. There is also special characters as well.

    As for photoIDid - this is an image field, I use this field to upload people face.

    the "#unless" tag is basically like this, "if nameAlt is blank" then show First Name, if there is a nameAlt, then it show the Name Alternative.

    Code:
    {{#each contacts}} {{#ifMultipleOf @key 3}}
    {{/ifMultipleOf}}{{imageTag photoIDId width=100 height=100}} {{#unless nameAlt}} {{firstName}}{{else}} {{nameAlt}} {{/unless}} {{/each}}
    Here is a sample.

    Data: Click image for larger version

Name:	image.png
Views:	607
Size:	25.4 KB
ID:	84983

    Template Result: Click image for larger version

Name:	image.png
Views:	524
Size:	47.6 KB
ID:	84984

    The first guy, Test no Photo.

    ----

    One thing I want to do is like this but I haven't figure out how to do it with the code yet.

    [photo] [photo] [photo]
    Name [name] [name]

    Comment


    • shalmaxb
      shalmaxb commented
      Editing a comment
      to have a layout in three columns per row, you will have to create a HTML-table, the caption would be another row.
      I will test your PDF-formula with one of my entities later.

    • esforim
      esforim commented
      Editing a comment
      Thank shalmaxb, the documents said it will break the system if I try to do that. And the name will be on another row wouldn't it?

      It be like this instead.

      [photo1] [photo2] [photo3]
      [photo4] [photo5] [photo6]

      [Name1] [name2] [name3]
      [Name4] [name5] [name6]

      From: https://docs.espocrm.com/user-guide/printing-to-pdf/
      "Note: Using <tr> and <td> tags along with {{#each}} helper is not recommended, since it breaks a layout of a contenteditable element."

  • #92
    Look like I found a hidden update and feature that wasn't announce, or I have overlook or forgotten about it!

    The image field, now we can drag and drop image into the field from a photo online/URL! No longer do I have to save the file and upload it. The downside is I become lazy, I don't save a backup image offline, and don't rename it. It mean I will totally be relying on EspoCRM and need to ensure I make backup often.

    ---

    Another feature I recently discover, which probably in the system for years now. With the Knowledge Base, there is an option, "Send to Email", which will directly copy what you write into the email! I never tried this till yesterday when I wanted to print out the PDF of it. PDF Printing made all my image look weird, but if I use the Send to Email, it look the same as what I see in the Knowledge Base. If only Print to PDF "default" {body} tag can do this!

    Comment


    • esforim
      esforim commented
      Editing a comment
      Perhaps this feature is a long time already, I was trying this on Firefox and realize it doesn't work! It look like it browser by browser?

      I know Chrome and Edge work but this seem to be the weakness of Firefox.

  • #93
    Hi all,

    FORMULA info

    This is probably not hard for most people but in case people who having trouble or want to copy/paste the code. I recently create this code to calculate 2 'fee' structure (tax). Initially I used 'ifThenElse' but it got messy and I keep getting syntax error and can't figure out where the error is! So I went with a simpler version of, "if between this number then calculate"

    Please update it to your correct field name and calculation.

    Code:
    //Calculate Tax
    ifThen(salePrice > 10000, Tax = (100+(0.5*(salePrice-10000))));
    ifThen(salePrice > 9000 && salePrice <= 10000, Tax= 0.055*salePrice);
    ifThen(salePrice > 2000 && salePrice <= 9000, Tax= (500+(0.10*(salePrice-2000))));
    ifThen(salePrice > 0 && salePrice <= 2000, Tax= 0.020*salePrice);
    
    //Calculate Admin Fee
    AdminFee = number\ceil(50.50+(2.5*number\round(salePrice/1000, 0)));​
    Now to explain:

    Sale Price = price selling/buying at
    Tax is field I create to calculate these.
    > greater than
    && I want a range check not just 1
    <= less than or equal to, if I don't use && it won't work

    number\ceil - I want to down it up because the tax man want it round. They don't like cents. ($0.10 for example, they want $1.00)
    round(salePrice/1000), because they also want to do round here as well.

    I have to have these because each $ range got different tax bracket. Not sure if you country is the same or it might be linear and you don't need to worry about this at all.

    Hopefully this help with someone.

    See Documents here: https://docs.espocrm.com/administration/formula/

    Comment


    • #94
      Was looking for OpenSource & Self Host new thing I can give it a try and came across quite a few EspoCRM on Reddit.

      Saw someone create a 'sub-category' here if anyone into Reddit. Look like the very first post is a Tutorial/Guide:

      Comment


      • #95
        Hi all, more learning. I finally played with sumRelated formula. And since there is no hope of having a "invoice" like adding for Accounting I created my own Accounting entity instead.

        Here is some photo for your reference. And here is a formula I create to do calculation. I link it to Case entity as a Many to Many.

        At the end of the day you want it to balance to $0.

        I also played with "variable" as well for the first time using formula. Rather than creating many field, I create a single field call, "accountingCalculation" to do all my calculation. I added \n so it appear in a new line instead of altogether.

        Code:
        //Calculate AccountingCase
        $credit = entity\sumRelated('accountings', 'credit');
        $debit = entity\sumRelated('accountings', 'debit');
        accountingCalculation = string\concatenate(
            'Credit: ', $credit, '\n', 'Debit: ', $debit,  '\n', 'Balance is: ', $credit-$debit
            );​
        Screenshot time:
        Click image for larger version

Name:	image.png
Views:	586
Size:	7.1 KB
ID:	86384
        Click image for larger version

Name:	image.png
Views:	486
Size:	16.1 KB
ID:	86385
        Click image for larger version

Name:	image.png
Views:	494
Size:	36.0 KB
ID:	86386

        Comment


        • #96
          Originally posted by espcrm View Post

          Code:
          //Calculate AccountingCase
          $credit = entity\sumRelated('accountings', 'credit');
          $debit = entity\sumRelated('accountings', 'debit');
          accountingCalculation = string\concatenate(
          'Credit: ', $credit, '\n', 'Debit: ', $debit, '\n', 'Balance is: ', $credit-$debit
          );​
          Restyle to have the $ sign:

          Code:
          accountingCalculation = string\concatenate(
          'Credit: ', $credit, '\n',
          'Debit: ', $debit, '\n',
          'Balance is: ', $credit-$debit, '\n',
          'Calculate: ', '$',number\format($credit,0), ' - $', number\format($credit,0), ' = $', number\format($credit-$debit,0)
          );​
          Click image for larger version  Name:	image.png Views:	0 Size:	9.3 KB ID:	86389

          You can add decimal place by changing this:

          number\format($credit-$debit,2)

          For example:
          $1,300.00

          Comment


          • esforim
            esforim commented
            Editing a comment
            Now that I'm adding more and more formula... I wonder how much it will slow down EspoCRM

          • shalmaxb
            shalmaxb commented
            Editing a comment
            I use hundreds of formulas in one app and do not perceive any slow down.

          • esforim
            esforim commented
            Editing a comment
            Are you on Shared Hosting though shalmaxb? We don't have much PHP Cache and RAMs on ours. I'm using Case as my main location so I will see if there is a performance drop that is noticeable as I think of more formula.

            I'm doing more and more calculation recently since I want to move away from Excel for Simple Calculation

            Looking at my Accounting entity, look like it possible for me to create my next goal, "Payslip/Payroll/Paystub" system... but I still need to solve 2 issue which may be possible using "Filter" in the sumrelated formula but need to learn how to use this Filter part.

            Second issue is PDF is still very ugly print, simple template is OK if you just want information but if we want to print for other business they won't be satisfy with 'plain looks'.
            Last edited by esforim; 12-19-2022, 06:49 AM.

        • #97
          Couldn't find where I put this sample code; basically I got a custom Entity I call "Asset", from Asset I link it to Many-Many with Contact. But I only want to filter 2 special asset for one of my PDF Template.

          What Car they Drive and their Bank Account. I achieve this with this code here.

          Code:
          {{#each assets}}{{#ifEqual assetType "Bank Account"}}{{name}}
          BankNumber: {{accountBankNumber}} | Account Number: {{accountNumber}} {{else}} {{/ifEqual}}
          {{/each}}
          {{#each assets}} {{#ifEqual assetType "Car"}}
          {{name}}
          Car: {{assetMainCode}} {{else}} {{/ifEqual}} {{/each}}​
          Last edited by esforim; 01-03-2023, 11:01 PM.

          Comment


          • #98
            Just a quick code, very simple to people get idea that they can use. nameAlt is a custom field which I use to write either their nickname or the true first name. Some people name is out of order due to their legal paperwork.

            Code:
             {{name}} {{#if nameAlt}}(a.k.a. {{nameAlt}}){{/if}}
            My details view
            Click image for larger version  Name:	image.png Views:	0 Size:	25.4 KB ID:	86773

            PDF Print Out
            Click image for larger version  Name:	image.png Views:	0 Size:	9.0 KB ID:	86774

            Comment


            • #99
              Wow this thread started so long ago:
              01-09-2020

              Anyway I saw a contributor on the 'wiki' and got excited enough to make edit, it should look slightly better but the general concept still the same...
              It doesn't look professional and cool but if you can change it go for it. There is no minimum standard and Quality Control at the moment.

              With all that said, this post is just to say that and hopefully we can recruit more contributor to making edit.
              Last edited by esforim; 03-09-2023, 04:25 AM.

              Comment


              • Thank to shalmaxb for asking this question, allowing me to update a lost feature I wasn't aware of!

                The result is here: https://github.com/o-data/EspoCRM_Mo...r%20RealEstate

                Here is the learning, the learning is below:

                EDIT EDIT: IGNORE EVERYTHING! I figure it out, I didn't see this other 'code' I need to change. This is what happen when you don't code. All seem to be working now! (I think). Just need to try enable on "Upon Update" somewhere now.

                Code:
                class Lead implements WhereBuilder​
                shalmaxb Would you mind looking at my code, I pretty much copy/paste from the documents and change very little but getting a Error 500 file not found for the class. I put my code here:​






                Please note that I tried without the .php and same error. Look like I'm doing something wrong still.

                Reading the documents, not sure which is correct or it dont matter: one Duplicate\WhereBuilder the other DuplicateWhereBuilder

                ​​​

                Interesting, if I change it to Lead it have no issue. So where does this go wrong.

                I change the Filename from Lead.php to Lead1.php, did a test without rebuilding/cache and it will instantly popup "Error 500". So there I just need to figure out this filename issue?

                Log Error:
                [2023-03-22] ERROR: (0) InjectableFactory: Class 'Espo\Custom\Classes\DuplicateWhereBuilders\RealEs tateProperty' does not exist.; POST /RealEstateProperty; line: 114, file: /home/username/domains/website.com/public_html/app/application/Espo/Core/InjectableFactory.php [] []

                I look at this file and don't see anything I can do with it. Is it because I'm doing this for a Custom Entity?​

                Comment


                • Sorry telecastg I like to ask you it solution with TextMyMail is still working with you. I can not login to gmail account. i can install app on Android Phone but not login into application. Is there something it must be done on gmail account

                  Comment


                  • LEARNING SUMMARY: Add Incoming SMS to EspoCRM Call/Custom Entity

                    Hi all,

                    Recently discover this App for Android (Free, Open-source project): https://github.com/bogkonstantin/and...ateway_webhook

                    What does it do? It forward all your Incoming SMS to a Webhook website through a "POST" request. I'm pretending to know jardon here, anyway it will send your SMS/Text Message on your phone to a website.

                    You can either do it for all phone SMS or just a specific numbers, in the tutorial below I will use All phone number since I'm using a Work phone for this purpose.

                    In term of setting, after many fail trial and error I figured it out and we can just use the default setting of it. You can trim down the data to save Internet Data...

                    Once you download the App and install it will ask for 3 information:
                    1) Phone number you want to forward (* for all and any)
                    2) Website of the Webhook/Server*. I use Pipedream as my webhook server, I will look in the future where I can self-host a Webhook but for now using this will get me (and whoever reading this) quickly start on this project.
                    3) Default data it.

                    Pipedream/Webhook server is here: https://pipedream.com
                    You can use other webhook server but I can't help you there, I tried a few available and Pipedream seem 'best' at the moment. Once you create a Pipedream Account, just create a new Workflow and choose Trigger as HTTP URL (see screenshot). As for the Action, choose Send any HTTP Request as EspoCRM isn't an available app (yet!).

                    Choose Post. Add in your website.
                    Add this to your Headers: X-Api-Key as for the hidden key, create a API user for this and copy the API Key. Be sure to give the API User the Role to Assigned User, otherwise you will get a 404.

                    I skip some explanation so if you got any question, feel free to ask me.


                    Click image for larger version

Name:	image.png
Views:	538
Size:	79.4 KB
ID:	90197

                    Comment


                    • Originally posted by espcrm View Post
                      LEARNING SUMMARY: Add Incoming SMS to EspoCRM Call/Custom Entity
                      Hi all,

                      I managed to fix the dateStart issue! (I think), need a to wait a see as I slowly hopefully resolve this one by one as I dive into the scary world of Coding.

                      Here how I manage to transform the date to a EspoCRM readable format without having validation issue.

                      You add this javascript/nodeJS before the Events in Pipedream. I'm starting to like to Pipedream more and more!

                      Anyway here is the code and the new Post. Next I need to figure out is how to make 'new lines' \n work because it failing at the moment.

                      Javascrip NODE JS
                      Code:
                      export default defineComponent({
                        props:{
                          sentStamp: {
                            type: "string",
                            label: "Start Date",
                            description: "Date that it was send"
                            }
                        },
                          async run({ steps, $ }) {
                          const unixTimestamp = this.sentStamp; // Example Unix timestamp;
                          const date = new Date(unixTimestamp);
                          const formattedDate = date.toISOString().replace(/T/, ' ').replace(/\..+/, '');
                          console.log(formattedDate);
                          return {EspoDate1: formattedDate}
                          },
                      })​
                      HTTP post
                      Code:
                      {
                      "name": "SMS from {{steps.trigger.event.from}}",
                      "smsMessage": "{{steps.trigger.event.text}}",
                      "phoneNumber": "{{steps.trigger.event.from}}",
                      "dateStart": "{{steps.code.$return_value.EspoDate1}}",
                      "dateEnd":{{steps.trigger.event.receivedStamp} }
                      "type": "SMS",
                      "direction": "Inbound",
                      "Status": "Held"
                      }
                      Last edited by esforim; 04-05-2023, 06:17 AM.

                      Comment


                      • More success! Manage to resolve the 2nd 'bug'. Convert the new lines to work. I have to create two separate code, if anyone know how I can merge it into one that that help clean up.

                        I'll see how it go for few more days and make a 'final' version on my Github (maybe).

                        Anyway here is the code use to convert, I kept everything the same from a tutorial I found online, and only change a few thing to make life easier for me to read, as long as it work I don't care about formatting and coding style at the moment.

                        Anyway here goes;

                        Code:
                        export default defineComponent({
                          props:{
                            description: {
                              type: "string",
                              label: "Description",
                              description: "New lines transform"
                              }
                          },
                            async run({ steps, $ }) {
                            const str = this.description;
                            const convertedStr = str.replace(/\r?\n/g, '\\n');
                            console.log(convertedStr);
                            return {EspoDescription: convertedStr}
                            },
                        })​
                        ​
                        I guess my next Goal is to add "Contact Name" or search a link to a Parent Contact relation because right now the Android App showing Phone Number Only... Maybe someone can teach me with this because I have a feeling I won't get too far.

                        Comment


                        • Be sure to go back to those fail one and "Replay" it, so it will get add to your EspoCRM.

                          With spinning top right of the icon are my "replay".
                          Click image for larger version

Name:	image.png
Views:	357
Size:	13.8 KB
ID:	90270

                          Comment


                          • esforim
                            esforim commented
                            Editing a comment
                            I found an app call Tasker and MacroDroid which can do HTTP Request... Hmm I wonder if I can take advantage of this feature to do something. Need to have a think.

                            Or if anyone already done something with it, please do share.
                        Working...
                        X