db-migration #10
@ -10,6 +10,7 @@ import net.hostsharing.hsadminng.stringify.Stringifyable;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
@ -28,6 +29,7 @@ public class HsOfficeDebitorEntity implements Stringifyable {
|
||||
stringify(HsOfficeDebitorEntity.class, "debitor")
|
||||
.withProp(HsOfficeDebitorEntity::getDebitorNumber)
|
||||
.withProp(HsOfficeDebitorEntity::getPartner)
|
||||
// TODO: add defaultPrefix?
|
||||
.withSeparator(": ")
|
||||
.quotedValues(false);
|
||||
|
||||
@ -59,21 +61,34 @@ public class HsOfficeDebitorEntity implements Stringifyable {
|
||||
@Column(name = "vatbusiness")
|
||||
private boolean vatBusiness;
|
||||
|
||||
@Column(name = "vatreversecharge")
|
||||
private boolean vatReverseCharge;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "refundbankaccountuuid")
|
||||
private HsOfficeBankAccountEntity refundBankAccount;
|
||||
|
||||
@Column(name = "defaultprefix", columnDefinition = "char(3) not null")
|
||||
private String defaultPrefix;
|
||||
|
||||
public String getDebitorNumberString() {
|
||||
// TODO: refactor
|
||||
if (partner.getDebitorNumberPrefix() == null ) {
|
||||
if (debitorNumberSuffix == null) {
|
||||
return null;
|
||||
}
|
||||
return String.format("%02d", debitorNumberSuffix);
|
||||
}
|
||||
if (debitorNumberSuffix == null) {
|
||||
return partner.getDebitorNumberPrefix() + "??";
|
||||
}
|
||||
return partner.getDebitorNumberPrefix() + String.format("%02d", debitorNumberSuffix);
|
||||
}
|
||||
|
||||
public int getDebitorNumber() {
|
||||
return Integer.parseInt(getDebitorNumberString());
|
||||
public Integer getDebitorNumber() {
|
||||
return Optional.ofNullable(getDebitorNumberString()).map(Integer::parseInt).orElse(null);
|
||||
}
|
||||
|
||||
@Column(name = "defaultprefix", columnDefinition = "char(3) not null")
|
||||
private String defaultPrefix;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return stringify.apply(this);
|
||||
|
@ -13,7 +13,8 @@ create table hs_office_debitor
|
||||
billingContactUuid uuid not null references hs_office_contact(uuid),
|
||||
vatId varchar(24), -- TODO.spec: here or in person?
|
||||
vatCountryCode varchar(2),
|
||||
vatBusiness boolean not null, -- TODO.spec: more of such?
|
||||
vatBusiness boolean not null,
|
||||
vatReverseCharge boolean not null,
|
||||
refundBankAccountUuid uuid references hs_office_bankaccount(uuid),
|
||||
defaultPrefix char(3) not null
|
||||
constraint check_member_code check (
|
||||
|
@ -193,6 +193,7 @@ call generateRbacRestrictedView('hs_office_debitor', 'target.debitorNumberSuffix
|
||||
vatId = new.vatId,
|
||||
vatCountryCode = new.vatCountryCode,
|
||||
vatBusiness = new.vatBusiness,
|
||||
vatreversecharge = new.vatreversecharge,
|
||||
defaultPrefix = new.defaultPrefix
|
||||
$updates$);
|
||||
--//
|
||||
|
@ -38,8 +38,8 @@ begin
|
||||
raise notice '- using partner (%): %', relatedPartner.uuid, relatedPartner;
|
||||
raise notice '- using billingContact (%): %', relatedContact.uuid, relatedContact;
|
||||
insert
|
||||
into hs_office_debitor (uuid, partneruuid, debitornumbersuffix, billable, billingcontactuuid, vatbusiness, refundbankaccountuuid, defaultprefix)
|
||||
values (uuid_generate_v4(), relatedPartner.uuid, debitorNumberSuffix, true, relatedContact.uuid, true, relatedBankAccountUuid, defaultPrefix);
|
||||
into hs_office_debitor (uuid, partneruuid, debitornumbersuffix, billable, billingcontactuuid, vatbusiness, vatreversecharge, refundbankaccountuuid, defaultprefix)
|
||||
values (uuid_generate_v4(), relatedPartner.uuid, debitorNumberSuffix, true, relatedContact.uuid, true, false, relatedBankAccountUuid, defaultPrefix);
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user