cqp 1 周之前
父節點
當前提交
1faae93c51
共有 1 個文件被更改,包括 52 次插入12 次删除
  1. 52 12
      app/Service/TPlusServerService.php

+ 52 - 12
app/Service/TPlusServerService.php

@@ -441,9 +441,22 @@ class TPlusServerService extends Service
             do {
                 $rows = $this->databaseService->table('ARAP_ReceivePayment_b as rp_b')
                     ->join('ARAP_ReceivePayment as rp', 'rp_b.idArapReceivePaymentDTO', '=', 'rp.ID')
-                    ->leftJoin('SA_SaleInvoice_b as si_b', 'rp_b.voucherDetailID', '=', 'si_b.ID')
-                    ->leftJoin('SA_SaleInvoice as si', 'si_b.idSaleInvoiceDTO', '=', 'si.ID')
-                    ->leftJoin('SA_SaleDelivery_b as sd_b', 'si_b.sourceVoucherDetailId', '=', 'sd_b.ID')
+//                    ->leftJoin('SA_SaleInvoice_b as si_b', 'rp_b.voucherDetailID', '=', 'si_b.ID')
+//                    ->leftJoin('SA_SaleInvoice as si', 'si_b.idSaleInvoiceDTO', '=', 'si.ID')
+//                    ->leftJoin('SA_SaleDelivery_b as sd_b', 'si_b.sourceVoucherDetailId', '=', 'sd_b.ID')
+                    // 发票子表关联(仅限 idvouchertype = 20)
+                    ->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('AA_Partner as pn', 'si.idsettlecustomer', '=', 'pn.ID')
                     ->leftJoin('AA_Person as ps', 'rp.idperson', '=', 'ps.ID')
                     ->leftJoin('AA_Person as ps2', 'pn.idsaleman', '=', 'ps2.ID')
@@ -451,11 +464,35 @@ class TPlusServerService extends Service
                     ->leftJoin('AA_Unit as ui', 'si_b.idbaseunit', '=', 'ui.ID')
                     ->where('rp.voucherdate','>=',$data['start_time'])
                     ->where('rp.voucherdate','<=',$data['end_time'])
-                    ->where('rp_b.idvouchertype','=', 20) // 销售发票
+//                    ->where('rp_b.idvouchertype','=', 20) // 销售发票
                     ->where('rp.isReceiveFlag','=', 1)
                     ->where('rp_b.ID', '>', $lastId)
                     ->orderBy('rp_b.ID')
                     ->limit($limit)
+//                    ->selectRaw("
+//                        COALESCE(rp.ID, 0) as order_id,
+//                        COALESCE(rp.code, '') as order_number,
+//                        rp.voucherdate as order_time,
+//                        COALESCE(pn.code, '') as customer_code,
+//                        COALESCE(pn.name, '') as customer_title,
+//                        COALESCE(pn.priuserdefnvc14, '') as customer_profit_rate,
+//                        COALESCE(it.code, '') as product_code,
+//                        COALESCE(it.name, '') 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,
+//                        COALESCE(it.specification, '') as product_size,
+//                        COALESCE(ui.name, '') as unit,
+//                        COALESCE(si_b.quantity, 0) as quantity,
+//                        COALESCE(si_b.taxPrice, 0) as price_1,
+//                        COALESCE(si_b.taxAmount, 0) as price_1_total,
+//                        COALESCE(rp_b.amount, 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(sd_b.pubuserdefdecm9, 0) as is_activity
+//                    ")
                     ->selectRaw("
                         COALESCE(rp.ID, 0) as order_id,
                         COALESCE(rp.code, '') as order_number,
@@ -463,22 +500,23 @@ class TPlusServerService extends Service
                         COALESCE(pn.code, '') as customer_code,
                         COALESCE(pn.name, '') as customer_title,
                         COALESCE(pn.priuserdefnvc14, '') as customer_profit_rate,
-                        COALESCE(it.code, '') as product_code,
-                        COALESCE(it.name, '') as product_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,
-                        COALESCE(it.specification, '') as product_size,
-                        COALESCE(ui.name, '') as unit,
-                        COALESCE(si_b.quantity, 0) as quantity,
-                        COALESCE(si_b.taxPrice, 0) as price_1,
-                        COALESCE(si_b.taxAmount, 0) as price_1_total,
+                        CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(it.specification, '') ELSE '' END as product_size,
+                        CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(ui.name, '') ELSE '' END as unit,
+                        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.amount, 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(sd_b.pubuserdefdecm9, 0) as is_activity
+                        CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(sd_b.pubuserdefdecm9, 0) ELSE 0 END as is_activity,
+                        rp_b.idvouchertype as voucher_type
                     ")
                     ->get();
 
@@ -594,6 +632,7 @@ class TPlusServerService extends Service
                             'order_number_upstream' => $item->order_number_upstream ?? "",
                             'is_activity' => $item->is_activity ?? 0,
                             'customer_profit_rate' => $item->customer_profit_rate ?? '',
+                            'voucher_type' => $item->voucher_type ?? 0,
                             'crt_time' => $time,
                         ];
                     })->toArray();
@@ -736,6 +775,7 @@ class TPlusServerService extends Service
                 $table->string('order_number_upstream', 100)->nullable();
                 $table->decimal('is_activity', 2, 0)->default(0);
                 $table->string('customer_profit_rate', 20)->default('');
+                $table->bigInteger('voucher_type')->default(0);
             });
         }
     }