trippest 单团财务表;+判断火车票,酒店,包价线路是否已生成项目报表,是则更新,否则新增

feature/pay
lyt 7 years ago
parent 969c8514e6
commit 3abe72fe57

@ -45,11 +45,6 @@ class Order_finance extends CI_Controller {
return $this->generate_report($order_info);
}
public function regenerate_report($coli_sn=0)
{
return $this->generate_report($order_info, TRUE);
}
/*!
* 单团财务表计算
* @date 2018-07-18
@ -64,7 +59,7 @@ class Order_finance extends CI_Controller {
* * * 写入单团财务表report_order
* END
*/
public function generate_report($order_info=array(), $update_flag=false)
public function generate_report($order_info=array())
{
$coli_sn = $order_info->COLI_SN;
/** 单团财务表 */
@ -196,11 +191,11 @@ class Order_finance extends CI_Controller {
}
/** 开始写入数据库 */
/** 图兰朵供应商 */
$this->OrderFinance_model->insert_report_tour_tulanduo($ret->report_tour, $update_flag);
$this->OrderFinance_model->insert_report_tour_tulanduo($ret->report_tour);
/** 非图兰朵供应商的包价线路产品 */
$other_tour = $this->OrderFinance_model->get_order_detail($coli_sn, 'D', false);
if ( ! empty($other_tour)) {
$ret->others = $this->OrderFinance_model->insert_report_tour_others($coli_sn, $update_flag);
$ret->others = $this->OrderFinance_model->insert_report_tour_others($coli_sn);
foreach ($ret->others as $kro => $vro) {
// $report_order['basemoney'] = bcadd($report_order['basemoney'], $vro->tourcost);
// test
@ -210,7 +205,7 @@ class Order_finance extends CI_Controller {
/** 火车票预定 */
$train_detail = $this->OrderFinance_model->get_order_detail($coli_sn, '2');
if( ! empty($train_detail)) {
$ret->train = $this->OrderFinance_model->insert_report_train($coli_sn, $update_flag);
$ret->train = $this->OrderFinance_model->insert_report_train($coli_sn);
foreach ($ret->train as $krt => $vrt) {
// $report_order['basemoney'] = bcadd($report_order['basemoney'], $vrt->TotalCost);
// test
@ -220,7 +215,7 @@ class Order_finance extends CI_Controller {
/** 酒店预订 */
$hotel_detail = $this->OrderFinance_model->get_order_detail($coli_sn, 'A');
if ( ! empty($hotel_detail)) {
$ret->hotel = $this->OrderFinance_model->insert_report_hotel($coli_sn, $update_flag);
$ret->hotel = $this->OrderFinance_model->insert_report_hotel($coli_sn);
foreach ($ret->hotel as $krh => $vrh) {
// $report_order['basemoney'] = bcadd($report_order['basemoney'], $vrh->roomcost);
// test
@ -231,7 +226,7 @@ class Order_finance extends CI_Controller {
$report_order['profitmoney'] = $report_order['OrderYJLR'] = bcsub($report_order['money'], $report_order['basemoney']);
$report_order['builddate'] = date('Y-m-d H:i:s');
$report_order['xh'] = $this->OrderFinance_model->get_report_order_xh(); //序号
$ret->report_order = $this->OrderFinance_model->insert_report_order($report_order, $update_flag);
$ret->report_order = $this->OrderFinance_model->insert_report_order($report_order, $coli_sn, $report_order['RO_GRI_SN']);
$this->output->set_content_type('application/json')->set_output(json_encode($ret));
return;

@ -175,12 +175,38 @@ class OrderFinance_model extends CI_Model {
return $ret;
}
/** 判断各种项目的报表是否已存在 */
public function report_tour_exists($coli_id=null, $tourCode=null)
{
$sql = "SELECT top 1 ordernumber from report_tour where ordernumber=? and tourCode=?";
$num_rows = $this->HT->query($sql, array($coli_id, $tourCode))->num_rows();
return $num_rows>0;
}
public function report_train_exists($coli_id=null, $TrainNo=null)
{
$sql = "SELECT top 1 OrderNumber from report_Train where OrderNumber=? and TrainNo=?";
$num_rows = $this->HT->query($sql, array($coli_id, $TrainNo))->num_rows();
return $num_rows>0;
}
public function report_room_exists($coli_id=null, $hotelName=null)
{
$sql = "SELECT top 1 ordernumber from report_room where ordernumber=? and hotelName=?";
$num_rows = $this->HT->query($sql, array($coli_id, $hotelName))->num_rows();
return $num_rows>0;
}
public function report_order_exists($coli_id=null, $gri_sn=null)
{
$sql = "SELECT top 1 ordernumber from report_order where ordernumber=? and ro_gri_sn=?";
$num_rows = $this->HT->query($sql, array($coli_id, $gri_sn))->num_rows();
return $num_rows>0;
}
/** 图兰朵包价线路产品 */
public function insert_report_tour_tulanduo($report_tour_arr=array(), $update_flag=false)
public function insert_report_tour_tulanduo($report_tour_arr=array())
{
$this->HT2 = $this->load->database('INFO', TRUE); // test
foreach ($report_tour_arr as $krt => $vrt) {
if ($update_flag === TRUE) {
if ($this->report_tour_exists($vrt['ordernumber'], $vrt['tourCode']) === TRUE) {
$where = " ordernumber='" . $vrt['ordernumber'] . "' AND tourCode='" . $vrt['tourCode'] . "'";
$update_sql = $this->HT2->update_string('tourmanager.dbo.Report_Tour', $vrt, $where);
$this->HT2->query($update_sql);
@ -192,55 +218,20 @@ $this->HT2 = $this->load->database('INFO', TRUE); // test
}
/** 火车票 */
public function insert_report_train($coli_sn=0, $update_flag=false)
{
if ($update_flag === TRUE) {
return $this->update_report_train($coli_sn);
}
// INSERT INTO report_Train(
// OrderNumber,
// TrainNo,
// DepartureCity,
// ArrivalCity,
// DepartureDate,
// PassengerNo,
// adultPrice,
// TotalCost,
// TotalPrice,
// TrainProvide,
// TrainBZ,
// orderstats)
$sql = "SELECT
dbo.BIZ_ConfirmLineInfo.COLI_ID,
FlightsNo,
DepartureCity,
ArrivalCity,
left(convert(varchar,DepartureDate,120),10) as DepartureDate1,
isnull(COLD_PersonNum,0)+ISNULL(COLD_ChildNum,0) as PersonNum,
adultcost,
COLD_TotalCost as TotalCost,
COLD_TotalPrice*6.77 as TotalPrice, --test
VEI2_CompanyBN,
' ' as TrainBZ, -- test
-- case when dbo.GetBIZTrainVEIDebt(COLD_SN)='YES' then '挂账' else ' ' end as TrainBZ,
0 as stat
from BIZ_ConfirmLineDetail
inner join BIZ_ConfirmLineInfo on COLI_SN=COLD_COLI_SN
inner join BIZ_FlightsOrderInfo on FOI_COLD_SN = COLD_SN
left join VEndorInfo2 on COLD_PlanVEI_SN = VEI2_VEI_SN and VEI2_LGC = 2
where COLD_COLI_SN = $coli_sn
and isnull(BIZ_ConfirmLineDetail.DeleteFlag,0)=0
and COLD_ServiceType = '2' ";
return $this->HT->query($sql)->result();
// return $this->HT->query("SELECT top 1 * from tourmanager.dbo.report_Train inner join BIZ_ConfirmLineInfo on COLI_ID=OrderNumber WHERE COLI_SN=$coli_sn order by OrderID desc")->row();
}
public function update_report_train($coli_sn=0)
public function insert_report_train($coli_sn=0)
{
$this->HT2 = $this->load->database('INFO', TRUE); // test
$update_data = $this->get_train_cost($coli_sn);
$where = " OrderNumber='" . $update_data->OrderNumber . "' AND TrainNo='" . $update_data->TrainNo . "' ";
$update_sql = $this->HT2->update_string('tourmanager.dbo.report_Train', $update_data, $where);
return $this->HT2->query($update_sql);
$train_cost = $this->get_train_cost($coli_sn);
foreach ($train_cost as $ktc => $vtc) {
if ($this->report_train_exists($vtc->OrderNumber, $vtc->TrainNo) === TRUE) {
$where = " OrderNumber='" . $vtc->OrderNumber . "' AND TrainNo='" . $vtc->TrainNo . "' ";
$update_sql = $this->HT2->update_string('tourmanager.dbo.report_Train', json_decode(json_encode($vtc), TRUE), $where);
$this->HT2->query($update_sql);
} else {
$this->HT2->insert('tourmanager.dbo.report_Train', json_decode(json_encode($vtc), TRUE));
}
}
return $this->HT2->query("SELECT * from tourmanager.dbo.report_Train inner join BIZ_ConfirmLineInfo on COLI_ID=OrderNumber WHERE COLI_SN=$coli_sn order by OrderID desc")->result();
}
public function get_train_cost($coli_sn=0)
{
@ -265,64 +256,24 @@ $this->HT2 = $this->load->database('INFO', TRUE); // test
where COLD_COLI_SN = $coli_sn
and isnull(BIZ_ConfirmLineDetail.DeleteFlag,0)=0
and COLD_ServiceType = '2' ";
return $this->HT->query($sql)->row();
return $this->HT->query($sql)->result();
}
/** 酒店 */
public function insert_report_hotel($coli_sn=0, $update_flag=false)
{
if ($update_flag === TRUE) {
return $this->update_report_hotel($coli_sn);
}
// INSERT INTO report_room( ordernumber, hotelName, cityName, hotelStar, roomtype, starttime, endtime, roomnumber, ExtraBedNumber, jianyeshu, jianyecost, ExtraBedCost, ExtraBedPrice, roomcost, roomprice, roomprofit, roomprovide, roombz, orderstats)
$sql = "
SELECT coli_id,
v2.VEI2_CompanyBN AS HotelName,
cityinfo2.CII2_Name AS cityname,
(SELECT SGC_ServiceGrade
FROM servicegradecode2
WHERE SGC2_LGC=2
AND SGC2_SGC_SN=Isnull(VEI_Grade,-1)) AS HStar,
(SELECT ROT2_TypeName
FROM roomtype2
WHERE ROT2_ROT_SN=ISNULL(COLD_ServiceSN2,-1)
AND ROT2_LGC=1) AS RoomType,
left(convert(varchar,COLD_StartDate,120),10) AS COLD_StartDate,
left(convert(varchar,COLD_EndDate,120),10) AS COLD_EndDate,
COLD_Count,
isnull(HOI_ExtraNum,0) AS HOI_ExtraNum,
COLD_DayCount=DATEDIFF(DAY,COLD_StartDate,COLD_EndDate),
COLD_TotalCost, -- test
-- COLD_TotalCost*1.0/dbo.ZeroToOne(DATEDIFF(DAY,COLD_StartDate,COLD_EndDate)),
0 as ExtraBedCost,
0 as ExtraBedPrice,
COLD_TotalCost,
COLD_TotalPrice*6.77 as COLD_TotalPrice,
(COLD_TotalPrice/1.03*6.77)-COLD_TotalCost as roomprofit,
VendorInfo2.VEI2_CompanyBN AS PlantVEI,
COLD_Describe,
0 as stat
FROM BIZ_ConfirmLineDetail
INNER JOIN BIZ_ConfirmLineInfo ON COLD_COLI_SN=COLI_SN
LEFT JOIN BIZ_HotelOrderInfo ON HOI_COLD_SN = COLD_SN
LEFT JOIN VEndorInfo2 ON COLD_PlanVEI_SN = VEI2_VEI_SN AND VEI2_LGC = 2
LEFT JOIN Vendorinfo2 AS V2 ON COLD_ServiceSN = V2.VEI2_VEI_SN AND V2.VEI2_LGC = 2
LEFT JOIN VendorInfo ON COLD_ServiceSN = VEI_SN
LEFT JOIN cityinfo2 ON vendorinfo.VEI_CII_Name=cityinfo2.CII2_CII_SN AND cityinfo2.CII2_LGC=2
WHERE COLD_COLI_SN = $coli_sn
AND BIZ_ConfirmLineDetail.DeleteFlag = 0
AND COLD_ServiceType = 'A'
";
return $this->HT->query($sql)->result();
// return $this->HT->query("SELECT top 1 * from tourmanager.dbo.report_room inner join BIZ_ConfirmLineInfo on COLI_ID=ordernumber WHERE COLI_SN=$coli_sn order by orderId desc")->row();
}
public function update_report_hotel($coli_sn)
public function insert_report_hotel($coli_sn=0)
{
$this->HT2 = $this->load->database('INFO', TRUE); // test
$update_data = $this->get_hotel_cost($coli_sn);
$where = " ordernumber='" . $update_data->ordernumber . "' AND hotelName='" . $update_data->hotelName . "' ";
$update_sql = $this->HT2->update_string('tourmanager.dbo.report_room', $update_data, $where);
return $this->HT2->query($update_sql);
$hotel_cost = $this->get_hotel_cost($coli_sn);
foreach ($hotel_cost as $khc => $vhc) {
if ($this->report_room_exists($vhc->ordernumber, $vhc->hotelName) === TRUE) {
$where = " ordernumber='" . $vhc->ordernumber . "' AND hotelName='" . $vhc->hotelName . "' ";
$update_sql = $this->HT2->update_string('tourmanager.dbo.report_room', json_decode(json_encode($vhc), TRUE), $where);
$this->HT2->query($update_sql);
} else {
$this->HT2->insert('tourmanager.dbo.report_room', json_decode(json_encode($vhc), TRUE));
}
}
return $this->HT2->query("SELECT * from tourmanager.dbo.report_room inner join BIZ_ConfirmLineInfo on COLI_ID=ordernumber WHERE COLI_SN=$coli_sn order by orderId desc")->result();
}
public function get_hotel_cost($coli_sn)
{
@ -364,88 +315,24 @@ $this->HT2 = $this->load->database('INFO', TRUE); // test
AND BIZ_ConfirmLineDetail.DeleteFlag = 0
AND COLD_ServiceType = 'A'
";
return $this->HT->query($sql)->row();
return $this->HT->query($sql)->result();
}
/** 非图兰朵供应商的包价线路产品 */
public function insert_report_tour_others($coli_sn=0, $update_flag=false)
public function insert_report_tour_others($coli_sn=0)
{
if ($update_flag === TRUE) {
return $this->update_report_tour_others($coli_sn);
}
// INSERT INTO report_tour(
// ordernumber,
// tourCode,
// tourname,
// tourtime,
// tourRSd,
// tourRSx,
// tourCostRsd,
// tourCostRSx,
// tourcost,
// tourPrice,
// tourProfit,
// tourProvide,
// tourBZ,
// orderstats)
$sql = "SELECT
dbo.BIZ_ConfirmLineInfo.COLI_ID,
dbo.BIZ_PackageInfo.PAG_Code,
dbo.BIZ_PackageInfo.PAG_Title,
SUBSTRING(CONVERT(varchar,dbo.BIZ_ConfirmLineDetail.COLD_StartDate, 120), 1, 10) AS COLD_StartDate,
dbo.BIZ_ConfirmLineDetail.COLD_PersonNum,
dbo.BIZ_ConfirmLineDetail.COLD_ChildNum,
--@AdultCost,
(select top 1 PKP_AdultCost
from BIZ_PackagePrice
where PKP_PAG_SN=COLD_ServiceSN
and PKP_VEI_SN=COLD_PlanVEI_SN
and PKP_PersonStart<=isnull(COLD_PersonNum,0)+isnull(COLD_ChildNum,0)
and PKP_PersonStop >=isnull(COLD_PersonNum,0)+isnull(COLD_ChildNum,0)
and PKP_ValidDate <= CONVERT(varchar(100),COLD_StartDate,23)
and PKP_InvalidDate >= CONVERT(varchar(100),COLD_StartDate,23)
ORDER BY PKP_PriceGrade
) as AdultCost,
--@ChildCost,
(select top 1 PKP_ChildCost
from BIZ_PackagePrice
where PKP_PAG_SN=COLD_ServiceSN
and PKP_VEI_SN=COLD_PlanVEI_SN
and PKP_PersonStart<=isnull(COLD_PersonNum,0)+isnull(COLD_ChildNum,0)
and PKP_PersonStop >=isnull(COLD_PersonNum,0)+isnull(COLD_ChildNum,0)
and PKP_ValidDate <= CONVERT(varchar(100),COLD_StartDate,23)
and PKP_InvalidDate >= CONVERT(varchar(100),COLD_StartDate,23)
ORDER BY PKP_PriceGrade
) as ChildCost,
dbo.BIZ_ConfirmLineDetail.COLD_TotalCost,
-- dbo.ConvertToRMB('USD',dbo.BIZ_ConfirmLineDetail.COLD_TotalPrice) COLD_TotalPrice,
-- dbo.ConvertToRMB('USD',dbo.BIZ_ConfirmLineDetail.COLD_TotalPrice)-dbo.BIZ_ConfirmLineDetail.COLD_TotalCost as COLD_Profit,
dbo.BIZ_ConfirmLineDetail.COLD_TotalPrice*6.77 COLD_TotalPrice,
(dbo.BIZ_ConfirmLineDetail.COLD_TotalPrice*6.77)-dbo.BIZ_ConfirmLineDetail.COLD_TotalCost as COLD_Profit,
isnull(dbo.VEndorInfo2.VEI2_CompanyBN,'.') as VEI2_CompanyN,
SUBSTRING(dbo.BIZ_ConfirmLineDetail.COLD_Describe,1,70) as COLD_Describe1,
0 as stat
FROM dbo.BIZ_ConfirmLineDetail
inner join BIZ_ConfirmLineInfo on COLI_SN=COLD_COLI_SN
LEFT OUTER JOIN dbo.VEndorInfo2 ON dbo.VEndorInfo2.VEI2_VEI_SN = dbo.BIZ_ConfirmLineDetail.COLD_PlanVEI_SN AND dbo.VEndorInfo2.VEI2_LGC = 2
INNER JOIN dbo.BIZ_PackageInfo ON dbo.BIZ_ConfirmLineDetail.COLD_ServiceSN = dbo.BIZ_PackageInfo.PAG_SN
WHERE (dbo.BIZ_ConfirmLineDetail.COLD_ServiceType='D')
AND (dbo.BIZ_ConfirmLineDetail.DeleteFlag = 0)
AND (dbo.BIZ_ConfirmLineDetail.COLD_COLI_SN=$coli_sn)
and dbo.BIZ_ConfirmLineDetail.COLD_PlanVEI_SN not in (1343,29188,30548,30016) ";
return $this->HT->query($sql)->result();
// return $this->HT->query("SELECT top 1 * from tourmanager.dbo.report_tour inner join BIZ_ConfirmLineInfo on COLI_ID=ordernumber WHERE COLI_SN=$coli_sn order by orderId desc")->row();
// $this->HT->query($sql);
$other_tour_cost = $this->get_report_tour_others_cost($coli_sn);
foreach ($other_tour_cost as $kotc => $votc) {
if ($this->report_tour_exists($votc->ordernumber, $votc->tourCode) === TRUE) {
$where = " ordernumber='" . $votc->ordernumber . "' AND tourCode='" . $votc->tourCode . "'";
$update_sql = $this->HT2->update_string('tourmanager.dbo.Report_Tour', json_decode(json_encode($votc), TRUE), $where);
$this->HT2->query($update_sql);
} else {
$this->HT2->insert('tourmanager.dbo.Report_Tour', json_decode(json_encode($votc), TRUE));
}
return TRUE;
}
public function update_report_tour_others($coli_sn)
{
$this->HT2 = $this->load->database('INFO', TRUE); // test
$update_data = $this->get_report_tour_others_cost($coli_sn);
$where = " ordernumber='" . $update_data->ordernumber . "' AND tourCode='" . $update_data->tourCode . "' ";
$update_sql = $this->HT2->update_string('tourmanager.dbo.report_tour', $update_data, $where);
return $this->HT2->query($update_sql);
}
return $this->HT->query("SELECT top 1 * from tourmanager.dbo.report_tour inner join BIZ_ConfirmLineInfo on COLI_ID=ordernumber WHERE COLI_SN=$coli_sn order by orderId desc")->result();
}
public function get_report_tour_others_cost($coli_sn=0)
{
@ -494,21 +381,21 @@ $this->HT2 = $this->load->database('INFO', TRUE); // test
AND (dbo.BIZ_ConfirmLineDetail.DeleteFlag = 0)
AND (dbo.BIZ_ConfirmLineDetail.COLD_COLI_SN=$coli_sn)
and dbo.BIZ_ConfirmLineDetail.COLD_PlanVEI_SN not in (1343,29188,30548,30016) ";
return $this->HT->query($sql)->row();
return $this->HT->query($sql)->result();
}
public function insert_report_order($report_order_arr=array(), $update_flag=false)
/** 单团财务表 */
public function insert_report_order($report_order_arr=array(), $coli_sn=0, $gri_sn=0)
{
$this->HT2 = $this->load->database('INFO', TRUE); // test
if ($update_flag === TRUE) {
if ( $this->report_order_exists($coli_sn, $gri_sn) === TRUE ) {
$where = " ordernumber='" . $report_order_arr['ordernumber'] . "' ";
$update_sql = $this->HT2->update_string('tourmanager.dbo.report_order', $report_order_arr, $where);
$this->HT2->query($update_sql);
} else {
$this->HT2->insert('tourmanager.dbo.report_order', $report_order_arr);
}
$this->HT2->insert('tourmanager.dbo.report_order', $report_order_arr);
return $this->HT2->query("SELECT top 1 * from tourmanager.dbo.report_order WHERE ordernumber=? order by orderID desc",
array($report_order_arr['ordernumber']))->row();
// return TRUE;
return $this->get_report_order($report_order_arr['ordernumber']);
}
public function get_report_order($coli_id=0)

Loading…
Cancel
Save