package com.realnet.vpspack.Services;
import com.realnet.vpspack.Repository.Xero_invoices_lineRepository;
import com.realnet.vpspack.Entity.Xero_invoices_line
;import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import com.realnet.SequenceGenerator.Service.SequenceService;
import com.realnet.Notification.Entity.NotificationService;
import org.springframework.data.domain.Page;
import com.realnet.realm.Entity.Realm;
import com.realnet.realm.Services.RealmService;
import org.springframework.data.domain.Pageable;
import org.springframework.http.*;import com.realnet.users.service1.AppUserServiceImpl;
import com.realnet.users.entity1.AppUser;




















	import org.springframework.stereotype.Service;

@Service
 public class Xero_invoices_lineService {
@Autowired
private Xero_invoices_lineRepository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;



















public Xero_invoices_line Savedata(Xero_invoices_line data) {




















	data.setUpdatedBy(getUser().getUserId());
		data.setCreatedBy(getUser().getUserId());
		data.setAccountId(getUser().getAccount().getAccount_id());
Xero_invoices_line save = Repository.save(data);
				return save;	
			}


//	get all with pagination
	public Page<Xero_invoices_line> getAllWithPagination(Pageable page) {
		return Repository.findAll(page, getUser().getUserId());
	}			
public List<Xero_invoices_line> getdetails() {  
		List<Realm> realm = realmService.findByUserId(getUser().getUserId());
List<Xero_invoices_line> all = Repository.findAll(getUser().getUserId());
		
		return all ;		}


public Xero_invoices_line getdetailsbyId(Integer id) {
	return Repository.findById(id).get();
			}


	public void delete_by_id(Integer id) {
 Repository.deleteById(id);
}


public Xero_invoices_line update(Xero_invoices_line data,Integer id) {
	Xero_invoices_line old = Repository.findById(id).get();
old.setPayed(data.getPayed());

old.setInvoice_sent(data.getInvoice_sent());

old.setCoustomer(data.getCoustomer());

old.setAgent(data.getAgent());

old.setInvoice_id(data.getInvoice_id());

old.setInvoice_number(data.getInvoice_number());

old.setTotal_price(data.getTotal_price());

old.setShow_btn(data.getShow_btn());

old.setShow_pdf_btn(data.getShow_pdf_btn());

old.setSend_invoice_btn(data.getSend_invoice_btn());

final Xero_invoices_line test = Repository.save(old);
		data.setUpdatedBy(getUser().getUserId());
  return test;} 




















 public AppUser getUser() {
		AppUser user = userService.getLoggedInUser();
		return user;

	}}
