$lines = Get-Content getbills.php
$start = -1
for($i=0; $i -lt $lines.Count; $i++){
    if($lines[$i].TrimStart().StartsWith('$prevdue=')){
        $start = $i
        break
    }
}
if($start -eq -1){ throw 'start not found' }
$end = $lines.Count
for($j=$start; $j -lt $lines.Count; $j++){
    if($lines[$j].TrimStart().StartsWith('$string = trim')){
        $end = $j
        break
    }
}
if($end -eq $lines.Count){ throw 'end not found' }
$newBlock = @(
"                  `$prevdue = `$getd['bl_prevdue'];",
"",
"                  `$currentc = `$getd['bl_amt'];     ",
"                  //$currentc=`$getd['bl_pak'];",
"                  `$showGst = (`$getcom['isgst']=='1');",
"                  if(`$showGst){",
"                      `$gstvalu=(floatval(`$currentc)*100)/118;",
"                      `$gstamt=floatval(`$currentc)-floatval(`$gstvalu);",
"                      `$packamt=`$gstvalu;      ",
"                      `$gst=`$gstamt;",
"                      `$gsth=round(floatval(`$gst)/2,2);",
"                  }else{",
"                      `$gstvalu=0;",
"                      `$gstamt=0;",
"                      `$packamt=`$currentc;",
"                      `$gst=0;",
"                      `$gsth=0;",
"                  }",
"                    `$subto=`$packamt;//floatval(`$getcust['price'])+floatval(`$gst);",
"                    `$prc=floatval(`$subto)*(0);",
"                    `$package=`$packamt;//`$getcust['price'];",
"                    // if(`$prevdue!='0'){",
"                    //       `$total=floatval(`$getcust['price'])+floatval(`$prc)+`$gst+`$prevdue;",
"                    //     }else{",
"",
"                    //       `$total=floatval(`$getcust['price'])+floatval(`$prc)+`$gst;",
"                    //     }",
"                    //`$total=floatval(`$getcust['price'])+floatval(`$prc)+`$gst;",
"                    `$total=`$package;",
"                    //`$packbill=floatval(`$packamt)-floatval(`$gst);",
"                    `$packbill=floatval(`$packamt);",
"                    //`$curcharges=floatval(`$packbill)+floatval(`$gst);",
"                    `$curcharges=floatval(`$packbill);",
"                     `$toalcharges=(floatval(`$packamt)-floatval(`$getd['bl_disc']))+floatval(`$gstamt)+floatval(`$prevdue);",
"",
)
$newLines = $lines[0..($start-1)] + $newBlock + $lines[$end..($lines.Count-1)]
Set-Content getbills.php -Value $newLines
