|
@@ -35,6 +35,8 @@ use App\Model\MaterialReturn;
|
|
use App\Model\MaterialReturnSub;
|
|
use App\Model\MaterialReturnSub;
|
|
use App\Model\PaymentReceipt;
|
|
use App\Model\PaymentReceipt;
|
|
use App\Model\PaymentReceiptInfo;
|
|
use App\Model\PaymentReceiptInfo;
|
|
|
|
+use App\Model\PurchaseOrder;
|
|
|
|
+use App\Model\PurchaseOrderInfo;
|
|
use App\Model\RollFilm;
|
|
use App\Model\RollFilm;
|
|
use App\Model\RollFilmCombine;
|
|
use App\Model\RollFilmCombine;
|
|
use App\Model\RollFilmCompany;
|
|
use App\Model\RollFilmCompany;
|
|
@@ -43,6 +45,7 @@ use App\Model\SalesOrder;
|
|
use App\Model\SalesOrderOtherFee;
|
|
use App\Model\SalesOrderOtherFee;
|
|
use App\Model\SalesOrderProductInfo;
|
|
use App\Model\SalesOrderProductInfo;
|
|
use App\Model\Storehouse;
|
|
use App\Model\Storehouse;
|
|
|
|
+use App\Model\Supplier;
|
|
use App\Model\Transfer;
|
|
use App\Model\Transfer;
|
|
use App\Model\TransferSub;
|
|
use App\Model\TransferSub;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
@@ -65,6 +68,7 @@ class ExportFileService extends Service
|
|
self::type_two => 'two',
|
|
self::type_two => 'two',
|
|
self::type_three => 'three',
|
|
self::type_three => 'three',
|
|
self::type_four => 'four',
|
|
self::type_four => 'four',
|
|
|
|
+ self::type_five => 'five',
|
|
];
|
|
];
|
|
|
|
|
|
protected static $fuc_name = [
|
|
protected static $fuc_name = [
|
|
@@ -72,6 +76,7 @@ class ExportFileService extends Service
|
|
self::type_two => '派工订单',
|
|
self::type_two => '派工订单',
|
|
self::type_three => '收付款单',
|
|
self::type_three => '收付款单',
|
|
self::type_four => '施工单',
|
|
self::type_four => '施工单',
|
|
|
|
+ self::type_five => '采购单',
|
|
];
|
|
];
|
|
|
|
|
|
public static $filename = "";
|
|
public static $filename = "";
|
|
@@ -285,6 +290,10 @@ class ExportFileService extends Service
|
|
//分派的总社或分社
|
|
//分派的总社或分社
|
|
$dispatch = (new SalesOrderService())->getDispatchData($id);
|
|
$dispatch = (new SalesOrderService())->getDispatchData($id);
|
|
|
|
|
|
|
|
+ //金额
|
|
|
|
+ $for_amount_list = (new PaymentReceiptService())->getPaymentReceiptDataCountList(array_column($data,'order_number'),1);
|
|
|
|
+ $getDifferentAmountALL = (new ReturnExchangeOrderService())->getDifferentAmountALL(array_column($data,'id'));
|
|
|
|
+
|
|
$flag = [];
|
|
$flag = [];
|
|
foreach ($data as $value){
|
|
foreach ($data as $value){
|
|
$tmp = $invoiceData[$value->id] ?? [];
|
|
$tmp = $invoiceData[$value->id] ?? [];
|
|
@@ -320,6 +329,10 @@ class ExportFileService extends Service
|
|
'contract_fee' => "",
|
|
'contract_fee' => "",
|
|
'fee' => "",
|
|
'fee' => "",
|
|
'dispatch_company' => "",
|
|
'dispatch_company' => "",
|
|
|
|
+ 'fee1' => "",
|
|
|
|
+ 'fee2' => "",
|
|
|
|
+ 'fee3' => "",
|
|
|
|
+ 'fee4' => "",
|
|
'crt_time' => "",
|
|
'crt_time' => "",
|
|
'crt_name' => "",
|
|
'crt_name' => "",
|
|
'state_title' => "",
|
|
'state_title' => "",
|
|
@@ -336,6 +349,20 @@ class ExportFileService extends Service
|
|
];
|
|
];
|
|
}else{
|
|
}else{
|
|
$flag[] = $val['sales_order_id'];
|
|
$flag[] = $val['sales_order_id'];
|
|
|
|
+
|
|
|
|
+ $one = $for_amount_list[$value->order_number . PaymentReceipt::type_one] ?? 0;
|
|
|
|
+ $three = $for_amount_list[$value->order_number . PaymentReceipt::type_three] ?? 0;
|
|
|
|
+ $four = $for_amount_list[$value->order_number . PaymentReceipt::type_four] ?? 0;
|
|
|
|
+ $return_exchange_amount = $getDifferentAmountALL[$value->id] ?? 0;
|
|
|
|
+ //最终已收金额
|
|
|
|
+ $fee1 = round($one - $three,2);
|
|
|
|
+ //未收金额
|
|
|
|
+ $fee2 = round($value->contract_fee - $return_exchange_amount - $fee1,2);
|
|
|
|
+ //红冲金额 $three
|
|
|
|
+ $fee3 = $three;
|
|
|
|
+ //坏账金额 $four
|
|
|
|
+ $fee4 = $four;
|
|
|
|
+
|
|
$return[] = [
|
|
$return[] = [
|
|
'order_number' => $value->order_number,
|
|
'order_number' => $value->order_number,
|
|
'model_type_title' => $model_type_title,
|
|
'model_type_title' => $model_type_title,
|
|
@@ -349,6 +376,10 @@ class ExportFileService extends Service
|
|
'contract_fee' => $value->contract_fee,
|
|
'contract_fee' => $value->contract_fee,
|
|
'fee' => $fee[$value->id] ?? "",
|
|
'fee' => $fee[$value->id] ?? "",
|
|
'dispatch_company' => $dispatch[$value->id] ?? '',
|
|
'dispatch_company' => $dispatch[$value->id] ?? '',
|
|
|
|
+ 'fee1' => $fee1,
|
|
|
|
+ 'fee2' => $fee2,
|
|
|
|
+ 'fee3' => $fee3,
|
|
|
|
+ 'fee4' => $fee4,
|
|
'crt_time' => $crt_time,
|
|
'crt_time' => $crt_time,
|
|
'crt_name' => $emp_map[$value->crt_id] ?? "",
|
|
'crt_name' => $emp_map[$value->crt_id] ?? "",
|
|
'state_title' => $state,
|
|
'state_title' => $state,
|
|
@@ -368,7 +399,7 @@ class ExportFileService extends Service
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- $header = ['合同单号','销售类型','产品类型','签订时间','平台单号','平台类型','产品合计','其他费用','优惠金额','合同金额','指派金额','派遣门店','创建时间','创建人','订单状态','发货状态','发货单号','付款方式','产品名称','产品编码','产品规格','产品税率','产品单价','产品数量','产品合同金额'];
|
|
|
|
|
|
+ $header = ['合同单号','销售类型','产品类型','签订时间','平台单号','平台类型','产品合计','其他费用','优惠金额','合同金额','指派金额','派遣门店','已收金额','未收金额','红冲金额','坏账金额','创建时间','创建人','订单状态','发货状态','发货单号','付款方式','产品名称','产品编码','产品规格','产品税率','产品单价','产品数量','产品合同金额'];
|
|
|
|
|
|
return $this->saveExportData($return,$header);
|
|
return $this->saveExportData($return,$header);
|
|
}
|
|
}
|
|
@@ -578,6 +609,110 @@ class ExportFileService extends Service
|
|
return $this->saveExportData($return,$header);
|
|
return $this->saveExportData($return,$header);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function five($ergs){
|
|
|
|
+ $id = $ergs['id'];
|
|
|
|
+
|
|
|
|
+ // 导出数据
|
|
|
|
+ $return = [];
|
|
|
|
+
|
|
|
|
+ DB::table('purchase_order')
|
|
|
|
+ ->whereIn('id', $id)
|
|
|
|
+ ->select('order_number','id','depart_id','top_depart_id','mark','crt_time','state','crt_id','order_type','sales_order_id','supplier','purchase_id','purchase_total','discount_fee','other_fee','total','storehouse_id')
|
|
|
|
+ ->orderBy('id','desc')
|
|
|
|
+ ->chunk(500,function ($data) use(&$return){
|
|
|
|
+ $data = $data->toArray();
|
|
|
|
+ $array = array_unique(array_merge_recursive(array_column($data,'crt_id'),array_column($data,'purchase_id')));
|
|
|
|
+ $emp_map = Employee::whereIn('id',$array)
|
|
|
|
+ ->pluck('emp_name','id')
|
|
|
|
+ ->toArray();
|
|
|
|
+
|
|
|
|
+ $sales = SalesOrder::whereIn('id',array_unique(array_column($data,'sales_order_id')))->pluck('order_number','id')->toArray();
|
|
|
|
+
|
|
|
|
+ $supplier = Supplier::whereIn('id',array_unique(array_column($data,'supplier')))
|
|
|
|
+ ->pluck('title','id')
|
|
|
|
+ ->toArray();
|
|
|
|
+
|
|
|
|
+ $product = [];
|
|
|
|
+ $p_info = PurchaseOrderInfo::where('del_time',0)->whereIn('purchase_order_id',array_unique(array_column($data,'id')))
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $map = (new ProductService())->getProductDetail(array_column($p_info,'product_id'));
|
|
|
|
+ foreach ($p_info as $value){
|
|
|
|
+ $tmp = $map[$value['product_id']] ?? [];
|
|
|
|
+ $value['title'] = $tmp['title'] ?? "";
|
|
|
|
+ $value['code'] = $tmp['code'] ?? "";
|
|
|
|
+ $value['size'] = $tmp['size'] ?? "";
|
|
|
|
+ $value['unit'] = $tmp['unit'] ?? "";
|
|
|
|
+ $value['bar_code'] = $tmp['bar_code'] ?? "";
|
|
|
|
+ $product[$value['purchase_order_id']][] = $value;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取发货信息
|
|
|
|
+ $invoice_map = (new InvoiceOrderService())->getInvoiceData($data);
|
|
|
|
+
|
|
|
|
+ $flag = [];
|
|
|
|
+ foreach ($data as $value){
|
|
|
|
+ $tmp_supplier = $supplier[$value->supplier] ?? "";
|
|
|
|
+ $crt_name = $emp_map[$value->crt_id] ?? "";
|
|
|
|
+ $purchase_name = $emp_map[$value->purchase_id] ?? "";
|
|
|
|
+ $sales_order = $sales[$value->sales_order_id] ?? "";
|
|
|
|
+ $crt_time = empty($value->crt_time) ? '' : date('Y-m-d',$value->crt_time);
|
|
|
|
+ //发货信息
|
|
|
|
+ $state_title = PurchaseOrder::$name[$value->state] ?? '';
|
|
|
|
+ $invoice_state = "未发货";
|
|
|
|
+ if(! empty($invoice_map[$value->order_number])) $invoice_state = implode(',',$invoice_map[$value->order_number]);
|
|
|
|
+ $state_message = "订单状态:" . $state_title . "\n"."是否发货:" . $invoice_state;
|
|
|
|
+ $product_tmp = $product[$value->id] ?? [];
|
|
|
|
+
|
|
|
|
+ foreach ($product_tmp as $val){
|
|
|
|
+ if(in_array($val['purchase_order_id'], $flag)){
|
|
|
|
+ $return[] = [
|
|
|
|
+ 'order_number' => "",
|
|
|
|
+ 'sales_order_number' => "",
|
|
|
|
+ 'purchase_name' => "",
|
|
|
|
+ 'product_total' => "",
|
|
|
|
+ 'supplier' => "",
|
|
|
|
+ 'purchase_amount' => "",
|
|
|
|
+ 'other_fee' => "",
|
|
|
|
+ 'discount_fee' => "",
|
|
|
|
+ 'state_title' => "",
|
|
|
|
+ 'crt_time' => "",
|
|
|
|
+ 'crt_name' => "",
|
|
|
|
+ 'product_title' => $val['title'],
|
|
|
|
+ 'product_code' => $val['code'],
|
|
|
|
+ 'product_size' => $val['size'],
|
|
|
|
+ 'product_price' => $val['price'],
|
|
|
|
+ 'product_num' => $val['number'],
|
|
|
|
+ ];
|
|
|
|
+ }else{
|
|
|
|
+ $flag[] = $val['purchase_order_id'];
|
|
|
|
+ $return[] = [
|
|
|
|
+ 'order_number' => $value->order_number,
|
|
|
|
+ 'sales_order_number' => $sales_order,
|
|
|
|
+ 'purchase_name' => $purchase_name,
|
|
|
|
+ 'product_total' => $value->total,
|
|
|
|
+ 'supplier' => $tmp_supplier,
|
|
|
|
+ 'purchase_amount' => $value->purchase_total,
|
|
|
|
+ 'other_fee' => $value->other_fee,
|
|
|
|
+ 'discount_fee' => $value->discount_fee,
|
|
|
|
+ 'state_title' => $state_message,
|
|
|
|
+ 'crt_time' => $crt_time,
|
|
|
|
+ 'crt_name' => $crt_name,
|
|
|
|
+ 'product_title' => $val['title'],
|
|
|
|
+ 'product_code' => $val['code'],
|
|
|
|
+ 'product_size' => $val['size'],
|
|
|
|
+ 'product_price' => $val['price'],
|
|
|
|
+ 'product_num' => $val['number'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ $header = ['采购单号','关联单号','采购人','产品合计','供应商','采购金额','其他费用','优惠金额','状态','创建时间','创建人','产品名称','产品编码','产品规格','产品单价','产品数量'];
|
|
|
|
+
|
|
|
|
+ return $this->saveExportData($return,$header);
|
|
|
|
+ }
|
|
|
|
+
|
|
public function saveExportData($data, $headers, $type = 'default',$file_name = ''){
|
|
public function saveExportData($data, $headers, $type = 'default',$file_name = ''){
|
|
if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
|
|
if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
|
|
$filename = $file_name . '.' . 'xlsx';
|
|
$filename = $file_name . '.' . 'xlsx';
|