/************ 別表16(2)(定率法による償却額の計算)*************/
/********** (copyright © 2009 TenFeet Co. Ltd.) **********/
function calcBP(){
   xx = new Array(7,9,10,13,14,15,16,17,18,19,21,22,23,24,26,28,
      31,32,33,34,36,37,38,39,40,41,42,43,44,45,46,47,48,50,51);
   yy = new Array(9,22,35,48,61);
   for (i=0; i<yy.length; i++) {
      var ctcnt=0;
      for (c=yy[i]; c<yy[i]+4; c++) {
         var c7=CellValue("1602",7,c);
         var c8=CellValue("1602",8,c);
         SetCellValue("1602",9,c,c7-c8);

         var c10=CellValue("1602",10,c);
         var c11=CellValue("1602",11,c);
         var c12=CellValue("1602",12,c);
         SetCellValue("1602",13, c, c10-c11-c12);

         var c13=CellValue("1602",13,c);
         var c14=CellValue("1602",14,c);
         var c15=CellValue("1602",15,c);
         SetCellValue("1602",16,c,c13+c14+c15);

         var ct=CellString("1602", 3,c);
         if (ct=="(当期除却)"){
            SetCellString("1602",16,c,"");
            SetCellString("1602",18,c,"");
            ctcnt=ctcnt+1;}
         else {
            var c16=CellValue("1602",16,c);
            var c17=CellValue("1602",17,c);
            SetCellValue("1602",18,c,c16-c17);
         }
         var c18=CellValue("1602",18,c);
         var c19=CellValue("1602",19,c);
         var c21=CellValue("1602",21,c);
         var c22=CellValue("1602",22,c);
         if (c18-c19<0){
            SetCellValue("1602",23, c, c21+c22);}
         else {
            if (c21+c22>c18-c19){
               SetCellValue("1602",23, c, c18-c19);
            } else {
               SetCellValue("1602",23, c, c21+c22);
            }
         }
         var c34=CellValue("1602",34,c);
         var c36=CellValue("1602",36,c);
         var c37=CellValue("1602",37,c);
         SetCellValue("1602",38, c, c34+c36+c37);

         var c41=CellValue("1602",41,c);
         var c42=CellValue("1602",42,c);
         var c43=CellValue("1602",43,c);
         var c44=CellValue("1602",44,c);
         SetCellValue("1602",45, c, c41+c42-c43-c44);

         var c46=CellValue("1602",46,c);
         var c47=CellValue("1602",47,c);
         SetCellValue("1602",48, c, c46-c47);
      }
      var ft=CellString("1602",1, yy[i]+4);
      if ( ft=="合計" | ft=="頁合計" | ft=="頁計") {
         for (j=0; j<xx.length; j++) {
            var c1=CellValue("1602", xx[j], yy[i]+0);
            var c2=CellValue("1602", xx[j], yy[i]+1);
            var c3=CellValue("1602", xx[j], yy[i]+2);
            var c4=CellValue("1602", xx[j], yy[i]+3);
            SetCellValue("1602", xx[j], yy[i]+4, c1+c2+c3+c4);
            if (xx[j]==16 | xx[j]==18){
               if (ctcnt>0){SetCellString("1602",xx[j],yy[i]+4,"");}
            }
         }
      }
   }
}