<commit_before>/*
 * Copyright © 2013 VillageReach.  All Rights Reserved.  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
 *
 * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

var RnrLineItem = function (lineItem, numberOfMonths, programRnrColumnList, rnrStatus) {
  $.extend(true, this, lineItem);
  this.numberOfMonths = numberOfMonths;
  this.rnrStatus = rnrStatus;
  this.programRnrColumnList = programRnrColumnList;

  RnrLineItem.prototype.initLossesAndAdjustments = function () {
    var tempLossesAndAdjustments = [];

    _.each(this.lossesAndAdjustments, function (lossAndAdjustmentJson) {
      tempLossesAndAdjustments.push(new LossAndAdjustment(lossAndAdjustmentJson));
    });

    this.lossesAndAdjustments = tempLossesAndAdjustments;
  };

  RnrLineItem.prototype.reduceForApproval = function() {
    return _.pick(this, 'id', 'productCode', 'quantityApproved', 'remarks');
  };

  RnrLineItem.prototype.init = function () {
    this.initLossesAndAdjustments();
    if (this.previousNormalizedConsumptions == undefined || this.previousNormalizedConsumptions == null)
      this.previousNormalizedConsumptions = [];

    this.reEvaluateTotalLossesAndAdjustments();
    this.fillConsumptionOrStockInHand();
  };

  RnrLineItem.prototype.fillConsumptionOrStockInHand = function () {
    this.beginningBalance = utils.getValueFor(this.beginningBalance);
    this.quantityReceived = utils.getValueFor(this.quantityReceived);
    this.quantityDispensed = utils.getValueFor(this.quantityDispensed);
    this.totalLossesAndAdjustments = utils.getValueFor(this.totalLossesAndAdjustments, 0);
    this.stockInHand = utils.getValueFor(this.stockInHand);

    this.calculateConsumption();
    this.calculateStockInHand();
    this.fillNormalizedConsumption();
  };

  function statusBeforeApproval() {
    return rnrStatus == 'INITIATED' || rnrStatus == 'SUBMITTED' || rnrStatus == 'AUTHORIZED';
  }

  RnrLineItem.prototype.fillPacksToShip = function () {
    this.quantityApproved = utils.getValueFor(this.quantityApproved);
    var orderQuantity;

    if (statusBeforeApproval()) orderQuantity = isUndefined(this.quantityRequested) ? this.calculatedOrderQuantity : this.quantityRequested;
    else orderQuantity = this.quantityApproved;

    this.calculatePacksToShip(orderQuantity);
    this.calculateCost();
  };

  RnrLineItem.prototype.fillNormalizedConsumption = function () {
    this.calculateNormalizedConsumption();
    this.fillAMC();
  };

  RnrLineItem.prototype.fillAMC = function () {
    this.calculateAMC();
    this.fillMaxStockQuantity();
  };

  RnrLineItem.prototype.fillMaxStockQuantity = function () {
    this.calculateMaxStockQuantity();
    this.fillCalculatedOrderQuantity();
  };
<commit_msg>|#813| +Rahul| update packtoship on approve rnr screen according to quantity approved<commit_after>/*
 * Copyright © 2013 VillageReach.  All Rights Reserved.  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
 *
 * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

var RnrLineItem = function (lineItem, numberOfMonths, programRnrColumnList, rnrStatus) {
  $.extend(true, this, lineItem);
  this.numberOfMonths = numberOfMonths;
  this.rnrStatus = rnrStatus;
  this.programRnrColumnList = programRnrColumnList;

  RnrLineItem.prototype.initLossesAndAdjustments = function () {
    var tempLossesAndAdjustments = [];

    _.each(this.lossesAndAdjustments, function (lossAndAdjustmentJson) {
      tempLossesAndAdjustments.push(new LossAndAdjustment(lossAndAdjustmentJson));
    });

    this.lossesAndAdjustments = tempLossesAndAdjustments;
  };

  RnrLineItem.prototype.reduceForApproval = function() {
    return _.pick(this, 'id', 'productCode', 'quantityApproved', 'remarks');
  };

  RnrLineItem.prototype.init = function () {
    this.initLossesAndAdjustments();
    if (this.previousNormalizedConsumptions == undefined || this.previousNormalizedConsumptions == null)
      this.previousNormalizedConsumptions = [];

    this.reEvaluateTotalLossesAndAdjustments();
    this.fillConsumptionOrStockInHand();
  };

  RnrLineItem.prototype.fillConsumptionOrStockInHand = function () {
    this.beginningBalance = utils.getValueFor(this.beginningBalance);
    this.quantityReceived = utils.getValueFor(this.quantityReceived);
    this.quantityDispensed = utils.getValueFor(this.quantityDispensed);
    this.totalLossesAndAdjustments = utils.getValueFor(this.totalLossesAndAdjustments, 0);
    this.stockInHand = utils.getValueFor(this.stockInHand);

    this.calculateConsumption();
    this.calculateStockInHand();
    this.fillNormalizedConsumption();
  };

  function statusBeforeAuthorize() {
    return rnrStatus == 'INITIATED' || rnrStatus == 'SUBMITTED';
  }

  RnrLineItem.prototype.fillPacksToShip = function () {
    this.quantityApproved = utils.getValueFor(this.quantityApproved);
    var orderQuantity;

    if (statusBeforeAuthorize()) orderQuantity = isUndefined(this.quantityRequested) ? this.calculatedOrderQuantity : this.quantityRequested;
    else orderQuantity = this.quantityApproved;

    this.calculatePacksToShip(orderQuantity);
    this.calculateCost();
  };

  RnrLineItem.prototype.fillNormalizedConsumption = function () {
    this.calculateNormalizedConsumption();
    this.fillAMC();
  };

  RnrLineItem.prototype.fillAMC = function () {
    this.calculateAMC();
    this.fillMaxStockQuantity();
  };

  RnrLineItem.prototype.fillMaxStockQuantity = function () {
    this.calculateMaxStockQuantity();
    this.fillCalculatedOrderQuantity();
  };

{'fraction_non_alphanumeric': 0.1067859021567596, 'fraction_numerical': 0.003682272488164124, 'mean_word_length': 4.820408163265306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4557348', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1697, 'n_words': 293}