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 get_db_data(&$num, &$fee) { $sql = "SELECT y.localgovcode, y.shisetsucode, y.shitsujyocode, y.combino, y.yoyakunum, y.userid, y.yoyakuname, y.mokutekicode, y.honyoyakukbn, y.amount, y.usedatefrom, y.usetimefrom, y.usetimeto, y.baseshisetsufee, y.shisetsufee, f.suuryo, f.suuryotani, f.surcharge, f.useninzu, f.bihinyoyakunum, f.optionfee4, s.shitsujyoname, s.shitsujyokbn, s.unit, s.number_input_flg 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(); $recs = array(); $sql = 'SELECT y.basefee, y.billingfee, y.usetimefrom, y.usetimeto, y.amount, s.shitsujyoname, s.unit, 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'; $num = 0; $fee = array('shisetsu_fee' => 0, 'setsubi_fee' => 0, 'genmen_fee' => 0, 'total_fee' => 0, 'receipt_fee' => 0); $today = date('Ymd'); foreach($res as $val) { if (array_key_exists($val['yoyakunum'], $recs)) { if ($val['shitsujyokbn'] == '3') { $stjname = $this->oSC->get_shisetsu_name($val['shisetsucode']).$val['shitsujyoname']; if ($val['number_input_flg'] == '1' && $this->type != 3) $stjname.= '('.$val['amount'].$val['unit'].')'; $recs[$val['yoyakunum']]['Fuzoku'][] = array('name' => $stjname, 'time' => $this->oSC->getTimeView($val['usetimefrom']).'~'.$this->oSC->getTimeView($val['usetimeto']), 'fee' => $val['baseshisetsufee'], 'amount' => $val['amount'], 'unit' => $val['unit']); $fee['setsubi_fee'] += $val['baseshisetsufee']; $fee['genmen_fee'] += $val['baseshisetsufee'] - $val['shisetsufee']; ++$num; } continue; } $oRS = new receipt_status($this->con, $val['yoyakunum'], $val['honyoyakukbn'], $val['suuryo']); $receipt = $oRS->getReceiptFee(); $val['AcceptDate'] = $receipt[8]; $fee['total_fee'] += $val['suuryo']; if (strncmp($receipt[12], $today, 8) == 0) $fee['receipt_fee'] += $receipt[1]; if (strncmp($receipt[13], $today, 8) == 0) $fee['receipt_fee'] += $receipt[2]; if (strncmp($receipt[14], $today, 8) == 0) $fee['receipt_fee'] += $receipt[3]; if (strncmp($receipt[15], $today, 8) == 0) $fee['receipt_fee'] += $receipt[4]; if (strncmp($receipt[16], $today, 8) == 0) $fee['receipt_fee'] += $receipt[5]; $val['UseDate'] = $this->oSC->put_wareki_date($val['usedatefrom'], true); $val['shitsujyoname'] = $this->oSC->get_shisetsu_name($val['shisetsucode']).$val['shitsujyoname']; if ($val['combino'] != 0) { $val['shitsujyoname'] .= $aCombi[$val['shisetsucode']][$val['shitsujyocode']][$val['combino']]; } $gassan = false; $basefee = $val['baseshisetsufee']; if ($gassan) $basefee += $val['optionfee4']; $val['List'] = array(); $val['List'][] = array('name' => $val['shitsujyoname'], 'time' => $this->oSC->getTimeView($val['usetimefrom']).'~'.$this->oSC->getTimeView($val['usetimeto']), 'fee' => $basefee, 'amount' => 1, 'unit' => ''); if ($val['optionfee4'] != 0 && !$gassan) $val['List'][] = array('name' => '調整額', 'time' => '', 'fee' => $val['optionfee4'], 'amount' => 1, 'unit' => ''); $val['Fuzoku'] = array(); $val['Bihin'] = array(); $opt = $this->con->getAll($sql, array(_CITY_CODE_, $val['yoyakunum']), DB_FETCHMODE_ASSOC); foreach ($opt as $v) { $optname = $v['shitsujyoname']; if ($this->type != 3) $optname .= '('.$v['amount'].$v['unit'].')'; $val['Bihin'][] = array('name' => $optname, 'time' => $this->oSC->getTimeView($v['usetimefrom']).'~'.$this->oSC->getTimeView($v['usetimeto']), 'fee' => $v['basefee'], 'amount' => $v['amount'], 'unit' => $v['unit']); $fee['setsubi_fee'] += $v['basefee']; $fee['genmen_fee'] += $v['basefee'] - $v['billingfee']; } if ($val['bihinyoyakunum'] != '') { $bihin = $oEQ->get_bihin_yoyaku_data($val['bihinyoyakunum']); $item = $oEQ->get_bihin_uchiwake_data($val['bihinyoyakunum']); foreach ($item as $v) { $bihinname = $v['bihinname']; if ($this->type != 3) $bihinname .= '('.$v['amount'].$v['unit'].')'; $val['Bihin'][] = array('name' => $bihinname, 'time' => date('H:i', $bihin['usedatefrom']).'~'.date('H:s', $bihin['usedateto']), 'fee' => $v['basefee'], 'amount' => $v['amount'], 'unit' => $v['unit']); $fee['setsubi_fee'] += $v['basefee']; $fee['genmen_fee'] += $v['basefee'] - $v['bihinfee']; } } ++$num; $num += count($val['Bihin']); $recs[$val['yoyakunum']] = $val; $fee['shisetsu_fee'] += $basefee; $fee['genmen_fee'] += $val['baseshisetsufee'] - $val['shisetsufee']; } unset($res, $aCombi); return $recs; } function output_pdf() { $total_recs = 0; $Fee = array(); $recs = $this->get_db_data($total_recs, $Fee); $toprec = $recs[$this->aYoyakuNum[0]]; $toprec = array_merge($toprec, $Fee); if ($toprec['suuryotani'] != '') { list($genId, $genCode) = explode(',', $toprec['suuryotani']); $genValue = $this->oSC->get_genmen_info($genId, $genCode); $toprec = array_merge($toprec, $genValue); } $tmpdate = date('Ymd'); $this->recDate = $this->oSC->put_wareki_date($tmpdate); $shisetsuInfo = $this->oSC->get_shisetsu_data($toprec['shisetsucode']); $sysInfo = $this->oSC->get_system_parameters(); $userInfo = $this->oSC->get_user_data($toprec['userid']); $userInfo['localgovname'] = $sysInfo['localgovname']; $userInfo['shisetsumaster'] = $shisetsuInfo['shisetsumaster']; $userInfo['addr'] = $userInfo['adr1']; $userInfo['telno1'] = ''; if ($userInfo['telno11'] || $userInfo['telno12'] || $userInfo['telno13']) { $userInfo['telno1'] = $userInfo['telno11'].'-'.$userInfo['telno12'].'-'.$userInfo['telno13']; } $userInfo['telno3'] = ''; if ($userInfo['telno31'] || $userInfo['telno32'] || $userInfo['telno33']) { $userInfo['telno3'] = $userInfo['telno31'].'-'.$userInfo['telno32'].'-'.$userInfo['telno33']; } if ($toprec['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['telno3'] = $unreg['unreg_contact']; $userInfo['contactname'] = $unreg['unreg_name']; $userInfo['adr3'] = $unreg['unreg_address']; } } if ($this->noout) { $userInfo['namesei'] = $userInfo['headnamesei'] = ''; $userInfo['addr'] = ''; $userInfo['telno1'] = $userInfo['telno3'] = ''; $userInfo['contactname'] = ''; $userInfo['adr3'] = ''; } $this->AddMBFont(KOZMIN, 'SJIS'); $this->AddMBFont(GOTHIC, 'SJIS'); $this->SetMargins(25, 45, 20); // Left, Top, Right $this->SetAutoPageBreak(false, 10); $this->AliasNbPages(); $this->SetLineWidth(0.35); $yen = utf2sjis(' 円'); $fmt = array('原本', '控え'); $total_page = ceil($total_recs/$this->MaxRowNumber); foreach ($fmt as $kind => $contents) { $rec_num = count($recs); $mod = 0; $i = 0; $p = 1; $SumFee = 0; $pageSumFee = 0; $this->AddPage(); $this->put_header($kind, $toprec, $userInfo); $this->put_table_header($toprec, $userInfo); foreach($recs as $val) { --$rec_num; $list = array_merge($val['List'], $val['Fuzoku'], $val['Bihin']); if ($this->type == 3) unset($list[0]); $line_num = count($list); foreach ($list as $line) { --$line_num; ++$i; $mod = $i%$this->MaxRowNumber; if ($mod == 1 && $i > 1) { ++$p; $this->AddPage(); $this->put_header($kind, $toprec, $userInfo); $this->put_table_header($toprec, $userInfo); } $tmpfee = (int)$line['fee']; $values = array(); $values[] = utf2sjis($val['UseDate']); $values[] = utf2sjis($line['time']); $values[] = $line['name']; $values[] = number_format($tmpfee).$yen; $this->put_table_row($values); $pageSumFee += $tmpfee; $SumFee += $tmpfee; if (($rec_num > 0 || $line_num > 0) && $mod == 0) { $this->put_footer($toprec, $userInfo, $pageSumFee, $p, $total_page, false); $pageSumFee = 0; } } } if ($mod > 0 || $i == 0) { $r = $this->MaxRowNumber - $mod; $values = array('', '', '', ''); for ($n = 0; $n < $r; ++$n) { $this->put_table_row($values); } } $this->put_footer($toprec, $userInfo, $pageSumFee, $p, $total_page); } $filename = utf2sjis('利用承認書').'-'.date('YmdHis').'.pdf'; $this->Output($filename, 'I'); } function put_table_header(&$rec, &$user) { $h1 = $this->height2; $w1 = $this->width1; $w2 = $this->width2; $this->SetFontSize($this->smallFontSize); $value = utf2sjis('利用日'); $this->Cell($w1*2, $h1, $value, 'LTB', 0, 'C'); $value = utf2sjis('利用時間帯 '); $this->Cell($w2, $h1, $value, 'LTB', 0, 'C'); $value = utf2sjis('施設・設備名'); $this->Cell($w2*3, $h1, $value, 'LTB', 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->width2; $this->Cell($w1*2, $h1, $val[0], 'LB', 0, 'C'); $this->Cell($w2, $h1, $val[1], 'LB', 0, 'C'); if ($val[3] == '') { $this->Cell($w2*3, $h1, '', 'LB'); } else { $y = $this->GetY(); $this->WrapCell($w2*3, $h1, $val[2], 3.5); $this->SetXY($this->GetX(), $y); } $this->Cell(0, $h1, $val[3], 'LRB', 1, 'R'); } function put_header($kind, &$rec, &$user) { $h1 = $this->height1; $w1 = $this->width1; $w2 = $this->width1*4; $w3 = 16; if ($kind == 0) { $stampfile = STAMP_FILE_PREFIX.'_'.$rec['shisetsucode'].'.jpg'; if (file_exists($stampfile)) { $this->Image($stampfile, 27, 42, 28); } else { $stampfile = STAMP_FILE_PREFIX.'.jpg'; if (file_exists($stampfile)) { $this->Image($stampfile, 27, 42, 28); } } } $this->SetFont(GOTHIC, 'B', $this->largeFontSize); $value = $user['localgovname'].'施設利用承認書'; $this->Cell(0, $h1*2, utf2sjis($value), 0, 1, 'C'); $this->SetFont(KOZMIN, '', $this->normalFontSize); $value = utf2sjis('承認番号:'); $this->Cell($w1*7, $h1, $value, 0, 0, 'R'); $this->Cell(0, $h1, $this->aYoyakuNum[0], 0, 1); $value = utf2sjis('承認日:'); $this->Cell($w1*7, $h1, $value, 0, 0, 'R'); $this->Cell(0, $h1, utf2sjis($this->recDate), 0, 1); $this->Ln(); $this->SetFont(GOTHIC, '', $this->middleFontSize); $this->SetX($this->GetX() + $w1*6); $value = utf2sjis($user['localgovname'].'長'); $this->Cell(0, $h1, $value, 0, 1); $this->SetX($this->GetX() + $w1*6); $value = utf2sjis($user['localgovname'].'教育委員会'); $this->Cell(0, $h1, $value, 0, 1); $this->SetFont(KOZMIN, '', $this->normalFontSize); $value = utf2sjis('申請者'); $this->Cell($w3, $h1, $value); $value = utf2sjis('団体番号'); $this->Cell($w1, $h1, $value); $this->Cell(0, $h1, $user['userid'], 0, 1); $this->SetX($this->GetX() + $w3); $value = utf2sjis('団 体 名'); $this->Cell($w1, $h1, $value); $value = $user['namesei']; if ($user['namesei'] != '') $value.= ' 様'; $this->Cell(0, $h1, utf2sjis($value), 0, 1); $this->SetX($this->GetX() + $w3); $value = utf2sjis('住 所'); $this->Cell($w1, $h1*2, $value); $this->Cell(0, $h1*2, utf2sjis($user['addr']), 0, 1); $this->SetX($this->GetX() + $w3); $value = utf2sjis('代表者名'); $this->Cell($w1, $h1, $value); $value = $user['headnamesei']; $this->Cell(0, $h1, utf2sjis($value), 0, 1); $this->SetX($this->GetX() + $w3); $value = utf2sjis('電話番号'); $this->Cell($w1, $h1, $value); $this->Cell(0, $h1, $user['telno1'], 0, 1); $this->Ln($h1); $this->SetFontSize($this->normalFontSize); $value = utf2sjis('下記のとおり利用を承認します。'); $this->Cell(0, $h1, $value, 0, 1); } function put_footer(&$rec, &$user, $page_fee, $page, $total_page, $display=true) { $h1 = $this->height2; $w1 = $this->width1*2; $w2 = $this->width2*3; $w3 = $w1 + $this->width2; $yen = utf2sjis('円'); $this->SetFontSize($this->normalFontSize); $value = utf2sjis('施設利用料計 '); $this->Cell($w3, $h1, $value, 'LB', 0, 'C'); $value = ''; if ($display) $value = number_format($rec['shisetsu_fee']).$yen; $this->Cell($w1, $h1, $value, 'LB', 0, 'R'); $this->Cell(0, $h1, '', 'RB', 1); $value = utf2sjis('減免額計'); $this->Cell($w3, $h1, $value, 'LB', 0, 'C'); $value = ''; if ($display) $value = number_format($rec['genmen_fee']).$yen; $this->Cell($w1, $h1, $value, 'LB', 0, 'R'); $this->Cell(0, $h1, '', 'RB', 1); $value = utf2sjis('差引使用料金計'); $this->Cell($w3, $h1, $value, 'LB', 0, 'C'); $value = ''; if ($display) $value = number_format($rec['total_fee']).$yen; $this->Cell($w1, $h1, $value, 'LB', 0, 'R'); $this->Cell(0, $h1, '', 'RB', 1); $value = utf2sjis('今回入金額'); $this->Cell($w3, $h1, $value, 'LB', 0, 'C'); $value = ''; if ($display) { $value = number_format($rec['receipt_fee']).$yen; } $this->Cell($w1, $h1, $value, 'LB', 0, 'R'); $this->Cell(0, $h1, '', 'RB', 1); $value = utf2sjis('備考'); $this->Cell($w1, $h1*3, $value, 'LB', 0, 'C'); $this->Cell(0, $h1*3, '', 'LRB', 1); $this->SetFont(KOZMIN, '', $this->smallFontSize); $value = sprintf('%2d/%d ', $page, $total_page); $this->Text(105, 290, $value); } 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'); } } ?>