Need help finishing a piece of code

i-Bead
New Member
2 0 1

Good morning all.  I’m working on a task to help my staff save time.  I’ve taken the “Generate a report of orders that still require payment” from the Mechanic App tasks and tweaked it to become a daily CSV sales report of orders processed [say] today (meaning actual capture of payment and fulfilment, as long as the orders haven’t been archived yet).  Everything works like a charm!  

Now the part where I’ve gotten hung up on again (happens too often)…. I would like for the last line of the report to show TOTALS in column[0] and the total sum of each column in their appropriate row.  (just like would can do/would do in Excel)  Is this doable?  And if yes… How?  Spend all night trying and searching Google for answers and haven’t found anything useful yet.  

PS…..  if you’re reading the code and wonder why I have the prepend $…  I was getting a weird <span> thing going on when I used the ” | money” filter.

 

 

 

{% assign orders = shop.orders %}
{% assign orders_to_report = orders.paid | concat: orders.partially_paid %}
{% if orders_to_report == empty and event.preview != true %}
  {% log "Zero orders found - skipping email. :)" %}
{% else %}
  {% assign rows = array %}
  {% assign header = array %}
  {% assign header[0] = "ORDERS" %}
  {% assign header[1] = "VISA" %}
  {% assign header[2] = "MASTERCARD" %}
  {% assign header[3] = "AMEX" %}
  {% assign header[4] = "PAYPAL" %}
  {% assign header[5] = "E TFR" %}
  {% assign rows[0] = header %}
 {% for order in orders_to_report %}
   
{% assign row = array %}
{% for tag in order.tags %}
{% if order.tags contains 'Scanned'%}
  {% assign row[0] = order.name %}
  {% for credit_card_company in order.transactions[0].payment_details.credit_card_company %}
    {% if order.transactions[0].payment_details.credit_card_company == 'Visa' %}
      {% assign row[1] = order.total_price | prepend: '$'  %}
    {% endif %}
  {% endfor %}
  {% for credit_card_company in order.transactions[0].payment_details.credit_card_company %}
    {% if order.transactions[0].payment_details.credit_card_company == 'Mastercard' %}
      {% assign row[2] = order.total_price | prepend: '$' %}
    {% endif %}
  {% endfor %}
  {% for credit_card_company in order.transactions[0].payment_details.credit_card_company %}
    {% if order.transactions[0].payment_details.credit_card_company == 'American Express' %}
      {% assign row[3] = order.total_price | prepend: '$' %}
    {% endif %}
  {% endfor %}
  {% for gateway in order.transactions[0].gateway %}
    {% if order.transactions[0].gateway == 'paypal' %}
      {% assign row[4] = order.total_price | prepend: '$' %}
    {% endif %}
  {% endfor %}
  {% for gateway in order.transactions[0].gateway %}
    {% if order.transactions[0].gateway == 'E Transfer' %}
      {% assign row[5] = order.total_price | prepend: '$' %}
    {% endif %}
  {% endfor %}
{% assign rows[rows.size] = row %} 
{% endif %}
{% endfor %}
{% endfor %}
  {% action "email" %}
    {
      "to": {{ options.recipient_email_address__email_required | json }},
      "subject": {{ options.email_subject__required | json }},
      "body": {{ options.email_body__required_multiline | strip | newline_to_br | json }},
      "reply_to": {{ shop.customer_email | json }},
      "from_display_name": {{ shop.name | json }},
      "attachments": {
        {{ options.csv_attachment_filename__required | replace: ".csv", "" | append: ".csv" | json }}: {{ rows | csv | json }}
      }
    }
  {% endaction %}
{% endif %}

 

 

  

0 Likes