<?php 

    
	include_once(ROOT."/libs/php/classes/agreement_class.php");
    $agreement = Agreement::fetch_agreement_content($agreement_id);
   
    $date_arr = explode('-',$agreement['date']);
	$agreement_year_folder = $date_arr[0];
	
	$our_requisit_id = fetchOneValFromGeneratedAgreementTbl(array('retrieve'=>'our_requisit_id','coll'=>'id','val'=>$agreement_id));
	$client_requisit_id = fetchOneValFromGeneratedAgreementTbl(array('retrieve'=>'client_requisit_id','coll'=>'id','val'=>$agreement_id));
	
	$path = $_SERVER['DOCUMENT_ROOT'].'/admin/order_manager/data/agreements/'.$client_id.'/'.$agreement_year_folder.'/'.$_GET['agreement_type'].'/'.$our_requisit_id.'_'.$client_requisit_id.'/specifications/'.$_GET['specification_num'].'.tpl';
	
    if(isset($_POST['submit_ok']))
	{
		put_content($path,$_POST['page_content']);
	}
	
	
  
 
    $page_content = get_content($path); 

?>

<?php include ('./skins/tpl/agreement/tinymse_js_block.html'); ?>
<style> .main_menu_tbl{ display:none; } </style>
<div style="margin:auto;width:1200px;">
    <div style="margin:10px 20px;">
        <button type="button" onclick="location = '?<?php echo htmlspecialchars(addOrReplaceGetOnURL('section=agreement_editor')); ?>';" style="cursor:pointer;">назад</button>
