openstack-uicore-foundation
Version:
ui reactjs components for openstack marketing site
2 lines • 19.2 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("openstack-uicore-foundation",[],t):"object"==typeof exports?exports["openstack-uicore-foundation"]=t():e["openstack-uicore-foundation"]=t()}(this,(()=>(()=>{"use strict";var e={3209:(e,t,o)=>{o.d(t,{OP:()=>n,UT:()=>a,eM:()=>c,fJ:()=>l,iC:()=>i,q9:()=>r});const r=100n,n=2,l=0,a=100,i=1e3,c={AMOUNT:"Amount",RATE:"Rate"}},8400:(e,t,o)=>{o.d(t,{currencyAmountFromCents:()=>l,formatBalance:()=>c,formatDiscount:()=>a,getOrderTotal:()=>i});var r=o(3209);const n={USD:"$",EUR:"€",GBP:"£",CAD:"C$",AUD:"A$",NZD:"NZ$",CHF:"CHF",ARS:"AR$",BRL:"R$",MXN:"MX$"};function l(e,t="USD"){let o="!ERROR";if("number"!=typeof e||!Number.isInteger(e))return console.error("ERROR - currencyAmountFromCents: cents must be an integer number"),o;try{const l=function(e){let t;if("bigint"==typeof e)t=e;else if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error("cents must be a safe integer Number (or pass BigInt/string).");t=BigInt(e)}else{if("string"!=typeof e)throw new Error("cents must be a bigint, number, or numeric string.");{const o=e.trim();if(!/^\d+$/.test(o))throw new Error("cents string must contain digits only (e.g., '1234').");t=BigInt(o)}}if(t<r.fJ)throw new Error("cents must be non-negative.");const o=t/r.q9,n=t%r.q9;return`${o.toString()}.${n.toString().padStart(r.OP,"0")}`}(e);o=`${n[t]??"$"}${l}`}catch(e){console.error(`ERROR - currencyAmountFromCents: ${e}`)}return o}const a=(e,t)=>t===r.eM.AMOUNT?l(e):t===r.eM.RATE?e/r.UT+"%":"",i=e=>e&&(e.net_amount||e.amount_due)||0,c=e=>{if(null==e)return"";const t=l(Math.abs(e));return e<0?`-${t}`:t}}},t={};function o(r){var n=t[r];if(void 0!==n)return n.exports;var l=t[r]={exports:{}};return e[r](l,l.exports,o),l.exports}(()=>{o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t}})(),(()=>{o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})}})(),(()=>{o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})();var r={};o.r(r),o.d(r,{OrderPdf:()=>R,buildRows:()=>v,generateInvoicePDF:()=>F,previewPDF:()=>V});const n=require("react");var l=o.n(n);const a=require("prop-types");var i=o.n(a);const c=require("i18n-react/dist/i18n-react");var d=o.n(c);const s=require("@react-pdf/renderer"),m=require("@babel/runtime/helpers/defineProperty");var u=o.n(m);const f=require("moment-timezone");var p=o.n(f),y=o(8400),b=o(3209);function g(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,r)}return o}function w(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?g(Object(o),!0).forEach((function(t){u()(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):g(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}const h="Helvetica",_=(e,t="LOC",o="dddd Do h:mm a")=>e?"LOC"===t?p()(e*b.iC).format(o):p()(e*b.iC).tz(t).format(o):"",E=e=>e?[e.address_1??e.line1,e.address_2??e.line2,e.city,e.state,e.zip_code??e.postal_code,e.country].map((e=>(e??"").toString().trim())).filter(Boolean).join(", "):"",C=e=>e?`${(null==e?void 0:e.short_name)??""}${null!=e&&e.name?` (${null==e?void 0:e.name})`:""}`:"",v=e=>{const t=[];let o=0;(e.forms||[]).forEach((e=>{(e.items||[]).filter((e=>(e.quantity??1)>0)).forEach((r=>{var n,l;const a=!!r.canceled_by_id,i=a?d().translate("sponsor_order_grid.cancelled_by",{user:r.canceled_by_full_name,date:_(r.canceled_at,"LOC","YYYY/MM/DD HH:mm")}):"";o+=r.amount,t.push({rowKey:`item-${r.line_id??r.id}`,type:"item",code:String(e.code||""),description:String((null===(n=r.type)||void 0===n?void 0:n.name)||r.title||""),addon:String((null===(l=e.add_on)||void 0===l?void 0:l.name)||""),qty:String(r.quantity??1),price:(0,y.currencyAmountFromCents)(r.amount),balanceCents:o,cancelled:a,cancelledBy:i})}));const r=e.discount_in_cents??0;r&&(o-=r,t.push({rowKey:`discount-${e.id}`,type:"discount",code:d().translate("mui_table.dis"),description:(0,y.formatDiscount)(e.discount_amount,e.discount_type),addon:"",qty:"",price:(0,y.currencyAmountFromCents)(r),balanceCents:o}))})),(e.fees||[]).forEach((e=>{o+=e.amount,t.push({rowKey:`fee-${e.line_id??e.id}`,type:"fee",code:d().translate("mui_table.payfee"),description:String(e.title||""),addon:"",qty:"1",price:(0,y.currencyAmountFromCents)(e.amount),balanceCents:o})}));return[...(e.payments||[]).map((e=>w(w({},e),{},{_rowType:"payment"}))),...(e.refunds||[]).map((e=>w(w({},e),{},{_rowType:"refund"})))].sort(((e,t)=>e.created-t.created)).forEach((e=>{"payment"===e._rowType?(o-=e.amount,t.push({rowKey:`payment-${e.id}`,type:"payment",code:d().translate("mui_table.pay"),description:`${d().translate("mui_table.paid_via")} ${e.method||d().translate("mui_table.card")}`,subDescription:_(e.created,"LOC","YYYY/MM/DD HH:mm"),addon:"",qty:"1",price:(0,y.currencyAmountFromCents)(e.amount),balanceCents:o})):(o+=e.amount,t.push({rowKey:`refund-${e.id}`,type:"refund",code:d().translate("mui_table.ref"),description:String(e.reason||d().translate("mui_table.refund")),subDescription:String(e.status||""),addon:"",qty:"1",price:(0,y.currencyAmountFromCents)(e.amount),balanceCents:o}))})),(e.notes||[]).forEach((e=>{t.push({rowKey:`note-${e.id}`,type:"note",content:String(e.content||"")})})),t},x=({styles:e,label:t,value:o,noBorder:r=!1})=>l().createElement(s.View,{style:[e.fieldRow,r&&e.fieldRowNoBorder]},l().createElement(s.Text,{style:e.fieldLabel},t??""),l().createElement(s.Text,{style:e.fieldValue},o??"")),T={ArrowUpward:"M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z",ArrowDownward:"M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z",Refresh:"M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z",DoNotDisturb:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8 0-1.85.63-3.55 1.69-4.9L16.9 18.31C15.55 19.37 13.85 20 12 20zm6.31-3.1L7.1 5.69C8.45 4.63 10.15 4 12 4c4.42 0 8 3.58 8 8 0 1.85-.63 3.55-1.69 4.9z"},B=({name:e,color:t,size:o=8})=>l().createElement(s.Svg,{width:o,height:o,viewBox:"0 0 24 24",style:{marginRight:3}},l().createElement(s.Path,{d:T[e],fill:t})),D=({row:e,styles:t,rowStyles:o})=>{if("note"===e.type)return l().createElement(s.View,{style:t.tdNote},l().createElement(s.Text,{style:[t.colCode,t.muted]},d().translate("mui_table.note")),l().createElement(s.Text,{style:[{flex:1},t.muted]},e.content));const r=o[e.cancelled?"cancelled":e.type];return l().createElement(s.View,{style:r.row},l().createElement(s.Text,{style:r.code},e.code),r.typeBadge?l().createElement(s.View,{style:t.typeCell},l().createElement(B,{name:r.typeBadge.icon,color:r.typeBadge.iconColor}),l().createElement(s.Text,{style:[t.typeBadgeLabel,{color:r.typeBadge.labelColor}]},r.typeBadge.label)):l().createElement(s.View,{style:t.colType}),l().createElement(s.View,{style:t.colDescMultiLine},l().createElement(s.Text,{style:r.descText},"item"===e.type?`${e.description} - ${d().translate("mui_table.total")}: ${e.qty}`:e.description),e.cancelledBy&&l().createElement(s.Text,{style:t.muted},e.cancelledBy),e.subDescription&&l().createElement(s.Text,{style:t.muted},e.subDescription)),l().createElement(s.Text,{style:r.price},e.price),null!=e.balanceCents?l().createElement(s.Text,{style:[r.balance??t.colBalance,e.balanceCents<0&&t.colBalanceNegative]},(0,y.formatBalance)(e.balanceCents)):l().createElement(s.View,{style:t.colBalance}))},S=({styles:e,cancelledTotal:t,refundsTotal:o,retained:r,credited:n})=>{const a=r>0?"#c62828":"#1b5e20",i=r>0?d().translate("sponsor_order_grid.retained"):n>0?d().translate("sponsor_order_grid.credited"):d().translate("sponsor_order_grid.balance"),c=r>0?r:n>0?n:r;return l().createElement(s.View,{style:e.reconciliationWrapper,wrap:!1},l().createElement(s.View,{style:e.reconciliationBox},l().createElement(s.Text,{style:e.reconciliationTitle},d().translate("sponsor_order_grid.reconciliation")),l().createElement(s.View,{style:e.reconciliationRow},l().createElement(s.Text,{style:e.reconciliationLabel},d().translate("sponsor_order_grid.cancelled")),l().createElement(s.Text,{style:e.reconciliationValue},(0,y.currencyAmountFromCents)(t??0))),l().createElement(s.View,{style:e.reconciliationRow},l().createElement(s.Text,{style:e.reconciliationLabel},d().translate("sponsor_order_grid.refunded")),l().createElement(s.Text,{style:e.reconciliationValue},(0,y.currencyAmountFromCents)(o??0))),l().createElement(s.View,{style:e.reconciliationDivider}),l().createElement(s.View,{style:e.reconciliationRow},l().createElement(s.Text,{style:e.reconciliationLabel},i),l().createElement(s.Text,{style:[e.reconciliationValue,{color:a}]},(0,y.currencyAmountFromCents)(c??0)))))},R=({order:e,summit:t,logoSrc:o,theme:r})=>{var n,a,i,c;if(!e)throw new Error("OrderPdf: order is required");if(!t)throw new Error("OrderPdf: summit is required");const m=(e=>{var t;const o=null==e||null===(t=e.typography)||void 0===t?void 0:t.fontFamily;if(!o)return h;const r=o.split(",")[0].trim().replace(/^['"]|['"]$/g,"");return s.Font.getRegisteredFontFamilies().includes(r)?r:h})(r),u=(e=>s.StyleSheet.create({page:{backgroundColor:"#F7F7F8",padding:64,fontFamily:e,fontSize:8,color:"#212529"},headerRow:{flexDirection:"row",marginBottom:20,gap:20},cellLeft:{flex:1,backgroundColor:"#ffffff",borderRadius:10,borderWidth:1,borderColor:"#DEE2E6",paddingHorizontal:18,paddingVertical:10,justifyContent:"center"},logo:{width:"100%",height:84,objectFit:"contain",marginBottom:0,paddingBottom:0},cellRight:{flex:1,backgroundColor:"#ffffff",borderRadius:10,borderWidth:1,borderColor:"#DEE2E6",paddingHorizontal:18,paddingVertical:10},invoiceTitle:{fontFamily:e,fontWeight:"bold",fontSize:14,lineHeight:1.5,letterSpacing:0,color:"rgba(17, 19, 21, 1)",marginBottom:8},fieldRow:{fontSize:8,lineHeight:1.8,flexDirection:"row",color:"rgba(0, 0, 0, 0.87)",paddingBottom:3,paddingTop:6,borderBottom:"1px solid rgba(224, 224, 224, 1)",alignContent:"flex-start"},fieldRowNoBorder:{borderBottomWidth:0},fieldLabel:{flex:4,fontWeight:"bold",color:"rgba(0, 0, 0, 0.87)"},fieldValue:{flex:9},tableWrapper:{marginTop:8,borderRadius:8,borderWidth:1,borderStyle:"solid",borderColor:"#eee",backgroundColor:"#ffffff"},table:{fontFamily:e,borderRadius:8,overflow:"hidden"},thRow:{flexDirection:"row",backgroundColor:"#f0f0f0",paddingVertical:12,paddingHorizontal:12,alignItems:"center",borderBottomWidth:1,borderBottomStyle:"solid",borderBottomColor:"#eee"},thText:{fontFamily:e,fontSize:7,fontWeight:600,color:"#333333"},tdRow:{backgroundColor:"#FFFFFF",flexDirection:"row",paddingHorizontal:12,paddingVertical:14,alignItems:"center",borderBottomWidth:1,borderBottomStyle:"solid",borderBottomColor:"#eee"},tdPayment:{flexDirection:"row",paddingHorizontal:12,paddingVertical:14,alignItems:"flex-start",backgroundColor:"#f0fdf4",borderBottomWidth:1,borderBottomStyle:"solid",borderBottomColor:"#eee"},tdRefund:{flexDirection:"row",paddingHorizontal:12,paddingVertical:14,alignItems:"flex-start",backgroundColor:"#fff7ed",borderBottomWidth:1,borderBottomStyle:"solid",borderBottomColor:"#eee"},tdNote:{flexDirection:"row",paddingHorizontal:12,paddingVertical:10,alignItems:"flex-start",backgroundColor:"#FFFFFF",borderBottomWidth:1,borderBottomStyle:"solid",borderBottomColor:"#eee"},tdAmountDue:{flexDirection:"row",paddingHorizontal:12,paddingVertical:14,alignItems:"center",backgroundColor:"#fafafa",borderTopWidth:1,borderTopColor:"#000000"},colCode:{width:"12%",fontSize:8},colCodePayment:{width:"12%",fontSize:8,fontWeight:"bold"},colType:{width:"15%",fontSize:8},colDesc:{width:"39%",fontSize:8},colDescMultiLine:{width:"39%",flexDirection:"column",justifyContent:"flex-start"},colPrice:{width:"18%",textAlign:"right",fontSize:8,color:"#333333"},colPriceRefund:{fontFamily:e,width:"18%",textAlign:"right",fontSize:8,fontWeight:"bold",color:"#e65100"},colPricePayment:{fontFamily:e,width:"18%",textAlign:"right",fontSize:8,fontWeight:"bold",color:"#1b5e20"},colBalance:{width:"16%",textAlign:"right",fontSize:8,color:"#666666"},colBalanceNegative:{color:"#dc2626"},tdAmountDueLabel:{fontFamily:e,width:"66%",fontSize:8,fontWeight:700},tdAmountDueValue:{fontFamily:e,width:"16%",textAlign:"right",fontSize:9,fontWeight:700},paymentDesc:{fontFamily:e,fontSize:8,fontWeight:"bold"},muted:{color:"#6C757D",fontSize:8},typeCell:{width:"15%",flexDirection:"row",alignItems:"center"},typeBadgeLabel:{fontSize:8},cancelledText:{color:"#9ca3af",textDecoration:"line-through"},reconciliationWrapper:{flexDirection:"row",paddingHorizontal:12,paddingVertical:12,borderBottomWidth:1,borderBottomStyle:"solid",borderBottomColor:"#eee"},reconciliationBox:{width:"33%"},reconciliationTitle:{fontFamily:e,fontSize:8,fontWeight:600,color:"#333333",marginBottom:6},reconciliationRow:{flexDirection:"row",justifyContent:"space-between",paddingVertical:2},reconciliationLabel:{fontSize:7,color:"#6C757D"},reconciliationValue:{fontSize:7,color:"#333333",textAlign:"right"},reconciliationDivider:{borderBottomWidth:1,borderBottomColor:"#dee2e6",marginVertical:4}}))(m),f=(e=>({fee:{row:e.tdRow,code:e.colCode,descText:null,price:e.colPrice,typeBadge:{icon:"ArrowUpward",iconColor:"#ff9800",label:d().translate("order_invoice_pdf.charge"),labelColor:"#333333"}},item:{row:e.tdRow,code:e.colCode,descText:null,price:e.colPrice,typeBadge:{icon:"ArrowUpward",iconColor:"#ff9800",label:d().translate("order_invoice_pdf.charge"),labelColor:"#333333"}},discount:{row:e.tdPayment,code:e.colCodePayment,descText:e.paymentDesc,price:e.colPricePayment,typeBadge:{icon:"ArrowDownward",iconColor:"#4caf50",label:d().translate("mui_table.discount"),labelColor:"#1b5e20"}},payment:{row:e.tdPayment,code:e.colCodePayment,descText:e.paymentDesc,price:e.colPricePayment,typeBadge:{icon:"ArrowDownward",iconColor:"#4caf50",label:d().translate("mui_table.payment"),labelColor:"#1b5e20"}},refund:{row:e.tdRefund,code:e.colCodePayment,descText:e.paymentDesc,price:e.colPriceRefund,typeBadge:{icon:"Refresh",iconColor:"#ea580c",label:d().translate("mui_table.refund"),labelColor:"#e65100"}},cancelled:{row:e.tdRow,code:[e.colCode,e.cancelledText],descText:e.cancelledText,price:[e.colPrice,e.cancelledText],balance:[e.colBalance,e.cancelledText],typeBadge:{icon:"DoNotDisturb",iconColor:"#9ca3af",label:d().translate("sponsor_order_grid.cancelled"),labelColor:"#9ca3af"}}}))(u),p=v(e,t),b=(null===(n=t.main_locations)||void 0===n?void 0:n[0])??(null===(a=t.locations)||void 0===a?void 0:a.find((e=>e.is_main))),{cancelled_total:g=0,refunds_total:w=0,retained:T=0,credited_to_payment_method:B=0}=e,R=(0,y.getOrderTotal)(e),F=(null===(i=e.client)||void 0===i?void 0:i.contact_name)||e.purchased_by_full_name||"",V=(null===(c=e.client)||void 0===c?void 0:c.company_name)||"",O=E(e.address)||d().translate("general.not_available");return l().createElement(s.Document,null,l().createElement(s.Page,{size:"A4",orientation:"portrait",style:u.page},l().createElement(s.View,{style:u.headerRow,wrap:!1},l().createElement(s.View,{style:u.cellLeft},o?l().createElement(s.Image,{src:o,style:u.logo}):null),l().createElement(s.View,{style:u.cellRight},l().createElement(s.Text,{style:u.invoiceTitle},d().translate("order_invoice_pdf.invoice_title")),l().createElement(x,{styles:u,label:d().translate("order_invoice_pdf.order"),value:e.number}),l().createElement(x,{styles:u,label:d().translate("order_invoice_pdf.date"),value:e.purchased_date?_(e.purchased_date,"LOC","YYYY/MM/DD hh:mm a"):d().translate("order_invoice_pdf.pending")}),l().createElement(x,{styles:u,label:d().translate("order_invoice_pdf.payment_method"),value:e.payment_method??""}),l().createElement(x,{styles:u,label:d().translate("order_invoice_pdf.status"),value:e.status??""}),l().createElement(x,{styles:u,label:d().translate("order_invoice_pdf.payment_date"),value:e.created?_(e.created,"LOC","YYYY/MM/DD hh:mm a"):"",noBorder:!0}))),l().createElement(s.View,{style:u.headerRow,wrap:!1},l().createElement(s.View,{style:u.cellLeft},l().createElement(x,{styles:u,label:d().translate("order_invoice_pdf.client"),value:`${V}\n${F}`}),l().createElement(x,{styles:u,label:d().translate("order_invoice_pdf.address"),value:O,noBorder:!0})),l().createElement(s.View,{style:u.cellRight},l().createElement(x,{styles:u,label:d().translate("order_invoice_pdf.event"),value:t.name??""}),l().createElement(x,{styles:u,label:d().translate("order_invoice_pdf.venue"),value:C(b)??""}),l().createElement(x,{styles:u,label:d().translate("order_invoice_pdf.address"),value:E(b)??"",noBorder:!0}))),l().createElement(s.View,{style:u.tableWrapper},l().createElement(s.View,{style:u.table},l().createElement(s.View,{style:u.thRow,fixed:!0},l().createElement(s.Text,{style:[u.thText,u.colCode]},d().translate("sponsor_order_grid.code")),l().createElement(s.Text,{style:[u.thText,u.colType]},d().translate("sponsor_order_grid.type")),l().createElement(s.Text,{style:[u.thText,u.colDesc]},d().translate("sponsor_order_grid.details")),l().createElement(s.Text,{style:[u.thText,u.colPrice]},d().translate("sponsor_order_grid.amount")),l().createElement(s.Text,{style:[u.thText,u.colBalance]},d().translate("sponsor_order_grid.balance"))),p.map((e=>l().createElement(D,{key:e.rowKey,row:e,styles:u,rowStyles:f}))),g||w||T||B?l().createElement(S,{styles:u,cancelledTotal:g,refundsTotal:w,retained:T,credited:B}):null,l().createElement(s.View,{style:u.tdAmountDue},l().createElement(s.Text,{style:u.tdAmountDueLabel},d().translate("sponsor_order_grid.amount_due")),l().createElement(s.View,{style:{width:"18%"}}),l().createElement(s.Text,{style:[u.tdAmountDueValue,{color:(R??0)>0?"#e65100":"#1b5e20"}]},(0,y.formatBalance)(R??0)))))))};R.propTypes={order:i().object.isRequired,summit:i().object.isRequired,logoSrc:i().string,theme:i().object};const F=async(e,t,{logoSrc:o,theme:r}={})=>{try{const n=await(0,s.pdf)(l().createElement(R,{order:e,summit:t,logoSrc:o,theme:r})).toBlob(),a=URL.createObjectURL(n),i=document.createElement("a");i.href=a,i.download=`invoice-${e.number}.pdf`.toLowerCase().replace(/\s+/g,"-"),document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout((()=>URL.revokeObjectURL(a)),6e4)}catch(e){throw console.error("Error generating invoice PDF:",e),e}},V=async(e,t,{logoSrc:o,theme:r}={})=>{const n=window.open("","_blank");try{const a=await(0,s.pdf)(l().createElement(R,{order:e,summit:t,logoSrc:o,theme:r})).toBlob(),i=URL.createObjectURL(a);return n?(n.location.href=i,void setTimeout((()=>URL.revokeObjectURL(i)),6e4)):(URL.revokeObjectURL(i),F(e,t,{logoSrc:o,theme:r}))}catch(e){throw console.error("Error generating invoice PDF preview:",e),n&&n.close(),e}};return r})()));
//# sourceMappingURL=order-invoice-pdf.js.map