Example #1
0
    // Formated date (localized)
    $fmt_amount = number_format($tr->amount, 2, ',', ' ');
    // Formated amount
    $amount_color = $tr->amount > 0 ? "#e0ffe0" : "#ffe0e0";
    $balance = $balance_lines[$tr->id];
    $balance_color = $balance > 0 ? "#e0ffe0" : "#ffe0e0";
    $fmt_balance = number_format($balance, 2, ',', ' ');
    // Formated balance
    $help_edit = addslashes(_('Click to modify this transaction'));
    $class = $count % 2 ? "row_odd" : "row_even";
    if ($tr->type == "prevision" and $tr->ts_date < mktime(23, 59, 59, date("m"), date("d") - 1, date("Y"))) {
        $class = "row_error";
    }
    $file = "";
    $File = new FileTransaction();
    $files = $File->getFiles($tr->id);
    foreach ($files as $file_object) {
        $file .= sprintf("<a href='save_transaction?action=file&id_file=%d' title='%s'><img src='/imgs/icons/attachment.png'/></a>", $file_object->id_file, $file_object->name);
    }
    if (isset($view) and $view == "edit" and $User->hasRole("manager", $_SESSION['id_user'])) {
        ?>
  <input type="hidden" name="query" value="?view=edit&<?php 
        echo $GLOBALS['_SERVER']['QUERY_STRING'];
        ?>
" />

<tr class="<?php 
        echo $class;
        ?>
">
  <td>
$amount = preg_replace("! +!", "", $amount);
if (empty($date)) {
    $date = date('d/m/Y');
}
if ($id_transaction > 0) {
    $q = sprintf("UPDATE webfinance_transactions SET " . "id_category=%d, " . "id_account=%d, " . "text='%s', " . "amount='%s', " . "exchange_rate='%s', " . "type='%s', " . "date=str_to_date('%s', '%%d/%%m/%%Y'), " . "comment='%s' " . "WHERE id=%d", $id_category, $id_account, $text, $amount, $exchange_rate, $type, $date, $comment, $id_transaction);
    mysql_query($q) or wf_mysqldie();
} else {
    $q = sprintf("INSERT INTO webfinance_transactions SET " . "id_category=%d, " . "id_account=%d, " . "text='%s', " . "amount=%s, " . "exchange_rate='%s', " . "type='%s', " . "date=str_to_date('%s', '%%d/%%m/%%Y'), " . "comment='%s' ", $id_category, $id_account, $text, $amount, $exchange_rate, $type, $date, $comment);
    mysql_query($q) or wf_mysqldie();
    $id_transaction = mysql_insert_id();
}
//fichiers attachés
$File = new FileTransaction();
if (isset($file_del)) {
    $files = $File->getFiles($id_transaction);
    foreach ($files as $file) {
        if (!array_key_exists($file->id_file, $file_del)) {
            $File->deleteFile($file->id_file);
        }
    }
} else {
    $File->deleteAllFiles($id_transaction);
}
if (isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
    $File->addFile($_FILES['file'], $id_transaction);
}
//factures liées
if (isset($id_invoices)) {
    mysql_query("DELETE FROM webfinance_transaction_invoice WHERE id_transaction={$id_transaction}") or wf_mysqldie();
    $id_invoices = array_unique($id_invoices);
?>
 </select>
</td>
</tr>

<tr>
  <td colspan="4"><?php 
echo _('File');
?>
 :</td>
</tr>
<tr>
 <td colspan="4">
  <?php 
$File = new FileTransaction();
$files = $File->getFiles($transaction->id);
foreach ($files as $file) {
    printf("<input checked='checked' name='file_del[%d]' type='checkbox' /><a href='save_transaction?action=file&id_file=%d'>%s</a><br/>", $file->id_file, $file->id_file, $file->name);
}
?>
 </td>
</tr>
<tr>
  <td></td>
 <td colspan="3"><input type="file" size="40"  name="file" /></td>
</tr>
<tr>
  <td colspan="4" style="text-align: center">
    <input id="submit_button" type="submit" value="<?php 
echo _('Save');
?>