/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2013 VillageReach
 *
 * 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 info@OpenLMIS.org. 
 */

package org.openlmis.core.service;

import lombok.NoArgsConstructor;
import org.openlmis.core.domain.BaseModel;
import org.openlmis.core.domain.PriceSchedule;
import org.openlmis.core.domain.PriceScheduleCategory;
import org.openlmis.core.domain.Product;
import org.openlmis.core.repository.PriceScheduleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@NoArgsConstructor
public class PriceScheduleService {

    @Autowired
    private PriceScheduleRepository repository;

    public void save(PriceSchedule priceSchedule) {
        if(priceSchedule.getId() == null)
          repository.insert(priceSchedule);

        else
            repository.update(priceSchedule);
    }

    public BaseModel getByProductCodePriceScheduleCategory(PriceSchedule priceSchedule) {
        return repository.getByProductCodePriceScheduleCategory(priceSchedule);
    }

    public List<PriceSchedule> getByProductId(Long id) {
        return repository.getByProductId(id);
    }

    public PriceScheduleCategory getPriceScheduleCategoryByCode(String code){
        return repository.getPriceScheduleCategoryByCode(code);
    }

    @Transactional
    public void saveAll(List<PriceSchedule> priceSchedules, Product product) {

        for(PriceSchedule priceSchedule : priceSchedules){

            if(priceSchedule.getId() == null)
            priceSchedule.setProduct(product);
            priceSchedule.setModifiedBy(product.getModifiedBy());
            priceSchedule.setCreatedBy(product.getModifiedBy());
            priceSchedule.setModifiedDate(product.getModifiedDate());
            save(priceSchedule);
        }
    }

    public List<PriceScheduleCategory> getPriceScheduleCategories() {

        return repository.getPriceScheduleCategories();
    }

   public List<PriceSchedule> getPriceScheduleFullSupplyFacilityApprovedProduct(Long programId, Long facilityId){
       return repository.getPriceScheduleFullSupplyFacilityApprovedProduct(programId, facilityId);
   }
}

@@ -16,123 +16,301 @@
 ram 
-is part of the OpenLMIS logistics management information system platform software.%0A * Copyright %C2%A9 2013 VillageReach
+was produced for the U.S. Agency for International Development. It was prepared by the USAID %7C DELIVER PROJECT, Task Order 4. It is part of a project which utilizes code originally licensed under the terms of the Mozilla Public License (MPL) v2 and therefore is licensed under MPL v2 or later.
 %0A *%0A
@@ -407,34 +407,23 @@
  of the 
-GNU Affero General
+Mozilla
  Public 
@@ -454,21 +454,15 @@
 the 
-Free Software
+Mozilla
  Fou
@@ -489,9 +489,9 @@
 ion 
-3
+2
  of 
@@ -544,18 +544,16 @@
 sion.%0A *
- %C2%A0
 %0A * This
@@ -727,17 +727,16 @@
 PURPOSE.
-%C2%A0
  See the
@@ -736,34 +736,23 @@
 See the 
-GNU Affero General
+Mozilla
  Public 
@@ -777,16 +777,19 @@
 etails.%0A
+ *%0A
  * You s
@@ -826,26 +826,15 @@
 the 
-GNU Affero General
+Mozilla
  Pub
@@ -869,17 +869,16 @@
 program.
-%C2%A0
  If not,
@@ -897,81 +897,24 @@
 www.
-gnu.org/licenses. %C2%A0For additional information contact info@OpenLMIS.org.%C2%A0
+mozilla.org/MPL/
 %0A */

Add copyright text to price schedule service