Subject: [PATCH] Built motion from commit 6ee6b18.|0.0.66

From: Daniele Cinti <[email-masked]>
Date: Tue, 15 Mar 2016 19:03:44 +0100

---
 public/index.html                                  |    4 +-
 release-notes/changelog_0.0.66.txt                 |    1 +
 server/app.js                                      |    2 +-
 server/config/history.js                           |  328 --------------------
 server/config/history/history.js                   |   55 ++++
 server/config/history/reportAgent.js               |   46 +++
 server/config/history/reportCall.js                |   46 +++
 server/config/history/reportChat.js                |   46 +++
 server/config/history/reportChatSession.js         |   46 +++
 server/config/history/reportIntegration.js         |   46 +++
 server/config/history/reportMail.js                |   46 +++
 server/config/history/reportMailSession.js         |   46 +++
 server/config/history/reportMember.js              |   46 +++
 server/config/history/reportQueue.js               |   46 +++
 server/config/history/reportSquare.js              |   46 +++
 server/config/history/reportSquareDetail.js        |   46 +++
 server/config/history/reportTransfer.js            |   46 +++
 server/models/history/report_chat_history.js       |   45 +++
 .../models/history/report_chat_session_history.js  |   35 ++
 server/models/history/report_mail_history.js       |   43 +++
 .../models/history/report_square_detail_history.js |   25 ++
 server/models/history/report_square_history.js     |   89 ++++++
 server/models/history/report_tranfer_history.js    |   25 ++
 23 files changed, 872 insertions(+), 332 deletions(-)
 delete mode 100644 server/config/history.js
 create mode 100644 server/config/history/history.js
 create mode 100644 server/config/history/reportAgent.js
 create mode 100644 server/config/history/reportCall.js
 create mode 100644 server/config/history/reportChat.js
 create mode 100644 server/config/history/reportChatSession.js
 create mode 100644 server/config/history/reportIntegration.js
 create mode 100644 server/config/history/reportMail.js
 create mode 100644 server/config/history/reportMailSession.js
 create mode 100644 server/config/history/reportMember.js
 create mode 100644 server/config/history/reportQueue.js
 create mode 100644 server/config/history/reportSquare.js
 create mode 100644 server/config/history/reportSquareDetail.js
 create mode 100644 server/config/history/reportTransfer.js
 create mode 100644 server/models/history/report_chat_history.js
 create mode 100644 server/models/history/report_chat_session_history.js
 create mode 100644 server/models/history/report_mail_history.js
 create mode 100644 server/models/history/report_square_detail_history.js
 create mode 100644 server/models/history/report_square_history.js
 create mode 100644 server/models/history/report_tranfer_history.js

diff --git a/public/index.html b/public/index.html
index df5c2c7..bdb46d0 100644
--- a/public/index.html
+++ b/public/index.html
@@ -20,7 +20,7 @@
     <!-- END DYMANICLY LOADED CSS FILES -->
 
   </head>
-  <body class="login page-header-fixed page-sidebar-closed-hide-logo page-quick-sidebar-over-content" data-ng-class="{'page-container-bg-solid': settings.layout.pageBodySolid, 'page-sidebar-closed': settings.layout.pageSidebarClosed, 'page-quick-sidebar-open': settings.layout.pageQuickSidebarOpened}">
+  <body class="login page-header-fixed page-sidebar-closed-hide-logo page-quick-sidebar-over-content" ng-class="{'page-container-bg-solid': settings.layout.pageBodySolid, 'page-sidebar-closed': settings.layout.pageSidebarClosed, 'page-quick-sidebar-open': settings.layout.pageQuickSidebarOpened}">
     <!--[if lt IE 7]>
       <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
     <![endif]-->
@@ -31,8 +31,6 @@
         Loadingâ¦
       </div>
     </div>
