const http = require('http');

// Test creating a credit transaction
const transactionData = JSON.stringify({
    transaction_date: "2026-01-28",
    payment_type: "Credit",
    customer_name: "Test Customer",
    items: [
        {
            sku_id: 1,
            quantity: 2,
            unit_price: 150
        }
    ],
    discount_percentage: 0,
    discount_amount: 0,
    amount_paid: 100  // Partial payment
});

const options = {
    hostname: 'localhost',
    port: 3000,
    path: '/api/transactions',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Content-Length': Buffer.byteLength(transactionData)
    }
};

const req = http.request(options, (res) => {
    let data = '';
    res.on('data', chunk => data += chunk);
    res.on('end', () => {
        console.log('Transaction response:', data);
        
        // Check customer credit after transaction
        http.get('http://localhost:3000/api/customers', (res) => {
            let data = '';
            res.on('data', chunk => data += chunk);
            res.on('end', () => {
                console.log('Customers after transaction:', data);
            });
        });
    });
});

req.on('error', (error) => {
    console.error('Error:', error);
});

req.write(transactionData);
req.end();