automatic billable calculation (#3200)
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Form\Type\BillableType;
|
||||
use App\Form\Type\DateTimePickerType;
|
||||
use App\Form\Type\DescriptionType;
|
||||
use App\Form\Type\DurationType;
|
||||
@@ -18,10 +17,12 @@ use App\Form\Type\FixedRateType;
|
||||
use App\Form\Type\HourlyRateType;
|
||||
use App\Form\Type\MetaFieldsCollectionType;
|
||||
use App\Form\Type\TagsType;
|
||||
use App\Form\Type\TimesheetBillableType;
|
||||
use App\Form\Type\UserType;
|
||||
use App\Form\Type\YesNoType;
|
||||
use App\Repository\CustomerRepository;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
@@ -169,7 +170,7 @@ class TimesheetEditForm extends AbstractType
|
||||
{
|
||||
$durationOptions = [
|
||||
'required' => false,
|
||||
'docu_chapter' => 'timesheet.html#duration-format',
|
||||
'docu_chapter' => 'duration-format.html',
|
||||
'attr' => [
|
||||
'placeholder' => '0:00',
|
||||
],
|
||||
@@ -261,11 +262,57 @@ class TimesheetEditForm extends AbstractType
|
||||
|
||||
protected function addBillable(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
if (!$options['include_billable']) {
|
||||
return;
|
||||
if ($options['include_billable']) {
|
||||
$builder->add('billableMode', TimesheetBillableType::class, []);
|
||||
}
|
||||
|
||||
$builder->add('billable', BillableType::class, []);
|
||||
$builder->addModelTransformer(new CallbackTransformer(
|
||||
function (Timesheet $record) {
|
||||
if ($record->getBillableMode() === Timesheet::BILLABLE_DEFAULT) {
|
||||
if ($record->isBillable()) {
|
||||
$record->setBillableMode(Timesheet::BILLABLE_YES);
|
||||
} else {
|
||||
$record->setBillableMode(Timesheet::BILLABLE_NO);
|
||||
}
|
||||
}
|
||||
|
||||
return $record;
|
||||
},
|
||||
function (Timesheet $record) {
|
||||
switch ($record->getBillableMode()) {
|
||||
case Timesheet::BILLABLE_NO:
|
||||
$record->setBillable(false);
|
||||
break;
|
||||
case Timesheet::BILLABLE_YES:
|
||||
$record->setBillable(true);
|
||||
break;
|
||||
case Timesheet::BILLABLE_AUTOMATIC:
|
||||
$billable = true;
|
||||
|
||||
$activity = $record->getActivity();
|
||||
if ($activity !== null && !$activity->isBillable()) {
|
||||
$billable = false;
|
||||
}
|
||||
|
||||
$project = $record->getProject();
|
||||
if ($billable && $project !== null && !$project->isBillable()) {
|
||||
$billable = false;
|
||||
}
|
||||
|
||||
if ($billable && $project !== null) {
|
||||
$customer = $project->getCustomer();
|
||||
if ($customer !== null && !$customer->isBillable()) {
|
||||
$billable = false;
|
||||
}
|
||||
}
|
||||
|
||||
$record->setBillable($billable);
|
||||
break;
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user