invoice

import { Component, OnInit } from '@angular/core';

import {

  FormArray,

  FormBuilder,

  FormGroup,

  Validators,

  FormControl,

} from '@angular/forms';

import { ActivatedRoute, Params, Router } from '@angular/router';

import { TemplateService } from '../../template.service';

import { NzMessageService, NzModalService } from 'ng-zorro-antd';

import { Option } from '../../../../model/common.model';

import * as CST from '../../../../const/const-define';

import { Utils } from 'utils/utils';

import { AddTemplateRequestRes } from '../../../../model/template/template-add.model';

import {

  TemplateGetRes,

  Template,

} from '../../../../model/template/template-get.model';

import { ItemsQueryRes } from '../../../../model/template/items-query.model';

import { AddTemplateItemRequestRes } from '../../../../model/template/items-add.model';

import { SearchSellerRequestRes } from '../../../../model/template/subject-query.model';

import { SearchSupplierRequestRes } from '../../../../model/template/supplier-query.model';

@Component({

  selector: 'app-templateedit',

  templateUrl: './templateedit.component.html',

  styleUrls: ['./templateedit.component.css'],

})

export class TemplateeditComponent implements OnInit {

  DataForm: FormGroup;

  Form1: FormGroup;

  Form2: FormGroup;

  Form3: FormGroup;

  Form4: FormGroup;

  public invoice: string;

  public templateNo: string;

  public PublicShow: boolean;

  templateInfo: Template = {

    createOpID: '',

    createTime: '',

    einvoiceSupplierName: '',

    einvoiceSupplierNo: '',

    invoiceContent: '',

    invoiceContentType: '',

    lastModifyTime: '',

    modifyOpID: '',

    paperInvoiceSupplierName: '',

    paperInvoiceSupplierNo: '',

    sellerName: '',

    sellerNo: '',

    templateName: '',

    templateNo: '',

  };

  templateinformationEdit = false; // 模板信息编辑显示

  billEdit = false; // 开票方关联编辑显示

  supplierEdit = false; // 开票供应商关联编辑显示

  regularEdit = false; // 开票规则显示

  a = false;

  templateNameError = false;

  copylist = {};

  // 签约主体

  public tsubjectlist = [];

  // 纸质发票

  public pinvoicelist = [];

  // 电子发票

  public einvoicelist = [];

  // 开票内容

  public invoicelist = [];

  // 零税率类型

  public taxtypelist = [new Option('', '空')];

  list = [];

  constructor(

    private fb: FormBuilder,

    private routeInfo: ActivatedRoute,

    private utils: Utils,

    private tservice: TemplateService,

    private router: Router,

    private messageService: NzMessageService,

    private modalService: NzModalService

  ) {}

  ngOnInit() {

    this.templateNo = this.routeInfo.snapshot.queryParams['templateNo'];

    this.initConst(); // 初始化常量

    if (this.templateNo) {

      this.PublicShow = false;

      this.queryTemplateInfo(true);

      this.editCreateForm();

      this.queryItems();

    } else {

      this.PublicShow = true;

      this.createForm();

    }

    this.invoice = '1';

  }

  // 查询单个模板信息

  queryTemplateInfo(e: boolean) {

    const data = {

      urlParams: {

        ID: this.templateNo,

      },

    };

    this.tservice.templateget(data).subscribe((res: TemplateGetRes) => {

      if (res.code && res.code === CST.CODE.SUCCESS) {

        this.templateInfo = Object.assign(this.templateInfo, res.data);

        if (e) {

          this.initInfoForm();

        }

      } else {

        this.messageService.error(res.message || '查询发票模板失败');

        // this.router.navigate(['/template/subject']);

      }

    });

  }

  // 查询发票明细

  queryItems() {

    const data = {

      urlParams: {

        templateNo: this.templateNo,

      },

    };

    this.tservice.templateitemssearch(data).subscribe((res: ItemsQueryRes) => {

      if (

        res.code &&

        res.code === CST.CODE.SUCCESS &&

        res.data.templateItemList

      ) {

        this.list = res.data.templateItemList;

        this.list.forEach((v) => {

          v.checked = false;

          v.editshow = false;

          v.addchecked = false;

        });

      } else {

        // this.messageService.error(res.message || '开票明细失败');

        this.list = [];

      }

    });

  }

