|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Service;
|
|
namespace App\Service;
|
|
|
|
|
|
|
|
+use App\Exports\Exports;
|
|
use App\Model\OrdersProduct;
|
|
use App\Model\OrdersProduct;
|
|
use App\Model\OrdersProductBom;
|
|
use App\Model\OrdersProductBom;
|
|
use App\Model\OrdersProductMain;
|
|
use App\Model\OrdersProductMain;
|
|
@@ -9,6 +10,7 @@ use App\Model\OrdersProductProcess;
|
|
use App\Model\SaleOrdersProduct;
|
|
use App\Model\SaleOrdersProduct;
|
|
use App\Model\Technology;
|
|
use App\Model\Technology;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
+use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
|
|
/**
|
|
/**
|
|
* bom相关
|
|
* bom相关
|
|
@@ -246,4 +248,67 @@ class ProductionOrderService extends Service
|
|
|
|
|
|
return $result;
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function productionExport($data){
|
|
|
|
+ $model = OrdersProduct::where('del_time',0)
|
|
|
|
+ ->select('id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time','production_quantity','production_time','production_no','status','sale_orders_product_id')
|
|
|
|
+ ->orderBy('id','desc');
|
|
|
|
+
|
|
|
|
+ if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
|
|
|
|
+ if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');
|
|
|
|
+ if(! empty($data['production_no'])) $model->where('production_no', 'LIKE', '%'.$data['production_no'].'%');
|
|
|
|
+ if(! empty($data['customer_name'])) $model->where('customer_name', 'LIKE', '%'.$data['customer_name'].'%');
|
|
|
|
+ if(! empty($data['product_title'])) $model->where('product_title', 'LIKE', '%'.$data['product_title'].'%');
|
|
|
|
+ if(! empty($data['product_size'])) $model->where('product_size', 'LIKE', '%'.$data['product_size'].'%');
|
|
|
|
+ if(! empty($data['technology_material'])) $model->where('technology_material', 'LIKE', '%'.$data['technology_material'].'%');
|
|
|
|
+ if(! empty($data['technology_name'])) $model->where('technology_name', 'LIKE', '%'.$data['technology_name'].'%');
|
|
|
|
+ if(! empty($data['wood_name'])) $model->where('wood_name', 'LIKE', '%'.$data['wood_name'].'%');
|
|
|
|
+ if(! empty($data['process_mark'])) $model->where('process_mark', 'LIKE', '%'.$data['process_mark'].'%');
|
|
|
|
+ if(! empty($data['table_header_mark'])) $model->where('table_header_mark', 'LIKE', '%'.$data['table_header_mark'].'%');
|
|
|
|
+ if(! empty($data['table_body_mark'])) $model->where('table_body_mark', 'LIKE', '%'.$data['table_body_mark'].'%');
|
|
|
|
+ if(! empty($data['out_checker_man'])) $model->where('out_checker_man', 'LIKE', '%'.$data['out_checker_man'].'%');
|
|
|
|
+ if(! empty($data['out_crt_man'])) $model->where('out_crt_man', 'LIKE', '%'.$data['out_crt_man'].'%');
|
|
|
|
+ if(! empty($data['out_checker_time'][0]) && ! empty($data['out_checker_time'][1])) $model->whereBetween('out_checker_time',[$data['out_checker_time'][0],$data['out_checker_time'][1]]);
|
|
|
|
+ if(! empty($data['out_order_no_time'][0]) && ! empty($data['out_order_no_time'][1])) $model->whereBetween('out_order_no_time',[$data['out_order_no_time'][0],$data['out_order_no_time'][1]]);
|
|
|
|
+ if(! empty($data['production_time'][0]) && ! empty($data['production_time'][1])) $model->whereBetween('production_time',[$data['production_time'][0],$data['production_time'][1]]);
|
|
|
|
+ if(isset($data['status'])) $model->where('status',$data['status']);
|
|
|
|
+
|
|
|
|
+ $list = $model->get()->toArray();
|
|
|
|
+
|
|
|
|
+ //组织数据
|
|
|
|
+ $data = $this->fillExportData($list);
|
|
|
|
+
|
|
|
|
+ //保存导出数据
|
|
|
|
+ $name = $this->saveExportData($data);
|
|
|
|
+
|
|
|
|
+ return [true,$name];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function fillExportData($data){
|
|
|
|
+ if(empty($data)) return $data;
|
|
|
|
+
|
|
|
|
+ $sale_orders_product_id = array_unique(array_column($data,'sale_orders_product_id'));
|
|
|
|
+ $production_map = $this->getProductionOrderQuantity($sale_orders_product_id);
|
|
|
|
+
|
|
|
|
+ date_default_timezone_set("PRC");
|
|
|
|
+ foreach ($data as $key => $value){
|
|
|
|
+ $data[$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
|
|
|
|
+ $data[$key]['out_checker_time'] = $value['out_checker_time'] ? date('Y-m-d',$value['out_checker_time']) : '';
|
|
|
|
+ $data[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
|
|
|
|
+ $data[$key]['not_production'] = $value['order_quantity'] - ($production_map[$value['sale_orders_product_id']] ?? 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function saveExportData($data){
|
|
|
|
+ $file_name = time(). '_' . rand(1000,9999);
|
|
|
|
+ $filename = $file_name.'.' . 'xlsx';
|
|
|
|
+ $headers = [
|
|
|
|
+ ['生产订单日期','生产订单号','销售订单日期','销售订单编号','客户编码','客户名称','表头备注','产品编码','产品名称','规格型号','计量单位','订单数量','生产数量','未下生产数量','工艺/材质','工艺名称','木皮名称','加工备注','表体备注','制单人']];
|
|
|
|
+
|
|
|
|
+ $bool = Excel::store(new Exports($data,'production_order',$headers),"/public/productionOrder/{$filename}", null, 'Xlsx', []);
|
|
|
|
+
|
|
|
|
+ return $filename;
|
|
|
|
+ }
|
|
}
|
|
}
|