"use strict";
var Item = require('./transactions').item,
  List = require('./transactions').list,
  moment = require('moment'),
  _ = require('lodash'),
  when = require('when'),
  stripe = require('stripe')(process.env.STRIPE_KEY);

// Model interactions

module.exports = {

  save: function (trans) {
    var promise, actions = [], list = new List();

    promise = when.promise(function (resolve, reject) {

      stripe.balance.retrieveTransaction(
        trans.data.object.balance_transaction,
        function(err, balanceTransaction) {

          if (err) {
            console.log(err);
            reject(err);
            return false;
          }

          var date = moment(balanceTransaction.available_on).format('YYYY.MM.DD'),
              time = moment(balanceTransaction.available_on).format('HH:MM');

          _.forEach(balanceTransaction.fee_details, function (fee) {
            var obj;

            console.log(fee);

            obj = {
              date: date,
              time: time,
              name: fee.description,
              amount: fee.amount
            };

            list.transactions.push(new Item(obj));
          });

          list.save()
          .catch(function (err) {
            reject(err);
          })
          .then(function (reply) {
            resolve(reply);
          });
        }
      );

    });

    return promise;
  },

  report: function () {
    var promise, list = new List(), week = moment().isoWeek();

    return list.fetch(week)
    .then(function (result) {
      return list;
    });
  }

};
@@ -911,39 +911,8 @@
 j;%0A%0A
-            console.log(fee);%0A%0A
     
@@ -1065,16 +1065,47 @@
     %7D;%0A%0A
+            console.log(obj);%0A%0A
         

test time;