1"use strict";(self.webpackChunkdatta_able_free_react_admin_template=self.webpackChunkdatta_able_free_react_admin_template||[]).push([[5505],{32465:(e,t,n)=>{n.d(t,{A:()=>s});var a=n(89379),o=n(9950),r=n(28429),l=n(44414);const s=e=>t=>{const n=(0,r.Zp)(),[s,i]=(0,o.useState)(!1);return(0,o.useEffect)((()=>{localStorage.getItem("userEmail")?i(!0):n("/auth/signin-1",{replace:!0})}),[n]),s?(0,l.jsx)(e,(0,a.A)({},t)):null}},95505:(e,t,n)=>{n.r(t),n.d(t,{default:()=>b});var a=n(89379),o=n(9950),r=n(5216),l=n(28429),s=n(62578),i=n(43203),c=n(4695),d=n.n(c),u=n(75261),m=(n(58489),n(32465)),h=n(39124),p=n(55142),x=n(97937),y=n(44414);const f=(0,m.A)((e=>{let{show:t,handleClose:n,documentId:r,grandTotal:l,tableId:i}=e;const[c,d]=(0,o.useState)("cash"),[u,m]=(0,o.useState)(0),[f,g]=(0,o.useState)(0),[b,j]=(0,o.useState)("googlepay"),[A,v]=(0,o.useState)(0),[C,I]=(0,o.useState)(0),[N,S]=(0,o.useState)(0),[w,D]=(0,o.useState)(0),[k,E]=(0,o.useState)(""),[F,O]=(0,o.useState)("");(0,o.useEffect)((()=>{"cash"===c?(m(l),v(0),g(0),I(0)):"card"===c||"other"===c?(m(0),v(l),g(0),I(0)):"part"===c?(m(0),v(0),g(0),I(l)):"due"===c&&(m(0),v(0),g(0),I(l),D(l))}),[l,c]),(0,o.useEffect)((()=>{T()}),[u,A,c]);const T=()=>{let e=0;"cash"===c?e=Math.min(u,l):"card"===c||"other"===c?e=A:"part"===c?e=u+A:"due"===c&&(e=0),S(e)},R=e=>{d(e.target.value)},P=e=>{const t=parseFloat(e.target.value)||0;if(m(t),"cash"===c){const e=Math.max(0,t-l);g(e),I(Math.max(0,l-t))}else if("part"===c){const e=Math.max(0,l-t-A);I(e)}},G=e=>{const t=parseFloat(e.target.value)||0;if(v(t),"card"===c||"other"===c)I(Math.max(0,l-t));else if("part"===c){const e=Math.max(0,l-u-t);I(e)}};async function _(e,t,n,a){const o=(0,s.KR)(a,"menus/".concat(e)),r=await(0,s.Jt)(o);if(!r.exists())return;const l=r.val();if(l.parentEmail!==n)return void console.error("Menu item does not belong to the parentEmail: ".concat(n));const i=new Date;K(l.weekResetDate,i,"week")?(l.weeklySales=t,l.weekResetDate=M(i),l.weekReset=!1):l.weeklySales=(l.weeklySales||0)+t;K(l.monthResetDate,i,"month")?(l.monthlySales=t,l.monthResetDate=M(i),l.monthReset=!1):l.monthlySales=(l.monthlySales||0)+t;K(l.yearResetDate,i,"year")?(l.yearlySales=t,l.yearResetDate=M(i),l.yearReset=!1):l.yearlySales=(l.yearlySales||0)+t,await(0,s.yo)(o,l)}function K(e,t,n){if(!e)return!0;const a=new Date(e);switch(n){case"week":return 1===t.getDay()&&(1!==a.getDay()||function(e,t){const n=864e5;return Math.round(Math.abs((t-e)/n))}(a,t)>=7);case"month":return 1===t.getDate()&&(1!==a.getDate()||(r=t,!((o=a).getFullYear()===r.getFullYear()&&o.getMonth()===r.getMonth())));case"year":return 0===t.getMonth()&&1===t.getDate()&&(0!==a.getMonth()||1!==a.getDate()||!function(e,t){return e.getFullYear()===t.getFullYear()}(a,t));default:return!1}var o,r}function M(e){return e.toISOString().split("T")[0]}async function L(e,t,n,a){const o=(0,s.KR)(a,"menus/".concat(e)),r=await(0,s.Jt)(o);if(!r.exists())return{insufficientInventory:!1};const l=r.val();if(l.parentEmail!==n)return{insufficientInventory:!1};let i=!1;if(l.recipe&&l.recipe.rawMaterials)for(const s of l.recipe.rawMaterials){(await q(s,t,n,a)).insufficientInventory&&(i=!0)}return{insufficientInventory:i}}async function q(e,t,n,o){const r=(0,s.P)((0,s.KR)(o,"closingStock"),(0,s.kT)("name"),(0,s.iz)(e.item)),l=await(0,s.Jt)(r);if(!l.exists())return{insufficientInventory:!0};let i=parseFloat(e.quantity)*t,c=[];l.forEach((e=>{const t=e.val();t.parentEmail===n&&c.push((0,a.A)({key:e.key},t))})),c.sort(((e,t)=>"Never Expire"===e.expireDate?1:"Never Expire"===t.expireDate?-1:new Date(e.expireDate)-new Date(t.expireDate)));const d=e=>Math.round(1e3*e)/1e3;for(const a of c){const t=(u=a.quantityType,m=e.quantityType,{gram_to_kilogram:.001,kilogram_to_gram:1e3,milliliter_to_litre:.001,litre_to_milliliter:1e3}["".concat(u,"_to_").concat(m)]||1),n=d(a.quantity*t),r=d(Math.min(i,n)),l=d(n-r),c=d(l/t),h=(0,s.KR)(o,"closingStock/".concat(a.key));if(c<=0?await(0,s.TF)(h):await(0,s.yo)(h,{quantity:c}),i=d(i-r),i<=0)break}var u,m;return i>0?{insufficientInventory:!0}:{insufficientInventory:!1}}return(0,y.jsxs)(h.A,{show:t,onHide:n,className:"settlement-modal",children:[(0,y.jsx)(h.A.Header,{closeButton:!0,children:(0,y.jsx)(h.A.Title,{children:"Settlement"})}),(0,y.jsx)(h.A.Body,{children:(0,y.jsxs)(p.A,{children:[(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formGrandTotal",children:[(0,y.jsx)(p.A.Label,{children:"Grand Total"}),(0,y.jsx)(p.A.Control,{type:"text",placeholder:"Grand Total",value:"\u20b9 ".concat(l),readOnly:!0})]}),(0,y.jsxs)(p.A.Group,{className:"mb-3",children:[(0,y.jsx)(p.A.Label,{children:"Payment Type"}),(0,y.jsxs)("div",{className:"payment-type-options",children:[(0,y.jsx)(p.A.Check,{type:"radio",id:"cash",label:"Cash",value:"cash",checked:"cash"===c,onChange:R}),(0,y.jsx)(p.A.Check,{type:"radio",id:"card",label:"Card",value:"card",checked:"card"===c,onChange:R}),(0,y.jsx)(p.A.Check,{type:"radio",id:"other",label:"Other",value:"other",checked:"other"===c,onChange:R}),(0,y.jsx)(p.A.Check,{type:"radio",id:"part",label:"Part",value:"part",checked:"part"===c,onChange:R}),(0,y.jsx)(p.A.Check,{type:"radio",id:"due",label:"Due",value:"due",checked:"due"===c,onChange:R})]})]}),"cash"===c&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formCashIn",children:[(0,y.jsx)(p.A.Label,{children:"Cash In"}),(0,y.jsx)(p.A.Control,{type:"number",placeholder:"Cash In",value:u,onChange:P})]}),(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formReturnToCustomer",children:[(0,y.jsx)(p.A.Label,{children:"Return To Customer"}),(0,y.jsx)(p.A.Control,{type:"text",placeholder:"Return To Customer",value:"\u20b9 ".concat(f),readOnly:!0})]})]}),"card"===c&&(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formOnlineAmount",children:[(0,y.jsx)(p.A.Label,{children:"Amount Paid"}),(0,y.jsx)(p.A.Control,{type:"number",placeholder:"Amount Paid",value:A,onChange:G})]}),"other"===c&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formOnlineType",children:[(0,y.jsx)(p.A.Label,{children:"Online Type"}),(0,y.jsxs)(p.A.Control,{as:"select",value:b,onChange:e=>j(e.target.value),children:[(0,y.jsx)("option",{value:"googlepay",children:"Google Pay"}),(0,y.jsx)("option",{value:"phonepay",children:"Phone Pay"}),(0,y.jsx)("option",{value:"paytm",children:"Paytm"}),(0,y.jsx)("option",{value:"qr",children:"QR"}),(0,y.jsx)("option",{value:"zomato",children:"Zomato"}),(0,y.jsx)("option",{value:"eazydiner",children:"Eazy Diner"}),(0,y.jsx)("option",{value:"zomatopro",children:"Zomato Pro"}),(0,y.jsx)("option",{value:"other",children:"Other"})]})]}),(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formOnlineAmount",children:[(0,y.jsx)(p.A.Label,{children:"Online Amount"}),(0,y.jsx)(p.A.Control,{type:"number",placeholder:"Online Amount",value:A,onChange:G})]})]}),"part"===c&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formCashIn",children:[(0,y.jsx)(p.A.Label,{children:"Cash In"}),(0,y.jsx)(p.A.Control,{type:"number",placeholder:"Cash In",value:u,onChange:P})]}),(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formOnlineType",children:[(0,y.jsx)(p.A.Label,{children:"Online Type"}),(0,y.jsxs)(p.A.Control,{as:"select",value:b,onChange:e=>j(e.target.value),children:[(0,y.jsx)("option",{value:"googlepay",children:"Google Pay"}),(0,y.jsx)("option",{value:"phonepay",children:"Phone Pay"}),(0,y.jsx)("option",{value:"paytm",children:"Paytm"}),(0,y.jsx)("option",{value:"qr",children:"QR"}),(0,y.jsx)("option",{value:"other",children:"Other"})]})]}),(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formOnlineAmount",children:[(0,y.jsx)(p.A.Label,{children:"Online Amount"}),(0,y.jsx)(p.A.Control,{type:"number",placeholder:"Online Amount",value:A,onChange:G})]})]}),"due"===c&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formDueAmount",children:[(0,y.jsx)(p.A.Label,{children:"Due Amount"}),(0,y.jsx)(p.A.Control,{type:"number",placeholder:"Due Amount",value:w,onChange:e=>D(e.target.value)})]}),(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formCustomerName",children:[(0,y.jsx)(p.A.Label,{children:"Customer Name"}),(0,y.jsx)(p.A.Control,{type:"text",placeholder:"Customer Name",value:k,onChange:e=>E(e.target.value)})]}),(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formContactNumber",children:[(0,y.jsx)(p.A.Label,{children:"Contact Number"}),(0,y.jsx)(p.A.Control,{type:"text",placeholder:"Contact Number",value:F,onChange:e=>O(e.target.value)})]})]}),(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formRemainingAmou
1nt",children:[(0,y.jsx)(p.A.Label,{children:"Remaining Amount"}),(0,y.jsx)(p.A.Control,{type:"text",placeholder:"Remaining Amount",value:"\u20b9 ".concat(C),readOnly:!0})]}),(0,y.jsxs)(p.A.Group,{className:"mb-3",controlId:"formSettlementAmount",children:[(0,y.jsx)(p.A.Label,{children:"Settlement Amount"}),(0,y.jsx)(p.A.Control,{type:"text",placeholder:"Settlement Amount",value:"\u20b9 ".concat(N),readOnly:!0})]})]})}),(0,y.jsxs)(h.A.Footer,{children:[(0,y.jsx)(x.A,{variant:"secondary",onClick:n,children:"Close"}),(0,y.jsx)(x.A,{variant:"primary",onClick:async()=>{try{if(!r)return void console.error("Document ID is not defined.");const e=(0,s.C3)(),t=localStorage.getItem("parentEmail");if(!t)return void console.error("Parent email not found in local storage.");const o=t.replace(/\./g,","),d=(0,s.KR)(e,"accounts/".concat(o)),m=await(0,s.Jt)(d);if(!m.exists())return void console.error("Account not found for Parent Email: ".concat(o));const h=m.val().orderId||0;await(0,s.yo)(d,{orderId:h+1});const p=(0,s.KR)(e,"accountPermissions/".concat(o)),x=await(0,s.Jt)(p);if(!x.exists())return void console.error("Permissions not found for Parent Email: ".concat(o));const y=x.val().AutoDeduction||!1,g=(0,s.KR)(e,"orderHistory/".concat(r)),j=await(0,s.Jt)(g);if(!j.exists())return void console.error("No order found for Document ID:",r);const v=j.val();if(v.parentEmail!==t)return void console.error("Order does not belong to the current user:",r,t);const I=(0,a.A)((0,a.A)((0,a.A)({},v),{},{orderId:h,settlement:{paymentType:c,cashIn:"card"===c?0:u,returnToCustomer:f,onlineType:"part"===c||"other"===c?b:"",onlineAmount:"card"===c?l:A,remainingAmount:C,settlementAmount:N}},k&&{customerName:k}),F&&{contactNumber:F});await(0,s.yo)(g,I);let S=!1;if(y){for(const n of v.orderItems){(await L(n.menuItemId,n.quantity,t,e)).insufficientInventory&&(S=!0)}S&&console.warn("Some items had insufficient inventory. Order processed with available stock.")}for(const n of v.orderItems)await _(n.menuItemId,n.quantity,t,e);if(i){const t=(0,s.KR)(e,"runningTables/".concat(i)),n=await(0,s.Jt)(t);if(n.exists()){const e=n.val(),a={};["tableName","tableNumber","parentEmail","floorId","floorName"].forEach((t=>{e[t]&&(a[t]=e[t])})),a.date=(new Date).toISOString(),a.orderItems=[],a.customerName="",a.tableStatus=0,a.OrderHistoryDocID="",a.mobileNumber="",a.personCount=0,await(0,s.yo)(t,a)}else console.error("Table not found for:",i)}n()}catch(e){console.error("Error in handleSave function:",e)}},children:"Save Changes"})]})]})})),g={0:"#EEEDEB",1:"#FFFFE0",2:"#FFF078",3:"#CDE8E5"},b=(0,m.A)((()=>{const[e,t]=(0,o.useState)([]),[n,c]=(0,o.useState)([]),[m,h]=(0,o.useState)(!1),[p,x]=(0,o.useState)(""),[b,j]=(0,o.useState)(""),[A,v]=(0,o.useState)(""),[C,I]=(0,o.useState)(""),N=(0,l.Zp)(),S=localStorage.getItem("parentEmail");localStorage.getItem("userAuthority");(0,o.useEffect)((()=>{(()=>{if(!S)return void console.error("Parent email not available or null.");const e=(0,s.KR)(i.db,"floors");(0,s.Zy)(e,(e=>{const n=e.val();if(n){const e=Object.keys(n).filter((e=>n[e].parentEmail===S)).map((e=>(0,a.A)({id:e},n[e])));t(e)}else t([])}),(e=>{console.error("Error fetching floors:",e),t([])}))})(),(()=>{if(!S)return void console.error("Parent email not available or null.");const e=(0,s.KR)(i.db,"runningTables"),t=(0,s.P)(e,(0,s.kT)("parentEmail"),(0,s.iz)(S));(0,s.Zy)(t,(e=>{const t=e.val();if(t){const e=Object.keys(t).map((e=>(0,a.A)({id:e},t[e])));c(e)}else c([]),d().fire({title:"No Data Found",text:"Set area first",icon:"warning",confirmButtonText:"Go"}).then((()=>{N("/basic/DiningSetting")}))}),(e=>{console.error("Error fetching running tables:",e),c([])}))})()}),[N,S]);const w=(e,t,n,a)=>{N("/views/tableorder/".concat(e,"/").concat(t,"/").concat(encodeURIComponent(n),"/").concat(a))},D=e=>{const t=n.find((t=>t.id===e.id));console.log("Order History Document Id",t.OrderHistoryDocID),console.log("Order History Document Id",t.orderId),t&&(x(t.orderId),v(t.grandTotal),I(t.id),j(t.OrderHistoryDocID),h(!0))};return(0,y.jsxs)("div",{className:"tables-page",children:[(0,y.jsxs)("div",{className:"legend",children:[(0,y.jsxs)("div",{className:"legend-item",children:[(0,y.jsx)("div",{className:"legend-color",style:{backgroundColor:"#EEEDEB"}}),(0,y.jsx)("span",{children:"Available"})]}),(0,y.jsxs)("div",{className:"legend-item",children:[(0,y.jsx)("div",{className:"legend-color",style:{backgroundColor:"#FFF078"}}),(0,y.jsx)("span",{children:"Billed"})]})]}),e.map((e=>(0,y.jsxs)(r.A,{className:"mb-3",children:[(0,y.jsx)(r.A.Header,{as:"h5",children:e.floorName}),(0,y.jsx)(r.A.Body,{children:(0,y.jsx)("div",{className:"table-grid",children:[...Array(e.numberOfTables)].map(((t,a)=>{const o=a+1,r=n.find((t=>t.floorId===e.id&&t.tableNumber===o));if(r){const t=g[r.tableStatus]||"#FFFFFF";return(0,y.jsxs)("div",{className:"table-box",style:{backgroundColor:t},onClick:()=>2!==r.tableStatus&&w(e.id,o,e.floorName,r.id),onKeyDown:t=>{"Enter"!==t.key&&" "!==t.key||2!==r.tableStatus&&w(e.id,o,e.floorName,r.id)},role:"button",tabIndex:0,children:[(0,y.jsx)("button",{onClick:()=>w(e.id,o,e.floorName,r.id),onKeyDown:t=>handleKeyPress(t,(()=>
1w(e.id,o,e.floorName,r.id))),tabIndex:-1,children:o}),2===r.tableStatus&&(0,y.jsxs)("div",{className:"icon-container",children:[(0,y.jsx)("span",{className:"icon-wrapper",role:"button",tabIndex:"0",onClick:()=>w(e.id,o,e.floorName,r.id),onKeyDown:t=>handleKeyPress(t,(()=>w(e.id,o,e.floorName,r.id))),title:"View",children:(0,y.jsx)(u.Ny1,{className:"icon"})}),"waiter"!=localStorage.getItem("userAuthority")&&(0,y.jsx)("span",{className:"icon-wrapper",role:"button",tabIndex:"0",onClick:()=>D(r),onKeyDown:e=>handleKeyPress(e,(()=>D(r))),title:"Invoice",children:(0,y.jsx)(u.xXS,{className:"icon"})})]})]},a)}return null}))})})]},e.id))),(0,y.jsx)(f,{show:m,handleClose:()=>{h(!1),x(""),v(""),I("")},orderId:p,documentId:b,grandTotal:parseFloat(A),tableId:C})]})}))},58489:()=>{}}]);
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.