CB
Welcome
Back
Sign in to access your account
Email / Login ID
Password
Show
Remember Me
Forgot Password?
Login
or
Don’t have an account?
Create Company
Terms of Service
Privacy Policy
Help
<!doctype html> <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"> <title>Commerce Book ERP · Dashboard</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css"> <style> *{box-sizing:border-box}body{margin:0;background:#f5f7fa;color:#192a40;font:13px Inter,system-ui,sans-serif} button{font:inherit;color:inherit}.layout{display:grid;grid-template-columns:224px minmax(0,1fr);min-height:100dvh}.layout.collapsed{grid-template-columns:minmax(0,1fr)}.collapsed aside{display:none} aside{background:#fff;border-right:1px solid #e1e7ef;padding:18px 14px}.company{display:flex;gap:10px;align-items:center;padding:0 6px 18px;border-bottom:1px solid #e9edf3}.avatar{width:34px;height:34px;display:grid;place-items:center;border-radius:50%;background:#e6f4ec;color:#1c704b;font-weight:800;flex:none}.company small{display:block;color:#5c6e84;margin-top:2px} nav{margin-top:14px}nav p{font-size:11px;color:#607187;margin:13px 0 4px 8px}.nav-row{display:flex;align-items:center;gap:10px;padding:6px 9px;border-radius:7px}.nav-row i{width:16px;text-align:center}.active{background:#eaf5ee;color:#196748;font-weight:750} main{min-width:0}.topbar{background:#fff;border-bottom:1px solid #e1e7ef;display:flex;gap:12px;align-items:center;padding:8px clamp(12px,2vw,28px);min-height:46px}.topbar button{background:#f1f5f8;border:1px solid #e1e7ef;border-radius:7px;padding:5px 9px;cursor:pointer}.topbar strong{margin-left:auto} .content{container-type:inline-size;padding:16px clamp(12px,2vw,28px) 24px}.intro{margin:0 0 14px}.intro h1{font-size:16px;margin:0 0 3px}.intro span{color:#196748}.intro p,.caption{margin:0;color:#52657d;font-size:12px} .summary,.analytics,.reports{display:grid;gap:12px;grid-template-columns:minmax(0,1fr)}.analytics,.reports{margin-top:14px} @container(min-width:480px){.summary{grid-template-columns:repeat(2,minmax(0,1fr))}} @container(min-width:900px){.summary{grid-template-columns:repeat(4,minmax(0,1fr))}.analytics{grid-template-columns:minmax(0,2fr) minmax(0,1fr)}.reports{grid-template-columns:repeat(2,minmax(0,1fr))}} .card,.panel{min-width:0;background:#fff;border:1px solid #e0e7f0;border-radius:13px;padding:14px;box-shadow:0 3px 10px #23385a06}.card{display:flex;flex-direction:column;overflow-wrap:anywhere} .card header{display:flex;align-items:center;gap:9px}.icon{width:34px;height:34px;display:grid;place-items:center;flex:none;border-radius:9px;color:var(--ink);background:var(--tint)}.green{--ink:#16764b;--tint:#e7f6ee}.amber{--ink:#a3510c;--tint:#fff2df}.blue{--ink:#225dca;--tint:#eaf1ff}.violet{--ink:#6044bd;--tint:#f0ebff} h2,h3{font-size:13px;margin:0}.balance{font-size:clamp(20px,2vw,27px);font-weight:750;letter-spacing:-.035em;margin:8px 0 2px}.balance,dd,td:not(:first-child){font-variant-numeric:tabular-nums} .breakdown{margin-top:10px;padding-top:8px;border-top:1px solid #e7edf4}h3{font-size:11px;color:#3e526a}dl{margin:4px 0 0;font-size:12px}dl div{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:6px;padding:1px 0}dt{color:#52657d}dd{margin:0;text-align:right;font-weight:650} .plot{margin-top:12px;display:grid;grid-template-columns:auto minmax(0,1fr);gap:8px}.scale{display:flex;flex-direction:column;justify-content:space-between;padding-bottom:22px;color:#5b6d83;font-size:10px}.plot svg{display:block;width:100%;height:clamp(130px,17vw,200px);background:repeating-linear-gradient(to bottom,#e7edf3 0 1px,transparent 1px 20%);border-bottom:1px solid #e7edf3}.dates{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:2px;text-align:center;color:#52657d;font-size:10px;margin-top:5px} .distribution{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:20px;min-height:165px}.donut{width:116px;aspect-ratio:1;border:16px solid #23835f;border-radius:50%;display:grid;place-content:center;text-align:center;font-weight:800;font-size:19px}.donut small{font-size:10px;color:#52657d}.legend{flex:1 1 115px;max-width:220px}.legend div{grid-template-columns:minmax(0,1fr) auto;padding:4px 0}.dot{display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:6px;background:var(--dot)} .table-wrap{overflow:auto;margin-top:9px}table{border-collapse:collapse;width:100%;min-width:320px}th,td{padding:5px 8px;text-align:left;border-bottom:1px solid #ebeff5;white-space:nowrap}th{background:#f1f5f9;color:#45596f;font-size:11px}th:not(:first-child),td:not(:first-child){text-align:right}.reports section:last-child tr:last-child td{font-weight:800;background:#eaf5ee}.note{margin:8px 0 0;color:#52657d;font-size:11px} @media(max-width:720px){.layout{grid-template-columns:minmax(0,1fr)}aside{display:none}.layout:not(.collapsed).mobile-open aside{display:block;position:fixed;inset:0 auto 0 0;width:min(224px,85vw);overflow:auto;z-index:1;box-shadow:0 0 0 100vmax #182a4050}.topbar{position:relative;z-index:2}} .topbar .intro{margin:0;min-width:0} .topbar .intro h1{font-size:14px;margin-bottom:1px} .topbar .intro p{font-size:11px;overflow-wrap:anywhere} .topbar button{flex:none} .layout.collapsed{grid-template-columns:56px minmax(0,1fr)} .collapsed aside{display:block;padding:14px 6px} .collapsed .company{padding:0 0 14px;justify-content:center} .collapsed .company div,.collapsed nav p,.collapsed .nav-row span{display:none} .collapsed .nav-row{justify-content:center;min-height:34px;padding:4px} @media(max-width:720px){ .layout{grid-template-columns:48px minmax(0,1fr)} .layout aside{display:block;padding:14px 4px} .layout:not(.mobile-open) .company{justify-content:center;padding:0 0 14px} .layout:not(.mobile-open) .company div,.layout:not(.mobile-open) nav p,.layout:not(.mobile-open) .nav-row span{display:none} .layout:not(.mobile-open) .nav-row{justify-content:center;min-height:34px;padding:4px} .topbar>strong{display:none} } /* Compact accounting dashboard typography and spacing */ body{font-size:13px;line-height:1.35} aside{padding:12px 10px}.company{padding-bottom:10px} nav{margin-top:8px}nav p{margin:9px 0 3px 8px} .nav-row{padding:5px 8px} .topbar{padding:5px 16px;min-height:42px;gap:9px} .content{padding:9px 16px 16px} .summary,.analytics,.reports{gap:8px} .analytics,.reports{margin-top:8px} .card,.panel{padding:10px;border-radius:10px;box-shadow:none} .card header{gap:7px}.icon{width:28px;height:28px;border-radius:7px} h2{font-size:13px;font-weight:650} .balance{font-size:22px;font-weight:700;margin:4px 0 1px} .breakdown{margin-top:6px;padding-top:5px} h3{font-size:12px;font-weight:650} dl{margin-top:3px}dl div{padding:0;line-height:1.4} .plot{margin-top:7px}.plot svg{height:clamp(168px,15vw,240px)} .distribution{gap:12px;min-height:0;margin-top:9px} .analytics .panel:last-child{display:flex;flex-direction:column} .distribution{flex:1;min-height:168px} .donut{width:clamp(100px,10vw,132px);border-width:14px;font-size:17px} .legend div{padding:2px 0} .table-wrap{margin-top:5px} th,td{padding:3px 7px;font-size:12px} .note{margin-top:5px} @media(max-width:720px){ .topbar{padding:5px 8px}.content{padding:8px} .topbar .intro p,.caption{font-size:12px} h2,dl,th,td{font-size:13px} .balance{font-size:20px} .dates,.scale{font-size:11px} .layout:not(.mobile-open) .nav-row{min-height:32px} } @media(max-width:720px){ .layout>aside{position:sticky;top:0;align-self:start;height:100dvh;overflow:auto;scrollbar-width:none} .layout:not(.collapsed).mobile-open aside{top:0;height:100dvh;padding-top:56px} .topbar{min-height:50px} .topbar button{min-width:40px;min-height:40px} .layout:not(.mobile-open) .nav-row{min-height:40px} .summary,.analytics,.reports{gap:8px} .card,.panel{padding:9px} .card header{gap:5px} .card .icon{width:24px;height:24px} .plot svg{height:clamp(138px,32vw,200px)} .dates span{white-space:nowrap} .dates span:nth-child(even){visibility:hidden} .distribution{min-height:132px} .table-wrap{max-width:100%;overscroll-behavior-inline:contain} } @media(max-width:720px){ @container(min-width:312px){ .summary{grid-template-columns:repeat(2,minmax(0,1fr))} } } .mobile-company,.mobile-nav,.mobile-panel{display:none} @media(max-width:720px){ .layout,.layout.collapsed{grid-template-columns:minmax(0,1fr)} .layout>aside,.layout:not(.collapsed).mobile-open aside,.topbar #menu,.topbar .intro{display:none} .topbar{padding:6px 10px} .mobile-company{display:flex;align-items:center;gap:8px} .mobile-company strong{margin:0} .content{padding-bottom:calc(68px + env(safe-area-inset-bottom))} .mobile-nav{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));position:fixed;inset:auto 0 0;margin:0;z-index:5;background:#fff;border-top:1px solid #e1e7ef;padding:3px 0 env(safe-area-inset-bottom)} .mobile-nav button{min-width:0;min-height:49px;border:0;background:transparent;display:grid;place-content:center;justify-items:center;gap:3px;padding:3px 1px;font-size:clamp(9px,2.8vw,11px);cursor:pointer} .mobile-nav i{font-size:16px}.mobile-nav [aria-current],.mobile-nav [aria-expanded=true]{color:#196748;background:#eaf5ee;font-weight:700} .mobile-panel:not([hidden]){display:block;position:fixed;inset:auto 8px calc(59px + env(safe-area-inset-bottom));z-index:4;background:white;border:1px solid #e1e7ef;border-radius:10px;padding:12px;box-shadow:0 4px 20px #182a4030;max-height:55dvh;overflow:auto} .mobile-panel ul{margin:6px 0 0;padding-left:18px}.mobile-panel li{padding:3px 0} } .analytics .panel,.reports .panel{background:transparent} /* Dashboard surfaces and financial status */ body{color:#192e38;background:#f5f7fa} .summary .card{border-color:#dce5ec;border-radius:12px;border-top:2px solid var(--ink);padding:11px 12px} .summary .card header{gap:8px} .summary .card h2{color:#294150} .balance{letter-spacing:-.035em;font-weight:750} .balance.negative{color:#a62d32} .breakdown h3{color:#314954} .breakdown dt,.caption{color:#526571} .analytics .panel,.reports .panel{border:0;border-radius:0;padding:10px 8px;background:transparent} .analytics .panel h2,.reports .panel h2{display:flex;align-items:center;gap:7px;font-size:14px} .analytics .panel h2::before,.reports .panel h2::before{content:"";width:3px;height:13px;border-radius:2px;background:#24805d;flex:none} .plot{margin-top:10px} .donut{color:#166349;box-shadow:0 0 0 4px #e4eee9} .table-wrap{border-block:1px solid #dce5ec;margin-top:8px} th{background:#eaf0f4;color:#344f5e;font-weight:650} td{border-color:#e1e8ee} tbody tr:nth-child(even){background:#edf2f6} .reports section:last-child tr:last-child td{background:#e1f1e8;color:#145839} @container(min-width:900px){ .analytics .panel+.panel,.reports .panel+.panel{border-inline-start:1px solid #dce5ec;padding-inline-start:12px} } @media(max-width:720px){ .summary .card{padding:8px} .analytics .panel,.reports .panel{padding-inline:2px} .analytics .panel+.panel,.reports .panel+.panel{border-block-start:1px solid #dce5ec} } :root{--text:#203642;--muted:#4b616d;--line:#d6e1e7;--focus:#16684d} body{color:var(--text)} .card h2,.panel h2{font-weight:650} .balance,dd,td:not(:first-child){font-variant-numeric:lining-nums tabular-nums} .balance{font-weight:700} .caption,.breakdown dt,.legend dt,.scale,.dates,.note{color:var(--muted)} .breakdown h3{font-weight:650} th,td{border-bottom-color:var(--line)} .reports .panel:first-child :is(th,td):nth-child(3){text-align:center} .reports .panel:last-child tbody tr:last-child td{border-top:1px solid #bcd8cb} :focus-visible{outline:1px solid #687f8c;outline-offset:-1px} .table-wrap:focus-visible{outline-offset:-2px} @media(max-width:720px){ .mobile-nav button{min-height:52px} .dates,.scale{font-size:11px} } @media(forced-colors:active){ .mobile-nav [aria-current],.mobile-nav [aria-expanded=true]{border-top:2px solid Highlight} } .analytics,.reports{gap:12px} .analytics .panel,.reports .panel{padding:10px 8px} .analytics .panel h2,.reports .panel h2{font-size:14px;font-weight:650;line-height:1.3} .plot,.table-wrap{margin-top:9px} .scale,.dates{font-size:11px} .distribution{display:grid;grid-template-columns:auto minmax(0,1fr);align-content:center;gap:16px;width:min(100%,310px);margin:9px auto 0;min-height:0} .distribution .donut{width:clamp(94px,8vw,120px);box-shadow:none} .legend{max-width:none;margin:0} .legend div{column-gap:10px;padding:4px 0} .table-wrap{border:1px solid var(--line);border-radius:7px} .reports th{background:#e7eef3;color:#2a4351;font-size:12px} .reports th,.reports td{padding:5px 8px} .reports section:last-child tbody tr:last-child td{background:#e0efe7;color:#145839;font-weight:700} @container(max-width:360px){ .distribution{gap:10px} .distribution .donut{width:84px;border-width:11px} } @media(max-width:720px){ .analytics .panel,.reports .panel{padding-inline:2px} .distribution{min-height:124px} } .nav-group{position:relative}.nav-group summary,.mobile-panel summary{cursor:pointer}.nav-group summary{list-style:none}.nav-group summary::-webkit-details-marker{display:none}.nav-group summary::after{content:"›";margin-inline-start:auto}.nav-group[open] summary::after{transform:rotate(90deg)}.sub-menu{list-style:none;margin:2px 0 4px 19px;padding:0 0 0 10px;border-inline-start:1px solid #d6e1e7;color:#395266}.sub-menu li{padding:4px 0}.collapsed .nav-group summary::after{display:none}.collapsed .nav-group>.sub-menu{position:absolute;z-index:8;left:100%;top:0;margin:0;min-width:150px;padding:6px 12px;background:#fff;border:1px solid #d6e1e7;border-radius:7px}.mobile-panel summary{padding-block:5px} @media(max-width:720px){ .mobile-panel:not([hidden]){padding:12px;border-radius:14px;box-shadow:0 8px 28px #182a4026} .mobile-panel h2{display:flex;align-items:center;min-height:44px;padding-right:48px;border-bottom:1px solid #e1e7ef} .mobile-panel-close{position:absolute;top:7px;right:8px;width:44px;height:44px;border:0;border-radius:9px;background:transparent;color:#395266;font-size:24px;line-height:1;cursor:pointer} .mobile-panel-close:hover,.mobile-panel-close:focus-visible{background:#edf3f6} .mobile-panel>ul{list-style:none;padding:0;margin:5px 0 0} .mobile-panel>ul>li{padding:0;border-bottom:1px solid #edf1f4} .mobile-panel>ul>li:not(:has(details)){padding:10px} .mobile-panel summary{list-style:none;display:flex;align-items:center;justify-content:space-between;min-height:42px;padding:7px 10px;font-weight:600} .mobile-panel summary::-webkit-details-marker{display:none} .mobile-panel summary::after{content:"›";font-size:18px;color:#52657d} .mobile-panel details[open]>summary{background:#edf6f0;color:#196748;border-radius:7px} .mobile-panel details[open]>summary::after{transform:rotate(90deg)} .mobile-panel ul.sub-menu{padding-left:12px;margin:4px 0 7px 12px} .mobile-panel .sub-menu li{padding:6px 0} } .customer-link,.customer-back{border:0;background:none;color:#196748;padding:4px;cursor:pointer;text-align:left} .customer-heading,.customer-toolbar,.customer-pagination,.customer-dialog-heading{display:flex;justify-content:space-between;align-items:center;gap:8px;flex-wrap:wrap} .customer-heading h1{font-size:22px;margin:4px 0}.customer-heading p{margin:0;color:#52657d}.customer-actions{display:flex;flex-wrap:wrap;gap:6px} .customers button:not(.customer-back),.customers select,.customers input{border:1px solid #d6e1e7;background:#fff;border-radius:6px;padding:6px 9px;color:inherit;font:inherit} .customers button{cursor:pointer}.customers button:disabled{opacity:.55;cursor:default} .customers #new-customer,.customers #customer-save{background:#196748;color:white;border-color:#196748;font-weight:650} .customer-summary{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;margin:12px 0} .customer-summary div{display:block;padding:8px 10px;background:#fff;border:1px solid #d6e1e7;border-radius:8px} .customer-summary dd{margin:3px 0 0;text-align:left;font-size:16px;overflow-wrap:anywhere} .customer-toolbar{margin:8px 0}.customer-toolbar input{width:min(52vw,230px)} .customer-table{min-width:0;background:#fff}.customer-table th,.customer-table td{padding:5px 7px;white-space:normal;overflow-wrap:anywhere;text-align:left} .customer-table :is(th,td):nth-child(7){text-align:right;font-variant-numeric:tabular-nums}.customer-table :is(th,td):nth-child(8){text-align:center} .customer-table th button{padding:0;border:0;background:none;font-weight:700;text-align:inherit} .customer-pagination{margin-top:10px}.customer-avatar{display:inline-grid;place-items:center;width:24px;height:24px;border-radius:50%;background:#eaf5ee;color:#196748} .customers dialog{width:min(420px,calc(100% - 24px));border:1px solid #d6e1e7;border-radius:12px;color:inherit;padding:14px}.customers dialog::backdrop{background:#20364266} #customer-dialog-body{display:grid;gap:8px;margin:10px 0}#customer-dialog-body label{display:grid;gap:4px} @container(max-width:760px){ .customer-table,.customer-table tbody{display:block}.customer-table thead{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)} .customer-table tbody tr{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:3px 8px;margin-bottom:7px;padding:8px;background:#fff;border:1px solid #d6e1e7;border-radius:8px} .customer-table td{border:0;padding:2px;text-align:left} .customer-table td:is(:nth-child(1),:nth-child(3),:nth-child(5),:nth-child(6)){display:none} .customer-table td:nth-child(2){font-weight:650}.customer-table td:nth-child(4){grid-row:2;grid-column:1;color:#52657d} .customer-table td:nth-child(7){grid-row:1;grid-column:2}.customer-table td:nth-child(7)::before{content:"Due ";color:#52657d;font-size:11px} .customer-table td:nth-child(8){grid-row:2;grid-column:2;text-align:right} .customer-summary div{padding:6px}.customer-summary dd{font-size:14px} } .customer-summary{display:grid;grid-template-columns:minmax(0,1fr);gap:3px;margin:6px 0 0} .customer-summary div{display:flex;align-items:baseline;gap:6px;background:none;border:0;padding:0} .customer-summary dd{margin:0;font-size:inherit;font-weight:700} .customer-toolbar{justify-content:flex-end} .customer-heading{padding:8px 10px;margin-bottom:6px;background:#fff;border:1px solid #d6e1e7;border-radius:8px} .customer-heading h1{font-size:19px;margin:0;line-height:1.25} .customer-heading .customer-back{padding:0;margin-bottom:3px;font-size:11px} .customer-summary{margin-top:3px;gap:1px;font-size:12px} .customer-tools{display:flex;align-items:center;gap:6px;flex-wrap:wrap} .customer-toolbar{margin:0}.customer-toolbar label{display:flex;align-items:center;gap:5px} .customer-table th,.customer-table td{padding:3px 7px} .customers .customer-table th button{padding:2px 0;border:0;background:transparent;color:#294657} .customers .customer-table th[aria-sort=ascending] button::after{content:" ↑"} .customers .customer-table th[aria-sort=descending] button::after{content:" ↓"} .customers .customer-table td button{padding:2px 7px} .customer-avatar{width:20px;height:20px} @container(max-width:760px){ .customer-heading{padding:7px 8px;gap:6px} .customer-tools{width:100%} .customer-toolbar{flex:1 1 100%} .customer-toolbar input{flex:1;width:100%;min-width:0} .customer-table tbody tr{margin-bottom:4px;padding:5px 7px;row-gap:1px} .customer-table td{padding:1px 2px} .customers .customer-table td button{min-height:32px} } .customers .customer-actions button{min-height:33px;padding:6px 11px;display:inline-flex;align-items:center;justify-content:center;gap:5px;font-weight:650} .customers #adjust-customer{background:#e6f4ec;border-color:#acd4bc;color:#14583d} .customers #adjust-customer:hover{background:#d7eee1} .customers #new-customer:hover{background:#12543b} .demo-portrait{position:relative;overflow:hidden;background:#e4efe9;color:#4c8065} .demo-portrait[data-tone="1"]{background:#e5edf5;color:#53728f} .demo-portrait[data-tone="2"]{background:#f1eae1;color:#866d54} .demo-portrait::before,.demo-portrait::after{content:"";position:absolute;background:currentColor} .demo-portrait::before{width:6px;height:6px;border-radius:50%;top:4px;left:7px} .demo-portrait::after{width:12px;height:8px;border-radius:8px 8px 0 0;bottom:1px;left:4px} @container(max-width:760px){ .customer-heading{padding:9px 10px;gap:9px} .customer-heading>div:first-child{width:100%} .customer-summary{grid-template-columns:repeat(2,minmax(0,1fr));gap:5px 12px;margin-top:5px} .customer-summary div{flex-wrap:wrap;gap:2px 5px} .customer-tools{display:grid;grid-template-columns:minmax(0,1fr);gap:6px} .customer-toolbar label{width:100%} .customer-toolbar input{min-height:36px} .customer-actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px} .customer-table tbody tr{padding:7px 9px;grid-template-columns:minmax(0,1fr) auto;row-gap:2px} .customer-table td:nth-child(3),.customer-table td:nth-child(5){display:block;color:#52657d} .customer-table td:nth-child(3){grid-row:2;grid-column:1} .customer-table td:nth-child(4){grid-row:3;grid-column:1} .customer-table td:nth-child(5){grid-row:4;grid-column:1} .customer-table td:nth-child(7){font-weight:650} .customer-table td:nth-child(8){grid-row:3 / span 2;align-self:end} } @container(max-width:345px){ .customer-summary{grid-template-columns:minmax(0,1fr);gap:2px} } @media(max-width:720px){ .customer-heading .customer-back{display:none} .customer-heading{gap:6px} .customer-summary{grid-template-columns:minmax(0,1fr);gap:2px} .customer-tools{gap:5px} .customer-table tbody tr{padding:5px 8px;row-gap:1px} .customer-table td{padding-block:0;line-height:1.3} } @media(max-width:720px){ .customer-heading{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:start;gap:6px 5px} .customer-heading h1{font-size:17px} .customer-tools{display:contents} .customer-actions{grid-row:1;grid-column:2;grid-template-columns:auto auto;gap:4px} .customers .customer-actions button{min-height:32px;padding:4px 6px;font-size:clamp(10px,2.5vw,12px)} .customer-toolbar{grid-row:2;grid-column:1 / -1} .customer-search-label{display:none} } .customers .customer-table td button.customer-more{width:30px;padding:0;font-size:20px;line-height:1.1} #customer-menu{position:fixed;inset:auto;margin:0;width:174px;padding:4px;border:1px solid #d6e1e7;border-radius:9px;box-shadow:0 8px 22px #182a4026;color:#243642} #customer-menu button{background:#fff;color:inherit;padding:6px 9px;cursor:pointer;display:flex;align-items:center;gap:9px;width:100%;min-height:35px;text-align:left;border:0} #customer-menu button:hover{background:#edf5f1} #customer-menu i{width:15px;text-align:center} #customer-menu [data-action=delete]{color:#a62d32} @media(max-width:720px){.customers .customer-table td button.customer-more{width:36px;min-height:36px}} .customers #customer-ledger{width:min(1540px,calc(100% - 24px));max-height:calc(100dvh - 24px);padding:0;overflow:auto} #customer-ledger header{display:flex;justify-content:space-between;align-items:center;position:sticky;top:0;background:white;z-index:1;border-bottom:1px solid #d6e1e7;padding:8px 14px} #customer-ledger h2{font-size:16px;margin:0} #customer-ledger header button{width:36px;height:36px;font-size:20px} .ledger-body{padding:12px 14px} .ledger-profile{display:flex;justify-content:space-between;gap:14px} #ledger-profile{margin:0;min-width:0;display:grid;align-content:start;gap:3px} #ledger-profile div{display:grid;grid-template-columns:90px minmax(0,1fr);gap:5px} #ledger-profile dt{font-weight:650}#ledger-profile dd{text-align:left;overflow-wrap:anywhere} .ledger-balance{display:grid;justify-items:end;align-content:start;gap:3px} .ledger-balance i{font-size:34px;color:#8ba49b}.ledger-balance strong{font-size:19px;color:#196748;font-variant-numeric:tabular-nums} .ledger-search{display:flex;justify-content:flex-end;align-items:center;gap:6px;margin:8px 0} .ledger-scroll{overflow:auto}.ledger-scroll table{min-width:760px}.ledger-scroll th,.ledger-scroll td{padding:4px 7px} .ledger-scroll :is(th,td):nth-child(-n+3){text-align:left} .ledger-scroll tr.ledger-detail td{white-space:normal;text-align:left;background:#edf5f1} #ledger-count{margin:8px 0 0} @media(max-width:720px){ .ledger-body{padding:9px} .ledger-profile{flex-wrap:wrap;gap:8px} .ledger-balance{display:flex;align-items:center;gap:6px} .ledger-balance i{display:none} } #customer-ledger .ledger-header{position:static;display:grid;justify-items:start;gap:3px;padding:0 0 7px;background:transparent;border:0} #customer-ledger .ledger-header h2{font-size:19px} #customer-ledger .ledger-header button{width:auto;height:auto;font-size:12px;padding:3px 0} #customer-ledger .ledger-body{padding:0} .ledger-profile{align-items:center;padding:9px 11px;background:#fff;border:1px solid #d6e1e7;border-radius:9px} .ledger-balance{min-width:122px;padding:7px 10px;border-radius:7px;background:#eaf5ee} .ledger-balance i{font-size:22px} .ledger-search{margin:6px 0} .ledger-scroll{border:1px solid #d6e1e7;border-radius:7px;background:#fff} .ledger-scroll th,.ledger-scroll td{padding:3px 7px} .customers .ledger-scroll td button{padding:1px 7px} @media(max-width:720px){ #customer-ledger .ledger-header button{min-height:34px} .ledger-profile{align-items:flex-start;gap:6px} .ledger-balance{width:100%;justify-content:space-between} .ledger-search input{width:min(100%,210px)} } #customer-ledger .ledger-header{grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:1px 8px;padding-bottom:4px} #customer-ledger .ledger-header button{grid-column:1;grid-row:1;min-height:0;padding:0} #customer-ledger .ledger-header h2{grid-column:1;grid-row:2;font-size:15px;line-height:1.25} #customer-ledger .ledger-header .ledger-search{grid-column:2;grid-row:1 / span 2;margin:0;width:min(36vw,200px);min-width:0} #customer-ledger .ledger-profile{background:transparent;border:0;border-radius:0;padding:2px 0 6px;gap:8px} #customer-ledger .ledger-balance{background:transparent;padding:0;min-width:0} #customer-ledger .ledger-balance strong{font-size:15px} #ledger-profile{gap:1px} @media(max-width:720px){ #customer-ledger .ledger-header button{min-height:28px} #customer-ledger .ledger-balance{width:auto;gap:5px} } @media(min-width:721px){ .customer-toolbar{order:-1} } .customers .customer-table td button.customer-more, .customers .ledger-scroll td button.ledger-more{border:0;background:transparent} .customers .customer-table td button.customer-more:hover, .customers .ledger-scroll td button.ledger-more:hover{background:#dfeae6} @media(max-width:720px){ #customer-ledger:not([hidden]){display:grid;grid-template-columns:minmax(0,1fr);gap:7px} #customer-ledger .ledger-header,#customer-ledger .ledger-body{display:contents} #customer-ledger .ledger-header button{grid-area:1 / 1;justify-self:start;min-height:32px} #customer-ledger .ledger-header h2{grid-area:2 / 1;font-size:16px} #customer-ledger .ledger-profile{grid-area:3 / 1;display:grid;grid-template-columns:minmax(0,1fr);padding:0;gap:6px} #ledger-profile div{grid-template-columns:100px minmax(0,1fr);gap:6px} #ledger-profile dt,#ledger-profile dd{font-size:12px;line-height:1.4} #customer-ledger .ledger-balance{width:100%;justify-content:space-between;align-items:baseline;border-block:1px solid #d6e1e7;padding:5px 0} #customer-ledger .ledger-header .ledger-search{grid-area:4 / 1;width:100%;min-height:36px} #customer-ledger .ledger-scroll{grid-area:5 / 1;min-width:0;overflow:visible;border:0;background:transparent} #customer-ledger .ledger-scroll table{display:block;min-width:0} #customer-ledger .ledger-scroll thead{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)} #ledger-rows{display:grid;gap:4px} #ledger-rows tr{display:grid;grid-template-columns:max-content minmax(0,1fr) max-content;gap:0 5px;padding:5px 6px 5px 8px;border:1px solid #d6e1e7;border-radius:6px;background:#fff} #ledger-rows td{border:0;padding:0;min-width:0;font-size:clamp(10px,2.9vw,13px);line-height:1.5;white-space:normal;overflow-wrap:anywhere;background:transparent} #ledger-rows td:nth-child(1){grid-area:1 / 1} #ledger-rows td:nth-child(2){grid-area:1 / 2} #ledger-rows td:nth-child(3){grid-area:2 / 1} #ledger-rows td:nth-child(4){grid-area:2 / 2;text-align:left} #ledger-rows td:nth-child(5){grid-area:1 / 3;text-align:right;white-space:nowrap} #ledger-rows td:nth-child(8){grid-area:2 / 3;text-align:right} #ledger-rows td:nth-child(6),#ledger-rows td:nth-child(7){display:none} #ledger-rows td:nth-child(2),#ledger-rows td:nth-child(4){border-left:1px solid #d6e1e7;padding-left:5px} #ledger-rows td:nth-child(1)::before{content:'Date: '} #ledger-rows td:nth-child(2)::before{content:'Bill Type: '} #ledger-rows td:nth-child(3)::before{content:'Bill No: '} #ledger-rows td:nth-child(4)::before{content:'Amount: '} #customer-ledger #ledger-rows .ledger-more{min-width:32px;min-height:24px;padding:0;font-size:17px;line-height:1} #customer-ledger #ledger-count{grid-area:6 / 1;margin:0} } #ledger-menu{position:fixed;inset:auto;margin:0;width:145px;padding:4px;border:1px solid #d6e1e7;border-radius:8px;box-shadow:0 6px 20px #182a4026} .customers #ledger-menu button{display:flex;align-items:center;gap:8px;width:100%;min-height:34px;text-align:left;border:0} .customers #ledger-menu button:hover{background:#edf5f1} #ledger-transaction-data div{grid-template-columns:minmax(0,1fr) auto;padding:4px 0} @media(max-width:720px){ #customer-ledger:not([hidden]){padding-top:3px;row-gap:4px} #customer-ledger .ledger-header button{min-height:22px;line-height:1.2} #customer-ledger .ledger-header h2{line-height:1.15} } .customers dialog.customer-create{width:min(720px,calc(100% - 20px));max-height:calc(100dvh - 20px);overflow:auto} .customer-create #customer-dialog-body{grid-template-columns:repeat(2,minmax(0,1fr))} .customer-create #customer-dialog-body [hidden]{display:none} .customer-create .create-wide,.customer-type{grid-column:1 / -1} .customer-create #customer-dialog-body .create-check,.customer-create #customer-dialog-body .customer-type label{display:flex;align-items:center;gap:5px} .customer-type{margin:0;padding:6px 9px;border:1px solid #d6e1e7;border-radius:6px;display:flex;gap:14px} .customer-create input,.customer-create textarea,.customer-create select{min-width:0;max-width:100%} .customer-create textarea{border:1px solid #d6e1e7;border-radius:6px;padding:6px;font:inherit} .customer-form-actions{display:flex;justify-content:flex-end;gap:6px} .customers #customer-save-new{background:#e6f4ec;border-color:#acd4bc;color:#14583d;font-weight:650} .customer-avatar{object-fit:cover} #customer-created{margin:5px 0 0;color:#196748} @media(max-width:420px){.customer-create #customer-dialog-body{grid-template-columns:minmax(0,1fr)}} .customers dialog.customer-create{padding:10px 12px;border-radius:10px} .customer-create .customer-dialog-heading{padding-bottom:5px;border-bottom:1px solid #e1e9ed} .customer-create .customer-dialog-heading h2{font-size:15px;font-weight:700;margin:0} .customer-create #customer-close{min-width:32px;min-height:30px;padding:2px} .customer-create #customer-dialog-body{margin:6px 0;gap:5px 8px} .customer-create #customer-dialog-body label{gap:1px;font-size:12px;font-weight:600} .customer-create #customer-dialog-body :is(input:not([type=radio],[type=checkbox]),select,textarea){padding:4px 7px;min-height:30px;border-color:#cddce3;background:#fcfdfe} .customer-create #customer-dialog-body textarea{min-height:42px;resize:vertical} .customer-create #customer-dialog-body small{font-size:11px;font-weight:400;color:#52657d} .customer-create .customer-type{padding:2px 8px 5px;border-color:#d6e1e7;background:#f5f8f9;gap:12px} .customer-create .customer-type legend{font-size:11px;color:#52657d;padding-inline:3px} .customer-create input:is([type=radio],[type=checkbox]){margin:0;accent-color:#196748} .customer-create .customer-form-actions{padding-top:5px;border-top:1px solid #e1e9ed} .customer-create .customer-form-actions button{min-height:32px} @media(max-width:420px){ .customers dialog.customer-create{padding:8px 9px} .customer-create #customer-dialog-body :is(input:not([type=radio],[type=checkbox]),select,textarea){min-height:34px} .customer-create .customer-form-actions button{min-height:36px} } .customer-create .customer-type{border:0;border-radius:0;background:transparent;padding:2px 0;gap:16px;min-inline-size:0} .customer-create .customer-type legend{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);padding:0} .customer-create #customer-dialog-body label{font-weight:500} .customer-create #customer-dialog-body :is(input:not([type=radio],[type=checkbox]),select,textarea){border:0;background:#eef3f6;border-radius:5px} .customer-create #customer-dialog-body :is(input,select,textarea):focus-visible{outline:1px solid #687f8c;outline-offset:-1px} .customer-create #customer-dialog-body input[type=file]::file-selector-button{border:0;border-radius:4px;padding:3px 7px;margin-inline-end:6px;background:#dce7ed;color:#243642;font:inherit;cursor:pointer} .customers dialog.customer-create{padding:10px 6px 12px} .customer-create #customer-dialog-body{row-gap:6px} .customer-create #customer-dialog-body :is(input:not([type=radio],[type=checkbox]),select,textarea){background:#fff;border:1px solid #d2dce3} .customer-create #customer-dialog-body :is(input:not([type=radio],[type=checkbox]),select,textarea):focus-visible{outline:none;border-color:#687f8c} .customer-create #customer-dialog-body label:has(input[type=file]){gap:3px;padding-block:5px} .customer-create #customer-dialog-body label:has(input[type=file])[hidden]{display:none} .customer-create #customer-dialog-body input[type=file]{min-height:33px;padding:2px 4px} .customer-create #customer-dialog-body input[type=file]::file-selector-button{background:#fff;border:1px solid #d2dce3;padding:4px 8px} .customers dialog.customer-create{width:min(720px,calc(100% - 24px));padding:12px clamp(14px,6vw,52px) 14px} .customer-create #customer-dialog-body .create-upload{min-width:0;align-content:start} .customer-create .create-upload input[type=file]{width:100%;font-size:0} .customer-create #customer-dialog-body .create-upload input[type=file]::file-selector-button{font-size:12px} .create-file-name{display:block;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#52657d;font-weight:400} @media(max-width:420px){ .customers dialog.customer-create{padding:10px 14px} .customer-create #customer-dialog-body{grid-template-columns:repeat(2,minmax(0,1fr))} .customer-create #customer-dialog-body>label:not(.create-upload){grid-column:1 / -1} } .customer-create .customer-dialog-heading{gap:8px} .customer-create #customer-close{border-color:transparent;background:#f4f7f8;font-size:17px} .customer-create #customer-dialog-body label{color:#243642} .customer-create #customer-dialog-body .create-upload{padding:4px 0} .customer-create #customer-dialog-body .create-upload input[type=file]{min-height:32px} .customer-create .customer-form-actions button{min-width:72px} @media(max-width:420px){ .customer-create .customer-form-actions button{min-height:40px} .customer-create #customer-dialog-body :is(input[type=text],input[type=tel],input[type=email],input[type=number],input[type=date],input:not([type]),textarea,select){font-size:16px} } #sales-view .customer-summary div{padding:0;background:none;border:0;display:flex;gap:6px} #sales-view .customer-summary dd{margin:0;font-size:inherit} .sales-controls,.sales-toolbar{display:flex;gap:6px;align-items:end;flex-wrap:wrap} .sales-controls label{display:grid;gap:2px}.sales-toolbar{justify-content:space-between;margin:7px 0} #sales-view #sales-create,#sales-entry button{background:#196748;color:#fff;border-color:#196748;font-weight:650} .sales-table-wrap{overflow:auto;border:1px solid #d6e1e7;border-radius:7px} .sales-table th,.sales-table td{padding:4px 7px}.sales-table :is(th,td):nth-child(-n+3){text-align:left} .sales-table td{white-space:normal}.sales-table td:nth-child(3){overflow-wrap:anywhere} .sales-status{font-weight:650}.sales-status.paid{color:#196748}.sales-status.unpaid{color:#a62d32}.sales-status.partial{color:#8b5612} #sales-entry:not([hidden]){display:grid;gap:6px;margin-top:9px}#sales-entry label{display:grid;gap:2px} #sales-details div{grid-template-columns:1fr 1fr;padding:3px 0} @media(max-width:720px){ .sales-controls{width:100%} .sales-table-wrap{border:0} .sales-table,.sales-table tbody{display:block;min-width:0} .sales-table thead{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)} .sales-table tr{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));padding:6px 8px;margin-bottom:5px;background:#fff;border:1px solid #d6e1e7;border-radius:7px} .sales-table td:nth-child(n){border:0;text-align:left;padding:2px} .sales-table td:nth-child(3){grid-column:1/-1;font-weight:650} .sales-table td[data-label]::before{content:attr(data-label) " ";color:#52657d;font-size:11px} .sales-table td:last-child{text-align:right} } #sales-view .customer-heading{padding:5px 8px;margin-bottom:3px} #sales-view .customer-heading h1{font-size:17px} #sales-view .customer-summary{gap:0} .sales-toolbar{margin:3px 0} .sales-table th,.sales-table td{padding:2px 6px} .sales-table :is(th,td):last-child{text-align:left;width:91px} .sales-row-actions{display:flex;align-items:center;gap:2px} #sales-view .sales-row-actions button{border:0;background:transparent;padding:0;width:24px;height:24px;color:#284759} #sales-view .sales-row-actions button:hover{background:#e0eee7} #sale-menu{position:fixed;inset:auto;margin:0;width:132px;padding:3px;border:1px solid #d6e1e7;border-radius:6px} #sale-menu button{width:100%} @media(max-width:720px){ .sales-table td:last-child{width:auto;justify-self:end} #sales-view .sales-row-actions button{width:31px;height:32px} .sales-table tr{margin-bottom:4px;padding:4px 6px} } .customers #sales-dialog.bill-editor{width:min(1480px,calc(100% - 20px));max-height:calc(100dvh - 20px);overflow:auto} .bill-meta{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));align-items:end;gap:6px} .bill-meta :is(input,select),.bill-lines input{width:100%;min-width:0} .bill-lines{overflow:auto}.bill-lines table{min-width:690px}.bill-lines th,.bill-lines td{padding:3px 5px} .bill-lines td:nth-child(2),.bill-lines th:nth-child(2){text-align:left} .bill-lines input{max-width:90px}.bill-lines td:nth-child(2){min-width:110px} .bill-editor #sales-entry .bill-lines button{background:transparent;color:#a62d32;border:0} .bill-bottom{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,320px);gap:12px} .bill-bottom textarea{border:1px solid #d6e1e7;border-radius:6px;padding:6px;font:inherit;resize:vertical} #sales-entry .bill-totals label{display:grid;grid-template-columns:110px minmax(0,1fr);align-items:center;margin:2px 0} .bill-totals output{text-align:right;font-weight:700;font-variant-numeric:tabular-nums} .bill-footer{display:flex;justify-content:flex-end;align-items:center;gap:6px;flex-wrap:wrap;padding-top:5px;border-top:1px solid #d6e1e7} .bill-editor #sales-entry button[value=continue]{color:#196748;background:#edf6f0} @media(max-width:720px){.bill-meta{grid-template-columns:repeat(2,minmax(0,1fr))}.bill-bottom{grid-template-columns:minmax(0,1fr)}} @media(max-width:720px){ #sales-view .customer-heading{display:grid;grid-template-columns:minmax(0,1fr);gap:7px;padding:7px 8px} #sales-view .customer-summary{grid-template-columns:repeat(3,minmax(0,1fr));gap:4px} #sales-view .customer-summary div{display:grid;gap:1px;min-width:0} #sales-view .customer-summary dd{overflow-wrap:anywhere} #sales-view .sales-controls{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:5px} #sales-view .sales-controls label,#sales-view .sales-controls input{width:100%;min-width:0} #sales-view .sales-controls button{min-height:34px} #sales-view .sales-toolbar{display:grid;grid-template-columns:auto minmax(0,1fr);align-items:center;gap:7px;margin:5px 0} #sales-search{width:100%;min-width:0;min-height:34px} #sales-view .sales-table tbody tr{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:3px 5px;padding:6px 8px;margin-bottom:5px;background:#fff} #sales-view .sales-table td{min-width:0;width:auto;padding:0;overflow-wrap:anywhere} #sales-view .sales-table td:nth-child(1){grid-area:1 / 3;text-align:right;color:#52657d} #sales-view .sales-table td:nth-child(2){grid-area:1 / 1 / 2 / 3;font-weight:700} #sales-view .sales-table td:nth-child(3){grid-area:2 / 1 / 3 / -1;padding-bottom:3px} #sales-view .sales-table td:nth-child(n+4):nth-child(-n+6){font-weight:650;font-variant-numeric:tabular-nums} #sales-view .sales-table td[data-label]::before{display:block;font-weight:400} #sales-view .sales-table td:nth-child(7){grid-area:4 / 1;align-self:center} #sales-view .sales-table td:nth-child(8){grid-area:4 / 2 / 5 / -1;justify-self:end} #sales-view .sales-row-actions{gap:2px} #sales-view .sales-row-actions button{width:36px;height:36px} } @media(max-width:720px){ #sales-view .sales-table tbody tr{grid-template-columns:minmax(0,28%) minmax(0,1fr) minmax(0,76px);gap:2px 5px;padding:6px 7px;font-size:12px} #sales-view .sales-table td:nth-child(1){grid-area:1 / 1;text-align:left;font-size:0} #sales-view .sales-table td:nth-child(1)::before{content:"Date: " attr(data-mobile-date);font-size:12px} #sales-view .sales-table td:nth-child(2){grid-area:2 / 1} #sales-view .sales-table td:nth-child(3){grid-area:1 / 2;padding-bottom:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} #sales-view .sales-table td:nth-child(4){grid-area:3 / 1} #sales-view .sales-table td:nth-child(5){grid-area:2 / 2} #sales-view .sales-table td:nth-child(6){grid-area:3 / 2} #sales-view .sales-table td:nth-child(7){grid-area:1 / 3;text-align:right} #sales-view .sales-table td:nth-child(8){grid-area:2 / 3 / 4 / 4;align-self:center} #sales-view .sales-table td:nth-child(3),#sales-view .sales-table td:nth-child(5),#sales-view .sales-table td:nth-child(6){border-inline-start:1px solid #d6e1e7;padding-inline-start:5px} #sales-view .sales-table td[data-label]:not([data-label=""]):not(:first-child)::before{display:inline;content:attr(data-label) ": ";font-size:11px} #sales-view .sales-table td[data-label=""]::before{content:none} #sales-view .sales-row-actions{gap:0} #sales-view .sales-row-actions button{width:25px;height:28px} #sales-view .sale-print-desktop{display:none} } @media(max-width:720px){ #sales-view .customer-heading{grid-template-columns:minmax(0,1fr) auto;gap:4px 6px;padding:6px 8px} #sales-view .customer-heading h1{font-size:15px} #sales-view .customer-summary{grid-template-columns:minmax(0,1fr);gap:1px;margin-top:3px} #sales-view .customer-summary div{display:grid;grid-template-columns:56px minmax(0,1fr);gap:5px} #sales-view .customer-summary dd{font-weight:600} #sales-view .sales-controls{display:contents} #sales-view .sales-controls label:first-child{grid-area:2 / 1} #sales-view .sales-controls label:nth-child(2){grid-area:2 / 2} #sales-view .sales-controls button[type=submit]{display:none} #sales-view #sales-create{grid-area:1 / 2;justify-self:end;align-self:start;min-height:30px;padding:4px 7px} #sales-view .customer-heading{grid-template-columns:repeat(2,minmax(0,1fr))} #sales-view .sales-toolbar{grid-template-columns:minmax(0,1fr);margin:4px 0} #sales-view .sales-table tbody tr{padding:4px 6px;gap:1px 5px;margin-bottom:4px;line-height:1.3} #sales-view .sales-table td:nth-child(n+2):nth-child(-n+7){font-weight:500} #sales-view .sales-table td:nth-child(3){font-weight:600} #sales-view .sales-row-actions button{height:27px} } #sales-view .sales-card-open{display:none} @media(max-width:720px){ #sales-view .sales-table tbody tr{cursor:pointer} #sales-view .sales-table td:not(:last-child){white-space:nowrap;overflow:hidden;text-overflow:ellipsis} #sales-view .sales-number-desktop{display:none} #sales-view .sales-card-open{display:inline;padding:0;border:0;background:transparent;color:inherit;font-weight:inherit} } #sale-menu{width:174px;box-shadow:0 6px 20px #182a4026} #sales-view #sale-menu button{display:flex;gap:8px;align-items:center;min-height:32px;text-align:left;border:0} #sales-view #sale-menu button:hover{background:#edf5f1} #sales-view #sale-menu [data-sale-action=delete]{color:#a62d32} #sales-view .sales-toolbar{display:flex;justify-content:flex-end;align-items:center;gap:6px} #sales-view #sales-page-size{min-width:65px} #sales-view #sales-search{width:min(220px,100%);min-width:0} @media(max-width:720px){ #sales-view .sales-toolbar{display:grid;grid-template-columns:auto minmax(0,1fr)} #sales-view #sales-search{width:100%} #sales-view #sales-page-size{min-height:34px} } #sales-view .customer-heading{align-items:start} #sales-view .sales-heading-tools{display:grid;gap:5px;justify-items:end;max-width:100%} #sales-view .sales-toolbar{margin:0} @media(max-width:720px){ #sales-view .sales-heading-tools{display:contents} #sales-view .sales-toolbar{grid-area:3 / 1 / 4 / -1;width:100%} } #sales-view .sales-heading-tools{min-width:0} #sales-view .sales-toolbar{display:grid;grid-template-columns:auto minmax(0,1fr);width:min(100%,290px);min-width:0;justify-content:stretch} #sales-view #sales-search,#sales-view #sales-page-size{width:100%;height:32px} #sales-view .sales-table tbody td{font-size:13px;font-weight:400} #sales-view .sales-table thead th{font-size:12px;font-weight:600} @media(max-width:720px){ #sales-view .sales-toolbar{width:100%} #sales-view .sales-table tbody td{font-size:12px} #sales-view .sales-table tbody td:first-child{font-size:0} #sales-view .sales-table tbody td:nth-child(3){font-weight:600} } #sales-view .sales-date-field{position:relative;display:block;margin-top:6px} #sales-view .sales-date-field span{position:absolute;inset-block-start:0;inset-inline-start:8px;transform:translateY(-50%);padding:0 3px;background:#fff;color:#52657d;font-size:10px;line-height:1;pointer-events:none} #sales-view .sales-date-field input{min-height:32px} @media(max-width:720px){ #sales-view #sales-page-size{display:none} #sales-view .sales-toolbar{grid-template-columns:minmax(0,1fr)} } #sales-view .sales-toolbar{grid-template-columns:auto minmax(0,1fr) auto;width:min(100%,360px)} #sales-view #sales-ask{white-space:nowrap;color:#196748;font-weight:650} #sales-ask-form label{display:grid;gap:4px;margin:8px 0} .sales-ask-actions{display:flex;flex-wrap:wrap;gap:5px} #sales-ai-filter{margin:5px 0;overflow-wrap:anywhere} @media(max-width:720px){#sales-view .sales-toolbar{width:100%;grid-template-columns:minmax(0,1fr) auto}} #sales-question{width:100%;min-width:0;padding:8px;border:1px solid #d6e1e7;border-radius:6px;font:inherit;color:inherit;resize:vertical} @media(max-width:720px){ #sales-view .sales-toolbar{grid-template-columns:minmax(0,1fr) auto;gap:5px} #sales-view #sales-search,#sales-view #sales-ask{height:40px} .customers #sales-assistant{width:min(100% - 16px,440px);max-height:calc(100dvh - 16px);overflow:auto;padding:11px} #sales-question{font-size:16px} #sales-assistant .sales-ask-actions{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr)} #sales-assistant .sales-ask-actions button,#sales-assistant .sales-ask-actions select{min-height:44px} #sales-assistant .sales-ask-actions button[type=submit]{grid-column:1/-1;background:#196748;color:white;border-color:#196748} #sales-ask-status{margin:6px 0 0} } .customers #sales-assistant{width:min(calc(100% - 20px),440px);padding:14px;border-radius:14px} #sales-assistant .customer-dialog-heading{padding-bottom:9px;border-bottom:1px solid #e1e9ed} #sales-assistant-title{margin:0;font-size:15px} #sales-assistant #sales-question{min-height:66px;background:#f8fafb} #sales-ask-form label{font-weight:600;margin:10px 0 6px} #sales-assistant #sales-ask-example{border-color:#d5e7dd;background:#f2f8f4;color:#196748;margin-bottom:10px;text-align:left} #sales-assistant .sales-ask-actions{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr) auto;gap:6px} #sales-assistant .sales-ask-actions :is(button,select){min-height:40px} #sales-assistant .sales-ask-actions button[type=submit]{background:#196748;color:#fff;border-color:#196748;font-weight:650} #sales-ask-status:empty{display:none} @media(max-width:720px){ #sales-assistant .sales-ask-actions{grid-template-columns:repeat(2,minmax(0,1fr))} #sales-assistant .sales-ask-actions :is(button,select){min-height:44px} } #customers-view .customer-tools{display:grid;justify-items:end;gap:5px} #suppliers-view .customer-tools{display:grid;justify-items:end;gap:5px} #customers-view .customer-toolbar{order:0;display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:6px;width:min(100%,360px)} #suppliers-view .customer-toolbar{order:0;display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:6px;width:min(100%,360px)} #customers-view .customer-toolbar label,#customers-view #customer-search{width:100%;min-width:0} #suppliers-view .customer-toolbar label,#suppliers-view #supplier-search{width:100%;min-width:0} #customers-view #customer-ask{white-space:nowrap;color:#196748;font-weight:650} @media(max-width:720px){ #customers-view .customer-tools{display:contents} #suppliers-view .customer-tools{display:contents} #customers-view .customer-toolbar{width:100%;grid-template-columns:minmax(0,1fr) auto} #suppliers-view .customer-toolbar{width:100%;grid-template-columns:minmax(0,1fr) auto} #customers-view #customer-page-size{display:none} #suppliers-view #supplier-size{display:none} #customers-view #customer-ask,#customers-view #customer-search{min-height:40px} #suppliers-view #supplier-ask,#suppliers-view #supplier-search{min-height:40px} } @media(min-width:721px){ #sales-view .customer-heading{align-items:end;padding:7px 10px} #sales-view .sales-heading-tools{align-self:end;justify-items:stretch} #sales-view .sales-toolbar{width:100%} } #customer-ai-fill:not([hidden]){margin-inline-start:auto;color:#196748;font-weight:650;background:#edf6f0} @media(min-width:721px){ #sales-view .customer-heading{align-items:start} #sales-view .sales-heading-tools{align-self:start;padding-top:6px} } .sales-editor-heading h1{font-size:17px;margin:2px 0 5px} #sales-editor-page #sales-entry{margin-top:0} #sales-editor-page .bill-meta,#sales-editor-page .bill-bottom{padding:8px;background:#fff;border:1px solid #d6e1e7;border-radius:7px} #sales-editor-page .bill-lines{border:1px solid #d6e1e7;border-radius:7px} #sales-editor-page .bill-bottom>label{align-content:start} #sales-editor-page .bill-footer{padding-bottom:4px} #sales-editor-page .bill-meta{grid-template-columns:minmax(0,2fr) minmax(0,2fr) minmax(150px,1fr);align-items:start;background:transparent;border:0;padding:0;gap:8px} .bill-lookup,.bill-dates{display:grid;gap:5px} .bill-lookup{grid-template-columns:repeat(2,minmax(0,1fr));align-items:end} .bill-party{margin:0;color:#52657d;min-width:0} .bill-party div{grid-template-columns:auto minmax(0,1fr);gap:5px} .bill-party dd{text-align:left;overflow-wrap:anywhere} #sales-editor-page .bill-lines table{min-width:1140px} #sales-editor-page .bill-lines :is(th,td){border-inline-end:1px solid #d6e1e7} #sales-editor-page .bill-lines input{padding:3px 4px} #sales-editor-page .bill-lines tfoot{background:#edf3f6;font-weight:650} #sales-editor-page .bill-bottom{background:transparent;border:0;padding:0} #sales-editor-page .bill-footer{position:sticky;bottom:0;background:#f5f7fa;padding:6px;z-index:1} @media(max-width:720px){ #sales-editor-page .bill-meta{grid-template-columns:minmax(0,1fr)} .bill-dates{grid-template-columns:repeat(2,minmax(0,1fr))} #sales-editor-page .bill-footer{bottom:calc(54px + env(safe-area-inset-bottom))} } #sales-entry .bill-field{position:relative;display:block;min-width:0;margin-top:6px} #sales-entry .bill-field>span:first-child{position:absolute;inset:0 auto auto 8px;transform:translateY(-50%);padding:0 3px;background:#fff;font-size:10px;line-height:1;color:#52657d;pointer-events:none} #sales-entry .bill-field :is(input,select){height:32px;padding:5px 8px} #sales-editor-page .bill-lines thead th{background:#f1f5f7} #sales-editor-page .bill-lines tbody tr:nth-child(odd){background:#fbfcfd} #sales-editor-page .bill-lines tbody tr:nth-child(even){background:#f6f8fa} #sales-editor-page .bill-lines tbody td:has(input){padding:2px} #sales-editor-page .bill-lines tbody td>input{display:block;width:100%;max-width:none;height:30px;margin:0;padding:3px 5px;border:1px solid #dbe4ec55;border-radius:3px;background:transparent;text-align:inherit} #sales-editor-page .bill-lines tbody td>input:focus-visible{outline:1px solid #79998b;outline-offset:-1px;background:inherit} #sales-editor-page .bill-lines input[type=number]{appearance:textfield;-moz-appearance:textfield} #sales-editor-page .bill-lines input::-webkit-inner-spin-button,#sales-editor-page .bill-lines input::-webkit-outer-spin-button{-webkit-appearance:none;margin:0} #sales-editor-page.content{padding-block-start:3px} #sales-editor-page .sales-editor-heading{display:flex;align-items:center;gap:8px;flex-wrap:wrap} #sales-editor-page .sales-editor-heading .customer-back{padding:2px 0} #sales-editor-page .sales-editor-heading h1{margin:0;font-size:15px} #sales-editor-page .bill-meta{gap:4px 8px} #sales-editor-page .bill-party:empty{display:none} #sales-editor-page .bill-item-field{grid-column:1 / -1} #sales-editor-page .bill-dates{grid-template-columns:repeat(2,minmax(0,1fr))} #sales-editor-page .bill-dates .bill-field:last-of-type{grid-column:1 / -1} @media(min-width:721px){ #sales-editor-page .bill-meta{grid-template-columns:minmax(0,min(38%,560px)) minmax(0,1fr) minmax(0,calc(min(19%,280px) - 2.5px))} #sales-editor-page .bill-dates{grid-area:1 / 3 / 3 / 4;grid-template-columns:minmax(0,1fr)} #sales-editor-page .bill-party{grid-area:1 / 2 / 3 / 3} #sales-editor-page .bill-lookup{grid-area:1 / 1 / 3 / 2} } #sales-editor-page .bill-item-info{display:flex;justify-content:space-between;align-items:center;gap:6px;min-height:22px;font-size:12px;color:#52657d} #sales-editor-page #bill-item-view{padding:1px 0;border:0;background:transparent;color:#196748;text-decoration:underline} #sales-editor-page .bill-warehouse{grid-column:1 / -1} #sales-editor-page #bill-ai-add{margin-inline-start:auto;padding:3px 7px;color:#196748;background:#edf6f0;border:1px solid #cfe4d8} #bill-ai-preview label{margin:5px 0;padding:5px;border:1px solid #d6e1e7;border-radius:6px} .customers #bill-ai-confirm:not([hidden]){background:#196748;color:#fff} #sales-editor-page #bill-check{background:#edf6f0;color:#196748;border-color:#b8d9c7} #bill-check-results{padding-inline-start:18px;margin:10px 0} #bill-check-results li{margin:6px 0} #bill-check-results li div{display:flex;flex-wrap:wrap;gap:4px;margin-top:4px} #bill-check-credit{margin:8px 0 0;padding:7px;background:#edf6f0;border-radius:6px;overflow-wrap:anywhere} #sales-editor-page kbd{font:inherit;font-size:10px;opacity:.8;margin-inline-start:3px}@media(pointer:coarse){#sales-editor-page kbd{display:none}} @media(min-width:721px){#suppliers-view .customer-table th:nth-child(2){width:24%} #suppliers-view .customer-table th:nth-child(3){width:16%}} #new-supplier{background:#196748;color:#fff;border-color:#196748} #adjust-supplier,#supplier-ask{color:#196748;font-weight:650} #supplier-dialog{width:min(420px,calc(100% - 24px));border:1px solid #d6e1e7;border-radius:8px;padding:14px} #supplier-fields{display:grid;gap:8px;margin:10px 0} #supplier-fields label{display:grid;gap:3px} #sales-editor-page #sales-settings-open{display:inline-grid;place-items:center;flex:0 0 27px;align-self:center;box-sizing:border-box;width:27px;height:27px;margin:0;padding:0;background:#fff;color:#196748;border:1px solid #d2e1da;border-radius:5px;line-height:1;cursor:pointer} @media(max-width:720px){ #sales-editor-page #sales-settings-open{border:0;background:transparent} } #sales-settings{width:min(496px,calc(100% - 24px));max-height:94vh;max-height:94dvh;padding:0;border:1px solid #d8e1eb;border-radius:8px;color:#243642} #sales-settings::backdrop{background:#182a4060} #sales-settings-form{display:flex;flex-direction:column;max-height:94vh;max-height:94dvh} #sales-settings header,#sales-settings footer{display:flex;align-items:center;justify-content:space-between;padding:10px 14px} #sales-settings header{background:#eef2fa}#sales-settings h2{margin:0;font-size:16px} #sales-settings button{cursor:pointer;border:0;border-radius:4px;padding:5px 9px} #sales-settings footer{justify-content:flex-end;border-top:1px solid #e1e8ee} #sales-settings footer button{background:#196748;color:white} .sales-settings-options{overflow:auto;padding:12px 24px} .sales-settings-options label{display:flex;align-items:center;gap:8px;min-height:22px;font-size:12px;cursor:pointer} .sales-settings-options input{margin:0;accent-color:#196748} #sales-entry [data-setting-hidden][hidden]{display:none!important} #sales-entry [hidden]{display:none!important} #sales-optional-controls{display:flex;align-items:center;gap:8px;flex-wrap:wrap;font-size:12px} #sales-optional-controls label{display:inline-flex;align-items:center;gap:4px} .bill-lines thead th[scope=colgroup],.bill-lines thead tr:nth-child(2) th{text-align:center} #sales-editor-page .bill-lines tbody td>select:is([data-field=tax],[data-field=unit]){width:100%;height:29px;min-width:60px;padding:0 4px;font:inherit;color:inherit;background:inherit;border:1px solid #e4ebf0;border-radius:3px} #sales-editor-page .bill-lines table{table-layout:fixed;width:100%;min-width:var(--bill-min-width,1140px);font-variant-numeric:tabular-nums} #sales-editor-page .bill-lines tbody td:nth-child(2){overflow:hidden;text-overflow:ellipsis;white-space:nowrap} #sales-editor-page .bill-lines tbody td>select:is([data-field=tax],[data-field=unit]){min-width:0} #sales-editor-page .bill-dates:has([name=dueDate])>.bill-field:has([name=date]):not([hidden]):last-child, #sales-editor-page .bill-dates:has(.bill-field[hidden] [name=dueDate]) .bill-field:has([name=date]), #sales-editor-page .bill-lookup:has(.bill-field[hidden] [name=category]) .bill-field:has([name=subcategory]), #sales-editor-page .bill-lookup:has(.bill-field[hidden] [name=subcategory]) .bill-field:has([name=category]){grid-column:1/-1} .bill-account{position:relative} #sales-entry #bill-customers{position:absolute;inset:100% 0 auto;transform:none;display:block;max-height:180px;overflow:auto;background:#fff;border:1px solid #c7d5de;border-radius:4px;z-index:20;box-shadow:0 5px 12px #162b401a;padding:2px;color:#243642;font-size:12px} #bill-customers[hidden]{display:none!important} #bill-customers [role=option]{display:flex;justify-content:space-between;gap:8px;padding:5px 7px;cursor:pointer} #bill-customers [role=option]:hover,#bill-customers [aria-selected=true]{background:#eaf4ee} #bill-customers small{color:#426b89;white-space:nowrap} #sales-entry #bill-customers{padding:0;max-height:169px;border-radius:0;box-shadow:none} #bill-customers [role=option]{align-items:center;height:24px;padding:2px 8px 2px 5px;gap:6px} #bill-customers [role=option]::before{content:"";width:6px;height:6px;border-radius:50%;background:#16813f;flex:none} #bill-customers .bill-cash-option::before{background:#bd8900} #bill-customers .bill-supplier-option::before{background:#c62e37} #bill-customers .bill-customer-name{text-align:left;max-width:min(23ch,100%)} #bill-customers .bill-customer-name{flex:1;min-width:0;max-width:23ch;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} #bill-customers small{margin-left:auto;font-size:inherit;color:#3951a2;font-variant-numeric:tabular-nums} #bill-customers .bill-cash-option{justify-content:flex-start} #bill-customers .bill-cash-option .bill-customer-name{flex:0 1 auto} #sales-editor-page .bill-lines tbody td{padding-block:2px} #sales-editor-page .bill-lines tbody td>input{height:26px} #sales-editor-page .bill-lines tbody td>select:is([data-field=tax],[data-field=unit]){height:25px;border:0;background:transparent} #sales-editor-page .bill-lines td:nth-last-child(-n+2){padding-inline:1px;text-align:center} #sales-editor-page .bill-lines button.bill-description-button{min-width:0;padding:0 2px;background:transparent;border:0;color:#196748} #bill-item-list{position:fixed;box-sizing:border-box;transform:none;padding:0;max-height:194px;overflow:auto;background:#fff;border:1px solid #c7d5de;z-index:21;font-size:12px;line-height:1.4;pointer-events:auto} #bill-item-list[hidden]{display:none!important} #bill-item-list [role=option]{display:flex;justify-content:space-between;align-items:center;gap:8px;height:24px;padding:2px 8px;cursor:pointer} #bill-item-list [role=option]>span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} #bill-item-list [role=option]:hover,#bill-item-list [aria-selected=true]{background:#eaf4ee} #bill-item-list small{color:#3951a2;font-variant-numeric:tabular-nums} #bill-item-list small.out-of-stock{color:#bf2d33} #bill-item-list [role=option]{font-size:13px;min-height:26px;height:auto;padding:4px 9px} #bill-item-list small{font-size:inherit;text-align:right;min-width:4ch} #sales-editor-page .bill-lines tbody td>select:is([data-field=tax],[data-field=unit]){font-size:12px;padding-inline:4px 15px} #sales-editor-page .bill-party .bill-party-address{min-width:0;max-width:32ch;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} #bill-notes{align-self:start;width:min(100%,320px)} #bill-notes summary{cursor:pointer;width:max-content;font-size:12px;color:#196748} #bill-notes textarea:focus{border-color:var(--field-focus-border)!important} #bill-notes textarea{border-color:#d2dfe8!important;display:block;width:100%;min-height:44px;height:48px;margin-top:4px;resize:vertical} #sales-entry{padding-bottom:calc(var(--bill-footer-height,48px) + 8px)} #sales-editor-page .bill-footer{position:fixed;left:var(--bill-footer-left,0px);right:var(--bill-footer-right,0px);bottom:0;z-index:4;background:#fff;padding:7px 10px;box-shadow:0 -2px 8px #182a4010} @media(max-width:720px){ #sales-editor-page .bill-footer{bottom:calc(54px + env(safe-area-inset-bottom))} } #sales-editor-page .bill-lines tbody td>input.bill-row-item-search:focus{outline:none;box-shadow:none;border-color:transparent} #sales-editor-page .bill-lines tbody td>input:is([data-field=qty],[data-field=price],[data-field=discount]):focus{outline:none;box-shadow:none;border-color:transparent} #sales-editor-page .bill-lines tbody td>input.bill-row-item-editor{border-color:transparent;text-align:left;text-overflow:ellipsis;cursor:text} #sales-editor-page .bill-bottom{grid-template-columns:minmax(0,1fr) minmax(0, min(100%, 520px))} #sales-entry .bill-totals label{grid-template-columns:minmax(78px,112px) minmax(0,1fr);gap:4px;text-align:right} #sales-entry .bill-totals .bill-total-pair{grid-template-columns:minmax(78px,112px) repeat(2,minmax(0,1fr))} #sales-entry .bill-totals :is(input,select){width:100%;min-width:0} .bill-total-suffix{position:relative;min-width:0} #sales-entry .bill-total-suffix input{padding-right:34px} .bill-total-suffix>span{position:absolute;right:8px;top:50%;transform:translateY(-50%);pointer-events:none;color:#52657d;font-size:11px} .bill-total-pair output{display:block;min-width:0;padding:7px;border:1px solid #d6e1e7;border-radius:4px;background:#f4f6f8;overflow-wrap:anywhere} .bill-balance-line{font-weight:700} @media(max-width:720px){#sales-editor-page .bill-bottom{grid-template-columns:minmax(0,1fr)}} @media(min-width:721px){ #sales-editor-page .bill-lines{max-height:var(--bill-lines-height,48vh);overflow:auto;overscroll-behavior-y:contain} #sales-editor-page .bill-lines thead{position:sticky;top:0;z-index:2;background:#eef3f6} #sales-editor-page .bill-lines tfoot{position:sticky;bottom:0;z-index:1;background:#eaf1f5} } @media(min-width:721px){ html:has(#sales-editor-page:not([hidden])),body:has(#sales-editor-page:not([hidden])){scrollbar-width:none} html:has(#sales-editor-page:not([hidden]))::-webkit-scrollbar,body:has(#sales-editor-page:not([hidden]))::-webkit-scrollbar{display:none} #sales-editor-page .bill-lines{overflow-x:auto;overflow-y:auto} #sales-editor-page .bill-lines table{width:100%;box-sizing:border-box} #sales-editor-page .bill-lines{container-type:inline-size} @container (min-width:1200px){#sales-editor-page .bill-lines table{min-width:0}} } @media(min-width:721px){ #sales-editor-page .bill-lines{container-name:bill-columns} @container bill-columns (min-width:1200px){ #sales-editor-page .bill-lines :is(th,td){overflow:hidden} } } #sales-entry select[name=warehouse]:disabled{opacity:1;background:#eaf0f3;color:#3c5263;cursor:not-allowed} #sales-editor-page .bill-lines tbody td>:is(input[data-field],input.bill-row-item-search,select[data-field]){ border:1px solid transparent;outline:none;box-shadow:none } #sales-editor-page .bill-lines tbody td>:is(input[data-field],input.bill-row-item-search,select[data-field]):focus{ border-color:#aeb5bc;outline:none;box-shadow:none } #sales-editor-page #bill-rows td:has(>:is(input,select):not([hidden])){padding:0} #sales-editor-page #bill-rows td>:is(input,select){box-sizing:border-box;display:block;width:100%;max-width:none;height:32px;margin:0} /* Fit the row item search to the full cell, including while editing. */ #sales-editor-page #bill-rows td:has(>input.bill-row-item-search:not([hidden])){position:relative;height:32px} #sales-editor-page #bill-rows td>input.bill-row-item-search:not([hidden]){ position:absolute;inset:0;width:100%;height:100%;border-radius:0 } /* Shared field appearance for current and future form controls. */ :root{--field-focus-border:#aeb5bc} :is(input:not([type=checkbox],[type=radio],[type=hidden],[type=range],[type=color],[type=button],[type=submit],[type=reset],[type=image]),select,textarea){ box-sizing:border-box; border:1px solid transparent!important; outline:none!important; box-shadow:none!important; } :is(input:not([type=checkbox],[type=radio],[type=hidden],[type=range],[type=color],[type=button],[type=submit],[type=reset],[type=image]),select,textarea):focus{ border-color:var(--field-focus-border)!important; } #sales-entry #bill-cost-open{justify-self:end;padding:0;background:none;color:inherit;border:0;text-decoration:underline;font:inherit;cursor:pointer} #bill-cost-dialog{width:min(452px,calc(100% - 24px));padding:15px;border:1px solid #d6e1e7;border-radius:8px;color:#243642} #bill-cost-form{display:flex;flex-direction:column;min-height:min(465px,75vh);gap:12px} #bill-cost-form .customer-dialog-heading h2{font-size:17px} .bill-cost-table{overflow:auto;max-height:45vh} #bill-cost-form table{width:100%;border-collapse:collapse;table-layout:fixed;font-size:12px} #bill-cost-form :is(th,td){padding:3px;border:1px solid #dce5eb;text-align:center} #bill-cost-form thead{background:#e6eef3} #bill-cost-form th:nth-child(3){width:20%} #bill-cost-form th:last-child{width:32px} #bill-cost-form :is(input,select){width:100%;min-width:0;padding:3px;font:inherit} #bill-cost-form input[type=number]{text-align:right} #bill-cost-form button{cursor:pointer} #bill-cost-add{color:#16803c} #bill-cost-rows button{color:#c53137} #bill-cost-form footer{margin-top:auto;display:flex;justify-content:space-between;align-items:flex-start;gap:8px} #bill-cost-form footer ul{margin:0;padding-left:17px;font-size:11px;line-height:1.7} #bill-cost-form button[type=submit]{padding:6px 10px;border:0;border-radius:4px;background:#148000;color:white} #bill-cost-form :is(tbody,tfoot) :is(tr,th,td,input,select,button,output){ background:transparent!important;box-shadow:none } #bill-cost-form :is(tbody,tfoot) :is(th,td){border:1px solid #e4e9ed} #bill-cost-form tbody button{border-color:transparent} #bill-cost-form :is(tbody,tfoot) :is(input,select,button):focus-visible{ outline:1px solid #aeb5bc!important;outline-offset:-1px } #bill-cost-form tbody td:has(>:is(input,select)){padding:0} #bill-cost-form tbody td>:is(input,select){box-sizing:border-box;display:block;width:100%;max-width:none;height:24px;min-height:0;margin:0;border-radius:0;padding:0 6px} #bill-cost-form tbody td:last-child{padding:0} #bill-cost-form tbody button{height:24px;min-height:0;padding:0 5px;line-height:1} #sales-entry :is(.bill-meta,.bill-totals) :is(input,select){border-color:#d2dfe8!important} #sales-entry :is(.bill-meta,.bill-totals) :is(input,select):focus{border-color:var(--field-focus-border)!important} #sales-entry .bill-field>span:first-child{ background:linear-gradient(to bottom,transparent 50%,var(--bill-field-surface,#fff) 50%); } #sales-entry .bill-field:has(select:disabled){--bill-field-surface:#eaf0f3} #bill-rows button.bill-wise-item{padding:0;border:0;background:none;color:inherit!important;font:inherit;text-decoration:none;cursor:pointer} #bill-wise-stock{padding:0;border:0;border-radius:8px 8px 3px 3px;color:#252525;background:white} #bill-wise-stock::backdrop{background:#0008} #bill-wise-stock .customer-dialog-heading{padding:14px 15px;margin:0} #bill-wise-title{font-size:18px;color:#252525} #bill-wise-title .bill-wise-title-unit{font-size:12px;color:inherit} #bill-wise-warehouse{margin:0 15px 7px;font-size:11px;color:#526474} #bill-wise-stock .bill-wise-table{overflow:auto;margin:0 15px 15px} #bill-wise-stock table{margin:0;border-collapse:collapse;font-size:12px} #bill-wise-stock :is(th,td){border:1px solid #d8d8d8;text-align:center;padding:7px 8px;background:white} #bill-wise-stock th{padding-block:3px;background:#e8ebf3;font-weight:500} #bill-wise-stock tbody td{padding-block:1px} #bill-wise-stock tbody :is(input,select){height:23px;min-height:0;margin:0;padding:0 4px;font:inherit;color:inherit;background:transparent} #bill-wise-stock .bill-wise-footer{display:flex;justify-content:flex-end;align-items:center;gap:16px;background:#f5f7f7;padding:19px} #bill-wise-stock output{display:block;width:min(238px,60%);border:1px solid #d2d2d2;border-radius:3px;padding:7px 10px;text-align:right} #bill-wise-stock button[value=apply]{background:#108000;color:white;border:0;border-radius:5px;padding:9px 16px;font-weight:650} #bill-item-qty{text-align:right} #bill-save-menu{position:relative} #bill-save-menu summary{list-style:none;cursor:pointer;padding:7px 9px;border:1px solid #196748;border-radius:5px;background:#edf6f0;color:#14583d;font-weight:650} #bill-save-menu summary::-webkit-details-marker{display:none} #bill-save-menu div{position:absolute;right:0;bottom:calc(100% + 6px);min-width:150px;padding:5px;border:1px solid #d2dfe8;border-radius:6px;background:white;box-shadow:0 4px 12px #0002} #sales-entry #bill-save-menu div button{display:flex;align-items:center;gap:5px;width:100%;text-align:left;white-space:nowrap;background:transparent;color:#26343b;border:0;padding:4px 6px;font-weight:500} #sales-entry #bill-save-menu div .bill-mobile-save{display:none} @media(max-width:720px){ #sales-entry #bill-save-menu div .bill-mobile-save{display:flex} #sales-entry #bill-save-menu div .bill-desktop-save{display:none} } #sales-entry #bill-save-menu div button:is(:hover,:focus-visible){background:#edf3f5} #bill-save-menu div i{display:grid;place-items:center;width:23px;height:23px;border-radius:5px;background:#edf3f5;color:inherit} #sales-dates input[type=date]{border-color:#d2dfe8!important} #sales-dates input[type=date]:focus{border-color:var(--field-focus-border)!important} @media(max-width:720px){ #sales-editor-page .bill-meta{ grid-template-columns:repeat(6,minmax(0,1fr));gap:0 5px;padding:7px; background:#f3f7fa;border:1px solid #d6e1e7;border-radius:6px; } #sales-editor-page .bill-meta :is(.bill-lookup,.bill-dates){display:contents} #sales-editor-page .bill-meta .bill-field:has([name=number]){grid-area:1/1/2/3} #sales-editor-page .bill-meta .bill-field:has([name=date]){grid-area:1/3/2/5} #sales-editor-page .bill-meta .bill-field:has([name=dueDate]){grid-area:1/5/2/7} #sales-editor-page .bill-meta:not(:has(.bill-field:not([hidden]) [name=dueDate])) .bill-field:has([name=date]){grid-column:3/7} #sales-editor-page .bill-meta .bill-warehouse{grid-area:2/1/3/4} #sales-editor-page .bill-meta .bill-field:has([name=person]){grid-area:2/4/3/7} #sales-editor-page .bill-meta:not(:has(.bill-field:not([hidden]) [name=person])) .bill-warehouse{grid-column:1/7} #sales-editor-page .bill-meta .bill-account{grid-area:3/1/4/7} #sales-editor-page .bill-meta .bill-party{grid-area:4/1/5/7;margin:0} #sales-editor-page .bill-meta .bill-party:empty{display:none} #sales-editor-page .bill-meta .bill-field:has([name=category]){grid-area:5/1/6/4} #sales-editor-page .bill-meta .bill-field:has([name=subcategory]){grid-area:5/4/6/7} #sales-editor-page .bill-meta .bill-item-field{grid-area:6/1/7/7} #sales-editor-page .bill-meta .bill-field :is(input,select){min-height:27px;height:27px;margin-block:4px} #sales-editor-page .bill-meta .bill-account input{height:36px;font-size:14px} #sales-editor-page .bill-meta :is(.bill-warehouse,.bill-field:has([name=person])) :is(input,select){ border-width:0 0 1px!important;border-style:dotted!important;border-radius:0;background:transparent; } #sales-editor-page .bill-item-info{display:flex;align-items:center;gap:5px} #sales-editor-page #bill-item-view{margin-inline-end:auto} } @media(max-width:720px){ #sales-editor-page{margin-inline:8px;padding:0;border:0;background:#fff} #sales-editor-page .sales-editor-heading{gap:5px;padding:2px 6px;background:#edf3f8;border-radius:7px 7px 0 0} #sales-editor-page .sales-editor-heading h1{font-size:12px} #sales-editor-page .sales-editor-heading .customer-back{font-size:10px} #sales-editor-page .bill-meta{padding:0 5px 6px;border:0;border-radius:0;background:#fff} #sales-editor-page .bill-meta .bill-account input{height:29px;font-size:13px} #sales-editor-page .bill-meta .bill-field:has(:is([name=number],[name=date],[name=dueDate])){ display:flex;align-items:center;gap:2px;min-width:0;background:#edf3f8;padding-inline:2px } #sales-editor-page .bill-meta .bill-field[hidden]{display:none} #sales-editor-page .bill-meta .bill-field:has(:is([name=number],[name=date],[name=dueDate])) input{ padding:0;margin:0;font-size:11px;border-color:transparent!important;background:transparent } #sales-editor-page .bill-meta .bill-field:has(:is([name=date],[name=dueDate])) > span:first-child{ position:static;transform:none;padding:0;background:none;white-space:nowrap;font-size:10px } #sales-editor-page .bill-meta .bill-field:has([name=number]) > span:first-child{ position:absolute;width:1px;height:1px;opacity:0 } } @media(max-width:720px){ main:has(#sales-editor-page:not([hidden])) > .topbar, #sales-editor-page .bill-meta .bill-party{display:none} #sales-editor-page .sales-editor-heading{background:transparent} #sales-editor-page .bill-meta .bill-field:has(:is([name=number],[name=date],[name=dueDate])){ background:#eaf1f7; } #sales-editor-page .bill-meta .bill-field:has([name=number]){ box-shadow:5px 0 #eaf1f7;border-radius:4px 0 0 4px;padding-inline-start:6px; } #sales-editor-page .bill-meta .bill-field:has([name=date]){ box-shadow:5px 0 #eaf1f7; } #sales-editor-page .bill-meta .bill-field:has([name=dueDate]), #sales-editor-page .bill-meta:not(:has(.bill-field:not([hidden]) [name=dueDate])) .bill-field:has([name=date]){ box-shadow:none;border-radius:0 4px 4px 0;padding-inline-end:6px; } #sales-editor-page .bill-meta .bill-field:has([name=date]){justify-content:flex-end} #sales-editor-page .bill-meta .bill-field:has([name=dueDate]){justify-content:flex-end} #sales-editor-page .bill-meta .bill-field input[type=date]{width:auto;max-width:100%} #sales-editor-page .bill-meta:not(:has(.bill-warehouse:not([hidden]) select:not([hidden]))) .bill-field:has([name=person]){grid-column:1/7} } @media(max-width:720px){ #sales-editor-page .sales-editor-heading{padding-block:0;margin-bottom:2px} #sales-editor-page .sales-editor-heading #sales-settings-open{height:23px} #sales-editor-page .bill-meta{column-gap:5px} #sales-editor-page .bill-meta .bill-field:has([name=number]){grid-column:1/3} #sales-editor-page .bill-meta .bill-field:has(input[type=date]){ flex-direction:row;align-items:center;justify-content:flex-end;gap:2px;padding-block:0 } #sales-editor-page .bill-meta .bill-field:has(input[type=date]) > span:first-child{font-size:11px;line-height:normal;align-self:center;transform:none} #sales-editor-page .bill-meta .bill-field input[type=date]{width:90px;min-width:0;min-height:25px;height:25px;font-size:11px} #sales-editor-page .bill-meta:has(.bill-field:not([hidden]) [name=dueDate]) .bill-field:has([name=number]){grid-column:1/2} #sales-editor-page .bill-meta:has(.bill-field:not([hidden]) [name=dueDate]) .bill-field:has([name=date]){grid-column:2/4} #sales-editor-page .bill-meta .bill-field:has([name=dueDate]){grid-column:4/7} #sales-editor-page .bill-meta input[type=date]::-webkit-calendar-picker-indicator{margin:0;padding:0;cursor:pointer} #sales-editor-page .bill-meta .bill-field:not(:has(:is([name=number],[name=date],[name=dueDate]))) :is(input,select){ box-sizing:border-box;height:30px;min-height:30px;margin-block:4px;border:1px solid #c9d9e6!important;border-radius:5px;background:#fff;font-size:12px } } .bill-date-mobile{display:none} @media(max-width:720px){ #sales-editor-page .bill-date-desktop{display:none} #sales-editor-page .bill-date-mobile{display:inline} #sales-editor-page .bill-meta .bill-field:has([name=dueDate]) > span:first-child::after{content:":"} #sales-editor-page .bill-meta .bill-field:has([name=dueDate]){justify-content:flex-end} } @media(max-width:720px){ #sales-editor-page .bill-meta .bill-field:has(:is([name=category],[name=subcategory])) > span:first-child{ top:4px; } } @media(max-width:720px){ #sales-editor-page .bill-meta .bill-field:has(input[type=date]) input{ font-family:inherit;line-height:normal;margin:0; } html:has(#sales-editor-page:not([hidden])), body:has(#sales-editor-page:not([hidden])), #sales-editor-page, #sales-editor-page *{scrollbar-width:none} html:has(#sales-editor-page:not([hidden]))::-webkit-scrollbar, body:has(#sales-editor-page:not([hidden]))::-webkit-scrollbar, #sales-editor-page::-webkit-scrollbar, #sales-editor-page *::-webkit-scrollbar{display:none} } @media(max-width:720px){ #sales-editor-page .sales-editor-heading{margin:0;padding-block:0;min-height:0} #sales-editor-page .sales-editor-heading #sales-settings-open{height:19px} #sales-editor-page .bill-meta .bill-field:has(:is([name=number],[name=date],[name=dueDate])){ align-self:stretch;min-height:24px } #sales-editor-page .bill-meta .bill-field input[type=date]{width:77px;height:24px;min-height:24px} #sales-editor-page .bill-meta .bill-field:not(:has(:is([name=number],[name=date],[name=dueDate]))) > span:first-child{ top:4px;transform:translateY(-50%); } } @media(max-width:720px){ #sales-editor-page #sales-entry.mobile-item-cards .bill-lines{border:0;border-radius:0;overflow:visible} #sales-editor-page #sales-entry.mobile-item-cards .bill-lines :is(table,tbody){display:block;width:100%;min-width:0} #sales-editor-page #sales-entry.mobile-item-cards .bill-lines :is(thead,colgroup){display:none} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr{ display:grid;grid-template-columns:repeat(12,minmax(0,1fr));gap:4px; margin-bottom:5px;padding:6px;border:1px solid #d2dfe8;border-radius:6px;background:#fff; } #sales-editor-page #sales-entry.mobile-item-cards #bill-rows td:not([hidden]){ display:block;min-width:0;border:0;padding:0 4px;grid-column:span 4;text-align:left;white-space:normal; } #sales-editor-page #sales-entry.mobile-item-cards #bill-rows td[data-card-label]::before{ content:attr(data-card-label);display:block;color:#52657d;font-size:10px;line-height:14px; } #sales-editor-page #sales-entry.mobile-item-cards #bill-rows td:nth-child(1){grid-area:1/1/2/2;color:#52657d} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows td:nth-child(2){grid-area:1/2/2/11;font-weight:600;height:auto} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows td:nth-child(20){grid-area:1/11/2/12} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows td:nth-child(21){grid-area:1/12/2/13} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows td > :is(input,select){height:27px;text-align:left} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows td > input.bill-row-item-search:not([hidden]){position:static;height:27px} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-empty-item] td:not(:nth-child(1),:nth-child(2),:nth-child(21)){display:none} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-empty-item] td:nth-child(2){grid-column:2/12} #sales-editor-page #sales-entry.mobile-item-cards .bill-lines tfoot{display:block} #sales-editor-page #sales-entry.mobile-item-cards .bill-lines tfoot tr{display:flex;flex-wrap:wrap;background:#eaf1f7;border-radius:5px} #sales-editor-page #sales-entry.mobile-item-cards .bill-lines tfoot :is(td,th):not([hidden]){border:0;padding:4px 6px;background:none} #sales-editor-page #sales-entry.mobile-item-cards .bill-lines tfoot :is(td,th):empty{display:none} #sales-editor-page #sales-entry.mobile-item-cards .bill-lines tfoot td:last-of-type{margin-inline-start:auto} } .mobile-card-edit{display:none} #mobile-line-dialog{width:min(400px,calc(100vw - 20px));border:1px solid #c6d6e5;border-radius:9px;padding:10px} .mobile-line-step{display:flex;justify-content:center;margin:6px 0 12px} .mobile-line-step input{width:65px;text-align:center} .mobile-line-fields{display:grid;grid-template-columns:1fr 1fr;gap:7px} .mobile-line-fields label{display:grid;gap:2px} .mobile-line-fields label[hidden]{display:none} .mobile-line-fields :is(input,select,output){width:100%;min-width:0;padding:4px;border:1px solid #c6d6e5!important;border-radius:4px} .mobile-line-actions{display:flex;justify-content:space-between;align-items:center;margin-top:9px} .mobile-line-actions output{background:#e8f4ed;padding:6px;border-radius:4px} @media(max-width:720px){ #sales-entry.mobile-item-cards .bill-lines tfoot, #sales-entry.mobile-item-cards #bill-rows tr[data-empty-item], #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(2) > :not(.mobile-card-edit){display:none} #sales-entry.mobile-item-cards #bill-rows tr[data-item]{position:relative;min-height:72px} #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(1){grid-area:1/1/2/11} #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(2){grid-area:2/1/3/9;overflow:visible} #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(2)::before{content:attr(data-card-name);display:block} #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(2)::after{content:attr(data-card-summary);display:block;white-space:pre-line;font-size:10px;font-weight:400;color:#52657d} #sales-entry.mobile-item-cards #bill-rows tr[data-item]::after{content:attr(data-card-total);grid-area:2/9/3/13;text-align:right;white-space:pre-line;font-size:11px;font-weight:600} #sales-entry.mobile-item-cards #bill-rows .mobile-card-edit{display:block;position:absolute;right:32px;top:4px;color:#6750a4} } @media(max-width:720px){ #sales-editor-page #sales-entry.mobile-item-cards .bill-lines:not(:has(#bill-rows tr[data-item])){display:none} } @media(max-width:720px){ #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item]{min-height:0;gap:3px 4px;padding:7px} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(1){grid-area:1/1/2/2} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(2){grid-area:1/2/2/10;padding-right:0} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item]::after{grid-area:2/9/3/13;align-self:start} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(20){grid-area:1/10/2/11} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(21){grid-area:1/12/2/13} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:is(:nth-child(10),:nth-child(11)):not([hidden]){grid-row:2} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(10){grid-column:1/5} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(11){grid-column:5/9} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td[data-card-label]:not([hidden]){padding:0 3px} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td > :is(input,select){height:24px} } @media(max-width:720px){ #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-empty-item], #sales-editor-page #sales-entry.mobile-item-cards .bill-lines tfoot, #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:not(:nth-child(1),:nth-child(2),:nth-child(21)){display:none} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(1){grid-area:1/1/2/10} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(2){grid-area:2/1/3/9} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(21){grid-area:1/12/2/13;text-align:right} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item]::after{align-self:end} } @media(max-width:720px){ #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item]{padding:4px 7px;gap:0 4px;line-height:1.2} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:first-child{padding:0;align-self:center;font-size:11px} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(2){padding:0} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:nth-child(2)::after{line-height:12px} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:last-child{padding:0} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] :is(.mobile-card-edit,td:last-child button){ display:inline-grid;place-items:center;width:22px;height:20px;min-height:0;padding:0;border:0;background:transparent;line-height:1;font-size:0 } #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] .mobile-card-edit{top:4px;right:30px;color:#7347d1} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] .mobile-card-edit::before{content:"\f044";font:900 11px "Font Awesome 6 Free"} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:last-child button::before{ content:"×";display:grid;place-items:center;width:11px;height:11px;border:1px solid currentColor;border-radius:50%;color:#a13232;font:11px/1 sans-serif } } @media(max-width:720px){ #sales-editor-page .bill-meta{padding-bottom:3px} #sales-editor-page .bill-meta .bill-field:not(:has(:is([name=number],[name=date],[name=dueDate]))) :is(input,select){ height:32px;min-height:32px;margin-block:4px 1px } #sales-editor-page .bill-item-info{min-height:0;margin-top:0} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item]{margin:0 5px 3px;padding:2px 6px} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] td:first-child::after{content:"."} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] :is(.mobile-card-edit,td:last-child button){height:16px} #sales-editor-page #sales-entry.mobile-item-cards #bill-rows tr[data-item] .mobile-card-edit{top:2px} } @media(max-width:720px){ body:has(#sales-editor-page:not([hidden])) .mobile-nav{display:none} #sales-editor-page:not([hidden]) .bill-footer{bottom:0;padding-bottom:calc(7px + env(safe-area-inset-bottom))} } .mobile-line-step > div{display:flex;align-items:stretch;border:1px solid #c6d6e5;border-radius:5px;overflow:hidden} .mobile-line-step > div :is(input,button){border:0;border-radius:0;min-height:32px;background:#fff;margin:0} .mobile-line-step > div input{border-inline:1px solid #c6d6e5;appearance:textfield} .mobile-line-step input::-webkit-inner-spin-button,.mobile-line-step input::-webkit-outer-spin-button{appearance:none;margin:0} .mobile-line-fields label{position:relative;margin-top:5px} .mobile-line-fields label > span{position:absolute;top:0;left:8px;transform:translateY(-50%);padding:0 3px;background:#fff;font-size:10px;color:#52657d} .mobile-line-fields :is(input,select,output){min-height:30px} #mobile-line-form .mobile-line-step [data-qty-step]{border:0!important;border-radius:0!important;min-width:32px;box-shadow:none} #mobile-line-form .mobile-line-step input{border-width:0 1px!important;border-color:#c6d6e5!important;border-radius:0!important} .mobile-line-result{display:flex;gap:4px 12px;flex-wrap:wrap;background:#e8f4ed;border-radius:5px;padding:7px 9px;font-variant-numeric:tabular-nums} .mobile-line-result output{display:inline;background:transparent;padding:0} @media(max-width:720px){ #mobile-line-dialog{width:min(420px,calc(100vw - 24px));padding:12px;border-radius:12px;box-shadow:0 12px 30px #142c4229} #mobile-line-form .customer-dialog-heading{flex-wrap:nowrap;padding-bottom:8px;border-bottom:1px solid #e3eaf0} #mobile-line-title{margin:0;font-size:14px;overflow-wrap:anywhere} #mobile-line-close{flex:none;width:32px;height:32px;padding:0} #mobile-line-form .mobile-line-step{margin:9px 0 11px} #mobile-line-form .mobile-line-step > div{border-radius:7px;background:#f5f8fa} #mobile-line-form .mobile-line-step [data-qty-step]{min-width:38px;min-height:36px;background:#f5f8fa;color:#196748;font-size:16px} #mobile-line-form .mobile-line-step input{width:74px;font-weight:650} #mobile-line-form .mobile-line-fields{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px} #mobile-line-form .mobile-line-fields :is(input,select,output){min-height:35px;padding:7px 8px} #mobile-line-form .mobile-line-fields output{background:#f5f8fa} #mobile-line-form .mobile-line-actions{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px;margin-top:10px} #mobile-line-form .mobile-line-result{align-items:center;min-height:36px;padding:6px 8px;color:#15563e;font-size:12px} #mobile-line-form .mobile-line-result span{white-space:nowrap} #mobile-line-form .mobile-line-actions button{min-height:36px;padding:0 13px;background:#196748;border-color:#196748;color:#fff;font-weight:650} } #sales-entry .bill-totals input[name=cost]{text-align:right} #sales-entry .bill-totals input[type=checkbox]{width:auto;margin:0 4px 0 0;vertical-align:middle;accent-color:#196748} #bill-add-row:not([hidden]){display:block;margin:auto;padding:0;width:20px;height:20px;line-height:1;color:#196748;background:#fff;border:1px solid #d2dfe8;border-radius:4px;cursor:pointer} </style></head><body> <div class="layout" id="layout"><aside id="sidebar"><div class="company"><span class="avatar">S</span><div><strong>Sumon Enterprise</strong><small>admin</small></div></div><nav aria-label="Dashboard navigation"><div class="nav-row active" title="Dashboard" aria-current="page"><i class="fa-solid fa-table-cells-large" aria-hidden="true"></i><span>Dashboard</span></div><p>Transaction</p><details class="nav-group" name="desktop-navigation"><summary class="nav-row" title="Parties" aria-label="Parties"><i class="fa-solid fa-users" aria-hidden="true"></i><span>Parties</span></summary><ul class="sub-menu"><li><button type="button" class="customer-link" data-open-customers>Customers</button></li><li><button type="button" class="customer-link" data-open-suppliers>Suppliers</button></li></ul></details><details class="nav-group" name="desktop-navigation"><summary class="nav-row" title="Item" aria-label="Item"><i class="fa-solid fa-cube" aria-hidden="true"></i><span>Item</span></summary><ul class="sub-menu"><li>Product</li></ul></details><details class="nav-group" name="desktop-navigation"><summary class="nav-row" title="Sales" aria-label="Sales"><i class="fa-solid fa-cart-shopping" aria-hidden="true"></i><span>Sales</span></summary><ul class="sub-menu"><li><button type="button" class="customer-link" data-open-sales>Sale Invoice</button></li><li>Sales Return</li></ul></details><details class="nav-group" name="desktop-navigation"><summary class="nav-row" title="Purchases" aria-label="Purchases"><i class="fa-solid fa-cart-flatbed" aria-hidden="true"></i><span>Purchases</span></summary><ul class="sub-menu"><li>Purchases Bill</li><li>Purchases Return</li><li>Price History</li></ul></details><p>Accounts</p><div class="nav-row " title="Receipt In"><i class="fa-solid fa-hand-holding-dollar" aria-hidden="true"></i><span>Receipt In</span></div><div class="nav-row " title="Payment Out"><i class="fa-solid fa-money-bill-transfer" aria-hidden="true"></i><span>Payment Out</span></div><div class="nav-row " title="Income"><i class="fa-solid fa-chart-line" aria-hidden="true"></i><span>Income</span></div><div class="nav-row " title="Expense"><i class="fa-solid fa-chart-area" aria-hidden="true"></i><span>Expense</span></div><div class="nav-row " title="Contra"><i class="fa-solid fa-scale-balanced" aria-hidden="true"></i><span>Contra</span></div><details class="nav-group" name="desktop-navigation"><summary class="nav-row" title="Accounts" aria-label="Accounts"><i class="fa-solid fa-book" aria-hidden="true"></i><span>Accounts</span></summary><ul class="sub-menu"><li>Cash In Hand</li><li>Bank</li></ul></details><div class="nav-row " title="Accounts View"><i class="fa-solid fa-chart-pie" aria-hidden="true"></i><span>Accounts View</span></div><p>Reports</p><details class="nav-group" name="desktop-navigation"><summary class="nav-row" title="Transaction" aria-label="Transaction reports"><i class="fa-solid fa-chart-column" aria-hidden="true"></i><span>Transaction</span></summary><ul class="sub-menu"><li>Sales Transaction</li><li>Purchase Transaction</li><li>Bill Details</li><li>All Parties</li><li>Customer</li><li>Supplier</li><li>Bill Wise Profit</li><li>Party Wise Profit</li></ul></details><details class="nav-group" name="desktop-navigation"><summary class="nav-row" title="Accounts" aria-label="Accounts reports"><i class="fa-solid fa-chart-area" aria-hidden="true"></i><span>Accounts</span></summary><ul class="sub-menu"><li>Cash Flow</li><li>Day Book</li><li>Ledger Book</li><li>Balance Sheet</li><li>Trial Balance</li><li>Profit & Loss</li></ul></details><details class="nav-group" name="desktop-navigation"><summary class="nav-row" title="Inventory" aria-label="Inventory reports"><i class="fa-solid fa-cubes" aria-hidden="true"></i><span>Inventory</span></summary><ul class="sub-menu"><li>Current Stock</li><li>By Category</li><li>Stock Summary</li><li>Stock Details</li><li>Item Details</li><li>Daily Summary</li><li>Serial Tracking</li><li>Batch Tracking</li><li>Party Wise Item</li><li>Item Wise P/L</li></ul></details><div class="nav-row " title="User Management"><i class="fa-solid fa-users-gear" aria-hidden="true"></i><span>User Management</span></div><div class="nav-row " title="Tools"><i class="fa-solid fa-wrench" aria-hidden="true"></i><span>Tools</span></div></nav></aside> <main><div class="topbar"><div class="mobile-company"><span class="avatar" aria-hidden="true">S</span><strong>Sumon Enterprise</strong></div><button id="menu" type="button" aria-label="Toggle sidebar" aria-controls="sidebar">☰</button><header class="intro"><h1>Good Evening, <span>hasan!</span></h1><p>Dhaka, Bangladesh · Thursday, 12 Nov 2026 · 6:46 PM</p></header><strong>Commerce Book ERP</strong></div> <div class="content" id="dashboard-content"> <section class="summary" aria-label="Financial summary"><article class="card green"><header><span class="icon"><i class="fa-solid fa-handshake" aria-hidden="true"></i></span><h2>Receivables</h2></header><p class="balance">6,810.00</p><p class="caption">2 Customers</p><div class="breakdown"><h3>Today’s Sales</h3><dl><div><dt>Cash</dt><dd>0.00</dd></div><div><dt>Credit</dt><dd>270.00</dd></div><div><dt>Receipts</dt><dd>0.00</dd></div></dl></div></article><article class="card amber"><header><span class="icon"><i class="fa-solid fa-truck" aria-hidden="true"></i></span><h2>Payables</h2></header><p class="balance">8,850.00</p><p class="caption">1 Supplier</p><div class="breakdown"><h3>Today’s Purchases</h3><dl><div><dt>Cash</dt><dd>0.00</dd></div><div><dt>Credit</dt><dd>0.00</dd></div><div><dt>Payments</dt><dd>0.00</dd></div></dl></div></article><article class="card blue"><header><span class="icon"><i class="fa-solid fa-wallet" aria-hidden="true"></i></span><h2>Cash in Hand</h2></header><p class="balance negative">−8,375.00</p><p class="caption">Current cash balance</p><div class="breakdown"><h3>Today’s Cash Flow</h3><dl><div><dt>Cash in</dt><dd>+ 0.00</dd></div><div><dt>Cash out</dt><dd>− 0.00</dd></div></dl></div></article><article class="card violet"><header><span class="icon"><i class="fa-solid fa-building-columns" aria-hidden="true"></i></span><h2>Bank Balance</h2></header><p class="balance">0.00</p><p class="caption">Current bank balance</p><div class="breakdown"><h3>Today’s Bank Flow</h3><dl><div><dt>Bank in</dt><dd>+ 0.00</dd></div><div><dt>Bank out</dt><dd>− 0.00</dd></div></dl></div></article></section> <div class="analytics"><section class="panel"><h2>Last 7 Days Sales</h2><div class="plot"><div class="scale"><span>5.4k</span><span>4.3k</span><span>3.2k</span><span>2.2k</span><span>1.1k</span><span>0</span></div><div><svg viewBox="0 0 600 150" preserveAspectRatio="none" role="img" aria-label="Sales peaked on 10 November"><defs><linearGradient id="fill" x2="0%" y2="100%"><stop stop-color="#b9dec9"/><stop offset="100%" stop-color="#f5fbf7"/></linearGradient></defs><path fill="url(#fill)" d="M0 149H100C140 149 166 2 200 2S266 131 300 131S370 141 400 142S465 149 500 149H600V150H0Z"/><path fill="none" stroke="#238353" stroke-width="2" vector-effect="non-scaling-stroke" d="M0 149H100C140 149 166 2 200 2S266 131 300 131S370 141 400 142S465 149 500 149H600"/></svg><div class="dates"><span>8 Nov</span><span>9 Nov</span><span>10 Nov</span><span>11 Nov</span><span>12 Nov</span><span>13 Nov</span><span>14 Nov</span></div></div></div></section> <section class="panel"><h2>This Week’s Distribution</h2><div class="distribution"><div class="donut" aria-hidden="true">100%<small>Receipt</small></div><dl class="legend"><div><dt><span class="dot" style="--dot:#23835f"></span>Receipt</dt><dd>100%</dd></div><div><dt><span class="dot" style="--dot:#d79c19"></span>Payment</dt><dd>0%</dd></div><div><dt><span class="dot" style="--dot:#367cd3"></span>Income</dt><dd>0%</dd></div><div><dt><span class="dot" style="--dot:#3b9997"></span>Expense</dt><dd>0%</dd></div></dl></div></section></div> <div class="reports"><section class="panel"><h2>Best Selling</h2><div class="table-wrap" tabindex="0" role="region" aria-label="Best Selling"><table><thead><tr><th scope="col">Product Name</th><th scope="col">Qty</th><th scope="col">Unit</th><th scope="col">Amount</th></tr></thead><tbody><tr><td>product04</td><td>8</td><td>pc</td><td>1,960.00</td></tr><tr><td>New R4</td><td>6</td><td>pc</td><td>1,020.00</td></tr><tr><td>New R5</td><td>5</td><td>pc</td><td>630.00</td></tr><tr><td>Biskit2</td><td>5</td><td>pc</td><td>660.00</td></tr><tr><td>New Reciclin</td><td>4</td><td>pc</td><td>520.00</td></tr><tr><td>New R3</td><td>4</td><td>pc</td><td>2,060.00</td></tr><tr><td>Restore Item</td><td>3</td><td>pc</td><td>540.00</td></tr><tr><td>Samsung A51</td><td>1</td><td>pc</td><td>400.00</td></tr><tr><td>Samsung A52</td><td>1</td><td>pc</td><td>400.00</td></tr></tbody></table></div></section><section class="panel"><h2>Today Stock Details</h2><div class="table-wrap" tabindex="0" role="region" aria-label="Today Stock Details"><table><thead><tr><th scope="col">Transaction</th><th scope="col">In Stock</th><th scope="col">Out Stock</th><th scope="col">Running</th></tr></thead><tbody><tr><td>Opening Stock</td><td></td><td></td><td>20,800.00</td></tr><tr><td>Purchase</td><td>0.00</td><td></td><td></td></tr><tr><td>Sales</td><td></td><td>240.00</td><td></td></tr><tr><td>Sales Return</td><td>0.00</td><td></td><td></td></tr><tr><td>Purchase Return</td><td></td><td>0.00</td><td></td></tr><tr><td>Add Stock</td><td>0.00</td><td></td><td></td></tr><tr><td>Reduce Stock</td><td></td><td>0.00</td><td></td></tr><tr><td>Closing Stock</td><td></td><td></td><td>20,560.00</td></tr></tbody></table></div><p class="note">Stock out and closing stock are valued at purchase price.</p></section></div></div> <section id="suppliers-view" class="content customers" hidden aria-labelledby="suppliers-title"> <header class="customer-heading"> <div><button class="customer-back" type="button" id="supplier-back">‹ Dashboard</button><h1 id="suppliers-title" tabindex="-1">Suppliers</h1> <dl class="customer-summary"><div><dt>Total Suppliers</dt><dd id="supplier-total"></dd></div><div><dt>Payable</dt><dd id="supplier-payable"></dd></div></dl> </div> <div class="customer-tools"><div class="customer-actions"><button type="button" id="adjust-supplier">Balance Adjustment</button><button type="button" id="new-supplier">+ New Supplier</button></div><div class="customer-toolbar"><select id="supplier-size" aria-label="Suppliers per page"><option>20</option><option selected>25</option><option>30</option><option>50</option><option>100</option><option>500</option><option>1000</option><option>All</option></select><label><input id="supplier-search" type="search" placeholder="Name, phone or email" aria-label="Search suppliers"></label><button type="button" id="supplier-ask">Ask AI</button></div></div> </header> <table class="customer-table"><thead><tr><th>SL</th><th>Business Name</th><th>Supplier Name</th><th>Mobile / Phone</th><th>Email</th><th>Picture</th><th>Due</th><th>Action</th></tr></thead><tbody id="supplier-list"></tbody></table> <footer class="customer-pagination"><span id="supplier-count" role="status"></span><div><button type="button" id="supplier-prev">Previous</button> <button type="button" id="supplier-next">Next</button></div></footer> <dialog id="supplier-dialog" aria-labelledby="supplier-dialog-title"> <form id="supplier-form"><div class="customer-dialog-heading"><h2 id="supplier-dialog-title"></h2><button type="button" id="supplier-close" aria-label="Close">×</button></div> <div id="supplier-fields"></div><button type="submit" id="supplier-submit">Save</button></form> </dialog> </section> <section id="customers-view" class="content customers" hidden aria-labelledby="customers-title"> <header class="customer-heading"> <div><button class="customer-back" type="button" id="customer-back">‹ Dashboard</button><h1 id="customers-title" tabindex="-1">Customers</h1><dl class="customer-summary"> <div><dt>Total Customers</dt><dd id="customer-total"></dd></div> <div><dt>Receivable</dt><dd id="customer-due"></dd></div> </dl></div> <div class="customer-tools"><div class="customer-actions"><button type="button" id="adjust-customer">Balance Adjustment</button><button type="button" id="new-customer">+ New Customer</button></div><div class="customer-toolbar"> <select id="customer-page-size" aria-label="Customers per page"><option>20</option><option>25</option><option>30</option><option>50</option><option>100</option><option>500</option><option>1000</option><option>All</option></select><label><input aria-label="Search customers" type="search" id="customer-search" placeholder="Name, phone or email"></label> <button type="button" id="customer-ask">Ask AI</button></div></div> </header> <table class="customer-table"> <thead><tr><th scope="col">SL</th><th scope="col" id="customer-name-column"><button type="button" data-customer-sort="name">Customer / Business</button></th><th scope="col">Proprietor Name</th><th scope="col">Mobile / Phone</th><th scope="col">Email</th><th scope="col">Picture</th><th scope="col" id="customer-due-column"><button type="button" data-customer-sort="due">Due</button></th><th scope="col">Action</th></tr></thead> <tbody id="customer-rows"></tbody> </table> <p id="customer-empty" hidden>No customers match your search.</p> <footer class="customer-pagination"><span id="customer-page" role="status"></span><div><button type="button" id="customer-prev">Previous</button> <button type="button" id="customer-next">Next</button></div></footer> <div id="customer-menu" popover aria-label="Customer actions"></div> <dialog id="customer-dialog" aria-labelledby="customer-dialog-title"><form id="customer-form"><div class="customer-dialog-heading"><h2 id="customer-dialog-title"></h2><button type="button" id="customer-ai-fill" hidden>AI Fill</button><button type="button" id="customer-close" aria-label="Close">×</button></div><div id="customer-dialog-body"></div><div class="customer-form-actions"><button type="submit" id="customer-save-new" hidden>Save & New</button><button type="submit" id="customer-save">Save</button></div><p id="customer-created" role="status" hidden></p></form></dialog> </section> <section class="content customers" id="customer-ledger" hidden aria-labelledby="customer-ledger-title"> <header class="ledger-header"><button type="button" id="ledger-back" class="customer-back">← Back to Customer List</button><h2 id="customer-ledger-title" tabindex="-1">Customer Summary</h2><input class="ledger-search" id="ledger-search" type="search" aria-label="Search transactions" placeholder="Bill no. or type"></header> <div class="ledger-body"> <div class="ledger-profile"><dl id="ledger-profile"></dl><div class="ledger-balance"><span>Receivable</span><strong id="ledger-balance"></strong></div></div> <div class="ledger-scroll"><table><thead><tr><th scope="col">Date</th><th scope="col">Bill Type</th><th scope="col">Bill No.</th><th scope="col">Bill Amount</th><th scope="col">Receipt / Due</th><th scope="col">Debit</th><th scope="col">Credit</th><th scope="col">Action</th></tr></thead><tbody id="ledger-rows"></tbody></table></div> <p id="ledger-count" role="status"></p> <div id="ledger-menu" popover aria-label="Transaction actions"> <button type="button" id="ledger-download"><i class="fa-solid fa-download" aria-hidden="true"></i> Download</button> <button type="button" id="ledger-view"><i class="fa-solid fa-eye" aria-hidden="true"></i> View</button> </div> <dialog id="ledger-transaction" aria-labelledby="ledger-transaction-title"> <div class="customer-dialog-heading"><h2 id="ledger-transaction-title">Transaction Details</h2><form method="dialog"><button aria-label="Close transaction details">×</button></form></div> <dl id="ledger-transaction-data"></dl> </dialog> </div> </section> <section id="sales-view" class="content customers" hidden aria-labelledby="sales-title"> <header class="customer-heading"> <div><button class="customer-back" id="sales-back" type="button">← Dashboard</button><h1 id="sales-title" tabindex="-1">Sales Information</h1> <dl class="customer-summary"><div><dt>Sales</dt><dd id="sales-total"></dd></div><div><dt>Received</dt><dd id="sales-received"></dd></div><div><dt>Due</dt><dd id="sales-due"></dd></div></dl></div> <div class="sales-heading-tools"><form id="sales-dates" class="sales-controls"><label class="sales-date-field"><span>From</span><input name="from" type="date"></label><label class="sales-date-field"><span>To</span><input name="to" type="date"></label><button type="submit">Apply</button><button type="button" id="sales-create">+ Create Sale</button></form><div class="sales-toolbar"><select id="sales-page-size" aria-label="Bills per page"><option value="20">20</option><option value="25">25</option><option value="30">30</option><option value="50">50</option><option value="100">100</option><option value="500">500</option><option value="1000">1000</option><option value="All">All</option></select><input id="sales-search" type="search" aria-label="Search sales bills" placeholder="Bill number or account"><button id="sales-ask" type="button">Ask AI</button></div></div></header> <div class="sales-table-wrap"><table class="sales-table"><thead><tr><th scope="col">Date</th><th scope="col">Bill Number</th><th scope="col">Accounts Name</th><th scope="col">Bill Amount</th><th scope="col">Receipt</th><th scope="col">Due</th><th scope="col">Payment Status</th><th scope="col">Action</th></tr></thead><tbody id="sales-rows"></tbody></table></div> <footer class="customer-pagination"><span id="sales-count" role="status"></span><div><button id="sales-prev" type="button">Previous</button> <button id="sales-next" type="button">Next</button></div></footer> <dialog id="sales-assistant" aria-labelledby="sales-assistant-title"> <div class="customer-dialog-heading"><h2 id="sales-assistant-title">Ask AI · Sales Bills</h2><form method="dialog"><button aria-label="Close">×</button></form></div> <form id="sales-ask-form"><label>Your question<textarea id="sales-question" rows="2" required placeholder="গত ৭ দিনের বকেয়া বিল"></textarea></label> <button id="sales-ask-example" type="button" lang="bn">গত ৭ দিনের বকেয়া বিল</button><div class="sales-ask-actions"><select id="sales-voice-language" aria-label="Voice language"><option value="bn-BD">বাংলা</option><option value="en-US">English</option></select><button type="button" id="sales-voice"><i class="fa-solid fa-microphone" aria-hidden="true"></i> Speak</button><button type="submit">Find bills</button></div> <div id="bill-ai-preview" hidden></div><button id="bill-ai-confirm" type="button" hidden>Add to bill</button><p id="sales-ask-status" role="status"></p></form></dialog> <p id="sales-ai-filter" hidden><span></span> <button id="sales-clear-ai" type="button">Clear AI filter</button></p> <div id="sale-menu" popover aria-label="Sale actions"><button type="button" data-sale-action="invoice"><i class="fa-solid fa-download" aria-hidden="true"></i>Invoice</button><button type="button" data-sale-action="challan"><i class="fa-solid fa-download" aria-hidden="true"></i>Delivery Challan</button><button type="button" data-sale-action="view"><i class="fa-solid fa-eye" aria-hidden="true"></i>View</button><button type="button" data-sale-action="edit"><i class="fa-solid fa-pen-to-square" aria-hidden="true"></i>Edit</button><button type="button" data-sale-action="delete"><i class="fa-solid fa-trash" aria-hidden="true"></i>Delete</button></div><dialog id="sales-dialog" aria-labelledby="sales-dialog-title"><div class="customer-dialog-heading"><h2 id="sales-dialog-title"></h2><button type="button" id="sales-close" aria-label="Close">×</button></div><dl id="sales-details"></dl> </dialog> </section> <section id="sales-editor-page" class="content customers bill-editor" aria-labelledby="sales-editor-title" hidden> <header class="sales-editor-heading"><button type="button" class="customer-back" id="sales-editor-back">← Back to Sales List</button><h1 id="sales-editor-title" tabindex="-1">Sales Bill</h1><button type="button" id="sales-settings-open" aria-label="Sales Form Settings" title="Sales Form Settings"><i class="fa-solid fa-gear" aria-hidden="true"></i></button></header> <dialog id="sales-settings" aria-labelledby="sales-settings-title"> <form id="sales-settings-form"> <header><h2 id="sales-settings-title">Sales Form</h2><button type="button" id="sales-settings-close" aria-label="Close">×</button></header> <div class="sales-settings-options"><label><input type="checkbox" id="sales-settings-all">All</label><label><input type="checkbox" name="option" value="0">Default Cash</label><label><input type="checkbox" name="option" value="1">Customer Address & Due Bill</label><label><input type="checkbox" name="option" value="2">Due Date</label><label><input type="checkbox" name="option" value="3">Bill Person</label><label><input type="checkbox" name="option" value="29">Item Card View (Only Mobile)</label><label><input type="checkbox" name="option" value="4">Category/Sub Category</label><label><input type="checkbox" name="option" value="5">Bill Wise Sales</label><label><input type="checkbox" name="option" value="6">Stock Qty & Unit Show</label><label><input type="checkbox" name="option" value="7">Stock View</label><label><input type="checkbox" name="option" value="8">Item Code/HNS</label><label><input type="checkbox" name="option" value="9">MRP</label><label><input type="checkbox" name="option" value="10">Batch No.</label><label><input type="checkbox" name="option" value="11">Model No.</label><label><input type="checkbox" name="option" value="12">Size</label><label><input type="checkbox" name="option" value="13">Color</label><label><input type="checkbox" name="option" value="14">MFG. Date</label><label><input type="checkbox" name="option" value="15">EXP. Date</label><label><input type="checkbox" name="option" value="16">Default QTY Show</label><label><input type="checkbox" name="option" value="28">Row Item Field</label><label><input type="checkbox" name="option" value="17">Item wise Discount</label><label><input type="checkbox" name="option" value="18">Item wise VAT/Tax</label><label><input type="checkbox" name="option" value="per-unit">Per Unit</label><label><input type="checkbox" name="option" value="19">Item Description</label><label><input type="checkbox" name="option" value="20">Bill Wise Discount</label><label><input type="checkbox" name="option" value="21">Bill Wise VAT/Tax</label><label><input type="checkbox" name="option" value="22">Additional Cost</label><label><input type="checkbox" name="option" value="23">Round Off</label><label><input type="checkbox" name="option" value="24">Show Profit/Loss Icon</label><label><input type="checkbox" name="option" value="25">Send SMS</label><label><input type="checkbox" name="option" value="26">WhatsApp SMS</label><label><input type="checkbox" name="option" value="27">Mail SMS</label></div><footer><button type="submit">Save</button></footer></form></dialog> <form id="sales-entry"> <div class="bill-meta"> <div class="bill-lookup"> <label class="bill-field"><span>Bill Number</span><input name="number" required></label><label class="bill-field bill-account"><span>Cash / Customer</span><input name="account" value="Cash" autocomplete="off" role="combobox" aria-expanded="false" aria-autocomplete="list" aria-controls="bill-customers" required><span id="bill-customers" role="listbox" hidden></span></label> <label class="bill-field"><span>Category</span><select name="category"><option value="">All categories</option><option>General</option></select></label> <label class="bill-field"><span>Sub Category</span><select name="subcategory"><option value="">All subcategories</option><option>General Items</option></select></label> <div class="bill-item-field"><label class="bill-field"><span>Items</span><input id="bill-item" autocomplete="off" role="combobox" aria-expanded="false" aria-controls="bill-item-list" aria-keyshortcuts="Alt+I"><span id="bill-item-list" role="listbox" hidden></span></label><div class="bill-item-info"><button type="button" id="bill-item-view" disabled>View</button><button type="button" id="bill-ai-add" aria-keyshortcuts="Alt+A" title="Alt+A">AI Add <kbd>Alt+A</kbd></button><output id="bill-item-stock" aria-label="Available stock">—</output></div></div> </div> <dl class="bill-party" id="bill-party"></dl> <div class="bill-dates"><label class="bill-field bill-warehouse"><span>Warehouse</span><select name="warehouse"><option value="Main Warehouse">Main Warehouse</option><option value="Branch Warehouse">Branch Warehouse</option><option value="Retail Warehouse">Retail Warehouse</option></select></label> <label class="bill-field"><span><span class="bill-date-desktop">Bill Date</span><span class="bill-date-mobile">Date:</span></span><input name="date" type="date" required></label> <label class="bill-field"><span>Due Date</span><input name="dueDate" type="date"></label> <label class="bill-field"><span>Bill Person</span><input name="person"></label> </div> </div> <div class="bill-lines"><table><colgroup id="bill-column-widths"></colgroup><thead><tr><th scope="col" rowspan="2">SL</th><th scope="col" rowspan="2">Item Name</th><th scope="col" rowspan="2">Code</th><th scope="col" rowspan="2">MRP</th><th scope="col" rowspan="2">Batch No.</th><th scope="col" rowspan="2">Model No.</th><th scope="col" rowspan="2">Size</th><th scope="col" rowspan="2">Color</th><th scope="col" rowspan="2">MFG. Date</th><th scope="col" rowspan="2">EXP. Date</th><th scope="col" rowspan="2">Qty</th><th scope="col" rowspan="2">Unit</th><th scope="col" rowspan="2">Price</th><th scope="colgroup" colspan="2" id="bill-discount-group">Discount</th><th scope="colgroup" colspan="2" id="bill-tax-group">VAT/Tax</th><th id="bill-per-unit-head" scope="col" rowspan="2" hidden>Per Unit</th><th scope="col" rowspan="2">Total</th><th id="bill-description-head" scope="col" rowspan="2" title="Description" aria-label="Description">✎</th><th scope="col" rowspan="2" aria-label="Item row actions"><button type="button" id="bill-add-row" data-sales-option="28" aria-label="Add item row" title="Add item row" hidden>+</button><span aria-hidden="true">×</span></th></tr><tr><th scope="col">%</th><th scope="col">Amount</th><th scope="col">%</th><th scope="col">Amount</th></tr></thead><tbody id="bill-rows"></tbody><tfoot><tr><th colspan="10" scope="row">Item totals</th><td id="bill-item-qty"></td><td colspan="2"></td><td></td><td id="bill-item-discount"></td><td></td><td id="bill-item-tax"></td><td id="bill-per-unit-foot" hidden></td><td id="bill-item-total"></td><td id="bill-description-foot"></td><td></td></tr></tfoot></table></div> <div class="bill-bottom"><details id="bill-notes"><summary>Notes</summary><textarea name="notes" rows="2" aria-label="Notes"></textarea></details><div class="bill-totals"> <label class="bill-total-pair">Discount <span class="bill-total-suffix"><input aria-label="Discount percent" name="discount" type="number" min="0" max="100" step=".01" value="0"><span>%</span></span><span class="bill-total-suffix"><input id="bill-discount-value" name="discountAmount" aria-label="Discount amount in BDT" type="number" min="0" step=".01" value="0"><span>BDT</span></span></label> <label class="bill-total-pair">Tax (%) <select name="tax" aria-label="Bill tax rate"><option value="0">None</option><option value="5">5%</option><option value="7.5">7.5%</option><option value="10">10%</option><option value="15">15%</option></select><output id="bill-tax-value" aria-label="Tax amount">0.00</output></label> <label><button type="button" id="bill-cost-open" aria-haspopup="dialog">Additional Cost</button><input aria-label="Additional Cost total" name="cost" type="number" min="0" step=".01" value="0" readonly></label> <label class="bill-total-pair"><span><input type="checkbox" id="bill-auto-round" aria-label="Automatically round bill total"> Round off</span><input aria-label="Round off amount" name="round" type="number" step=".01" value="0"><output id="bill-round-total" aria-label="Total after round off"></output></label> <label id="bill-total-fallback">Total <output id="bill-total"></output></label> <label><span><input type="checkbox" id="bill-auto-receipt" aria-label="Receive full bill amount"> Received</span><span class="bill-total-suffix"><input name="receipt" type="number" min="0" step=".01" value="0" required><span>BDT</span></span></label> <label class="bill-balance-line">Balance <output id="bill-balance"></output></label> <input name="amount" type="hidden"> </div></div> <div class="bill-footer"><div id="sales-optional-controls"> <output data-sales-option="24" id="bill-profit-preview" title="Demo estimate using 75% of selling price as item cost"></output> <label data-sales-option="25"><input type="checkbox" name="sendSms">SMS preview</label> <label data-sales-option="26"><input type="checkbox" name="sendWhatsapp">WhatsApp preview</label> <label data-sales-option="27"><input type="checkbox" name="sendMail">Email preview</label> </div><span id="bill-feedback" role="status"></span><button type="button" id="bill-check" aria-keyshortcuts="Alt+C" title="Alt+C">Check Bill <kbd>Alt+C</kbd></button><details id="bill-save-menu"><summary aria-keyshortcuts="Control+Shift+S Meta+Shift+S">Save & Continue ▴</summary><div> <button type="submit" value="print" class="bill-desktop-save"><i class="fa-solid fa-print" aria-hidden="true"></i>Save & Print</button> <button type="submit" value="view" class="bill-desktop-save"><i class="fa-solid fa-eye" aria-hidden="true"></i>Save & View</button> <button type="submit" value="whatsapp" class="bill-mobile-save"><i class="fa-brands fa-whatsapp" aria-hidden="true"></i>Save & WhatsApp</button> <button type="submit" value="sms" class="bill-mobile-save"><i class="fa-solid fa-comment-sms" aria-hidden="true"></i>Save & SMS</button> <button type="submit" value="continue"><i class="fa-solid fa-file-invoice" aria-hidden="true"></i>Save & New</button> </div></details><button type="submit" value="save" aria-keyshortcuts="Control+S Meta+S">Save <kbd>Ctrl+S</kbd></button></div> </form><dialog id="bill-cost-dialog" aria-labelledby="bill-cost-title"> <form id="bill-cost-form"> <div class="customer-dialog-heading"><h2 id="bill-cost-title">Additional Cost</h2><button type="button" id="bill-cost-close" aria-label="Close">×</button></div> <div class="bill-cost-table"><table><thead><tr><th scope="col">Account Name</th><th scope="col">Narration</th><th scope="col">Amount</th><th scope="col"><button type="button" id="bill-cost-add" aria-label="Add cost row">+</button></th></tr></thead><tbody id="bill-cost-rows"></tbody><tfoot><tr><th scope="row" colspan="2">Total</th><td><output id="bill-cost-total">0.00</output></td><td></td></tr></tfoot></table></div> <footer><ul><li>Additional cost for this sales bill</li><li>Account type: Indirect Income</li></ul><button type="submit">OK</button></footer> </form></dialog><dialog id="bill-check-dialog" aria-labelledby="bill-check-title"> <div class="customer-dialog-heading"><h2 id="bill-check-title">Check Bill</h2><form method="dialog"><button aria-label="Close bill check">×</button></form></div> <ul id="bill-check-results"></ul><p id="bill-check-credit"></p> </dialog><dialog id="mobile-line-dialog" aria-labelledby="mobile-line-title"> <form id="mobile-line-form"> <div class="customer-dialog-heading"><h2 id="mobile-line-title"></h2><button type="button" id="mobile-line-close" aria-label="Close">×</button></div> <div class="mobile-line-step"><div><button type="button" data-qty-step="-1">−</button><input name="qty" aria-label="Quantity" type="number" min=".01" step=".01" required><button type="button" data-qty-step="1">+</button></div></div> <div class="mobile-line-fields"> <label><span>Unit</span><select name="unit"></select></label><label><span>Price</span><input name="price" type="number" min="0" step="any" required></label> <label data-mobile-discount><span>Discount %</span><input name="discount" type="number" min="0" max="100" step=".01"></label><label data-mobile-discount><span>Discount Amount</span><input id="mobile-line-discount" name="discountAmount" type="number" min="0" step=".01" aria-label="Item discount amount"></label> <label data-mobile-tax><span>VAT / Tax %</span><select name="tax"><option value="0">None</option><option value="5">5%</option><option value="7.5">7.5%</option><option value="10">10%</option><option value="15">15%</option></select></label><label data-mobile-tax><span>VAT / Tax Amount</span><output id="mobile-line-tax"></output></label> </div> <div class="mobile-line-actions"><div class="mobile-line-result" aria-live="polite"><span id="mobile-line-per-unit-group" hidden><strong>Per Unit:</strong> <output id="mobile-line-per-unit"></output></span><span><strong>Total:</strong> <output id="mobile-line-total"></output></span></div><button type="submit">OK</button></div> </form></dialog><dialog id="bill-wise-stock" aria-labelledby="bill-wise-title" style="width:min(1050px,94vw);max-width:94vw"> <form method="dialog"> <div class="customer-dialog-heading"><h2 id="bill-wise-title"></h2><button value="cancel" formnovalidate aria-label="Close">×</button></div> <p id="bill-wise-warehouse"></p> <div class="bill-wise-table"><table><thead><tr> <th>Bill date</th><th>Bill Type</th><th>Bill No</th><th>Item Total</th><th>Trade Price</th><th>Discount</th><th>VAT/Tax</th><th>Unit Price</th><th>Bill Qty</th><th>Out Qty</th><th>Current Qty</th><th>Sales Qty</th><th>Unit</th> </tr></thead><tbody><tr> <td>—</td><td>Warehouse stock</td><td>—</td><td>—</td><td>—</td><td>—</td><td>—</td><td id="bill-wise-price"></td><td>—</td><td>—</td><td id="bill-wise-current"></td><td><input id="bill-wise-qty" aria-label="Sales Qty" type="number" min="0" step="any" required style="width:85px"></td><td><select id="bill-wise-unit" aria-label="Unit"></select></td> </tr></tbody></table></div> <div class="bill-wise-footer"><output id="bill-wise-total"></output><button value="apply">OK</button></div> </form></dialog><dialog id="bill-item-details" aria-labelledby="bill-item-details-title"><div class="customer-dialog-heading"><h2 id="bill-item-details-title">Item Details</h2><form method="dialog"><button aria-label="Close item details">×</button></form></div><p id="bill-item-details-text"></p></dialog></section> <section class="mobile-panel" id="mobile-transaction" aria-label="Transaction" hidden><h2>Transaction</h2><button type="button" class="mobile-panel-close" aria-label="Close Transaction menu">×</button><ul><li><details name="mobile-navigation"><summary>Parties</summary><ul class="sub-menu"><li><button type="button" class="customer-link" data-open-customers>Customers</button></li><li><button type="button" class="customer-link" data-open-suppliers>Suppliers</button></li></ul></details></li><li><details name="mobile-navigation"><summary>Item</summary><ul class="sub-menu"><li>Product</li></ul></details></li><li><details name="mobile-navigation"><summary>Sales</summary><ul class="sub-menu"><li><button type="button" class="customer-link" data-open-sales>Sale Invoice</button></li><li>Sales Return</li></ul></details></li><li><details name="mobile-navigation"><summary>Purchases</summary><ul class="sub-menu"><li>Purchases Bill</li><li>Purchases Return</li><li>Price History</li></ul></details></li></ul></section><section class="mobile-panel" id="mobile-accounts" aria-label="Accounts" hidden><h2>Accounts</h2><button type="button" class="mobile-panel-close" aria-label="Close Accounts menu">×</button><ul><li>Receipt In</li><li>Payment Out</li><li>Income</li><li>Expense</li><li>Contra</li><li><details name="mobile-navigation"><summary>Accounts</summary><ul class="sub-menu"><li>Cash In Hand</li><li>Bank</li></ul></details></li><li>Accounts View</li></ul></section><section class="mobile-panel" id="mobile-reports" aria-label="Reports" hidden><h2>Reports</h2><button type="button" class="mobile-panel-close" aria-label="Close Reports menu">×</button><ul><li><details name="mobile-navigation"><summary>Transaction</summary><ul class="sub-menu"><li>Sales Transaction</li><li>Purchase Transaction</li><li>Bill Details</li><li>All Parties</li><li>Customer</li><li>Supplier</li><li>Bill Wise Profit</li><li>Party Wise Profit</li></ul></details></li><li><details name="mobile-navigation"><summary>Accounts</summary><ul class="sub-menu"><li>Cash Flow</li><li>Day Book</li><li>Ledger Book</li><li>Balance Sheet</li><li>Trial Balance</li><li>Profit & Loss</li></ul></details></li><li><details name="mobile-navigation"><summary>Inventory</summary><ul class="sub-menu"><li>Current Stock</li><li>By Category</li><li>Stock Summary</li><li>Stock Details</li><li>Item Details</li><li>Daily Summary</li><li>Serial Tracking</li><li>Batch Tracking</li><li>Party Wise Item</li><li>Item Wise P/L</li></ul></details></li><li>User Management</li><li>Tools</li></ul></section><section class="mobile-panel" id="mobile-settings" aria-label="Settings" hidden><h2>Settings</h2><button type="button" class="mobile-panel-close" aria-label="Close Settings menu">×</button><p>Settings are available in the live app.</p></section><section class="mobile-panel" id="mobile-profile" aria-label="Profile" hidden><h2>Profile</h2><button type="button" class="mobile-panel-close" aria-label="Close Profile menu">×</button><p>Sumon Enterprise · admin</p></section><nav class="mobile-nav" aria-label="Mobile navigation"><button type="button" data-mobile-nav="dashboard"><i class="fa-solid fa-table-cells-large" aria-hidden="true"></i><span>Dashboard</span></button><button type="button" data-mobile-nav="transaction" aria-controls="mobile-transaction" aria-expanded="false"><i class="fa-solid fa-cart-shopping" aria-hidden="true"></i><span>Transaction</span></button><button type="button" data-mobile-nav="accounts" aria-controls="mobile-accounts" aria-expanded="false"><i class="fa-solid fa-book" aria-hidden="true"></i><span>Accounts</span></button><button type="button" data-mobile-nav="reports" aria-controls="mobile-reports" aria-expanded="false"><i class="fa-solid fa-chart-column" aria-hidden="true"></i><span>Reports</span></button><button type="button" data-mobile-nav="settings" aria-controls="mobile-settings" aria-expanded="false"><i class="fa-solid fa-gear" aria-hidden="true"></i><span>Settings</span></button><button type="button" data-mobile-nav="profile" aria-controls="mobile-profile" aria-expanded="false"><i class="fa-solid fa-circle-user" aria-hidden="true"></i><span>Profile</span></button></nav></main></div> <script> const layout = document.getElementById('layout'); const menu = document.getElementById('menu'); const narrow = matchMedia('(max-width:720px)'); function syncMenu() { const open = narrow.matches ? layout.classList.contains('mobile-open') : !layout.classList.contains('collapsed'); menu.setAttribute('aria-expanded', String(open)); } menu.addEventListener('click', () => { layout.classList.toggle(narrow.matches ? 'mobile-open' : 'collapsed'); syncMenu(); }); narrow.addEventListener('change', () => { layout.classList.remove('mobile-open', 'collapsed'); syncMenu(); }); syncMenu(); const compactSalesDesktop = matchMedia('(min-width:721px) and (max-width:1440px)'); function collapseSalesSidebar() { if (!compactSalesDesktop.matches || document.getElementById('sales-editor-page').hidden) return; layout.classList.add('collapsed'); syncMenu(); } compactSalesDesktop.addEventListener('change', collapseSalesSidebar); document.addEventListener('click', event => { if (!layout.classList.contains('collapsed')) return; for (const group of layout.querySelectorAll('#sidebar .nav-group[open]')) { if (!group.querySelector('summary').contains(event.target)) group.open = false; } }, true); const mobileNav = document.querySelector('.mobile-nav'); const mobileButtons = [...mobileNav.querySelectorAll('button')]; function showMobilePanel(key) { for (const button of mobileButtons) { const panel = document.getElementById(button.getAttribute('aria-controls')); if (!panel) { if (key === 'dashboard') button.setAttribute('aria-current', 'page'); else button.removeAttribute('aria-current'); continue; } panel.hidden = button.dataset.mobileNav !== key; button.setAttribute('aria-expanded', String(!panel.hidden)); } } showMobilePanel('dashboard'); mobileNav.addEventListener('click', event => { const button = event.target.closest('button'); if (!button) return; const key = button.dataset.mobileNav; showMobilePanel(button.getAttribute('aria-expanded') === 'true' ? 'dashboard' : key); if (key === 'dashboard') window.scrollTo(0, 0); }); document.addEventListener('keydown', event => { if (event.key === 'Escape') showMobilePanel('dashboard'); }); document.querySelectorAll('.mobile-panel-close').forEach(close => { close.addEventListener('click', () => { const panel = close.closest('.mobile-panel'); const trigger = mobileButtons.find(button => button.getAttribute('aria-controls') === panel.id); showMobilePanel('dashboard'); trigger?.focus(); }); }); const demoOwners = ["আরিফ হোসেন", "রাশেদ আহমেদ", "মিরাজ ইসলাম", "কামাল উদ্দিন", "জাহিদ হাসান", "নাসরিন আক্তার", "আলি হোসেন", "ফাতেমা বেগম", "রফিকুল ইসলাম", "মিজানুর রহমান", "মেহেদী হাসান", "রিফাত আহমেদ", "শফিক ভূঁইয়া", "মাসুদ মজুমদার", "সাইফুল ইসলাম", "মাহমুদ হাসান", "রুহুল আমিন", "রাজিয়া সুলতানা", "শারমিন আক্তার", "নাঈম হোসেন", "আবদুল মোল্লা"]; const customers = [ ['মা ক্রোকারিজ-চাঁদপুর রেলগেট-১',646166.20],['রাজকীয় ফার্নিচার-মুক্তিখোলা',227755.75], ['মিরাজ ক্রোকারিজ - বাঙ্গড্ডা',144054.80],['মামা ভাগিনা - হরিশ্চর',60381.50], ['ফাইভ স্টার ক্রোকারিজ - লাকসাম',992294.50],['গুলশান ক্রোকারিজ - লাকসাম',6864], ['আলি ক্রোকারিজ - মনোহরগঞ্জ',22905.60],['ফাতেমা ক্রোকারিজ - লাকসাম',65097.90], ['এ কে ইলেকট্রিক - লাকসাম',140306.25],['মিজান ক্রোকারিজ - লাকসাম',231170.65], ['মেগা শপ - নাঙ্গলকোট',212155.05],['রিফাত - কুমিল্লা',91204.30], ['ভুঁইয়া ফার্নিচার - মনোহরগঞ্জ',52515.90],['মজুমদার ক্রোকারিজ - লাকসাম',486940.40], ['রাজধানী ক্রোকারিজ - মুদাফফরগঞ্জ',622162],['মেহেদী ক্রোকারিজ - মুদাফফরগঞ্জ',176953.60], ['রয়েল ক্রোকারিজ - নাঙ্গলকোট',126734.25],['রাজিয়া ক্রোকারিজ - নাঙ্গলকোট',106539.15], ['ঘরকন্যা ক্রোকারিজ - লাকসাম',129947.90],['মদিনা ইলেকট্রিক - লক্ষ্মণপুর',118197.90], ['মোল্লা ক্রোকারিজ - নাথেরপেটুয়া',91551.30] ].map(([name,due],index)=>({id:index+1,name,due,owner:demoOwners[index],phone:'01X-XXXX-'+String(index+1).padStart(4,'0'),email:'customer'+(index+1)+'@example.com',demoPhoto:true})); const el = id => document.getElementById(id); const formatDue = amount => (amount / 100).toLocaleString('en',{minimumFractionDigits:2,maximumFractionDigits:2}); customers.forEach(customer => {customer.due = Math.round(customer.due * 100);}); let customerPage = 1; let customerDueFilter=null; let customerSort = ''; let sortDirection = 1; function renderCustomers(){ const term = el('customer-search').value.trim().toLowerCase(); const rows = customers.filter(c=>customerDueFilter===null?[c.name,c.owner,c.phone,c.email].some(value=>value.toLowerCase().includes(term)):c.due>customerDueFilter); if(customerSort) rows.sort((a,b)=>sortDirection*(customerSort==='due' ? a.due-b.due : a.name.localeCompare(b.name))); const selection=matchMedia('(max-width:720px)').matches?'20':el('customer-page-size').value; const size=selection==='All'?Math.max(1,rows.length):Number(selection); const pages = Math.max(1,Math.ceil(rows.length/size)); customerPage = Math.min(customerPage,pages); const offset = (customerPage-1)*size; el('customer-total').textContent = customers.length; el('customer-due').textContent = formatDue(customers.reduce((sum,c)=>sum+Math.max(0,c.due),0)); el('customer-empty').hidden = rows.length!==0; el('customer-page').textContent = rows.length ? (offset+1)+'–'+Math.min(offset+size,rows.length)+' of '+rows.length : '0 customers'; el('customer-prev').disabled = customerPage===1; el('customer-next').disabled = customerPage===pages; el('customer-rows').replaceChildren(...rows.slice(offset,offset+size).map((c,i)=>{ const tr=document.createElement('tr'); if(c.inactive)tr.classList.add('customer-inactive'); [offset+i+1,c.name,c.owner||'—',c.phone||'—',c.email||'—',c.name.charAt(0),formatDue(c.due)].forEach((value,column)=>{ const cell=tr.insertCell(); if(column===5 && (c.avatar||c.logo)){const image=document.createElement('img');image.className='customer-avatar';image.alt='';image.src=c.avatar||c.logo;cell.append(image);} else if(column===5){const avatar=document.createElement('span');avatar.className='customer-avatar';if(c.demoPhoto){avatar.classList.add('demo-portrait');avatar.dataset.tone=String(c.id%3);avatar.setAttribute('role','img');avatar.setAttribute('aria-label','Sample profile avatar');}else{avatar.textContent=value;}cell.append(avatar);} else cell.textContent=column===1&&c.inactive?value+' · Inactive':value; }); const button=document.createElement('button'); button.type='button';button.textContent='⋮';button.className='customer-more';button.setAttribute('aria-label','Actions for '+c.name);button.setAttribute('popovertarget','customer-menu'); button.addEventListener('click',()=>prepareCustomerMenu(button,c)); tr.insertCell().append(button); return tr; })); } function showCustomers(open){ el('suppliers-view').hidden=true; el('sales-editor-page').hidden=true; el('sales-view').hidden=true; el('customer-ledger').hidden=true; el('dashboard-content').hidden=open; el('customers-view').hidden=!open; showMobilePanel('dashboard'); window.scrollTo(0,0); if(open){renderCustomers();el('customers-title').focus();} } document.querySelectorAll('[data-open-customers]').forEach(button=>button.addEventListener('click',()=>showCustomers(true))); el('customer-back').addEventListener('click',()=>showCustomers(false)); document.querySelector('[data-mobile-nav="dashboard"]').addEventListener('click',()=>showCustomers(false)); document.querySelectorAll('.nav-row.active').forEach(row=>{ const button=document.createElement('button'); button.type='button';button.className=row.className;button.setAttribute('aria-current','page'); button.style.cssText='width:100%;border:0;text-align:left;cursor:pointer'; button.append(...row.childNodes);row.replaceWith(button); button.addEventListener('click',()=>showCustomers(false)); }); el('customer-search').addEventListener('input',()=>{customerDueFilter=null;customerPage=1;renderCustomers();}); const customerSize=el('customer-page-size'); const wideCustomers=matchMedia('(min-width:1440px)'); let customerSizeChosen=false; function refreshCustomerSize(){ if(!customerSizeChosen)customerSize.value=wideCustomers.matches?'25':'20'; if(!el('customers-view').hidden){customerPage=1;renderCustomers();} } refreshCustomerSize(); wideCustomers.addEventListener('change',refreshCustomerSize); matchMedia('(max-width:720px)').addEventListener('change',refreshCustomerSize); customerSize.addEventListener('change',()=>{customerSizeChosen=true;customerPage=1;renderCustomers();}); el('customer-prev').addEventListener('click',()=>{customerPage--;renderCustomers();}); el('customer-next').addEventListener('click',()=>{customerPage++;renderCustomers();}); document.querySelectorAll('[data-customer-sort]').forEach(button=>button.addEventListener('click',()=>{ const key=button.dataset.customerSort; sortDirection=customerSort===key ? -sortDirection : 1;customerSort=key;customerPage=1; document.querySelectorAll('[data-customer-sort]').forEach(other=>other.closest('th').removeAttribute('aria-sort')); button.closest('th').setAttribute('aria-sort',sortDirection===1?'ascending':'descending');renderCustomers(); })); const customerDialog=el('customer-dialog'); const customerMenu=el('customer-menu'); document.body.append(customerMenu); let selectedCustomer; let customerMenuTrigger; function prepareCustomerMenu(trigger,customer,isSupplier=false){ customerMenuTrigger=trigger; const bounds=trigger.getBoundingClientRect(); const height=190; customerMenu.style.left=Math.max(8,bounds.right-174)+'px'; customerMenu.style.top=(bounds.bottom+height+8 < window.innerHeight ? bounds.bottom+4 : Math.max(8,bounds.top-height-4))+'px'; const actions=[['sms','Reminder SMS','comment'],['status',customer.inactive?'Activate':'Inactive','ban'],['view','View','eye'],['edit','Edit','pen-to-square'],['delete','Delete','trash']]; customerMenu.replaceChildren(...actions.map(([mode,label,icon])=>{ const button=document.createElement('button'); button.type='button'; button.dataset.action=mode; const symbol=document.createElement('i'); symbol.className='fa-solid fa-'+icon; symbol.setAttribute('aria-hidden','true'); button.append(symbol,label); button.addEventListener('click',()=>{ customerMenu.hidePopover(); if(mode==='view') openCustomerLedger(customer,isSupplier); else if(isSupplier) openSupplierForm(mode,customer); else openCustomerDialog(mode,customer); }); return button; })); } customerDialog.addEventListener('close',()=>{if(customerMenuTrigger?.isConnected)customerMenuTrigger.focus();customerMenuTrigger=null;}); function renderCustomerCreate(body){ body.innerHTML=` <fieldset class="customer-type"><legend>Customer Type</legend><label><input type="radio" name="type" value="individual" checked> Individual</label><label><input type="radio" name="type" value="business"> Business</label></fieldset> <label class="create-wide"><span id="create-name-label">Name</span><input name="name" required maxlength="140"></label> <label class="create-wide" data-business hidden>Proprietor Name<input name="owner" maxlength="140"></label> <label class="create-check create-wide"><input type="checkbox" name="priceEnabled"> Price Level</label> <label class="create-wide" data-price hidden>Price Level<select name="priceLevel"><option value="">Select a price level</option><option>Retail</option><option>Wholesale</option></select></label> <label>Country<select name="country"><option data-code="+880">Bangladesh</option><option data-code="+91">India</option><option data-code="+971">United Arab Emirates</option><option data-code="">Other</option></select></label> <label>Phone<input name="phone" type="tel" placeholder="+880"></label> <label class="create-wide">Email<input name="email" type="email"></label> <label>Opening Balance<input name="openingBalance" type="number" step="0.01" min="-999999999" max="999999999"></label> <label>Opening Date<input name="openingDate" type="date" required></label> <label class="create-wide">Address<textarea name="address" rows="2"></textarea></label> <label class="create-check create-wide"><input type="checkbox" name="shippingEnabled"> Shipping Address</label> <label class="create-wide" data-shipping hidden><textarea aria-label="Shipping address" name="shippingAddress" rows="2"></textarea></label> <label class="create-upload">Avatar<input name="avatar" type="file" accept="image/png,image/jpeg,image/webp"><span class="create-file-name" aria-live="polite">No file selected</span><small>PNG, JPEG or WebP · under 100 KB</small></label> <label class="create-upload" data-business hidden>Logo<input name="logo" type="file" accept="image/png,image/jpeg,image/webp"><span class="create-file-name" aria-live="polite">No file selected</span><small>PNG, JPEG or WebP · under 100 KB</small></label>`; const fields=el('customer-form').elements; fields.openingDate.value=new Intl.DateTimeFormat('en-CA',{timeZone:'Asia/Dhaka',year:'numeric',month:'2-digit',day:'2-digit'}).format(new Date()); function syncField(selector,visible,required=false){ body.querySelectorAll(selector).forEach(label=>{ label.hidden=!visible; const input=label.querySelector('input,select,textarea'); input.disabled=!visible; input.required=visible&&required; }); } function syncCreateFields(){ const business=fields.type.value==='business'; el('create-name-label').textContent=business?'Business Name':'Name'; syncField('[data-business]',business); syncField('[data-price]',fields.priceEnabled.checked,true); syncField('[data-shipping]',fields.shippingEnabled.checked); fields.phone.placeholder=fields.country.selectedOptions[0].dataset.code; } body.onchange=syncCreateFields; body.querySelectorAll('input[type=file]').forEach(input=>{ if(matchMedia('(max-width:720px) and (pointer:coarse)').matches) input.setAttribute('capture','environment'); input.addEventListener('change',async()=>{ const file=input.files[0]; const filename=input.closest('label').querySelector('.create-file-name'); filename.textContent=file?.name||'No file selected'; filename.title=file?.name||''; input.setCustomValidity(''); if(!file)return; if(!['image/png','image/jpeg','image/webp'].includes(file.type)){ input.setCustomValidity('Choose a PNG, JPEG or WebP image.'); }else if(file.size>=100000 && input.hasAttribute('capture')){ input.setCustomValidity('Wait for the camera photo to finish processing.'); filename.textContent='Preparing photo…'; try{ const image=await createImageBitmap(file); let photo; try{ const canvas=document.createElement('canvas'); const context=canvas.getContext('2d'); for(const limit of [800,600,400,240]){ const scale=Math.min(1,limit/Math.max(image.width,image.height)); canvas.width=Math.max(1,Math.round(image.width*scale)); canvas.height=Math.max(1,Math.round(image.height*scale)); context.drawImage(image,0,0,canvas.width,canvas.height); photo=await new Promise(resolve=>canvas.toBlob(resolve,'image/jpeg',0.75)); if(photo&&photo.size<100000)break; } }finally{image.close();} if(!input.isConnected||input.files[0]!==file)return; if(!photo||photo.size>=100000)throw new Error('Photo exceeds limit'); const transfer=new DataTransfer(); transfer.items.add(new File([photo],file.name.replace(/\.[^.]+$/,'')+'.jpg',{type:'image/jpeg'})); input.files=transfer.files; filename.textContent=input.files[0].name; filename.title=input.files[0].name; input.setCustomValidity(''); }catch{ if(!input.isConnected||input.files[0]!==file)return; filename.textContent=file.name; input.setCustomValidity('This photo could not be reduced. Choose an image under 100 KB.'); } }else if(file.size>=100000){ input.setCustomValidity('Choose an image under 100 KB.'); } if(input.validationMessage)input.reportValidity(); }); }); syncCreateFields(); } let customerMode=''; function openCustomerDialog(mode,customer){ customerMode=mode;selectedCustomer=customer; customerDialog.classList.toggle('customer-create',mode==='new'); el('customer-ai-fill').hidden=mode!=='new'; el('customer-save-new').hidden=mode!=='new'; el('customer-created').hidden=true; const body=el('customer-dialog-body'); body.replaceChildren(); el('customer-save').hidden=mode==='view'||mode==='sms'; el('customer-dialog-title').textContent={view:'Customer Details',new:'Create Customer',adjust:'Balance Adjustment',edit:'Edit Customer',status:customer?.inactive?'Activate Customer':'Set Customer Inactive',delete:'Delete Customer',sms:'Reminder SMS'}[mode]; el('customer-save').textContent=mode==='delete'?'Delete':mode==='status'?'Confirm':'Save'; if(mode==='sms'){ body.textContent='Demo reminder for '+customer.name+' · '+customer.phone+' · Due '+formatDue(customer.due)+'. SMS sending is not connected.'; }else if(mode==='delete'||mode==='status'){ body.textContent=(mode==='delete'?'Delete ':customer.inactive?'Activate ':'Set inactive: ')+customer.name+'?'; }else if(mode==='view'){ [['Customer / Business',customer.name],['Proprietor',customer.owner],['Phone',customer.phone],['Email',customer.email],['Due',formatDue(customer.due)]].forEach(([label,value])=>{ const line=document.createElement('div');line.textContent=label+': '+(value||'—');body.append(line); }); }else if(mode==='new'){ renderCustomerCreate(body); }else if(mode==='edit'){ body.innerHTML='<label>Customer / Business<input name="name" required maxlength="140"></label><label>Proprietor Name<input name="owner" maxlength="140"></label><label>Mobile / Phone<input name="phone" type="tel"></label><label>Email<input name="email" type="email"></label>'; if(mode==='edit') for(const input of body.querySelectorAll('input')) input.value=customer[input.name]; }else{ body.innerHTML='<label>Customer<select name="id" required></select></label><label>Adjustment amount (+ or −)<input name="amount" type="number" step="0.01" min="-999999999" max="999999999" required></label>'; body.querySelector('select').append(...customers.map(c=>new Option(c.name,c.id))); } customerDialog.showModal(); } el('customer-close').addEventListener('click',()=>customerDialog.close()); el('new-customer').addEventListener('click',()=>openCustomerDialog('new')); el('adjust-customer').addEventListener('click',()=>openCustomerDialog('adjust')); el('customer-form').addEventListener('submit',event=>{ event.preventDefault(); const data=new FormData(event.currentTarget); if(customerMode==='delete'){ for(const image of [selectedCustomer.avatar,selectedCustomer.logo]) if(image) URL.revokeObjectURL(image); customers.splice(customers.indexOf(selectedCustomer),1); }else if(customerMode==='status'){ selectedCustomer.inactive=!selectedCustomer.inactive; }else if(customerMode==='edit'){ const name=data.get('name').trim(); if(!name){event.currentTarget.elements.name.focus();return;} Object.assign(selectedCustomer,{name,owner:data.get('owner').trim(),phone:data.get('phone').trim(),email:data.get('email').trim()}); }else if(customerMode==='new'){ const name=data.get('name').trim(); if(!name){event.currentTarget.elements.name.focus();return;} const readField=key=>String(data.get(key)??'').trim(); const imageUrl=key=>data.get(key)?.size ? URL.createObjectURL(data.get(key)) : ''; customers.push({id:Math.max(0,...customers.map(c=>c.id))+1,name,owner:readField('owner'),phone:readField('phone'),email:readField('email'),type:readField('type'),country:readField('country'),address:readField('address'),shippingAddress:readField('shippingAddress'),priceLevel:readField('priceLevel'),openingDate:readField('openingDate'),due:Math.round(Number(readField('openingBalance'))*100),avatar:imageUrl('avatar'),logo:imageUrl('logo')}); if(event.submitter?.id==='customer-save-new'){ renderCustomers(); renderCustomerCreate(el('customer-dialog-body')); el('customer-created').textContent='Customer saved.'; el('customer-created').hidden=false; event.currentTarget.elements.name.focus(); return; } }else if(customerMode==='adjust'){ const customer=customers.find(c=>c.id===Number(data.get('id'))); if(customer) customer.due+=Math.round(Number(data.get('amount'))*100); } renderCustomers();customerDialog.close(); }); const ledgerPage=el('customer-ledger'); let customerListScroll=0; const sampleLedger=[ ['07-19','Sales','sal-1867',2850000,0],['07-21','Payment','py-27',2168000,null], ['07-21','Purchase','pur-1954',2168000,2168000],['07-21','Purchase','pur-1949',530000,0], ['07-21','Sales','sal-1915',3800000,0],['07-21','Sales','sal-1911',2850000,0], ['08-02','Receipt','rc-1562',8970000,null],['08-30','Purchase','pur-2179',2892125,2892125], ['08-30','Payment','py-177',2892125,null],['09-27','Purchase','pur-2298',732816,0], ['09-28','Payment','py-278',1231600,null],['09-28','Purchase','pur-2300',1231600,1231600], ['10-06','Purchase','pur-2338',6859900,0],['10-11','Sales','sal-3235',3000000,0], ['10-15','Receipt','rc-2797',4592716,null] ]; const suppliers=[ {name:'Demo Hardware Supplier', transactions:[ ['2026-10-06','Purchase','pur-2338',6859900,2000000], ['2026-10-06','Payment','py-301',2000000,null] ]}, {name:'Demo Electrical Supplier', transactions:[ ['2026-09-28','Purchase','pur-2300',1231600,1231600], ['2026-09-28','Payment','py-278',1231600,null] ]} ]; const supplierPayable=supplier=>supplier.transactions.reduce((due,[,type,,amount,paid])=>due+(type==='Purchase'?amount-paid:0),supplier.openingPayable||0); suppliers.push(...[ 'Rainbow/Pirgonj','Fom/Thakurgoun','Molla Enterprize/Imamgong,Dhaka','AB Sattar/Imamgong,Dhaka', 'Mayer Dowa Screw/Imamgong,Dhaka','Dhaka Iron Agency/Imamgonj,Dhaka','MT Kopal Barnish & Paint', 'Najmul Iron/Sibgong','Ancharul Hard/Thakurgone','Lira Pipe Fitting','Eriction/Pirgonj', 'Shams Hardware & Tools','Shohal Hard/Imamgong,Dhaka','Subhanallah Hard/Imamgong,Dhaka', 'Nurani Enterprise/Imamgong,Dhaka','Full Zaru/Tangail','Krishi Foundry','Sprit Pounchogor/Thakurgoun', 'Hazi Mona Poly/Chokbazer,Dhaka','RFL Delux Grup/Ranisingol','Sambond/Thakurgone' ].map((name,index)=>({name,phone:['01810155790','','01778348399','01711987491','01786314311','01743036557','01737471324','01723016471','01738449238'][index],openingPayable:({6:78904,8:59909,10:24850,13:92599,15:5000,18:27950,20:6180}[index]||0)*100,transactions:[]}))); let ledgerEntries=[]; let ledgerReturnView; const sampleSupplierContacts=['আরিফ হোসেন','রাশেদ আহমেদ','মিজান রহমান','তানভীর ইসলাম','মোস্তাফিজুর রহমান','আবদুল সাত্তার','সাইফুল ইসলাম','হাবিবুর রহমান','কামাল উদ্দিন','নাজমুল ইসলাম','আনছারুল হক','শামীম আহমেদ','জাহিদ হাসান','শামসুল আলম','সোহেল রানা','সাইদুল ইসলাম','নুরুল আমিন','আবদুল করিম','মাহবুব আলম','সুমন মিয়া','মনির হোসেন','রফিকুল ইসলাম','আবদুল্লাহ রহমান']; suppliers.forEach((supplier,index)=>{ const number=String(index+1).padStart(4,'0'); supplier.owner ||= sampleSupplierContacts[index]; supplier.phone ||= '01X-XXXX-'+number; supplier.email ||= 'supplier'+number+'@example.com'; }); const kopalSupplier=suppliers.find(supplier=>supplier.name==='MT Kopal Barnish & Paint'); Object.assign(kopalSupplier,{ address:'Pirgonj, Thakurgaon', openingDate:'2026-11-01', openingPayable:(78904-25456)*100, transactions:[ ["2026-11-02", "Payment", "Pay-112", 18180000, null], ["2026-11-02", "Purchase", "Pur-16", 18180000, 18180000], ["2026-11-02", "Purchase", "Pur-6", 2545600, 0], ["2026-11-03", "Payment", "Pay-116", 2500000, null], ["2026-11-03", "Purchase", "Pur-19", 2500000, 2500000], ["2026-11-03", "Purchase", "Pur-15", 2720000, 2720000], ["2026-11-03", "Payment", "Pay-111", 2720000, null], ["2026-11-04", "Purchase", "Pur-22", 732816, 732816], ["2026-11-04", "Payment", "Pay-117", 732816, null], ["2026-11-09", "Payment", "Pay-148", 1548800, null], ["2026-11-09", "Purchase", "Pur-45", 1548800, 1548800], ["2026-11-10", "Purchase", "Pur-48", 1143600, 1143600], ["2026-11-10", "Payment", "Pay-140", 1143600, null], ["2026-11-11", "Payment", "Pay-146", 58800, null], ["2026-11-11", "Purchase", "Pur-51", 58800, 58800], ["2026-11-14", "Purchase", "Pur-62", 1000000, 1000000], ["2026-11-14", "Payment", "Pay-157", 1000000, null], ["2026-11-14", "Payment", "Pay-156", 1237200, null], ["2026-11-14", "Purchase", "Pur-61", 1487700, 1487700], ["2026-11-14", "Payment", "Pay-155", 1487700, null], ["2026-11-14", "Purchase", "Pur-60", 1237200, 1237200], ["2026-11-15", "Payment", "Pay-165", 3767200, null], ["2026-11-15", "Purchase", "Pur-69", 3767200, 3767200], ] }); let supplierPage=1; const supplierViewport=matchMedia('(max-width:720px)'); const supplierSize=el('supplier-size'); const supplierPrev=el('supplier-prev'); const supplierNext=el('supplier-next'); function renderSuppliers(){ const search=el('supplier-search').value.trim().toLowerCase(); const matches=suppliers.filter(supplier=>[supplier.name,supplier.owner,supplier.phone,supplier.email].some(value=>value?.toLowerCase().includes(search))); const size=supplierViewport.matches?20:supplierSize.value==='All'?suppliers.length:Number(supplierSize.value); const pages=Math.max(1,Math.ceil(matches.length/size)); supplierPage=Math.min(supplierPage,pages); const offset=(supplierPage-1)*size; el('supplier-total').textContent=suppliers.length; el('supplier-payable').textContent=formatDue(suppliers.reduce((sum,supplier)=>sum+supplierPayable(supplier),0)); el('supplier-count').textContent=matches.length?(offset+1)+'–'+Math.min(offset+size,matches.length)+' of '+matches.length:'No suppliers found'; supplierPrev.disabled=supplierPage===1; supplierNext.disabled=supplierPage===pages; el('supplier-list').replaceChildren(...matches.slice(offset,offset+size).map((supplier,index)=>{ const row=document.createElement('tr'); [offset+index+1,supplier.name+(supplier.inactive?' (Inactive)':''),supplier.owner||'—',supplier.phone||'—',supplier.email||'—'].forEach(value=>{row.insertCell().textContent=value;}); const avatar=document.createElement('span'); avatar.className='customer-avatar demo-portrait'; avatar.dataset.tone=String((offset+index)%3); avatar.setAttribute('aria-hidden','true'); row.insertCell().append(avatar); row.insertCell().textContent=formatDue(supplierPayable(supplier)); const button=document.createElement('button'); button.type='button'; button.className='customer-more'; button.textContent='⋮'; button.setAttribute('aria-label','Actions for '+supplier.name); button.setAttribute('popovertarget','customer-menu'); button.addEventListener('click',()=>prepareCustomerMenu(button,supplier,true)); row.insertCell().append(button); return row; })); } function resetSupplierPage(){ supplierPage=1; supplierSize.hidden=supplierViewport.matches; renderSuppliers(); } el('supplier-search').addEventListener('input',resetSupplierPage); supplierSize.addEventListener('change',resetSupplierPage); supplierViewport.addEventListener('change',resetSupplierPage); supplierPrev.addEventListener('click',()=>{supplierPage--;renderSuppliers();}); supplierNext.addEventListener('click',()=>{supplierPage++;renderSuppliers();}); document.querySelectorAll('[data-open-suppliers]').forEach(button=>button.addEventListener('click',()=>{ showCustomers(false); el('dashboard-content').hidden=true; el('suppliers-view').hidden=false; resetSupplierPage(); el('suppliers-title').focus(); })); el('supplier-back').addEventListener('click',()=>showCustomers(false)); const supplierDialog=el('supplier-dialog'); const supplierForm=el('supplier-form'); let supplierAction; let selectedSupplier; const supplierForms={ new:['New Supplier','<label>Business Name<input name="name" required maxlength="140"></label><label>Supplier Name<input name="owner" maxlength="140"></label><label>Mobile / Phone<input name="phone" type="tel"></label><label>Email<input name="email" type="email"></label>','Save'], adjust:['Balance Adjustment','<label>Supplier<select name="supplier" required></select></label><label>Adjustment amount (+/−)<input name="amount" type="number" step="0.01" required></label>','Apply'], ask:['Ask AI','<label>Find suppliers by name, phone or email<input name="query" required></label>','Search'] }; function openSupplierForm(action,supplier){ supplierAction=action; selectedSupplier=supplier; const extra={ edit:['Edit Supplier',supplierForms.new[1],'Save'], status:[supplier?.inactive?'Activate Supplier':'Set Supplier Inactive','','Confirm'], delete:['Delete Supplier','','Delete'], sms:['Reminder SMS','<label>Phone<input name="phone" type="tel" required></label><label>Message<textarea name="message" required></textarea></label>','Preview SMS'] }; const [title,fields,submit]=supplierForms[action]||extra[action]; el('supplier-dialog-title').textContent=title; el('supplier-fields').innerHTML=fields; el('supplier-submit').textContent=submit; el('supplier-submit').hidden=false; if(action==='adjust'){ suppliers.forEach((supplier,index)=>supplierForm.elements.supplier.add(new Option(supplier.name,index))); } if(action==='edit'){ for(const key of ['name','owner','phone','email']) supplierForm.elements[key].value=supplier[key]||''; }else if(action==='delete'||action==='status'){ el('supplier-fields').textContent=supplier.name; }else if(action==='sms'){ supplierForm.elements.phone.value=supplier.phone||''; supplierForm.elements.message.value='Payment reminder for '+supplier.name+'.'; } supplierDialog.showModal(); } el('new-supplier').addEventListener('click',()=>openSupplierForm('new')); el('adjust-supplier').addEventListener('click',()=>openSupplierForm('adjust')); el('supplier-ask').addEventListener('click',()=>openSupplierForm('ask')); el('supplier-close').addEventListener('click',()=>supplierDialog.close()); supplierForm.addEventListener('submit',event=>{ event.preventDefault(); const data=new FormData(supplierForm); if(supplierAction==='new'){ const name=data.get('name').trim(); if(!name)return; suppliers.unshift({name,owner:data.get('owner').trim(),phone:data.get('phone').trim(),email:data.get('email').trim(),transactions:[]}); el('supplier-search').value=''; }else if(supplierAction==='edit'){ const name=data.get('name').trim(); if(!name)return; for(const key of ['name','owner','phone','email']) selectedSupplier[key]=data.get(key).trim(); }else if(supplierAction==='status'){ selectedSupplier.inactive=!selectedSupplier.inactive; }else if(supplierAction==='delete'){ suppliers.splice(suppliers.indexOf(selectedSupplier),1); }else if(supplierAction==='sms'){ el('supplier-fields').textContent='Demo SMS preview for '+data.get('phone')+': '+data.get('message'); el('supplier-submit').hidden=true; return; }else if(supplierAction==='adjust'){ const supplier=suppliers[Number(data.get('supplier'))]; supplier.openingPayable=(supplier.openingPayable||0)+Math.round(Number(data.get('amount'))*100); }else{ el('supplier-search').value=data.get('query').trim(); } supplierDialog.close(); resetSupplierPage(); }); function renderCustomerLedger(){ const query=el('ledger-search').value.trim().toLowerCase(); const matches=ledgerEntries.filter(entry=>entry.slice(0,3).some(value=>value.toLowerCase().includes(query))); const rows=matches.map(([date,type,number,amount,paid])=>{ const tr=document.createElement('tr'); const debit=type==='Sales'||type==='Payment'; [date,type,number,formatDue(amount),paid===null?'—':formatDue(paid)+' / '+formatDue(amount-paid),debit?formatDue(amount):'—',debit?'—':formatDue(amount)].forEach(value=>{tr.insertCell().textContent=value;}); const button=document.createElement('button'); button.type='button';button.textContent='⋮';button.className='ledger-more';button.setAttribute('aria-label','Details for '+number);button.setAttribute('popovertarget','ledger-menu'); button.addEventListener('click',()=>{ activeTransaction=[date,type,number,amount,paid]; const bounds=button.getBoundingClientRect(); ledgerMenu.style.left=Math.max(8,bounds.right-145)+'px'; ledgerMenu.style.top=(bounds.bottom+82<=window.innerHeight ? bounds.bottom+3 : Math.max(8,bounds.top-82))+'px'; }); tr.insertCell().append(button);return tr; }); el('ledger-rows').replaceChildren(...rows); el('ledger-count').textContent=matches.length ? 'Showing '+matches.length+' of '+ledgerEntries.length+' sample transactions' : 'No transactions found'; } function openCustomerLedger(customer,isSupplier=false){ const partyLabel=isSupplier?'Supplier':'Customer'; ledgerReturnView=el(isSupplier?'suppliers-view':'customers-view'); el('customer-ledger-title').textContent=partyLabel+' Summary'; el('ledger-back').textContent='← Back to '+partyLabel+' List'; el('ledger-balance').previousElementSibling.textContent=isSupplier?'Payable':'Receivable'; const profile=el('ledger-profile'); profile.replaceChildren(...[['Name',customer.name],['Phone / Mobile',customer.phone],['E-mail',customer.email],['Address',customer.address],['Price Level',customer.priceLevel],...(isSupplier?[ ['Opening Date',customer.openingDate], ['Opening Balance',formatDue(customer.openingPayable||0)] ]:[])].map(([label,value])=>{ const row=document.createElement('div'); const term=document.createElement('dt');term.textContent=label; const detail=document.createElement('dd');detail.textContent=value||'—';row.append(term,detail);return row; })); el('ledger-balance').textContent=formatDue(isSupplier?supplierPayable(customer):customer.due); ledgerEntries=isSupplier?customer.transactions:customer.demoPhoto?sampleLedger.map(([date,...entry])=>['2026-'+date,...entry]):[]; el('ledger-search').value=''; renderCustomerLedger(); customerListScroll=window.scrollY; ledgerReturnView.hidden=true; ledgerPage.hidden=false; window.scrollTo(0,0); el('customer-ledger-title').focus({preventScroll:true}); } el('ledger-search').addEventListener('input',renderCustomerLedger); el('ledger-back').addEventListener('click',()=>{ ledgerPage.hidden=true; ledgerReturnView.hidden=false; window.scrollTo(0,customerListScroll); if(customerMenuTrigger?.isConnected)customerMenuTrigger.focus({preventScroll:true}); customerMenuTrigger=null; }); const ledgerMenu=el('ledger-menu'); let activeTransaction; function transactionFields(){ const [date,type,number,amount,paid]=activeTransaction; const debit=type==='Sales'||type==='Payment'; return [['Date',date],['Bill Type',type],['Bill No.',number],['Bill Amount',formatDue(amount)],['Receipt / Due',paid===null?'—':formatDue(paid)+' / '+formatDue(amount-paid)],['Debit',debit?formatDue(amount):'—'],['Credit',debit?'—':formatDue(amount)]]; } el('ledger-view').addEventListener('click',()=>{ ledgerMenu.hidePopover(); const details=transactionFields().map(([label,value])=>{ const row=document.createElement('div'); const term=document.createElement('dt'); const description=document.createElement('dd'); term.textContent=label;description.textContent=value; row.append(term,description);return row; }); el('ledger-transaction-data').replaceChildren(...details); el('ledger-transaction').showModal(); }); el('ledger-download').addEventListener('click',()=>{ ledgerMenu.hidePopover(); const fields=transactionFields(); const csv=[fields.map(field=>field[0]),fields.map(field=>field[1])].map(row=>row.map(value=>'"'+value.replaceAll('"','""')+'"').join(',')).join('\r\n'); const url=URL.createObjectURL(new Blob([csv],{type:'text/csv;charset=utf-8'})); const link=document.createElement('a'); link.href=url;link.download=activeTransaction[2]+'.csv';link.click(); setTimeout(()=>URL.revokeObjectURL(url),1000); }); function dhakaBillDate(daysBack=0){ const today=new Intl.DateTimeFormat('en-CA',{timeZone:'Asia/Dhaka',year:'numeric',month:'2-digit',day:'2-digit'}).formatToParts(new Date()); const parts=Object.fromEntries(today.map(part=>[part.type,part.value])); return new Date(Date.UTC(Number(parts.year),Number(parts.month)-1,Number(parts.day)-daysBack)).toISOString().slice(0,10); } let salesAI=null; const salesBills=[ ['3580','Five Brothers Nasir/Jadurani Bazar',3220,3220],['3579','Bismillah Hardware/Pirgong',8520,0], ['3577','Islamia Hard/Ranisonkoil',2200,0],['3576','Shohel Hard/Dhirgong',4420,4420], ['3575','Ma Hardware/New Nekmorod',402,402],['3574','Vai Vai Hard/Pachghorea Bazar',4840,4840], ['3573','Sanik Trader/Jamun Bazar',2940,2940],['3572','Sofiz Uddin Hardware/Amgaon',4690,4690], ['3571','Five Brothers Badol/Jadurani Bazar',2400,2400],['3570','Aziz Hard/Jadurani Bazar',3478,3478], ['3569','Amir Hard/Dhirgong',1900,1900],['3568','Vai Vai Hard Chacha/Dhirgong',2800,2800], ['3567','Sahadot Hard/Bongao Bazar',3020,3020],['3566','Rony Hard/Jaborhat',5000,5000], ['3565','Balu Bari Hard',4560,3680],['3564','Mukul Traders/Border Hat',6040,6040], ['3563','Saha Brothers/Zonglipir',4560,2560],['3562','Babu Mia/Pirgong',10500,0], ['3561','Cash',55910,55910],['3560','Varieties Store/Ruiha',5300,5300], ['3559','Narayon Hard/Dangi Bazar',4250,4250],['3558','Sokhina Hard/Boleya Bazar',2350,2350], ['3557','Muskan Hard/Kalopir',7050,7050],['3556','Pach Siri/Mirzapur',5332,5332], ['3555','Suvechaa Hard/Atowari',8870,8870] ].map(([number,account,amount,receipt],index)=>({date:dhakaBillDate(index<18?1:2),number:'sal-'+number,account,amount:amount*100,receipt:receipt*100})); const salesDates=el('sales-dates'); const salesDialog=el('sales-dialog'); const salesEntry=el('sales-entry'); let additionalCosts=[]; const costDialog=el('bill-cost-dialog'); const costForm=el('bill-cost-form'); const costRows=el('bill-cost-rows'); function readAdditionalCosts(){ return [...costRows.rows].map(row=>({ account:row.querySelector('select').value, narration:row.querySelector('[data-cost-narration]').value.trim(), cents:Math.round(Number(row.querySelector('[data-cost-amount]').value)*100) })); } function costSum(entries){return entries.reduce((sum,entry)=>sum+entry.cents,0);} function refreshCostTotal(){ el('bill-cost-total').textContent=formatDue(costSum(readAdditionalCosts())); } function addCostRow(entry={}){ const row=costRows.insertRow(); const account=document.createElement('select'); account.setAttribute('aria-label','Account Name'); const names=['Delivery Charge','Packing Charge','Service Charge','Other Indirect Income']; if(entry.account&&!names.includes(entry.account))names.push(entry.account); account.add(new Option('Select account','')); names.forEach(name=>account.add(new Option(name,name))); account.value=entry.account||''; row.insertCell().append(account); const narration=document.createElement('input'); narration.dataset.costNarration=''; narration.setAttribute('aria-label','Narration'); narration.value=entry.narration||''; row.insertCell().append(narration); const amount=document.createElement('input'); amount.type='number'; amount.min='0'; amount.step='.01'; amount.dataset.costAmount=''; amount.setAttribute('aria-label','Amount'); amount.value=entry.cents?(entry.cents/100).toFixed(2):''; row.insertCell().append(amount); const remove=document.createElement('button'); remove.type='button'; remove.textContent='×'; remove.setAttribute('aria-label','Remove cost row'); remove.addEventListener('click',()=>{row.remove();refreshCostTotal();}); row.insertCell().append(remove); } el('bill-cost-open').addEventListener('click',()=>{ costRows.replaceChildren(); additionalCosts.forEach(addCostRow); while(costRows.rows.length<3)addCostRow(); refreshCostTotal(); costDialog.showModal(); }); el('bill-cost-close').addEventListener('click',()=>costDialog.close()); el('bill-cost-add').addEventListener('click',()=>{ addCostRow(); costRows.lastElementChild.querySelector('select').focus(); }); costForm.addEventListener('input',event=>{ event.target.closest('tr')?.querySelector('select')?.setCustomValidity(''); refreshCostTotal(); }); costForm.addEventListener('submit',event=>{ event.preventDefault(); const entries=readAdditionalCosts(); for(const [index,entry] of entries.entries()){ if((entry.cents||entry.narration)&&!entry.account){ const account=costRows.rows[index].querySelector('select'); account.setCustomValidity('Select an account for this cost.'); account.reportValidity(); return; } } additionalCosts=entries.filter(entry=>entry.account); salesEntry.elements.cost.value=(costSum(additionalCosts)/100).toFixed(2); recalculateBill(); costDialog.close(); }); const billFooter=salesEntry.querySelector('.bill-footer'); const billLines=salesEntry.querySelector('.bill-lines'); const billBottom=salesEntry.querySelector('.bill-bottom'); let scrollToNewBillRow=false; function positionBillFooter(){ if(!salesEntry.getClientRects().length)return; const bounds=el('sales-editor-page').getBoundingClientRect(); salesEntry.style.setProperty('--bill-footer-left',Math.max(0,bounds.left)+'px'); salesEntry.style.setProperty('--bill-footer-right',Math.max(0,document.documentElement.clientWidth-bounds.right)+'px'); salesEntry.style.setProperty('--bill-footer-height',billFooter.offsetHeight+'px'); const top=billLines.getBoundingClientRect().top; const available=billFooter.getBoundingClientRect().top-top-billBottom.offsetHeight-16; const height=Math.max(170,Math.floor(available))+'px'; if(billLines.style.getPropertyValue('--bill-lines-height')!==height){ billLines.style.setProperty('--bill-lines-height',height); } } const billFooterObserver=new ResizeObserver(positionBillFooter); billFooterObserver.observe(salesEntry); billFooterObserver.observe(billFooter); billFooterObserver.observe(billBottom); billFooterObserver.observe(salesEntry.querySelector('.bill-meta')); window.addEventListener('resize',positionBillFooter); let salesPage=1; let useRollingSalesDates=true; let salesFrom=dhakaBillDate(6); let salesTo=dhakaBillDate(); salesDates.elements.from.value=salesFrom; salesDates.elements.to.value=salesTo; salesDates.elements.to.min=salesFrom; const saleStatus=bill=>bill.receipt===bill.amount?'Paid':bill.receipt?'Partial':'Unpaid'; function salesFields(bill){ return [bill.date,bill.number,bill.account,formatDue(bill.amount),formatDue(bill.receipt),formatDue(bill.amount-bill.receipt),saleStatus(bill)]; } function renderSales(){ const query=el('sales-search').value.trim().toLowerCase(); const from=salesAI?.days?dhakaBillDate(salesAI.days-1):salesFrom; const to=salesAI?.days?dhakaBillDate():salesTo; const dated=salesBills.filter(bill=>(!from||bill.date>=from)&&(!to||bill.date<=to)&&matchesSalesAI(bill)); const rows=dated.filter(bill=>[bill.number,bill.account].some(value=>value.toLowerCase().includes(query))); const selection=mobileSalesScreen.matches?'20':el('sales-page-size').value; const size=selection==='All'?Math.max(1,rows.length):Number(selection); const pages=Math.max(1,Math.ceil(rows.length/size)); salesPage=Math.min(salesPage,pages); const offset=(salesPage-1)*size; const amount=dated.reduce((sum,bill)=>sum+bill.amount,0); const receipt=dated.reduce((sum,bill)=>sum+bill.receipt,0); el('sales-total').textContent=formatDue(amount); el('sales-received').textContent=formatDue(receipt); el('sales-due').textContent=formatDue(amount-receipt); el('sales-count').textContent=rows.length ? (offset+1)+'–'+Math.min(offset+size,rows.length)+' of '+rows.length : 'No sales bills found'; el('sales-prev').disabled=salesPage===1; el('sales-next').disabled=salesPage===pages; el('sales-rows').replaceChildren(...rows.slice(offset,offset+size).map(bill=>{ const row=document.createElement('tr'); salesFields(bill).forEach((value,index)=>{ const cell=row.insertCell();cell.textContent=value;cell.title=value; if(index===1){ const open=document.createElement('button');open.type='button';open.className='sales-card-open'; open.textContent=value;open.setAttribute('aria-label','View invoice '+value); open.addEventListener('click',()=>openSale(bill)); const text=document.createElement('span');text.className='sales-number-desktop';text.textContent=value; cell.replaceChildren(text,open); } if(index===2)cell.title=value; cell.dataset.label=['Date','Bill No','', 'Amount','Receipt','Due','Status'][index]; if(index===0)cell.dataset.mobileDate=value.split('-').reverse().join('/'); if(index===6)cell.className='sales-status '+value.toLowerCase(); }); const actions=document.createElement('div'); actions.className='sales-row-actions'; const makeAction=(label,icon,handler)=>{ const button=document.createElement('button'); button.type='button';button.title=label;button.setAttribute('aria-label',label+' '+bill.number); const glyph=document.createElement('i');glyph.className='fa-solid fa-'+icon;glyph.setAttribute('aria-hidden','true'); button.append(glyph);button.addEventListener('click',handler);return button; }; const more=makeAction('More actions','ellipsis-vertical',()=>{ selectedSale=bill; const bounds=more.getBoundingClientRect(); saleMenu.style.left=Math.max(8,bounds.right-174)+'px'; saleMenu.style.top=(bounds.bottom+177<innerHeight?bounds.bottom:Math.max(8,bounds.top-177))+'px'; }); more.setAttribute('popovertarget','sale-menu'); const print=makeAction('Print','print',()=>printSale(bill));print.className='sale-print-desktop'; actions.append(print,makeAction('Share','share-nodes',()=>shareSale(bill)),more); row.insertCell().append(actions); row.addEventListener('click',event=>{ if(matchMedia('(max-width:720px)').matches&&!event.target.closest('button'))openSale(bill); }); return row; })); } let editingSale=null; let salesListScroll=0; function backToSalesList(){ el('sales-editor-page').hidden=true; el('sales-view').hidden=false; renderSales(); window.scrollTo(0,salesListScroll); el('sales-title').focus({preventScroll:true}); } el('sales-editor-back').addEventListener('click',backToSalesList); function openSale(bill,edit=false){ editingSale=edit?bill:null; if(edit)bill=null; el('sales-dialog-title').textContent=bill?'Sale Invoice':edit?'Edit Sale':'Sales Bill'; el('sales-details').replaceChildren(); if(bill){ el('sales-details').append(...salesFields(bill).map((value,index)=>{ const row=document.createElement('div'), label=document.createElement('dt'), data=document.createElement('dd'); label.textContent=['Date','Bill Number','Accounts Name','Bill Amount','Receipt','Due','Payment Status'][index];data.textContent=value; row.append(label,data);return row; })); if(bill.items?.length){ const items=document.createElement('p');items.textContent=bill.items.map(item=>item.name+' × '+item.qty+' '+item.unit).join(' · '); el('sales-details').append(items); } }else{ resetSalesBill(); if(editingSale?.warehouse){ const warehouse=salesEntry.elements.warehouse; if(!Array.from(warehouse.options).some(option=>option.value===editingSale.warehouse)){ warehouse.add(new Option(editingSale.warehouse,editingSale.warehouse)); } warehouse.value=editingSale.warehouse; } salesEntry.querySelector('[value=continue]').hidden=edit; if(edit){ const fields=salesEntry.elements; for(const key of ['number','account','date','dueDate','notes','person'])fields[key].value=editingSale[key]??''; updateBillParty(); fields.receipt.value=(editingSale.receipt/100).toFixed(2); fields.cost.value=(editingSale.amount/100).toFixed(2); for(const item of editingSale.items??[]){ addBillLine(item.name,item.discount,item.price,item.qty,item.unit,item.tax,item.description,null,item.discountAmount); const inputs=el('bill-rows').rows[el('bill-rows').rows.length-1].querySelectorAll('input'); for(const input of inputs)input.value=item[input.dataset.field]; } if(editingSale.items?.length){ fields.cost.value=0;recalculateBill(); fields.cost.value=((editingSale.amount-Math.round(Number(fields.amount.value)*100))/100).toFixed(2); if(Number(fields.cost.value)<0){fields.round.value=fields.cost.value;fields.cost.value=0;} } if(Array.isArray(editingSale.additionalCosts)){ additionalCosts=editingSale.additionalCosts.map(entry=>({...entry})); fields.cost.value=(costSum(additionalCosts)/100).toFixed(2); fields.discount.value=editingSale.billDiscount??0; salesEntry.dataset.discountMode=editingSale.billDiscountAmount==null?'percent':'amount'; fields.discountAmount.value=editingSale.billDiscountAmount??0; fields.tax.value=editingSale.billTax??0; fields.round.value=editingSale.billRound??0; }else if(Number(fields.cost.value)>0){ additionalCosts=[{account:'Other Indirect Income',narration:'',cents:Math.round(Number(fields.cost.value)*100)}]; } recalculateBill(); } salesEntry.elements.receipt.setCustomValidity(''); salesEntry.elements.number.setCustomValidity(''); } if(bill){salesDialog.showModal();return;} salesListScroll=window.scrollY; el('sales-view').hidden=true; el('sales-editor-title').textContent=edit?'Edit Sale':'Sales Bill'; el('sales-editor-page').hidden=false; collapseSalesSidebar(); window.scrollTo(0,0); el('sales-editor-title').focus({preventScroll:true}); } document.querySelectorAll('[data-open-sales]').forEach(button=>button.addEventListener('click',()=>{ el('dashboard-content').hidden=true;el('suppliers-view').hidden=true;el('customers-view').hidden=true;el('customer-ledger').hidden=true; el('sales-editor-page').hidden=true;el('sales-view').hidden=false;showMobilePanel('dashboard');refreshSalesDates();renderSales();window.scrollTo(0,0);el('sales-title').focus(); })); el('sales-back').addEventListener('click',()=>showCustomers(false)); const settingsDialog=el('sales-settings'); const settingsForm=el('sales-settings-form'); const settingsAll=el('sales-settings-all'); const salesOptions=[...settingsForm.querySelectorAll('[name=option]')]; const settingsKey='cbook.sales-form.preferences'; function defaultSalesAccount(){ return savedSalesOptions.includes('0')?'Cash':''; } let savedSalesOptions=salesOptions.map(option=>option.value).filter(value=>value!=='29'&&value!=='per-unit'); try{ const stored=JSON.parse(localStorage.getItem(settingsKey)); if(Array.isArray(stored)) savedSalesOptions=stored; }catch{} const salesSettingFields={ 1:'#bill-party', 20:'#sales-entry [name=discount]', 21:'#sales-entry [name=tax]', 22:'#sales-entry [name=cost]', 23:'#sales-entry [name=round]', 2:'#sales-entry [name=dueDate]', 3:'#sales-entry [name=person]', 4:'#sales-entry [name=category],#sales-entry [name=subcategory]', 6:'#bill-item-stock', 7:'#bill-item-view' }; function applySalesSettings(){ salesEntry.classList.toggle('mobile-item-cards',savedSalesOptions.includes('29')); for(const [key,selector] of Object.entries(salesSettingFields)){ for(const field of document.querySelectorAll(selector)){ const target=field.closest('label')||field; target.dataset.settingHidden=''; target.hidden=!savedSalesOptions.includes(key); } } } function syncSalesColumns(){ const columns={2:8,3:9,4:10,5:11,6:12,7:13,8:14,9:15,13:17,14:17,15:18,16:18,17:"per-unit",19:19}; const table=salesEntry.querySelector('.bill-lines table'); const labels=['','','Item Code','MRP','Batch No.','Model No.','Size','Color','MFG. Date','EXP. Date','Qty','Unit','Price','Discount %','Discount','VAT/Tax %','VAT/Tax','Per Unit','Total']; for(const row of table.tBodies[0].rows){ if(row.dataset.item && !row.cells[10].dataset.cardLabel){ labels.forEach((label,index)=>{if(label)row.cells[index].dataset.cardLabel=label;}); } for(const [index,key] of Object.entries(columns)){ row.cells[index].hidden=!savedSalesOptions.includes(String(key)); } } const widths=[3,null,10,10,10,10,10,10,10,10,10,{chars:7,extra:11},10,5,10,{chars:8,extra:12},10,10,10,3,2]; const visibleWidths=widths.filter((width,index)=>columns[index]===undefined||savedSalesOptions.includes(String(columns[index]))); const colgroup=el('bill-column-widths'); const widthKey=visibleWidths.join(','); if(colgroup.dataset.widthKey!==widthKey){ colgroup.replaceChildren(...visibleWidths.map(width=>{ const col=document.createElement('col'); if(width!==null){ const chars=width.chars??width; col.style.width='calc('+chars+'ch + '+(10+(width.extra??0))+'px)'; } return col; })); const chars=visibleWidths.reduce((sum,width)=>sum+(width?.chars??width??24),0); const padding=visibleWidths.reduce((sum,width)=>sum+10+(width?.extra??0),0); table.style.setProperty('--bill-min-width','calc('+chars+'ch + '+padding+'px)'); colgroup.dataset.widthKey=widthKey; } const head=table.tHead.rows[0]; for(const [index,key] of Object.entries(columns)){ if(Number(index)<13)head.cells[index].hidden=!savedSalesOptions.includes(String(key)); } for(const [index,key] of ['17','18'].entries()){ const hidden=!savedSalesOptions.includes(key); head.cells[13+index].hidden=hidden; table.tHead.rows[1].cells[index*2].hidden=hidden; table.tHead.rows[1].cells[index*2+1].hidden=hidden; } el('bill-per-unit-head').hidden=el('bill-per-unit-foot').hidden=!savedSalesOptions.includes('per-unit'); el('bill-description-head').hidden=!savedSalesOptions.includes('19'); el('bill-description-foot').hidden=!savedSalesOptions.includes('19'); const footer=table.tFoot.rows[0]; footer.cells[0].colSpan=2+Object.keys(columns).slice(0,8).filter(index=>!table.tHead.rows[0].cells[index].hidden).length; [3,4,5,6].forEach((index)=>{footer.cells[index].hidden=!savedSalesOptions.includes(index<5?'17':'18');}); for(const control of salesEntry.querySelectorAll('[data-sales-option]')){ control.hidden=!savedSalesOptions.includes(control.dataset.salesOption); } } function syncSalesSettingsAll(){ const count=salesOptions.filter(option=>option.checked).length; settingsAll.checked=count===salesOptions.length; settingsAll.indeterminate=count>0&&count<salesOptions.length; } el('sales-settings-open').addEventListener('click',()=>{ salesOptions.forEach(option=>{option.checked=savedSalesOptions.includes(option.value);}); syncSalesSettingsAll(); settingsDialog.showModal(); }); el('sales-settings-close').addEventListener('click',()=>settingsDialog.close()); settingsAll.addEventListener('change',()=>{ salesOptions.forEach(option=>{option.checked=settingsAll.checked;}); syncSalesSettingsAll(); }); settingsForm.addEventListener('change',syncSalesSettingsAll); settingsForm.addEventListener('submit',event=>{ event.preventDefault(); savedSalesOptions=salesOptions.filter(option=>option.checked).map(option=>option.value); for(const qty of salesEntry.querySelectorAll('#bill-rows [data-default-qty]')){ qty.value=savedSalesOptions.includes('16')?'1':''; } try{localStorage.setItem(settingsKey,JSON.stringify(savedSalesOptions));}catch{} applySalesSettings(); if(!editingSale && (!salesEntry.elements.account.value || salesEntry.elements.account.value==='Cash')){ salesEntry.elements.account.value=defaultSalesAccount(); updateBillParty(); } recalculateBill(); settingsDialog.close(); }); applySalesSettings(); el('sales-create').addEventListener('click',()=>openSale()); el('sales-close').addEventListener('click',()=>salesDialog.close()); salesDates.addEventListener('submit',event=>{ event.preventDefault(); useRollingSalesDates=false; salesFrom=salesDates.elements.from.value;salesTo=salesDates.elements.to.value;salesPage=1;renderSales(); }); salesDates.addEventListener('input',()=>{ const {from,to}=salesDates.elements; to.min=from.value; }); salesDates.addEventListener('input',()=>{ if(!matchMedia('(max-width:720px)').matches)return; const {from,to}=salesDates.elements; if(from.value && to.value && to.value<from.value)to.value=from.value; salesDates.requestSubmit(); }); const mobileSalesScreen=matchMedia('(max-width:720px)'); mobileSalesScreen.addEventListener('change',()=>{salesPage=1;if(!el('sales-view').hidden)renderSales();}); const wideSalesScreen=matchMedia('(min-width:1440px)'); const salesPageSize=el('sales-page-size'); let salesPageSizeChosen=false; function setSalesPageSizeDefault(){ if(salesPageSizeChosen)return; salesPageSize.value=wideSalesScreen.matches?'25':'20'; salesPage=1; if(!el('sales-view').hidden)renderSales(); } setSalesPageSizeDefault(); wideSalesScreen.addEventListener('change',setSalesPageSizeDefault); salesPageSize.addEventListener('change',()=>{salesPageSizeChosen=true;salesPage=1;renderSales();}); el('sales-search').addEventListener('input',()=>{salesPage=1;renderSales();}); el('sales-prev').addEventListener('click',()=>{salesPage--;renderSales();}); el('sales-next').addEventListener('click',()=>{salesPage++;renderSales();}); salesEntry.addEventListener('input',()=>{salesEntry.elements.receipt.setCustomValidity('');salesEntry.elements.number.setCustomValidity('');salesEntry.elements.account.setCustomValidity('');}); function billMessagePhone(value){ const raw=String(value||'').trim(); if(!/^\+?[\d ()-]+$/.test(raw))return ''; const digits=raw.replace(/\D/g,''); if(/^01\d{9}$/.test(digits))return '+88'+digits; return /^\+?[1-9]\d{7,14}$/.test(raw.replace(/[ ()-]/g,''))?'+'+digits:''; } salesEntry.addEventListener('submit',event=>{ event.preventDefault(); const data=new FormData(salesEntry),number=data.get('number').trim(),account=data.get('account').trim(); const amount=Math.round(Number(data.get('amount'))*100),receipt=Math.round(Number(data.get('receipt'))*100); if((!editingSale&&!readBillLines().length)||!Number.isFinite(amount)||amount<=0){el('bill-feedback').textContent='Add at least one item and check the bill total.';return;} if(!number||salesBills.some(bill=>bill!==editingSale&&bill.number.toLowerCase()===number.toLowerCase())){salesEntry.elements.number.setCustomValidity('Enter a unique bill number.');salesEntry.elements.number.reportValidity();return;} if(!account){salesEntry.elements.account.setCustomValidity('Enter an account name.');salesEntry.elements.account.reportValidity();return;} if(receipt>amount){salesEntry.elements.receipt.setCustomValidity('Receipt cannot exceed the bill amount.');salesEntry.elements.receipt.reportValidity();return;} const action=event.submitter?.value; let destination; if(action==='whatsapp'||action==='sms'){ const matches=customers.filter(customer=>customer.name.toLowerCase()===account.toLowerCase()); const savedPhone=matches.length===1?billMessagePhone(matches[0].phone):''; const phone=savedPhone||billMessagePhone(window.prompt('Enter the customer mobile number with country code for '+account+'.')); if(!phone){ el('bill-feedback').textContent='A valid customer mobile number is required. Use Save to save without messaging.'; return; } const message=encodeURIComponent('Sumon Enterprise | Sales Bill '+number+' | Total: '+formatDue(amount)+' BDT | Received: '+formatDue(receipt)+' BDT | Due: '+formatDue(amount-receipt)+' BDT'); const smsSeparator=/iPhone|iPad|iPod/.test(navigator.userAgent)?'&':'?'; destination=action==='whatsapp'?'https://wa.me/'+phone.slice(1)+'?text='+message:'sms:'+phone+smsSeparator+'body='+message; } const record={date:data.get('date'),dueDate:data.get('dueDate'),number,account,amount,receipt,items:readBillLines(),additionalCosts:additionalCosts.map(entry=>({...entry})),billDiscount:salesEntry.elements.discount.value,billDiscountAmount:salesEntry.dataset.discountMode==='amount'?Number(salesEntry.elements.discountAmount.value):null,billTax:salesEntry.elements.tax.value,billRound:salesEntry.elements.round.value,notes:data.get('notes'),warehouse:salesEntry.elements.warehouse.value,person:data.get('person')}; if(editingSale)Object.assign(editingSale,record); else salesBills.unshift(record); salesPage=1;el('sales-search').value=''; renderSales(); if(event.submitter?.value==='continue'){resetSalesBill();el('bill-feedback').textContent='Bill saved.';salesEntry.elements.number.focus();} else { backToSalesList(); if(action==='print')printSale(record); if(action==='view')openSale(record); if(action==='whatsapp')window.open(destination,'_blank','noopener,noreferrer'); if(action==='sms')window.location.href=destination; } el('bill-save-menu').open=false; }); document.addEventListener('click',event=>{ const menu=el('bill-save-menu'); if(menu.open&&!menu.contains(event.target))menu.open=false; }); const saleMenu=el('sale-menu'); let selectedSale; saleMenu.addEventListener('click',event=>{ const button=event.target.closest('[data-sale-action]'); if(!button)return; saleMenu.hidePopover(); const bill=selectedSale; switch(button.dataset.saleAction){ case 'view': openSale(bill); break; case 'edit': openSale(bill,true); break; case 'delete': if(window.confirm('Delete sale '+bill.number+' from this demo session?')){ salesBills.splice(salesBills.indexOf(bill),1);renderSales(); } break; case 'invoice': downloadSaleDocument(bill,false); break; case 'challan': downloadSaleDocument(bill,true); break; } }); function downloadSaleDocument(bill,challan){ const heading=challan?'Delivery Challan':'Sale Invoice'; const items=(bill.items??[]).map(item=>item.name+' × '+item.qty+' '+item.unit); const details=challan?[bill.date,bill.number,bill.account]:[saleText(bill)]; const text=[heading,...details,...(items.length?items:['No item details in this demo bill.'])].join('\n'); const url=URL.createObjectURL(new Blob([text],{type:'text/plain;charset=utf-8'})); const link=document.createElement('a'); link.href=url;link.download=(challan?'challan-':'invoice-')+bill.number+'.txt';link.click(); setTimeout(()=>URL.revokeObjectURL(url),1000); } const salesLabels=['Date','Bill Number','Accounts Name','Bill Amount','Receipt','Due','Payment Status']; function saleText(bill){ return salesFields(bill).map((value,index)=>salesLabels[index]+': '+value).join('\n'); } function printSale(bill){ const printWindow=window.open('','_blank','popup'); if(!printWindow){openSale(bill);return;} printWindow.opener=null; printWindow.document.title='Sale Invoice '+bill.number; const title=printWindow.document.createElement('h1'); title.textContent='Sale Invoice'; const details=printWindow.document.createElement('pre'); details.textContent=saleText(bill); printWindow.document.body.append(title,details); printWindow.focus();printWindow.print(); } async function shareSale(bill){ const message=saleText(bill); try{ if(navigator.share){await navigator.share({title:'Sale Invoice '+bill.number,text:message});return;} }catch(error){if(error.name==='AbortError')return;} window.prompt('Copy invoice summary',message); } const demoItemDefaults={ 'Power Star Drum 2 No':{discount:5,tax:5} }; const itemPrices={'RFL PVC Net 5 Fit':70,'Power Star Drum 2 No':1050,'SS LED Pipe (M) 36″':300,'Ring 14×15':90,'Chain Kobja Heavy 3/4″':150,'LED Tube Light 10 Watt':350,'R Socket PVC 1×1/2″':90,'Thread Pipe 3/4 inch RFL':250}; let viewedBillItem=''; const demoItemStock={'RFL PVC Net 5 Fit':12,'Power Star Drum 2 No':8,'SS LED Pipe (M) 36″':20,'Ring 14×15':18,'Chain Kobja Heavy 3/4″':9,'LED Tube Light 10 Watt':11,'R Socket PVC 1×1/2″':10,'Thread Pipe 3/4 inch RFL':6}; function updateBillItemInfo(name=''){ viewedBillItem=name; el('bill-item-view').disabled=!name; el('bill-item-stock').textContent=name?availableBillStock(name)+' pc':'—'; } el('bill-item-view').addEventListener('click',()=>{ el('bill-item-details-text').textContent=viewedBillItem+' · Demo stock '+el('bill-item-stock').textContent; el('bill-item-details').showModal(); }); const itemSearch=el('bill-item'); const itemList=el('bill-item-list'); for(const [family,sizes] of Object.entries({ 'PVC Elbow':['½','¾','1','1¼','1½','2','2½','3','4'], 'PVC Tee':['½','¾','1','1¼','1½','2','2½','3','4'], 'Galvanized Bolt':['M4','M5','M6','M8','M10','M12','M14','M16','M18','M20'], 'Wall Plug':['4','5','6','7','8','9','10','12','14','16'], 'Cable Clip':['4','5','6','7','8','9','10','12','14','16'], 'Pipe Clamp':['½','¾','1','1¼','1½','2','2½','3','4'] })){ sizes.forEach((size,i)=>{ const name=family+' '+size; itemPrices[name]=20+i*10; demoItemStock[name]=i===0?0:12+i*4; }); } document.body.append(itemList); let activeItemInput=itemSearch; const warehouseStock={ 'Main Warehouse':demoItemStock, 'Branch Warehouse':Object.fromEntries(Object.entries(demoItemStock).map(([name,qty],index)=>[name,index%4===0?0:Math.floor(qty/2)])), 'Retail Warehouse':Object.fromEntries(Object.entries(demoItemStock).map(([name,qty],index)=>[name,index%3===0?Math.ceil(qty/3):0])) }; const billWiseStock = document.getElementById('bill-wise-stock'); const billWiseQty = document.getElementById('bill-wise-qty'); const billWiseUnit = document.getElementById('bill-wise-unit'); let billWiseRow; function updateBillWiseQuantity() { document.getElementById('bill-wise-total').value = (billWiseQty.value || '0') + ' ' + billWiseUnit.value; } billWiseQty.addEventListener('input', updateBillWiseQuantity); billWiseUnit.addEventListener('change', () => { document.querySelector('#bill-wise-title .bill-wise-title-unit').textContent = ' (' + billWiseUnit.value + ')'; updateBillWiseQuantity(); }); billWiseStock.addEventListener('close', () => { if (billWiseStock.returnValue === 'apply' && billWiseRow?.isConnected) { billWiseRow.querySelector('[data-field=qty]').value = billWiseQty.value; billWiseRow.querySelector('[data-field=unit]').value = billWiseUnit.value; recalculateBill(); } billWiseRow = null; }); function openBillWiseStock(row) { closeItemList(); billWiseRow = row; const name = row.dataset.item; const rowUnit = row.querySelector('[data-field=unit]'); const unit = rowUnit.value; const unitTag = document.createElement('span'); unitTag.className = 'bill-wise-title-unit'; unitTag.textContent = ' (' + unit + ')'; document.getElementById('bill-wise-title').replaceChildren(name, unitTag); document.getElementById('bill-wise-warehouse').textContent = salesEntry.elements.warehouse.value; document.getElementById('bill-wise-price').textContent = row.querySelector('[data-field=price]').value; document.getElementById('bill-wise-current').textContent = availableBillStock(name); billWiseUnit.replaceChildren(...Array.from(rowUnit.options, option => option.cloneNode(true))); billWiseUnit.value = unit; billWiseQty.value = row.querySelector('[data-field=qty]').value || '0'; updateBillWiseQuantity(); billWiseStock.returnValue = 'cancel'; billWiseStock.showModal(); } function selectedWarehouseStock(){ return warehouseStock[salesEntry.elements.warehouse.value]??{}; } function availableBillStock(name){ return selectedWarehouseStock()[name]??0; } salesEntry.elements.warehouse.addEventListener('change',()=>{ updateBillItemInfo(viewedBillItem); closeItemList(); }); let itemMatches=[]; let itemActive=-1; function closeItemList(){ itemList.hidden=true; activeItemInput.setAttribute('aria-expanded','false'); activeItemInput.removeAttribute('aria-activedescendant'); } function appendItemBatch(){ const start=itemList.children.length; for(const [offset,name] of itemMatches.slice(start,start+50).entries()){ const option=document.createElement('span'); option.id='bill-item-option-'+(start+offset); option.setAttribute('role','option'); const label=document.createElement('span'); label.textContent=name+' / pc'; label.title=name; const stock=document.createElement('small'); stock.textContent=availableBillStock(name); stock.classList.toggle('out-of-stock',availableBillStock(name)===0); option.append(label,stock); option.addEventListener('mousedown',event=>event.preventDefault()); option.addEventListener('click',event=>{ event.preventDefault(); event.stopPropagation(); chooseBillItem(name); }); itemList.append(option); } } function markBillItem(index){ itemActive=index; [...itemList.children].forEach((option,i)=>option.setAttribute('aria-selected',String(i===index))); const option=itemList.children[index]; if(option)activeItemInput.setAttribute('aria-activedescendant',option.id); } function showItemList(query=''){ itemMatches=Object.keys(itemPrices).filter(name=>name.toLowerCase().includes(query.toLowerCase())); itemList.replaceChildren(); itemList.scrollTop=0; appendItemBatch(); if(!itemMatches.length){closeItemList();return;} const bounds=activeItemInput.getBoundingClientRect(); itemList.style.left=bounds.left+'px'; itemList.style.top=bounds.bottom+'px'; itemList.style.width=Math.min(bounds.width,document.documentElement.clientWidth-bounds.left)+'px'; itemList.style.maxHeight=Math.min(194,Math.max(48,window.innerHeight-bounds.bottom-8))+'px'; itemList.hidden=false; activeItemInput.setAttribute('aria-expanded','true'); activeItemInput.removeAttribute('aria-activedescendant'); markBillItem(itemMatches.slice(0,50).indexOf(activeItemInput.value)); } function chooseBillItem(name){ if(activeItemInput===itemSearch)itemSearch.value=name; closeItemList(); updateBillItemInfo(name); if(mobileItemCards()){openMobileLine(name,activeItemInput.closest("tr[data-empty-item]"));return;} const existingRow=activeItemInput.closest('tr[data-item]'); if(existingRow){ if(existingRow.dataset.item!==name){ const qty=existingRow.querySelector('[data-field=qty]'); addBillLine(name,undefined,itemPrices[name],qty.hasAttribute('data-default-qty')?undefined:qty.value,'pc',undefined,'',existingRow); recalculateBill(); }else activeItemInput.value=name; return; } const fromRow=activeItemInput!==itemSearch; addBillLine(name,undefined,itemPrices[name],undefined,"pc",undefined,"",fromRow?activeItemInput.closest("tr[data-empty-item]"):null); recalculateBill(); if(fromRow){ const nextSearch=el('bill-rows').querySelector('[data-empty-item] .bill-row-item-search'); if(nextSearch&&!nextSearch.hidden){ nextSearch.focus(); closeItemList(); } } } itemList.addEventListener('scroll',()=>{ if(!itemList.hidden&&itemList.scrollHeight-itemList.clientHeight-itemList.scrollTop<24)appendItemBatch(); }); function wireItemSearch(input){ const open=()=>{ if(activeItemInput!==input)closeItemList(); activeItemInput=input; input.select(); showItemList(); }; input.addEventListener('focus',open); input.addEventListener('click',open); input.addEventListener('blur',()=>{if(activeItemInput===input)closeItemList();}); input.addEventListener('input',()=>{activeItemInput=input;showItemList(input.value.trim());}); input.addEventListener('dragstart',event=>event.preventDefault()); input.addEventListener('keydown',event=>{ if(event.key==='Escape'){closeItemList();return;} if(event.key==='ArrowDown'||event.key==='ArrowUp'){ event.preventDefault(); event.stopPropagation(); if(itemList.hidden)showItemList(); if(event.key==='ArrowDown'&&itemActive===itemList.children.length-1)appendItemBatch(); const count=itemList.children.length; if(!count)return; const next=event.key==='ArrowDown'?Math.min(itemActive+1,count-1):Math.max(itemActive-1,0); markBillItem(next); itemList.children[next].scrollIntoView({block:'nearest'}); }else if(event.key==='Enter'&&!itemList.hidden){ event.preventDefault(); event.stopPropagation(); if(itemActive>=0)chooseBillItem(itemMatches[itemActive]); } }); } wireItemSearch(itemSearch); window.addEventListener('resize',closeItemList); document.addEventListener('scroll',event=>{if(event.target!==itemList)closeItemList();},true); function updateBillParty(){ const account=salesEntry.elements.account.value.trim(); const customer=customers.find(entry=>entry.name===account); const supplier=suppliers.find(entry=>entry.name===account&&!entry.inactive); const isSupplier=supplier&&(!customer||billPartyKind==='supplier'); const party=isSupplier?supplier:customer; const rows=party?[ ['',party.name], ['',party.phone||'—'], ['',party.address,'address'], [isSupplier?'Payable':'Receivable',formatDue(isSupplier?supplierPayable(party):party.due)] ]:[]; el('bill-party').replaceChildren(...rows.filter(([,value])=>value).map(([label,value,field])=>{ const row=document.createElement('div'),term=document.createElement('dt'),detail=document.createElement('dd'); term.textContent=label;detail.textContent=value; if(label)row.append(term); if(field==='address'){ detail.className='bill-party-address'; detail.title=value; } row.append(detail);return row; })); } const billAccount=salesEntry.elements.account; // Keep selected account text editable, but prevent moving it between inputs. billAccount.addEventListener('dragstart',event=>event.preventDefault()); salesEntry.elements.number.addEventListener('drop',event=>{ if(event.dataTransfer?.types.includes('text/plain')) event.preventDefault(); }); const billCustomers=el('bill-customers'); let activeBillCustomer=-1; let billPartyKind=''; function closeBillCustomers(){ billCustomers.hidden=true; billAccount.setAttribute('aria-expanded','false'); billAccount.removeAttribute('aria-activedescendant'); } function markBillCustomer(index){ activeBillCustomer=index; [...billCustomers.children].forEach((option,i)=>option.setAttribute('aria-selected',String(i===index))); const option=billCustomers.children[index]; if(option) billAccount.setAttribute('aria-activedescendant',option.id); else billAccount.removeAttribute('aria-activedescendant'); } let billCustomerQuery=''; let billCustomerLimit=50; function showBillCustomers(query='',append=false){ if(!append){billCustomerQuery=query;billCustomerLimit=50;} const entries=[{name:'Cash',kind:'cash'},...customers,...suppliers.filter(supplier=>!supplier.inactive).map(supplier=>({name:supplier.name,due:supplierPayable(supplier),kind:'supplier'}))].filter(entry=>entry.name.toLowerCase().includes(query.toLowerCase())); const start=append?billCustomers.children.length:0; if(!append){billCustomers.replaceChildren();billCustomers.scrollTop=0;} billCustomers.append(...entries.slice(start,billCustomerLimit).map((entry,offset)=>{ const index=start+offset; const option=document.createElement('span'); option.id='bill-customer-option-'+index; option.setAttribute('role','option'); const name=document.createElement('span'); name.textContent=entry.name; name.className='bill-customer-name'; name.title=entry.name; option.classList.toggle('bill-cash-option', entry.name==='Cash'); option.classList.toggle('bill-supplier-option',entry.kind==='supplier'); option.append(name); if(entry.due!=null){ const amount=document.createElement('small'); amount.textContent=formatDue(entry.due); option.append(amount); } option.addEventListener('mousedown',event=>event.preventDefault()); option.addEventListener('click',event=>{ event.preventDefault(); event.stopPropagation(); pickBillCustomer(entry.name,entry.kind||'customer'); }); return option; })); if(!entries.length){closeBillCustomers();return;} billCustomers.hidden=false; billAccount.setAttribute('aria-expanded','true'); billCustomers.dataset.total=entries.length; markBillCustomer(append?activeBillCustomer:entries.slice(0,billCustomerLimit).findIndex(entry=>entry.name===billAccount.value)); } function loadMoreBillCustomers(){ if(billCustomers.children.length>=Number(billCustomers.dataset.total))return; billCustomerLimit+=50; showBillCustomers(billCustomerQuery,true); } billCustomers.addEventListener('scroll',()=>{ if(!billCustomers.hidden&&billCustomers.scrollHeight-billCustomers.clientHeight-billCustomers.scrollTop<24)loadMoreBillCustomers(); }); function pickBillCustomer(name,kind){ billAccount.value=name; billPartyKind=kind; billAccount.setCustomValidity(''); updateBillParty(); closeBillCustomers(); } function focusBillCustomers(){ billAccount.select(); showBillCustomers(); } billAccount.addEventListener('focus',focusBillCustomers); billAccount.addEventListener('click',focusBillCustomers); billAccount.addEventListener('blur',closeBillCustomers); billAccount.addEventListener('input',()=>{ billPartyKind=''; updateBillParty(); showBillCustomers(billAccount.value.trim()); }); billAccount.addEventListener('keydown',event=>{ if(event.key==='Escape'){closeBillCustomers();return;} if(event.key==='ArrowDown'||event.key==='ArrowUp'){ event.preventDefault();event.stopPropagation(); if(billCustomers.hidden)showBillCustomers(); if(event.key==='ArrowDown'&&activeBillCustomer===billCustomers.children.length-1)loadMoreBillCustomers(); const count=billCustomers.children.length; if(!count)return; const step=event.key==='ArrowDown'?1:-1; const next=activeBillCustomer<0?(step===1?0:count-1):(activeBillCustomer+step+count)%count; markBillCustomer(next); billCustomers.children[next].scrollIntoView({block:'nearest'}); }else if(event.key==='Enter'&&!billCustomers.hidden&&activeBillCustomer>=0){ event.preventDefault();event.stopPropagation(); billCustomers.children[activeBillCustomer].click(); } }); const demoSecondUnits={'RFL PVC Net 5 Fit':'roll','SS LED Pipe (M) 36″':'box','LED Tube Light 10 Watt':'box'}; function mobileItemCards(){ return matchMedia('(max-width:720px)').matches && savedSalesOptions.includes('29'); } const mobileLineDialog=el('mobile-line-dialog'); const mobileLineForm=el('mobile-line-form'); const billNumericInput='#bill-rows input:is([data-field="qty"],[data-field="price"],[data-field="discount"],[data-line-discount-amount],[data-line-total]), .bill-totals input:is([name="discount"],[name="discountAmount"],[name="round"],[name="receipt"]), #mobile-line-form input[type="number"]'; function selectBillValue(event){ const field=event.target; if(field instanceof HTMLInputElement && field.matches(billNumericInput) && !field.disabled){ field.select(); } } for(const form of [salesEntry,mobileLineForm]){ form.addEventListener('focusin',selectBillValue); form.addEventListener('click',selectBillValue); } let mobileLineName, mobileLineRow; function updateMobileLine(){ const fields=mobileLineForm.elements; const gross=Number(fields.qty.value)*Number(fields.price.value)*100; const discount=discountCents(Math.round(gross),Number(fields.discount.value),mobileLineForm.dataset.discountMode==='amount'?Number(fields.discountAmount.value):null); const net=Math.round(gross)-discount; const tax=Math.round(net*Number(fields.tax.value)/100); syncDiscountInputs(gross,discount,mobileLineForm.dataset.discountMode,fields.discount,fields.discountAmount); el('mobile-line-tax').value=formatDue(tax); const total=net+tax; const qty=Number(fields.qty.value); el('mobile-line-per-unit-group').hidden=!savedSalesOptions.includes('per-unit'); el('mobile-line-per-unit').value=formatDue(qty>0?Math.round(total/qty):0); el('mobile-line-total').value=formatDue(total); } function openMobileLine(name,row=null){ if(!mobileItemCards())return; mobileLineName=name; mobileLineRow=row; const fields=mobileLineForm.elements; const value=key=>row?.querySelector('[data-field='+key+']')?.value; const unit=value('unit')||'pc'; fields.unit.replaceChildren(...Array.from(new Set(['pc',demoSecondUnits[name],unit].filter(Boolean)),choice=>new Option(choice,choice))); fields.unit.value=unit; fields.qty.value=value('qty')||1; fields.price.value=value('price')??itemPrices[name]; fields.discount.disabled=!savedSalesOptions.includes('17'); fields.discountAmount.disabled=fields.discount.disabled; mobileLineForm.dataset.discountMode=fields.discount.disabled?'percent':(row?.dataset.discountMode||'percent'); fields.discountAmount.value=row?.querySelector('[data-line-discount-amount]')?.value??0; fields.tax.disabled=!savedSalesOptions.includes('18'); mobileLineForm.querySelectorAll('[data-mobile-discount]').forEach(label=>label.hidden=fields.discount.disabled); mobileLineForm.querySelectorAll('[data-mobile-tax]').forEach(label=>label.hidden=fields.tax.disabled); fields.tax.querySelector('[data-custom-rate]')?.remove(); const currentRate=String(value('tax')??demoItemDefaults[name]?.tax??0); if(!fields.tax.disabled && currentRate && !Array.from(fields.tax.options).some(option=>option.value===currentRate)){ const option=new Option(currentRate+'%',currentRate); option.dataset.customRate=''; fields.tax.add(option); } fields.discount.value=fields.discount.disabled?0:(value('discount')??demoItemDefaults[name]?.discount??0); fields.tax.value=fields.tax.disabled?0:currentRate; el('mobile-line-title').textContent=name; updateMobileLine(); mobileLineDialog.showModal(); } el('mobile-line-close').addEventListener('click',()=>mobileLineDialog.close()); mobileLineForm.addEventListener('input',event=>{ if(event.target.name==='discount'||event.target.name==='discountAmount'){ mobileLineForm.dataset.discountMode=event.target.name==='discountAmount'?'amount':'percent'; } updateMobileLine(); }); mobileLineForm.querySelectorAll('[data-qty-step]').forEach(button=>button.addEventListener('click',()=>{ const qty=mobileLineForm.elements.qty; qty.value=Math.max(.01,Number(qty.value)+Number(button.dataset.qtyStep)).toFixed(2); updateMobileLine(); })); mobileLineForm.addEventListener('submit',event=>{ event.preventDefault(); const fields=mobileLineForm.elements; addBillLine(mobileLineName,fields.discount.value,fields.price.value,fields.qty.value,fields.unit.value,fields.tax.value,mobileLineRow?.dataset.description??'',mobileLineRow,mobileLineForm.dataset.discountMode==='amount'?Number(fields.discountAmount.value):null); recalculateBill(); mobileLineDialog.close(); closeItemList(); }); function ensureBlankBillRow(){ const body=el('bill-rows'); if(!savedSalesOptions.includes('28')){ const blanks=Array.from(body.querySelectorAll('[data-empty-item]')); blanks.slice(body.querySelector('[data-item]')?0:1).forEach(row=>row.remove()); } if(!body.rows.length || (savedSalesOptions.includes('28')&&!body.querySelector('[data-empty-item]')))appendBlankBillRow(); } function appendBlankBillRow(){ const row=el('bill-rows').insertRow(); row.dataset.emptyItem=''; for(let i=0;i<21;i++)row.insertCell(); row.cells[0].textContent=row.sectionRowIndex+1; const removeBlank=document.createElement('button'); removeBlank.type='button'; removeBlank.textContent='×'; removeBlank.setAttribute('aria-label','Remove empty item row'); removeBlank.addEventListener('click',()=>{ closeItemList(); row.remove(); renumberBillRows(); }); row.cells[20].append(removeBlank); const search=document.createElement('input'); search.className='bill-row-item-search'; search.setAttribute('aria-label','Search item in row'); search.setAttribute('role','combobox'); search.setAttribute('aria-controls','bill-item-list'); search.setAttribute('aria-expanded','false'); search.autocomplete='off'; search.placeholder='Search item'; wireItemSearch(search); row.cells[1].append(search); return search; } function renumberBillRows(){ for(const row of el('bill-rows').rows)row.cells[0].textContent=row.sectionRowIndex+1; } el('bill-add-row').addEventListener('click',()=>{ const search=appendBlankBillRow(); recalculateBill(); search.focus(); }); function addBillLine(name,discount=demoItemDefaults[name]?.discount??0,price=itemPrices[name],quantity,unit='pc',tax=demoItemDefaults[name]?.tax??0,description='',replaceRow=null,discountAmount=null){ const body=el('bill-rows'); replaceRow ||= body.querySelector('[data-empty-item]'); const row=replaceRow?body.insertRow(replaceRow.sectionRowIndex):body.insertRow(); replaceRow?.remove(); if(!replaceRow)scrollToNewBillRow=true; row.insertCell(); const itemCell=row.insertCell(); const itemLabel=document.createElement('span'); itemLabel.className='bill-row-item-label'; itemLabel.textContent=name; itemLabel.title=name; const stockButton=document.createElement('button'); stockButton.type='button'; stockButton.className='bill-wise-item'; stockButton.textContent=name; stockButton.addEventListener('click',()=>openBillWiseStock(row)); const itemEditor=document.createElement('input'); itemEditor.className='bill-row-item-search bill-row-item-editor'; itemEditor.value=name; itemEditor.autocomplete='off'; itemEditor.setAttribute('role','combobox'); itemEditor.setAttribute('aria-label','Change item in row'); itemEditor.setAttribute('aria-controls','bill-item-list'); itemEditor.setAttribute('aria-expanded','false'); itemEditor.addEventListener('blur',()=>{itemEditor.value=row.dataset.item;}); wireItemSearch(itemEditor); const cardEdit=document.createElement('button'); cardEdit.type='button';cardEdit.className='mobile-card-edit';cardEdit.textContent='✎'; cardEdit.setAttribute('aria-label','Edit '+name); cardEdit.addEventListener('click',()=>openMobileLine(name,row)); itemCell.append(itemLabel,itemEditor,stockButton,cardEdit); row.dataset.item=name; row.dataset.description=description; for(let i=0;i<8;i++)row.insertCell(); for(const [key,label,value,max] of [['qty','Quantity',quantity,''],['unit','Unit',unit,''],['price','Price',price, ''],['discount','Discount percent',discount,100],['tax','Tax percent',tax,100]]){ const input=document.createElement(key==='tax'||key==='unit'?'select':'input'); if(key==='unit') for(const choice of new Set(['pc',demoSecondUnits[name],unit].filter(Boolean))) input.add(new Option(choice,choice)); if(key==='tax') for(const rate of [0,5,7.5,10,15]) input.add(new Option(rate?rate+'%':'None',rate)); input.dataset.field=key;input.setAttribute('aria-label',label+' for '+name);input.value=value??(savedSalesOptions.includes('16')?'1':''); if(key==='qty'&&quantity===undefined){ input.dataset.defaultQty=''; input.addEventListener('input',()=>delete input.dataset.defaultQty); } if(key!=='unit'&&key!=='tax'){input.type='number';input.min=key==='qty'?'0.01':'0';input.step=key==='price'?'any':'.01';input.required=true;if(max)input.max=max;} if(key==='price'){ input.dataset.exactPrice=input.value; input.addEventListener('input',()=>delete input.dataset.exactPrice); } row.insertCell().append(input); if(key==="discount"){ const amount=document.createElement('input'); amount.type='number';amount.min='0';amount.step='.01'; amount.dataset.lineDiscountAmount=''; if(discountAmount!=null){ row.dataset.discountMode='amount'; amount.value=discountAmount; } amount.setAttribute('aria-label','Item discount amount'); row.insertCell().append(amount); } if(key==="tax")row.insertCell().className="bill-line-tax"; } const totalInput=document.createElement('input'); totalInput.type='text'; totalInput.inputMode='decimal'; totalInput.dataset.lineTotal=''; totalInput.setAttribute('aria-label','Total for '+name); totalInput.addEventListener('focus',()=>totalInput.select()); totalInput.addEventListener('input',()=>{ const amount=Number(totalInput.value.replaceAll(',','')); const qty=Number(row.querySelector('[data-field=qty]').value); const discount=savedSalesOptions.includes('17')?Number(row.querySelector('[data-field=discount]').value):0; const tax=savedSalesOptions.includes('18')?Number(row.querySelector('[data-field=tax]').value):0; const fixedDiscount=savedSalesOptions.includes('17')&&row.dataset.discountMode==='amount'?Number(row.querySelector('[data-line-discount-amount]').value):null; const factor=fixedDiscount===null?qty*(1-discount/100):qty; if(totalInput.value.trim()&&Number.isFinite(amount)&&amount>=0&&factor>0){ const netCents=Math.round(amount*100/(1+tax/100)); const priceInput=row.querySelector('[data-field=price]'); priceInput.dataset.exactPrice=String((netCents/100+(fixedDiscount??0))/factor); priceInput.value=Number(priceInput.dataset.exactPrice).toFixed(2); recalculateBill(); } }); totalInput.addEventListener('blur',()=>recalculateBill()); row.insertCell().className='bill-line-per-unit'; const totalCell=row.insertCell(); totalCell.className='bill-line-total'; totalCell.append(totalInput); const editDescription=document.createElement('button'); editDescription.type='button'; editDescription.className='bill-description-button'; editDescription.textContent='✎'; editDescription.title=description||'Description'; editDescription.setAttribute('aria-label','Edit description for '+name); editDescription.addEventListener('click',()=>{ const value=prompt('Description for '+name,row.dataset.description); if(value!==null){ row.dataset.description=value.trim(); editDescription.title=row.dataset.description||'Description'; } }); row.insertCell().append(editDescription); const remove=document.createElement('button'); remove.type='button';remove.textContent='×';remove.setAttribute('aria-label','Remove '+name); remove.addEventListener('click',()=>{row.remove();recalculateBill();}); row.insertCell().append(remove); } function readBillLines(){ return Array.from(el('bill-rows').rows).filter(row=>row.dataset.item).map(row=>{ const fields=Object.fromEntries(Array.from(row.querySelectorAll('[data-field]'),input=>[input.dataset.field,input.value])); return {name:row.dataset.item,description:row.dataset.description,unit:fields.unit,qty:Number(fields.qty),price:Number(row.querySelector('[data-field=price]').dataset.exactPrice??fields.price),discount:savedSalesOptions.includes('17')?Number(fields.discount):0, discountAmount:savedSalesOptions.includes('17')&&row.dataset.discountMode==='amount'?Number(row.querySelector('[data-line-discount-amount]').value):null,tax:savedSalesOptions.includes('18')?Number(fields.tax):0}; }); } function formatBillNumber(input){ if(input.value!=='' && Number.isFinite(input.valueAsNumber))input.value=input.valueAsNumber.toFixed(2); } salesEntry.addEventListener('focusout',event=>{ if(event.target.matches('input[type=number]'))formatBillNumber(event.target); }); function discountCents(gross,percent,amount){ return Math.max(0,Math.min(gross,Math.round(amount===null?gross*percent/100:amount*100))); } function syncDiscountInputs(gross,discount,mode,percentField,amountField){ if(mode==='amount'){ percentField.value=(gross?discount*100/gross:0).toFixed(2); if(document.activeElement!==amountField)amountField.value=(discount/100).toFixed(2); }else{ amountField.value=(discount/100).toFixed(2); } } function recalculateBill(){ for(const input of salesEntry.querySelectorAll('input[type=number]')){ if(input!==document.activeElement)formatBillNumber(input); } const warehouse=salesEntry.elements.warehouse; warehouse.disabled=Boolean(el('bill-rows').querySelector('tr[data-item]')); warehouse.title=warehouse.disabled?'Remove all items to change the warehouse':'Select warehouse'; ensureBlankBillRow(); renumberBillRows(); const rowEditing=savedSalesOptions.includes('28'); const billWise=savedSalesOptions.includes('5'); for(const button of salesEntry.querySelectorAll('.bill-wise-item'))button.hidden=!billWise; for(const search of salesEntry.querySelectorAll('.bill-row-item-search'))search.hidden=!rowEditing || (billWise && search.classList.contains('bill-row-item-editor')); for(const label of salesEntry.querySelectorAll('.bill-row-item-label'))label.hidden=rowEditing || billWise; syncSalesColumns(); positionBillFooter(); if(scrollToNewBillRow){ scrollToNewBillRow=false; if(window.innerWidth>720)billLines.scrollTop=billLines.scrollHeight; } let subtotal=0, totalQty=0, totalDiscount=0, totalTax=0; const itemRows=el('bill-rows').querySelectorAll('tr[data-item]'); readBillLines().forEach((line,index)=>{ const gross=Math.round(line.qty*line.price*100); const discount=discountCents(gross,line.discount,line.discountAmount); const net=gross-discount; const tax=Math.round(net*line.tax/100); const total=net+tax; const row=itemRows[index]; const totalInput=row.querySelector('[data-line-total]'); if(document.activeElement!==totalInput)totalInput.value=formatDue(total); syncDiscountInputs(gross,discount,row.dataset.discountMode,row.querySelector('[data-field=discount]'),row.querySelector('[data-line-discount-amount]')); row.querySelector('.bill-line-tax').textContent=formatDue(tax); row.cells[1].dataset.cardName=line.name; const adjustments=[]; if(discount>0)adjustments.push('Dis: '+line.discount+'% ('+formatDue(discount)+')'); if(tax>0)adjustments.push('VAT/Tax: '+line.tax+'% ('+formatDue(tax)+')'); row.cells[1].dataset.cardSummary=[line.qty+' '+line.unit+' × '+line.price.toFixed(2),adjustments.join(', ')].filter(Boolean).join('\n'); const perUnit=formatDue(line.qty?Math.round(total/line.qty):0); row.querySelector('.bill-line-per-unit').textContent=perUnit; row.dataset.cardTotal=(savedSalesOptions.includes('per-unit')?'Per Unit: '+perUnit+'\n':'')+'Total: '+formatDue(total); subtotal+=total;totalQty+=line.qty;totalDiscount+=discount;totalTax+=tax; }); const fields=salesEntry.elements; el('bill-item-qty').textContent=Number(totalQty.toFixed(2)); el('bill-item-discount').textContent=formatDue(totalDiscount); el('bill-item-tax').textContent=formatDue(totalTax); el('bill-item-total').textContent=formatDue(subtotal); const settingAmount=(key,field)=>savedSalesOptions.includes(key)?Number(fields[field].value):0; const discountValue=discountCents(subtotal,settingAmount('20','discount'),savedSalesOptions.includes('20')&&salesEntry.dataset.discountMode==='amount'?Number(fields.discountAmount.value):null); syncDiscountInputs(subtotal,discountValue,salesEntry.dataset.discountMode,fields.discount,fields.discountAmount); const net=subtotal-discountValue; const taxValue=Math.round(net*settingAmount('21','tax')/100); const beforeRound=net+taxValue+Math.round(settingAmount('22','cost')*100); if(el('bill-auto-round').checked)fields.round.value=((Math.round(beforeRound/100)*100-beforeRound)/100).toFixed(2); const total=beforeRound+Math.round(settingAmount('23','round')*100); if(el('bill-auto-receipt').checked)fields.receipt.value=(Math.max(0,total)/100).toFixed(2); el('bill-profit-preview').textContent='Est. profit/loss: '+formatDue(total-Math.round(readBillLines().reduce((sum,line)=>sum+line.qty*line.price*75,0))); fields.amount.value=(total/100).toFixed(2); el('bill-total').textContent=formatDue(total); el('bill-tax-value').textContent=formatDue(taxValue)+' BDT'; el('bill-round-total').textContent=formatDue(total); el('bill-total-fallback').hidden=savedSalesOptions.includes('23'); el('bill-balance').textContent=formatDue(total-Math.round(Number(fields.receipt.value)*100)); } function resetSalesBill(){ delete salesEntry.dataset.discountMode; salesEntry.reset(); additionalCosts=[]; el('bill-notes').open=false; salesEntry.elements.account.value=defaultSalesAccount(); const fields=salesEntry.elements; fields.number.value='sal-'+(Math.max(0,...salesBills.map(bill=>Number(/^sal-(\d+)$/i.exec(bill.number)?.[1]||0)))+1); const parts=new Intl.DateTimeFormat('en',{timeZone:'Asia/Dhaka',year:'numeric',month:'2-digit',day:'2-digit'}).formatToParts(new Date()); const date=Object.fromEntries(parts.map(part=>[part.type,part.value])); fields.date.value=date.year+'-'+date.month+'-'+date.day; fields.dueDate.value=fields.date.value; fields.account.value=defaultSalesAccount(); updateBillParty(); for(const name of ['number','account','receipt'])fields[name].setCustomValidity(''); closeBillCustomers(); el('bill-rows').replaceChildren(); itemSearch.value=''; closeItemList(); updateBillItemInfo(); fields.discount.value='0'; el('bill-feedback').textContent=''; recalculateBill(); } salesEntry.addEventListener('input',event=>{ const field=event.target; if(field.matches('[data-line-discount-amount],[data-field=discount]')){ field.closest('tr').dataset.discountMode=field.hasAttribute('data-line-discount-amount')?'amount':'percent'; } if(field.matches('[name=discountAmount],[name=discount]'))salesEntry.dataset.discountMode=field.name==='discountAmount'?'amount':'percent'; if(field.name==='round')el('bill-auto-round').checked=false; if(field.name==='receipt')el('bill-auto-receipt').checked=false; if(field.id==='bill-auto-round'&&!field.checked)salesEntry.elements.round.value='0'; if(field.id==='bill-auto-receipt'&&!field.checked)salesEntry.elements.receipt.value='0'; recalculateBill(); }); function refreshSalesDates(){ if(!useRollingSalesDates)return false; const today=dhakaBillDate(); if(today===salesTo)return false; salesTo=today; salesFrom=dhakaBillDate(6); salesDates.elements.from.value=salesFrom; salesDates.elements.to.value=salesTo; salesDates.elements.to.min=salesFrom; salesPage=1; return true; } function refreshOpenSalesList(){ if(refreshSalesDates()&&!el('sales-view').hidden)renderSales(); } setInterval(refreshOpenSalesList,15000); document.addEventListener('visibilitychange',()=>{if(!document.hidden)refreshOpenSalesList();}); function matchesSalesAI(bill){ if(!salesAI)return true; const due=bill.amount-bill.receipt; return (!salesAI.status||saleStatus(bill)===salesAI.status)&& (!salesAI.due||due>0)&& (salesAI.minimum===null||due>salesAI.minimum)&& (!salesAI.bill||bill.number.toLowerCase()===salesAI.bill)&& (!salesAI.account||bill.account.toLowerCase().includes(salesAI.account)); } function parseSalesQuestion(value){ const q=value.normalize('NFC').trim().toLowerCase().replace(/[০-৯]/g,digit=>String('০১২৩৪৫৬৭৮৯'.indexOf(digit))).replace(/,/g,''); const days=Number(q.match(/(?:last|past|গত)\s*(\d+)\s*(?:days?|দিন)/)?.[1]||0); const status=/unpaid|অপরিশোধিত/.test(q)?'Unpaid':/partial|আংশিক/.test(q)?'Partial':/\bpaid\b|পরিশোধিত/.test(q)?'Paid':''; const due=/\bdue\b|outstanding|বকে(?:য়|য়|য)া/.test(q); const amount=q.match(/(?:over|above|more than)\s*(?:৳|bdt\s*)?(\d+(?:\.\d+)?)/)?.[1]??q.match(/(\d+(?:\.\d+)?)\s*(?:টাকা(?:র)?\s*)?বেশি/)?.[1]; const bill=q.match(/\bsal-\d+\b/)?.[0]; if(!q)return null; const account=!days&&!status&&!due&&!bill&&amount===undefined?q:''; if(days>366||(!due&&amount!==undefined))return null; return {days,status,due,bill,account,minimum:amount===undefined?null:Math.round(Number(amount)*100)}; } const assistantDialog=el('sales-assistant'); el('sales-ask-example').addEventListener('click',()=>{ const question=el('sales-question'); question.value=el('sales-ask-example').textContent; question.focus(); }); let askCustomers=false; let fillCustomer=false; let addBillItems=false; function openSearchAssistant(forCustomers,fill=false,addItems=false){ addBillItems=addItems; clearBillItemPreview(); askCustomers=forCustomers; fillCustomer=fill; const question=el('sales-question'); const example=addItems?'৩ পিস SS LED Pipe আর ২ পিস Power Star Drum':fill?'ব্যবসার নাম আল ইকরাম টাইলস, মালিক হাসান, ঠিকানা কুমিল্লা':forCustomers?'৫,০০০ টাকার বেশি বকেয়া কাস্টমার':'গত ৭ দিনের বকেয়া বিল'; el(addItems?'sales-editor-page':forCustomers?'customers-view':'sales-view').append(assistantDialog); el('sales-assistant-title').textContent=addItems?'AI Add · Sales Bill':fill?'AI Fill · Create Customer':forCustomers?'Ask AI · Customers':'Ask AI · Sales Bills'; el('sales-ask-example').textContent=example; el('sales-ask-form').querySelector('button[type=submit]').textContent=addItems?'Review items':fill?'Fill form':forCustomers?'Find customers':'Find bills'; question.value='';question.placeholder=example; el('sales-ask-status').textContent=''; assistantDialog.showModal(); } el('sales-ask').addEventListener('click',()=>openSearchAssistant(false)); el('customer-ask').addEventListener('click',()=>openSearchAssistant(true)); el('customer-ai-fill').addEventListener('click',()=>openSearchAssistant(true,true)); function applyCustomerDraft(question){ const fields=el('customer-form').elements; const labels={business:'ব্যবসার নাম|business name',owner:'মালিকের নাম|মালিক|proprietor(?: name)?|owner(?: name)?',name:'নাম|name',address:'ঠিকানা|address',phone:'ফোন(?: নম্বর)?|মোবাইল(?: নম্বর)?|phone|mobile',email:'ইমেইল|ই-মেইল|email',openingBalance:'ওপেনিং ব্যালান্স|opening balance'}; const pattern=new RegExp('(?:^|[,;।\\n]\\s*|\\s+)(?:'+Object.entries(labels).map(([key,value])=>'(?<'+key+'>'+value+')').join('|')+')(?=\\s|:|$)\\s*:?\\s*','giu'); const matches=[...question.matchAll(pattern)]; const draft={}; matches.forEach((match,index)=>{ const key=Object.keys(match.groups).find(key=>match.groups[key]); const value=question.slice(match.index+match[0].length,matches[index+1]?.index??question.length).trim().replace(/[,;।]+$/,'').trim(); if(value)draft[key]=value; }); if(draft.business||draft.owner){ fields.type.value='business'; fields.type[1].dispatchEvent(new Event('change',{bubbles:true})); } const digits=value=>value.replace(/[০-৯]/g,digit=>String('০১২৩৪৫৬৭৮৯'.indexOf(digit))); if(draft.phone)draft.phone=digits(draft.phone).replace(/[\s()-]/g,''); if(draft.openingBalance){ const amount=digits(draft.openingBalance).replace(/[,৳\s]/g,'').replace(/টাকা$|bdt$/i,''); draft.openingBalance=/^-?\d+(?:\.\d{1,2})?$/.test(amount)?amount:''; } draft.name=draft.business||draft.name; let filled=0; for(const key of ['name','owner','address','phone','email','openingBalance']){ if(draft[key]&&!fields[key].value){fields[key].value=draft[key];filled++;} } return filled; } el('sales-ask-form').addEventListener('submit',event=>{ event.preventDefault(); const question=el('sales-question').value.trim(); if(addBillItems){previewBillItems(question);return;} if(fillCustomer){ if(!applyCustomerDraft(question)){ el('sales-ask-status').textContent='No empty fields could be filled. Include labels such as Name, Phone or Address.'; return; } assistantDialog.close(); el('customer-created').textContent='Review the filled fields before saving.'; el('customer-created').hidden=false; return; } if(askCustomers){ const query=question.normalize('NFC').replace(/[০-৯]/g,digit=>String('০১২৩৪৫৬৭৮৯'.indexOf(digit))).replace(/,/g,''); const due=/বকে(?:য়|য়|য)া|\bdue\b|outstanding/.test(query.toLowerCase()); const amount=query.match(/(\d+(?:\.\d+)?)\s*(?:টাকা(?:র)?\s*)?বেশি/)?.[1]??query.match(/(?:over|above|more than)\s*(?:৳|bdt\s*)?(\d+(?:\.\d+)?)/i)?.[1]; customerDueFilter=due?Math.round(Number(amount??0)*100):null; el('customer-search').value=due?question:question.replace(/^(?:find|show|search)\s+(?:customers?\s+)?/i,''); customerPage=1;renderCustomers();assistantDialog.close();return; } const filter=parseSalesQuestion(question); if(!filter){el('sales-ask-status').textContent='Try “গত ৭ দিনের ৫,০০০ টাকার বেশি বকেয়া বিল” or “unpaid bills in the last 7 days”.';return;} salesAI=filter;salesPage=1;el('sales-search').value=''; el('sales-ai-filter').hidden=false;el('sales-ai-filter').querySelector('span').textContent=question; renderSales();assistantDialog.close(); }); el('sales-clear-ai').addEventListener('click',()=>{salesAI=null;salesPage=1;el('sales-ai-filter').hidden=true;renderSales();}); let recognition; assistantDialog.addEventListener('close',()=>recognition?.abort()); el('sales-voice').addEventListener('click',()=>{ let speechWindow=window; try{if(window.parent.document)speechWindow=window.parent;}catch{} const SpeechRecognition=speechWindow.SpeechRecognition||speechWindow.webkitSpeechRecognition; const status=el('sales-ask-status'); if(!SpeechRecognition){ status.textContent='Use the microphone on your phone keyboard to dictate, or type your request.'; el('sales-question').focus(); return; } if(recognition)return; recognition=new SpeechRecognition(); recognition.lang=el('sales-voice-language').value; recognition.onresult=event=>{if(addBillItems)clearBillItemPreview();el('sales-question').value=event.results[0][0].transcript;status.textContent='Review the text and press Find.';}; recognition.onerror=()=>{if(assistantDialog.open)status.textContent='Voice unavailable. Open the HTML in a browser tab and allow microphone access, or type your request.';}; recognition.onend=()=>{recognition=null;}; try{el('sales-question').blur();recognition.start();status.textContent='Listening…';}catch{recognition=null;status.textContent='Could not start the microphone.';} }); let billDraft=[]; function clearBillItemPreview(){ billDraft=[]; el('bill-ai-preview').replaceChildren(); el('bill-ai-preview').hidden=true; el('bill-ai-confirm').hidden=true; } function parseBillItems(question){ const normalized=question.normalize('NFC').replace(/[০-৯]/g,digit=>String('০১২৩৪৫৬৭৮৯'.indexOf(digit))); return normalized.split(/[,;।\n]|\s+(?:আর|এবং|and)\s+/i).map(part=>{ const text=part.trim().replace(/\s+(?:যোগ করো|যোগ করুন|add)$/i,'').replace(/^add\s+/i,''); const match=text.match(/^(\d+(?:\.\d{1,2})?)\s+(?:(?:পিস|টি|pcs?|pieces?)\s+)?(.+)$/i); const query=match?.[2].trim().toLowerCase()??''; const quantity=Number(match?.[1]??0); const names=Object.keys(itemPrices); const exact=names.find(name=>name.toLowerCase()===query); return {text,quantity,matches:!query||quantity<=0?[]:exact?[exact]:names.filter(name=>name.toLowerCase().includes(query))}; }).filter(line=>line.text); } function previewBillItems(question){ clearBillItemPreview(); const lines=parseBillItems(question); const missing=lines.filter(line=>!line.matches.length); if(!lines.length||missing.length){ el('sales-ask-status').textContent=missing.length?'Check item name and quantity: '+missing.map(line=>line.text).join('; '):'Enter an item and quantity.'; return; } const panel=el('bill-ai-preview'); billDraft=lines.map(line=>{ const row=document.createElement('label'), select=document.createElement('select'), detail=document.createElement('small'); row.append(line.quantity+' pc',select,detail); if(line.matches.length>1)select.add(new Option('Choose matching item','')); for(const name of line.matches)select.add(new Option(name,name)); const update=()=>{detail.textContent=select.value?'Unit price '+formatDue(itemPrices[select.value]*100)+' · Demo stock '+availableBillStock(select.value)+' pc':'';}; select.addEventListener('change',update);update(); panel.append(row); return {quantity:line.quantity,select}; }); panel.hidden=false;el('bill-ai-confirm').hidden=false; el('sales-ask-status').textContent='Review the matches before adding them.'; } el('bill-ai-add').addEventListener('click',()=>openSearchAssistant(false,false,true)); el('sales-question').addEventListener('input',()=>{if(addBillItems)clearBillItemPreview();}); el('bill-ai-confirm').addEventListener('click',()=>{ if(!billDraft.length)return; if(billDraft.some(line=>!line.select.value)){ el('sales-ask-status').textContent='Choose an item for each line.'; return; } const totals=new Map(); for(const item of readBillLines())totals.set(item.name,(totals.get(item.name)||0)+item.qty); for(const line of billDraft)totals.set(line.select.value,(totals.get(line.select.value)||0)+line.quantity); for(const line of billDraft){ const name=line.select.value; if(totals.get(name)>availableBillStock(name)+0.000001){ el('sales-ask-status').textContent='Quantity exceeds demo stock for '+name+'.'; return; } } for(const line of billDraft)addBillLine(line.select.value,undefined,itemPrices[line.select.value],line.quantity); updateBillItemInfo(billDraft.at(-1).select.value); recalculateBill();assistantDialog.close(); }); function getBillIssues(lines,stock){ const groups=new Map(); lines.forEach((line,index)=>{ if(!groups.has(line.name))groups.set(line.name,{qty:0,indices:[]}); const group=groups.get(line.name); group.qty+=line.qty;group.indices.push(index); }); const issues=[]; for(const [name,{qty,indices}] of groups){ const total=Number(qty.toFixed(2)); if(indices.length>1)issues.push({text:name+' appears on '+indices.length+' lines · Total qty '+total,indices}); if(Object.hasOwn(stock,name)&&qty>stock[name]+0.000001)issues.push({text:name+' · Requested '+total+' · Available '+stock[name],indices}); } return issues; } const billCheckDialog=el('bill-check-dialog'); el('bill-check').addEventListener('click',()=>{ recalculateBill(); const lines=readBillLines(); const fields=salesEntry.elements; const issues=getBillIssues(lines,selectedWarehouseStock()); const results=el('bill-check-results'); results.replaceChildren(...issues.map(issue=>{ const row=document.createElement('li'); row.append(issue.text); const links=document.createElement('div'); for(const index of issue.indices){ const button=document.createElement('button'); button.type='button';button.textContent='Line '+(index+1); button.addEventListener('click',()=>{ const input=el('bill-rows').rows[index]?.querySelector('[data-field=qty]'); billCheckDialog.close(); if(input){input.focus({preventScroll:true});input.scrollIntoView({block:'center',inline:'nearest'});} }); links.append(button); } row.append(links);return row; })); if(!issues.length){ const row=document.createElement('li'); row.textContent=lines.length?'No duplicate items or demo stock shortages found.':'No items to check.'; results.append(row); } const account=fields.account.value.trim(); const customer=customers.find(customer=>customer.name===account); const newDue=Math.max(0,Math.round(Number(fields.amount.value)*100)-Math.round(Number(fields.receipt.value)*100)); const credit=el('bill-check-credit'); credit.textContent=customer?'Current due '+formatDue(customer.due)+' · This bill '+formatDue(newDue)+' · Projected due '+formatDue(customer.due+newDue): account==='Cash'?'Cash sale · This bill balance '+formatDue(newDue):'Customer balance unavailable · This bill due '+formatDue(newDue); billCheckDialog.showModal(); }); document.addEventListener('keydown',event=>{ if(event.defaultPrevented||event.isComposing||event.repeat||el('sales-editor-page').hidden||document.querySelector('dialog[open]'))return; const key=event.key.toLowerCase(); if((event.ctrlKey||event.metaKey)&&!event.altKey&&key==='s'){ event.preventDefault(); const button=salesEntry.querySelector(event.shiftKey?'[value=continue]':'[value=save]'); if(button&&!button.hidden)salesEntry.requestSubmit(button); return; } if(!event.altKey||event.ctrlKey||event.metaKey||event.shiftKey)return; const target={i:'bill-item',a:'bill-ai-add',c:'bill-check'}[key]; if(!target)return; event.preventDefault(); if(key==='i')el(target).focus(); else el(target).click(); }); const billArrowFields='input:not([type=hidden]), select, textarea, #bill-cost-open'; let lastBillItemInput; function billArrowTargets(container){ return Array.from(container.querySelectorAll(billArrowFields)).filter(field=>!field.disabled&&field.getClientRects().length); } function nearestBillField(origin,candidates,dx,dy){ const rect=origin.getBoundingClientRect(); const x=rect.left+rect.width/2,y=rect.top+rect.height/2; let best,score=Infinity; for(const field of candidates){ const box=field.getBoundingClientRect(); const horizontal=box.left+box.width/2-x,vertical=box.top+box.height/2-y; const forward=horizontal*dx+vertical*dy; const offset=Math.abs(dx?vertical:horizontal); if(forward<=2 ||(dx&&offset>Math.max(rect.height,box.height)/2))continue; const weight=forward+offset*3; if(weight<score){best=field;score=weight;} } return best; } function navigateBillFields(event){ const field=event.target; if(event.defaultPrevented||event.isComposing||event.ctrlKey||event.metaKey||event.altKey||event.shiftKey||!field.matches(billArrowFields)||field.getAttribute('aria-expanded')==='true')return; const direction={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[event.key]; if(!direction)return; const [dx,dy]=direction; const form=event.currentTarget; const rows=el('bill-rows'), totals=salesEntry.querySelector('.bill-totals'); const row=field.closest('#bill-rows tr'); let next; if(row){ if(dx){ const fields=billArrowTargets(row); next=fields[fields.indexOf(field)+dx]; }else{ const cell=field.closest('td'); const adjacent=rows.rows[row.sectionRowIndex+dy]; next=adjacent?.cells[cell.cellIndex]?.querySelector(billArrowFields); if(next&&(!next.getClientRects().length||next.disabled))next=undefined; } if(!next && ((dy>0&&!Array.from(rows.rows).slice(row.sectionRowIndex+1).some(other=>other.dataset.item)) || (dx>0&&row===rows.lastElementChild))){ lastBillItemInput=field; next=billArrowTargets(totals)[0]; } }else if(field===billArrowTargets(totals)[0]&&dy<0&&lastBillItemInput?.isConnected&&lastBillItemInput.getClientRects().length){ next=lastBillItemInput; } if(!next){ const fields=billArrowTargets(form); next=nearestBillField(field,fields,dx,dy); } if(!next)return; event.preventDefault(); next.focus({preventScroll:true}); if(next instanceof HTMLInputElement && next.matches(billNumericInput))next.select(); next.scrollIntoView({block:'nearest',inline:'nearest'}); } for(const form of [salesEntry,mobileLineForm,costForm])form.addEventListener('keydown',navigateBillFields); </script></body></html>