'領収書', 2=>'請求書', 3=>'見積書'); private $type_name = ''; private $exists_stamp = false; function __construct(&$con, &$aYoyakuNum, &$aOpt, &$req) { $this->con = $con; $this->aYoyakuNum = $aYoyakuNum; $this->req = $req; $this->noout = $aOpt['noout']; $this->type = $aOpt['type']; $this->type_name = $this->aTypeName[$aOpt['type']]; parent::__construct('P', 'mm', 'A4'); $this->oSC = new system_common($con); } function Header() { $this->SetFont(KOZMIN, '', $this->smallFontSize); $this->Text(11, 18, 'No.'.$this->aYoyakuNum[0]); $this->Text(170, 20, utf2sjis($this->recDate)); } function get_db_data(&$num, &$totalfee) { $sql = "SELECT y.localgovcode, y.shisetsucode, y.shitsujyocode, y.combino, y.yoyakunum, y.userid, y.yoyakuname, y.honyoyakukbn, y.usedatefrom, y.usetimefrom, y.usetimeto, y.shisetsupaylimitdate, y.shisetsufee, f.suuryo, 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'; $num = 0; 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']); ++$num; } continue; } $oRS = new receipt_status($this->con, $val['yoyakunum'], $val['honyoyakukbn'], $val['suuryo']); $receipt = $oRS->getReceiptFee(); $val['AcceptDate'] = $receipt[8]; if ($this->type == 1) $totalfee += $oRS->getT_YoyakuFeeUketsukeSumFee(); else $totalfee += $val['suuryo']; $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']); } } $num += count($val['Bihin']) + 1; $recs[$val['yoyakunum']] = $val; } unset($res, $aCombi); return $recs; } function output_pdf() { $total_recs = 0; $total_fee = 0; $recs = $this->get_db_data($total_recs, $total_fee); $toprec = $recs[$this->aYoyakuNum[0]]; if ($total_fee == 0) $toprec['shisetsupaylimitdate'] = ''; if ($toprec['shisetsupaylimitdate'] != '') $toprec['shisetsupaylimitdate'] = $this->oSC->put_wareki_date($toprec['shisetsupaylimitdate']); $tmpdate = date('Ymd'); if ($this->type == 1 && $toprec['AcceptDate'] != '') { $tmpdate = isset($this->req['Year']) ? $this->req['Year'].$this->req['Month'].$this->req['Day'] : $toprec['AcceptDate']; } $this->recDate = $this->oSC->put_wareki_date($tmpdate); $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['totalFee'] = $total_fee; $userInfo['localgovname'] = $sysInfo['localgovname']; $userInfo['shisetsuname'] = $shisetsuInfo['shisetsuname']; $userInfo['shisetsumaster'] = $shisetsuInfo['shisetsumaster']; if ($userid === _UNREGISTED_USER_ID_) { $unreg = $this->oSC->get_unregisted_user_info($this->aYoyakuNum[0]); if ($unreg) { $userInfo['namesei'] = $unreg['unreg_name']; } } if ($this->noout) { $userInfo['namesei'] = $userInfo['headnamesei'] = ''; } $h1 = $this->height2; $w1 = $this->width1*5/2; $w2 = $this->width1*2; $w3 = $this->width1*3/2; $this->AddMBFont(KOZMIN, 'SJIS'); $this->AddMBFont(GOTHIC, 'SJIS'); $this->SetMargins(15, 23, 15); // Left, Top, Right $this->SetAutoPageBreak(false, 10); $this->AliasNbPages(); $yen = utf2sjis(' 円'); $total_page = ceil($total_recs/$this->MaxRowNumber); $fmt = array('原本'); if ($this->type == 1) $fmt[] = '控え'; foreach ($fmt as $kind => $contents) { $rec_num = count($recs); $mod = 0; $i = 0; $p = 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) { ++$p; $this->AddPage(); $this->put_header($kind, $scd, $userInfo); $this->put_table_header(); } $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+$w2+$w3, $h1, $value, 'LB', 0, 'R'); $value = number_format($pageSumFee).$yen; $this->Cell(0, $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+$w2+$w3, $h1, $value, 'LB', 0, 'R'); $value = number_format($SumFee).$yen; $this->Cell(0, $h1, $value, 'LRB', 1, 'R'); $this->put_footer($toprec, $p, $total_page); } $filename = utf2sjis($this->type_name).'-'.date('YmdHis').'.pdf'; $this->Output($filename, 'I'); } function put_table_header() { $h1 = $this->height2; $w1 = $this->width1*5/2; $w2 = $this->width1*2; $w3 = $this->width1*3/2; $this->SetFont(GOTHIC, '', $this->normalFontSize); $value = utf2sjis('使用施設名'); $this->Cell($w1, $h1, $value, 'LTB', 0, 'C'); $value = utf2sjis('使用日'); $this->Cell($w2, $h1, $value, 'LTB', 0, 'C'); $value = utf2sjis('使用時間 '); $this->Cell($w3, $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*5/2; $w2 = $this->width1*2; $w3 = $this->width1*3/2; if ($val[0] == '') { $this->Cell($w1, $h1, '', 'LB'); } else { $y = $this->GetY(); $this->WrapCell($w1, $h1, $val[0], 3.5); $this->SetXY($this->GetX(), $y); } $this->Cell($w2, $h1, $val[1], 'LB', 0, 'C'); $this->Cell($w3, $h1, $val[2], 'LB', 0, 'C'); $this->Cell(0, $h1, $val[3], 'LRB', 1, 'R'); } function put_header($kind, $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); $this->exists_stamp = true; } else { $stampfile = STAMP_FILE_PREFIX.'.jpg'; if (file_exists($stampfile)) { $this->Image($stampfile, 170, 50); $this->exists_stamp = true; } } */ $this->SetFont(KOZMIN, 'B', $this->largeFontSize); $w6 = $this->w/8; $this->SetX($w6*3); $this->Cell($w6, $h1*2, utf2sjis(mb_substr($this->type_name, 0, 1, 'UTF-8'))); $this->Cell($w6, $h1*2, utf2sjis(mb_substr($this->type_name, 1, 1, 'UTF-8'))); $value = mb_substr($this->type_name, 2, 1, 'UTF-8'); if ($kind > 0) $value .= ' (控)'; $this->Cell(0, $h1*2, utf2sjis($value), 0, 1); $this->Ln($h1); $this->SetFont(KOZMIN, '', $this->middleFontSize); $value = $user['namesei']; if ($user['namesei'] != '') $value .= ' 御中'; $this->Cell(0, $h1*2, utf2sjis($value), 0, 1); $this->SetFontSize($this->normalFontSize); $value = $user['headnamesei'] == '' ? '' : utf2sjis('代表者名'); $this->Cell($w1, $h1, $value); $value = $user['headnamesei']; if ($user['headnamesei'] != '') $value .= ' 様'; $this->Cell($w2, $h1, utf2sjis($value), 0, 1); $this->SetFontSize($this->middleFontSize); $value = utf2sjis($user['shisetsumaster']); $this->Cell(0, $h1, $value, 0, 1, 'R'); $this->SetFontSize($this->normalFontSize); $value = '下記の金額を領収いたしました。'; if ($this->type == 3) $value = '下記の通りお見積り申し上げます。'; elseif ($this->type == 2) $value = '下記の通りご請求申し上げます。'; $this->Cell(0, $h1*2, utf2sjis($value), 0, 1); $this->SetFont(KOZMIN, 'B', $this->largeFontSize); $this->Cell($w1, $h1*2, utf2sjis('金'), 0, 0, 'R'); $x1 = $this->GetX(); $this->SetFontSize($this->largeFontSize*6/5); $this->Cell($w1*2, $h1*2, number_format($user['totalFee']), 0, 0, 'R'); $x2 = $this->GetX(); $this->SetFontSize($this->largeFontSize); $this->Cell(0, $h1*2, utf2sjis('円'), 0, 1); $y = $this->GetY() - 2; $this->Ln($h1); $this->SetLineWidth(0.1); $this->Line($x1, $y, $x2, $y); $this->SetLineWidth(0.2); $this->SetFontSize($this->normalFontSize); $value = '但し、'.$user['shisetsuname'].'の下記使用料として'; $this->Cell($w1, $h1, utf2sjis($value), 0, 1); $this->Ln($h1/2); } function put_footer($rec, $page, $total_page) { $this->SetFont(KOZMIN, '', $this->normalFontSize); $h1 = $this->height3; $this->Ln($h1/2); $y = $this->GetY(); $value = ''; if ($this->type == 2) { if ($rec['shisetsupaylimitdate'] != '') $value.= "{$rec['shisetsupaylimitdate']}までにお支払いいただだきますようお願い申し上げます。\n"; } $this->SetX(17); $this->MultiCell(0, $h1, utf2sjis($value)); if (!$this->exists_stamp) { $this->SetLineWidth(0.1); if ($this->type == 1) { $this->SetXY(168, $y+$h1*3); $value = utf2sjis('領収印 '); $this->Cell(24, 7, $value, 1, 2, 'C'); $this->Cell(24, 19, '', 'LRB', 1); } elseif ($this->type == 2) { $this->SetXY(132, $y+$h1*3+7); $this->Cell(20, 19, '', 1); $this->Cell(20, 19, '', 'TRB'); $this->Cell(20, 19, '', 'TRB', 1); } elseif ($this->type == 3) { $this->SetXY(144, $y+$h1*3); $value = utf2sjis('承認'); $this->Cell(24, 7, $value, 1, 0, 'C'); $value = utf2sjis('担当'); $this->Cell(24, 7, $value, 'TRB', 2, 'C'); $this->SetX(144); $this->Cell(24, 19, '', 'LRB'); $this->Cell(24, 19, '', 'RB', 1); } $this->SetLineWidth(0.2); } $this->SetFont(KOZMIN, '', $this->smallFontSize); $value = sprintf('%2d/%d ', $page, $total_page); $this->Text(198, 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'); } } ?>