<commit_before>// @flow
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import Datastore from 'nedb';



export default class Billing extends Component {
	constructor(props) {
		super(props);
		this.state= {
			addAnotherBill : []
		};
	}

	_handleFormData = (e) => {
		const { addAnotherBill } = this.state;
		const formData = {};
		const tempBill = addAnotherBill;
		for (const field in this.refs) {
			formData[field] = this.refs[field].value;
		}

		const timeStamp = Date.now();

		const tempData = Object.assign({}, {
			productID : formData.productID,
			productDesc: formData.productDesc,
			quantity: formData.quantity,
			amount: formData.amount,
			unitPrice: formData.unitPrice
		});
		tempBill.push(tempData)

		const finalDataToSubmit = Object.assign({}, {
			customerName: formData.customerName,
			phoneNumber: formData.phoneNumber,
			address: formData.address,
			timeStamp,
			productDetails: tempBill
		});
		console.log(this.props)
		this.props.db.insert(finalDataToSubmit, function (err, data) {   // Callback is optional
			console.log("Data Inserted", data, err);
		});
	}

	_addAnotherBill = (e) => {
		const { state, refs } = this;
		const { addAnotherBill } = state;
		const tempBill = addAnotherBill;		
		const formData = {};
		for (const field in refs) {
			formData[field] = refs[field].value;
		}
		const tempData = Object.assign({}, {
			productID : formData.productID,
			productDesc: formData.productDesc,
			quantity: formData.quantity,
			amount: formData.amount,
			unitPrice: formData.unitPrice,
		})
		tempBill.push(tempData);
		this.setState({
			addAnotherBill: tempBill		
		});
		refs.productID.value = '';
		refs.productDesc.value = '';
		refs.quantity.value = '';
		refs.amount.value = '';
		refs.unitPrice.value = '';
		refs.attentionTo.value = '';
	}

	calculateAmount = (e) => {
		this.refs.amount.value = this.refs.unitPrice.value * this.refs.quantity.value;
	}

	render() {
		const { addAnotherBill } = this.state;
		console.log(addAnotherBill)
		return (
			<div className="pane padded-bottom-more entry-form"><commit_msg>feat: added table for billing<commit_after>// @flow
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import Datastore from 'nedb';



export default class Billing extends Component {
	constructor(props) {
		super(props);
		this.state= {
			addAnotherBill : []
		};
	}

	_handleFormData = (e) => {
		const { addAnotherBill } = this.state;
		const formData = {};
		const tempBill = addAnotherBill;
		for (const field in this.refs) {
			formData[field] = this.refs[field].value;
		}

		const timeStamp = Date.now();

		const tempData = Object.assign({}, {
			productID : formData.productID,
			productDesc: formData.productDesc,
			quantity: formData.quantity,
			amount: formData.amount,
			unitPrice: formData.unitPrice
		});
		tempBill.push(tempData)

		const finalDataToSubmit = Object.assign({}, {
			customerName: formData.customerName,
			phoneNumber: formData.phoneNumber,
			address: formData.address,
			timeStamp,
			productDetails: tempBill
		});
		console.log(this.props)
		this.props.db.insert(finalDataToSubmit, function (err, data) {   // Callback is optional
			console.log("Data Inserted", data, err);
		});
	}

	_addAnotherBill = (e) => {
		const { state, refs } = this;
		const { addAnotherBill } = state;
		const tempBill = addAnotherBill;		
		const formData = {};
		for (const field in refs) {
			formData[field] = refs[field].value;
		}
		const tempData = Object.assign({}, {
			productID : formData.productID,
			productDesc: formData.productDesc,
			quantity: formData.quantity,
			amount: formData.amount,
			unitPrice: formData.unitPrice,
		})
		tempBill.push(tempData);
		this.setState({
			addAnotherBill: tempBill		
		});
		refs.productID.value = '';
		refs.productDesc.value = '';
		refs.quantity.value = '';
		refs.amount.value = '';
		refs.unitPrice.value = '';
		refs.attentionTo.value = '';
	}

	calculateAmount = (e) => {
		this.refs.amount.value = this.refs.unitPrice.value * this.refs.quantity.value;
	}

	render() {
		const { addAnotherBill } = this.state;
		const showTable = addAnotherBill.length > 0;

		const renderTable = addAnotherBill.map((l, index) => {

      console.log(l);

      return (
        <tr key={index}>
          <td>{index + 1}</td>
          <td>{l.productName}</td>
          <td>{l.quantity}</td>
          <td>{l.price}</td>
				</tr>
      );
    });

		return (
			<div className="pane padded-bottom-more entry-form">
				{showTable && (
					<table className="table-striped padded-bottom-more">
						<thead>
							<tr>
								<th>SlNo</th>
								<th>Product ID</th>
								<th>Quantity</th>
								<th>Price</th>
							</tr>
						</thead>
						<tbody>
							{renderTable}
						</tbody>
					</table>
				)}
{'fraction_non_alphanumeric': 0.14442602569415666, 'fraction_numerical': 0.0004144218814753419, 'mean_word_length': 3.2230971128608923, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5185725', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1598, 'n_words': 321}