-
-    <span us-spinner="{radius:30, width:8, length: 16, scale: 0.25}" spinner-key="spinner-grid"></span>
     <!-- END PAGE SPINNER -->
 
     <!-- BEGIN PAGE SPINNER -->
diff --git a/release-notes/changelog_0.0.66.txt b/release-notes/changelog_0.0.66.txt
index 9361b63..25857c0 100644
--- a/release-notes/changelog_0.0.66.txt
+++ b/release-notes/changelog_0.0.66.txt
@@ -1,5 +1,6 @@
 # xCALLY MOTION Changelog
 
+- * 190d31b - 2016-03-15: Changed history move service and added missing history tables. 
 - * 4253e76 - 2016-03-15: migration add migration test file 
 - * c122b65 - 2016-03-15: migration test remove 
 - * 6c220c9 - 2016-03-15: scripts post-mgerge.sh 
diff --git a/server/app.js b/server/app.js
index 5b16a4a..241452e 100644
--- a/server/app.js
+++ b/server/app.js
@@ -102,7 +102,7 @@ models
       .sync();
   })
   .then(function() {
-    require('./config/history')(cronjob);
+    require('./config/history/history')(cronjob);
   })
   .catch(function(err) {
     console.error(err);
diff --git a/server/config/history.js b/server/config/history.js
deleted file mode 100644
index 160778b..0000000
--- a/server/config/history.js
+++ /dev/null
@@ -1,328 +0,0 @@
-'use strict';
-
-var _ = require('lodash');
-var moment = require('moment');
-
-var sequelize = require('../models').sequelize;
-
-var ReportAgent = require('../models').ReportAgent;
-var ReportCall = require('../models').ReportCall;
-var ReportDial = require('../models').ReportDial;
-var ReportMember = require('../models').ReportMember;
-var ReportQueue = require('../models').ReportQueue;
-var ReportIntegration = require('../models').ReportIntegration;
-var ReportMailSession = require('../models').ReportMailSession;
-
-var ReportAgentHistory = require('../models').history.ReportAgentHistory;
-var ReportCallHistory = require('../models').history.ReportCallHistory;
-var ReportDialHistory = require('../models').history.ReportDialHistory;
-var ReportMemberHistory = require('../models').history.ReportMemberHistory;
-var ReportQueueHistory = require('../models').history.ReportQueueHistory;
-var ReportIntegrationHistory = require('../models').history.ReportIntegrationHistory;
-var ReportMailSessionHistory = require('../models').history.ReportMailSessionHistory;
-
-function ReportAgentInReportAgentHistory() {
-  ReportAgent
-    .findAll({
-      where: {
-        createdAt: {
-          $lte: moment().format("YYYY-MM-DD HH:mm:ss")
-        },
-        reason: {
-          $ne: null
-        }
-      },
-      raw: true
-    })
-    .then(function(rows) {
-      console.log('[report_agent] found: ' + rows.length);
-      rows.forEach(function(row, key) {
-        ReportAgentHistory
-          .create(row)
-          .then(function() {
-            console.log('[report_agent] ' + row.id + ' row copied');
-            ReportAgent.destroy({
-              where: {
-                id: row.id
-              },
-              individualHooks: true
-            }).then(function(res) {
-              console.log('[report_agent] ' + row.id + ' row deleted');
-            }).catch(function(err) {
-              console.log('[report_agent] error: ' + err)
-            });
-          })
-          .catch(function(err) {
-            console.log('[report_agent] error: ' + err);
-          });
-      });
-    })
-    .catch(function(err) {
-      console.error('[report_agent] error: ' + err);
-    });
-}
-
-function ReportCallInReportCallHistory() {
-  ReportCall
-    .findAll({
-      where: {
-        createdAt: {
-          $lte: moment().format("YYYY-MM-DD HH:mm:ss")
-        }
-      },
-      raw: true
-    })
-    .then(function(rows) {
-      rows.forEach(function(row, key) {
-        console.log('[report_call] found: ' + rows.length);
-        ReportCallHistory
-          .create(row)
-          .then(function() {
-            console.log('[c] ' + row.id + ' row copied');
-            ReportCall.destroy({
-              where: {
-                id: row.id
-              },
-              individualHooks: true
-            }).then(function(res) {
-              console.log('[report_call] ' + row.id + ' row deleted');
-            }).catch(function(err) {
-              console.log('[report_call] error: ' + err)
-            });
-          })
-          .catch(function(err) {
-            console.log('[report_call] error: ' + err);
-          });
-      });
-    })
-    .catch(function(err) {
-      console.error('[report_call] error: ' + err);
-    });
-}
-
-function ReportDialInReportDialHistory() {
-  ReportDial
-    .findAll({
-      where: {
-        createdAt: {
-          $lte: moment().format("YYYY-MM-DD HH:mm:ss")
-        },
-        dialstatus: {
-          $ne: null
-        }
-      },
-      raw: true
-    })
-    .then(function(rows) {
-      console.log('[report_dial] found: ' + rows.length);
-      rows.forEach(function(row, key) {
-        ReportDialHistory
-          .create(row)
-          .then(function() {
-            console.log('[report_dial] ' + row.id + ' row copied');
-            ReportDial.destroy({
-              where: {
-                id: row.id
-              },
-              individualHooks: true
-            }).then(function(res) {
-              console.log('[report_dial] ' + row.id + ' row deleted');
-            }).catch(function(err) {
-              console.log('[report_dial] error: ' + err)
-            });
-          })
-          .catch(function(err) {
-            console.log('[report_dial] error: ' + err);
-          });
-      });
-    })
-    .catch(function(err) {
-      console.error('[report_dial] error: ' + err);
-    });
-}
-
-function ReportMemberInReportMemberHistory() {
-  ReportMember
-    .findAll({
-      where: {
-        createdAt: {
-          $lte: moment().format("YYYY-MM-DD HH:mm:ss")
-        },
-        exitdate: {
-          $ne: null
-        }
-      },
-      raw: true
-    })
-    .then(function(rows) {
-      console.log('[report_member] found: ' + rows.length);
-      rows.forEach(function(row, key) {
-        ReportMemberHistory
-          .create(row)
-          .then(function() {
-            console.log('[report_member] ' + row.id + ' row copied');
-            ReportMember.destroy({
-              where: {
-                id: row.id
-              },
-              individualHooks: true
-            }).then(function(res) {
-              console.log('[report_member] ' + row.id + ' row deleted');
-            }).catch(function(err) {
-              console.log('[report_member] error: ' + err)
-            });
-          })
-          .catch(function(err) {
-            console.log('[report_member] error: ' + err);
-          });
-      });
-    })
-    .catch(function(err) {
-      console.error('[report_member] error: ' + err);
-    });
-}
-
-function ReportQueueInReportQueueHistory() {
-  ReportQueue
-    .findAll({
-      where: {
-        createdAt: {
-          $lte: moment().format("YYYY-MM-DD HH:mm:ss")
-        },
-        queuecallerleaveAt: {
-          $ne: null
-        }
-      },
-      raw: true
-    })
-    .then(function(rows) {
-      console.log('[report_queue] found: ' + rows.length);
-      rows.forEach(function(row, key) {
-        ReportQueueHistory
-          .create(row)
-          .then(function() {
-            console.log('[report_queue] ' + row.id + ' row copied');
-            ReportQueue.destroy({
-              where: {
-                id: row.id
-              },
-              individualHooks: true
-            }).then(function(res) {
-              console.log('[report_queue] ' + row.id + ' row deleted');
-            }).catch(function(err) {
-              console.log('[report_queue] error: ' + err)
-            });
-          })
-          .catch(function(err) {
-            console.log('[report_queue] error: ' + err);
-          });
-      });
-    })
-    .catch(function(err) {
-      console.error('[report_queue] error: ' + err);
-    });
-}
-
-function ReportIntegrationInReportIntegrationHistory() {
-  ReportIntegration
-    .findAll({
-      where: {
-        createdAt: {
-          $lte: moment().format("YYYY-MM-DD HH:mm:ss")
-        }
-      },
-      raw: true
-    })
-    .then(function(rows) {
-      rows.forEach(function(row, key) {
-        console.log('[report_integration] found: ' + rows.length);
-        ReportIntegrationHistory
-          .create(row)
-          .then(function() {
-            console.log('[c] ' + row.id + ' row copied');
-            ReportIntegration.destroy({
-              where: {
-                id: row.id
-              },
-              individualHooks: true
-            }).then(function(res) {
-              console.log('[report_integration] ' + row.id + ' row deleted');
-            }).catch(function(err) {
-              console.log('[report_integration] error: ' + err)
-            });
-          })
-          .catch(function(err) {
-            console.log('[report_integration] error: ' + err);
-          });
-      });
-    })
-    .catch(function(err) {
-      console.error('[report_integration] error: ' + err);
-    });
-}
-
-function ReportMailSessionInReportMailSessionHistory() {
-  return sequelize.transaction(function(t) {
-    var _reportMailSessions;
-    return ReportMailSession
-      .findAll({
-        where: {
-          createdAt: {
-            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
-          },
-          leaveAt: {
-            $ne: null
-          }
-        },
-        raw: true
-      })
-      .then(function(reportMailSessions) {
-        console.log('[report_mail_session] found: ' + reportMailSessions.length);
-        _reportMailSessions = reportMailSessions;
-        console.log('_reportMailSessions', _reportMailSessions);
-        return ReportMailSessionHistory
-          .bulkCreate(_reportMailSessions, {
-            individualHooks: true,
-            transaction: t
-          });
-      })
-      .then(function() {
-        return ReportMailSession
-          .destroy({
-            where: {
-              id: _.map(_reportMailSessions, 'id')
-            },
-            individualHooks: true,
-            transaction: t
-          });
-      })
-
-  }).then(function(result) {
-    // Transaction has been committed
-    // result is whatever the result of the promise chain returned to the transaction callback
-  }).catch(function(err) {
-    // Transaction has been rolled back
-    // err is whatever rejected the promise chain returned to the transaction callback
-  });
-}
-
-module.exports = function(CronJob) {
-
-  // Every 1 Minute
-  var job = new CronJob({
-    cronTime: '00 59 23 * * *',
-    // cronTime: '* * * * *',
-    onTick: function() {
-      console.log('cronTime onTick');
-      new ReportAgentInReportAgentHistory();
-      new ReportCallInReportCallHistory();
-      new ReportDialInReportDialHistory();
-      new ReportMemberInReportMemberHistory();
-      new ReportQueueInReportQueueHistory();
-      new ReportIntegrationInReportIntegrationHistory();
-      new ReportMailSessionInReportMailSessionHistory();
-    }
-  });
-
-  job.start();
-}
diff --git a/server/config/history/history.js b/server/config/history/history.js
new file mode 100644
index 0000000..ba77c2b
--- /dev/null
+++ b/server/config/history/history.js
@@ -0,0 +1,55 @@
+'use strict';
+
+var Promise = require('bluebird');
+var sequelize = require('../../models').sequelize;
+
+var ReportCall = require('./reportCall');
+var ReportAgent = require('./reportAgent');
+var ReportMember = require('./reportMember');
+var ReportQueue = require('./reportQueue');
+var ReportIntegration = require('./reportIntegration');
+var ReportMailSession = require('./reportMailSession');
+var ReportChat = require('./reportChat');
+var ReportChatSession = require('./reportChatSession');
+var ReportMail = require('./reportMail');
+var ReportSquare = require('./reportSquare');
+var ReportSquareDetail = require('./reportSquareDetail');
+var ReportTransfer = require('./reportTransfer');
+
+module.exports = function(CronJob) {
+
+  // Every 1 Minute
+  var job = new CronJob({
+    // cronTime: '10 * * * * *',
+    cronTime: '0 59 23 * * *',
+    // cronTime: '* * * * *',
+    onTick: function() {
+      console.log('updating history...');
+      var bulkHistory = [ReportCall];
+      return sequelize.transaction(function(t) {
+          return Promise
+            .all([])
+            .then(ReportCall.move(t))
+            .then(ReportAgent.move(t))
+            .then(ReportMember.move(t))
+            .then(ReportQueue.move(t))
+            .then(ReportIntegration.move(t))
+            .then(ReportMailSession.move(t))
+            .then(ReportChat.move(t))
+            .then(ReportChatSession.move(t))
+            .then(ReportMail.move(t))
+            .then(ReportSquare.move(t))
+            .then(ReportSquareDetail.move(t))
+            .then(ReportTransfer.move(t))
+            .then(function() {
+              console.log('history updated');
+            })
+        })
+        .catch(function(err) {
+          console.error(err);
+        });
+    }
+  });
+
+  job.start();
+}
diff --git a/server/config/history/reportAgent.js b/server/config/history/reportAgent.js
new file mode 100644
index 0000000..04523b7
--- /dev/null
+++ b/server/config/history/reportAgent.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportAgent = require('../../models').ReportAgent;
+var ReportAgentHistory = require('../../models').history.ReportAgentHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportAgent
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportAgentHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportAgent
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportAgents history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/config/history/reportCall.js b/server/config/history/reportCall.js
new file mode 100644
index 0000000..b137705
--- /dev/null
+++ b/server/config/history/reportCall.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportCall = require('../../models').ReportCall;
+var ReportCallHistory = require('../../models').history.ReportCallHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportCall
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportCallHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportCall
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportCalls history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/config/history/reportChat.js b/server/config/history/reportChat.js
new file mode 100644
index 0000000..fb1abce
--- /dev/null
+++ b/server/config/history/reportChat.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportChat = require('../../models').ReportChat;
+var ReportChatHistory = require('../../models').history.ReportChatHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportChat
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportChatHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportChat
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportChats history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/config/history/reportChatSession.js b/server/config/history/reportChatSession.js
new file mode 100644
index 0000000..55e52e3
--- /dev/null
+++ b/server/config/history/reportChatSession.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportChatSession = require('../../models').ReportChatSession;
+var ReportChatSessionHistory = require('../../models').history.ReportChatSessionHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportChatSession
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportChatSessionHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportChatSession
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportChatSessions history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/config/history/reportIntegration.js b/server/config/history/reportIntegration.js
new file mode 100644
index 0000000..df9bd35
--- /dev/null
+++ b/server/config/history/reportIntegration.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportIntegration = require('../../models').ReportIntegration;
+var ReportIntegrationHistory = require('../../models').history.ReportIntegrationHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportIntegration
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportIntegrationHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportIntegration
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportIntegrations history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/config/history/reportMail.js b/server/config/history/reportMail.js
new file mode 100644
index 0000000..3bbb2c7
--- /dev/null
+++ b/server/config/history/reportMail.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportMail = require('../../models').ReportMail;
+var ReportMailHistory = require('../../models').history.ReportMailHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportMail
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportMailHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportMail
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportMails history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/config/history/reportMailSession.js b/server/config/history/reportMailSession.js
new file mode 100644
index 0000000..dddde25
--- /dev/null
+++ b/server/config/history/reportMailSession.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportMailSession = require('../../models').ReportMailSession;
+var ReportMailSessionHistory = require('../../models').history.ReportMailSessionHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportMailSession
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportMailSessionHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportMailSession
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportMailSessions history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/config/history/reportMember.js b/server/config/history/reportMember.js
new file mode 100644
index 0000000..c02ab88
--- /dev/null
+++ b/server/config/history/reportMember.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportMember = require('../../models').ReportMember;
+var ReportMemberHistory = require('../../models').history.ReportMemberHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportMember
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportMemberHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportMember
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportMembers history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/config/history/reportQueue.js b/server/config/history/reportQueue.js
new file mode 100644
index 0000000..62856b3
--- /dev/null
+++ b/server/config/history/reportQueue.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportQueue = require('../../models').ReportQueue;
+var ReportQueueHistory = require('../../models').history.ReportQueueHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportQueue
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportQueueHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportQueue
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportQueues history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/config/history/reportSquare.js b/server/config/history/reportSquare.js
new file mode 100644
index 0000000..56d43b2
--- /dev/null
+++ b/server/config/history/reportSquare.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportSquare = require('../../models').ReportSquare;
+var ReportSquareHistory = require('../../models').history.ReportSquareHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportSquare
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportSquareHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportSquare
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportSquares history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/config/history/reportSquareDetail.js b/server/config/history/reportSquareDetail.js
new file mode 100644
index 0000000..3ebf314
--- /dev/null
+++ b/server/config/history/reportSquareDetail.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportSquareDetail = require('../../models').ReportSquareDetail;
+var ReportSquareDetailHistory = require('../../models').history.ReportSquareDetailHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportSquareDetail
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportSquareDetailHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportSquareDetail
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportSquareDetailss history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/config/history/reportTransfer.js b/server/config/history/reportTransfer.js
new file mode 100644
index 0000000..a62b87b
--- /dev/null
+++ b/server/config/history/reportTransfer.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _ = require('lodash');
+var moment = require('moment');
+var ReportTransfer = require('../../models').ReportTransfer;
+var ReportTransferHistory = require('../../models').history.ReportTransferHistory;
+
+exports.move = function(t) {
+  return function() {
+    var _items;
+    return ReportTransfer
+      .findAll({
+        where: {
+          createdAt: {
+            $lte: moment().format("YYYY-MM-DD HH:mm:ss")
+          }
+        },
+        raw: true
+      })
+      .then(function(items) {
+        _items = items;
+        return ReportTransferHistory
+          .bulkCreate(items, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        return ReportTransfer
+          .destroy({
+            where: {
+              id: _.map(_items, 'id')
+            }
+          }, {
+            individualHooks: true,
+            transaction: t
+          });
+      })
+      .then(function() {
+        console.log('updated ReportTransfers history');
+      })
+      .catch(function(err) {
+        console.error(err);
+      });
+  }
+}
diff --git a/server/models/history/report_chat_history.js b/server/models/history/report_chat_history.js
new file mode 100644
index 0000000..fabf94d
--- /dev/null
+++ b/server/models/history/report_chat_history.js
@@ -0,0 +1,45 @@
+/**
+ * Agent Log Model
+ */
+
+var moment = require('moment');
+
+module.exports = function(sequelize, DataTypes) {
+
+  var ReportChatHistory = sequelize.define('ReportChatHistory', {
+
+    uniqueid: DataTypes.STRING,
+    timeslot: DataTypes.INTEGER,
+    websitename: DataTypes.STRING,
+    websiteaddress: DataTypes.STRING,
+    websiteid: DataTypes.INTEGER,
+    application: DataTypes.STRING,
+    agentid: DataTypes.INTEGER,
+    agentname: DataTypes.STRING,
+    visitorid: DataTypes.STRING,
+    visitorname: DataTypes.STRING,
+    visitoremail: DataTypes.STRING,
+    queueid: DataTypes.INTEGER,
+    queuename: DataTypes.STRING,
+    roomid: DataTypes.INTEGER,
+    reason: {
+      type: DataTypes.STRING,
+      defaultValue: 'called'
+    },
+    connectid: {
+      type: DataTypes.STRING,
+      unique: true,
+      set: function(agentconnectedAt) {
+        this.setDataValue('connectid', this.uniqueid);
+        this.setDataValue('reason', 'connect');
+        this.setDataValue('connectedAt', moment().format("YYYY-MM-DD HH:mm:ss"));
+      }
+    },
+    calledAt: DataTypes.DATE,
+    connectedAt: DataTypes.DATE
+  }, {
+    tableName: 'report_chat_history'
+  });
+
+  return ReportChatHistory;
+};
diff --git a/server/models/history/report_chat_session_history.js b/server/models/history/report_chat_session_history.js
new file mode 100644
index 0000000..ed11a09
--- /dev/null
+++ b/server/models/history/report_chat_session_history.js
@@ -0,0 +1,35 @@
+/**
+ * Agent Log Model
+ */
+
+var moment = require('moment');
+
+module.exports = function(sequelize, DataTypes) {
+
+  var ReportChatSessionHistory = sequelize.define('ReportChatSessionHistory', {
+    uniqueid: {
+      type: DataTypes.STRING,
+      unique: true
+    },
+    websitename: DataTypes.STRING,
+    websiteaddress: DataTypes.STRING,
+    websiteid: DataTypes.INTEGER,
+    application: DataTypes.STRING,
+    visitorid: DataTypes.STRING,
+    visitorname: DataTypes.STRING,
+    visitoremail: DataTypes.STRING,
+    agentid: DataTypes.STRING,
+    agentname: DataTypes.STRING,
+    queueid: DataTypes.INTEGER,
+    queuename: DataTypes.STRING,
+    roomid: DataTypes.INTEGER,
+    joinAt: DataTypes.DATE,
+    leaveAt: DataTypes.DATE,
+    unmanagedAt: DataTypes.DATE,
+    abandonAt: DataTypes.DATE
+  }, {
+    tableName: 'report_chat_session_history'
+  });
+
+  return ReportChatSessionHistory;
+};
diff --git a/server/models/history/report_mail_history.js b/server/models/history/report_mail_history.js
new file mode 100644
index 0000000..0af6acd
--- /dev/null
+++ b/server/models/history/report_mail_history.js
@@ -0,0 +1,43 @@
+/**
+ * Agent Log Model
+ */
+
+var moment = require('moment');
+
+module.exports = function(sequelize, DataTypes) {
+
+  var ReportMailHistory = sequelize.define('ReportMailHistory', {
+    uniqueid: DataTypes.STRING,
+    timeslot: DataTypes.INTEGER,
+    subject: DataTypes.STRING,
+    accountid: DataTypes.STRING,
+    accountname: DataTypes.STRING,
+    accountaddress: DataTypes.STRING,
+    application: DataTypes.STRING,
+    memberid: DataTypes.INTEGER,
+    membername: DataTypes.STRING,
+    queue: DataTypes.INTEGER,
+    queuename: DataTypes.STRING,
+    roomid: DataTypes.INTEGER,
+    messageid: DataTypes.INTEGER,
+    reason: {
+      type: DataTypes.STRING,
+      defaultValue: 'called'
+    },
+    connectid: {
+      type: DataTypes.STRING,
+      unique: true,
+      set: function(agentconnectedAt) {
+        this.setDataValue('connectid', this.uniqueid);
+        this.setDataValue('reason', 'connect');
+        this.setDataValue('connectedAt', moment().format("YYYY-MM-DD HH:mm:ss"));
+      }
+    },
+    calledAt: DataTypes.DATE,
+    connectedAt: DataTypes.DATE
+  }, {
+    tableName: 'report_mail_history'
+  });
+
+  return ReportMailHistory;
+};
diff --git a/server/models/history/report_square_detail_history.js b/server/models/history/report_square_detail_history.js
new file mode 100644
index 0000000..f918cf2
--- /dev/null
+++ b/server/models/history/report_square_detail_history.js
@@ -0,0 +1,25 @@
+/**
+ * Context Model
+ */
+
+module.exports = function(sequelize, DataTypes) {
+
+  var ReportSquareDetailHistory = sequelize.define('ReportSquareDetailHistory', {
+    uniqueid: {
+      type: DataTypes.STRING,
+    },
+    node: {
+      type: DataTypes.STRING,
+    },
+    application: {
+      type: DataTypes.STRING,
+    },
+    data: {
+      type: DataTypes.STRING,
+    }
+  }, {
+    tableName: 'report_square_details_history'
+  });
+
+  return ReportSquareDetailHistory;
+};
diff --git a/server/models/history/report_square_history.js b/server/models/history/report_square_history.js
new file mode 100644
index 0000000..d56f92c
--- /dev/null
+++ b/server/models/history/report_square_history.js
@@ -0,0 +1,89 @@
+/**
+ * Context Model
+ */
+
+module.exports = function(sequelize, DataTypes) {
+
+  var ReportSquareHistory = sequelize.define('ReportSquareHistory', {
+    network: {
+      type: DataTypes.STRING,
+    },
+    network_script: {
+      type: DataTypes.STRING,
+    },
+    request: {
+      type: DataTypes.STRING,
+    },
+    channel: {
+      type: DataTypes.STRING,
+    },
+    language: {
+      type: DataTypes.STRING,
+    },
+    type: {
+      type: DataTypes.STRING,
+    },
+    uniqueid: {
+      type: DataTypes.STRING,
+    },
+    version: {
+      type: DataTypes.STRING,
+    },
+    callerid: {
+      type: DataTypes.STRING,
+    },
+    calleridname: {
+      type: DataTypes.STRING,
+    },
+    callingpres: {
+      type: DataTypes.STRING,
+    },
+    callingani2: {
+      type: DataTypes.STRING,
+    },
+    callington: {
+      type: DataTypes.STRING,
+    },
+    callingtns: {
+      type: DataTypes.STRING,
+    },
+    dnid: {
+      type: DataTypes.STRING,
+    },
+    rdnis: {
+      type: DataTypes.STRING,
+    },
+    context: {
+      type: DataTypes.STRING,
+    },
+    extension: {
+      type: DataTypes.STRING,
+    },
+    priority: {
+      type: DataTypes.STRING,
+    },
+    enhanced: {
+      type: DataTypes.STRING,
+    },
+    accountcode: {
+      type: DataTypes.STRING,
+    },
+    threadid: {
+      type: DataTypes.STRING,
+    },
+    project_name: {
+      type: DataTypes.STRING,
+    },
+    joinAt: {
+      type: DataTypes.DATE,
+    },
+    leaveAt: {
+      type: DataTypes.DATE,
+      unique: true
+    }
+  }, {
+    tableName: 'report_square_history'
+  });
+
+  return ReportSquareHistory;
+};
diff --git a/server/models/history/report_tranfer_history.js b/server/models/history/report_tranfer_history.js
new file mode 100644
index 0000000..aec5d4b
--- /dev/null
+++ b/server/models/history/report_tranfer_history.js
@@ -0,0 +1,25 @@
+/**
+ * Agent Log Model
+ */
+
+module.exports = function(sequelize, DataTypes) {
+
+  var ReportTransferHistory = sequelize.define('ReportTransferHistory', {
+    type: DataTypes.ENUM('blind', 'attended'),
+    transferercalleridnum: DataTypes.STRING,
+    transferercalleridname: DataTypes.STRING,
+    transfererconnectedlinenum: DataTypes.STRING,
+    transfererconnectedlinename: DataTypes.STRING,
+    transferercontext: DataTypes.STRING,
+    transfererexten: DataTypes.STRING,
+    transfereecontext: DataTypes.STRING,
+    transfereeexten: DataTypes.STRING,
+    transfereruniqueid: DataTypes.STRING,
+    transfererlinkedid: DataTypes.STRING,
+    extension: DataTypes.STRING,
+  }, {
+    tableName: 'report_transfer_history'
+  });
+
+  return ReportTransferHistory;
+};
-- 
1.7.1