
delete from challandetail
delete from challan



insert into Challan(Oid,SequentialNumber,feereceiptno,ChallanDate
, ReferenceNo, StudentName, PaymentType, ChequeDDChallanNo, ChequeDDChallanDate
, BankName, Cancel, PostingNo, PostingStatus, AcademicYearId, CollectOn
, LastChangeDate, SchoolId, Remarks, OptimisticLockField, GCRecord
, DataInput, CancelDate, ReceiptPerson, UserInput
--, Fdt
, RptDate
, [Print] , SMS, ReceivedChequeBankName
,Status)

select Oid, SequentialNumber, FeeReceiptNo, ReceiptDate
, ReferenceNo, StudentName, PaymentType, ChequeDDChallanNo, ChequeDDChallanDate
, BankName, Cancel, PostingNo, PostingStatus, AcademicYearId, FeeReceiptScreenType
, LastChangeDate, SchoolId, Remarks, OptimisticLockField, GCRecord
, DataInput, CancelDate, ReceiptPerson, UserInput
--, Fdt
, RptDate
, [Print], SMS, ReceivedChequeBankName
,0
from feereceipt
where AcademicYearId=(select Oid from AcademicYearMaster where StartYear=2017)



insert into ChallanDetail(Oid, ChallanNo, FeeType, FeeIndex, FeeName
, FeeAmount, ConcessionAmt, ExclusionAmount, NetAmount
, Payable, OptimisticLockField, GCRecord, OptionalSubjectFee
, RefundAmount)

select a.Oid, ReceiptNo, FeeType, FeeIndex, FeeName
, FeeAmount, ConcessionAmount, ExclusionAmount, NetAmount
, Payable, a.OptimisticLockField, a.GCRecord, OptionalSubjectFee
, RefundAmount
from FeeReceiptDetail a
join FeeReceipt b  on b.Oid =a.ReceiptNo
where AcademicYearId=(select Oid from AcademicYearMaster where StartYear=2017)


update Sequence set ChallanSequence = NextSequence, ChallanPreFix = PreFixCode
where  AcademicYear=(select Oid from AcademicYearMaster where StartYear=2017)
and PreFixCode is not null
