- Updated task editing template to handle default status for new tasks and corrected variable names. - Enhanced work time reporting by rounding time to the nearest quarter hour and adjusting amount formatting. - Introduced TasksController to manage task-related operations, including status resolution and email notifications. - Added TaskAttachmentRepository for handling task attachments, including upload, rename, and delete functionalities. - Implemented WorkTimeRepository to fetch clients with unsettled tasks and calculate total work time. - Created unit tests for TasksController and TaskAttachmentRepository to ensure functionality and correctness.
355 lines
9.7 KiB
PHP
355 lines
9.7 KiB
PHP
<?
|
|
global $db;
|
|
|
|
ob_start();
|
|
?>
|
|
<?=
|
|
\Html::input(
|
|
[
|
|
'label' => 'Nazwa',
|
|
'name' => 'name',
|
|
'id' => 'name',
|
|
'value' => $this -> task[ 'name' ],
|
|
'class' => 'require',
|
|
'inline' => true
|
|
]
|
|
);
|
|
?>
|
|
<?=
|
|
\Html::textarea(
|
|
[
|
|
'label' => 'Treść',
|
|
'name' => 'text',
|
|
'id' => 'text',
|
|
'value' => $this -> task[ 'text' ],
|
|
'rows' => 10
|
|
]
|
|
);
|
|
?>
|
|
<?
|
|
if ( $this -> task['date_start'] )
|
|
$date_start = date( 'Y-m-d', strtotime( $this -> task['date_start'] ) );
|
|
else
|
|
{
|
|
if ( !$this -> task['id'] )
|
|
$date_start = date( 'Y-m-d' );
|
|
}
|
|
|
|
if ( $this -> task['date_end'] )
|
|
$date_end = date( 'Y-m-d', strtotime( $this -> task['date_end'] ) );
|
|
else
|
|
{
|
|
if ( !$this -> task['id'] )
|
|
$date_end = date( 'Y-m-d' );
|
|
}
|
|
?>
|
|
<?= \Html::input([
|
|
'label' => 'Data rozpoczęcia',
|
|
'name' => 'date_start',
|
|
'id' => 'date_start',
|
|
'value' => $date_start,
|
|
'class' => 'datetime',
|
|
'inline' => true,
|
|
'autocomplete' => 'off'
|
|
]);?>
|
|
<?= \Html::input([
|
|
'label' => 'Data zakończenia',
|
|
'name' => 'date_end',
|
|
'id' => 'date_end',
|
|
'value' => $date_end,
|
|
'class' => 'datetime',
|
|
'inline' => true,
|
|
'autocomplete' => 'off'
|
|
]);?>
|
|
<?
|
|
$projects[ 0 ] = '--- wybierz projekt ---';
|
|
if ( is_array( $this -> projects ) )
|
|
foreach ( $this -> projects as $project )
|
|
{
|
|
$projects[ $project[ 'id' ] ] = $project[ 'name' ];
|
|
if ( (int)$project['client_id'] )
|
|
$projects[ $project['id'] ] .= ' (' . \factory\Crm::get_client_name( (int)$project[ 'client_id' ] ) . ')';
|
|
}
|
|
?>
|
|
<?
|
|
if ( $this -> task['project_id'] )
|
|
$project_id = $this -> task[ 'project_id' ];
|
|
else
|
|
{
|
|
if ( !$this -> task['id'] )
|
|
$project_id = 72;
|
|
}
|
|
?>
|
|
<?= \Html::select([
|
|
'label' => 'Projekt',
|
|
'name' => 'project_id',
|
|
'id' => 'project_id',
|
|
'value' => $project_id,
|
|
'values' => $projects
|
|
]);?>
|
|
<?
|
|
$clients[ 0 ] = '--- wybierz klienta ---';
|
|
if ( is_array( $this -> clients ) )
|
|
foreach ( $this -> clients as $client )
|
|
$clients[ $client[ 'id' ] ] = $client[ 'firm' ];
|
|
?>
|
|
<?=
|
|
\Html::select( [
|
|
'label' => 'Klient',
|
|
'name' => 'client_id',
|
|
'id' => 'client_id',
|
|
'value' => $this -> task[ 'id' ] ? $this -> task[ 'client_id' ] : 0,
|
|
'values' => $clients
|
|
] );
|
|
?>
|
|
<!-- zadanie nadrzędne -->
|
|
<?
|
|
$parent_tasks[ 0 ] = '--- wybierz zadanie nadrzędne ---';
|
|
if ( is_array( $this -> parent_tasks ) )
|
|
foreach ( $this -> parent_tasks as $parent_task )
|
|
$parent_tasks[ $parent_task[ 'id' ] ] = $parent_task[ 'name' ] . ( $parent_task['client'] ? ' (' . $parent_task['client'] . ')' : '' );
|
|
?>
|
|
<?
|
|
\Html::select( [
|
|
'label' => 'Zadanie nadrzędne',
|
|
'name' => 'parent_id',
|
|
'id' => 'parent_id',
|
|
'value' => $this -> task[ 'parent_id' ],
|
|
'values' => $parent_tasks
|
|
] );
|
|
?>
|
|
<?= \Html::select( [
|
|
'label' => 'Status',
|
|
'name' => 'status',
|
|
'id' => 'status',
|
|
'value' => $this -> task[ 'id' ] ? $this -> task[ 'status' ] : 5,
|
|
'values' => \factory\Tasks::get_statuses()
|
|
] );?>
|
|
<!-- priorytet -->
|
|
<?
|
|
$priorities[ 0 ] = '--- wybierz priorytet ---';
|
|
if ( is_array( $this -> priorities ) )
|
|
foreach ( $this -> priorities as $priority )
|
|
$priorities[ $priority[ 'id' ] ] = $priority[ 'name' ];
|
|
?>
|
|
<?=
|
|
\Html::select( [
|
|
'label' => 'Priorytet',
|
|
'name' => 'priority',
|
|
'id' => 'priority',
|
|
'value' => $this -> task[ 'priority' ],
|
|
'values' => $this -> priorities
|
|
] );
|
|
?>
|
|
<? if ( $this -> user['id'] == 1 ):?>
|
|
<?= \Html::input([
|
|
'label' => 'Stawka',
|
|
'name' => 'pay_rate',
|
|
'id' => 'pay_rate',
|
|
'value' => $this -> task[ 'pay_rate' ],
|
|
'class' => 'price',
|
|
'inline' => true,
|
|
'autocomplete' => 'off'
|
|
]);?>
|
|
<? endif;?>
|
|
<?=
|
|
\Html::input_switch( [
|
|
'label' => 'Powiadom o zmianie statusu',
|
|
'name' => 'status_change_mail',
|
|
'id' => 'status_change_mail',
|
|
'checked' => ( $this -> task[ 'status_change_mail' ] or !$this -> task['id'] ) ? true : false,
|
|
'type' => 'checkbox'
|
|
] );
|
|
?>
|
|
<div class="form_group">
|
|
<label class="label">Uczestnicy:</label>
|
|
<div class="input">
|
|
<? if ( is_array( $this -> users ) ): foreach ( $this -> users as $user ):?>
|
|
<div class="name" id="user-<?= $user[ 'id' ];?>">
|
|
<label for="user-<?= $user[ 'id' ];?>">
|
|
<input type="checkbox" class="g-checkbox" name="users" value="<?= $user[ 'id' ];?>" <? if ( in_array( $user[ 'id' ], $this -> task[ 'users' ] ) ):?>checked="checked"<? endif;?>>
|
|
<?= $user[ 'name' ] . ' ' . $user[ 'surname' ];?>
|
|
</label>
|
|
</div>
|
|
<? endforeach; endif;?>
|
|
</div>
|
|
</div>
|
|
<?=
|
|
\Html::input( [
|
|
'label' => 'Przypomnij x dni przed',
|
|
'name' => 'reminders_interval',
|
|
'value' => $this -> task[ 'reminders_interval' ],
|
|
'inline' => true
|
|
] );
|
|
?>
|
|
<?=
|
|
\Html::input_switch( [
|
|
'label' => 'Powtarzaj',
|
|
'name' => 'recursively',
|
|
'id' => 'recursively',
|
|
'checked' => $this -> task[ 'recursively' ] ? true : false,
|
|
'type' => 'checkbox'
|
|
] );
|
|
?>
|
|
<div class="form_group" id="recursive-details" style="<?= $this -> task[ 'recursively' ] ? '' : 'display: none;';?>">
|
|
<label class="label">Powtarzaj co:</label>
|
|
<div class="input" style="display: flex; gap: 10px; align-items: center;">
|
|
<input type="text" class="form-control" name="frequency" style="max-width: 110px;" value="<?= $this -> task[ 'id' ] ? $this -> task[ 'frequency' ] : 1;?>">
|
|
<select name="period" class="form-control" style="max-width: 140px;">
|
|
<option value="1" <? if ( $this -> task[ 'period' ] == '1' ):?>selected="selected"<? endif;?>>dni</option>
|
|
<option value="2" <? if ( $this -> task[ 'period' ] == '2' ):?>selected="selected"<? endif;?>>m-ce</option>
|
|
<option value="3" <? if ( $this -> task[ 'period' ] == '3' ):?>selected="selected"<? endif;?>>lata</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<?=
|
|
\Html::input_switch( [
|
|
'label' => 'Powiadom użytkowników mailem',
|
|
'name' => 'send_email_notification',
|
|
'id' => 'send_email_notification',
|
|
'checked' => false,
|
|
'type' => 'checkbox'
|
|
] );
|
|
?>
|
|
<?=
|
|
\Html::input_switch( [
|
|
'label' => 'Pokaż w kalendarzu',
|
|
'name' => 'show_in_calendar',
|
|
'id' => 'show_in_calendar',
|
|
'checked' => ( $this -> task[ 'show_in_calendar' ] or !$this -> task['id'] ) ? true : false,
|
|
'type' => 'checkbox'
|
|
] );
|
|
?>
|
|
<? if ( $this -> task['id'] ):?>
|
|
<div class="form-group row">
|
|
<label class="col-md-3 col-form-label"></label>
|
|
<div class="col-md-9">
|
|
<a href="#" class="btn btn-danger task-remove" task-id="<?= $this -> task['id'];?>">
|
|
<i class="fa fa-trash"></i>
|
|
Usuń zadanie
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<? endif;?>
|
|
<?
|
|
$this -> task[ 'id' ] ? $project_id = $this -> task[ 'project_id' ] : $project_id = $this -> project_id;
|
|
|
|
$out = ob_get_clean();
|
|
|
|
$grid = new \gridEdit;
|
|
$grid -> id = 'task-edit';
|
|
$grid -> gdb_opt = $gdb;
|
|
$grid -> include_plugins = true;
|
|
$grid -> title = 'Edycja <strong>zadania</strong>';
|
|
$grid -> fields = [
|
|
[
|
|
'db' => 'id',
|
|
'type' => 'hidden',
|
|
'value' => $this -> task[ 'id' ]
|
|
]
|
|
];
|
|
$grid -> external_code = $out;
|
|
$grid -> actions = [
|
|
'save' => [ 'url' => '/tasks/task_save/', 'back_url' => '/tasks/main_view/' ],
|
|
'cancel' => [ 'url' => '/tasks/main_view/' ]
|
|
];
|
|
$grid -> persist_edit = true;
|
|
$grid -> id_param = 'id';
|
|
echo $grid -> draw();
|
|
?>
|
|
<script type="text/javascript" src="/libraries/ckeditor/ckeditor.js"></script>
|
|
<script type="text/javascript" src="/libraries/ckeditor/adapters/jquery.js"></script>
|
|
<script type="text/javascript">
|
|
$(document).ready(function ()
|
|
{
|
|
function toggleRecursiveDetails() {
|
|
if ( $( '#recursively' ).is( ':checked' ) )
|
|
$( '#recursive-details' ).show();
|
|
else
|
|
$( '#recursive-details' ).hide();
|
|
}
|
|
|
|
$('input[type="checkbox"]').iCheck({
|
|
checkboxClass: 'icheckbox_square-blue',
|
|
radioClass: 'iradio_square-blue',
|
|
});
|
|
|
|
toggleRecursiveDetails();
|
|
|
|
$( '#recursively' ).on( 'ifChanged change', function() {
|
|
toggleRecursiveDetails();
|
|
});
|
|
|
|
$( 'body' ).on( 'click', '.task-remove', function(e)
|
|
{
|
|
e.preventDefault();
|
|
var task_id = $( this ).attr( 'task-id' );
|
|
|
|
$.confirm(
|
|
{
|
|
title: 'Potwierdź',
|
|
type: 'orange',
|
|
columnClass: 'col-md-8 col-md-offset-2 col-12',
|
|
closeIcon: true,
|
|
closeIconClass: 'fa fa-close',
|
|
content: 'Na pewno chcesz usunąć wybrane zadanie?',
|
|
theme: 'modern',
|
|
buttons: {
|
|
submit: {
|
|
text: '<i class="fa fa-check"></i>Zatwierdź',
|
|
btnClass: 'btn-success',
|
|
keys: ['enter'],
|
|
action: function ()
|
|
{
|
|
$.ajax(
|
|
{
|
|
type: 'POST',
|
|
cache: false,
|
|
url: '/projects/task_delete/',
|
|
data:
|
|
{
|
|
task_id: task_id
|
|
},
|
|
beforeSend: function()
|
|
{},
|
|
success: function( response )
|
|
{
|
|
document.location.href = "<?= $this -> referer;?>";
|
|
}
|
|
});
|
|
}
|
|
},
|
|
cancel: {
|
|
text: '<i class="fa fa-close"></i>Anuluj',
|
|
btnClass: 'btn-danger',
|
|
action: function() {}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
$('textarea#text').ckeditor(
|
|
{
|
|
toolbar: 'Basic',
|
|
language: 'pl',
|
|
height: '100'
|
|
});
|
|
|
|
$( '#project_id, #client_id, #status' ).select2({
|
|
theme: 'bootstrap-5',
|
|
minimumResultsForSearch: 0
|
|
});
|
|
|
|
$( '#project_id, #client_id, #status' ).on( 'select2:open', function() {
|
|
setTimeout( function() {
|
|
var search_field = document.querySelector( '.select2-container--open .select2-search__field' );
|
|
if ( search_field )
|
|
{
|
|
search_field.focus();
|
|
search_field.select();
|
|
}
|
|
}, 0 );
|
|
});
|
|
});
|
|
</script>
|