Added manual editing of the paid status for expense items.
authorNik Okuntseff <support@anuko.com>
Mon, 22 Jan 2018 17:00:46 +0000 (17:00 +0000)
committerNik Okuntseff <support@anuko.com>
Mon, 22 Jan 2018 17:00:46 +0000 (17:00 +0000)
WEB-INF/lib/ttExpenseHelper.class.php
WEB-INF/templates/expense_edit.tpl
WEB-INF/templates/footer.tpl
expense_edit.php
time_edit.php

index c41a141..ff7879c 100644 (file)
@@ -56,6 +56,7 @@ class ttExpenseHelper {
   // update - updates a record in tt_expense_items table.
   static function update($fields)
   {
+    global $user;
     $mdb2 = getConnection();
 
     $id = (int) $fields['id'];
@@ -67,9 +68,14 @@ class ttExpenseHelper {
     $cost = str_replace(',', '.', $fields['cost']);
     $invoice_id = $fields['invoice_id'];
 
+    $paid_part = '';
+    if ($user->canManageTeam() && $user->isPluginEnabled('ps')) {
+      $paid_part = $fields['paid'] ? ', paid = 1' : ', paid = 0';
+    }
+
     $sql = "UPDATE tt_expense_items set date = ".$mdb2->quote($date).", user_id = $user_id, client_id = ".$mdb2->quote($client_id).
       ", project_id = ".$mdb2->quote($project_id).", name = ".$mdb2->quote($name).
-      ", cost = ".$mdb2->quote($cost).", invoice_id = ".$mdb2->quote($invoice_id).
+      ", cost = ".$mdb2->quote($cost)."$paid_part, invoice_id = ".$mdb2->quote($invoice_id).
       " WHERE id = $id";
 
     $affected = $mdb2->exec($sql);
@@ -122,7 +128,7 @@ class ttExpenseHelper {
     if ($user->isPluginEnabled('cl'))
       $left_joins .= " left join tt_clients c on (ei.client_id = c.id)";
 
-    $sql = "select ei.id, ei.date, ei.client_id, ei.project_id, ei.name, ei.cost, ei.invoice_id $client_field, p.name as project_name
+    $sql = "select ei.id, ei.date, ei.client_id, ei.project_id, ei.name, ei.cost, ei.invoice_id, ei.paid $client_field, p.name as project_name
       from tt_expense_items ei
       $left_joins
       where ei.id = $id and ei.user_id = $user_id and ei.status = 1";
index bcd393a..39198b8 100644 (file)
@@ -150,6 +150,12 @@ function recalculateCost() {
       <td align="right">{$i18n.label.cost}:</td>
       <td>{$forms.expenseItemForm.cost.control} {$user->currency|escape}</td>
     </tr>
+{if ($user->canManageTeam() && $user->isPluginEnabled('ps'))}
+    <tr>
+      <td align="right">&nbsp;</td>
+      <td><label>{$forms.expenseItemForm.paid.control}{$i18n.label.paid}</label></td>
+    </tr>
+{/if}
     <tr>
       <td align="right">{$i18n.label.date}:</td>
       <td>{$forms.expenseItemForm.date.control}</td>
index fa6d568..9e1b82e 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.17.0.3776 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.17.1.3777 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
index 7a256d6..d7d815c 100644 (file)
@@ -56,12 +56,15 @@ if ($request->isPost()) {
   $cl_project = $request->getParameter('project');
   $cl_item_name = trim($request->getParameter('item_name'));
   $cl_cost = trim($request->getParameter('cost'));
+  if ($user->isPluginEnabled('ps'))
+    $cl_paid = $request->getParameter('paid');
 } else {
   $cl_date = $item_date->toString($user->date_format);
   $cl_client = $expense_item['client_id'];
   $cl_project = $expense_item['project_id'];
   $cl_item_name = $expense_item['name'];
   $cl_cost = $expense_item['cost'];
+  $cl_paid = $expense_item['paid'];
 }
 
 // Initialize elements of 'expenseItemForm'.
@@ -134,6 +137,8 @@ if ($predefined_expenses) {
 }
 $form->addInput(array('type'=>'textarea','maxlength'=>'800','name'=>'item_name','style'=>'width: 250px; height:'.NOTE_INPUT_HEIGHT.'px;','value'=>$cl_item_name));
 $form->addInput(array('type'=>'text','maxlength'=>'40','name'=>'cost','style'=>'width: 100px;','value'=>$cl_cost));
+if ($user->canManageTeam() && $user->isPluginEnabled('ps'))
+  $form->addInput(array('type'=>'checkbox','name'=>'paid','value'=>$cl_paid));
 $form->addInput(array('type'=>'datefield','name'=>'date','maxlength'=>'20','value'=>$cl_date));
 // Hidden control for record id.
 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id));
@@ -181,7 +186,7 @@ if ($request->isPost()) {
     // Now, an update.
     if ($err->no()) {
       if (ttExpenseHelper::update(array('id'=>$cl_id,'date'=>$new_date->toString(DB_DATEFORMAT),'user_id'=>$user->getActiveUser(),
-          'client_id'=>$cl_client,'project_id'=>$cl_project,'name'=>$cl_item_name,'cost'=>$cl_cost))) {
+          'client_id'=>$cl_client,'project_id'=>$cl_project,'name'=>$cl_item_name,'cost'=>$cl_cost,'paid'=>$cl_paid))) {
         header('Location: expenses.php?date='.$new_date->toString(DB_DATEFORMAT));
         exit();
       }
index b656c23..6628ce3 100644 (file)
@@ -206,7 +206,7 @@ if ($custom_fields && $custom_fields->fields[0]) {
 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id));
 if ($user->isPluginEnabled('iv'))
   $form->addInput(array('type'=>'checkbox','name'=>'billable','value'=>$cl_billable));
-if ($user->isPluginEnabled('ps'))
+if ($user->canManageTeam() && $user->isPluginEnabled('ps'))
   $form->addInput(array('type'=>'checkbox','name'=>'paid','value'=>$cl_paid));
 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save or btn_copy click.
 $form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date()','value'=>$i18n->getKey('button.save')));