7 changed files with 181 additions and 32 deletions
@ -0,0 +1,136 @@ |
|||
<?php |
|||
include "header.php"; |
|||
require_once dirname(__DIR__) . '/common/composer/vendor/autoload.php'; |
|||
|
|||
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
|||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as xls; |
|||
//use PhpOffice\PhpSpreadsheet\Reader\Xls; |
|||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx; |
|||
|
|||
$arrayData = []; |
|||
echo "合約號,部門,經理,營業員,客戶名稱,簽約款,二次款,貨抵工地款,安裝款,試車款,交車款,取得許可證約交款,取得許可函後6個月約交款,狀態</br>"; |
|||
|
|||
// $T8_array = mysqli_fetch_all($T8_array, MYSQLI_ASSOC); |
|||
|
|||
// $sql_depid = "SELECT department_id, name from department"; |
|||
// $dept_query = mysqli_query($link, $sql_depid); |
|||
// $deptype = mysqli_fetch_all($dept_query, MYSQLI_ASSOC); |
|||
|
|||
|
|||
$sql_contract = "SELECT a.BillNo, a.PayStage, a.PlanPayAmt,s.BizPartnerId,c.BizPartnerName FROM salOrderStagePay AS a |
|||
LEFT JOIN salSalesOrder AS s on a.BillNo = s.BillNo |
|||
LEFT JOIN comBusinessPartner as c ON s.BizPartnerId=c.BizPartnerId |
|||
WHERE s.ModeId = 'M' AND (s.CurrentState=2 OR s.CurrentState=4) "; |
|||
$contract = $conn->query($sql_contract); |
|||
foreach ($contract as $cont) { |
|||
// print_r($cont); |
|||
// echo "<br>"; |
|||
$BillNo = $cont['BillNo']; |
|||
$PayStage = $cont['PayStage']; |
|||
$PayAmount = $cont['PlanPayAmt']; |
|||
$partnerName = $cont['BizPartnerName']; |
|||
|
|||
if (isset($arrayData[$BillNo])) { |
|||
if (stristr($PayStage, '二次款') || stristr($PayStage, '出貨前') || stristr($PayStage, '簽約後') || stristr($PayStage, '簽訂後') || stristr($PayStage, '建照核發時') || stristr($PayStage, '簽約60')) { |
|||
$arrayData[$BillNo][5] = $PayAmount; |
|||
} elseif ($PayStage == '簽約' || stristr($PayStage, '簽定') || stristr($PayStage, '簽訂') || stristr($PayStage, '訂金')) { |
|||
$arrayData[$BillNo][4] = $PayAmount; |
|||
} elseif (stristr($PayStage, '貨抵工地') || stristr($PayStage, '貨底工地')) { |
|||
$arrayData[$BillNo][6] = $PayAmount; |
|||
} elseif (stristr($PayStage, '安裝')) { |
|||
$arrayData[$BillNo][7] = $PayAmount; |
|||
} elseif (stristr($PayStage, '試車')) { |
|||
$arrayData[$BillNo][8] = $PayAmount; |
|||
} elseif (stristr($PayStage, '交車') || stristr($PayStage, '完工') || stristr($PayStage, '驗收')) { |
|||
$arrayData[$BillNo][9] = $PayAmount; |
|||
} elseif (stristr($PayStage, '取得合格函') || stristr($PayStage, '取得許可函')) { |
|||
$arrayData[$BillNo][10] = $PayAmount; |
|||
} elseif (stristr($PayStage, '得合格函後6個月') || stristr($PayStage, '核可函取得後6個月')) { |
|||
$arrayData[$BillNo][11] = $PayAmount; |
|||
} else { |
|||
$arrayData[$BillNo][12] = $PayAmount; |
|||
} |
|||
} else { |
|||
$arrayData[$BillNo] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; |
|||
$arrayData[$BillNo][3] = $partnerName; |
|||
if (stristr($PayStage, '二次款') || stristr($PayStage, '出貨前') || stristr($PayStage, '簽約後') || stristr($PayStage, '簽訂後') || stristr($PayStage, '建照核發時') || stristr($PayStage, '簽約60')) { |
|||
$arrayData[$BillNo][5] = $PayAmount; |
|||
} elseif ($PayStage == '簽約' || stristr($PayStage, '簽定') || stristr($PayStage, '簽訂') || stristr($PayStage, '訂金')) { |
|||
$arrayData[$BillNo][4] = $PayAmount; |
|||
} elseif (stristr($PayStage, '貨抵工地') || stristr($PayStage, '貨底工地')) { |
|||
$arrayData[$BillNo][6] = $PayAmount; |
|||
} elseif (stristr($PayStage, '安裝')) { |
|||
$arrayData[$BillNo][7] = $PayAmount; |
|||
} elseif (stristr($PayStage, '試車')) { |
|||
$arrayData[$BillNo][8] = $PayAmount; |
|||
} elseif (stristr($PayStage, '交車') || stristr($PayStage, '完工') || stristr($PayStage, '驗收')) { |
|||
$arrayData[$BillNo][9] = $PayAmount; |
|||
} elseif (stristr($PayStage, '取得合格函') || stristr($PayStage, '取得許可函')) { |
|||
$arrayData[$BillNo][10] = $PayAmount; |
|||
} elseif (stristr($PayStage, '得合格函後6個月') || stristr($PayStage, '核可函取得後6個月')) { |
|||
$arrayData[$BillNo][11] = $PayAmount; |
|||
} else { |
|||
$arrayData[$BillNo][12] = $PayAmount; |
|||
} |
|||
} |
|||
} |
|||
foreach ($arrayData as $key => $value) { |
|||
$sql = "SELECT |
|||
tmp2.*, |
|||
d.name AS depart_name |
|||
FROM( |
|||
SELECT |
|||
a.manager, |
|||
a2.name as manager_name, |
|||
a.name, |
|||
a.department_id, |
|||
w.salesid, |
|||
w.contractno, |
|||
w.facilityno, |
|||
w.estimated_shipping_date, |
|||
w.actual_tofactory_date, |
|||
w.real_arrival_date, |
|||
w.install_end_date, |
|||
w.tryrun_end_date, |
|||
w.delivery_date |
|||
from wipwholestatus AS w |
|||
left join account AS a |
|||
ON w.salesid = a.accountid |
|||
left join account AS a2 |
|||
ON a2.accountid = a.manager |
|||
where w.status = '1' AND w.contractno='" . $key . "'" . " |
|||
|
|||
)AS tmp2 |
|||
left join ( |
|||
SELECT DISTINCT |
|||
department_id, |
|||
name |
|||
FROM department |
|||
|
|||
) AS d |
|||
ON d.department_id = tmp2.department_id"; |
|||
$facitities = ""; |
|||
|
|||
$wipwhole_array = mysqli_query($link, $sql); |
|||
foreach ($wipwhole_array as $wip) { |
|||
$value[0] = $wip['depart_name']; |
|||
$value[1] = $wip['manager_name']; |
|||
$value[2] = $wip['name']; |
|||
if ($wip['delivery_date'] != NULL) { |
|||
$facitities .= $wip['facilityno'] . "(" . $wip['delivery_date'] . "已移交);\n"; |
|||
} elseif ($wip['tryrun_end_date'] != NULL) { |
|||
$facitities .= $wip['facilityno'] . "(" . $wip['tryrun_end_date'] . "試車完畢);\n"; |
|||
} elseif ($wip['install_end_date'] != NULL) { |
|||
$facitities .= $wip['facilityno'] . "(" . $wip['install_end_date'] . "安裝完畢);\n"; |
|||
} elseif ($wip['real_arrival_date'] != NULL) { |
|||
$facitities .= $wip['facilityno'] . "(" . $wip['real_arrival_date'] . "貨抵工地);\n"; |
|||
} elseif ($wip['actual_tofactory_date'] != NULL) { |
|||
$facitities .= $wip['facilityno'] . "(" . $wip['actual_tofactory_date'] . "實際到觀音日);\n"; |
|||
} elseif ($wip['estimated_shipping_date'] != NULL) { |
|||
$facitities .= $wip['facilityno'] . "(" . $wip['estimated_shipping_date'] . "預計到港);\n"; |
|||
} else { |
|||
$facitities .= $wip['facilityno'] . "(預計到港日待確認);\n"; |
|||
} |
|||
} |
|||
echo $key . "," . $value[0] . "," . $value[1] . "," . $value[2] . "," . $value[3] . "," . $value[4] . "," . $value[5] . "," . $value[6] . "," . $value[7] . "," . $value[8] . "," . $value[9] . "," . $value[10] . "," . $value[11] . "," . $facitities . "<br>"; |
|||
} |
Loading…
Reference in new issue