Alan Colon 7 лет назад
Родитель
Сommit
89087973d4

+ 1 - 1
app/assets/index.js

@@ -7,6 +7,6 @@ module.exports = Object.assign(assets, {
   terminalIcon: require('@alancnet/icomoon-svg/location.svg'),
   terminalIcon: require('@alancnet/icomoon-svg/location.svg'),
   laborIcon: require('./noun_constructor_593655.svg'),
   laborIcon: require('./noun_constructor_593655.svg'),
   crumbIcon: require('@alancnet/material-design-icons/image_ic_navigate_next_48px.svg'),
   crumbIcon: require('@alancnet/material-design-icons/image_ic_navigate_next_48px.svg'),
-  retailerIcon: require('@alancnet/material-design-icons/maps_ic_store_mall_directory_48px.svg'),
+  clientIcon: require('@alancnet/material-design-icons/maps_ic_store_mall_directory_48px.svg'),
   serviceIcon: require('./noun_service_406879.svg')
   serviceIcon: require('./noun_service_406879.svg')
 })
 })

+ 7 - 7
app/components/services-entry-page.js

@@ -28,9 +28,9 @@ app.component('appServicesEntryPage', {
           </tr>
           </tr>
         </thead>
         </thead>
         <tbody md-body>
         <tbody md-body>
-          <tr md-row ng-repeat="sfl in ::ctrl.retailerServices track by sfl.id">
+          <tr md-row ng-repeat="sfl in ::ctrl.clientServices track by sfl.id">
             <td md-cell>
             <td md-cell>
-              {{::ctrl.retailers[sfl.id].name}}
+              {{::ctrl.clients[sfl.id].name}}
             </td>
             </td>
             <td md-cell ng-repeat="day in ::sfl.days track by $index">
             <td md-cell ng-repeat="day in ::sfl.days track by $index">
               <input class="hour-input md-button md-raised" ng-model="day.cartons" type="number" min="0" step="1">
               <input class="hour-input md-button md-raised" ng-model="day.cartons" type="number" min="0" step="1">
@@ -52,13 +52,13 @@ app.component('appServicesEntryPage', {
     if (!week.isSame(week.startOf('week'))) throw new Error('Date is not start of week')
     if (!week.isSame(week.startOf('week'))) throw new Error('Date is not start of week')
     this.startDate = week
     this.startDate = week
     this.endDate = week.endOf('week')
     this.endDate = week.endOf('week')
-    api.retailerDictionary().then(retailers => {
-      this.retailers = retailers
+    api.clientDictionary().then(clients => {
+      this.clients = clients
     })
     })
     this.promise = api.get(`/api/services/${$routeParams.terminal}/${$routeParams.week}`).then(({workdays}) => {
     this.promise = api.get(`/api/services/${$routeParams.terminal}/${$routeParams.week}`).then(({workdays}) => {
       this.model = workdays
       this.model = workdays
-      const retailerIds = workdays[0].services.map(x => x.retailerId)
-      this.retailerServices = retailerIds.map((id, i) => ({
+      const clientIds = workdays[0].services.map(x => x.clientId)
+      this.clientServices = clientIds.map((id, i) => ({
         id,
         id,
         days: this.model.map(wd => wd.services[i])
         days: this.model.map(wd => wd.services[i])
       }))
       }))
@@ -68,7 +68,7 @@ app.component('appServicesEntryPage', {
       const model = {
       const model = {
         workdays: this.model.map(workday => ({
         workdays: this.model.map(workday => ({
           services: workday.services.map(service => ({
           services: workday.services.map(service => ({
-            retailerId: service.retailerId,
+            clientId: service.clientId,
             cartons: service.cartons || null
             cartons: service.cartons || null
           }))
           }))
         }))
         }))

+ 7 - 7
app/components/user-area-nav.js

@@ -1,6 +1,6 @@
 const app = require('../app')
 const app = require('../app')
 const _ = require('lodash')
 const _ = require('lodash')
-const { dashboardIcon, staffMemberIcon, staffingAgencyIcon, laborIcon, retailerIcon, serviceIcon } = require('../assets')
+const { dashboardIcon, staffMemberIcon, staffingAgencyIcon, laborIcon, clientIcon, serviceIcon } = require('../assets')
 
 
 app.component('appUserAreaNav', {
 app.component('appUserAreaNav', {
   template: html`
   template: html`
@@ -37,9 +37,9 @@ app.component('appUserAreaNav', {
           {{::terminal.key}} Staff Members
           {{::terminal.key}} Staff Members
         </md-button>
         </md-button>
       </md-menu-item>
       </md-menu-item>
-      <md-menu-item ng-if="$ctrl.api.claims.RETAILER_READ">
-        <md-button ng-href="/retailers/{{::terminal.key}}">
-          <md-icon md-svg-icon="${retailerIcon}"></md-icon>
+      <md-menu-item ng-if="$ctrl.api.claims.CLIENT_READ">
+        <md-button ng-href="/clients/{{::terminal.key}}">
+          <md-icon md-svg-icon="${clientIcon}"></md-icon>
           {{::terminal.key}} Clients
           {{::terminal.key}} Clients
         </md-button>
         </md-button>
       </md-menu-item>
       </md-menu-item>
@@ -59,9 +59,9 @@ app.component('appUserAreaNav', {
           Staffing Agencies
           Staffing Agencies
         </md-button>
         </md-button>
       </md-menu-item>
       </md-menu-item>
-      <md-menu-item ng-if="$ctrl.api.claims.RETAILER_READ">
-        <md-button ng-href="/retailers/all">
-          <md-icon md-svg-icon="${retailerIcon}"></md-icon>
+      <md-menu-item ng-if="$ctrl.api.claims.CLIENT_READ">
+        <md-button ng-href="/clients/all">
+          <md-icon md-svg-icon="${clientIcon}"></md-icon>
           Clients
           Clients
         </md-button>
         </md-button>
       </md-menu-item>
       </md-menu-item>

+ 5 - 5
app/services/api.js

@@ -22,12 +22,12 @@ app.run(function(api) {
     _.fromPairs(staffMembers.map(sm => [sm.id, sm]))
     _.fromPairs(staffMembers.map(sm => [sm.id, sm]))
   ))
   ))
 
 
-  let retailers = null
-  api.retailers = () => retailers || (retailers = api.get('/api/retailers/all'))
+  let clients = null
+  api.clients = () => clients || (clients = api.get('/api/clients/all'))
 
 
-  let retailerDictionary = null
-  api.retailerDictionary = () => retailerDictionary || (retailerDictionary = api.retailers().then(retailers =>
-    _.fromPairs(retailers.map(sm => [sm.id, sm]))
+  let clientDictionary = null
+  api.clientDictionary = () => clientDictionary || (clientDictionary = api.clients().then(clients =>
+    _.fromPairs(clients.map(sm => [sm.id, sm]))
   ))
   ))
 
 
 })
 })

+ 3 - 3
auto-crud/retailer.js → auto-crud/client.js

@@ -1,10 +1,10 @@
 const { register, Sequelize } = require('@alancnet/material-framework/auto-crud')
 const { register, Sequelize } = require('@alancnet/material-framework/auto-crud')
 
 
 register({
 register({
-  camelName: 'retailer',
+  camelName: 'client',
   iconAsset: 'userIcon',
   iconAsset: 'userIcon',
-  appPrefix: '/retailers/:terminal',
-  apiPrefix: '/api/retailers/:terminal',
+  appPrefix: '/clients/:terminal',
+  apiPrefix: '/api/clients/:terminal',
   titles: {
   titles: {
     details: ctrl => ctrl.isNew
     details: ctrl => ctrl.isNew
     ? `New ${ctrl.$routeParams.terminal == 'all' ? '' : ctrl.$routeParams.terminal} Client`
     ? `New ${ctrl.$routeParams.terminal == 'all' ? '' : ctrl.$routeParams.terminal} Client`

+ 1 - 1
auto-crud/index.js

@@ -1,6 +1,6 @@
 require('./terminal')
 require('./terminal')
 require('./labor-category')
 require('./labor-category')
-require('./retailer')
+require('./client')
 /* Example */
 /* Example */
 /*
 /*
 
 

+ 3 - 3
auto-crud/service.js

@@ -10,7 +10,7 @@ register({
       primaryKey: true
       primaryKey: true
     },
     },
     workdayId: Sequelize.UUID,
     workdayId: Sequelize.UUID,
-    retailerId: Sequelize.UUID,
+    clientId: Sequelize.UUID,
     date: Sequelize.DATEONLY, // Copy from Workday
     date: Sequelize.DATEONLY, // Copy from Workday
     delivered: Sequelize.INTEGER,
     delivered: Sequelize.INTEGER,
     scanned: Sequelize.INTEGER
     scanned: Sequelize.INTEGER
@@ -20,14 +20,14 @@ register({
     indexes: [
     indexes: [
       {
       {
         unique: true,
         unique: true,
-        fields: ['workdayId', 'retailerId']
+        fields: ['workdayId', 'clientId']
       }
       }
     ]
     ]
   },
   },
   columns: [
   columns: [
     { camelName: 'date', type: 'date' },
     { camelName: 'date', type: 'date' },
     { camelName: 'workdayId', titleName: 'Workday', type: 'autocomplete', source: '/api/workdays' },
     { camelName: 'workdayId', titleName: 'Workday', type: 'autocomplete', source: '/api/workdays' },
-    { camelName: 'retailerId', titleName: 'Retailer', type: 'autocomplete', source: '/api/retailers' },
+    { camelName: 'clientId', titleName: 'Client', type: 'autocomplete', source: '/api/clients' },
     { camelName: 'delivered', type: 'number' },
     { camelName: 'delivered', type: 'number' },
     { camelName: 'scanned', type: 'number' }
     { camelName: 'scanned', type: 'number' }
   ],
   ],

+ 21 - 21
lib/controllers/services.js

@@ -1,7 +1,7 @@
 const _ = require('lodash')
 const _ = require('lodash')
 const moment = require('moment-immutable')
 const moment = require('moment-immutable')
 const { getWeeks, formatDate, parseDate } = require('../dates')
 const { getWeeks, formatDate, parseDate } = require('../dates')
-const { Retailer, Workday, Terminal, Service, sequelize } = require('../database')
+const { Client, Workday, Terminal, Service, sequelize } = require('../database')
 const { Op } = require('sequelize')
 const { Op } = require('sequelize')
 
 
 const list = async (req, res) => {
 const list = async (req, res) => {
@@ -66,25 +66,25 @@ const get = async (req, res) => {
     }
     }
   })
   })
   const servicesByWorkday = _.groupBy(services, x => x.workdayId)
   const servicesByWorkday = _.groupBy(services, x => x.workdayId)
-  const extraRetailers = _.chain(services)
-    .map(x => x.retailerId)
+  const extraClients = _.chain(services)
+    .map(x => x.clientId)
     .filter(x => x)
     .filter(x => x)
     .uniq()
     .uniq()
     .value()
     .value()
-  const retailers = await Retailer.findAll({
+  const clients = await Client.findAll({
     where: {
     where: {
       [Op.or]: [
       [Op.or]: [
         { terminalId: terminal.id },
         { terminalId: terminal.id },
         {
         {
           id: {
           id: {
-            [Op.in]: extraRetailers
+            [Op.in]: extraClients
           }
           }
         }
         }
       ]      
       ]      
     },
     },
     order: [ 'name' ]
     order: [ 'name' ]
   })
   })
-  const retailersById = _.chain(retailers).map(x => [x.id, x]).fromPairs().value()
+  const clientsById = _.chain(clients).map(x => [x.id, x]).fromPairs().value()
 
 
   // Fill in empty days
   // Fill in empty days
   const workdaysByKey = _.chain(workdays).map(wd => [formatDate(wd.date), wd]).fromPairs().value()
   const workdaysByKey = _.chain(workdays).map(wd => [formatDate(wd.date), wd]).fromPairs().value()
@@ -96,17 +96,17 @@ const get = async (req, res) => {
 
 
   const workdaysWithServices = allWorkdays.map(wd => {
   const workdaysWithServices = allWorkdays.map(wd => {
     const services = servicesByWorkday[wd.id] || []
     const services = servicesByWorkday[wd.id] || []
-    const serviceByRetailer = _.chain(services).map(l => [l.retailerId, l]).fromPairs().value()
+    const serviceByClient = _.chain(services).map(l => [l.clientId, l]).fromPairs().value()
     // Map from staffMembers to preserve sorting
     // Map from staffMembers to preserve sorting
-    wd.services = retailers
-      .map(sm => serviceByRetailer[sm.id] || {retailerId: sm.id})
+    wd.services = clients
+      .map(sm => serviceByClient[sm.id] || {clientId: sm.id})
       .map(sm => ({
       .map(sm => ({
-        retailerId: sm.retailerId,
+        clientId: sm.clientId,
         cartons: sm.cartons || null
         cartons: sm.cartons || null
       }))
       }))
     // Restore any staffMembers that are no longer assigned this terminal
     // Restore any staffMembers that are no longer assigned this terminal
     services.forEach(l => {
     services.forEach(l => {
-      if (!serviceByRetailer[l.retailerId]) {
+      if (!serviceByClient[l.clientId]) {
         wd.services.push(l)
         wd.services.push(l)
       }
       }
     })
     })
@@ -142,25 +142,25 @@ const patch = async (req, res) => {
       }
       }
     })
     })
     const servicesByWorkday = _.groupBy(services, x => x.workdayId)
     const servicesByWorkday = _.groupBy(services, x => x.workdayId)
-    const extraRetailers = _.chain(services)
-      .map(x => x.retailerId)
+    const extraClients = _.chain(services)
+      .map(x => x.clientId)
       .filter(x => x)
       .filter(x => x)
       .uniq()
       .uniq()
       .value()
       .value()
-    const retailers = await Retailer.findAll({
+    const clients = await Client.findAll({
       where: {
       where: {
         [Op.or]: [
         [Op.or]: [
           { terminalId: terminal.id },
           { terminalId: terminal.id },
           {
           {
             id: {
             id: {
-              [Op.in]: extraRetailers
+              [Op.in]: extraClients
             }
             }
           }
           }
         ]      
         ]      
       },
       },
       order: [ 'name' ]
       order: [ 'name' ]
     })
     })
-    const retailersById = _.chain(retailers).map(x => [x.id, x]).fromPairs().value()
+    const clientsById = _.chain(clients).map(x => [x.id, x]).fromPairs().value()
 
 
     // Fill in empty days
     // Fill in empty days
     const workdaysByKey = _.chain(workdays).map(wd => [formatDate(wd.date), wd]).fromPairs().value()
     const workdaysByKey = _.chain(workdays).map(wd => [formatDate(wd.date), wd]).fromPairs().value()
@@ -175,12 +175,12 @@ const patch = async (req, res) => {
 
 
     const workdaysWithServices = allWorkdays.map(wd => {
     const workdaysWithServices = allWorkdays.map(wd => {
       const services = servicesByWorkday[wd.id] || []
       const services = servicesByWorkday[wd.id] || []
-      const servicesByRetailer = _.chain(services).map(l => [l.retailerId, l]).fromPairs().value()
+      const servicesByClient = _.chain(services).map(l => [l.clientId, l]).fromPairs().value()
       // Map from staffMembers to preserve sorting
       // Map from staffMembers to preserve sorting
-      wd.services = retailers.map(sm => servicesByRetailer[sm.id] || Service.build({retailerId: sm.id, workdayId: wd.id}))
+      wd.services = clients.map(sm => servicesByClient[sm.id] || Service.build({clientId: sm.id, workdayId: wd.id}))
       // Restore any staffMembers that are no longer assigned this terminal
       // Restore any staffMembers that are no longer assigned this terminal
       services.forEach(l => {
       services.forEach(l => {
-        if (!retailersById[l.retailerId]) {
+        if (!clientsById[l.clientId]) {
           wd.services.push(l)
           wd.services.push(l)
         }
         }
       })
       })
@@ -190,11 +190,11 @@ const patch = async (req, res) => {
     // Update with model
     // Update with model
     const model = req.body
     const model = req.body
     await Promise.all(model.workdays.map(async (modelWorkday, i) => {
     await Promise.all(model.workdays.map(async (modelWorkday, i) => {
-      const modelServicesById = _.chain(modelWorkday.services).map(l => [l.retailerId, l]).fromPairs().value()
+      const modelServicesById = _.chain(modelWorkday.services).map(l => [l.clientId, l]).fromPairs().value()
       const workday = allWorkdays[i]
       const workday = allWorkdays[i]
 
 
       workday.services.forEach(service => {
       workday.services.forEach(service => {
-        const modelService = modelServicesById[service.retailerId]
+        const modelService = modelServicesById[service.clientId]
 
 
         service.cartons = modelService.cartons || 0
         service.cartons = modelService.cartons || 0
       })
       })

+ 2 - 2
lib/database/retailer.js → lib/database/client.js

@@ -1,7 +1,7 @@
 const Sequelize = require('sequelize')
 const Sequelize = require('sequelize')
 const sequelize = require('./sequelize')
 const sequelize = require('./sequelize')
 
 
-const Retailer = sequelize.define('retailer', {
+const Client = sequelize.define('client', {
   id: {
   id: {
     type: Sequelize.UUID,
     type: Sequelize.UUID,
     defaultValue: Sequelize.UUIDV1,
     defaultValue: Sequelize.UUIDV1,
@@ -25,4 +25,4 @@ const Retailer = sequelize.define('retailer', {
   ]
   ]
 })
 })
 
 
-module.exports = Retailer
+module.exports = Client

+ 11 - 11
lib/database/index.js

@@ -1,13 +1,13 @@
 require('./migrations')
 require('./migrations')
 // TODO: App Specific Models
 // TODO: App Specific Models
 const {database} = require('@alancnet/material-framework/server')
 const {database} = require('@alancnet/material-framework/server')
-const { Terminal, Retailer } = database
+const { Terminal, Client } = database
 const initialize = require('./initialize')
 const initialize = require('./initialize')
 
 
 // const Terminal = require('./terminal')
 // const Terminal = require('./terminal')
 const Workday = require('./workday')
 const Workday = require('./workday')
 const Service = require('./service')
 const Service = require('./service')
-//const Retailer = require('./retailer')
+//const Client = require('./client')
 const StaffMember = require('./staff-member')
 const StaffMember = require('./staff-member')
 const StaffingAgency = require('./staffing-agency')
 const StaffingAgency = require('./staffing-agency')
 const Labor = require('./labor')
 const Labor = require('./labor')
@@ -18,14 +18,14 @@ const WorkdayTerminal = Workday.belongsTo(Terminal)
 const WorkdayService = Workday.hasMany(Service)
 const WorkdayService = Workday.hasMany(Service)
 const ServiceWorkday = Service.belongsTo(Workday)
 const ServiceWorkday = Service.belongsTo(Workday)
 
 
-const RetailerService = Retailer.hasMany(Service)
-const ServiceRetailer = Service.belongsTo(Retailer)
+const ClientService = Client.hasMany(Service)
+const ServiceClient = Service.belongsTo(Client)
 
 
 const TerminalStaffMember = Terminal.hasMany(StaffMember)
 const TerminalStaffMember = Terminal.hasMany(StaffMember)
 const StaffMemberTerminal = StaffMember.belongsTo(Terminal)
 const StaffMemberTerminal = StaffMember.belongsTo(Terminal)
 
 
-const TerminalRetailer = Terminal.hasMany(Retailer)
-const RetailerTerminal = Retailer.belongsTo(Terminal)
+const TerminalClient = Terminal.hasMany(Client)
+const ClientTerminal = Client.belongsTo(Terminal)
 
 
 // const StaffingAgencyStaffMember = StaffingAgency.hasMany(StaffMember)
 // const StaffingAgencyStaffMember = StaffingAgency.hasMany(StaffMember)
 // const StaffMemberStaffingAgency = StaffMember.belongsTo(StaffingAgency)
 // const StaffMemberStaffingAgency = StaffMember.belongsTo(StaffingAgency)
@@ -42,18 +42,18 @@ module.exports = Object.assign(database, {
   Terminal,
   Terminal,
   Workday,
   Workday,
   Service,
   Service,
-  Retailer,
+  Client,
   StaffMember,
   StaffMember,
   StaffingAgency,
   StaffingAgency,
   TerminalWorkday,
   TerminalWorkday,
   WorkdayTerminal,
   WorkdayTerminal,
   WorkdayService,
   WorkdayService,
   ServiceWorkday,
   ServiceWorkday,
-  RetailerService,
-  ServiceRetailer,
+  ClientService,
+  ServiceClient,
   TerminalStaffMember,
   TerminalStaffMember,
   StaffMemberTerminal,
   StaffMemberTerminal,
   Labor,
   Labor,
-  TerminalRetailer,
-  RetailerTerminal
+  TerminalClient,
+  ClientTerminal
 })
 })

+ 11 - 11
lib/database/initialize.js

@@ -57,11 +57,11 @@ const roles = [
       'TERMINAL_UNDELETE',
       'TERMINAL_UNDELETE',
       'TERMINAL_UPDATE',
       'TERMINAL_UPDATE',
       'METRICS_VIEW',
       'METRICS_VIEW',
-      'RETAILER_CREATE',
-      'RETAILER_DELETE',
-      'RETAILER_READ',
-      'RETAILER_UNDELETE',
-      'RETAILER_UPDATE',
+      'CLIENT_CREATE',
+      'CLIENT_DELETE',
+      'CLIENT_READ',
+      'CLIENT_UNDELETE',
+      'CLIENT_UPDATE',
       'ROLE_CREATE',
       'ROLE_CREATE',
       'ROLE_DELETE',
       'ROLE_DELETE',
       'ROLE_READ',
       'ROLE_READ',
@@ -101,11 +101,11 @@ const roles = [
       'LABOR_CATEGORY_READ',
       'LABOR_CATEGORY_READ',
       'TERMINAL_READ',
       'TERMINAL_READ',
       'METRICS_VIEW',
       'METRICS_VIEW',
-      'RETAILER_CREATE',
-      'RETAILER_DELETE',
-      'RETAILER_READ',
-      'RETAILER_UNDELETE',
-      'RETAILER_UPDATE',
+      'CLIENT_CREATE',
+      'CLIENT_DELETE',
+      'CLIENT_READ',
+      'CLIENT_UNDELETE',
+      'CLIENT_UPDATE',
       'STAFFING_AGENCY_READ',
       'STAFFING_AGENCY_READ',
       'STAFF_MEMBER_CREATE',
       'STAFF_MEMBER_CREATE',
       'STAFF_MEMBER_DELETE',
       'STAFF_MEMBER_DELETE',
@@ -122,7 +122,7 @@ const roles = [
     permissions: [
     permissions: [
       'LABOR_CATEGORY_READ',
       'LABOR_CATEGORY_READ',
       'TERMINAL_READ',
       'TERMINAL_READ',
-      'RETAILER_READ',
+      'CLIENT_READ',
       'STAFFING_AGENCY_CREATE',
       'STAFFING_AGENCY_CREATE',
       'STAFFING_AGENCY_DELETE',
       'STAFFING_AGENCY_DELETE',
       'STAFFING_AGENCY_READ',
       'STAFFING_AGENCY_READ',

+ 3 - 3
lib/database/migrations/1.01-location-to-terminal.js

@@ -5,13 +5,13 @@ module.exports = {
   description: 'Refactors `Location` to `Terminal`',
   description: 'Refactors `Location` to `Terminal`',
   up: async (queryInterface, Sequelize) => {
   up: async (queryInterface, Sequelize) => {
     // Tables with locationId: 
     // Tables with locationId: 
-    // Retailer
+    // Client
     // Service
     // Service
     // StaffMember
     // StaffMember
     // Workday
     // Workday
 
 
-    console.log(chalk.red('Renaming locationId -> terminalId on retailers'))
-    await queryInterface.renameColumn('retailers', 'locationId', 'terminalId')
+    console.log(chalk.red('Renaming locationId -> terminalId on clients'))
+    await queryInterface.renameColumn('clients', 'locationId', 'terminalId')
 
 
     console.log(chalk.red('Renaming locationId -> terminalId on staffMembers'))
     console.log(chalk.red('Renaming locationId -> terminalId on staffMembers'))
     await queryInterface.renameColumn('staffMembers', 'locationId', 'terminalId')
     await queryInterface.renameColumn('staffMembers', 'locationId', 'terminalId')

+ 10 - 0
lib/database/migrations/1.02-retailer-to-client.js

@@ -0,0 +1,10 @@
+module.exports = {
+  version: 1.02,
+  name: 'Retailer to Client',
+  description: 'Refactors `Retailer` to `Client`',
+  up: async (queryInterface, Sequelize) => {
+    await queryInterface.renameColumn('services', 'retailerId', 'clientId')
+    await queryInterface.renameTable('retailers', 'clients')
+    return 1.02
+  }
+}

+ 2 - 1
lib/database/migrations/index.js

@@ -1,7 +1,8 @@
 const migrations = require('@alancnet/material-framework/lib/database/migrations')
 const migrations = require('@alancnet/material-framework/lib/database/migrations')
 module.exports = Object.assign(migrations, {
 module.exports = Object.assign(migrations, {
   'special-dispatch-app': [
   'special-dispatch-app': [
-    require('./1.01-location-to-terminal.js')
+    require('./1.01-location-to-terminal.js'),
+    require('./1.02-retailer-to-client.js')
   ]
   ]
 })
 })
 
 

+ 2 - 2
lib/database/service.js

@@ -8,7 +8,7 @@ const Service = sequelize.define('service', {
     primaryKey: true
     primaryKey: true
   },
   },
   workdayId: Sequelize.UUID,
   workdayId: Sequelize.UUID,
-  retailerId: Sequelize.UUID,
+  clientId: Sequelize.UUID,
   date: Sequelize.DATEONLY, // Copy from Workday
   date: Sequelize.DATEONLY, // Copy from Workday
   delivered: Sequelize.INTEGER,
   delivered: Sequelize.INTEGER,
   scanned: Sequelize.INTEGER,
   scanned: Sequelize.INTEGER,
@@ -18,7 +18,7 @@ const Service = sequelize.define('service', {
   indexes: [
   indexes: [
     {
     {
       unique: true,
       unique: true,
-      fields: ['workdayId', 'retailerId']
+      fields: ['workdayId', 'clientId']
     }
     }
   ]
   ]
 })
 })

+ 12 - 12
lib/integration/xlsx-reports.js

@@ -1,5 +1,5 @@
 const _ = require('lodash')
 const _ = require('lodash')
-const { init, Retailer, Service, Workday } = require('../database')
+const { init, Client, Service, Workday } = require('../database')
 const { title } = require('change-case')
 const { title } = require('change-case')
 const terminals = require('./terminals')
 const terminals = require('./terminals')
 
 
@@ -25,12 +25,12 @@ const $import = async (locKey, filename) => {
     const date = sheet[0][0]
     const date = sheet[0][0]
     const regularHours = +sheet[5][1]
     const regularHours = +sheet[5][1]
     const overtimeHours = +sheet[5][2]
     const overtimeHours = +sheet[5][2]
-    let foundRetailer = 0
+    let foundClient = 0
     const services = sheet
     const services = sheet
-      .filter(row => (row[0] && foundRetailer) || (row[0] === 'Retailer' && foundRetailer++))
-      .map(([retailer, totalDel, nonDlv, early, late, onTime, pctOnTime, delivered, scanned, notScanned, pctScanned]) => ({
+      .filter(row => (row[0] && foundClient) || (row[0] === 'Client' && foundClient++))
+      .map(([client, totalDel, nonDlv, early, late, onTime, pctOnTime, delivered, scanned, notScanned, pctScanned]) => ({
         date,
         date,
-        retailer,
+        client,
         delivered: +delivered,
         delivered: +delivered,
         scanned: +scanned
         scanned: +scanned
       }))
       }))
@@ -43,27 +43,27 @@ const $import = async (locKey, filename) => {
       })
       })
   }
   }
 
 
-  const retailerKeys = _.chain(workdays)
+  const clientKeys = _.chain(workdays)
     .map(x => x.services)
     .map(x => x.services)
     .flatten()
     .flatten()
-    .map(x => x.retailer)
+    .map(x => x.client)
     .uniq()
     .uniq()
     .value()
     .value()
 
 
-  for (let key of retailerKeys) {
+  for (let key of clientKeys) {
     console.log(key)
     console.log(key)
-    await Retailer.upsert({
+    await Client.upsert({
       key,
       key,
       name: title(key)
       name: title(key)
     })
     })
   }
   }
 
 
-  const retailerIds = _.chain(await Retailer.findAll())
+  const clientIds = _.chain(await Client.findAll())
     .map(({key, id}) => [key, id])
     .map(({key, id}) => [key, id])
     .fromPairs()
     .fromPairs()
     .value()
     .value()
 
 
-  console.log(retailerIds)
+  console.log(clientIds)
   
   
   for (let workday of workdays) {
   for (let workday of workdays) {
     await Workday.upsert({
     await Workday.upsert({
@@ -83,7 +83,7 @@ const $import = async (locKey, filename) => {
         console.log(service)
         console.log(service)
         await Service.upsert({
         await Service.upsert({
           workdayId: wd.id,
           workdayId: wd.id,
-          retailerId: retailerIds[service.retailer],
+          clientId: clientIds[service.client],
           date: workday.date,
           date: workday.date,
           delivered: service.delivered,
           delivered: service.delivered,
           scanned: service.scanned
           scanned: service.scanned