Skip to content

Commit

Permalink
Fix and add messages, highlighting etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
emaijala committed Dec 3, 2024
1 parent b34b698 commit b833eef
Show file tree
Hide file tree
Showing 19 changed files with 140 additions and 100 deletions.
1 change: 1 addition & 0 deletions add_rows.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@
dbQueryCheck('COMMIT');
dbQueryCheck('SET AUTOCOMMIT = 1');

$_SESSION['formWarningMessage'] = Translator::Translate('CheckUpdatedInvoice');
header("Location: index.php?func=invoices&list=invoice&form=invoice&id=$invoiceId");
2 changes: 1 addition & 1 deletion copy_invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
$invoiceData['template_invoice_id'] = $intInvoiceId;
}

advanceInvoiceIntervalData($invoiceData);
advanceInvoiceIntervalDate($invoiceData);

dbQueryCheck('SET AUTOCOMMIT = 0');
dbQueryCheck('BEGIN');
Expand Down
136 changes: 63 additions & 73 deletions create_invoice_from_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,85 +83,75 @@
return;
}

$paymentDays = getPaymentDays($invoiceData['company_id']);

unset($invoiceData['id']);
unset($invoiceData['invoice_no']);
$invoiceData['deleted'] = 0;
$invoiceData['invoice_date'] = date('Ymd');
$invoiceData['due_date'] = date(
'Ymd', mktime(0, 0, 0, date('m'), date('d') + $paymentDays, date('Y'))
);
$invoiceData['payment_date'] = null;
$invoiceData['state_id'] = 1;
$invoiceData['archived'] = false;
$invoiceData['refunded_invoice_id'] = null;
$invoiceData['interval_type'] = 0;
$invoiceData['next_interval_date'] = null;
$invoiceData['template_invoice_id'] = $intInvoiceId;



dbQueryCheck('SET AUTOCOMMIT = 0');
dbQueryCheck('BEGIN');

