wugg 2 년 전
부모
커밋
1aafa80525
5개의 변경된 파일75개의 추가작업 그리고 20개의 파일을 삭제
  1. 11 2
      app/admin/controller/Customer.php
  2. 19 1
      app/admin/controller/InvCat.php
  3. 37 17
      app/admin/controller/OrderInv.php
  4. 1 0
      config/console.php
  5. 7 0
      config/invoice.php

+ 11 - 2
app/admin/controller/Customer.php

@@ -143,7 +143,12 @@ class Customer extends BaseController
         if($companyNo==""){
             return error_show(1003,"参数name 不能为空");
         }
+
         $condition = [['invoice_title','like',"%{$companyNo}%"],['is_del',"=",0]];
+         $company_type= isset($post['company_type'])&&$post['company_type']!='' ? $post['company_type'] : "";
+        if($company_type!=""){
+          $condition[]=["company_type","=",$company_type];
+        }
         $list = Db::name("customer_invoice")->where($condition)->page(1,100)->field("id,invoice_title,invoice_people,invoice_addr,invoice_mobile,invoice_code,invoice_bank,invoice_bankNo,LENGTH(invoice_title) as weight")
             ->order('weight asc')->select();
         if(empty($list)){
@@ -203,6 +208,7 @@ class Customer extends BaseController
            return error_show(1004,"参数 invoice_bankNo 不能为空");
         }
 
+        $company_type = isset($this->post['company_type'])&&$this->post['company_type']!=''?trim($this->post['company_type']):"01";
         $isTr =Db::name("customer_invoice")->where(["invoice_code"=>$code,"is_del"=>0])->find();
         if($isTr){
              return error_show(1004,"开票信息已存在");
@@ -216,13 +222,14 @@ class Customer extends BaseController
             "invoice_mobile"=>$invoice_mobile,
             "invoice_bank"=>$invoice_bank,
             "invoice_bankNo"=>$invoice_bankNo,
+            "company_type"=>$company_type,
             "apply_id"=>$this->uid,
             "apply_name"=>$this->uname,
             "addtime"=>date("Y-m-d H:i:s"),
             "updatetime"=>date("Y-m-d H:i:s")
         ];
