update vs4tarcard set tricduedate=(select tivoduedate from vs4tinvoice where tivono=tricdocno)where trictype='I'
update vs4tarcard set tricduedate=tricdocdate where tricduedate is null
update vs4tarcard set tricsignarrear=(select tivoarrears from vs4tinvoice where tivono=tricdocno)where trictype='I'
update vs4tarcard set tricsignarrear=-1*(select trcnarrears from vs4tarcreditnote where trcnno=tricdocno) where  trictype='C'
update vs4tarcard set tricsignarrear=(select tdbnarrears from vs4tardebitnote where tdbnno=tricdocno) where trictype='D'
update vs4tarcard set tricsignarrear=0 where trictype='P'

update vs4tarcard set tricsigntotal=(select tivograndtotal from vs4tinvoice where tivono=tricdocno)where trictype='I'
update vs4tarcard set tricsigntotal=-1*(select trcngrandtotal from vs4tarcreditnote where trcnno=tricdocno) where  trictype='C'
update vs4tarcard set tricsigntotal=(select tdbngrandtotal from vs4tardebitnote where tdbnno=tricdocno) where trictype='D'
update vs4tarcard set tricsigntotal=-1*(select trvhsubtotal from vs4treceivevoucher where trvhno=tricdocno) where trictype='P'


update vs4tapcard set tpicduedate=(select tiapduedate from vs4tapinvoice where tiapno=tpicdocno)where tpictype='I'
update vs4tapcard set tpicduedate=tpicdocdate where tpicduedate is null
update vs4tapcard set tpicsignarrear=(select tiaparrears from vs4tapinvoice where tiapno=tpicdocno)where tpictype='I'
update vs4tapcard set tpicsignarrear=-1*(select tpcnarrears from vs4tapcreditnote where tpcnno=tpicdocno) where  tpictype='C'
update vs4tapcard set tpicsignarrear=(select tdenarrears from vs4tapdebitnote where tdenno=tpicdocno) where tpictype='D'
update vs4tapcard set tpicsignarrear=0 where tpictype='P'

update vs4tapcard set tpicsigntotal=(select tiapgrandtotal from vs4tapinvoice where tiapno=tpicdocno)where tpictype='I'
update vs4tapcard set tpicsigntotal=-1*(select tpcngrandtotal from vs4tapcreditnote where tpcnno=tpicdocno) where  tpictype='C'
update vs4tapcard set tpicsigntotal=(select tdengrandtotal from vs4tapdebitnote where tdenno=tpicdocno) where tpictype='D'
update vs4tapcard set tpicsigntotal=-1*(select tapvsubtotal from vs4tAPvoucher where tapvno=tpicdocno) where tpictype='P'