1import{a as ne}from"./chunk-46XLSQET.js";import{a as te}from"./chunk-CEXXMGZJ.js";import{a as ie}from"./chunk-F3F4KY2J.js";import{b as $,m as ee}from"./chunk-BTGS7UQC.js";import"./chunk-H4QOO6OK.js";import"./chunk-KQ64G6NT.js";import"./chunk-75RZFELW.js";import"./chunk-TCMZHPVP.js";import"./chunk-4QOKRR5P.js";import"./chunk-AYDJ2M35.js";import"./chunk-LWIDYNC2.js";import"./chunk-VXGHG3J7.js";import"./chunk-4RZZDUFM.js";import{a as oe}from"./chunk-DMKEOHTA.js";import{b as X,c as q,f as H,j as G,k as J,l as K,s as Y}from"./chunk-OLEMAAA2.js";import"./chunk-RZAKCWA5.js";import{e as Z}from"./chunk-WPSUQLBS.js";import{f as V,h as Q,k as z}from"./chunk-XYTVABNA.js";import"./chunk-VVTDXABX.js";import{$b as A,Ja as g,Ka as n,La as r,Ma as D,Ta as O,Va as v,Xa as y,ac as j,fb as l,ha as o,hb as _,ib as S,j as N,lb as d,mb as c,nb as m,nc as k,pa as f,r as P,s as B,ua as U,x as L,za as h}from"./chunk-VKOZ2CK3.js";import{Ca as E,I,Oa as F,Tb as R,V as w,Xa as W,Zb as T,n as M}from"./chunk-TAAAIZHL.js";import{a as x,b,e as re}from"./chunk-EQDQRRRY.js";var C=re(oe());function ae(a,u){if(a&1){let i=O();n(0,"div",31),v("click",function(){let e=P(i).$implicit,s=y(2);return B(s.selectFiscal(e))}),n(1,"p",32),l(2),r(),n(3,"p",33),l(4),r()()}if(a&2){let i=u.$implicit;o(2),_(" ",i.businessName," "),o(2),_(" ",i.rfc," ")}}function le(a,u){if(a&1&&(n(0,"div",29),h(1,ae,5,2,"div",30),r()),a&2){let i=y();o(),g("ngForOf",i.searchResults)}}function se(a,u){a&1&&(n(0,"p",34),l(1," Buscando\u2026 "),r())}function de(a,u){if(a&1&&(n(0,"p",33),l(1),r()),a&2){let i=y();o(),_(" Sin resultados para \xAB",i.searchQuery,"\xBB. Captura los datos abajo para dar de alta al cliente. ")}}function ce(a,u){if(a&1&&(n(0,"p",35),D(1,"i",36),l(2),r()),a&2){let i=y();o(2),_("",i.searchError," ")}}function me(a,u){if(a&1&&(n(0,"option",37),l(1),r()),a&2){let i=u.$implicit;g("value",i.id),o(),S(" ",i.id," - ",i.description," ")}}function pe(a,u){if(a&1&&(n(0,"option",37),l(1),r()),a&2){let i=u.$implicit;g("value",i.id),o(),S(" ",i.id," - ",i.description," ")}}function ge(a,u){if(a&1&&(n(0,"option",37),l(1),r()),a&2){let i=u.$implicit;g("value",i.id),o(),S(" ",i.id," - ",i.description," ")}}var Te=(()=>{class a{route;invoiceService;catalogService;AuthService;router;orderId;paymentFormCode;step=2;isLoading=!1;searchQuery="";searchResults=[];searchState="idle";searchError="";searchTerm$=new M;destroyRef=N(L);taxRegimes=[];cfdiUses=[];paymentForms=[];fiscal={customerId:null,restaurantId:null,isPersonaMoral:!1,businessName:"",rfc:"",taxRegimeId:"",cfdiUseId:"",street:"",exteriorNumber:"",interiorNumber:"",neighborhood:"",city:"",stateId:"1",postalCode:"",email:"",phone:""};constructor(i,p,e,s,t){this.route=i,this.invoiceService=p,this.catalogService=e,this.AuthService=s,this.router=t}ngOnInit(){this.wireFiscalSearch();let i=this.route.snapshot.paramMap.get("orderId");if(!i){C.default.fire({icon:"error",title:"Orden no v\xE1lida",text:"No se encontr\xF3 la orden para facturar",confirmButtonColor:"#dc2626"});return}this.orderId=Number(i),this.loadCatalogs()}loadCatalogs(){this.catalogService.getCatalog("SatTaxRegimes").subscribe({next:i=>this.taxRegimes=i,error:()=>this.taxRegimes=[]}),this.catalogService.getCatalog("SatCfdiUses").subscribe({next:i=>this.cfdiUses=i,error:()=>this.cfdiUses=[]}),this.catalogService.getCatalog("SatPaymentForms").subscribe({next:i=>this.paymentForms=i,error:()=>this.paymentForms=[]})}searchFiscal(){this.searchTerm$.next((this.searchQuery||"").trim())}wireFiscalSearch(){this.searchTerm$.pipe(F(300),W(),T(i=>{this.searchState=i.length<3?"idle":"searching",this.searchError=""}),R(i=>i.length<3?I({data:[],estado:"idle"}):this.invoiceService.searchCustomerFiscal(i).pipe(w(p=>({data:p?.data||[],estado:"done"})),E(p=>(console.error("searchCustomerFiscal",p),this.searchError=p?.error?.message||"No se pudo consultar el cat\xE1logo de clientes. Intenta de nuevo.",I({data:[],estado:"error"}))))),ne(this.destroyRef)).subscribe(i=>{this.searchResults=i.data,this.searchState=i.estado})}selectFiscal(i){this.searchTerm$.next(""),this.searchState="idle",this.searchError="",this.fiscal=b(x(x({},this.fiscal),i),{isPersonaMoral:!!i.isPersonaMoral,cfdiUseId:i.cfdiUseId||"",taxRegimeId:i.taxRegimeId||""}),this.searchResults=[]}
1saveFiscal(){if([this.fiscal.businessName,this.fiscal.rfc,this.fiscal.taxRegimeId,this.fiscal.cfdiUseId,this.fiscal.postalCode,this.fiscal.email].some(e=>!e||!String(e).trim())){C.default.fire({icon:"warning",title:"Datos fiscales incompletos",text:"Raz\xF3n social, RFC, r\xE9gimen fiscal, uso CFDI y c\xF3digo postal son obligatorios",confirmButtonColor:"#16a34a"});return}if(!this.paymentFormCode){C.default.fire({icon:"warning",title:"Forma de pago requerida",text:"Selecciona la forma de pago para la factura",confirmButtonColor:"#16a34a"});return}this.isLoading=!0;let p={customerId:this.fiscal.customerId??null,restaurantId:this.AuthService.getRestaurantId(),isPersonaMoral:this.fiscal.isPersonaMoral?1:0,businessName:this.fiscal.businessName.trim(),rfc:this.fiscal.rfc.trim().toUpperCase(),taxRegimeCode:this.fiscal.taxRegimeId,cfdiUseCode:this.fiscal.cfdiUseId,street:this.fiscal.street?.trim()||null,exteriorNumber:this.fiscal.exteriorNumber?.trim()||null,interiorNumber:this.fiscal.interiorNumber?.trim()||null,neighborhood:this.fiscal.neighborhood?.trim()||null,city:this.fiscal.city?.trim()||null,stateId:this.fiscal.stateId||null,postalCode:this.fiscal.postalCode.trim(),email:this.fiscal.email?.trim()||null,phone:this.fiscal.phone?.trim()||null};this.invoiceService.saveCustomerFiscal(p).subscribe({next:e=>{this.isLoading=!1;let s=e?.data?.id;if(!s){C.default.fire({icon:"error",title:"Error",text:"No se pudo obtener el ID fiscal del cliente",confirmButtonColor:"#dc2626"});return}this.router.navigate(["/invoice-preview",this.orderId,s,this.paymentFormCode])},error:e=>{this.isLoading=!1,C.default.fire({icon:"error",title:"Error al guardar datos fiscales",text:e?.error?.message||"Error inesperado",confirmButtonColor:"#dc2626"})}})}static \u0275fac=function(p){return new(p||a)(f(V),f(ie),f(te),f(Z),f(Q))};static \u0275cmp=U({type:a,selectors:[["app-invoice-create"]],decls:64,vars:23,consts:[[1,"px-6","py-8","max-w-5xl","mx-auto","space-y-8"],[1,"text-2xl","font-semibold","text-gray-800"],[1,"text-sm","text-gray-500"],[1,"bg-white","rounded-xl","shadow","p-5","space-y-3"],[1,"text-sm","font-medium","text-gray-700"],["placeholder","RFC o Raz\xF3n Social",1,"w-full","rounded-lg","border","border-gray-300","px-4","py-2","text-sm","focus:ring-2","focus:ring-green-500","focus:outline-none",3,"ngModelChange","input","ngModel"],["class","border rounded-lg divide-y mt-2 max-h-60 overflow-auto",4,"ngIf"],["class","text-xs text-gray-400",4,"ngIf"],["class","text-xs text-gray-500",4,"ngIf"],["class","text-xs text-red-600 font-medium",4,"ngIf"],[1,"bg-white","rounded-xl","shadow","p-6","space-y-6"],[1,"block","text-sm","font-medium","text-gray-700","mb-1"],[1,"w-full","rounded-lg","border","border-gray-300","px-4","py-2","text-sm","focus:ring-2","focus:ring-green-500","focus:outline-none",3,"ngModelChange","ngModel"],[3,"ngValue"],["placeholder","Nombre o raz\xF3n social",1,"w-full","rounded-lg","border","border-gray-300","px-4","py-2","text-sm","focus:ring-2","focus:ring-green-500","focus:outline-none",3,"ngModelChange","ngModel"],["placeholder","XAXX010101000",1,"w-full","rounded-lg","border","border-gray-300","px-4","py-2","text-sm","uppercase","focus:ring-2","focus:ring-green-500","focus:outline-none",3,"ngModelChange","ngModel"],[1,"grid","grid-cols-1","md:grid-cols-2","gap-4"],["value",""],[3,"value",4,"ngFor","ngForOf"],[1,"grid","grid-cols-1","md:grid-cols-3","gap-4"],["placeholder","Calle",1,"w-full","rounded-lg","border","border-gray-300","px-4","py-2","text-sm",3,"ngModelChange","ngModel"],["placeholder","No. Exterior",1,"w-full","rounded-lg","border","border-gray-300","px-4","py-2","text-sm",3,"ngModelChange","ngModel"],["placeholder","No. Interior",1,"w-full","rounded-lg","border","border-gray-300","px-4","py-2","text-sm",3,"ngModelChange","ngModel"],["placeholder","Colonia",1,"w-full","rounded-lg","border","border-gray-300","px-4","py-2","text-sm",3,"ngModelChange","ngModel"],["placeholder","Ciudad",1,"w-full","rounded-lg","border","border-gray-300","px-4","py-2","text-sm",3,"ngModelChange","ngModel"],["placeholder","C\xF3digo Postal *",1,"w-full","rounded-lg","border","border-gray-300","px-4","py-2","text-sm",3,"ngModelChange","ngModel"],["type","email","placeholder","Correo Electr\xF3nico *",1,"w-full","rounded-lg","border","border-gray-300","px-4","py-2","text-sm",3,"ngModelChange","ngModel"],[1,"flex","justify-end","pt-4"],[1,"inline-flex","items-center","rounded-lg","bg-green-600","px-6","py-2","text-sm","font-semibold","text-white","hover:bg-green-700","transition",3,"click"],[1,"border","rounded-lg","divide-y","mt-2","max-h-60","overflow-auto"],["class","px-4 py-3 hover:bg-gray-50 cursor-pointer transition",3,"click",4,"ngFor","ngForOf"],[1,"px-4","py-3","hover:bg-gray-50","cursor-pointer","transition",3,"click"],[1,"font-semibold","text-sm","text-gray-800"],[1,"text-xs","text-gray-500"],[1,"text-xs","text-gray-400"],[1,"text-xs","text-red-600","font-medium"],[1,"fa-solid","fa-triangle-exclamation","mr-1"],[3,"value"]],template:function(p,e){p&1&&(n(0,"div",0)(1,"div")(2,"h1",1),l(3," Datos fiscales del cliente "),r(),n(4,"p",2),l(5," Busca o captura los datos necesarios para emitir la factura CFDI 4.0 "),r()(),n(6,"div",3)(7,"label",4),l(8," Buscar cliente fiscal "),r(),n(9,"input",5),m("ngModelChange",function(t){return c(e.searchQuery,t)||(e.searchQuery=t),t}),v("input",function(){return e.searchFiscal()}),r(),h(10,le,2,1,"div",6)(11,se,2,0,"p",7)(12,de,2,1,"p",8)(13,ce,3,1,"p",9),r(),n(14,"div",10)(15,"div")(16,"label",11),l(17," Tipo de persona "),r(),n(18,"select",12),m("ngModelChange",function(t){return c(e.fiscal.isPersonaMoral,t)||(e.fiscal.isPersonaMoral=t),t}),n(19,"option",13),l(20,"Persona F\xEDsica"),r(),n(21,"option",13),l(22,"Persona Moral"),r()()(),n(23,"div")(24,"label",11),l(25," Raz\xF3n Social * "),r(),n(26,"input",14),m("ngModelChange",function(t){return c(e.fiscal.businessName,t)||(e.fiscal.businessName=t),t}),r()(),n(27,"div")(28,"label",11),l(29," RFC * "),r(),n(30,"input",15),m("ngModelChange",function(t){return c(e.fiscal.rfc,t)||(e.fiscal.rfc=t),t}),r()(),n(31,"div",16)(32,"div")(33,"label",11),l(34," R\xE9gimen Fiscal * "),r(),n(35,"select",12),m("ngModelChange",function(t){return c(e.fiscal.taxRegimeId,t)||(e.fiscal.taxRegimeId=t),t}),n(36,"option",17),l(37,"Selecciona"),r(),h(38,me,2,3,"option",18),r()(),n(39,"div")(40,"label",11),l(41," Uso CFDI * "),r(),n(42,"select",12),m("ngModelChange",function(t){return c(e.fiscal.cfdiUseId,t)||(e.fiscal.cfdiUseId=t),t}),n(43,"option",17),l(44,"Selecciona"),r(),h(45,pe,2,3,"option",18),r()()(),n(46,"div")(47,"label",11),l(48," Forma de pago * "),r(),n(49,"select",12),m("ngModelChange",function(t){return c(e.paymentFormCode,t)||(e.paymentFormCode=t),t}),n(50,"option",17),l(51,"Selecciona"),r(),h(52,ge,2,3,"option",18),r()(),n(53,"div",19)(54,"input",20),m("ngModelChange",function(t){return c(e.fiscal.street,t)||(e.fiscal.street=t),t}),r(),n(55,"input",21),m("ngModelChange",function(t){return c(e.fiscal.exteriorNumber,t)||(e.fiscal.exteriorNumber=t),t}),r(),n(56,"input",22),m("ngModelChange",function(t){return c(e.fiscal.interiorNumber,t)||(e.fiscal.interiorNumber=t),t}),r(),n(57,"input",23),m("ngModelChange",function(t){return c(e.fiscal.neighborhood,t)||(e.fiscal.neighborhood=t),t}),r(),n(58,"input",24),m("ngModelChange",function(t){return c(e.fiscal.city,t)||(e.fiscal.city=t),t}),r(),n(59,"input",25),m("ngModelChange",function(t){return c(e.fiscal.postalCode,t)||(e.fiscal.postalCode=t),t}),r(),n(60,"input",26),m("ngModelChange",function(t){return c(e.fiscal.email,t)||(e.fiscal.email=t),t}),r()(),n(61,"div",27)(62,"button",28),v("click",function(){return e.saveFiscal()}),l(63," Guardar y continuar "),r()()()()),p&2&&(o(9),d("ngModel",e.searchQuery),o(),g("ngIf",e.searchResults.length),o(),g("ngIf",e.searchState==="searching"),o(),g("ngIf",e.searchState==="done"&&!e.searchResults.length),o(),g("ngIf",e.searchState==="error"),o(5),d("ngModel",e.fiscal.isPersonaMoral),o(),g("ngValue",!1),o(2),g("ngValue",!0),o(5),d("ngModel",e.fiscal.businessName),o(4),d("ngModel",e.fiscal.rfc),o(5),d("ngModel",e.fiscal.taxRegimeId),o(3),g("ngForOf",e.taxRegimes),o(4),d("ngModel",e.fiscal.cfdiUseId),o(3),g("ngForOf",e.cfdiUses),o(4),d("ngModel",e.paymentFormCode),o(3),g("ngForOf",e.paymentForms),o(2),d("ngModel",e.fiscal.street),o(),d("ngModel",e.fiscal.exteriorNumber),o(),d("ngModel",e.fiscal.interiorNumber),o(),d("ngModel",e.fiscal.neighborhood),o(),d("ngModel",e.fiscal.city),o(),d("ngModel",e.fiscal.postalCode),o(),d("ngModel",e.fiscal.email))},dependencies:[k,A,j,Y,J,K,X,G,q,H,$,ee,z],encapsulation:2})}return a})();export{Te as InvoiceCreateComponent};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.