From 71eada5d680b5a610f1f4c357252c2ce4181c3d2 Mon Sep 17 00:00:00 2001
From: Jules Laplace <jules@okfoc.us>
Date: Mon, 24 Apr 2017 08:18:50 -0400
Subject: order date, filter pending

---
 client/components/OrderList.jsx | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

(limited to 'client/components/OrderList.jsx')

diff --git a/client/components/OrderList.jsx b/client/components/OrderList.jsx
index 1061f91..c21109f 100644
--- a/client/components/OrderList.jsx
+++ b/client/components/OrderList.jsx
@@ -3,6 +3,8 @@ import state_lookup from '../state_lookup'
 import saveAs from 'browser-saveas'
 import csvStringify from 'csv-stringify'
 
+const SR_REGEXP = /(Sr|Jr|I|II|III|IV)\.?$/i
+
 export default class OrderList extends React.Component {
   constructor(props) {
     super()
@@ -10,12 +12,23 @@ export default class OrderList extends React.Component {
   }
   downloadCsv() {
     const orders = this.parseOrders().map((order) => {
+      let name = order.order_ship_name.replace(/&quot/g,'\"').split(" ")
+      let lastName = name.pop()
+      if (lastName.match(SR_REGEXP)) {
+        lastName = name.pop() + " " + lastName
+      }
+      const firstName = name.join(" ")
+      const date_partz = order.order_date.split("T")
+      const date = date_partz[0]
+      const time = date_partz[1].replace(/\:\d\d\.\d\d\dZ/,"")
       return [
         order.order_id,
-        order.order_date,
+        date,
+        time,
         order.order_checkout_type,
-        order.order_ship_name,
-        order.order_company,
+        firstName,
+        lastName,
+        (order.order_company && order.order_company !== order.order_ship_name) ? order.order_company : "",
         order.order_address1,
         order.order_address2,
         order.order_city,
@@ -34,11 +47,11 @@ export default class OrderList extends React.Component {
     return this.props.orders.filter( (order) => {
       // also filter where order.order_status == 3 (paid in full) ?
       // filter weird blank orders if found
-      return !! order.order_ship_name
+      return !! order.order_ship_name && (order.order_status == 3 || order.order_status == 4)
     }).map( (order, i) => {
       const name = order.order_ship_name
         .toUpperCase()
-        .replace(/(Sr|Jr|I|II|III|IV)\.?$/i, "")
+        .replace(SR_REGEXP, "")
         .split(" ")
         .reverse()[0]
       return [ name, order ]
@@ -74,7 +87,7 @@ export default class OrderList extends React.Component {
       if (order.order_company && order.order_company !== order.order_ship_name) {
         order_name = (
           <span>
-            {order.order_ship_name}<br />
+            {order.order_ship_name.replace(/&quot/g,'\"')}<br />
             {order.order_company}
           </span>
         )
-- 
cgit v1.2.3-70-g09d2

