|
|
@@ -1550,6 +1550,99 @@ class TPlusServerService extends Service
|
|
|
$lastId = 0;
|
|
|
|
|
|
do {
|
|
|
+// $rows = $this->databaseService->table('ARAP_ReceivePayment as rp')
|
|
|
+// // 使用 leftJoin 确保主表始终存在
|
|
|
+// ->leftJoin('ARAP_ReceivePayment_b as rp_b', 'rp.ID', '=', 'rp_b.idArapReceivePaymentDTO')
|
|
|
+// // 发票子表等关联逻辑保持不变
|
|
|
+// ->leftJoin('SA_SaleInvoice_b as si_b', function ($join) {
|
|
|
+// $join->on('rp_b.voucherDetailID', '=', 'si_b.ID')
|
|
|
+// ->where('rp_b.idvouchertype', '=', 20);
|
|
|
+// })
|
|
|
+// ->leftJoin('SA_SaleInvoice as si', function ($join) {
|
|
|
+// $join->on('si_b.idSaleInvoiceDTO', '=', 'si.ID')
|
|
|
+// ->where('rp_b.idvouchertype', '=', 20);
|
|
|
+// })
|
|
|
+// ->leftJoin('SA_SaleDelivery_b as sd_b', function ($join) {
|
|
|
+// $join->on('si_b.sourceVoucherDetailId', '=', 'sd_b.ID')
|
|
|
+// ->where('rp_b.idvouchertype', '=', 20);
|
|
|
+// })
|
|
|
+// ->leftJoin('SA_SaleDelivery as sd', function ($join) {
|
|
|
+// $join->on('sd_b.idSaleDeliveryDTO', '=', 'sd.ID')
|
|
|
+// ->where('rp_b.idvouchertype', '=', 20);
|
|
|
+// })
|
|
|
+// ->leftJoin('AA_Inventory as it', 'sd_b.idinventory', '=', 'it.ID')
|
|
|
+// ->leftJoin('AA_Partner as pn', 'rp.idpartner', '=', 'pn.ID')
|
|
|
+// ->leftJoin('AA_Person as ps', 'rp.idperson', '=', 'ps.ID')
|
|
|
+// ->leftJoin('AA_Person as ps2', 'pn.idsaleman', '=', 'ps2.ID')
|
|
|
+// ->where('rp.voucherdate', '>=', $data['start_time'])
|
|
|
+// ->where('rp.voucherdate', '<=', $data['end_time'])
|
|
|
+// ->where('rp.isReceiveFlag', '=', 1)
|
|
|
+// // 核心修改:按主表 ID 进行分页过滤
|
|
|
+// ->where('rp.ID', '>', $lastId)
|
|
|
+// ->orderBy('rp.ID', 'asc')
|
|
|
+// ->limit($limit)
|
|
|
+// ->selectRaw("
|
|
|
+// COALESCE(rp.ID, 0) as order_id,
|
|
|
+// COALESCE(rp.code, '') as order_number,
|
|
|
+// rp.voucherdate as order_time,
|
|
|
+// rp.voucherstate as order_state,
|
|
|
+// COALESCE(rp.pubuserdefnvc11, '') as channel_finance,
|
|
|
+// COALESCE(rp.pubuserdefnvc12, '') as channel_details,
|
|
|
+// COALESCE(si.pubuserdefnvc12, '') as channel_details_fp,
|
|
|
+// COALESCE(pn.code, '') as customer_code,
|
|
|
+// COALESCE(pn.name, '') as customer_title,
|
|
|
+// CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(it.code, '') ELSE '' END as product_code,
|
|
|
+// CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(it.name, '') ELSE '' END as product_title,
|
|
|
+// COALESCE(rp.idperson, 0) as employee_id_1,
|
|
|
+// COALESCE(ps.name, '') as employee_id_1_title,
|
|
|
+// COALESCE(pn.idsaleman, 0) as employee_id_2,
|
|
|
+// COALESCE(ps2.name, '') as employee_id_2_title,
|
|
|
+// CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(si_b.quantity, 0) ELSE 0 END as quantity,
|
|
|
+// CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(si_b.taxPrice, 0) ELSE 0 END as price_1,
|
|
|
+// CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(si_b.taxAmount, 0) ELSE 0 END as price_1_total,
|
|
|
+// COALESCE(rp_b.origCurrentAmount, 0) as payment_amount,
|
|
|
+// COALESCE(rp_b.ID, 0) as id_detail,
|
|
|
+// COALESCE(rp_b.voucherDetailID, 0) as id_detail_upstream,
|
|
|
+// COALESCE(rp_b.voucherCode, '') as order_number_upstream,
|
|
|
+// COALESCE(rp_b.idvouchertype, 0) as voucher_type,
|
|
|
+// CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(sd.priuserdefnvc4, '') ELSE '' END as is_kh
|
|
|
+// ")
|
|
|
+// ->get();
|
|
|
+//
|
|
|
+// if ($rows->isEmpty()) break;
|
|
|
+//
|
|
|
+// $dataArray = $rows->map(function ($item) {
|
|
|
+// return (array)$item;
|
|
|
+// })->toArray();
|
|
|
+//
|
|
|
+// // 存货档案业务成本
|
|
|
+// $product_codes = array_filter(array_unique(array_column($dataArray, 'product_code')));
|
|
|
+// $product_map = [];
|
|
|
+// if (!empty($product_codes)) {
|
|
|
+// $product_map = Product::where('del_time', 0)
|
|
|
+// ->whereIn('code', $product_codes)
|
|
|
+// ->pluck('business_cost', 'code')
|
|
|
+// ->all();
|
|
|
+// }
|
|
|
+//
|
|
|
+// foreach ($dataArray as $key => $value) {
|
|
|
+// $p_tmp = $product_map[$value['product_code']] ?? 0;
|
|
|
+// $dataArray[$key]['order_type'] = RevenueCost::ORDER_THREE;
|
|
|
+// // 注意:如果 order_time 是字符串格式,strtotime 是必须的
|
|
|
+// $dataArray[$key]['order_time'] = is_numeric($value['order_time']) ? $value['order_time'] : strtotime($value['order_time']);
|
|
|
+//
|
|
|
+// $business_cost = (float)$p_tmp;
|
|
|
+// $dataArray[$key]['price_4'] = $business_cost;
|
|
|
+// $dataArray[$key]['price_4_total'] = bcmul((string)$business_cost, (string)$value['quantity'], 2);
|
|
|
+// }
|
|
|
+//
|
|
|
+// DB::table($table)->insert($dataArray);
|
|
|
+//
|
|
|
+// // 更新 lastId 为当前批次最后一条数据的【主表ID】
|
|
|
+// $lastId = end($dataArray)['order_id'];
|
|
|
+//
|
|
|
+// } while (count($rows) === $limit);
|
|
|
+
|
|
|
$rows = $this->databaseService->table('ARAP_ReceivePayment_b as rp_b')
|
|
|
->join('ARAP_ReceivePayment as rp', 'rp_b.idArapReceivePaymentDTO', '=', 'rp.ID')
|
|
|
// 发票子表关联(仅限 idvouchertype = 20)
|
|
|
@@ -1570,12 +1663,11 @@ class TPlusServerService extends Service
|
|
|
->where('rp_b.idvouchertype', '=', 20);
|
|
|
})
|
|
|
->leftJoin('AA_Inventory as it', 'sd_b.idinventory', '=', 'it.ID')
|
|
|
- ->leftJoin('AA_Partner as pn', 'si.idsettlecustomer', '=', 'pn.ID') //结算客户
|
|
|
+ ->leftJoin('AA_Partner as pn', 'rp.idpartner', '=', 'pn.ID') //结算客户
|
|
|
->leftJoin('AA_Person as ps', 'rp.idperson', '=', 'ps.ID')
|
|
|
->leftJoin('AA_Person as ps2', 'pn.idsaleman', '=', 'ps2.ID') // 结算客户的上级管理人员
|
|
|
->where('rp.voucherdate','>=',$data['start_time'])
|
|
|
->where('rp.voucherdate','<=',$data['end_time'])
|
|
|
-// ->where('priuserdefnvc4','=', 1) //.. 不计入考核 todo
|
|
|
->where('rp.isReceiveFlag','=', 1)
|
|
|
->where('rp_b.ID', '>', $lastId)
|
|
|
->orderBy('rp_b.ID')
|