con = $con; $this->aYoyakuNum = $aYoyakuNum; $this->noout = $aOpt['noout']; $this->type = $aOpt['type']; parent::__construct('P', 'mm', 'A4'); $this->oSC = new system_common($con); } function Header() { $this->SetFont(GOTHIC, '', $this->normalFontSize); $value = $this->type == 1 ? 'X1' : 'X2'; $this->Text(11, 13, utf2sjis('第'.$value.'号様式(第Y条関係)')); $this->Text(11, 18, 'No.'.$this->aYoyakuNum[0]); $value = sprintf('%s年%2s月%2s日', $this->oSC->getNengouViewYMD(date('Y'), date('n'), date('j')), date('n'), date('j')); $this->Text(170, 20, utf2sjis($value)); } function Footer() { $this->SetFont(GOTHIC, '', $this->normalFontSize); $this->Text(198, 290, $this->PageNo().'/{nb}'); } function get_db_data() { $sql = "SELECT y.localgovcode, y.shisetsucode, y.shitsujyocode, y.combino, y.yoyakunum, y.userid, y.yoyakuname, y.mokutekicode, y.usedatefrom, y.usetimefrom, y.usetimeto, y.shisetsufee, f.suuryo, f.suuryotani, f.useninzu, f.bihinyoyakunum, f.optionfee4, s.shitsujyoname, s.shitsujyokbn FROM t_yoyaku y JOIN m_shitsujyou s USING (localgovcode, shisetsucode, shitsujyocode) JOIN t_yoyakufeeshinsei f USING (localgovcode, yoyakunum)"; $sql .= " WHERE y.localgovcode='"._CITY_CODE_."'"; if (empty($this->aYoyakuNum)) { $sql .= " AND y.yoyakunum='000000' "; } else { $sql .= " AND (y.yoyakunum='".implode("' OR y.yoyakunum='", $this->aYoyakuNum)."') "; } $sql .= ' ORDER BY usedatefrom,usetimefrom,yoyakunum,shitsujyokbn,shitsujyocode'; $res = $this->con->getAll($sql, array() ,DB_FETCHMODE_ASSOC); $oEQ = new equipment($this->con, $res[0]['shisetsucode']); $aCombi = $this->oSC->get_combi_name_array($res[0]['shisetsucode']); $recs = array(); $sql = 'SELECT y.billingfee, y.usetimefrom, y.usetimeto, s.shitsujyoname, s.shitsujyocode, s.shitsujyoskbcode FROM t_yoyaku_fee_option y JOIN m_shitsujyou s USING (localgovcode, shisetsucode, shitsujyocode) WHERE y.localgovcode=? AND y.yoyakunum=? ORDER BY shitsujyoskbcode, shitsujyocode'; foreach($res as $val) { if (array_key_exists($val['yoyakunum'], $recs)) { if ($val['shitsujyokbn'] == '3') { $usetime = $this->oSC->getTimeView($val['usetimefrom']).'~'.$this->oSC->getTimeView($val['usetimeto']); $recs[$val['yoyakunum']]['List'][] = array('name' => $val['shitsujyoname'], 'time' => $usetime, 'fee' => $val['shisetsufee']); } continue; } $val['MokutekiName'] = $this->oSC->get_purpose_name($val['mokutekicode']); $val['UseDate'] = $this->oSC->put_wareki_date($val['usedatefrom'], true); if ($val['combino'] != 0) { $val['shitsujyoname'] .= ' '.$aCombi[$val['shisetsucode']][$val['shitsujyocode']][$val['combino']]; } $UseTime = $this->oSC->getTimeView($val['usetimefrom']).'~'.$this->oSC->getTimeView($val['usetimeto']); $val['List'] = array(); $val['List'][] = array('name' => $val['shitsujyoname'], 'time' => $UseTime, 'fee' => $val['shisetsufee']); if ($val['optionfee4'] != 0) $val['List'][] = array('name' => '調整額', 'time' => '', 'fee' => $val['optionfee4']); $val['Bihin'] = array(); $opt = $this->con->getAll($sql, array(_CITY_CODE_, $val['yoyakunum']), DB_FETCHMODE_ASSOC); foreach ($opt as $v) { $usetime = $this->oSC->getTimeView($v['usetimefrom']).'~'.$this->oSC->getTimeView($v['usetimeto']); $val['Bihin'][] = array('name' => $v['shitsujyoname'], 'time' => $usetime, 'fee' => $v['billingfee']); } if ($val['bihinyoyakunum'] != '') { $bihin = $oEQ->get_bihin_yoyaku_data($val['bihinyoyakunum']); $usetime = $this->oSC->getTimeView(date('His', $bihin['usedatefrom'])).'~'.$this->oSC->getTimeView(date('His', $bihin['usedateto'])); $item = $oEQ->get_bihin_uchiwake_data($val['bihinyoyakunum']); foreach ($item as $v) { $val['Bihin'][] = array('name' => $v['bihinname'].'('.$v['amount'].$v['unit'].')', 'time' => $usetime, 'fee' => $v['bihinfee']); } } $recs[$val['yoyakunum']] = $val; } unset($res, $aCombi); return $recs; } function output_pdf() { $recs = $this->get_db_data(); $toprec = $recs[$this->aYoyakuNum[0]]; if ($toprec['suuryotani'] != '') { list($genId, $genCode) = explode(',', $toprec['suuryotani']); $genValue = $this->oSC->get_genmen_info($genId, $genCode); $toprec = array_merge($toprec, $genValue); } $scd = $toprec['shisetsucode']; $userid = $toprec['userid']; $shisetsuInfo = $this->oSC->get_shisetsu_data($scd); $sysInfo = $this->oSC->get_system_parameters(); $userInfo = $this->oSC->get_user_data($userid); $userInfo['localgovname'] = $sysInfo['localgovname']; $userInfo['shisetsuname'] = $shisetsuInfo['shisetsuname']; $userInfo['shisetsumaster'] = $shisetsuInfo['shisetsumaster']; $userInfo['addr'] = $userInfo['adr1'].' '.$userInfo['adr2']; $userInfo['telno1'] = ''; if ($userInfo['telno11'] || $userInfo['telno12'] || $userInfo['telno13']) { $userInfo['telno1'] = $userInfo['telno11'].'-'.$userInfo['telno12'].'-'.$userInfo['telno13']; } $userInfo['telno2'] = ''; if ($userInfo['telno21'] || $userInfo['telno22'] || $userInfo['telno23']) { $userInfo['telno2'] = $userInfo['telno21'].'-'.$userInfo['telno22'].'-'.$userInfo['telno23']; } if ($userid === _UNREGISTED_USER_ID_) { $unreg = $this->oSC->get_unregisted_user_info($this->aYoyakuNum[0]); if ($unreg) { $userInfo['namesei'] = $unreg['unreg_name']; $userInfo['addr'] = $unreg['unreg_address']; $userInfo['telno1'] = $unreg['unreg_tel']; $userInfo['telno2'] = $unreg['unreg_contact']; } } if ($this->noout) { $userInfo['namesei'] = $userInfo['headnamesei'] = ''; $userInfo['addr'] = ''; $userInfo['telno1'] = $userInfo['telno2'] = ''; } $h1 = $this->height2; $w1 = $this->width1; $w2 = $this->width1*3/2; $this->AddMBFont(GOTHIC, 'SJIS'); $this->SetMargins(15, 23, 15); // Left, Top, Right $this->SetAutoPageBreak(false, 10); $this->AliasNbPages(); $yen = utf2sjis(' 円'); $rec_num = count($recs); $mod = 0; $i = 0; $SumFee = 0; $pageSumFee = 0; foreach($recs as $val) { --$rec_num; $list = array_merge($val['List'], $val['Bihin']); $line_num = count($list); foreach ($list as $line) { --$line_num; ++$i; $mod = $i%$this->MaxRowNumber; if ($mod == 1) { $this->AddPage(); if ($this->type == 1) { $this->put_header_shinsei($userInfo); } else { $this->put_header_kyoka($scd, $userInfo); } $this->put_table_header($toprec, $userInfo); } $tmpfee = (int)$line['fee']; $values = array(); $values[] = $line['name']; $values[] = utf2sjis($val['UseDate']); $values[] = utf2sjis($line['time']); $values[] = number_format($tmpfee).$yen; $this->put_table_row($values); $pageSumFee += $tmpfee; $SumFee += $tmpfee; if (($rec_num > 0 || $line_num > 0) && $mod == 0) { $value = utf2sjis('小 計'); $this->Cell($w1*3+$w2, $h1, $value, 'LB', 0, 'R'); $value = number_format($pageSumFee).$yen; $this->Cell($w1, $h1, $value, 'LRB', 1, 'R'); $pageSumFee = 0; } } } if ($mod > 0) { $values = array('', '', '', ''); $r = $this->MaxRowNumber - $mod; for ($n = 0; $n < $r; ++$n) $this->put_table_row($values); } $value = utf2sjis('合 計'); $this->Cell($w1*3+$w2, $h1, $value, 'LB', 0, 'R'); $value = number_format($SumFee).$yen; $this->Cell($w1, $h1, $value, 'LRB', 1, 'R'); if ($this->type == 1) { $this->put_footer_shinsei(); } else { $this->put_footer_kyoka(); } $type = $this->type == 1 ? '申請書' : '許可書兼領収書'; $filename = utf2sjis('使用'.$type).'-'.date('YmdHis').'.pdf'; $this->Output($filename, 'I'); } function put_table_header(&$rec, &$user) { $h1 = $this->height2; $w1 = $this->width1; $w2 = $this->width1*3/2; $this->SetFontSize($this->normalFontSize); $value = utf2sjis('使用目的'); $this->Cell($w1, $h1, $value, 'LTB', 0, 'C'); $value = $rec['MokutekiName']; $len = mb_strlen($value, 'UTF-8'); if ($len > 26) { $this->Cell($w1*2+$w2, $h1/2, utf2sjis(mb_substr($value, 0, 26, 'UTF-8')), 'LT', 2); $this->Cell($w1*2+$w2, $h1/2, utf2sjis(mb_substr($value, 26, $len, 'UTF-8')), 'LB'); $this->SetXY($this->GetX(), $this->GetY()-$h1/2); } else { $this->Cell($w1*2+$w2, $h1, utf2sjis($value) , 'LTB', 0, 'C'); } $value = utf2sjis('使用人数'); $this->Cell($w1, $h1, $value, 'LTB', 0, 'C'); $value = utf2sjis($rec['useninzu']." 名"); $this->Cell(0, $h1, $value, 'LTRB', 1, 'R'); $value = utf2sjis('使用料区分'); $this->Cell($w1, $h1, $value, 'LB', 0, 'C'); $value = ''; if ($rec['suuryotani'] != '') { $value = utf2sjis($rec['genname']."(".$rec['rate']."%)"); } $this->Cell(0, $h1, $value, 'LRB', 1); $value = utf2sjis('使用施設名'); $this->Cell($w1*2, $h1, $value, 'LB', 0, 'C'); $value = utf2sjis('使用日'); $this->Cell($w2, $h1, $value, 'LB', 0, 'C'); $value = utf2sjis('使用時間 '); $this->Cell($w1, $h1, $value, 'LB', 0, 'C'); $value = utf2sjis('使用料 '); $this->Cell($w1, $h1, $value, 'LB', 0, 'C'); $value = utf2sjis('備考'); $this->Cell(0, $h1, $value, 'LTRB', 1, 'C'); } function put_table_row(&$val) { $h1 = $this->height2; $w1 = $this->width1; $w2 = $this->width1*3/2; if ($val[0] == '') { $this->Cell($w1*2, $h1, '', 'LB'); } else { $y = $this->GetY(); $this->WrapCell($w1*2, $h1, $val[0], 3.5); $this->SetXY($this->GetX(), $y); } $this->Cell($w2, $h1, $val[1], 'LB', 0, 'C'); $this->Cell($w1, $h1, $val[2], 'LB', 0, 'C'); $this->Cell($w1, $h1, $val[3], 'LB', 0, 'R'); $this->Cell(0, $h1, '', 'LRB', 1); } function put_header_shinsei($user) { $h1 = $this->height1; $w1 = $this->width1; $w2 = $this->width1*4; $w3 = $w2 + $this->lMargin; $this->SetFont(GOTHIC, 'B', $this->largeFontSize); $value = utf2sjis($user['localgovname'].$user['shisetsuname'].'使用変更許可申請書'); $this->Cell(0, $h1*2, $value, 0, 1, 'C'); $this->Ln($h1); $this->SetFontSize($this->middleFontSize); $value = utf2sjis($user['shisetsumaster'].' 様'); $this->Cell($w2, $h1, $value); $this->SetFont(GOTHIC, '', $this->normalFontSize); $value = utf2sjis('団 体 名'); $this->Cell($w1, $h1, $value); $value = $user['kojindankbn'] == '1' ? '' : $user['namesei']; $len = mb_strlen($value, 'UTF-8'); $tmpH = $len > 18 ? $h1*2/3 : $h1; $this->MultiCell(0, $tmpH, utf2sjis($value)); $this->SetX($w3); $value = utf2sjis('使用責任者名'); $this->Cell($w1, $h1, $value); $value = $user['kojindankbn'] == '1' ? $user['namesei'] : $user['headnamesei']; $this->Cell(0, $h1, utf2sjis($value), 0, 1); $this->SetX($w3); $value = utf2sjis('住 所'); $this->Cell($w1, $h1*2, $value); $y = $this->GetY(); $x = $this->GetX(); $this->MultiLine($user['addr'], 21, 0, $h1*2, $x, $y); $this->SetFontSize($this->normalFontSize); $this->SetX($w3); $value = utf2sjis('電話番号'); $this->Cell($w1, $h1, $value); $this->Cell(0, $h1, $user['telno1'], 0, 1); $this->SetX($w3); $value = utf2sjis('携帯番号'); $this->Cell($w1, $h1, $value); $this->Cell(0, $h1, $user['telno2'], 0, 1); $value = utf2sjis('下記の施設の使用を申請します。'); $this->Cell(0, $h1*2, $value, 0, 1); } function put_header_kyoka($scd, &$user) { $h1 = $this->height1; $w1 = $this->width1; $w2 = $this->width1*4; $stampfile = STAMP_FILE_PREFIX.'_'.$scd.'.jpg'; if (file_exists($stampfile)) { $this->Image($stampfile, 170, 50); } else { $stampfile = STAMP_FILE_PREFIX.'.jpg'; if (file_exists($stampfile)) { $this->Image($stampfile, 170, 50); } } $this->SetFont(GOTHIC, 'B', $this->largeFontSize); $value = utf2sjis($user['localgovname'].$user['shisetsuname'].'使用変更許可書'); $this->Cell(0, $h1*2, $value, 0, 1, 'C'); $this->Ln($h1); $this->SetFont(GOTHIC, '', $this->normalFontSize); $value = utf2sjis('団 体 名'); $this->Cell($w1, $h1, $value); $value = $user['kojindankbn'] == '1' ? '' : $user['namesei']; $len = mb_strlen($value, 'UTF-8'); $tmpH = $len > 29 ? $h1*2/3 : $h1; $this->MultiCell($w2, $tmpH, utf2sjis($value)); $value = utf2sjis('使用責任者名'); $this->Cell($w1, $h1, $value); $value = $user['kojindankbn'] == '1' ? $user['namesei'] : $user['headnamesei']; $this->Cell($w2, $h1, utf2sjis($value), 0, 1); $value = utf2sjis('住 所'); $this->Cell($w1, $h1*2, $value); $y = $this->GetY(); $x = $this->GetX(); $this->MultiLine($user['addr'], 33, $w2, $h1*2, $x, $y); $this->SetFontSize($this->normalFontSize); $value = utf2sjis('電話番号'); $this->Cell($w1, $h1, $value); $this->Cell($w2, $h1, $user['telno1']); $this->SetFontSize($this->middleFontSize); $value = utf2sjis($user['shisetsumaster']); $this->Cell(0, $h1, $value, 0, 1, 'R'); $this->SetFontSize($this->normalFontSize); $value = utf2sjis('携帯番号'); $this->Cell($w1, $h1, $value); $this->Cell($w2, $h1, $user['telno2'], 0, 1); $value = utf2sjis('下記の通り使用を許可します。'); $this->Cell(0, $h1*2, $value, 0, 1); } function put_footer_shinsei() { $h1 = $this->height3; $w1 = 5; $w2 = 16; $this->Ln($h1*2); $x = $this->GetX(); $y = $this->GetY(); $value = utf2sjis("\n決\n裁\n"); $this->MultiCell($w1, $h1, $value, 1); $this->SetXY($x+$w1, $y); $value = utf2sjis('施設長 '); $this->Cell($w2, $h1, $value, 'T', 0, 'C'); $value = utf2sjis('課長'); $this->Cell($w2, $h1, $value, 'LT', 0, 'C'); $value = utf2sjis('係長'); $this->Cell($w2, $h1, $value, 'LT', 0, 'C'); $this->Cell($w2, $h1, '', 'LT'); $value = utf2sjis('担当'); $this->Cell($w2, $h1, $value, 'LT', 0, 'C'); $value = "備 考\n\n\n\n\n"; $this->MultiCell(0, $h1, utf2sjis($value), 1); $this->SetXY($x+$w1, $y+$h1); $this->Cell($w2, $h1*4, '', 'TB'); $this->Cell($w2, $h1*4, '', 'LTB'); $this->Cell($w2, $h1*4, '', 'LTB'); $this->Cell($w2, $h1*4, '', 'LTB'); $this->Cell($w2, $h1*4, '', 'LTB'); } function put_footer_kyoka() { $h1 = $this->height3; $this->Ln($h1); $y = $this->GetY(); $value = utf2sjis('(注意事項)'); $this->Cell(0, $h1, $value, 0, 1); $value = "1.この許可書は、施設の使用時には必ず携帯し、係員に求められたときは提示してください。\n"; $value.= "2.施設及び器具の使用等については、すべての提示に従ってください。\n"; $value.= "3.使用の当日又は使用の前日の天候によって、施設が使用できない場合もありますので\n  ご承知ください。\n"; $value.= "4.施設の使用後は、整備清掃し、元の状態に戻してください。\n"; $value.= "5.施設を使用しなくなった場合には、速やかに連絡してください。\n"; $value.= "6.使用料の合計金額について領収しました。\n"; $value.= "7.領収書として扱う場合には、領収印欄に領収印が捺印されていないものは無効とします。\n"; $this->SetX(17); $this->MultiCell(0, $h1, utf2sjis($value)); $this->SetLineWidth(0.1); $this->SetXY(168, $y+$h1*3); $value = utf2sjis('領収印 '); $this->Cell(24, 7, $value, 1, 2, 'C'); $this->Cell(24, 19, '', 1, 1); } function WrapCell($width, $height, $str, $fontSize) { $stringArr = array(); $halfSize = $fontSize/2; $len = mb_strlen($str, 'UTF-8'); $j = $l = 0; $stringArr[$j] = ''; for($i=0; $i<$len; ++$i) { $c = mb_substr($str, $i, 1, 'UTF-8'); if ($c == "\n") { $stringArr[++$j] = ''; $l = 0; continue; } $stringArr[$j].= $c; if (preg_match("/^(?:\xEF\xBD[\xA1-\xBF]|\xEF\xBE[\x80-\x9F]|[ -~]|\s)+$/D", $c)) $l += $halfSize; else $l += $fontSize; if ($l > $width) { $stringArr[++$j] = ''; $l = 0; } } $tmpH = $height / ($j + 1); for ($i = 0; $i < $j; ++$i) $this->Cell($width, $tmpH, utf2sjis($stringArr[$i]), 'L', 2); $this->Cell($width, $tmpH, utf2sjis($stringArr[$j]), 'LB'); } function MultiLine($str, $num, $width, $height, $x, $y) { $value = utf2sjis($str); $len = mb_strlen($value, 'SJIS'); if ($len > $num * 0.9) $this->SetFontSize($this->smallFontSize); $lineCount = ceil($len / $num); if ($lineCount > 1) { $tmpH = $height/$lineCount; for ($i=0; $i<$lineCount; ++$i) { $this->SetXY($x, $y+($i * $tmpH)); $tmpStr = mb_substr($value, $i*$num, $num, 'SJIS'); $this->Cell($width, $tmpH, $tmpStr); } } else { $this->SetXY($x, $y); $this->Cell($width, $height, $value); } $this->Ln(); } } ?>