# Daily Close S-File API

## Endpoints

**Auth**: `X-API-Key` header (validated against store API key)

---

### POST `/api/:typeNum/daily-close` — Submit parsed S-File data

**Content-Type**: `application/json`

**Request body** (key fields shown — 118 data columns total in `drsDailySFileData`):

```json
{
  "closingDate": "2026-02-17",
  "grossSalesCost": 831.43,
  "grossSalesRetail": 1779.40,
  "grossSalesNumber": 42,
  "netSalesCost": 781.43,
  "netSalesRetail": 1659.40,
  "cashTendered": 500.00,
  "mastercardActual": 400.00,
  "visaActual": 450.00,
  "buysCost": 300.00,
  "taxCollected": 120.00
  // ... all other drsDailySFileData fields optional
}
```

**Response (201)**:

```json
{
  "success": true,
  "reportId": 123,
  "closingDate": "2026-02-17",
  "fieldsReceived": 45,
  "fieldsParsed": 42,
  "fieldsNulled": 3,
  "warnings": ["cashVariance: non-numeric value 'N/A'"]
}
```

---

### POST `/api/:typeNum/daily-close/upload` — Upload raw S-File.txt

**Content-Type**: `multipart/form-data`, field name `sfile`

**Supported MIME**: `text/plain`, `application/octet-stream`, `text/csv`

**Storage**: `uploads/{typeNum}/s-files/{date}_sfile.txt`

**Response (201)**:

```json
{
  "success": true,
  "filename": "2026-02-17_sfile.txt",
  "path": "uploads/pc00/s-files/2026-02-17_sfile.txt",
  "size": 4096
}
```

---

## `drsDailySFileData` Table Schema

**123 columns total** — 25 `INT(11)` fields, 94 `DECIMAL(12,2)` fields, 1 `DATE`, and 3 metadata columns (`id`, `createdAt`, `updatedAt`).

**Database**: Store DB (`kiosk_{typeNum}`)

---

### Primary Key & Metadata

| # | Column | Type |
|---|--------|------|
| 1 | `id` | `INT(11)` PK AUTO_INCREMENT |
| 2 | `createdAt` | `DATETIME` DEFAULT CURRENT_TIMESTAMP |
| 3 | `updatedAt` | `DATETIME` DEFAULT CURRENT_TIMESTAMP ON UPDATE |
| 4 | `closingDate` | `DATE` NOT NULL UNIQUE |

### Gross Sales

| # | Column | Type |
|---|--------|------|
| 5 | `grossSalesCost` | `DECIMAL(12,2)` |
| 6 | `grossSalesRetail` | `DECIMAL(12,2)` |
| 7 | `grossSalesNumber` | `INT(11)` |
| 8 | `grossSalesGM` | `DECIMAL(12,2)` |

### Returns

| # | Column | Type |
|---|--------|------|
| 9 | `returnsCost` | `DECIMAL(12,2)` |
| 10 | `returnsRetail` | `DECIMAL(12,2)` |
| 11 | `returnsNumber` | `INT(11)` |
| 12 | `returnsGM` | `DECIMAL(12,2)` |

### Net Sales / Continuing Fee

| # | Column | Type |
|---|--------|------|
| 13 | `netSalesContinuiingForFee` | `DECIMAL(12,2)` |
| 14 | `continuingFeePercentage` | `DECIMAL(12,2)` |
| 15 | `continuingFee` | `DECIMAL(12,2)` |
| 16 | `netSalesCost` | `DECIMAL(12,2)` |
| 17 | `netSalesRetail` | `DECIMAL(12,2)` |
| 18 | `netSalesGM` | `DECIMAL(12,2)` |
| 19 | `salesCount` | `INT(11)` |

### Buys

| # | Column | Type |
|---|--------|------|
| 20 | `buysCost` | `DECIMAL(12,2)` |
| 21 | `buysRetail` | `DECIMAL(12,2)` |
| 22 | `buysNumber` | `INT(11)` |
| 23 | `buysGM` | `DECIMAL(12,2)` |
| 24 | `buysCount` | `INT(11)` |
| 25 | `averageRetail` | `DECIMAL(12,2)` |

### Cash

