125 lines
2.6 KiB
JavaScript
125 lines
2.6 KiB
JavaScript
/*
|
|
* addLineItem.js
|
|
*
|
|
* Brings up a jQuery modal form dialog for adding a line item to a quote/job/invoice
|
|
*
|
|
* Also does the date picker on the commercial details. Might change the commercial details so they're all javacript sexy too.
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
|
|
fetchTable();
|
|
|
|
var quoteID = $("#QuoteId").serialize();
|
|
$("#unitPrice").hide();
|
|
$("#addLineItem-form").dialog({
|
|
autoOpen: false,
|
|
height: 800,
|
|
width: 800,
|
|
modal: true,
|
|
buttons: {
|
|
'Add Product': function() {
|
|
|
|
$.post("/line_items/ajaxSave", $("#LineItemAddForm").serialize(), function(data) {
|
|
|
|
fetchTable();
|
|
}
|
|
);
|
|
|
|
$("#LineItemAddForm").resetForm();
|
|
$(this).dialog('close');
|
|
},
|
|
Cancel: function() {
|
|
$(this).dialog('close');
|
|
}
|
|
},
|
|
close: function() {
|
|
//What happens on close goes here.
|
|
}
|
|
});
|
|
|
|
|
|
$('#addLineItem')
|
|
.button()
|
|
.click(function() {
|
|
$('#addLineItem-form2').hide();
|
|
|
|
$('#addLineItem-form').dialog('open');
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#generatePDF')
|
|
.button()
|
|
.click(function() {
|
|
$.post("/quotes/ajaxpdf",quoteID, function(data) {
|
|
alert(data);
|
|
});
|
|
});
|
|
|
|
|
|
$("#LineItemPrincipleId").change(getPrincipleProducts);
|
|
|
|
$('#QuoteDateIssuedDisplay').datepicker({
|
|
showButtonPanel: true,
|
|
dateFormat: 'DD d MM yy',
|
|
altFormat: 'yy-mm-dd',
|
|
altField: '#QuoteDateIssued'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
/**
|
|
* Updates the productBox div with a Select Box of the products.
|
|
*
|
|
* puts the output in a div called productBox
|
|
*/
|
|
function getPrincipleProducts() {
|
|
$.post("/products/getPrincipleProducts", $("#LineItemPrincipleId").serialize(), function(data) {
|
|
|
|
|
|
|
|
$('#productBox').html(data);
|
|
$("#LineItemProductId").change(getProductOptions);
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* Ajax Request to get the Product Options (if any) for the Product selected
|
|
*/
|
|
|
|
function getProductOptions() {
|
|
|
|
$.post("/products/getProductOptions", $("#LineItemProductId").serialize(), function(optionData) {
|
|
$("#productOptionsBox").html(optionData);
|
|
|
|
});
|
|
|
|
$("#unitPrice").show();
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* Fetch the most recent table of Line Items. This allows calculation to be done in PHP rather than JS.
|
|
*/
|
|
function fetchTable() {
|
|
$.post("/lineItems/viewTable", $("#LineItemQuoteId").serialize(), function (itemTable) {
|
|
$("#productTable").html(itemTable);
|
|
});
|
|
}
|
|
|
|
|