Commit fb23a403 authored by RobertPlummer's avatar RobertPlummer

[FIX] Fixes to tiki invoice to get update working, now I just need to manage deletion of objects

[FIX] Tracker Query Lib, better detection of variables in use
[FIX] Tracker Query Lib was wiping fields if used byName
parent 5882e48e
......@@ -239,14 +239,14 @@ class TrackerQueryLib extends TikiLib
$params[] = $tracker;
if ($start && !$search) $params[] = $start;
if ($end && !$search) $params[] = $end;
if ($itemId && !$search) $params[] = $itemId;
if (isset($start) && !empty($start) && !$search) $params[] = $start;
if (isset($end) && !empty($end) && !$search) $params[] = $end;
if (isset($itemId) && !empty($itemId) && !$search) $params[] = $itemId;
if(isset($byName)) {
if(isset($byName) && !empty($byName)) {
$fieldIds = array();
foreach($fields as $field) {
$fields[] = $tikilib->getOne("
$fieldIds[] = $tikilib->getOne("
SELECT fieldId
FROM tiki_tracker_fields
LEFT JOIN tiki_trackers ON (
......@@ -301,11 +301,11 @@ class TrackerQueryLib extends TikiLib
}
}
if ( isset($limit) == true && is_numeric($limit) == false) {
if ( isset($limit) && !empty($limit) && is_numeric($limit) == false) {
unset($limit);
}
if ( isset($offset) == true && is_numeric($offset) == false) {
if ( isset($offset) && !empty($offset) && is_numeric($offset) == false) {
unset($offset);
}
......@@ -352,20 +352,20 @@ class TrackerQueryLib extends TikiLib
WHERE
".(isset($byName) ? "tiki_trackers.name" : "tiki_trackers.trackerId")." = ?
".(isset($byName) && !empty($byName) ? "tiki_trackers.name" : "tiki_trackers.trackerId")." = ?
".(isset($start) && !$search ? " AND tiki_tracker_items.lastModif > ? " : "")."
".(isset($end) && !$search ? " AND tiki_tracker_items.lastModif < ? " : "")."
".(isset($itemId) && !$search ? " AND tiki_tracker_item_fields.itemId = ? " : "")."
".(isset($fields_safe) ? $fields_safe : "")."
".(isset($status_safe) ? $status_safe : "")."
".(isset($start) && !empty($start) && !$search ? " AND tiki_tracker_items.lastModif > ? " : "")."
".(isset($end) && !empty($end) && !$search ? " AND tiki_tracker_items.lastModif < ? " : "")."
".(isset($itemId) && !empty($itemId) && !$search ? " AND tiki_tracker_item_fields.itemId = ? " : "")."
".(isset($fields_safe) && !empty($fields_safe) ? $fields_safe : "")."
".(isset($status_safe) && !empty($status_safe) ? $status_safe : "")."
GROUP BY
tiki_tracker_item_fields.itemId
ORDER BY
tiki_tracker_items.lastModif
".(isset($limit) ?
" LIMIT ".(isset($offset) ? "$offset, " : "")." $limit"
".(isset($limit) && !empty($limit) ?
" LIMIT ".(isset($offset) && !empty($offset) ? "$offset, " : "")." $limit"
: ""
);
......
......@@ -9,8 +9,11 @@
{assign var=DateIssued value="Date Issued"}
{assign var=InvoiceNote value="Invoice Note"}
{assign var=InvoiceItemId value="Invoice Item Id"}
{assign var=ItemIds value="Item Ids"}
<form action="tiki-edit_invoice.php" method="post" id="InvoiceForm">
<input type='hidden' value={$InvoiceId} name='InvoiceId' id='InvoiceId' />
<input type='hidden' value='{$invoice.$ItemIds}' name='InvoiceItemIds' id='InvoiceItemIds' />
{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>
......@@ -39,7 +42,7 @@
{foreach from=$invoiceItems item=invoiceItem}
<tr class='InvoiceItem'>
<input name='InvoiceItemId' class='InvoiceItemId' type='hidden' value='{$invoiceItem.$InvoiceItemId}' />
<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='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>
......
......@@ -3,13 +3,13 @@
{include file='tiki-invoice_menu.tpl'}
{* vars to deal with keys that have spaces *}
{assign var=clientId value="Client Id"}
{assign var=itemAmounts value="Item Amounts"}
{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=invoiceId value="Invoice Id"}
{assign var=ClientId value="Client Id"}
{assign var=ItemAmounts value="Item Amounts"}
{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=InvoiceId value="Invoice Id"}
<table>
<tr>
......@@ -22,11 +22,11 @@
{foreach from=$invoices key=k item=invoice}
<tr>
<td><a href='tiki-view_invoice.php?invoice={$invoice.$invoiceId}'>{$invoice.$invoiceNumber}</a></td>
<td><a href='tiki-view_invoice.php?invoice={$invoice.$invoiceId}'>{$invoice.$dateIssued}</a></td>
<td><a href='tiki-view_invoice_client.php?invoice={$invoice.$clientId}'>{$invoice.$clientName}</a></td>
<td><a href='tiki-view_invoice.php?invoice={$invoice.$invoiceId}'>{$invoice.Amount}</a></td>
<td><a href='tiki-view_invoice.php?invoice={$invoice.$invoiceId}'>{$invoice.Status}</a></td>
<td><a href='tiki-view_invoice.php?InvoiceId={$invoice.$InvoiceId}'>{$invoice.$InvoiceNumber}</a></td>
<td><a href='tiki-view_invoice.php?InvoiceId={$invoice.$InvoiceId}'>{$invoice.$DateIssued}</a></td>
<td><a href='tiki-view_invoice_client.php?invoice={$invoice.$ClientId}'>{$invoice.$ClientName}</a></td>
<td><a href='tiki-view_invoice.php?InvoiceId={$invoice.$InvoiceId}'>{$invoice.Amount}</a></td>
<td><a href='tiki-view_invoice.php?InvoiceId={$invoice.$InvoiceId}'>{$invoice.Status}</a></td>
</tr>
{/foreach}
......
......@@ -44,11 +44,14 @@
<td>{$invoiceItem.Quantity}</td>
<td>{$invoiceItem.$workDescription}</td>
<td>{$invoiceItem.Amount}</td>
<td>{$invoiceItem.Amount} {$invoiceItem.Quantity}</td>
<td>{$invoiceItem.Amount*$invoiceItem.Quantity}</td>
</tr>
{/foreach}
</table>
Amount: {$amount}<br />
Total: {$amount}<br />
Payment Terms: {$invoice.$paymentTerm}
\ No newline at end of file
Payment Terms: {$invoice.$paymentTerm}
<br />
<br />
<a href="tiki-edit_invoice?InvoiceId={$InvoiceId}">{tr}Edit Invoice{/tr}</a>
\ No newline at end of file
......@@ -9,7 +9,6 @@ global $tikilib, $trklib, $trkqrylib;
$access->check_feature('feature_invoice');
$access->check_permission('tiki_p_admin');
print_r($trkqrylib->tracker_query_by_names("Invoice Items"));
//check if profile is created
$installer = new Tiki_Profile_Installer();
......@@ -20,32 +19,9 @@ if (!$installer->isInstalled( $profile )) {
die;
}
$smarty->assign("clients", $trkqrylib->tracker_query_by_names("Invoice Clients"));
$smarty->assign("setting", end($trkqrylib->tracker_query_by_names("Invoice Settings")));
print_r($trkqrylib->tracker_query_by_names("Invoices"));
$invoiceItems = array();
(int)$_REQUEST['InvoiceId'] = $_REQUEST['InvoiceId'];
//we are editing an invoice here
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" => "",
"Work Description" => "",
"Taxable" => "",
"Amount" => "",
);
$smarty->assign("invoiceItems", $invoiceItems);
//we are updating or adding
//handle saving data (edit or update)
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//form to tracker item transformation
function processItem($trackerName, $fieldNames, $fieldValues, $itemId, $i) {
......@@ -62,7 +38,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
}
//start invoice
$_REQUEST['invoice'] = processItem("Invoices", array(
$_REQUEST['InvoiceId'] = processItem("Invoices", array(
"Client Id",
"Invoice Number",
"Date Issued",
......@@ -73,28 +49,72 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
"Tax 2 Rate",
"Invoice Note",
"Days Payment Due",
), $_REQUEST, $_REQUEST['invoice']);
), $_REQUEST, $_REQUEST['InvoiceId']);
//end invoice
//start invoice items
$invoiceItems = array();
for($i = 0; $i < count($_REQUEST["Amount"]); $i++) {
$_TEMP = $_REQUEST;
$itemsToDelete = array();
foreach(explode(',', $_REQUEST['InvoiceItemIds']) as $itemId) {
$itemsToDelete[$itemId] = $itemId;
}
$_TEMP['InvoiceId'] = array();
for($i = 0; $i < count($_REQUEST['InvoiceItemId']); $i++) {
$_TEMP['InvoiceId'][$i] = $_REQUEST['InvoiceId'];
$invoiceItem = processItem("Invoice Items", array(
"Invoice Id",
"Amount",
"Quantity",
"Work Description",
"Taxable",
), $_REQUEST, $_REQUEST['InvoiceItemId'][$i], $i);
), $_TEMP, $_REQUEST['InvoiceItemId'][$i], $i);
if (isset($itemsToDelete[$_REQUEST['InvoiceItemId'][$i]])) {
unset($itemsToDelete[$_REQUEST['InvoiceItemId'][$i]]);
}
array_push($invoiceItems, $invoiceItem);
}
print_r(array($_REQUEST['invoice'] => $invoiceItems));
//end invoice items
//here I need to delete items that were deleted on the page
//:)
//end delete
header( 'Location: tiki-view_invoice.php?InvoiceId='.$_REQUEST['InvoiceId'] ) ;
die;
}
$invoiceItems = array();
if (!empty($_REQUEST['InvoiceId'])) {
$invoice = end($trkqrylib->tracker_query_by_names("Invoices", null, null, $_REQUEST['InvoiceId']));
$invoice['Item Ids'] = implode(',', $invoice['Item Ids']);
$smarty->assign("invoice", $invoice);
$invoiceItems = $trkqrylib->tracker_query_by_names("Invoice Items", null, null, null, array($_REQUEST['InvoiceId']), null, array("Invoice Id"));
} else {
$_REQUEST['InvoiceId'] = 0;
}
$smarty->assign("InvoiceId", $_REQUEST['InvoiceId']);
$smarty->assign("clients", $trkqrylib->tracker_query_by_names("Invoice Clients"));
$smarty->assign("setting", end($trkqrylib->tracker_query_by_names("Invoice Settings")));
//we add an extra item to the end of invoiceItems, so we can duplicate it on the page
if (count($invoiceItems) < 1) {
$invoiceItems[] = array(
"Quantity" => "",
"Work Description" => "",
"Taxable" => "",
"Amount" => "",
);
}
$smarty->assign("invoiceItems", $invoiceItems);
$headerlib->add_jq_onready("
function setupTotal() {
$('#InvoiceForm :input')
......@@ -148,8 +168,11 @@ $headerlib->add_jq_onready("
$('.InvoiceItemId').each(function() {
var InvoiceItemId = $(this);
InvoiceItemId.val(InvoiceItemId.val() ? InvoiceItemId.val() : 0);
InvoiceItemId.val(InvoiceItemId.val() ? InvoiceItemId.val() : '0');
});
var InvoiceId = $('#InvoiceId');
InvoiceId.val(InvoiceId.val() ? InvoiceId.val() : 0);
});
");
......
......@@ -18,8 +18,11 @@ if (!$installer->isInstalled( $profile )) {
die;
}
$invoice = end($trkqrylib->tracker_query_by_names("Invoices", null, null, $_REQUEST['invoice']));
(int)$_REQUEST['InvoiceId'] = $_REQUEST['InvoiceId'];
$smarty->assign('InvoiceId', $_REQUEST['InvoiceId']);
$invoice = end($trkqrylib->tracker_query_by_names("Invoices", null, null, $_REQUEST['InvoiceId']));
$amount = 0;
if (is_array($invoice["Item Amounts"])) {
foreach($invoice["Item Amounts"] as $key => $sum) {
$amount += $invoice["Item Amounts"][$key] * $invoice["Item Quantities"][$key];
......@@ -32,7 +35,7 @@ $smarty->assign("invoice", $invoice);
$smarty->assign("amount", $amount);
$smarty->assign("client", end($trkqrylib->tracker_query_by_names("Invoice Clients", null, null, null, array($invoice['Client Id']), null, array("Client Id"))));
$smarty->assign("setting", end($trkqrylib->tracker_query_by_names("Invoice Settings")));
$smarty->assign("invoiceItems", $trkqrylib->tracker_query_by_names("Invoice Items", null, null, null, array($_REQUEST['invoice']), null, array("Invoice Id")));
$smarty->assign("invoiceItems", $trkqrylib->tracker_query_by_names("Invoice Items", null, null, null, array($_REQUEST['InvoiceId']), null, array("Invoice Id")));
// Display the template
$smarty->assign('mid', 'tiki-view_invoice.tpl');
......
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