wugg 2 years ago
parent
commit
290fd14999
4 changed files with 187 additions and 1 deletions
  1. 120 0
      app/admin/controller/OrderInv.php
  2. 3 0
      app/admin/route/app.php
  3. 63 0
      app/common.php
  4. 1 1
      composer.lock

+ 120 - 0
app/admin/controller/OrderInv.php

@@ -1949,4 +1949,124 @@ class OrderInv extends BaseController{
     	 }
     	 return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
     }
+
+    public function downorder(){
+    	$post=$this->request->only(["invNo"=>[]],"post","trim");
+    	 $condition=[["open_type","in",[2,3]],["is_del","=",0],["status","=",0]];
+        if(!empty($post['invNo'])){
+            $condition[]=['invNo',"in",$post['invNo']];
+        }
+      $invice = Db::name("invoice_pool")->where($condition)->select()->toArray();
+        if (empty($invice)){
+            return error_show(1003,"未找到数据");
+        }
+      $data=[];
+      foreach ($invice as $value){
+          $temp=[];
+         $orderNo = Db::name("assoc")->where([["status","=",1],["is_del","=",0],['viceNo',"=",$value['invNo']]])
+         ->find();
+         if(!$orderNo){
+             continue;
+         }
+
+         $good = Db::name("qrd_info")->where([['sequenceNo',"=",$orderNo['orderCode']],["status","=",1]])
+         ->findOrEmpty();
+        if(empty($good)){
+           continue;
+        }
+        if(isset($value['inv_out'])&& $value['inv_out']!=''){
+            $invout = Db::name("company_info")->where([['companyNo',"=",$value['inv_out']]])->find();
+        }
+        $invinfo = Db::name("invoice_pool_info")->where("invNo","=",$value['invNo'])->findOrEmpty();
+
+//       foreach ($good as $val){
+//         $qrd = Db::name("qrd_list")->where("sequenceNo","=",$val['goodNo'])->find();
+         $temp['invNo'] = $value['invNo'];
+         $temp['qrdNo'] = $orderNo['orderCode'];
+         $temp['depart'] = $good['department'];
+         $temp['apply_name'] =$value['apply_name'];
+         $temp['code'] ="";
+         $temp['invoice_title'] =$invinfo['buyer_title']??"";
+         $temp['invoice_code'] =$invinfo['buyer_code']." ";
+         $temp['invoice_addr'] =$invinfo['buyer_addr']??"";
+         $temp['invoice_mobile'] =$invinfo['buyer_mobile']??"";
+         $temp['invoice_bank'] =$invinfo['buyer_bank']??"";
+         $temp['invoice_bankNo'] =$invinfo['buyer_bankNo']." ";
+         $temp['company'] =$good['customerName'];
+         $temp['goodname'] =$good['goodName'];
+         $temp['tax'] =$good['tax'];
+         $temp['inv_name'] =$good['goodName'];
+         $temp['diff_weight'] =$good['diff_weight'];
+         $temp['diff_price'] =$good['diff_fee'];
+           $temp['unit'] =$good['goodUnit'];
+           $temp['num'] =$good['goodNum'];
+           $temp['price'] =$good['goodPrice'];
+           $temp['total_fee'] =$good['totalPrice'];
+           switch ($value['inv_type']){
+               case 1:
+                   $temp['inv_type']  = "增值税专用发票";
+                   break;
+               case 2:
+                   $temp['inv_type']  = "增值税普通发票";
+                   break;
+               case 3:
+                   $temp['inv_type']  = "增值税电子专用发票";
+                   break;
+               case 4:
+                  $temp['inv_type']  = "增值税电子普通发票";
+                  break;
+               default:
+                   $temp['inv_type']  = "-";
+                   break;
+           }
+        // $temp['inv_type'] = $value['inv_type']==1?"增值税专用发票": "增值税普通发票";
+        // $temp['inv_value'] =$value['inv_value'];
+            $temp['remark'] =$value['remark'];
+           $temp['kp_companyName'] = $invinfo['seller_title']??"";
+           $temp['kp_company_address'] = $invinfo['seller_addr']??"";
+           $temp['kp_company_license'] = $invinfo['seller_code']." ";
+           $temp['kp_bank_name'] = $invinfo['seller_bank']??"";
+           $temp['kp_bankNo'] = $invinfo['seller_bankNo']."";
+           $temp['kp_contector'] = $invout['contector']??"";
+           $temp['kp_mobile'] = $invinfo['seller_mobile']??"";
+         $data[]=$temp;
+       }
+//      }
+      if (empty($data)){
+          return error_show(1003,"未找到数据");
+      }
+      $header=[
+          "申请编号",
+          "公司订单号",
+          "申请部门(所属平台)",
+          "申请人",
+          "代码",
+          "发票开具全称",
+          "发票开具企业纳税识别号",
+          "发票开具企业地址",
+          "发票开具企业地址联系方式",
+          "发票开具企业收款银行",
+          "发票开具企业收款账户",
+          "分公司",
+          "采购商品名",
+          "税率",
+          "发票商品名",
+          "工差重量",
+          "工差金额",
+          "单位",
+          "数量",
+          "单价",
+          "总价",
+          "开票种类",
+          "备注说明",
+          '开票企业名称',
+          '开票企业地址',
+          '开票企业纳税号',
+          '开票企业银行名称',
+          '开票企业银行账户',
+          '开票企业法人',
+          '开票企业联系方式'
+      ];
+       $li = excelExport("待开票",$header,$data);
+    }
 }

