# Sale Calculator Strategy 

Calculate complex sales totals with taxes, discounts, and wholesale pricing.

## Install
```bash
npm install sale-calculator-strategy
```

Basic Usage
javascript
```bash
const { init, calcTotal } = require('sale-calculator-strategy');

// 1. Setup your products
init({
  products: {
    101: { 
      original_public_price: 20000, // $200.00 MXN
      quantity: 1 
    }
  },
  taxes: {
    vat: { rate: 16, general: true }
  }
});

// 2. Create a sale
const myOrder = {
  receipt_type_key: 'invoice',
  dwSaleProducts: [{
    product_id: 101,
    quantity: 5
  }]
};

// 3. Get total
const total = calcTotal(myOrder);
console.log(`Total: $${total / 100}`); // $1000 * 1.16 = $1160.00
```

Key Features
Bulk Pricing
```bash
init({
  wholesale_levels: {
    101: [{
      quantity_min: 10,
      quantity_max: 20,
      price: 15000 // $150.00 per unit for 10-20 units
    }]
  }
});
```

Apply Discounts
javascript
```bash
const saleWithDeal = {
  ...myOrder,
  dwSaleDeals: [{ amount: 5000 }] // $50.00 discount
};

calcTotal(saleWithDeal); // Applies discount proportionally
```

Custom Prices
javascript
```bash
dwSaleProducts: [{
  product_id: 101,
  quantity: 2,
  custom_price: 18000 // Override price to $180.00
}]
```
Error Handling
javascript
```bash
try {
  calcTotal({ invalid: 'data' });
} catch (error) {
  console.error('Failed:', error.message);
  // Example error: "Invalid sale structure - Missing dwSaleProducts"
}}
```

Version: 1.0.2

License: MIT © Softseti