Esempio n. 2
0
function delete_specification($client_id, $agreement_id, $specification_num)
{
    global $db;
    $query = "DELETE FROM `" . GENERATED_SPECIFICATIONS_TBL . "` WHERE agreement_id = '" . $agreement_id . "' AND client_id = '" . $client_id . "' AND specification_num = '" . $specification_num . "'";
    mysql_query($query, $db) or die(mysql_error());
    $our_requisit_id = fetchOneValFromGeneratedAgreementTbl(array('retrieve' => 'our_requisit_id', 'coll' => 'id', 'val' => $agreement_id));
    $client_requisit_id = fetchOneValFromGeneratedAgreementTbl(array('retrieve' => 'client_requisit_id', 'coll' => 'id', 'val' => $agreement_id));
    $date = fetchOneValFromGeneratedAgreementTbl(array('retrieve' => 'date', 'coll' => 'id', 'val' => $agreement_id));
    $file_name = $_SERVER['DOCUMENT_ROOT'] . '/admin/order_manager/data/agreements/' . strval($client_id) . '/' . substr($date, 0, 4) . '/long_term/' . $our_requisit_id . '_' . $client_requisit_id . '/specifications/' . $specification_num . '.tpl';
    if (file_exists($file_name)) {
        unlink($file_name);
    }
}
Esempio n. 3
0
 static function add_items_for_specification($dateDataObj, $specification_num, $rows_data, $client_id, $agreement_id, $agreement_date, $our_firm_acting_manegement_face, $client_firm_acting_manegement_face, $date, $short_description, $address, $prepayment)
 {
     global $mysqli;
     // print_r($dateDataObj);
     // exit;
     if (!$specification_num) {
         $query = "SELECT MAX(specification_num) specification_num FROM `" . GENERATED_SPECIFICATIONS_TBL . "` WHERE agreement_id = '" . $agreement_id . "'";
         $result = $mysqli->query($query) or die($mysqli->error);
         if ($result->num_rows > 0) {
             $row = $result->fetch_assoc();
             $specification_num = $row['specification_num'] + 1;
         } else {
             $specification_num = 1;
         }
     }
     $date_arr = explode('.', $date);
     $date = $date_arr[2] . '-' . $date_arr[1] . '-' . $date_arr[0];
     $rows_data_arr = json_decode($rows_data);
     // echo $specification_num.'<pre>'; print_r($rows_data_arr); echo '</pre>';//
     // exit;
     // настройки в завасимости от типа спецификации
     $dates_data = self::date_terms_convert($dateDataObj);
     $shipping = '0000-00-00 00:00:00';
     foreach ($rows_data_arr as $data_arr) {
         if (count($data_arr) == 0) {
             continue;
         }
         $summ_out = 0;
         $uslugi_summ_out = 0;
         $main_id = $data_arr->pos_id;
         $dop_id = $data_arr->row_id;
         $query = "SELECT*FROM `" . RT_MAIN_ROWS . "` WHERE `id` = '" . $main_id . "'";
         // echo $query."\r\n";
         $result = $mysqli->query($query) or die($mysqli->error);
         if ($result->num_rows > 0) {
             // 1). main_data
             $main_data = $result->fetch_assoc();
             $query2 = "SELECT*FROM `" . RT_DOP_DATA . "` WHERE `id` = '" . $dop_id . "'";
             // echo $query."\r\n";
             $result2 = $mysqli->query($query2) or die($mysqli->error);
             if ($result2->num_rows > 0) {
                 // 2). dop_data
                 $dop_data = $result2->fetch_assoc();
                 $expel = array("main" => 0, "print" => 0, "dop" => 0);
                 if (@$dop_data['expel'] != '') {
                     $obj = @json_decode($dop_data['expel']);
                     foreach ($obj as $expel_key => $expel_val) {
                         $expel[$expel_key] = $expel_val;
                     }
                 }
                 $summ_out = $dop_data['quantity'] * $dop_data['price_out'];
                 $name = ($main_data['art'] != '' ? 'арт.' . $main_data['art'] : '') . " " . $main_data['name'];
                 $price = $dop_data['price_out'];
                 // прежде чем записать ряд в спецификацию сверим совпадает ли количество в расчете и в услугах
                 // для этого делаем дополнительный запрос к таблице RT_DOP_USLUGI, далее после добавления ряда
                 // будет такойже запрос к таблице RT_DOP_USLUGI но уже чтобы добавить доп услуги в спецификацию
                 $query2_dop = "SELECT*FROM `" . RT_DOP_USLUGI . "` WHERE `dop_row_id` = '" . $dop_id . "' ORDER BY glob_type";
                 // echo $query."\r\n";
                 $result2_dop = $mysqli->query($query2_dop) or die($mysqli->error);
                 if ($result2_dop->num_rows > 0) {
                     while ($uslugi_data = $result2_dop->fetch_assoc()) {
                         if ($uslugi_data['glob_type'] == 'print' && $uslugi_data['quantity'] != $dop_data['quantity']) {
                             $reload['flag'] = true;
                             //echo $dop_data['quantity'];
                             include_once ROOT . "/libs/php/classes/rt_calculators_class.php";
                             $json_out = rtCalculators::change_quantity_and_calculators($dop_data['quantity'], $dop_data['id'], 'true', 'false');
                             $json_out_obj = json_decode($json_out);
                             // если расчет не может быть произведен по причине outOfLimit или needIndividCalculation
                             // сбрасываем количество тиража и нанесения до 1шт.
                             if (isset($json_out_obj->print->outOfLimit) || isset($json_out_obj->print->needIndividCalculation)) {
                                 rtCalculators::change_quantity_and_calculators(1, $dop_data['id'], 'true', 'false');
                                 $query = "UPDATE `" . RT_DOP_DATA . "` SET  `quantity` = '1'  WHERE `id` = '" . $dop_data['id'] . "'";
                                 $result = $mysqli->query($query) or die($mysqli->error);
                             }
                         }
                         /**/
                         if ($uslugi_data['glob_type'] == 'extra' && $uslugi_data['quantity'] != $dop_data['quantity']) {
                             $query = "UPDATE `" . RT_DOP_USLUGI . "` SET  `quantity` = '" . $dop_data['quantity'] . "'  WHERE `id` = '" . $uslugi_data['id'] . "'";
                             $result = $mysqli->query($query) or die($mysqli->error);
                             $uslugi_data['quantity'] = $dop_data['quantity'];
                         }
                     }
                 }
                 if (isset($reload['flag']) && $reload['flag'] == true) {
                     header('Location:' . HOST . '/?' . $_SERVER['QUERY_STRING']);
                     exit;
                 }
                 if ($main_data['type'] != 'cat') {
                     include_once ROOT . "/libs/php/classes/os_form_class.php";
                     include_once ROOT . "/libs/php/classes/cabinet/cabinet_class.php";
                     //os_form_class.php
                     $cabinet = new Cabinet();
                     $details = $cabinet->get_a_detailed_specifications($main_data['type'], $dop_data['no_cat_json']);
                     $details = strip_tags($details, '<div><br><br/><br />');
                     $details = str_replace(array('<div>', '</div>'), array('<br>', ''), $details);
                     $details = str_replace(array("\n", "\r", "\t"), '', $details);
                     $details = str_replace('<br><br>', '<br>', $details);
                     $details = preg_replace('/<div[^<]+>/', '', $details);
                     $name .= $details;
                 }
                 // записываем ряд
                 $specIdsArr[] = Agreement::insert_row($client_id, $agreement_id, $our_firm_acting_manegement_face, $client_firm_acting_manegement_face, $specification_num, $short_description, $address, $prepayment, $name, $dop_data['quantity'], $price, $dop_data['discount'], $date, $dateDataObj, $dates_data);
                 $query3 = "SELECT*FROM `" . RT_DOP_USLUGI . "` WHERE `dop_row_id` = '" . $dop_id . "' ORDER BY glob_type DESC";
                 // echo $query."\r\n";
                 $result3 = $mysqli->query($query3) or die($mysqli->error);
                 if ($result3->num_rows > 0) {
                     while ($uslugi_data = $result3->fetch_assoc()) {
                         // 3). uslugi_data
                         if ($uslugi_data['glob_type'] == 'print' && !!!$expel["print"]) {
                             include_once ROOT . "/libs/php/classes/print_calculators_class.php";
                             $name = printCalculator::convert_print_details($uslugi_data['print_details']);
                             // записываем ряд
                             $specIdsArr[] = Agreement::insert_row($client_id, $agreement_id, $our_firm_acting_manegement_face, $client_firm_acting_manegement_face, $specification_num, $short_description, $address, $prepayment, $name, $uslugi_data['quantity'], $uslugi_data['price_out'], $uslugi_data['discount'], $date, $dateDataObj, $dates_data);
                         }
                         if ($uslugi_data['glob_type'] == 'extra' && !!!$expel["dop"]) {
                             // если альтернативное название отсутствует (вводится при заведении услуги "НЕТ В СПИСКЕ")
                             if (trim($uslugi_data['other_name']) == "") {
                                 $extra_usluga_details = self::get_usluga_details($uslugi_data['uslugi_id']);
                                 $name = $extra_usluga_details ? $extra_usluga_details['name'] : 'Неопределено';
                             } else {
                                 $name = $uslugi_data['other_name'];
                             }
                             // меняем количество на 1(еденицу) если это надбавка на всю стоимость
                             $uslugi_data['quantity'] = $uslugi_data['for_how'] == 'for_all' ? 1 : $uslugi_data['quantity'];
                             // записываем ряд
                             $specIdsArr[] = Agreement::insert_row($client_id, $agreement_id, $our_firm_acting_manegement_face, $client_firm_acting_manegement_face, $specification_num, $short_description, $address, $prepayment, $name, $uslugi_data['quantity'], $uslugi_data['price_out'], $uslugi_data['discount'], $date, $dateDataObj, $dates_data);
                         }
                         /**/
                     }
                 }
             }
         }
     }
     // exit;
     // этап создания отдельного файла Спецификации и сохраниения его на диск
     // проверяем существует ли папка данного клиента если нет создаем её
     // если происходит ошибка выводим отчет
     // проверяем есть папка данного клента, если её нет то создаем её
     $client_dir_name = $_SERVER['DOCUMENT_ROOT'] . '/admin/order_manager/data/agreements/' . strval($client_id);
     //chmod("data/com_offers/", 0775);
     if (!file_exists($client_dir_name)) {
         if (!mkdir($client_dir_name, 0775)) {
             echo 'ошибка создания папки клиента (4)' . $client_dir_name;
             exit;
         }
     }
     // папка обозначающая год (название папки - название года)
     $agreement_date = explode('-', $agreement_date);
     $year_dir_name = $client_dir_name . '/' . $agreement_date[0];
     if (!file_exists($year_dir_name)) {
         if (!mkdir($year_dir_name, 0775)) {
             echo 'ошибка создания папки с именем года' . $year_dir_name;
             exit;
         }
     }
     // папка для типа договора
     $type_dir_name = $year_dir_name . '/long_term';
     if (!file_exists($type_dir_name)) {
         if (!mkdir($type_dir_name, 0775)) {
             echo 'ошибка создания папки с именем года' . $type_dir_name;
             exit;
         }
     }
     $our_requisit_id = fetchOneValFromGeneratedAgreementTbl(array('retrieve' => 'our_requisit_id', 'coll' => 'id', 'val' => $agreement_id));
     $client_requisit_id = fetchOneValFromGeneratedAgreementTbl(array('retrieve' => 'client_requisit_id', 'coll' => 'id', 'val' => $agreement_id));
     // папка для выбранных сторон
     $full_dir_name = $type_dir_name . '/' . $our_requisit_id . '_' . $client_requisit_id;
     if (!file_exists($full_dir_name)) {
         if (!mkdir($full_dir_name, 0775)) {
             echo 'ошибка создания папки с именем года' . $full_dir_name;
             exit;
         }
     }
     // папка для выбранных спецификаций
     $full_dir_name = $full_dir_name . '/specifications';
     if (!file_exists($full_dir_name)) {
         if (!mkdir($full_dir_name, 0775)) {
             echo 'ошибка создания папки с именем года' . $full_dir_name;
             exit;
         }
     }
     // записываем файл
     $file_name = $full_dir_name . '/' . $specification_num . '.tpl';
     //echo $file_name;
     //$file_name = $dir_name_full.'/com_pred_1_1.doc';
     //if(file_exists($file_name)){
     //echo 'файл с таким именем уже существует (232)';
     //exit;
     //}
     if ($dateDataObj->data_type == 'days') {
         $origin_file_name = ROOT . '/modules/agreement/agreements_templates/specification.tpl';
     }
     if ($dateDataObj->data_type == 'date') {
         $origin_file_name = ROOT . '/modules/agreement/agreements_templates/specification_type2_by_date.tpl';
     }
     $fd_origin = fopen($origin_file_name, 'r');
     $file_content = fread($fd_origin, filesize($origin_file_name));
     fclose($fd_origin);
     $fd = fopen($file_name, 'w');
     $write_result = fwrite($fd, $file_content);
     //\r\n
     fclose($fd);
     /*
     // создаем предзаказ 
     include_once(ROOT."/libs/php/classes/rt_class.php");
     
     RT::make_order($rows_data,$client_id,$_GET['query_num'],$specification_num,$agreement_id,$dateDataObj->doc_type,$dateDataObj->data_type,$dates_data['shipping_date_time'],$dates_data['item_production_term'],$dates_data['final_date_time']);
     */
     return $specification_num;
 }