Esempio n. 1
0
File: func.php Progetto: nikuha/rs
function generate_order($order_id, $type, $stamp)
{
	global $office_arr, $provider_arr, $rus_month_1, $admin_region_list;
	$office_fields = array();
	foreach($office_arr as $v) $office_fields[] = "of.$v as office_$v";
	foreach($provider_arr as $v) $office_fields[] = "pr.$v as provider_$v";
	$of_sql = join(', ', $office_fields);
	
	$sql = mysql_query("
		SELECT 
			z.*, ob.name as object_name, ob.address as object_address,
			ct.name as city_name, c.name as country_name, c.country_id,
			of.doctop, u.name as username, u.email as admin_email, u.name as admin_name,
			$of_sql
		FROM 
			".TABLE_ORDER." z 
			LEFT JOIN ".TABLE_OBJECT." ob on (ob.object_id=z.object_id) 
			LEFT JOIN ".TABLE_CITY." ct ON (ob.city_id=ct.city_id)
			LEFT JOIN ".TABLE_COUNTRY." c ON (ct.country_id=c.country_id)
			LEFT JOIN ".TABLE_OFFICE." of ON (z.office_id=of.office_id)
			LEFT JOIN ".TABLE_PROVIDER." pr ON (z.provider_id=pr.provider_id)
			LEFT JOIN ".TABLE_USER." u on (u.user_id=z.user_id) 
		WHERE
			z.order_id=$order_id AND ob.object_id>0
		GROUP BY
			z.order_id
		LIMIT
			1
		") or Error(1, __FILE__, __LINE__);
	if(!($arr = @mysql_fetch_array($sql))) return false; 
	
	if($arr['country_id']==25) {$arr['country_name'] = ''; $arr['city_name'] = ''; }
	
	list($y_ld,$m_ld,$d_ld) = explode("-", $arr['date_from']);
	$i=-1;
	do 
	{
		$i++;
		$ts = mktime(0,0,0,$m_ld,31-$i,$y_ld);
		
	} while(!checkdate($m_ld,31-$i,$y_ld));
	
	$arr['date_lastday'] = sql_to_text_date(date("Y-m-d", $ts));
	
	$arr['date_zayavka'] = sql_to_text_date($arr['date']);
	$arr['date_from'] = sql_to_text_date($arr['date_from']);
	$arr['date_to_rus'] = sql_to_text_date($arr['date_to'], 1);
	$arr['date_to'] = sql_to_text_date($arr['date_to']);
	
	$arr['date_pay_rus'] = sql_to_text_date($arr['date_pay'], 1);
	
	if($arr['fio'])
	{
		$arr['fio_list'] = preg_split("/[\r\n]+/", $arr['fio']);
		$arr['pasport'] = preg_split("/[\r\n]+/", $arr['pasport']);
		$arr['birthday'] = preg_split("/[\r\n]+/", $arr['birthday']);
		$arr['tphone'] = preg_split("/[\r\n]+/", $arr['tphone']);
	}
	else
	{
		$client_arr = $arr['clients'] ? explode(",", $arr['clients']) : array();
		
		$arr['fio_list'] = array();
		$arr['pasport'] = array();
		$arr['birthday'] = array();
		$arr['birthday_city'] = array();
		$arr['tphone'] = array();
		
		$plus = preg_split("/[\r\n]/", $arr['plus']);

		foreach($client_arr as $k=>$v) 
		{
			$sql = mysql_query("SELECT * FROM ".TABLE_CLIENT." WHERE client_id='$v'") or Error(1, __FILE__, __LINE__);
			if($client = @mysql_fetch_array($sql)) 
			{
				$name = $client['name'];
				if($arr['plus'] && isset($plus[$k])) $name .= ' '.$plus[$k];
				$arr['fio_list'][] = $name;
				$arr['pasport'][] = $client['pasport'];
				$arr['birthday'][] = sql_to_text_date($client['birthday'], 0, 1);
				$arr['birthday_city'][] = $client['birthday_city'];
				$arr['tphone'][] = $client['phone'];
			}
		}
	}
	
	$arr['amount_list'] = explode(",", $arr['amount']);
	$arr['price_list'] = explode(",", $arr['price']);
	$arr['summa_list'] = explode(",", $arr['summa']);
	
	if(!$arr['discount'] && $arr['skidka']) 
	{
		$arr['discount'] = $arr['total'] - $arr['inall'];
	}
	
	list($arr['total_doc'], $arr['provider_sum'], $arr['agentsum_doc']) = 
		get_agentsum($arr['total'], $arr['inall'], $arr['provider_sum'], $arr['debt'], $arr['paid_debt'], $arr['paytoprovider']);
	
	
	$arr['date'] = date("d.m.y");
	$arr['date_rus'] =  '"'.date("d").'" '.$rus_month_1[(int)date("m")]." ".date("Y");
	$arr['date_full'] = date("d.m.Y");
	$arr['time'] = date("H:i");
	
	$arr['note'] = nl2br($arr['note']);
	$arr['suite_descr'] = nl2br($arr['suite_descr']);
	$arr['extra'] = nl2br($arr['extra']);
	
	$arr['suite_st'] = nl2br($arr['suite_st']);
	
	$arr['provider_rekvizit_string'] = ereg_replace("(\r)?\n", ", ", $arr['provider_rekvizit']);
	$arr['provider_rekvizit'] = nl2br($arr['provider_rekvizit']);
	$arr['client_rekvizit'] = nl2br($arr['client_rekvizit']);
	
	$arr['region_name'] = $arr['office_region'];
	
	$arr['stamp'] = $stamp;
	if($stamp)
	{
		$arr['act_img'] = get_img_code("act_$arr[office_id].jpg"); 
		$arr['stamp_img'] = get_img_code("stamp_$arr[office_id].png");  
		$arr['otchetagenta_img'] = get_img_code("otchetagenta_$arr[office_id].jpg"); 		
		$arr['schet_img'] = get_img_code("schet_$arr[office_id].jpg"); 
		$arr['dogovor_img'] = get_img_code("dogovor_$arr[office_id].jpg");  
	}
	
	$arr['direktora'] = $arr['office_id']==7 ? 'Директора' : 'Генерального директора';
	$arr['direktor'] = $arr['office_id']==7 ? 'Директор' : 'Генеральный директор';

	if($type=='dogovor') 
	{
		$file = $arr['person'] ? 'dogovor_oper_f' : 'dogovor_oper_u';
	}
	elseif($type=='dogovor2')
	{
		$file = $arr['person'] ? 'dogovor_otel_f' : 'dogovor_otel_u';
	}
	elseif($type=='dogovor3')
	{
		$file = $arr['person'] ? 'dogovor_uslugi_f' : 'dogovor_uslugi_u';
	}
	else $file = $type;  
	$text = get_template("templ/doc/$file.htm", $arr);
	//$text = escape_string($text);
	
	$sql = mysql_query("SELECT doc_id FROM ".TABLE_DOC." WHERE order_id=$order_id AND type='$type'") 
		or Error(1, __FILE__, __LINE__);
	$arr = @mysql_fetch_array($sql);	
	if($doc_id = @$arr[doc_id])
	{
		mysql_query("UPDATE ".TABLE_DOC." SET date=CURDATE(), stamp=$stamp 
			WHERE doc_id=$doc_id") 
			or Error(1, __FILE__, __LINE__);
	}
	else	
	{
		mysql_query("INSERT INTO ".TABLE_DOC." SET order_id=$order_id, type='$type', date=CURDATE(),
				stamp=$stamp") 
			or Error(1, __FILE__, __LINE__);
		$doc_id = mysql_insert_id();
	}
			
	$fn = "doc/$doc_id.htm";
	$f = fopen($fn, 'w');
	fwrite($f, $text);
	fclose($f);
	
	
	return true;
}
Esempio n. 2
0
File: doc.php Progetto: nikuha/rs
     $replace['order_list'] = $order_list;
     if (!$office_id) {
         $office_id = 1;
     }
     $office_arr = array('region', 'name', 'director', 'director1', 'inn', 'kpp', 'rs', 'ks', 'bank', 'bik', 'licence', 'address', 'phone', 'fax', 'email');
     $sql = mysql_query("SELECT *  FROM " . TABLE_OFFICE . " \n\t\t\tWHERE office_id={$office_id}") or Error(1, __FILE__, __LINE__);
     $arr = @mysql_fetch_array($sql);
     foreach ($office_arr as $v) {
         $replace["office_{$v}"] = $arr[$v];
     }
     $sql = mysql_query("SELECT fullname  FROM " . TABLE_PROVIDER . " pr \n\t\t\tWHERE pr.provider_id={$provider_id}") or Error(1, __FILE__, __LINE__);
     $arr = @mysql_fetch_array($sql);
     $replace['provider_fullname'] = $arr['fullname'];
     if ($replace['stamp']) {
         $replace['otchetagenta_img'] = get_img_code("otchetagenta_{$office_id}.jpg");
         $replace['schet_img'] = get_img_code("schet_{$office_id}.jpg");
     }
     $text = get_template("templ/doc/agent_all.htm", $replace);
     $date = date("d-m-Y_H-i");
     $archive_file = "files/archive/agent_{$date}.doc";
     $f = fopen($archive_file, 'w');
     fwrite($f, $text);
     fclose($f);
     include "pdfmaster/pdf.php";
 }
 if ($i_count) {
     Header("Location: ?p={$part}&download=" . urlencode($archive_file));
 } else {
     $_SESSION['message'] = "За указанный период не найдена не одна заявка";
     Header("Location: ?p={$part}");
 }