+ 3 - 0
app/admin/route/app.php

@@ -182,6 +182,9 @@ route::rule('login', 'admin/Login/login');//登录接口
 route::rule('ticketlist', 'admin/OrderInv/tikcetList');//订单发票查询
 route::rule('hpinvlist', 'admin/Payment/hpinvList');//采购单发票查询
 
+route::rule('orderinvdown', 'admin/OrderInv/downorder');//销售单批量开票导出
+route::rule('orderinvimport', 'admin/OrderInv/impoertInv');//销售单批量开票数据导入
+
 
 
 

+ 63 - 0
app/common.php

@@ -398,4 +398,67 @@ if(!function_exists("invoiceType")){
 		$panda= ['',"004",'007','026','028'];
 		return $panda[$key]??'';
 	}
+}
+
+if(!function_exists(excelExport)){
+	/**
+* @param string $fileName
+* @param array $headArr
+* @param array $data
+* @throws \PHPExcel_Exception
+* @throws \PHPExcel_Reader_Exception
+* @throws \PHPExcel_Writer_Exception
+ */
+function excelExport($fileName = '', $headArr = [], $data = [])
+{
+    $objPHPExcel = new PHPExcel();
+    $objPHPExcel->getProperties();
+    $keyA = 0; // 设置表头
+    foreach ($headArr as $v) {
+        $colum = PHPExcel_Cell::stringFromColumnIndex($keyA);
+        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v);
+        $keyA += 1;
+    }
+
+    $column = 2;
+    $objActSheet = $objPHPExcel->getActiveSheet();
+
+    foreach ($data as $key => $rows) { // 行写入
+        $span = 0;
+        foreach ($rows as $keyName => $value) { // 列写入
+            //判断数据是否有数组,如果有数组,转换成字符串
+
+            if(is_array($value)){
+                $value = implode("、", $value);
+            }
+            $objActSheet->setCellValue(PHPExcel_Cell::stringFromColumnIndex($span) . $column, $value);
+            $span++;
+        }
+        $column++;
+    }
+    //  var_dump($objActSheet->getActiveCell());
+    $fileName .= "_" . date("Y_m_d", time()) . ".xls";
+    //$fileName .= "_" . date("Y_m_d", Request()->instance()->time()) . ".xls";
+    //$fileName = iconv("utf-8", "gb2312", $fileName); // 重命名表
+
+    $objPHPExcel->setActiveSheetIndex(0); // 设置活动单指数到第一个表,所以Excel打开这是第一个表
+    // Redirect output to a client’s web browser (Excel2007)
+    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+    header('Content-Disposition: attachment;filename="'.$fileName.'"');
+    header('Cache-Control: max-age=0');
+// If you're serving to IE 9, then the following may be needed
+    header('Cache-Control: max-age=1');
+
+// If you're serving to IE over SSL, then the following may be needed
+    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
+    header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
+    header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
+    header ('Pragma: public'); // HTTP/1.0
+
+    // header("Content-Type: application/octet-stream");                           # 流文件输出
+    //  header("Content-Transfer-Encoding: binary");                                # 告诉浏览器,这是二进制文件
+    $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
+    $objWriter->save('php://output'); // 文件通过浏览器下载
+    exit();
+}
 }

+ 1 - 1
composer.lock

@@ -1243,5 +1243,5 @@
         "php": ">=7.2.5"
     },
     "platform-dev": [],
-    "plugin-api-version": "2.2.0"
+    "plugin-api-version": "2.3.0"
 }