public function uslugi_template_cat_Html($arr, $NO_show_head = 0, $status_snab = '', $pause = 0, $edit_true = true) { // определяем редакторов для полей (html тегов) $this->edit_admin = $this->user_access == 1 ? ' contenteditable="true" class="edit_span"' : ''; $this->edit_men = $this->user_access == 5 ? ' contenteditable="true" class="edit_span"' : ''; $this->edit_snab = $this->user_access == 8 ? ' contenteditable="true" class="edit_span"' : ''; // '.$this->edit_admin.$this->edit_snab.$this->edit_men.' // если работает снаб, ограничиваем права мена и наоборот if ($status_snab == 'in_calculation' || $status_snab == 'in_recalculation') { $this->edit_snab = $this->user_access == 8 && !$pause ? ' contenteditable="true" class="edit_span"' : ''; $this->edit_men = ''; } else { $this->edit_men = $this->user_access == 5 && !$pause ? ' contenteditable="true" class="edit_span"' : ''; $this->edit_snab = ''; } // обнуляем все права при $edit_true == false if ($edit_true == false) { $this->edit_men = ''; $this->edit_snab = ''; $this->edit_admin = ''; $pause = 1; } $html = ''; // если массив услуг пуст возвращаем пустое значение if (!count($arr)) { return $html; } // сохраняем id услуг $id_s = array(); foreach ($arr as $key => $value) { $id_s[] = $value['uslugi_id']; } $id_s = implode(', ', $id_s); // делаем запрос по услугам global $mysqli; $query = "SELECT `" . OUR_USLUGI_LIST . "`.`parent_id`,\n\t\t`" . OUR_USLUGI_LIST . "`.`tz`,\n\t\t`" . OUR_USLUGI_LIST . "`.`edit_pr_in`,\n\t\t`" . OUR_USLUGI_LIST . "`.`price_out`,\n\t\t`" . OUR_USLUGI_LIST . "`.`for_how`,\n\t\t`" . OUR_USLUGI_LIST . "`.`id`,\n\t\t`" . OUR_USLUGI_LIST . "`.`name`,\n\t\t`" . OUR_USLUGI_LIST . "_par`.`name` AS 'parent_name' \n\t\tFROM " . OUR_USLUGI_LIST . "\ninner join `" . OUR_USLUGI_LIST . "` AS `" . OUR_USLUGI_LIST . "_par` ON `" . OUR_USLUGI_LIST . "`.`parent_id`=`" . OUR_USLUGI_LIST . "_par`.`id` WHERE `" . OUR_USLUGI_LIST . "`.`id` IN (" . $id_s . ") ORDER BY `os__our_uslugi_par`.`name` ASC "; // $query = "SELECT * FROM `".OUR_USLUGI_LIST."` WHERE `id` IN (".$id_s.")"; // echo $query; $result = $mysqli->query($query) or die($mysqli->error); $services_arr = array(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { foreach ($arr as $key => $value) { $services_arr[$row['id']] = $row; } } } include_once ROOT . "/libs/php/classes/print_calculators_class.php"; $uslname = ''; foreach ($services_arr as $key => $service) { // $NO_show_head добавлен как необязательная переменная для отключения вывода // названия группы услуги if ($uslname != $service['parent_name'] && !$NO_show_head) { $html .= '<tr class="group_usl_name" data-usl_id="' . $service['parent_id'] . '"> <th colspan="7">' . $service['parent_name'] . '</th> </tr>'; $uslname = $service['parent_name']; } foreach ($arr as $key2 => $value2) { if ($value2['uslugi_id'] == $key) { $price_in = $value2['for_how'] == "for_all" ? $value2['price_in'] : $value2['price_in'] * $value2['quantity']; $price_out_men = $value2['for_how'] == "for_all" ? $value2['price_out'] : $value2['price_out'] * $value2['quantity']; $pribl = $value2['for_how'] == "for_all" ? $value2['price_out'] - $value2['price_in'] : $value2['price_out'] * $value2['quantity'] - $value2['price_in'] * $value2['quantity']; $dop_inf = $value2['for_how'] == "for_one" ? '(за тираж ' . $value2['quantity'] . ' шт.)' : ''; // информация из калькулятора $calc_info = ''; $calc_class = ''; if ($service['parent_id'] == 6) { $calc_class = ' service-calculator'; $calc_info = '<span class="calc_info">/ ' . printCalculator::convert_print_details($value2['print_details']) . ' /</span>'; } $price_out_snab = $value2['for_how'] == "for_all" ? $value2['price_out_snab'] : $value2['price_out_snab'] * $value2['quantity']; $real_price_out = $service['for_how'] == "for_all" ? $service['price_out'] : $service['price_out'] * $value2['quantity']; // ТЗ кнопки $buttons_tz = trim($value2['tz']) == '' ? '<span class="tz_text_new"></span>' : '<span class="tz_text_edit"></span>'; $html .= '<tr class="calculate calculate_usl " data-dop_uslugi_id="' . $value2['id'] . '" data-our_uslugi_id="' . $service['id'] . '" data-our_uslugi_parent_id="' . trim($service['parent_id']) . '" data-for_how="' . trim($service['for_how']) . '"> <td><div class="' . $calc_class . '">' . $service['name'] . ' ' . $dop_inf . ' <br> ' . $calc_info . '</div></td> <td class="row_tirage_in_gen uslugi_class price_in"><span ' . ($service['edit_pr_in'] == '1' ? $this->edit_admin . $this->edit_snab . $this->edit_men : '') . '>' . $this->round_money($price_in) . '</span></td> <td class="row_tirage_in_gen uslugi_class percent_usl"><span ' . $this->edit_admin . $this->edit_snab . $this->edit_men . '>' . $this->get_percent_Int($value2['price_in'], $value2['price_out']) . '</span></td> <td class="row_price_out_gen uslugi_class price_out_men"><span ' . $this->edit_admin . $this->edit_men . '>' . $this->round_money($price_out_men) . '</span></td> <td class="row_pribl_out_gen uslugi_class pribl"><span>' . $this->round_money($pribl) . '</span></td> <td class="usl_tz">' . $buttons_tz . '<span class="tz_text">' . base64_decode($value2['tz']) . '</span><span class="tz_text_shablon">' . $service['tz'] . '</span></td>'; $html .= $this->user_id == $value2['creator_id'] || $this->user_access == 1 ? '<td class="usl_del"><span class="del_row_variants"></span></td>' : ''; // $html .= $value2['creator_id']; $html .= '</tr>'; } } } return $html; }
protected function get_dop_inputs_for_services($id, $dop_usluga_id, $enable_edit = 0) { global $mysqli; // допуски на редактирование $enable_edit = isset($_POST['order_status']) && $_POST['order_status'] != 'in_work' && $_POST['order_status'] != 'paused' && $_POST['order_status'] != 'cancelled' && $_POST['order_status'] != 'shipped' ? 1 : 0; if ($this->user_access != 5) { $enable_edit = 1; } // запрет для буха if ($this->user_access == 2) { $enable_edit = 0; } $readonly = $enable_edit == 0 ? ' disabled' : ''; include_once ROOT . "/libs/php/classes/print_calculators_class.php"; // запрашиваем информацию по ТЗ и , если нужно if (!isset($this->Service)) { // если нам ничего не известно по строке из CAB_DOP_USLUGI $query = "SELECT * FROM " . CAB_DOP_USLUGI . " WHERE `id` = '" . $dop_usluga_id . "'"; $result = $mysqli->query($query) or die($mysqli->error); $this->Service = array(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $this->Service = $row; } } } // если у нас есть информация в поле $this->Service['print_details'] - декодируем её в читабельный вид if (trim($this->Service['print_details']) != '') { include_once './libs/php/classes/agreement_class.php'; $this->Service['print_details_read'] = '<div><span>Данные из калькулятора:</span><br><div class="calculator_info">' . printCalculator::convert_print_details($this->Service['print_details']) . '</div></div>'; } else { $this->Service['print_details_read'] = ''; } // получаем инфу и настройки по данной услуге if (!isset($this->All_Services_arr)) { $this->All_Services_arr = $this->get_all_services_names_Database(); } $this->iputs_id_Str = isset($this->All_Services_arr[$id]['uslugi_dop_inputs_id']) ? $this->All_Services_arr[$id]['uslugi_dop_inputs_id'] : ''; $this->Service_logotip_on = isset($this->All_Services_arr[$id]['logotip_on']) ? $this->All_Services_arr[$id]['logotip_on'] : ''; $this->Service_show_status_film_photos = isset($this->All_Services_arr[$id]['show_status_film_photos']) ? $this->All_Services_arr[$id]['show_status_film_photos'] : ''; $this->maket_old_true_for_Service = isset($this->All_Services_arr[$id]['maket_old_true']) ? $this->All_Services_arr[$id]['maket_old_true'] : ''; // echo $row['logotip_on']; ////////////////////////// // СЛЕДУЮЩИЕ 2 запроса В БЛИЖАЙШЕМ БУДУЩЕМ нужно сократить до одного !!!!!!!!!!!! ////////////////////////// // запрашиваем список полей предназначенных для этой услуги $query = "SELECT * FROM `" . CAB_DOP_USLUGI_DOP_INPUTS . "` WHERE `id` IN (" . $this->iputs_id_Str . ")"; $this->iputs_arr = array(); if (trim($this->iputs_id_Str) != '') { $result = $mysqli->query($query) or die($mysqli->error); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $this->iputs_arr[] = $row; } } } // получаем список всех полей $query = "SELECT * FROM `" . CAB_DOP_USLUGI_DOP_INPUTS . "`"; $result = $mysqli->query($query) or die($mysqli->error); $iputs_all_arr = array(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $iputs_all_arr[] = $row; } } // получаем json $this->print_details_dop_Json = trim($this->Service['print_details_dop']) == "" ? '{}' : $this->Service['print_details_dop']; // декодируем json в массив $this->print_details_dop = json_decode($this->print_details_dop_Json, true); // перебор полей указанных в услуге $html = ''; // добавляем скрытую json строку для обработке в JS $html = '<div id="dop_input_json">' . $this->print_details_dop_Json . '</div>'; //$html .= $this->print_arr($this->print_details_dop); // добавляем информацию из калькулятора.... если есть $html .= $this->Service['print_details_read']; foreach ($this->iputs_arr as $key => $input) { //echo $input['name_ru']; $html .= $input['name_ru'] . ':<br>'; //if($input['name_en'] == "tip_pechati"){$html .= '<div>'.$this->print_details_dop[$input['name_en']].'</div>';} if ($input['type'] == "text") { if (isset($this->print_details_dop[$input['name_en']])) { $text = $this->print_details_dop[$input['name_en']]; $text = htmlspecialchars(base64_decode($text), ENT_QUOTES); } else { // $html .= '!= '.$input['name_en']; $text = ''; } $html .= '<div><input class="dop_inputs" data-dop_usluga_id="' . $dop_usluga_id . '" type="' . $input['type'] . '" name="' . $input['name_en'] . '" placeholder="" value=\'' . $text . '\'" ' . $readonly . '></div>'; } else { $html .= 'данный тип поля пока что не предусмотрен'; } // удаляем $this->print_details_dop[$input['name_en']] unset($this->print_details_dop[$input['name_en']]); } //перебираем оставшиеся значения из json .... они могут остаться, // если админы что-то наменяли и открепили доп поля от услуги foreach ($iputs_all_arr as $key => $input) { if (isset($this->print_details_dop[$input['name_en']])) { $html .= $input['name_ru'] . ' * <span class="delete_dop_input_for_admin">(было удалено Админом из списка обязательных полей для услуги)</span><br>'; if ($input['type'] == "text") { $text = isset($this->print_details_dop[$input['name_en']]) ? $this->print_details_dop[$input['name_en']] : ''; $text = htmlspecialchars(base64_decode($text), ENT_QUOTES); $html .= '<div><input class="dop_inputs" data-dop_usluga_id="' . $dop_usluga_id . '" type="' . $input['type'] . '" name="' . $input['name_en'] . '" placeholder="" value="' . $text . '" ' . $readonly . '></div>'; } else { $html .= 'данный тип поля пока что не предусмотрен'; } } } // подключаем поле логотип, если оно включено в админке или уже что-то содержит if ($this->Service['logotip'] != '' || trim($this->Service_logotip_on) == "on") { $html .= '<div>Логотип<br><input type="text" class="save_logotip" name="logotip" value="' . addslashes($this->Service['logotip']) . '" ' . $readonly . '></div>'; } // подключаем поле плёнки, если оно включено в админке if (trim($this->Service_show_status_film_photos) == "on") { $html .= '<div>Плёнки/Клише<br>'; $html .= $this->get_statuslist_film_photos($this->Service['film_photos_status'], $this->Service['id']); // $html .='<textarea class="save_logotip" name="logotip">'.$this->Service['logotip'].'</textarea>'; $html .= '</div>'; } // подключаем поле путь к макету if (trim($this->maket_old_true_for_Service) == "on") { $html .= '<div>Путь к макету (к старому):<br>'; $html .= '<div><input type="text" name="the_url_for_layout" placeholder="заполнить при необходимости" class="save_the_url_for_layout" value="' . base64_decode($this->Service['the_url_for_layout']) . '" ' . $readonly . '></div>'; // $html .='<textarea class="save_logotip" name="logotip">'.$this->Service['logotip'].'</textarea>'; $html .= '</div>'; } $html .= '<div>Комментарии для исполнителя ' . (isset($this->performer[$this->Service['performer']]) ? '"' . $this->performer[$this->Service['performer']] . '"' : '') . '<br><textarea class="save_tz" name="tz" ' . $readonly . '>' . str_replace('<br>', "", base64_decode($this->Service['tz'])) . '</textarea></div>'; return $html; }
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; }