Commit 1a2024a3 authored by RobertPlummer's avatar RobertPlummer

[NEW] Changes to invoice to help with form data, new we need to configure...

[NEW] Changes to invoice to help with form data, new we need to configure postback to save to trackers
[NEW] Added a few functions to tracker lib to aid with application building that obtain ids from names
parent f65dc050
......@@ -3565,7 +3565,30 @@ class TrackerLib extends TikiLib
function get_tracker_by_name($name) {
return $this->trackers()->fetchOne('trackerId', array('name' => $name));
}
function get_field_by_name($trackerId, $fieldName) {
return $this->fields()->fetchOne('fieldId', array(
'trackerId' => $trackerId,
'name' => $fieldName
));
}
function get_field_by_names($trackerName, $fieldName) {
$trackerId = $this->trackers()->fetchOne('trackerId', array('name' => $trackerName));
return $fieldId = $this->fields()->fetchOne('fieldId', array(
'trackerId' => $trackerId,
'name' => $fieldName
));
}
function get_fields_by_names($trackerName, $fieldNames) {
$fields = array();
foreach($fieldNames as $fieldName) {
$fields[$fieldName] = $this->get_field_by_names($trackerName, $fieldName);
}
return $fields;
}
function get_field_handler($field, $item = array())
{
$trackerId = (int) $field['trackerId'];
......
......@@ -9,51 +9,59 @@
{assign var=dateIssued value="Date Issued"}
{assign var=invoiceNote value="Invoice Note"}
Client <select>
{foreach from=$clients key=k item=client}
<option value='{$client.$clientId}' {if $client.$clientId eq $invoice.$clientId} selected='true' {/if}>{$client.Name}</option>
{/foreach}
</select>
<table class='invoiceDetails'>
<tr>
<td>
Invoice Number <input name='invoiceNumber' id='invoiceNumber' type='text' value='{$invoice.$invoiceNumber}' />
<br />
Date Issued <input name='dateIssued' id='dateIssued' class='invoiceDate' value='{$invoice.$dateIssued}' />
</td>
</tr>
</table>
<hr />
<table class='invoiceItems'>
<tr>
<th>{tr}Quantity{/tr}</th>
<th>{tr}Work Description{/tr}</th>
<th>{tr}Taxable{/tr}</th>
<th>{tr}Amount{/tr}</th>
</tr>
{foreach from=$invoiceItems item=invoiceItem}
<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>
{/foreach}
</select>
<table class='InvoiceDetails'>
<tr>
<td>
{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}' />
</td>
</tr>
</table>
<hr />
<table id='InvoiceItems'>
<tr>
<td><input name='quantity' class='quantity' type='text' value='{$invoiceItem.Quantity}' /></td>
<td><teaxtarea>{$invoiceItem.$workDescription}</teaxtarea></td>
<td><input name='taxable' class='taxable' type='checkbox' value='y' {if $invoiceItem.Taxable eq 'y'} checked='true' {/if} /></td>
<td><input name='amount' class='quantity' type='text' value='{$invoiceItem.Amount}' /></td>
<th>{tr}Quantity{/tr}</th>
<th>{tr}Work Description{/tr}</th>
<th>{tr}Taxable{/tr}</th>
<th>{tr}Amount{/tr}</th>
<th></th>
</tr>
{/foreach}
<tr>
<td colspan='4'>
<input type='button' value='New Item' class='invoiceNewItem' />
</td>
</tr>
{foreach from=$invoiceItems item=invoiceItem}
<tr class='InvoiceItem'>
<td><input name='Quantity[]' class='InvoiceQuantity' type='text' value='{$invoiceItem.Quantity}' /></td>
<td><textarea name='Work Description[]' 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>
</td>
</tr>
{/foreach}
<tr>
<td colspan='4'>
<input type='button' value='{tr}New Item{/tr}' id='InvoiceNewItem' />
</td>
</tr>
</table>
</table>
Amount: <span id='amount'></span><br />
Total: <span id='total'></span><br />
{tr}Amount:{/tr} <span id='Amount'></span><br />
{tr}Total:{/tr} <span id='Total'></span><br />
Invoice Note
<br />
<textarea>{$invoice.$invoiceNote}</textarea>
\ No newline at end of file
{tr}Invoice Note{/tr}
<br />
<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
......@@ -2,9 +2,10 @@
require_once('tiki-setup.php');
require_once('lib/profilelib/installlib.php');
require_once('lib/profilelib/profilelib.php');
require_once('lib/trackers/trackerlib.php');
require_once('lib/trackers/trackerquerylib.php');
global $tikilib, $trkqrylib;
global $tikilib, $trklib, $trkqrylib;
$access->check_feature('feature_invoice');
$access->check_permission('tiki_p_admin');
......@@ -20,13 +21,116 @@ if (!$installer->isInstalled( $profile )) {
$smarty->assign("clients", $trkqrylib->tracker_query_by_names("Invoice Clients"));
$smarty->assign("setting", end($trkqrylib->tracker_query_by_names("Invoice Settings")));
$invoiceItems = array();
//we are editing an invoice here
if (isset($_REQUEST['invoice'])) {
$smarty->assign("invoice", end($trkqrylib->tracker_query_by_names("Invoices", null, null, $_REQUEST['invoice'])));
$smarty->assign("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"));
}
//we add an extra item to the end of invoiceItems, so we can duplicate it on the page
$invoiceItems[] = array(
"Quantity" => "",
"Work Description" => "",
"Taxable" => "",
"Amount" => "",
);
$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",
"Client Id",
"Invoice Number",
"Date Issued",
"Payment Term",
"Tax 1 Description",
"Tax 1 Rate",
"Tax 2 Description",
"Tax 2 Rate",
"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",
"Invoice Id",
"Amount",
"Quantity",
"Work Description",
"Taxable",
));
//This part doesn't yet work, to update or save invoice
if (isset($_REQUEST['invoice'])) { //edit
} else { //new
$newInvoice = array();
foreach($invoicesFieldIds as $invoicesFieldId) {
$newInvoice[] = array(
'fieldId' => $invoicesFieldId,
'value' => 99999
);
}
$_REQUEST['invoice'] = $trklib->replace_item($trklib->get_tracker_by_name("Invoices"), 0, array('data' => $newInvoice));
}
}
$headerlib->add_jq_onready("
function setupTotal() {
$('#InvoiceForm :input')
.unbind('change')
.change(function() {
findTotal();
})
.change();
}
function findTotal() {
var total = 0;
$('.InvoiceItem').each(function() {
var itemTotal = $(this).find('.InvoiceQuantity').val() * $(this).find('.InvoiceAmount').val();
total += itemTotal;
});
$('#Amount').text(total);
}
setupTotal();
$('#InvoiceNewItem').click(function() {
var lastInvoiceItem = $('.InvoiceItem:last');
var newInvoiceItem = lastInvoiceItem.clone();
newInvoiceItem.find(':input').val('');
newInvoiceItem.insertAfter(lastInvoiceItem);
setupTotal();
});
$('#InvoiceForm').click(function(e) {
if ($(e.target).hasClass('DeleteItem')) {
if ($('.InvoiceItem').length > 1) {
$(e.target).parent().parent().remove();
}
return false;
}
});
");
// Display the template
$smarty->assign('mid', 'tiki-edit_invoice.tpl');
$smarty->display("tiki.tpl");
\ No newline at end of file
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