'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Payment = function () {
  function Payment(data) {
    _classCallCheck(this, Payment);

    this.update(data);
  }

  _createClass(Payment, [{
    key: 'update',
    value: function update(data) {

      if (moment(data.payment_duedate).isValid()) data.payment_duedate = moment(data.payment_duedate).format('YYYY-MM-DD');else data.payment_duedate = "";

      if (moment(data.payment_datetime).isValid()) data.payment_datetime = moment(data.payment_datetime).format('YYYY-MM-DD');else data.payment_datetime = "";

      if (moment(data.created_datetime).isValid()) data.created_datetime = moment(data.created_datetime).format('YYYY-MM-DD');else data.created_datetime = "";

      for (var field in data) {
        this[field] = data[field];
      }
    }
  }, {
    key: 'edit',
    value: function edit() {
      edit_payment(this.id);
    }
  }, {
    key: 'new',
    value: function _new() {
      new_payemnt();
    }
  }, {
    key: 'getStatus',
    value: function getStatus() {
      var status = "";

      if (this.payment_status == 1) {
        if (dateset(this.payment_duedate) && dateset(this.payment_datetime) && moment(this.payment_duedate).isBefore(moment(this.payment_datetime))) status = "paid_late";else status = "paid";
      } else if (this.payment_status == 2) status = "pending";else {
        if (!dateset(this.payment_duedate)) status = "unpaid_ontime";else {
          if (moment(this.payment_duedate).isBefore(moment())) status = "pastdue";else status = "unpaid_ontime";
        }
      }

      return status;
    }
  }]);

  return Payment;
}(); // end Payment class

//export default Payment;