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 @@
{include file='tiki-invoice_menu.tpl'}
{* vars to deal with keys that have spaces *}
{assign var=clientId value="Client Id"}
{assign var=workDescription value="Work Description"}
{assign var=invoiceNumber value="Invoice Number"}
{assign var=dateIssued value="Date Issued"}
{assign var=invoiceNote value="Invoice Note"}
{assign var=ClientId value="Client Id"}
{assign var=WorkDescription value="Work Description"}
{assign var=InvoiceNumber value="Invoice Number"}
{assign var=DateIssued value="Date Issued"}
{assign var=InvoiceNote value="Invoice Note"}
{assign var=InvoiceItemId value="Invoice Item Id"}
<form action="tiki-edit_invoice.php" method="post" id="InvoiceForm">
{tr}Client{/tr} <select name="ClientId" class="InvoiceClientId">
{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}
</select>
<table class='InvoiceDetails'>
<tr>
<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 />
{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>
</tr>
</table>
......@@ -38,12 +39,13 @@
{foreach from=$invoiceItems item=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><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='Amount[]' class='InvoiceAmount' type='text' value='{$invoiceItem.Amount}' /></td>
<td>
<a href="#" class="DeleteItem">Delete</a>
<input type='button' class='DeleteItem' value='{tr}Delete{/tr}' />
</td>
</tr>
{/foreach}
......@@ -61,7 +63,7 @@
{tr}Invoice Note{/tr}
<br />
<textarea name="InvoiceNote" id="InvoiceNote">{$invoice.$invoiceNote}</textarea>
<textarea name="InvoiceNote" id="InvoiceNote">{$invoice.$InvoiceNote}</textarea>
<br />
<input type="submit" value="{tr}Save Invoice{/tr}" name="submit" />
</form>
\ No newline at end of file
......@@ -28,8 +28,12 @@ if (isset($_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"));
} 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
$invoiceItems[] = array(
"Quantity" => "",
......@@ -41,11 +45,64 @@ $smarty->assign("invoiceItems", $invoiceItems);
//we are updating or adding
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//testing post back
print_r($_REQUEST);
die;
$invoicesFieldIds = $trklib->get_fields_by_names("Invoices", array(
"Invoice Id",
/*This is what an array will look like on post back:
Array
(
[ClientId] => 6336
[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",
"Invoice Number",
"Date Issued",
......@@ -57,22 +114,24 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
"Invoice Note",
"Days Payment Due",
"Client Name",
"Item Amounts",
"Item Quantities",
"Amounts Paid",
));
$invoiceItemsFieldIds = $trklib->get_fields_by_names("Invoice Items", array(
"Invoice Item Id",
$invoiceItems = array();
for($i = 0; $i < count($_REQUEST["Amount"]); $i++) {
array_push($invoiceItems, processItem("Invoice Items", array(
"Invoice Id",
"Amount",
"Quantity",
"Work Description",
"Taxable",
));
), $i));
}
//This part doesn't yet work, to update or save invoice
print_r($invoiceItems);
die;
if (isset($_REQUEST['invoice'])) { //edit
} else { //new
......@@ -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("
var lastInvoiceItem = $('.InvoiceItem:last');
var newInvoiceItem = lastInvoiceItem.clone();
newInvoiceItem.find(':input').val('');
newInvoiceItem.find(':input').not(':checkbox,:button').val('');
newInvoiceItem.insertAfter(lastInvoiceItem);
......@@ -129,6 +188,17 @@ $headerlib->add_jq_onready("
return false;
}
});
$('#InvoiceForm').submit(function() {
$('.InvoiceTaxable').each(function() {
var InvoiceTaxable = $(this);
if (!InvoiceTaxable.is(':checked')) {
InvoiceTaxable
.val('n')
.attr('checked', 'true');
}
});
});
");
// 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