| # | Column | Type |
|---|--------|------|
| 26 | `cashCount` | `INT(11)` |
| 27 | `cashExpected` | `DECIMAL(12,2)` |
| 28 | `cashActual` | `DECIMAL(12,2)` |
| 29 | `cashVariance` | `DECIMAL(12,2)` |

### Mastercard

| # | Column | Type |
|---|--------|------|
| 30 | `mastercardCount` | `INT(11)` |
| 31 | `mastercardExpected` | `DECIMAL(12,2)` |
| 32 | `mastercardActual` | `DECIMAL(12,2)` |
| 33 | `mastercardVariance` | `DECIMAL(12,2)` |

### Visa

| # | Column | Type |
|---|--------|------|
| 34 | `visaCount` | `INT(11)` |
| 35 | `visaExpected` | `DECIMAL(12,2)` |
| 36 | `visaActual` | `DECIMAL(12,2)` |
| 37 | `visaVariance` | `DECIMAL(12,2)` |

### Amex

| # | Column | Type |
|---|--------|------|
| 38 | `amexCount` | `INT(11)` |
| 39 | `amexExpected` | `DECIMAL(12,2)` |
| 40 | `amexActual` | `DECIMAL(12,2)` |
| 41 | `amexVariance` | `DECIMAL(12,2)` |

### Discover

| # | Column | Type |
|---|--------|------|
| 42 | `discoverCount` | `INT(11)` |
| 43 | `discoverExpected` | `DECIMAL(12,2)` |
| 44 | `discoverActual` | `DECIMAL(12,2)` |
| 45 | `discoverVariance` | `DECIMAL(12,2)` |

### Debit Card

| # | Column | Type |
|---|--------|------|
| 46 | `debitcardCount` | `INT(11)` |
| 47 | `debitcardExpected` | `DECIMAL(12,2)` |
| 48 | `debitcardActual` | `DECIMAL(12,2)` |
| 49 | `debitcardVariance` | `DECIMAL(12,2)` |

### Gift Card

| # | Column | Type |
|---|--------|------|
| 50 | `giftcardCount` | `INT(11)` |
| 51 | `giftcardExpected` | `DECIMAL(12,2)` |
| 52 | `giftcardActual` | `DECIMAL(12,2)` |
| 53 | `giftcardVariance` | `DECIMAL(12,2)` |

### Store Credit

| # | Column | Type |
|---|--------|------|
| 54 | `storeCreditCount` | `INT(11)` |
| 55 | `storeCreditExpected` | `DECIMAL(12,2)` |
| 56 | `storeCreditActual` | `DECIMAL(12,2)` |
| 57 | `storeCreditVariance` | `DECIMAL(12,2)` |

### Coupons

| # | Column | Type |
|---|--------|------|
| 58 | `couponsCount` | `INT(11)` |
| 59 | `couponsExpected` | `DECIMAL(12,2)` |
| 60 | `couponsActual` | `DECIMAL(12,2)` |
| 61 | `couponsVariance` | `DECIMAL(12,2)` |

### Cash Operations

| # | Column | Type |
|---|--------|------|
| 62 | `openingCash` | `DECIMAL(12,2)` |
| 63 | `checksIssued` | `DECIMAL(12,2)` |
| 64 | `cashTendered` | `DECIMAL(12,2)` |
| 65 | `storeCreditsIssued` | `DECIMAL(12,2)` |
| 66 | `cashPaidIn` | `DECIMAL(12,2)` |
| 67 | `cashPaidOut` | `DECIMAL(12,2)` |
| 68 | `freightCollected` | `DECIMAL(12,2)` |
| 69 | `cashOverShort` | `DECIMAL(12,2)` |

### Buy Payments

| # | Column | Type |
|---|--------|------|
| 70 | `buyPaidCash` | `DECIMAL(12,2)` |
| 71 | `buyPaidCheck` | `DECIMAL(12,2)` |
| 72 | `buyPaidStoreCredit` | `DECIMAL(12,2)` |
| 73 | `nextDayOpen` | `DECIMAL(12,2)` |
| 74 | `buyPaidOffsite` | `DECIMAL(12,2)` |
| 75 | `buyPaidTradeIns` | `DECIMAL(12,2)` |
| 76 | `checkDeposit` | `DECIMAL(12,2)` |
| 77 | `buyPaidTotal` | `DECIMAL(12,2)` |

