package cn.lihongjie.coal.warehouseReceipt.dto;

import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.warehouse.dto.WarehouseDto;
import cn.lihongjie.coal.warehouseReceiptDetail.dto.WarehouseReceiptDetailDto;

import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;

import lombok.Data;

import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;

import java.time.LocalDateTime;
import java.util.List;

@Data
public class WarehouseReceiptDto extends OrgCommonDto {


    @Comment("单据类型")
    private String receiptType;

    @Formula(
            "(select i.name\n"
            + "from t_dictionary d,\n"
            + "     t_dictionary_item i\n"
            + "where d.id = i.dictionary_id\n"
            + "  and d.code = 'warehouse.receiptType'\n"
            + "  and i.code = receipt_type)")
    private String receiptTypeName;

    @Comment("单据编号")
    private String receiptNo;

    @Comment("事由")
    private String reason;

    @Comment("是由说明")
    private String reasonDesc;

    @ManyToOne
    private WarehouseDto warehouse;


    @ManyToOne
    private WarehouseDto warehouse2;

    @Comment("单据日期")
    private LocalDateTime receiptDate;


    @OneToMany
    private List<WarehouseReceiptDetailDto> detail;


    @Formula("(select sum(d.number * d.price) from t_warehouse_receipt_detail d where d.receipt_id = id)")
    private Double amount;


    @Formula("(select sum(d.number) from t_warehouse_receipt_detail d where d.receipt_id = id)")
    private Double number;

}