  // 新增

  addData() {

    let validateSuccess = true;

    for (const i in this.DataForm.controls) {

      if (this.DataForm.controls.hasOwnProperty(i)) {

        this.DataForm.controls[i].markAsDirty();

        this.DataForm.controls[i].updateValueAndValidity();

        if (this.DataForm.controls[i].status === 'INVALID') {

          validateSuccess = false;

        }

      }

    }

    if (!validateSuccess) {

      return false;

    }

    const value = this.DataForm.value;

    const data = {

      templateNo: value.templateNo,

      templateInfo: {

        einvoiceSupplierNo: value.einvoiceSupplierNo,

        invoiceContent: value.invoiceContent,

        invoiceContentType: value.invoiceContentType,

        paperInvoiceSupplierNo: value.paperInvoiceSupplierNo,

        sellerNo: value.sellerNo,

        templateName: value.templateName,

      },

    };

    this.tservice.templatesadd(data).subscribe((res: AddTemplateRequestRes) => {

      if (res.code && res.code === CST.CODE.SUCCESS) {

        this.messageService.success('添加成功');

        this.router.navigate(['/template/invoicetemplate']);

      } else {

        this.messageService.error(res.message || '添加失败');

      }

    });

  }

  // 模板信息修改

  templateInformationEdit() {

    let validateSuccess = true;

    for (const i in this.Form1.controls) {

      if (this.Form1.controls.hasOwnProperty(i)) {

        this.Form1.controls[i].markAsDirty();

        this.Form1.controls[i].updateValueAndValidity();

        if (this.Form1.controls[i].status === 'INVALID') {

          validateSuccess = false;

        }

      }

    }

    if (!validateSuccess) {

      return false;

    }

    const data = this.Form1.value;

    this.update(data, '1');

  }

  // 开票方关联修改

  saveBill() {

    this.update(this.Form2.value, '2');

  }

  // 开票供应商关联修改

  saveSupplier() {

    this.update(this.Form3.value, '3');

  }

  // 开票规则修改

  saveRegular() {

    let validateSuccess = true;

    for (const i in this.Form4.controls) {

      if (this.Form4.controls.hasOwnProperty(i)) {

        this.Form4.controls[i].markAsDirty();

        this.Form4.controls[i].updateValueAndValidity();

        if (this.Form4.controls[i].status === 'INVALID') {

          validateSuccess = false;

        }

      }

    }

    if (!validateSuccess) {

      return false;

    }

    this.update(this.Form4.value, '4');

  }

  // 修改服务

  update(datas: any, num) {

    const data = {

      urlParams: {

        ID: this.templateNo,

      },

      templateInfo: Object.assign({}, datas),

    };

    this.tservice

      .templateupdate(data)

      .subscribe((res: AddTemplateRequestRes) => {

        if (res.code && res.code === CST.CODE.SUCCESS) {

          this.messageService.success('修改成功');

          this.queryTemplateInfo(false);

          setTimeout(() => {

            this.editForm(num);

          }, 100);

        } else {

          this.messageService.error(res.message || '修改失败');

        }

      });

  }

  editForm(num) {

    switch (num) {

      case '1':

        this.Form1.setValue({

          templateName: this.templateInfo.templateName,

        });

        this.templateinformationEdit = false;

        break;

      case '2':

        this.Form2.setValue({

          sellerNo: this.templateInfo.sellerNo,

        });

        this.billEdit = false;

        break;

      case '3':

        this.Form3.setValue({

          paperInvoiceSupplierNo: this.templateInfo.paperInvoiceSupplierNo,

          einvoiceSupplierNo: this.templateInfo.einvoiceSupplierNo,

        });

        this.supplierEdit = false;

        break;

      case '4':

        this.Form4.setValue({

          invoiceContentType: this.templateInfo.invoiceContentType,

          invoiceContent: this.templateInfo.invoiceContent,

        });

        this.regularEdit = false;

        break;

      default:

        break;

    }

  }

