Overview page recent sales order list

In SCMA wbsite recent invoices list was showing client want to show recent sales order there.
For that created an extension and updated the model to change the filter.

suitescript file: JJ.OverviewHome.OverviewHome.Model.js:

define('JJ.OverviewHome.OverviewHome.Model', ['underscore', 'Invoice.Model', 'Utils'], function(_, InvoiceModel, Utils) {
  'use strict';
  _.extend(InvoiceModel, {
    setExtraListFilters: function() {
      const status = this.data;
      if (status) {
        var value = null;
        switch (status.status) {
          case 'open':
            value = 'CustInvc:A';
            break;
          case 'paid':
            value = 'CustInvc:B';
            break;
        }
        if (value) {
          this.filters.status_operator = 'and';
          this.filters.status = ['status', 'anyof', value];
        }
      }
      if (!status.status) {
        try {
          var self = this;
          //changing filter to get recent salesorder in myaccount overview
          this.filters.types_operator = 'and';
          this.filters.types = ["type", "anyof", "SalesOrd"];
        } catch (e) {
          console.error("this e", e);
        }
      }
    }
  });
});

javascript : JJ.OverviewHome.OverviewHome.js:

define('JJ.OverviewHome.OverviewHome', ['Overview.Home.Standalone.View', 'Configuration', 'Handlebars', 'Backbone.CollectionView', 'RecordViews.View', 'underscore', 'Utils', 'Backbone'], function(OverviewHomeStandaloneView, Configuration, Handlebars, BackboneCollectionView, RecordViewsView, _, Utils, Backbone) {
  'use strict';
  return {
    mountToApp: function mountToApp(container) {
      var layout = container.getComponent('Layout');
      if (layout) {
        //To show recent 3 sales orders in myaccount overview page.
        _.extend(OverviewHomeStandaloneView.prototype, {
          childViews: _.extend(OverviewHomeStandaloneView.prototype.childViews, {
            'Invoices.Results': function() {
              try {
                const self = this;
                let selectedColumns = [];
                if (!Configuration.get().transactionListColumns.enableInvoice) {
                  selectedColumns.push({
                    label: 'Date:',
                    type: 'date',
                    name: 'date',
                    id: 'trandate'
                  });
                  selectedColumns.push({
                    label: 'Amount:',
                    type: 'currency',
                    name: 'amount',
                    id: 'amount_formatted'
                  });
                  selectedColumns.push({
                    label: 'Status:',
                    type: 'status',
                    name: 'name',
                    id: 'status'
                  });
                } else {
                  selectedColumns = Configuration.get().transactionListColumns.invoiceOpen;
                }
                const records_collection = new Backbone.Collection(this.collection.map(function(invoice) {
                  const recordtype = invoice.get('recordtype');
                  var statusName;
                  const soStatus = invoice.get('status').internalid;
                  if (soStatus === 'pendingApproval') {
                    statusName = Utils.translate('Pending Approval');
                  } else if (soStatus === 'pendingFulfillment') {
                    statusName = Utils.translate('Pending Fulfillment');
                  } else if (soStatus === 'pendingBilling') {
                    statusName = Utils.translate('Pending Billing');
                  } else if (soStatus === 'partiallyFulfilled') {
                    statusName = Utils.translate('Partially Fulfilled');
                  } else {
                    statusName = invoice.get('status').internalid;
                  }
                  invoice.status.name = invoice.get('status').internalid === 'open' ? new Handlebars.SafeString(Utils.translate('<span class="invoice-pending">Pending</span>')) : new Handlebars.SafeString(Utils.translate('<span class="invoice-paid">$(0)</span>', statusName));
                  return new Backbone.Model({
                    touchpoint: 'customercenter',
                    title: new Handlebars.SafeString(Utils.translate('<span class="tranid">$(0)</span>', invoice.get('tranid'))),
                    detailsURL: `/purchases/view/${invoice.get('recordtype')}/${invoice.get('internalid')}`,
                    id: invoice.get('internalid'),
                    internalid: invoice.get('internalid'),
                    status: invoice.get('status'),
                    columns: self._buildColumns(selectedColumns, invoice)
                  });
                }));
                return new BackboneCollectionView({
                  childView: RecordViewsView,
                  collection: records_collection,
                  viewsPerRow: 1,
                  childViewOptions: {
                    referrer: ''
                  }
                });
              } catch (e) {
                console.log("overview error", e)
              }
            }
          })
        });
      }
    }
  };
});

Leave a comment

Your email address will not be published. Required fields are marked *