You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

143 lines
6.3 KiB

<?php
include "../header.php";
if (isset($_POST['status'])) {
$fromsign = $_POST['fromsign'];
foreach ($_POST as $k => $v) {
$$k = htmlspecialchars(stripslashes(trim($v)));
}
if ($checker) {
$do_assign = $end_flow = 0;
$check_date = date("Y-m-d H:i:s");
// 總共簽核關卡數
$db_query = "select sign_total, case when (length(sign1)>7) then 1 else 0 end +
case when (POSITION('Y' IN sign2) or POSITION('N' IN sign2)) then 1 else 0 end +
case when (length(sign3)>7) then 1 else 0 end +
case when (length(sign4)>7) then 1 else 0 end,
sign2
from pricereview_sign where mid = '$id'";
$res = mysqli_query($link, $db_query);
$row = mysqli_fetch_row($res);
list($sign_total, $sign_now, $sign2_ori) = $row;
$sql = $sql2 = "";
if ($st == 1) {
$sql = "sign1 = '$checker,$status,$check_date', sign1_note = '$sign_note'";
} elseif ($st == 2) {
if ($sign_now > 1) {
echo "<script>";
echo "alert('請勿重覆審核。');";
echo "location.href='pricereview-index.php?function_name=pricereview&".$token_link."';";
echo "</script>";
exit;
}
$sign2_ori_arr = explode("<##>", $sign2_ori);
$sign2_upd_arr = [];
foreach ($sign2_ori_arr as $k => $v) {
list($a, $b, $c) = explode(",", $v);
if ($a == $checker) $sign2_upd_arr[$k] = $checker.",".$status.",".$check_date;
else $sign2_upd_arr[$k] = $v;
}
$sql = "sign2 = '".implode("<##>", $sign2_upd_arr)."', sign2_note = '$sign_note'";
} elseif ($st == 3) {
$sql = "sign3 = '$checker,$status,$check_date', sign3_note = '$sign_note'";
} else {
$sql = "sign4 = '$checker,$status,$check_date', sign4_note = '$sign_note'";
}
if ($status == "N") {
$sql2 .= "status = 'YN'";
$end_flow = 1;
} elseif ($sign_total == ($sign_now+1)) {
if ($user_id == "M0006") {
$final_price_total = str_replace(",", "", $final_price_total);
if ($final_price_total > 0) {
$sql2 .= "status = 'YY', price_total = '$final_price_total'";
} else {
$sql2 .= "status = 'YY'";
}
} else {
$sql2 .= "status = 'YY'";
}
$end_flow = 1;
}elseif($status == 'YY'){
$sql2 .= "status = 'YY'";
$end_flow = 1;
}
else {
$do_assign = 1;
}
if ($item_no_all) {
$item_no_arr = explode(",", $item_no_all);
$item_price_arr = explode(",", $item_price_all);
$pv_rate_arr = explode(",", $pv_rate_all);
$allocate_arr = explode(",", $allocate_all);
$gross_profit_arr = explode(",", $gross_profit_all);
$gross_profit_rate_arr = explode(",", $gross_profit_rate_all);
$note_arr = explode(",", $note_all);
$mi_fix_arr = explode(",", $mi_fix_all);
foreach ($item_no_arr as $k => $v) {
if (empty($mi_fix_all)) $mi_fix_arr[$k] = 0;
else $mi_fix_arr[$k] = str_replace(",", "", $mi_fix_arr[$k]);
if (empty($gross_profit_arr[$k])) $gross_profit_arr[$k] = 0;
if (empty($gross_profit_rate_arr[$k])) $gross_profit_rate_arr[$k] = 0;
$db_query = "update pricereview_item set mi_fix = '$mi_fix_arr[$k]', ";
$db_query .= "gross_profit = '$gross_profit_arr[$k]', gross_profit_rate = '$gross_profit_rate_arr[$k]' ";
$db_query .= "where mid = '$id' and item_no = '$v'";
mysqli_query($link, $db_query);
}
}
echo $status;
if ($sql) {
$db_query = "update pricereview_sign set $sql where mid = '$id'";
mysqli_query($link, $db_query);
}
if ($sql2) {
$db_query = "update pricereview_main set $sql2 where id = '$id'";
mysqli_query($link, $db_query);
}
if ($do_assign) {
$db_query = "select sign2, concat(length(sign3), sign3), concat(length(sign4), sign4) from pricereview_sign where mid = '$id'";
$res = mysqli_query($link, $db_query);
$row = mysqli_fetch_row($res);
if (!preg_match("/Y/", $row[0]) && !preg_match("/N/", $row[0])) {
$sign_arr = explode("<##>", $row[0]);
foreach ($sign_arr as $v) {
$next_signer[] = substr($v, 0, 5);
}
} elseif (strlen($row[1]) == 8) {
$next_signer = substr(str_replace(",","",$row[1]), 1);
} elseif (strlen($row[2]) == 8) {
$next_signer = substr(str_replace(",","",$row[2]), 1);
}
do_assign("prm01", $id, $contractno_h, $next_signer, $st);
// 寄信給下位簽核人
$mail_list = [];
$ret = accountid2email($next_signer);
if (!empty($ret)) {
foreach ($ret as $uid => $uemail) {
$mail_list[] = [$uid, $uemail];
}
include dirname(__DIR__)."/class/Cmail.php";
$sendmail = new Cmail;
$title = "【新梯價審通知】卷號:".$contractno_h;
$content = "<p>您有待簽核案件,請至<a href=\"http://oa.masada.com.tw\">客戶管理 > 價格審查_新梯</a>,點擊「待簽核」進行作業,謝謝!</p>";
//print_r($mail_list);
$sendmail->sendx($title, $content, $mail_list);
}
}
if ($end_flow) {
end_flow("prm", "prm01", $id, $contractno_h);
}
}
mysqli_close($link);
echo "<script type ='text/JavaScript'>";
if($fromsign == 1){
echo "location.href='../sign/list.php?system_id=prm&flow_id=prm01&function_name=show&".$token_link."';";
}else{
echo "location.href='pricereview-check.php?id=".$id."&function_name=pricereview&".$token_link."';";
}
echo "</script>";
}