<commit_before>(function() {
  var module = angular.module('fim.base');
  module.config(function($routeProvider) {
    $routeProvider
      .when('/goods/:id_rs/:listing', {
        templateUrl: 'partials/goods.html',
        controller: 'GoodsCtrl'
      })
  });

  module.controller('GoodsCtrl', function($location, $scope, $http, $routeParams, nxt, plugins, shoppingCartService, AccountBalanceProvider, AllGoodsProvider, PastGoodsProvider, GoodsDetailsProvider, UserGoodsProvider, SoldGoodsProvider, DeliveryConfirmedGoodsProvider) {

    $scope.id_rs = $routeParams.id_rs;
    $scope.paramSection = $routeParams.listing;

    var api = nxt.get($scope.id_rs);

    $scope.shoppingCart = shoppingCartService.get();

    $scope.deleteGood = function(good, index) {
      var deleteGoodArgs = {
        requestType: 'dgsDelisting',
        goods: good.goods
      }
      plugins.get('transaction').get('dgsDelisting').execute($scope.id_rs, deleteGoodArgs).then(function(deletedGood) {
        if(deletedGood) {
          $scope.showGoods.entities.splice(index, 1);
        }
      })
    }

    $scope.details = function(goodsDetails) {
      $location.path('/goods/' + $scope.id_rs + '/' + goodsDetails.goods);
    }

    $scope.add = function() {
      var args = {
        requestType: 'dgsListing'
      }
      plugins.get('transaction').get('dgsListing').execute($scope.id_rs, args).then(function(addedGoods) {
        $scope.isAdded = addedGoods;
        // $scope.priceNQT = nxt.util.convertToNQT(addedGoods.priceNXT);
      })
    }

    if ($scope.paramSection == 'listing') {
      $scope.showGoods = new AllGoodsProvider(api, $scope, 10, $scope.id_rs);
      $scope.showGoods.reload();
    } else if ($scope.paramSection == 'cart') {
      $scope.shoppingCart = shoppingCartService.get();
      $scope.total = 0;
      $scope.shoppingCart.forEach(function(good) {
        $scope.total += parseFloat(good.priceFIMK)
        try {
          var data = JSON.parse(good.description);
        } catch (ex) {
          console.log("Unable to parse");
        }
        if (data) {
          good.description = data.description;
          good.image = data.image;
          good.callback = data.callback;
        }
      });

      $scope.accountBalance = new AccountBalanceProvider(api, $scope, $scope.id_rs);
      $scope.accountBalance.reload();
      $scope.placeOrder = function() {
        $scope.balance = $scope.accountBalance.entities;
        $scope.balance.forEach(function(balanceData) {
          if($scope.total >= balanceData.effectiveBalanceNXT){
            $scope.balanceError = "You don't have enough balance to place these orders.";
          } else {
            $scope.balanceError = ' ';
            processCart($scope.shoppingCart);
          }
        })
      }

      function processCart(shoppingCart) {
        if (shoppingCart.length > 0) {
          var shoppingCartGoods = shoppingCart[0];
          var order_args = {
            requestType: "dgsPurchase",
            goods: shoppingCartGoods.goods,
            priceNQT: shoppingCartGoods.priceFIMK,
            name: shoppingCartGoods.name,
            deliveryDeadlineTimestamp: String(nxt.util.convertToEpochTimestamp(Date.now()) + 60 * 60 * 168)
          }
          plugins.get('transaction').get('dgsPurchase').execute($scope.id_rs, order_args).then(function(data) {
            if(data) {  
              $http({
                url: shoppingCartGoods.callback,
                data: shoppingCartGoods,
                method: 'POST'
              }).success(function(data) {
                console.log(data);
              }).error(function(err) {
                console.log(err);
              })
              shoppingCartService.removeItem(0);
              shoppingCart.splice(0, 1);
              processCart(shoppingCart);

              $scope.successful = "Payment Completed";
            }
          });
        }
      }

      $scope.remove = function(index, items) {
        var abc = shoppingCartService.removeItem(index);
        $scope.shoppingCart.splice(index, 1);
        $scope.total -= parseFloat(items.priceFIMK);
      }
    } else if ($scope.paramSection == "pastorders") {

      $scope.shoppingCart = shoppingCartService.get();

      $scope.pastGoods = new PastGoodsProvider(api, $scope, 10, $scope.id_rs);
      $scope.pastGoods.reload();
      $scope.msg = function(id) {
        var recipient_args = {
          recipient: id<commit_msg>send message to seller after purchase item<commit_after>(function() {
  var module = angular.module('fim.base');
  module.config(function($routeProvider) {
    $routeProvider
      .when('/goods/:id_rs/:listing', {
        templateUrl: 'partials/goods.html',
        controller: 'GoodsCtrl'
      })
  });

  module.controller('GoodsCtrl', function($location, $scope, $http, $routeParams, nxt, plugins, shoppingCartService, AccountBalanceProvider, AllGoodsProvider, PastGoodsProvider, GoodsDetailsProvider, UserGoodsProvider, SoldGoodsProvider, DeliveryConfirmedGoodsProvider) {

    $scope.id_rs = $routeParams.id_rs;
    $scope.paramSection = $routeParams.listing;

    var api = nxt.get($scope.id_rs);

    $scope.shoppingCart = shoppingCartService.get();

    $scope.deleteGood = function(good, index) {
      var deleteGoodArgs = {
        requestType: 'dgsDelisting',
        goods: good.goods
      }
      plugins.get('transaction').get('dgsDelisting').execute($scope.id_rs, deleteGoodArgs).then(function(deletedGood) {
        if(deletedGood) {
          $scope.showGoods.entities.splice(index, 1);
        }
      })
    }

    $scope.details = function(goodsDetails) {
      $location.path('/goods/' + $scope.id_rs + '/' + goodsDetails.goods);
    }

    $scope.add = function() {
      var args = {
        requestType: 'dgsListing'
      }
      plugins.get('transaction').get('dgsListing').execute($scope.id_rs, args).then(function(addedGoods) {
        $scope.isAdded = addedGoods;
        // $scope.priceNQT = nxt.util.convertToNQT(addedGoods.priceNXT);
      })
    }

    if ($scope.paramSection == 'listing') {
      $scope.showGoods = new AllGoodsProvider(api, $scope, 10, $scope.id_rs);
      $scope.showGoods.reload();
    } else if ($scope.paramSection == 'cart') {
      $scope.shoppingCart = shoppingCartService.get();
      $scope.total = 0;
      $scope.shoppingCart.forEach(function(good) {
        $scope.total += parseFloat(good.priceFIMK)
        try {
          var data = JSON.parse(good.description);
        } catch (ex) {
          console.log("Unable to parse");
        }
        if (data) {
          good.description = data.description;
          good.image = data.image;
          good.callback = data.callback;
        }
      });

      $scope.accountBalance = new AccountBalanceProvider(api, $scope, $scope.id_rs);
      $scope.accountBalance.reload();
      $scope.placeOrder = function() {
        $scope.balance = $scope.accountBalance.entities;
        $scope.balance.forEach(function(balanceData) {
          if($scope.total >= balanceData.effectiveBalanceNXT){
            $scope.balanceError = "You don't have enough balance to place these orders.";
          } else {
            $scope.balanceError = ' ';
            processCart($scope.shoppingCart);
          }
        })
      }

      function processCart(shoppingCart) {
        if (shoppingCart.length > 0) {
          var shoppingCartGoods = shoppingCart[0];
          var order_args = {
            requestType: "dgsPurchase",
            goods: shoppingCartGoods.goods,
            priceNQT: shoppingCartGoods.priceFIMK,
            name: shoppingCartGoods.name,
            deliveryDeadlineTimestamp: String(nxt.util.convertToEpochTimestamp(Date.now()) + 60 * 60 * 168)
          }
          plugins.get('transaction').get('dgsPurchase').execute($scope.id_rs, order_args).then(function(data) {
            if(data) { 
              var recipient_args = {
                recipient: shoppingCartGoods.sellerRS 
              }
              plugins.get('transaction').get('sendMessage').execute($scope.id_rs, recipient_args).then(function() {
                $http({
                  url: shoppingCartGoods.callback,
                  data: shoppingCartGoods,
                  method: 'POST'
                }).success(function(data) {
                  console.log(data);
                }).error(function(err) {
                  console.log(err);
                })
                shoppingCartService.removeItem(0);
                shoppingCart.splice(0, 1);
                processCart(shoppingCart);

                $scope.successful = "Payment Completed";
              })
            }
          });
        }
      }

      $scope.remove = function(index, items) {
        var abc = shoppingCartService.removeItem(index);
        $scope.shoppingCart.splice(index, 1);
        $scope.total -= parseFloat(items.priceFIMK);
      }
    } else if ($scope.paramSection == "pastorders") {

      $scope.shoppingCart = shoppingCartService.get();

      $scope.pastGoods = new PastGoodsProvider(api, $scope, 10, $scope.id_rs);
      $scope.pastGoods.reload();
      $scope.msg = function(id) {
        var recipient_args = {
          recipient: id
{'fraction_non_alphanumeric': 0.13102328099621008, 'fraction_numerical': 0.004114780725500812, 'mean_word_length': 2.2962169878658103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '796443', 'n_tokens_mistral': 2763, 'n_tokens_neox': 2722, 'n_words': 417}