add column vatReverseCharge to table hs_office_debitor + view hs_office_debitor_rv

This commit is contained in:
Michael Hoennig 2024-01-11 09:34:10 +01:00
parent ab281c93a7
commit 340a53a3d5
4 changed files with 25 additions and 8 deletions

View File

@ -10,6 +10,7 @@ import net.hostsharing.hsadminng.stringify.Stringifyable;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import jakarta.persistence.*; import jakarta.persistence.*;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import static net.hostsharing.hsadminng.stringify.Stringify.stringify; import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
@ -28,6 +29,7 @@ public class HsOfficeDebitorEntity implements Stringifyable {
stringify(HsOfficeDebitorEntity.class, "debitor") stringify(HsOfficeDebitorEntity.class, "debitor")
.withProp(HsOfficeDebitorEntity::getDebitorNumber) .withProp(HsOfficeDebitorEntity::getDebitorNumber)
.withProp(HsOfficeDebitorEntity::getPartner) .withProp(HsOfficeDebitorEntity::getPartner)
// TODO: add defaultPrefix?
.withSeparator(": ") .withSeparator(": ")
.quotedValues(false); .quotedValues(false);
@ -59,21 +61,34 @@ public class HsOfficeDebitorEntity implements Stringifyable {
@Column(name = "vatbusiness") @Column(name = "vatbusiness")
private boolean vatBusiness; private boolean vatBusiness;
@Column(name = "vatreversecharge")
private boolean vatReverseCharge;
@ManyToOne @ManyToOne
@JoinColumn(name = "refundbankaccountuuid") @JoinColumn(name = "refundbankaccountuuid")
private HsOfficeBankAccountEntity refundBankAccount; private HsOfficeBankAccountEntity refundBankAccount;
@Column(name = "defaultprefix", columnDefinition = "char(3) not null")
private String defaultPrefix;
public String getDebitorNumberString() { 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); return partner.getDebitorNumberPrefix() + String.format("%02d", debitorNumberSuffix);
} }
public int getDebitorNumber() { public Integer getDebitorNumber() {
return Integer.parseInt(getDebitorNumberString()); return Optional.ofNullable(getDebitorNumberString()).map(Integer::parseInt).orElse(null);
} }
@Column(name = "defaultprefix", columnDefinition = "char(3) not null")
private String defaultPrefix;
@Override @Override
public String toString() { public String toString() {
return stringify.apply(this); return stringify.apply(this);

View File

@ -13,7 +13,8 @@ create table hs_office_debitor
billingContactUuid uuid not null references hs_office_contact(uuid), billingContactUuid uuid not null references hs_office_contact(uuid),
vatId varchar(24), -- TODO.spec: here or in person? vatId varchar(24), -- TODO.spec: here or in person?
vatCountryCode varchar(2), 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), refundBankAccountUuid uuid references hs_office_bankaccount(uuid),
defaultPrefix char(3) not null defaultPrefix char(3) not null
constraint check_member_code check ( constraint check_member_code check (

View File

@ -193,6 +193,7 @@ call generateRbacRestrictedView('hs_office_debitor', 'target.debitorNumberSuffix
vatId = new.vatId, vatId = new.vatId,
vatCountryCode = new.vatCountryCode, vatCountryCode = new.vatCountryCode,
vatBusiness = new.vatBusiness, vatBusiness = new.vatBusiness,
vatreversecharge = new.vatreversecharge,
defaultPrefix = new.defaultPrefix defaultPrefix = new.defaultPrefix
$updates$); $updates$);
--// --//

View File

@ -38,8 +38,8 @@ begin
raise notice '- using partner (%): %', relatedPartner.uuid, relatedPartner; raise notice '- using partner (%): %', relatedPartner.uuid, relatedPartner;
raise notice '- using billingContact (%): %', relatedContact.uuid, relatedContact; raise notice '- using billingContact (%): %', relatedContact.uuid, relatedContact;
insert insert
into hs_office_debitor (uuid, partneruuid, debitornumbersuffix, billable, billingcontactuuid, vatbusiness, refundbankaccountuuid, 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, relatedBankAccountUuid, defaultPrefix); values (uuid_generate_v4(), relatedPartner.uuid, debitorNumberSuffix, true, relatedContact.uuid, true, false, relatedBankAccountUuid, defaultPrefix);
end; $$; end; $$;
--// --//