  // 批量删除开票明细管理

  ticketDetailDel() {

    if (this.list.every((v) => v.checked === false)) {

      this.messageService.warning('请选择开票明细');

      return false;

    }

    const delList = [];

    this.list.forEach((v1) => {

      if (v1.templateItemID && v1.checked === true) {

        delList.push(v1.templateItemID);

      }

    });

    const data = {

      templateItemIDList: delList,

    };

    this.modalService.info({

      nzContent: '删除信息已提交,请点击确定查看处理结果',

      nzOnOk: () => {

        this.tservice

          .templateitemsdelete(data)

          .subscribe((res: AddTemplateRequestRes) => {

            if (res.code && res.code === CST.CODE.SUCCESS) {

              this.queryItems();

              this.messageService.success('删除成功');

            } else {

              this.messageService.error(res.message || '删除失败');

            }

          });

      },

    });

  }

  // 添加开票明细管理

  ticketDetailAdd() {

    const ticketAddList = {

      createOpID: null,

      createTime: null,

      itemName: null,

      lastModifyTime: null,

      modifyOpID: null,

      taxCategoryCode: null,

      taxRate: null,

      templateItemID: null,

      templateItemNo: null,

      templateNo: null,

      unit: null,

      zeroTaxRateType: null,

      checked: false,

      editshow: true,

      addchecked: true,

    };

    this.list.push(ticketAddList);

  }

  // 新增不需要时删除

  ticketDetaiAddDel(i) {

    this.list = this.list.filter((k, v) => v !== i);

  }

  // 保存开票明细

  ticketDetaiSave(i) {

    const valadate = this.itemVadate(i);

    if (!valadate) {

      return false;

    }

    const data = {

      templateNo: this.templateNo,

      templateItemInfo: {

        itemName: this.list[i].itemName,

        taxCategoryCode: this.list[i].taxCategoryCode,

        taxRate: this.list[i].taxRate,

        templateItemNo: this.list[i].templateItemNo,

        zeroTaxRateType: this.list[i].zeroTaxRateType,

        unit: this.list[i].unit,

      },

    };

    this.tservice

      .templateitemsadd(data)

      .subscribe((res: AddTemplateItemRequestRes) => {

        if (res.code && res.code === CST.CODE.SUCCESS) {

          this.queryItems();

          this.messageService.success('添加成功');

        } else {

          this.messageService.error(res.message || '添加失败');

        }

      });

  }

  // 修改开票明细

  ticketDetaiUpdate(i) {

    const valadate = this.itemVadate(i);

    if (!valadate) {

      return false;

    }

    const data = {

      urlParams: {

        ID: this.list[i].templateItemID,

      },

      templateItemInfo: {

        itemName: this.list[i].itemName,

        taxCategoryCode: this.list[i].taxCategoryCode,

        taxRate: this.list[i].taxRate,

        templateItemNo: this.list[i].templateItemNo,

        zeroTaxRateType: this.list[i].zeroTaxRateType,

        unit: this.list[i].unit,

      },

    };

    this.tservice

      .templateitemsupdate(data)

      .subscribe((res: AddTemplateItemRequestRes) => {

        if (res.code && res.code === CST.CODE.SUCCESS) {

          this.queryItems();

          this.messageService.success('修改成功');

        } else {

          this.messageService.error(res.message || '修改失败');

        }

      });

  }

  // 开票明细管理验证

  itemVadate(i) {

    const a = /^\d+(\.\d+)?$/;

    let itemError = true;

    if (this.list[i].taxRate !== null && !a.test(this.list[i].taxRate)) {

      this.showError(this.list[i], 'taxRateShow');

      itemError = false;

    }

    if (

      Number.parseFloat(this.list[i].taxRate) === 0 &&

      (this.list[i].zeroTaxRateType === '' ||

        this.list[i].zeroTaxRateType == null)

    ) {

      this.showError(this.list[i], 'zeroTaxRateTypeShows');

      itemError = false;

    }

    return itemError;

  }

