Commit 5efd8a8f authored by RobertPlummer's avatar RobertPlummer

[FIX] Adding better ways of handling variables on post back and invoice items...

[FIX] Adding better ways of handling variables on post back and invoice items that already exist, still not working, but direction much better.
parent 21f0fbec
...@@ -3,25 +3,26 @@ ...@@ -3,25 +3,26 @@
{include file='tiki-invoice_menu.tpl'} {include file='tiki-invoice_menu.tpl'}
{* vars to deal with keys that have spaces *} {* vars to deal with keys that have spaces *}
{assign var=clientId value="Client Id"} {assign var=ClientId value="Client Id"}
{assign var=workDescription value="Work Description"} {assign var=WorkDescription value="Work Description"}
{assign var=invoiceNumber value="Invoice Number"} {assign var=InvoiceNumber value="Invoice Number"}
{assign var=dateIssued value="Date Issued"} {assign var=DateIssued value="Date Issued"}
{assign var=invoiceNote value="Invoice Note"} {assign var=InvoiceNote value="Invoice Note"}
{assign var=InvoiceItemId value="Invoice Item Id"}
<form action="tiki-edit_invoice.php" method="post" id="InvoiceForm"> <form action="tiki-edit_invoice.php" method="post" id="InvoiceForm">
{tr}Client{/tr} <select name="ClientId" class="InvoiceClientId"> {tr}Client{/tr} <select name="ClientId" class="InvoiceClientId">
{foreach from=$clients key=k item=client} {foreach from=$clients key=k item=client}
<option value='{$client.$clientId}' {if $client.$clientId eq $invoice.$clientId} selected='true' {/if}>{$client.Name}</option> <option value='{$client.$ClientId}' {if $client.$ClientId eq $invoice.$ClientId} selected='true' {/if}>{$client.Name}</option>
{/foreach} {/foreach}
</select> </select>
<table class='InvoiceDetails'> <table class='InvoiceDetails'>
<tr> <tr>
<td> <td>
{tr}Invoice Number{/tr} <input name='InvoiceNumber' id='InvoiceNumber' type='text' value='{$invoice.$invoiceNumber}' /> {tr}Invoice Number{/tr} <input name='InvoiceNumber' id='InvoiceNumber' type='text' value='{$invoice.$InvoiceNumber}' />
<br /> <br />
{tr}Date Issued{/tr} <input name='DateIssued' id='DateIssued' value='{$invoice.$dateIssued}' /> {tr}Date Issued{/tr} <input name='DateIssued' id='DateIssued' value='{$invoice.$DateIssued}' />
</td> </td>
</tr> </tr>
</table> </table>
...@@ -38,12 +39,13 @@ ...@@ -38,12 +39,13 @@
{foreach from=$invoiceItems item=invoiceItem} {foreach from=$invoiceItems item=invoiceItem}
<tr class='InvoiceItem'> <tr class='InvoiceItem'>
<input name='InvoiceItemId' class='InvoiceItemId' type='hidden' value='{$invoiceItem.$InvoiceItemId}'
<td><input name='Quantity[]' class='InvoiceQuantity' type='text' value='{$invoiceItem.Quantity}' /></td> <td><input name='Quantity[]' class='InvoiceQuantity' type='text' value='{$invoiceItem.Quantity}' /></td>
<td><textarea name='Work Description[]' class='InvoiceWorkDescription'>{$invoiceItem.$workDescription}</textarea></td> <td><textarea name='WorkDescription[]' class='InvoiceWorkDescription'>{$invoiceItem.$WorkDescription}</textarea></td>
<td><input name='Taxable[]' class='InvoiceTaxable' type='checkbox' value='y' {if $invoiceItem.Taxable eq 'y'} checked='true' {/if} /></td> <td><input name='Taxable[]' class='InvoiceTaxable' type='checkbox' value='y' {if $invoiceItem.Taxable eq 'y'} checked='true' {/if} /></td>
<td><input name='Amount[]' class='InvoiceAmount' type='text' value='{$invoiceItem.Amount}' /></td> <td><input name='Amount[]' class='InvoiceAmount' type='text' value='{$invoiceItem.Amount}' /></td>
<td> <td>
<a href="#" class="DeleteItem">Delete</a> <input type='button' class='DeleteItem' value='{tr}Delete{/tr}' />
</td> </td>
</tr> </tr>
{/foreach} {/foreach}
...@@ -61,7 +63,7 @@ ...@@ -61,7 +63,7 @@
{tr}Invoice Note{/tr} {tr}Invoice Note{/tr}
<br /> <br />
<textarea name="InvoiceNote" id="InvoiceNote">{$invoice.$invoiceNote}</textarea> <textarea name="InvoiceNote" id="InvoiceNote">{$invoice.$InvoiceNote}</textarea>
<br /> <br />
<input type="submit" value="{tr}Save Invoice{/tr}" name="submit" /> <input type="submit" value="{tr}Save Invoice{/tr}" name="submit" />
</form> </form>
\ No newline at end of file
...@@ -28,8 +28,12 @@ if (isset($_REQUEST['invoice'])) { ...@@ -28,8 +28,12 @@ if (isset($_REQUEST['invoice'])) {
$smarty->assign("invoice", end($trkqrylib->tracker_query_by_names("Invoices", null, null, $_REQUEST['invoice']))); $smarty->assign("invoice", end($trkqrylib->tracker_query_by_names("Invoices", null, null, $_REQUEST['invoice'])));
$invoiceItems = $trkqrylib->tracker_query_by_names("Invoice Items", null, null, null, array($_REQUEST['invoice']), null, array("Invoice Id")); $invoiceItems = $trkqrylib->tracker_query_by_names("Invoice Items", null, null, null, array($_REQUEST['invoice']), null, array("Invoice Id"));
} else {
$_REQUEST['invoice'] = 0;
} }
(int)$_REQUEST['invoice'] = $_REQUEST['invoice'];
//we add an extra item to the end of invoiceItems, so we can duplicate it on the page //we add an extra item to the end of invoiceItems, so we can duplicate it on the page
$invoiceItems[] = array( $invoiceItems[] = array(
"Quantity" => "", "Quantity" => "",
...@@ -41,11 +45,64 @@ $smarty->assign("invoiceItems", $invoiceItems); ...@@ -41,11 +45,64 @@ $smarty->assign("invoiceItems", $invoiceItems);
//we are updating or adding //we are updating or adding
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//testing post back /*This is what an array will look like on post back:
print_r($_REQUEST); Array
die; (
$invoicesFieldIds = $trklib->get_fields_by_names("Invoices", array( [ClientId] => 6336
"Invoice Id", [InvoiceNumber] => 123
[DateIssued] => 4/4/2012
[Quantity] => Array
(
[0] => 3
[1] => 30
)
[WorkDescription] => Array
(
[0] => Hourly Rate
[1] => Hourly Rate 2
)
[Taxable] => Array
(
[0] => n
[1] => y
)
[Amount] => Array
(
[0] => 100
[1] => 100
)
[InvoiceNote] => Invoice Note
[submit] => Save Invoice
[invoice] => 0
)
*/
//This part doesn't yet work, to update or save invoice
function processItem($trackerName, $fieldNames, $idFieldName, $i) {
global $trklib;
$fieldIds = $trklib->get_fields_by_names($trackerName, $fieldNames);
$fieldData = array();
foreach($fieldNames as $fieldName) {
$fieldVal = (isset($i) ? $_REQUEST[str_replace(" ", "", $fieldName)][$i] : $_REQUEST[str_replace(" ", "", $fieldName)]);
array_push($fieldData, formToTrackerField($fieldIds[$fieldName], $fieldVal));
}
return $fieldData;
}
function formToTrackerField($id, $val) {
return array(
'fieldId' => $id,
'value' => $val
);
}
$invoice = processItem("Invoices", array(
"Client Id", "Client Id",
"Invoice Number", "Invoice Number",
"Date Issued", "Date Issued",
...@@ -57,22 +114,24 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { ...@@ -57,22 +114,24 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
"Invoice Note", "Invoice Note",
"Days Payment Due", "Days Payment Due",
"Client Name", "Client Name",
"Item Amounts",
"Item Quantities",
"Amounts Paid", "Amounts Paid",
)); ));
$invoiceItemsFieldIds = $trklib->get_fields_by_names("Invoice Items", array( $invoiceItems = array();
"Invoice Item Id",
for($i = 0; $i < count($_REQUEST["Amount"]); $i++) {
array_push($invoiceItems, processItem("Invoice Items", array(
"Invoice Id", "Invoice Id",
"Amount", "Amount",
"Quantity", "Quantity",
"Work Description", "Work Description",
"Taxable", "Taxable",
)); ), $i));
}
//This part doesn't yet work, to update or save invoice
print_r($invoiceItems);
die;
if (isset($_REQUEST['invoice'])) { //edit if (isset($_REQUEST['invoice'])) { //edit
} else { //new } else { //new
...@@ -85,7 +144,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { ...@@ -85,7 +144,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
); );
} }
$_REQUEST['invoice'] = $trklib->replace_item($trklib->get_tracker_by_name("Invoices"), 0, array('data' => $newInvoice)); $_REQUEST['invoice'] = $trklib->replace_item($trklib->get_tracker_by_name("Invoices"), $_REQUEST['invoice'], array('data' => $newInvoice));
} }
} }
...@@ -114,7 +173,7 @@ $headerlib->add_jq_onready(" ...@@ -114,7 +173,7 @@ $headerlib->add_jq_onready("
var lastInvoiceItem = $('.InvoiceItem:last'); var lastInvoiceItem = $('.InvoiceItem:last');
var newInvoiceItem = lastInvoiceItem.clone(); var newInvoiceItem = lastInvoiceItem.clone();
newInvoiceItem.find(':input').val(''); newInvoiceItem.find(':input').not(':checkbox,:button').val('');
newInvoiceItem.insertAfter(lastInvoiceItem); newInvoiceItem.insertAfter(lastInvoiceItem);
...@@ -129,6 +188,17 @@ $headerlib->add_jq_onready(" ...@@ -129,6 +188,17 @@ $headerlib->add_jq_onready("
return false; return false;
} }
}); });
$('#InvoiceForm').submit(function() {
$('.InvoiceTaxable').each(function() {
var InvoiceTaxable = $(this);
if (!InvoiceTaxable.is(':checked')) {
InvoiceTaxable
.val('n')
.attr('checked', 'true');
}
});
});
"); ");
// Display the template // Display the template
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment