<commit_before>/*
 * This program is part of the OpenLMIS logistics management information
 * system platform software.
 *
 * Copyright © 2015 ThoughtWorks, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version. This program is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details. You should
 * have received a copy of the GNU Affero General Public License along with
 * this program. If not, see http://www.gnu.org/licenses. For additional
 * information contact <EMAIL>
 */

package org.openlmis.core.view.viewmodel;

import org.openlmis.core.model.RnrFormItem;

import lombok.Data;

@Data
public class RequisitionFormItemViewModel {

    private String fmn;
    private String productName;
    private String initAmount;
    private String received;
    private String issued;
    private String theoretical;
    private String total;
    private String inventory;
    private String different;
    private String totalRequest;

    public RequisitionFormItemViewModel(RnrFormItem item) {

        this.fmn = (item.getProduct().getCode());
        this.productName = item.getProduct().getPrimaryName();

        long issued = item.getIssued();
        long received = item.getReceived();
        long theoretical = item.getInitialAmount() + received - item.getIssued();
        long inventory = item.getInventory();

        this.initAmount = String.valueOf(item.getInitialAmount());
        this.received = String.valueOf(received);
        this.issued = String.valueOf(issued);
        this.theoretical = String.valueOf(theoretical);
        this.total = "-";
        this.inventory = String.valueOf(inventory);
        this.different = String.valueOf(inventory - theoretical);
        this.totalRequest = String.valueOf(issued * 2 - inventory);
    }
}<commit_msg>HL-#69-change calculation rule, do not allow negative values<commit_after>/*
 * This program is part of the OpenLMIS logistics management information
 * system platform software.
 *
 * Copyright © 2015 ThoughtWorks, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version. This program is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details. You should
 * have received a copy of the GNU Affero General Public License along with
 * this program. If not, see http://www.gnu.org/licenses. For additional
 * information contact <EMAIL>
 */

package org.openlmis.core.view.viewmodel;

import org.openlmis.core.model.RnrFormItem;

import lombok.Data;

@Data
public class RequisitionFormItemViewModel {

    private String fmn;
    private String productName;
    private String initAmount;
    private String received;
    private String issued;
    private String theoretical;
    private String total;
    private String inventory;
    private String different;
    private String totalRequest;

    public RequisitionFormItemViewModel(RnrFormItem item) {

        this.fmn = (item.getProduct().getCode());
        this.productName = item.getProduct().getPrimaryName();

        long issued = item.getIssued();
        long received = item.getReceived();
        long theoretical = item.getInitialAmount() + received - item.getIssued();
        theoretical = theoretical > 0 ? theoretical : 0;
        long inventory = item.getInventory();
        long different = inventory - theoretical;
        different = different > 0 ? different : 0;

        long totalRequest = issued * 2 - inventory;
        totalRequest = totalRequest > 0 ? totalRequest : 0;

        this.initAmount = String.valueOf(item.getInitialAmount());
        this.received = String.valueOf(received);
        this.issued = String.valueOf(issued);
        this.theoretical = String.valueOf(theoretical);
        this.total = "-";
        this.inventory = String.valueOf(inventory);
        this.different = String.valueOf(different);
        this.totalRequest = String.valueOf(totalRequest);
    }
}
{'fraction_non_alphanumeric': 0.08120398440883499, 'fraction_numerical': 0.0043308791684712, 'mean_word_length': 3.3823529411764706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2501374', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1137, 'n_words': 438}