New function to format small and short dates
This commit is contained in:
parent
e2d79c1bb4
commit
ce5f89b38f
18 changed files with 119 additions and 118 deletions
|
@ -5,35 +5,43 @@
|
|||
* (creating invoices based on other SuiteDesk nodes)
|
||||
*/
|
||||
function storminvoice_auto_add($node, $invoice = NULL) {
|
||||
$type = $node->type;
|
||||
|
||||
switch ($node->type) {
|
||||
case 'stormorganization':
|
||||
$type = 'organization';
|
||||
$invoice_nid = stormorganization_storminvoice_auto_add($node, $invoice);
|
||||
break;
|
||||
case 'stormproject':
|
||||
$type = 'project';
|
||||
$invoice_nid = stormproject_storminvoice_auto_add($node, $invoice);
|
||||
break;
|
||||
case 'stormtask':
|
||||
$type = 'task';
|
||||
$invoice_nid = stormtask_storminvoice_auto_add($node, $invoice);
|
||||
break;
|
||||
case 'stormticket':
|
||||
$type = 'ticket';
|
||||
$invoice_nid = stormticket_storminvoice_auto_add($node, $invoice);
|
||||
break;
|
||||
case 'stormtimetracking':
|
||||
$type = 'timetracking';
|
||||
$invoice_nid = stormtimetracking_storminvoice_auto_add($node, $invoice);
|
||||
break;
|
||||
case 'stormexpense':
|
||||
$type = 'expense';
|
||||
$invoice_nid = stormexpense_storminvoice_auto_add($node, $invoice);
|
||||
break;
|
||||
default:
|
||||
drupal_set_message(t('This type of node cannot be automatically added to an invoice'), 'error');
|
||||
drupal_set_message(t('This type of content cannot be automatically added to an invoice.'), 'error');
|
||||
// watchdog - add link to record error in more detail?
|
||||
drupal_goto('node/'. $node->nid);
|
||||
}
|
||||
if ($invoice) {
|
||||
drupal_set_message(t('The @type has been added to the selected invoice.', array('@type' => $node->type)));
|
||||
drupal_set_message(t('The @type has been added to the selected invoice.', array('@type' => t($type))));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('This invoice was created automatically from the selected @type.', array('@type' => $node->type)));
|
||||
drupal_set_message(t('This invoice was created automatically from the selected @type.', array('@type' => t($type))));
|
||||
}
|
||||
drupal_goto('node/'. $invoice_nid);
|
||||
}
|
||||
|
@ -42,7 +50,7 @@ function storminvoice_auto_add_select() {
|
|||
$form['node'] = array(
|
||||
'#title' => t('Node'),
|
||||
'#type' => 'hidden',
|
||||
'#value' => arg(4),
|
||||
'#value' => arg(3),
|
||||
);
|
||||
|
||||
$form['invoice'] = array(
|
||||
|
@ -54,7 +62,7 @@ function storminvoice_auto_add_select() {
|
|||
|
||||
// THIS CODE LOADS OPTIONS INTO THE INVOICE SELECTOR
|
||||
// Load the node object, but don't know how to handle it yet because it could be a node of several types.
|
||||
$node = node_load(arg(4));
|
||||
$node = node_load(arg(3));
|
||||
/* This function does not know the type of node that is being billed for. To avoid recording all relationships between the SuiteDesk nodes,
|
||||
* we simply check for the existance of a parent node (perhaps project, task, ticket etc). Organization will always be set.
|
||||
* The invoices we show in the list are those that match these parents or where these attributes are not set.
|
||||
|
|
|
@ -742,31 +742,33 @@ function _storminvoice_beforesave(&$node) {
|
|||
}
|
||||
|
||||
function _storminvoice_insert_items($node) {
|
||||
foreach ($node->items as $j => $item) {
|
||||
$node->items[$j]->src_nid = (isset($node->items[$j]->src_nid)) ? $node->items[$j]->src_nid : $node->src_nid;
|
||||
$node->items[$j]->src_vid = (isset($node->items[$j]->src_vid)) ? $node->items[$j]->src_vid : $node->src_vid;
|
||||
if (!empty($node->items)) {
|
||||
foreach ($node->items as $j => $item) {
|
||||
$node->items[$j]->src_nid = (isset($node->items[$j]->src_nid)) ? $node->items[$j]->src_nid : $node->src_nid;
|
||||
$node->items[$j]->src_vid = (isset($node->items[$j]->src_vid)) ? $node->items[$j]->src_vid : $node->src_vid;
|
||||
|
||||
db_query("INSERT INTO {storminvoice_items}
|
||||
(invoice_nid, invoice_vid, amount, description,
|
||||
tax1app, tax1percent, tax1,
|
||||
tax2app, tax2percent, tax2,
|
||||
total, weight,
|
||||
src_nid, src_vid
|
||||
) VALUES
|
||||
(%d, %d, %f, '%s',
|
||||
%d, %f, %f,
|
||||
%d, %f, %f,
|
||||
%f, %d,
|
||||
%d, %d
|
||||
)",
|
||||
$node->nid, $node->vid, $node->items[$j]->amount, $node->items[$j]->description,
|
||||
$node->items[$j]->tax1app, $node->items[$j]->tax1percent, $node->items[$j]->tax1,
|
||||
$node->items[$j]->tax2app, $node->items[$j]->tax2percent, $node->items[$j]->tax2,
|
||||
$node->items[$j]->total, $node->items[$j]->weight,
|
||||
$node->items[$j]->src_nid, $node->items[$j]->src_vid
|
||||
db_query("INSERT INTO {storminvoice_items}
|
||||
(invoice_nid, invoice_vid, amount, description,
|
||||
tax1app, tax1percent, tax1,
|
||||
tax2app, tax2percent, tax2,
|
||||
total, weight,
|
||||
src_nid, src_vid
|
||||
) VALUES
|
||||
(%d, %d, %f, '%s',
|
||||
%d, %f, %f,
|
||||
%d, %f, %f,
|
||||
%f, %d,
|
||||
%d, %d
|
||||
)",
|
||||
$node->nid, $node->vid, $node->items[$j]->amount, $node->items[$j]->description,
|
||||
$node->items[$j]->tax1app, $node->items[$j]->tax1percent, $node->items[$j]->tax1,
|
||||
$node->items[$j]->tax2app, $node->items[$j]->tax2percent, $node->items[$j]->tax2,
|
||||
$node->items[$j]->total, $node->items[$j]->weight,
|
||||
$node->items[$j]->src_nid, $node->items[$j]->src_vid
|
||||
);
|
||||
}
|
||||
db_query("DELETE FROM {storminvoice_items} WHERE invoice_vid=%d AND total=0 AND description='' ", $node->vid);
|
||||
}
|
||||
db_query("DELETE FROM {storminvoice_items} WHERE invoice_vid=%d AND total=0 AND description='' ", $node->vid);
|
||||
}
|
||||
|
||||
function _storminvoice_aftersave($node) {
|
||||
|
@ -1016,32 +1018,32 @@ function storminvoice_get_item_desc($rate_array, $node) {
|
|||
switch ($rate_array['pricemode_used']) {
|
||||
case 'hourly':
|
||||
if ($node->type == 'stormtimetracking') {
|
||||
$description = date('d M y', $node->trackingdate) . ': ' . t('@dur @units work at @rate per hour on @desc', array('@dur' => $node->billing_duration, '@unit' => $node->durationunit, '@rate' => $node->price, '@desc' => $node->title));
|
||||
$description = _format_small_date($node->trackingdate) . ' - ' . t('@dur @units work at @rate per hour on @desc', array('@dur' => $node->billing_duration, '@unit' => t($node->durationunit), '@rate' => $node->price, '@desc' => $node->title));
|
||||
}
|
||||
else {
|
||||
$description = date('d M y') . ': ' . t('@dur @units work at @rate per hour on @desc', array('@dur' => $node->duration, '@unit' => $node->durationunit, '@rate' => $node->price, '@desc' => $node->title));
|
||||
$description = _format_small_date() . ' - ' . t('@dur @units work at @rate per hour on @desc', array('@dur' => $node->duration, '@unit' => t($node->durationunit), '@rate' => $node->price, '@desc' => $node->title));
|
||||
}
|
||||
break;
|
||||
case 'daily':
|
||||
if ($node->type == 'stormtimetracking') {
|
||||
$description = date('d M y', $node->trackingdate) . ': ' . t('@dur @units work at @rate per day on @desc', array('@dur' => $node->billing_duration, '@unit' => $node->durationunit, '@rate' => $node->price, '@desc' => $node->title));
|
||||
$description = _format_small_date($node->trackingdate) . ' - ' . t('@dur @units work at @rate per day on @desc', array('@dur' => $node->billing_duration, '@unit' => t($node->durationunit), '@rate' => $node->price, '@desc' => $node->title));
|
||||
}
|
||||
else {
|
||||
$description = date('d M y') . ': ' . t('@dur @units work at @rate per day on @desc', array('@dur' => $node->duration, '@unit' => $node->durationunit, '@rate' => $node->price, '@desc' => $node->title));
|
||||
$description = _format_small_date() . ' - ' . t('@dur @units work at @rate per day on @desc', array('@dur' => $node->duration, '@unit' => t($node->durationunit), '@rate' => $node->price, '@desc' => $node->title));
|
||||
}
|
||||
break;
|
||||
case 'fixed':
|
||||
if ($node->type == 'stormtimetracking') {
|
||||
$description = date('d M y', $node->trackingdate) . ': ' . t('@dur @units unbilled work on @desc', array('@dur' => $node->billing_duration, '@unit' => $node->durationunit, '@desc' => $node->title));
|
||||
$description = _format_small_date($node->trackingdate) . ' - ' . t('@dur @units unbilled work on @desc', array('@dur' => $node->billing_duration, '@unit' => t($node->durationunit), '@desc' => $node->title));
|
||||
}
|
||||
else {
|
||||
$description = date('d M y') . ': ' . t('@dur @units unbilled work on @desc', array('@dur' => $node->duration, '@unit' => $node->durationunit, '@desc' => $node->title));
|
||||
$description = _format_small_date() . ' - ' . t('@dur @units unbilled work on @desc', array('@dur' => $node->duration, '@unit' => t($node->durationunit), '@desc' => $node->title));
|
||||
}
|
||||
break;
|
||||
case 'fixed_price':
|
||||
switch ($node->type) {
|
||||
case 'stormtimetracking':
|
||||
$description = date('d M y', $node->trackingdate) . ': ' . t('work billed for @desc', array('@desc' => $node->title));
|
||||
$description = _format_small_date($node->trackingdate) . ' - ' . t('Work billed for @desc', array('@desc' => $node->title));
|
||||
break;
|
||||
case 'stormproject':
|
||||
$description = t('Project billed: @desc', array('@desc' => $node->title));
|
||||
|
|
|
@ -34,9 +34,6 @@ function theme_storminvoice_list($header, $invoices, $itemsperpage, $totals_topa
|
|||
$invoice->status = 'overdue';
|
||||
}
|
||||
|
||||
$requestdate = format_date($invoice->requestdate, 'small');
|
||||
$requestdate = substr($requestdate, 0, strpos($requestdate, ' '));
|
||||
|
||||
$rows[] = array(
|
||||
array(
|
||||
'data' => storm_icon('invoice_status_'. check_plain($invoice->status), storm_attribute_value('Invoice status', $invoice->status)),
|
||||
|
@ -49,7 +46,7 @@ function theme_storminvoice_list($header, $invoices, $itemsperpage, $totals_topa
|
|||
'<span class="invoice-title">' . l($invoice->title, 'node/'. $invoice->nid) . theme('mark', node_mark($invoice->nid, $invoice->changed)) . '</span><br />' .
|
||||
l($invoice->organization_title, 'node/'. $invoice->organization_nid) .' » '.
|
||||
l($invoice->project_title, 'node/'. $invoice->project_nid),
|
||||
$requestdate,
|
||||
_format_short_date($invoice->requestdate),
|
||||
array('data' => sprintf('%.2f', $invoice->total), 'align' => 'right'),
|
||||
array(
|
||||
'data' => storm_icon_edit_node($invoice, $_GET) .' '. storm_icon_delete_node($invoice, $_GET),
|
||||
|
@ -270,14 +267,14 @@ function theme_storminvoice_view($node, $teaser = FALSE, $page = FALSE) {
|
|||
$node->content['group3']['requestdate'] = array(
|
||||
'#prefix' => '<div class="requestdate">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Request date'), format_date($node->requestdate, 'custom', 'Y-m-d')),
|
||||
'#value' => theme('storm_view_item', t('Request date'), _format_short_date($node->requestdate)),
|
||||
'#weight' => 1,
|
||||
);
|
||||
|
||||
$node->content['group3']['duedate'] = array(
|
||||
'#prefix' => '<div class="duedate">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Due date'), format_date($node->duedate, 'custom', 'Y-m-d')),
|
||||
'#value' => theme('storm_view_item', t('Due date'), _format_short_date($node->duedate)),
|
||||
'#weight' => 2,
|
||||
);
|
||||
|
||||
|
@ -285,7 +282,7 @@ function theme_storminvoice_view($node, $teaser = FALSE, $page = FALSE) {
|
|||
$node->content['group3']['paymentdate'] = array(
|
||||
'#prefix' => '<div class="paymentdate">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Payment date'), $node->paymentdate? format_date($node->paymentdate, 'custom', 'Y-m-d') : ''),
|
||||
'#value' => theme('storm_view_item', t('Payment date'), $node->paymentdate ? _format_short_date($node->paymentdate) : ''),
|
||||
'#weight' => 3,
|
||||
);
|
||||
}
|
||||
|
@ -449,14 +446,14 @@ function theme_storminvoice_view($node, $teaser = FALSE, $page = FALSE) {
|
|||
$node->content['group_item']['created'] = array(
|
||||
'#prefix' => '<div class="created">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Created'), format_date($node->created, 'small')),
|
||||
'#value' => theme('storm_view_item', t('Created'), _format_small_date($node->created)),
|
||||
'#weight' => 2,
|
||||
);
|
||||
if ($node->changed != $node->created) {
|
||||
$node->content['group_item']['modified'] = array(
|
||||
'#prefix' => '<div class="modified">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Modified'), format_date($node->changed, 'small')),
|
||||
'#value' => theme('storm_view_item', t('Modified'), _format_small_date($node->changed)),
|
||||
'#weight' => 3,
|
||||
);
|
||||
}
|
||||
|
@ -584,7 +581,7 @@ function theme_storminvoice_report_pdf($node, $language, $output = 'screen') {
|
|||
$h = $pdf->getY() - $h;
|
||||
$pdf->MultiCell($w-2, $h, $node->number, 1, 'L', 0, 0, PDF_MARGIN_LEFT + $pageWidth *.5, $pdf->getY() - $h);
|
||||
$pdf->MultiCell($w-3, $h, $mycurrency, 1, 'L', 0, 0);
|
||||
$pdf->MultiCell($w+5, $h, format_date($node->requestdate, 'custom', 'Y-m-d'), 1, 'L', 0, 1);
|
||||
$pdf->MultiCell($w+5, $h, _format_short_date($node->requestdate), 1, 'L', 0, 1);
|
||||
|
||||
$pdf->SetFont("times", "B", 10);
|
||||
|
||||
|
@ -607,7 +604,7 @@ function theme_storminvoice_report_pdf($node, $language, $output = 'screen') {
|
|||
}
|
||||
$pdf->MultiCell($w * 2 - 5, 12, $o, 1, 'C', 0, 0, PDF_MARGIN_LEFT + $pageWidth * .5);
|
||||
$pdf->SetFont("times", "N", 10);
|
||||
$pdf->MultiCell($w + 5, 12, format_date($node->duedate, 'custom', 'Y-m-d'), 1, 'L', 0, 0);
|
||||
$pdf->MultiCell($w + 5, 12, _format_short_date($node->duedate), 1, 'L', 0, 0);
|
||||
$pdf->MultiCell($w, 12, variable_get('storminvoice_payment_terms', ''), 1, 'L', 0, 1);
|
||||
|
||||
$y = $pdf->getY();
|
||||
|
@ -775,7 +772,7 @@ function theme_storminvoice_report_html($node, $language) {
|
|||
$o .= '<tr>';
|
||||
$o .= '<td>'. $node->number .'</td>';
|
||||
$o .= '<td>'. $mycurrency .'</td>';
|
||||
$o .= '<td>'. format_date($node->requestdate, 'custom', 'Y-m-d') .'</td>';
|
||||
$o .= '<td>'. _format_short_date($node->requestdate) .'</td>';
|
||||
$o .= '<td>'. $node->reference .'</td>';
|
||||
$o .= '</tr>';
|
||||
$o .= '<tr>';
|
||||
|
@ -800,7 +797,7 @@ function theme_storminvoice_report_html($node, $language) {
|
|||
$o .= '('. $organization->currency .' '. sprintf('%.2f', $node->totalcustomercurr) .')';
|
||||
}
|
||||
$o .= '</td>';
|
||||
$o .= '<td>'. format_date($node->duedate, 'custom', 'Y-m-d') .'</td>';
|
||||
$o .= '<td>'. _format_short_date($node->duedate) .'</td>';
|
||||
$o .= '<td>'. variable_get('storminvoice_payment_terms', '') .'</td>';
|
||||
$o .= '</tr>';
|
||||
$o .= '</table></div>';
|
||||
|
|
Reference in a new issue