try {
if ($invoiceData['interval_type'] > 0) {
// Reset interval type of the original invoice
$strQuery = 'UPDATE {prefix}invoice ' . 'SET interval_type = 0 ' .
'WHERE {prefix}invoice.id = ?';
dbParamQuery($strQuery, [$intInvoiceId], 'exception');
$paymentDays = getPaymentDays($invoiceData['company_id']);

unset($invoiceData['id']);
unset($invoiceData['invoice_no']);
$invoiceData['deleted'] = 0;
$invoiceData['invoice_date'] = date('Ymd');
$invoiceData['due_date'] = date(
'Ymd', mktime(0, 0, 0, date('m'), date('d') + $paymentDays, date('Y'))
);
$invoiceData['payment_date'] = null;
$invoiceData['state_id'] = 1;
$invoiceData['archived'] = false;
$invoiceData['refunded_invoice_id'] = null;
$invoiceData['interval_type'] = 0;
$invoiceData['next_interval_date'] = null;
$invoiceData['template_invoice_id'] = $templateId;

dbQueryCheck('SET AUTOCOMMIT = 0');
dbQueryCheck('BEGIN');

try {
$strQuery = 'INSERT INTO {prefix}invoice(' .
implode(', ', array_keys($invoiceData)) . ') ' . 'VALUES (' .
str_repeat('?, ', count($invoiceData) - 1) . '?)';

dbParamQuery($strQuery, array_values($invoiceData), 'exception');
$intNewId = mysqli_insert_id($dblink);
if (!$intNewId) {
die('Could not get ID of the new invoice');
}
$newRowDate = date('Ymd');
$strQuery = 'SELECT * ' . 'FROM {prefix}invoice_row WHERE deleted=0 AND invoice_id=?';
$rows = dbParamQuery($strQuery, [$templateId], 'exception');
foreach ($rows as $row) {
if ($boolRefund) {
$row['pcs'] = -$row['pcs'];
if ($row['partial_payment']) {
$row['price'] = -$row['price'];
}
} elseif ($row['reminder_row']) {
continue;
}
unset($row['id']);
$row['invoice_id'] = $intNewId;

$strQuery = 'INSERT INTO {prefix}invoice(' .
implode(', ', array_keys($invoiceData)) . ') ' . 'VALUES (' .
str_repeat('?, ', count($invoiceData) - 1) . '?)';

dbParamQuery($strQuery, array_values($invoiceData), 'exception');
$intNewId = mysqli_insert_id($dblink);
if (!$intNewId) {
die('Could not get ID of the new invoice');
if ($row['row_date']) {
$row['row_date'] = $newRowDate;
}
$newRowDate = date('Ymd');
$strQuery = 'SELECT * ' . 'FROM {prefix}invoice_row ' .
'WHERE deleted=0 AND invoice_id=?';
$rows = dbParamQuery($strQuery, [$intInvoiceId], 'exception');
foreach ($rows as $row) {
if ($boolRefund) {
$row['pcs'] = -$row['pcs'];
if ($row['partial_payment']) {
$row['price'] = -$row['price'];
}
} elseif ($row['reminder_row']) {
continue;
}
unset($row['id']);
$row['invoice_id'] = $intNewId;

if (getSetting('invoice_update_row_dates_on_copy')) {
$row['row_date'] = $newRowDate;
}
// Update product stock balance
if (!$isOffer && !$isTemplate && $row['product_id'] !== null) {
updateProductStockBalance(null, $row['product_id'], $row['pcs']);
}
$strQuery = 'INSERT INTO {prefix}invoice_row(' .
implode(', ', array_keys($row)) . ') ' . 'VALUES (' .
str_repeat('?, ', count($row) - 1) . '?)';
dbParamQuery($strQuery, $row, 'exception');
// Update product stock balance
if (!$isOffer && !$isTemplate && $row['product_id'] !== null) {
updateProductStockBalance(null, $row['product_id'], $row['pcs']);
}

// Update interval of the template:
$template = getInvoice($templateId);
advanceInvoiceIntervalData($template);
updateInvoice($template);
} catch (Exception $e) {
dbQueryCheck('ROLLBACK');
dbQueryCheck('SET AUTOCOMMIT = 1');
die($e->getMessage());
$strQuery = 'INSERT INTO {prefix}invoice_row(' .
implode(', ', array_keys($row)) . ') ' . 'VALUES (' .
str_repeat('?, ', count($row) - 1) . '?)';
dbParamQuery($strQuery, $row, 'exception');
}
dbQueryCheck('COMMIT');

// Update interval of the template:
$template = getInvoice($templateId);
advanceInvoiceIntervalDate($template);
updateInvoice($template);
} catch (Exception $e) {
dbQueryCheck('ROLLBACK');
dbQueryCheck('SET AUTOCOMMIT = 1');
die($e->getMessage());
}
dbQueryCheck('COMMIT');
dbQueryCheck('SET AUTOCOMMIT = 1');

$_SESSION['formWarningMessage'] = Translator::Translate('CheckCreatedInvoice');
header("Location: index.php?func=$strFunc&list=$strList&form=invoice&id=$intNewId");
2 changes: 1 addition & 1 deletion css/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* dataTables display
*/

tr.overdue td.due-date {
tr.overdue td.due-date, tr.due td.next-interval-date {
&, &.sorting_1, &.sorting_2, &.sorting_3 {
background-color: #FFCCDD;
}
Expand Down
2 changes: 1 addition & 1 deletion css/style.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion css/style.css.map

Large diffs are not rendered by default.

26 changes: 18 additions & 8 deletions form.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,23 @@ function createForm($strFunc, $strList, $strForm)
}

$strMessage = '';
if (isset($_SESSION['formMessage']) && $_SESSION['formMessage']) {
$strMessage = Translator::translate($_SESSION['formMessage']);
if ($msg = $_SESSION['formMessage'] ?? null) {
$strMessage = Translator::translate($msg);
unset($_SESSION['formMessage']);
}

$strErrorMessage = '';
if (isset($_SESSION['formErrorMessage']) && $_SESSION['formErrorMessage']) {
$strErrorMessage = Translator::translate($_SESSION['formErrorMessage']);
if ($msg = $_SESSION['formErrorMessage'] ?? null) {
$strErrorMessage = Translator::translate($msg);
unset($_SESSION['formErrorMessage']);
}

$strWarningMessage = '';
if ($msg = $_SESSION['formWarningMessage'] ?? null) {
$strWarningMessage = Translator::translate($msg);
unset($_SESSION['formWarningMessage']);
}

if ('new' === $action) {
$formConfig['readOnly'] = false;
}
Expand Down Expand Up @@ -202,7 +208,7 @@ function createForm($strFunc, $strList, $strForm)
$strForm, $formConfig, $intKeyValue ? false : true, true, $recordDeleted
);

if ($strForm == 'invoice' && !empty($astrValues['next_interval_date'])
if ($strForm == 'invoice_template' && !empty($astrValues['next_interval_date'])
&& strDate2UnixTime($astrValues['next_interval_date']) <= time()
) {
?>
Expand Down Expand Up @@ -427,6 +433,11 @@ function ($s) {
MLInvoice.errormsg(<?php echo json_encode($strErrorMessage)?>);
<?php
}
if ($strWarningMessage) {
?>
MLInvoice.warningmsg(<?php echo json_encode($strWarningMessage)?>, 5000);
<?php
}
if ($strForm == 'product') {
?>
MLInvoice.Form.updateStockBalanceLog();
Expand Down Expand Up @@ -1101,7 +1112,7 @@ function createFormButtons($form, $formConfig, $new, $top, $deleted)
?>
<div class="btn-set">
<a id="linked_invoices_button" class="btn btn-secondary" role="button" aria-expanded="false">
<?php echo Translator::translate('Created Invoices')?>
<?php echo Translator::translate('CreatedInvoices')?>
(<span class="linked-invoice-count"><?php echo count($linkedInvoices)?></span>)
<span class="dropdown-open"><i class="icon-down-dir"></i><span class="visually-hidden"><?php echo Translator::translate('Show')?></span></span>
<span class="dropdown-close hidden"><i class="icon-up-dir"></i><span class="visually-hidden"><?php echo Translator::translate('Hide')?></span></span>
Expand Down Expand Up @@ -1185,7 +1196,6 @@ function createFormButtons($form, $formConfig, $new, $top, $deleted)
<th><?php echo Translator::translate('HeaderInvoiceName') ?></th>
<th><?php echo Translator::translate('HeaderInvoiceReference') ?></th>
<th><?php echo Translator::translate('HeaderInvoiceState') ?></th>
<th><?php echo Translator::translate('HeaderInvoiceTotal') ?></th>
</tr>
</thead>
<tbody>
Expand All @@ -1202,7 +1212,6 @@ function createFormButtons($form, $formConfig, $new, $top, $deleted)
<td><?php echo escapeHtml($linkedInvoice['name'])?></td>
<td><?php echo escapeHtml($linkedInvoice['reference'])?></td>
<td><?php echo Translator::translate($linkedInvoice['state'])?></td>
<td><?php echo miscRound2Decim($linkedInvoice['row_total'] ?? 0)?></td>
</tr>
<?php
if (++$linkCount === 10) {
Expand All @@ -1211,6 +1220,7 @@ function createFormButtons($form, $formConfig, $new, $top, $deleted)
...
</td>
<?php
break;
}
}
?>
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
} elseif ($strFunc == 'archived_invoices') {
createList('archived_invoices', 'archived_invoices', 'archived_invoices', '', Search::SEARCH_ARCHIVED_INVOICES, false, false, 'invoice');
} elseif ($strFunc == 'invoice_templates') {
createList('invoice_templates', 'invoice_templates', 'invoice_templates', '', Search::SEARCH_RECURRING_INVOICE_TEMPLATES, false, false, 'invoice');
createList('invoice_templates', 'invoice_templates', 'invoice_templates', '', Search::SEARCH_RECURRING_INVOICE_TEMPLATES, false, true, 'invoice');
} elseif ($strFunc == 'offers') {
createList($strFunc, $strList, '', '', Search::SEARCH_NON_ARCHIVED_OFFERS, false, false, 'invoice');
} elseif ($strFunc == 'archived_offers') {
Expand Down
6 changes: 6 additions & 0 deletions js/mlinvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ var MLInvoice = (function CreateMLInvoice() {
infomsg(msg, timeout, 'text-white bg-danger');
}

function warningmsg(msg, timeout)
{
infomsg(msg, timeout, 'bg-warning');
}

function clearMessages()
{
$('#toasts').html('');
Expand Down Expand Up @@ -803,6 +808,7 @@ var MLInvoice = (function CreateMLInvoice() {
updateRowSelectedState: updateRowSelectedState,
infomsg: infomsg,
errormsg: errormsg,
warningmsg: warningmsg,
editUnitPrice: editUnitPrice,
setCurrencyDecimals: setCurrencyDecimals,
getDateFormat: getDateFormat,
Expand Down
4 changes: 2 additions & 2 deletions js/mlinvoice.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/mlinvoice.min.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions lang/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ ServerError = 'Error from server'
CannotDeleteCurrentUser = 'Cannot delete currently logged-in user'
RecurringInvoiceDueForProcessing = 'This recurring invoice is due for processing'
RecurringInvoicesDueForProcesing = 'There are recurring invoices due for processing'
CheckCreatedInvoice = 'Check created invoice'
CheckUpdatedInvoice = 'Check updated invoice'

; Updater
UpdateAvailable = '(update v{version} available)'
Expand Down Expand Up @@ -461,9 +463,10 @@ RecurringInvoiceTemplate = 'Recurring invoice template'
RecurringInvoiceTemplates = 'Recurring invoice templates'
NewRecurringInvoiceTemplate = 'New Recurring Invoice Template'
AddToInvoice = 'Add to Invoice'
AddToExistingOpenInvoice = 'Add to the Existing Open Invoice'
CreateNewInvoice = 'Create a New Invoice'
AddToExistingOpenInvoice = 'Add to Existing Open Invoice'
CreateNewInvoice = 'Create New Invoice'
ShowRecurringInvoiceTemplate = 'Show Template'
CreatedInvoices = 'Created Invoices'

; Email
SendEmail = 'Send Email'
Expand Down
4 changes: 4 additions & 0 deletions lang/fi-FI.ini
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ ServerError = 'Virhe palvelimelta'
CannotDeleteCurrentUser = 'Kirjautuneena olevaa käyttäjää ei voida poistaa'
RecurringInvoiceDueForProcessing = 'Tämä toistuva lasku odottaa käsittelyä'
RecurringInvoicesDueForProcesing = 'Käsittelyä odottavia toistuvia laskuja'
CheckCreatedInvoice = 'Tarkista luotu lasku'
CheckUpdatedInvoice = 'Tarkista päivitetty lasku'

; Updater
UpdateAvailable = '(päivitys v{version} saatavissa)'
Expand Down Expand Up @@ -462,6 +464,8 @@ NewRecurringInvoiceTemplate = 'Uusi toistuvan laskun malli'
AddToInvoice = 'Lisää laskulle'
AddToExistingOpenInvoice = 'Lisää olemassaolevaan avoimeen laskuun'
CreateNewInvoice = 'Luo uusi lasku'
ShowRecurringInvoiceTemplate = 'Näytä malli'
CreatedInvoices = 'Luodut laskut'

; Email
SendEmail = 'Sähköpostin lähetys'
Expand Down
4 changes: 4 additions & 0 deletions lang/sv-FI.ini
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ ServerError = 'Fel från servern'
CannotDeleteCurrentUser = 'Kan inte radera inloggad användare'
RecurringInvoiceDueForProcessing = 'Denna återkommande faktura ska behandlas'
RecurringInvoicesDueForProcesing = 'Det finns återkommande fakturor som ska behandlas'
CheckCreatedInvoice = 'Kontrollera skapad faktura'
CheckUpdatedInvoice = 'Kontrollera uppdaterad faktura'

; Updater
UpdateAvailable = '(uppdatering till v{version} tillgänglig)'
Expand Down Expand Up @@ -465,6 +467,8 @@ NewRecurringInvoiceTemplate = 'Ny mall för en återkommande faktura'
AddToInvoice = 'Lägg till på faktura'
AddToExistingOpenInvoice = 'Lägg till i den befintliga öppna fakturan'
CreateNewInvoice = 'Skapa en ny faktura'
ShowRecurringInvoiceTemplate = 'Visa mallen'
CreatedInvoices = 'Skapade fakturor'

; Email
SendEmail = 'Skicka per e-post'
Expand Down
17 changes: 16 additions & 1 deletion list.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ function createList($strFunc, $strList, $strTableName = '', $strTitleOverride =
$class = 'editable';
} elseif ('i.due_date' === $field['name']) {
$class = 'due-date';
} elseif ('i.next_interval_date' === $field['name']) {
$class = 'next-interval-date';
}
$visible = !isset($field['visible']) || $field['visible'] ? 'true' : 'false';
?>
Expand Down Expand Up @@ -626,7 +628,7 @@ function createJSONList(
$resultValues[] = $value;

// Special colouring for overdue invoices
if ($highlight && $name == 'due_date') {
if ($highlight && 'invoices' === $strList && $name == 'due_date') {
$rowDue = dbDate2UnixTime($row['due_date']);
if ($rowDue < mktime(0, 0, 0, date("m"), date("d") - 14, date("Y"))
) {
Expand All @@ -640,6 +642,19 @@ function createJSONList(
$rowClass = 'overdue';
}
}

// Special colouring for due/overdue invoice templates
if ($highlight
&& 'invoice_templates' === $strList
&& $name == 'next_interval_date'
&& $row['next_interval_date']
) {
$nextDate = dbDate2UnixTime($row['next_interval_date']);
if ($nextDate <= mktime(0, 0, 0, date("m"), date("d"), date("Y"))
) {
$rowClass = 'due';
}
}
}
$class = trim("$rowClass$deleted");
if ($class) {
Expand Down
2 changes: 1 addition & 1 deletion list_switch.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
'width' => 60,
'type' => 'INTDATE',
'header' => 'HeaderInvoiceNextIntervalDate',
'visible' => false,
'visible' => 'invoice_templates' === $strList,
],
[
'name' => 'i.ref_number',
Expand Down
Loading

0 comments on commit b833eef

Please sign in to comment.