  // 开票明细编辑按钮

  ticketDetaiEdit(i: number) {

    this.copylist[i] = Object.assign(

      Object.create(Object.getPrototypeOf(this.list[i])),

      this.list[i]

    );

    // this.copylist[i] = JSON.parse(JSON.stringify(this.list[i]));

    this.list[i].editshow = true;

  }

  // 开票明细取消按钮

  ticketDetaiCancel(i: number) {

    Object.assign(this.list[i], this.copylist[i]);

    this.list[i].editshow = false;

    delete this.copylist[i];

  }

  // 新增时初始化

  createForm() {

    this.DataForm = this.fb.group({

      templateName: ['', [Validators.required, this.utils.isEmptySpace]],

      templateNo: ['', [Validators.required, this.utils.isEmptySpace]],

      einvoiceSupplierNo: [''],

      invoiceContentType: [''],

      paperInvoiceSupplierNo: [''],

      sellerNo: ['', [Validators.required]],

      invoiceContent: ['', [Validators.required, this.utils.isEmptySpace]],

      checkbox: [''],

    });

  }

  // 编辑初始化

  editCreateForm() {

    this.Form1 = this.fb.group({

      templateName: ['', [Validators.required, this.utils.isEmptySpace]],

    });

    this.Form2 = this.fb.group({

      sellerNo: [''],

    });

    this.Form3 = this.fb.group({

      paperInvoiceSupplierNo: [''],

      einvoiceSupplierNo: [''],

    });

    this.Form4 = this.fb.group({

      invoiceContentType: [''],

      invoiceContent: ['', [Validators.required, this.utils.isEmptySpace]],

    });

  }

  // 请求消息后赋值

  initInfoForm() {

    this.Form1.setValue({

      templateName: this.templateInfo.templateName,

    });

    this.Form2.setValue({

      sellerNo: this.templateInfo.sellerNo,

    });

    this.Form3.setValue({

      paperInvoiceSupplierNo: this.templateInfo.paperInvoiceSupplierNo,

      einvoiceSupplierNo: this.templateInfo.einvoiceSupplierNo,

    });

    this.Form4.setValue({

      invoiceContentType: this.templateInfo.invoiceContentType,

      invoiceContent: this.templateInfo.invoiceContent,

    });

  }

  // 查询签约主体列表

  querySubjectList() {

    const data = {

      urlParams: {

        pageSize: 100,

        pageIndex: 1,

      },

      sellerName: null,

      sellerNo: null,

    };

    this.tservice

      .sellerssearch(data)

      .subscribe((res: SearchSellerRequestRes) => {

        if (res && res.code === CST.CODE.SUCCESS && res.data.sellerList) {

          res.data.sellerList.forEach((v) => {

            this.tsubjectlist.push(new Option(v.sellerNo, v.sellerName));

          });

        } else {

          this.tsubjectlist = [];

        }

      });

  }

  // 查询纸质发票

  pquerySupplierList() {

    const data = {

      urlParams: {

        pageSize: 100,

        pageIndex: 1,

      },

      invoiceMethod: '1',

    };

    this.tservice

      .supplierssearch(data)

      .subscribe((res: SearchSupplierRequestRes) => {

        if (

          res.code &&

          res.code === CST.CODE.SUCCESS &&

          res.data.supplierList

        ) {

          res.data.supplierList.forEach((v) => {

            this.pinvoicelist.push(new Option(v.supplierNo, v.supplierName));

          });

        } else {

          this.pinvoicelist = [];

        }

      });

  }

  // 查询电子发票列表

