+=head2 CalcDateDue
+
+$newdatedue = CalcDateDue($startdate,$loanlength,$branchcode);
+this function calculates the due date given the loan length ,
+checking against the holidays calendar as per the 'useDaysMode' syspref.
+C<$startdate> = C4::Dates object representing start date of loan period (assumed to be today)
+C<$branch> = location whose calendar to use
+C<$loanlength> = loan length prior to adjustment
+=cut
+
+sub CalcDateDue {
+ my ($startdate,$loanlength,$branch) = @_;
+ if(C4::Context->preference('useDaysMode') eq 'Days') { # ignoring calendar
+ my $datedue = time + ($loanlength) * 86400;
+ #FIXME - assumes now even though we take a startdate
+ my @datearr = localtime($datedue);
+ return C4::Dates->new( sprintf("%04d-%02d-%02d", 1900 + $datearr[5], $datearr[4] + 1, $datearr[3]), 'iso');
+ } else {
+ warn $branch;
+ my $calendar = C4::Calendar->new( branchcode => $branch );
+ my $datedue = $calendar->addDate($startdate, $loanlength);
+ return $datedue;
+ }
+}
+