<?
// путевой лист
function put_list_n1($options=array())
{

    include_once(_DIR_TO_ENGINE.'/admin/i_img_working.php') ;
    if (file_exists(_DIR_EXT.'/work_order/put_list_n1.jpg')) list($source,$type) = open_image(_DIR_EXT.'/work_order/put_list_n1.jpg') ;
    else return(array('error'=>'Не найден файл шаблона путевого листа "/work_order/put_list_n1.jpg"')) ;


    if ($_GET['id'])
    { $rec_personal=PERSONAL()->get_personal_by_id($_GET['id']) ;
      imagefttext($source,12,0,138,245,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_personal['obj_name']) ;
    }

    if ($_GET['to_id'])
    { $rec_WO=WO()->get_wo_by_id($_GET['to_id']) ;
      if ($rec_WO['pkey'])
      {
	    $rec_WO['_member_name']='Иванов А.А.' ;
	    $rec_WO['probeg']=12000 ;
	    $rec_WO['fuel']=34 ;

      	//$rec_member=ESMO()->get_member_by_id($rec_WO['member_id']) ;
	    $rec_member['_ext_info']['seria_PL']='01 02' ;

        $rec_personal=PERSONAL()->get_personal_by_id($rec_WO['personal_id']) ;
	    $rec_personal['_ext_info']['cat']='BC' ;
	    $rec_personal['_ext_info']['DriverDetails']['Permit']='AA 01 127524' ;

        //$rec_car=ESMO()->get_car_by_id($rec_WO['car_id']) ;
	    $rec_car['model']='NISSAN' ;


        $rec_org=PERSONAL()->get_org_by_id($rec_personal['_org_id']) ;
	    //$stamp_rec=execSQL_van('select pkey,tkey,file_name from obj_site_personals_image where parent='.$rec_org['pkey'].' and alt="stamp"',0) ;
	    $stamp_rec=execSQL_van('select pkey,tkey,file_name from obj_site_personals_image where parent='.$rec_org['pkey'].' and alt="stamp"',0) ;
	    if ($stamp_rec['pkey']) $rec_org['stamp']=$stamp_rec ;

        $rec_MO=ESMO()->get_mo_by_id($rec_WO['mo_id'],array('view_sertificate_stamp'=>'image_print_MO_sertificate_stamp')) ;
	    $rec_doctor=ACCOUNTS()->get_member_by_id($rec_MO['doctor_id']) ;



        $arr_name=explode(' ',$rec_personal['obj_name']) ;
        $FIO=$arr_name[0].' '.mb_substr($arr_name[1],0,1).'. '.mb_substr($arr_name[2],0,1).'.' ;

        imagefttext($source,22,0,1170,310,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_member['_ext_info']['seria_PL']) ;
        imagefttext($source,22,0,1391,310,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_WO['doc_number']) ;
        imagefttext($source,22,0,350,735,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_personal['obj_name']) ;
        imagefttext($source,22,0,1254,735,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_personal['tab_number']) ;
        imagefttext($source,22,0,449,495,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_org['obj_name']) ; // название организации
        imagefttext($source,22,0,449,569,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_org['adres1'].' т.'.$rec_org['phone']) ; // адрес и телефон
        imagefttext($source,22,0,534,649,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_car['model']) ; // марка модель
        imagefttext($source,22,0,728,697,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_WO['car_number']) ; // номер
        imagefttext($source,22,0,468,820,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_personal['driving']) ; // вод.удостоверение
        imagefttext($source,22,0,1264,820,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_personal['_ext_info']['cat']) ; // катеогрия прав


        $arr_permit=explode(' ',$rec_personal['_ext_info']['DriverDetails']['Permit']) ;
        //$arr_permit=explode(' ',$rec_car['permit']) ;

        imagefttext($source,22,0,515,945,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$arr_permit[0]) ;
        imagefttext($source,22,0,868,945,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$arr_permit[1]) ;
        imagefttext($source,22,0,1128,945,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$arr_permit[2]) ;

        imagefttext($source,22,0,1220,1415,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_WO['_member_name']) ;
        imagefttext($source,22,0,632,1829,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_WO['_member_name']) ;
        //imagefttext($source,22,0,632,2046,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_WO['_member_name']) ;
        imagefttext($source,22,0,1225,2489,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_WO['_member_name']) ;

        imagefttext($source,22,0,1250,1590,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$FIO) ;
        //imagefttext($source,22,0,655,2390,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$FIO) ;
        imagefttext($source,22,0,598,2415,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$FIO) ;

        imagefttext($source,22,0,700,1730,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',date('H:i',$rec_WO['c_data'])) ; // время выезда из гаража
        imagefttext($source,22,0,1130,1720,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_personal['_ext_info']['fuel']) ; // тип топлива

        imagefttext($source,22,0,440,1315,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf','по указанию диспечтера') ;
        imagefttext($source,22,0,440,1585,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf','по указанию диспечтера') ;

          //imagefttext($source,22,0,1200,945,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_car['permit']) ;

        // информация по докутору, проводившему МО
        if ($rec_doctor['signature'])
          { list($logo,$type_logo)=open_image(img_clone($rec_doctor['signature'],'source',array('return_dir'=>1))) ;
            if (_sizeof($logo))
             { $w_l=imagesx($logo)  ; $h_l=imagesy($logo) ;
               imagecopymerge($source,$logo,1200,1065, 0, 0,$w_l,$h_l,100) ;
               ImageDestroy($logo);
             }
          }

        if ($rec_doctor['stamp'])
        { list($logo,$type_logo)=open_image(img_clone($rec_doctor['stamp'],'source',array('return_dir'=>1))) ;
          if (_sizeof($logo))
           { $w_l=imagesx($logo)  ; $h_l=imagesy($logo) ;
             imagecopymerge($source,$logo,1100,970, 0, 0,$w_l,$h_l,100) ;
             ImageDestroy($logo);
           }
        }
	    /*
        imagefttext($source,22,0,194,1014,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf','Медосмотр предрейсовый: допушен к выполнению') ;
        imagefttext($source,22,0,194,1050,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf','трудовых обязанностей. '.$rec_doctor['obj_name']) ;
        imagefttext($source,22,0,194,1086,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf','Документ '.date('Ymd',$rec_MO['c_data']).'-'.$rec_doctor['pkey'].'/'.$rec_MO['pkey'].' Дата '.$rec_MO['_data']) ;
        if ($rec_doctor['sert_id'])
        { imagefttext($source,22,0,194,1122,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf','ЭЦП с/н '.str_replace(' ','',$rec_doctor['certificate']['SerialNumber']).', уд.центр: '.$rec_doctor['certificate']['IssuerName']) ;
          imagefttext($source,22,0,194,1158,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf','Действителен с '.date('d.m.Y H:i',$rec_doctor['certificate']['ValidFromDate']).' по '.date('d.m.Y H:i',$rec_doctor['certificate']['ValidToDate'])) ;
        } */



        imagefttext($source,22,0,1340,1275,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_WO['probeg']) ;
        imagefttext($source,22,0,1370,2090,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$rec_WO['fuel']) ;

         // дата выдачи пут.листа
        imagefttext($source,22,0,639,355,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',date('d',$rec_WO['data_from'])) ;
        imagefttext($source,22,0,726,355,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$_SESSION['list_mon_short_names'][date('n',$rec_WO['data_from'])]) ;
        imagefttext($source,22,0,940,355,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',date('y',$rec_WO['data_from'])) ;
        imagefttext($source,22,0,1030,355,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',date('H:i',$rec_WO['data_from'])) ;
        // срок действия путевого листа
        imagefttext($source,22,0,639,405,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',date('d',$rec_WO['data_to'])) ;
        imagefttext($source,22,0,726,405,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',$_SESSION['list_mon_short_names'][date('n',$rec_WO['data_to'])]) ;
        imagefttext($source,22,0,940,405,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',date('y',$rec_WO['data_to'])) ;
        imagefttext($source,22,0,1030,405,hexdec(0),_DIR_EXT.'/image_print/DejaVuSerif.ttf',date('H:i',$rec_WO['data_to'])) ;

          //$mpdf->WriteHTML('<img id=stamp src="/transkom.png" width="300">');
        if ($rec_org['stamp'])
        { list($logo,$type_logo)=open_image(img_clone($rec_org['stamp'],'source',array('return_dir'=>1))) ;
          if (_sizeof($logo))
           { $w_l=imagesx($logo)  ; $h_l=imagesy($logo) ;
             imagecopymerge($source,$logo,120,10, 0, 0,$w_l,$h_l,100) ;
             ImageDestroy($logo);
           }
        }

	    $temp_fname='' ;
        if ($rec_MO['_sertificate_stamp_base64'])
        { $img_cont=base64_decode($rec_MO['_sertificate_stamp_base64']) ;
          $temp_fname=_TEMP_DIR.$rec_MO['pkey'].'_mo_stamp.png' ;
          file_put_contents($temp_fname,$img_cont) ;
        }

	    //$img_dir=ESMO()->get_mo_img_dir_by_id($rec_MO['pkey'],'dir','ticket.png',array('check_directory'=>0,'no_check_exist_file'=>1)) ;
	    if (file_exists($temp_fname))
        list($logo,$type_logo)=open_image($temp_fname) ;
          if (_sizeof($logo))
           { $w_l=imagesx($logo)  ; $h_l=imagesy($logo) ;
             imagecopymerge($source,$logo,400,1000, 0, 0,$w_l,$h_l,100) ;
             ImageDestroy($logo);
           }
      }

    }



    put_image($source,$type,array()) ;

    ImageDestroy($source);

    return(array())  ;
}

?>