### Card Issuance & AR

| # | Column | Type |
|---|--------|------|
| 78 | `giftCardsIssued` | `DECIMAL(12,2)` |
| 79 | `newARCharges` | `DECIMAL(12,2)` |

### Deposits

| # | Column | Type |
|---|--------|------|
| 80 | `depositsReceived` | `DECIMAL(12,2)` |
| 81 | `depositsUsed` | `DECIMAL(12,2)` |

### Checks

| # | Column | Type |
|---|--------|------|
| 82 | `checksCount` | `INT(11)` |
| 83 | `checksExpected` | `DECIMAL(12,2)` |
| 84 | `checksActual` | `DECIMAL(12,2)` |
| 85 | `checksVariance` | `DECIMAL(12,2)` |

### Other Cards

| # | Column | Type |
|---|--------|------|
| 86 | `otherCardsCount` | `INT(11)` |
| 87 | `otherCardsExpected` | `DECIMAL(12,2)` |
| 88 | `otherCardsActual` | `DECIMAL(12,2)` |
| 89 | `otherCardsVariance` | `DECIMAL(12,2)` |

### House Account

| # | Column | Type |
|---|--------|------|
| 90 | `houseAcctCount` | `INT(11)` |
| 91 | `houseAcctExpected` | `DECIMAL(12,2)` |
| 92 | `houseAcctActual` | `DECIMAL(12,2)` |
| 93 | `houseAcctVariance` | `DECIMAL(12,2)` |

### PayPal

| # | Column | Type |
|---|--------|------|
| 94 | `payPalCount` | `INT(11)` |
| 95 | `payPalExpected` | `DECIMAL(12,2)` |
| 96 | `payPalActual` | `DECIMAL(12,2)` |
| 97 | `payPalVariance` | `DECIMAL(12,2)` |

### Internet

| # | Column | Type |
|---|--------|------|
| 98 | `internetCount` | `INT(11)` |
| 99 | `internetExpected` | `DECIMAL(12,2)` |
| 100 | `internetActual` | `DECIMAL(12,2)` |
| 101 | `internetVariance` | `DECIMAL(12,2)` |

### New Inventory

| # | Column | Type |
|---|--------|------|
| 102 | `newSales` | `DECIMAL(12,2)` |
| 103 | `newReturns` | `DECIMAL(12,2)` |
| 104 | `newNetSales` | `DECIMAL(12,2)` |
| 105 | `newCost` | `DECIMAL(12,2)` |

### Used Inventory

| # | Column | Type |
|---|--------|------|
| 106 | `usedSales` | `DECIMAL(12,2)` |
| 107 | `usedReturns` | `DECIMAL(12,2)` |
| 108 | `usedNetSales` | `DECIMAL(12,2)` |
| 109 | `usedCost` | `DECIMAL(12,2)` |

### Total Tender

| # | Column | Type |
|---|--------|------|
| 110 | `totalTenderExpected` | `DECIMAL(12,2)` |
| 111 | `totalTenderActual` | `DECIMAL(12,2)` |
| 112 | `totalTenderVariance` | `DECIMAL(12,2)` |

### Trade & Outstanding Credits

| # | Column | Type |
|---|--------|------|
| 113 | `tradeCount` | `INT(11)` |
| 114 | `tradeAmount` | `DECIMAL(12,2)` |
| 115 | `storeCreditsOutstandingCount` | `INT(11)` |
| 116 | `storeCreditsOutstandingAmount` | `DECIMAL(12,2)` |

### Tax & Period Totals

| # | Column | Type |
|---|--------|------|
| 117 | `taxCollected` | `DECIMAL(12,2)` |
| 118 | `newWTD` | `DECIMAL(12,2)` |
| 119 | `usedWTD` | `DECIMAL(12,2)` |
| 120 | `newMTD` | `DECIMAL(12,2)` |
| 121 | `usedMTD` | `DECIMAL(12,2)` |
| 122 | `newYTD` | `DECIMAL(12,2)` |
| 123 | `usedYTD` | `DECIMAL(12,2)` |