-        $ind =Db::name("customer_invoice")->insert($data);
-        if($ind) return app_show(0,"新建成功"); else return error_show(1004,"新建失败");
+        $ind =Db::name("customer_invoice")->insertGetId($data);
+        if($ind) return app_show(0,"新建成功",["id"=>$ind]); else return error_show(1004,"新建失败");
   }
     //编辑开票信息
   public function invoiceSave(){
@@ -267,6 +274,7 @@ class Customer extends BaseController
         if($invoice_bankNo==''){
            return error_show(1004,"参数 invoice_bankNo 不能为空");
         }
+        $company_type = isset($this->post['company_type'])&&$this->post['company_type']!=''?trim($this->post['company_type']):"01";
           $data=[
             "invoice_title"=>$title,
             "invoice_code"=>$code,
@@ -275,6 +283,7 @@ class Customer extends BaseController
             "invoice_mobile"=>$invoice_mobile,
             "invoice_bank"=>$invoice_bank,
             "invoice_bankNo"=>$invoice_bankNo,
+            "company_type"=>$company_type,
             "updatetime"=>date("Y-m-d H:i:s")
         ];
         $ind =Db::name("customer_invoice")->where($isTr)->update($data);

+ 19 - 1
app/admin/controller/InvCat.php

@@ -30,13 +30,31 @@ class InvCat extends BaseController{
             if(empty($catinfo)) return error_show(1004,"未找到对应的开票类目");
             $taxArr=$catinfo['tax']!=''? explode("、",$catinfo['tax']):[];
             if(!in_array($tax,$taxArr))return error_show(1004,"未找到对应的开票类目税率");
+            $tax=str_replace("%","",$tax)/100;
 			$invTag=isset($this->post['inv_tag'])&& $this->post['inv_tag']!==''?intval($this->post['inv_tag']):0;
 			$is_discount=isset($this->post['is_discount'])&& $this->post['is_discount']!==''?intval($this->post['is_discount']):0;
 			$addTax=isset($this->post['addTax'])&& $this->post['addTax']!==''?trim($this->post['addTax']):'';
+			if($is_discount==1){
+				// 优惠政策下 税率标识只能选择 0非零说率 1免税 2不征税 增值税管理为空"出口零税/免税/不征税"
+				if($tax==0 && $invTag==3){
+					return error_show(1004,"税率标识不能选择零税率");
+				}
+				if($addTax==''){
+					return error_show(1004,"参数 addTax 不能为空");
+				}
+			}else{
+				// 非优惠政策下 零税率 税率标识只能选择 3 普通零税率  增值税管理为空
+				// 非优惠政策下 非零税率 税率标识只能选择 0 非零税率  增值税管理为空
+				if($tax==0 && $invTag!=3){
+					return error_show(1004,"税率标识只能选择零税率");
+				}
+				$addTax='';
+			}
+
             $data=[
                 "inv_cat_name"=>$catinfo['short_name'],
                 "inv_cat_code"=>$catinfo['merge_code'],
-                "inv_tax"=>str_replace("%","",$tax)/100,
+                "inv_tax"=>$tax,
                 "inv_good_name"=>$inv_good_name,
                 "inv_tag"=>$invTag,
                 "is_discount"=>$is_discount,

+ 37 - 17
app/admin/controller/OrderInv.php

@@ -6,6 +6,7 @@ use app\admin\BaseController;
 use app\admin\model\ReportCode;
 use think\App;
 use think\facade\Db;
+use think\facade\Cache;
 
 class OrderInv extends BaseController{
     public function __construct(App $app) {
@@ -15,14 +16,32 @@ class OrderInv extends BaseController{
      * 新建销售单开票申请
      */
    public function create(){
-       $buy_id = isset($this->post['buy_id'])&&$this->post['buy_id']!=='' ? intval($this->post['buy_id']):"";
-       if($buy_id==''){
-           return error_show(1004,"参数 buy_id 不能为空");
-       }
+   	    $companyType = isset($this->post['companyType'])&&$this->post['companyType']!=='' ? trim($this->post['companyType']):"";
+        if ($companyType==''){
+        	  return error_show(1004,"参数 companyType 不能为空");
+        }
+        if($companyType!="03"){
+        	$buy_id = isset($this->post['buy_id'])&&$this->post['buy_id']!=='' ? intval($this->post['buy_id']):"";
+	       if($buy_id==''){
+	           return error_show(1004,"参数 buy_id 不能为空");
+	       }
            $buyinfo =Db::name("customer_invoice")->where(['id'=>$buy_id,"is_del"=>0])->find();
            if($buyinfo==false){
                  return error_show(1004,"购买方发票信息未找到");
            }
+        }else{
+        	$username=  isset($this->post['username'])&&$this->post['username']!=='' ? trim($this->post['username']):"个人";
+        	$userID=isset($this->post['userID'])&&$this->post['userID']!=='' ? trim($this->post['userID']):"";
+			$buyinfo=[
+				"invoice_title"=>$username,
+				"invoice_code"=>$userID,
+				"invoice_addr"=>'',
+				"invoice_mobile"=>'',
+				"invoice_bank"=>'',
+				"invoice_bankNo"=>'',
+			] ;
+        }
+
 
         $companyNo = isset($this->post['companyNo'])&&$this->post['companyNo']!=='' ? trim($this->post['companyNo']):"";
        if($companyNo==''){
@@ -45,10 +64,7 @@ class OrderInv extends BaseController{
            return error_show(1004,"参数 invtype 不能为空");
        }
         $email = isset($this->post['email'])&&$this->post['email']!=='' ? trim($this->post['email']):"";
-        $companyType = isset($this->post['companyType'])&&$this->post['companyType']!=='' ? trim($this->post['companyType']):"";
-        if ($companyType==''){
-        	  return error_show(1004,"参数 companyType 不能为空");
-        }
+
         $remark = isset($this->post['remark'])&&$this->post['remark']!=='' ? trim($this->post['remark']):"";
         $orderArr = isset($this->post['orderArr'])&&!empty($this->post['orderArr']) ? $this->post['orderArr']:[];
         if(empty($orderArr)){
@@ -155,7 +171,7 @@ class OrderInv extends BaseController{
             "inv_type"=>$invtype,//发票类型  专用 普通 电子专用 电子普通
             "open_type"=>0, //开票类型 金税开票 金税线下 纯线下
             "is_ticket"=>$company['out_ticket'], //是否支持金税开票
-            "company_type"=>$companyType, //类型01 企业,02 机关事业单位,03 个人, 04 其他
+            "company_type"=> $buyinfo['company_type'], //类型01 企业,02 机关事业单位,03 个人, 04 其他
             "remark"=>$remark, //申请备注
             "exam_remark"=>'', //审核备注
             "ainv_fee"=>0,//已核销金额
@@ -197,12 +213,12 @@ class OrderInv extends BaseController{
         }
          Db::rollback();
         return error_show(1004,"确认单发票申请失败");
-        }catch (Exception $e){
+        }catch (\Exception $e){
             Db::rollback();
             return error_show(1004,$e->getMessage());
         }
    }
-    // 0 待财务开票/待金税开票   1待财务审核 2待填写物流 3开票完成  4开票失败/开票驳回   5财务驳回 6退票
+    // 0 待财务开票/待金税开票   1待财务审核 2待填写物流 3开票完成  4开票失败/开票驳回   5财务驳回 6退票 7金税开票中
    public  function  status(){
         $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=''?trim($this->post['invNo']):"";
         if($invNo==""){
@@ -237,6 +253,8 @@ class OrderInv extends BaseController{
                if($total_fee==='') return error_show(1004,"参数 tatal_fee 不能为空");
                if($subtotal_fee==='') return error_show(1004,"参数 subtotal_fee 不能为空");
                if($total_fee!=$invinfo['inv_value'])return error_show(1004,"发票金额不足");
+           }else{
+           	$status=7;
            }
         }
         $update=[
@@ -250,8 +268,8 @@ class OrderInv extends BaseController{
 
           $invup =Db::name("invoice_pool")->where($invinfo)->update($update);
         if($invup){
-            if($status==1){
-            	if($open_type!=1){
+            if($status==1&& $open_type!=1){
+
             		 $invpool=[
                         "invNo"=>$invinfo['invNo'],
                         "inv_type"=>$open_type,
@@ -270,7 +288,8 @@ class OrderInv extends BaseController{
 	                    Db::rollback();
 	                   return error_show(1004,"发票信息添加失败");
 	                }
-            	}else{
+            	}
+            if($status==7 && $open_type==1){
             		$invpoolinfo =Db::name("invoice_pool_info")->where(["invNo"=>$invNo])->findOrEmpty();
             		if(empty($invpoolinfo)){
             		    Db::rollback();
@@ -327,7 +346,7 @@ class OrderInv extends BaseController{
 							"DDMXXX"=>$goodinfo,
 							"FPLXDM"=>invoiceType($invinfo['inv_type']),
 							"DDQQPCH"=>"",
-							"DDQQLSH"=>randomkeys(40),
+							"DDQQLSH"=>randomkeys(26).date("YmdHis"),
 							"status"=>"0",
 							"addtime"=>date("Y-m-d H:i:s"),
 							"updatetime"=>date("Y-m-d H:i:s")
@@ -337,8 +356,9 @@ class OrderInv extends BaseController{
 						Db::rollback();
                        return error_show(1003,"开票信息生成失败");
 					}
+					Cache::push("invoiceList",$data["DDQQLSH"]);
             	}
-            }
+
 
             if($status==4 ||$status==5 ){
                $qrdArr=Db::name("assoc")->where(["viceCode"=>$invNo,"is_del"=>0])->column("id,orderCode,cancel_fee");
@@ -381,7 +401,7 @@ class OrderInv extends BaseController{
         }
                 Db::rollback();
               return error_show(1004,"审核失败");
-        }catch (Exception $e){
+        }catch (\Exception $e){
               Db::rollback();
               return error_show(1004,$e->getMessage());
         }

+ 1 - 0
config/console.php

@@ -5,5 +5,6 @@
 return [
     // 指令定义
     'commands' => [
+    	"generrateinvoice"=>app\admin\command\GenerrateInvoice::class,
     ],
 ];

+ 7 - 0
config/invoice.php

@@ -0,0 +1,7 @@
+<?php
+
+return [
+	"appKey"=>'KI65kioKD6mZ6IF0SsSackgE',
+	"appSecret"=>'sfMhQSpC9pjeUteAexm0sQLn',
+	'entCode'=>'911101050628285328'
+];