Skip to content

Commit

Permalink
Merge pull request #118 from Vincent440/mike32
Browse files Browse the repository at this point in the history
Mike32
  • Loading branch information
sialbul committed Jul 30, 2019
2 parents 9b974b1 + d6c8b0a commit c0b87f8
Show file tree
Hide file tree
Showing 10 changed files with 412 additions and 285 deletions.
4 changes: 4 additions & 0 deletions client/src/pages/arrivals/arrivals.js
Expand Up @@ -40,6 +40,10 @@ class Arrivals extends Component {
.catch(err => console.log(err));
}

handleRoomAssign = () => {

}

componentDidMount() {
this.makeAxiosCall();
}
Expand Down
40 changes: 28 additions & 12 deletions client/src/pages/billing/billing.js
Expand Up @@ -17,11 +17,13 @@ class Billing extends Component {
roomNumber: "",
taxRates: {},
checkOutSuccess: false,
checked_out: false,
res_room_id: "",
invoice_id: "",
stayOver: false,
dueOut: false,
checkedOut: false
checkedOut: false,
room_num: ""
};

makeAxiosCall = () => {
Expand All @@ -39,10 +41,14 @@ class Billing extends Component {
.catch(err => console.log(err));
}

handleCheckOut = (id, room_id) => {
this.setState({ res_room_id: id });
api.updateRoomCheckout(id, room_id)
.then(res => this.setState({ checkOutSuccess: true, invoice_id: res[1].data }))
handleCheckOut = (id, room_num) => {
this.setState({ res_room_id: id, checkOutSuccess: true, room_num: room_num });
}

handleLinkInvoice = (id, room_num) => {
this.setState({ res_room_id: id, room_num: room_num });
api.getInvoiceId(id)
.then(res => this.setState({ checkOutSuccess: true, invoice_id: res[0].invoice_id, checked_out: true }))
.catch(err => console.log(err));
}

Expand All @@ -52,6 +58,7 @@ class Billing extends Component {
.then(res => this.setState({ taxRates: res[0] }))
.catch(err => console.log(err));
}

handleInputChange = event => {
const { name, value } = event.target;
this.setState({
Expand All @@ -70,12 +77,21 @@ class Billing extends Component {

render() {
if (this.state.checkOutSuccess) {
localStorage.setItem('invoice_id', this.state.invoice_id);
return (
<Redirect to={{
pathname: '/cashiering/payment'
}} />
)
if (this.state.checked_out) {
return (
<Redirect to={{
pathname: '/cashiering/payment',
state: { invoice_id: this.state.invoice_id, room_num: this.state.room_num }
}} />
)
} else {
return (
<Redirect to={{
pathname: '/cashiering/payment',
state: { res_room_id: this.state.res_room_id, room_num: this.state.room_num }
}} />
)
}
}
return (
<div>
Expand Down Expand Up @@ -191,7 +207,7 @@ class Billing extends Component {
<td>{Number(Number((departure.num_days) * (departure.rate)) + Number(((departure.num_days) * (departure.rate) * this.state.taxRates.county_rate).toFixed(2)) + Number(((departure.num_days) * (departure.rate) * this.state.taxRates.city_rate).toFixed(2)) + Number(((departure.num_days) * (departure.rate) * this.state.taxRates.state_rate).toFixed(2))).toLocaleString('en-US', { style: 'currency', currency: 'USD' })}
</td>
<td>
{departure.room_num !== "Not Set" ? <button onClick={() => this.handleCheckOut(departure.res_room_id, this.state.departuresArray[i].room_num)}>Check Out</button> : "Checked Out"}
{this.state.departuresArray[i].checked_out === 0 ? <button onClick={() => this.handleCheckOut(departure.res_room_id, this.state.departuresArray[i].room_num)}>Check Out</button> : <button onClick={() => this.handleLinkInvoice(departure.res_room_id, this.state.departuresArray[i].room_num)}>Invoice</button>}
</td>
</tr>
))}
Expand Down
174 changes: 113 additions & 61 deletions client/src/pages/payment/payment.js
Expand Up @@ -5,53 +5,100 @@ import Header from "../../components/Header"
import Table from 'react-bootstrap/Table';
import api from '../../utils/api';
import { Link } from 'react-router-dom';
import moment from 'moment';

class Payment extends Component {

state = {
RoomInfo: [],
InvoiceArray: [],
invoice_id: ""
invoice_id: "",
paid: false,
res_room_id: "",
room_num: "",
taxRates: {},
creditCardChecked: true,
cashChecked: false,
payment_type: "Credit Card"
};

componentDidMount() {
let invoice_id = "";
if (localStorage && localStorage.getItem('invoice_id')) {
invoice_id = JSON.parse(localStorage.getItem('invoice_id'));
if (this.props.location.state.invoice_id) {
this.setState({ paid: true, room_num: this.props.location.state.room_num }, () => {
this.makeAxiosCall(this.props.location.state.invoice_id);
})
} else if (this.props.location.state.res_room_id) {
api.getTaxRates()
.then(res => this.setState({ taxRates: res[0] }))
.catch(err => console.log(err));
this.setState({ res_room_id: this.props.location.state.res_room_id, room_num: this.props.location.state.room_num }, () => {
api.getPreInvoice(this.state.res_room_id)
.then(res => this.setState({ InvoiceArray: res }))
.catch(err => console.log(err))
});
}
this.setState({ invoice_id: invoice_id }, () => {
api.getInvoice(this.state.invoice_id)
.then(res => this.setState({ InvoiceArray: res }))
.catch(err => console.log(err))
});
}

makeAxiosCall = (id) => {
api.getInvoice(id)
.then(res => this.setState({ InvoiceArray: res }))
.catch(err => console.log(err))
}

handleCheckbox = event => {
event.target.value === "creditCard" ? this.setState({ creditCardChecked: true, cashChecked: false, payment_type: "Credit Card" }) : this.setState({ creditCardChecked: false, cashChecked: true, payment_type: "Cash" })
}

handleSubmitPayment = event => {
event.preventDefault();
api.updateRoomCheckout(this.state.res_room_id, this.state.room_num, this.state.payment_type)
.then(res => this.setState({ paid: true, invoice_id: res[1].data }))
.catch(err => console.log(err))
.then(() => this.makeAxiosCall(this.state.invoice_id));
}

render() {
return (
<div>
<Row>
<Col xl={12}>
<Header>INVOICE</Header>
</Col>
</Row>
<div id="res">
<div id="res" style={{ paddingBottom: "10px" }}>
<div>
<Row>
<Col xl={12}>
<Header>INVOICE</Header>
</Col>
</Row>
<div id="res" style={{ paddingLeft: "15px", paddingBottom: "10px" }}>
<Row>
<Table border="1">
<tbody>
{this.state.InvoiceArray.map(invoice => (
<ul key={invoice.res_room_id}>
{this.state.InvoiceArray.map(invoice => (
<div className="p-2" key={invoice.res_room_id}>
<Table border="1" className="mb-3">
<tbody>
<tr>
<th>Room Number:</th>
<th>Name:</th>
<th>CC Number: </th>
<th>Checked In Date:</th>
<th>Check Out Date:</th>
<th>Payment Type:</th>
</tr>
<tr>
<th><strong>Room Number:</strong> {invoice.room_num}</th>
<th colspan="2"><strong>Name:</strong> {invoice.last_name}, {invoice.first_name}</th>
<th><strong>CC Number: </strong> {invoice.ccLastFour} </th>
<th><strong>Date: </strong></th>
<td>{this.state.room_num}</td>
<td>{invoice.first_name} {invoice.last_name}</td>
<td>**** **** **** {invoice.ccLastFour}</td>
<td>{moment(invoice.check_in_date).format('YYYY-MM-DD')}</td>
<td>{moment(invoice.check_out_date).format('YYYY-MM-DD')}</td>
<td>{invoice.payment_type}</td>
</tr>
</tbody>
</Table>
<Table border="1">
<tbody>
<tr>
<th><strong>Num Nights</strong></th>
<th><strong>Rate</strong></th>
<th><strong>Room Total</strong></th>
<th><strong>County Tax</strong></th>
<th><strong>City Tax</strong></th>
<th><strong>State Tax</strong></th>
<th><strong>Total Due</strong></th>
<th>Num Nights</th>
<th>Rate</th>
<th>Room Total</th>
<th>County Tax</th>
<th>City Tax</th>
<th>State Tax</th>
<th>Total Due</th>
</tr>
<tr>
<td>{invoice.num_days}</td>
Expand All @@ -61,43 +108,48 @@ class Payment extends Component {
<td>${invoice.city_tax}</td>
<td>${invoice.state_tax}</td>
<td>${((parseInt(invoice.num_days) * parseFloat(invoice.rate)) + parseFloat(invoice.county_tax) + parseFloat(invoice.city_tax) + parseFloat(invoice.state_tax)).toFixed(2)}</td>

</tr>
</ul>
))}
</tbody>
<Row style={{ margin: "10px 0px 20px" }}>
<Col xl={2}>
</Col>
<Col xl={2}>
<strong> </strong>
</Col>
<Col xl={2}>
Credit Card <input type="radio" name="myCheck" checked />
</Col>
<Col xl={2}>
Cash <input type="radio" name="myCheck" />
</tbody>
</Table>
</div>
))}
</Row>
{this.state.paid ? "" :
<div>
<Row>
<Col className="text-center">
Credit Card
<input
className="mt-4 ml-2 mr-4"
type="checkbox"
value="creditCard"
checked={this.state.creditCardChecked}
onChange={this.handleCheckbox}
/>
Cash
<input
className="mt-4 ml-2"
type="checkbox"
value="cash"
checked={this.state.cashChecked}
onChange={this.handleCheckbox}
/>
</Col>
</Row>
<Row style={{ margin: "30px 0px 20px" }}>
<Col xl={5}>
</Col>
<Col>
<Link className="btn navbar-right btn-primary" to="/cashiering/billing" type="submit">Submit Payment</Link>
<Row className="mt-4">
<Col className="text-center">
<button className="btn btn-primary" onClick={this.handleSubmitPayment}>Submit Payment</button>
</Col>
</Row>


</Table>
</div>
}
<Row className="mt-4">
<Col className="text-center">
<Link className="btn btn-primary m-3" to="/cashiering/billing">Back to Billing</Link>
</Col>
</Row>

{/* <button type="button" class="btn btn-primary" style={{ marginLeft: "350px", marginTop: "10px" }}>Post</button>
<button type="button" class="btn btn-danger" style={{ marginTop: "10px" }}>Payment</button>
<button type="button" class="btn btn-danger" style={{ marginTop: "10px" }}>Check Out</button>
<button type="button" class="btn btn-primary" style={{ marginTop: "10px", marginLeft: "5px" }}>Close</button> */}
</div>
</div>
</div>
)
}
}
Expand Down
7 changes: 1 addition & 6 deletions client/src/pages/payment/style3.css
Expand Up @@ -57,10 +57,5 @@ h2 {
border: 1px solid transparent;
width: 45%;
font-size: 18px;
padding-left: 20px;
}

#res > div > table > tbody > ul {
padding-left: 5px;
padding-right: 5px;
padding-left: 15px;
}
22 changes: 20 additions & 2 deletions client/src/utils/api.js
Expand Up @@ -152,15 +152,24 @@ export default {
console.log(error);
});
},
updateRoomCheckout: (id, room_num) => {
updateRoomCheckout: (id, room_num, payment_type) => {
return axios.all([
axios.put('/api/hw/checkoutRoom/' + id + '/' + room_num),
axios.post('/api/hw/invoice', { id: id })
axios.post('/api/hw/invoice', { id: id, payment_type: payment_type })
])
.then(axios.spread((res1, res2) => {
return [res1, res2];
}));
},
getPreInvoice: (id) => {
return axios.get('/api/hw/pre_invoice/' + id)
.then((response) => {
return response.data;
})
.catch((error) => {
console.log(error);
});
},
getInvoice: (id) => {
return axios.get('/api/hw/invoice/' + id)
.then((response) => {
Expand All @@ -170,6 +179,15 @@ export default {
console.log(error);
});
},
getInvoiceId: (id) => {
return axios.get('/api/hw/invoice_id/' + id)
.then((response) => {
return response.data;
})
.catch((error) => {
console.log(error);
});
},
updateCleanStatus: (room_id, status) => {
return axios.put('/api/hw/updateCleanStatus/' + status + '/' + room_id)
.then((response) => {
Expand Down
2 changes: 1 addition & 1 deletion config/schema.sql
Expand Up @@ -126,7 +126,7 @@ CREATE TABLE invoices (
county_tax decimal(5,2) NOT NULL,
city_tax decimal(5,2) NOT NULL,
state_tax decimal(5,2) NOT NULL,
paid boolean DEFAULT 0,
payment_type varchar(50) NOT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (invoice_id)
);
Expand Down

0 comments on commit c0b87f8

Please sign in to comment.