  equerySupplierList() {

    const data = {

      urlParams: {

        pageSize: 100,

        pageIndex: 1,

      },

      invoiceMethod: '2',

    };

    this.tservice

      .supplierssearch(data)

      .subscribe((res: SearchSupplierRequestRes) => {

        if (

          res.code &&

          res.code === CST.CODE.SUCCESS &&

          res.data.supplierList

        ) {

          res.data.supplierList.forEach((v) => {

            this.einvoicelist.push(new Option(v.supplierNo, v.supplierName));

          });

        } else {

          this.einvoicelist = [];

        }

      });

  }

  initConst() {

    this.tservice.queryConst({}).subscribe((res) => {

      if (res && res.code === CST.CODE.SUCCESS) {

        // 开票内容

        Object.keys(res.data.INVOICE_CONTENT_TYPE).forEach((key, index) => {

          this.invoicelist.push(

            new Option(key, res.data.INVOICE_CONTENT_TYPE[key])

          );

        });

        Object.keys(res.data.ZERO_TAX_RATE_TYPE).forEach((key, index) => {

          this.taxtypelist.push(

            new Option(key, res.data.ZERO_TAX_RATE_TYPE[key])

          );

        });

      }

    });

    this.querySubjectList(); // 查询签约主体列表

    this.pquerySupplierList(); // 查询纸质发票,电子发票

    this.equerySupplierList(); // 查询纸质发票,电子发票

  }

  // 边框变红

  showError(list, name) {

    list[name] = true;

    setTimeout(() => {

      list[name] = false;

    }, 3000);

  }

  clickTemplateInformation() {

    this.templateinformationEdit = true;

  }

  cancelTemplateInformation() {

    this.templateinformationEdit = false;

    this.editForm('1');

  }

  clickBill() {

    this.billEdit = true;

  }

  cancelBill() {

    this.billEdit = false;

    this.editForm('2');

  }

  clickSupplier() {

    this.supplierEdit = true;

  }

  cancelSupplier() {

    this.supplierEdit = false;

    this.editForm('3');

  }

  clickRegular() {

    this.regularEdit = true;

  }

  cancelRegular() {

    this.regularEdit = false;

    this.editForm('4');

  }

}、









































 



       

          模板信息





      模板名称*


       

       

         

          模板名称不能为空






      模板编号

        *



       

         

           

            模板编号不能为空







       

          开票方关联





      签约主体*


       

         

           

             


            请选择签约主体







       

          开票供应商关联





      纸质发票


       

         






      电子发票


       

         







       

          开票规则





      开票内容*


       

         






      项目名称*


       

         

           

          项目名称不能为空







       

          新增模板






 

   



         

            模板信息


          修改

          取消

          保存




       

模板名称*


          {{templateInfo.templateName}}

         

           

             

              模板名称不能为空







         

模板编号*




          {{templateNo}}

         





     

     



         

            开票方关联


          修改

          取消

          保存




       

签约主体*


          {{templateInfo.sellerName}}

         

           







     

     



         

            开票供应商关联


          修改

          取消

          保存




       

纸质发票


          {{templateInfo.paperInvoiceSupplierName}}

         

           






       

电子发票


          {{templateInfo.einvoiceSupplierName}}

         

           







     

     



         

            开票规则


          修改

          取消

          保存




       

开票内容*


          {{templateInfo.invoiceContentType === '1' ? '项目明细' : '商品明细'}}

         

           






       

项目名称*


          {{templateInfo.invoiceContent}}

         

           

             

              项目名称不能为空







     



         

            开票明细管理






         

            添加

            删除


         

           




                  操作

                  编号

                  发票内容名称

                  单位

                  税收分类编码

                  税率

                  零税率类型





                   



                  编辑

                    保存

                    保存

                    |

                    删除

                    取消



                  {{option.templateItemNo}}

                 



                  {{option.itemName}}

                 



                  {{option.unit}}

                 



                  {{option.taxCategoryCode}}

                 



                  {{option.taxRate}}

                 



                  {{option.zeroTaxRateTypeShow}}

                 

                   

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 195,783评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,360评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 142,942评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,507评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,324评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,299评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,685评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,358评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,652评论 1 293
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,704评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,465评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,318评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,711评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,991评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,265评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,661评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,864评论 2 335

推荐阅读更多精彩内容