MAIL_BCC_ALL=test+toolbox@cubedesigners.com
MAIL_TEAM_NAME=Fluidbook
+RATE_PEOPLE_DAY=630
+RATE_PEOPLE_HOUR=100
+
MAILJET_API_KEY=ca110b35f8735c223d69c9987c2ac47d
MAILJET_API_SECRET=b289d0acb08e0fe56ce98ccf0dd1ed8b
$d = self::getInvoiceData($invoicable);
foreach ($d as $project_id => $p) {
- foreach ($p['tasks'] as $task_id => $task_name) {
- static::$_taskOptions[$invoicable][$task_id] = $project_id . ' | ' . $p['entry']->nom . ' > ' . $task_name;
+ foreach ($p['tasks'] as $task_id => $task_data) {
+ static::$_taskOptions[$invoicable][$task_id] = $project_id . ' | ' . $p['entry']->nom . ' > ' . $task_data['name'];
}
}
}
}
$res = [];
- foreach (static::$_projectTasks as $project => $tasks) {
- if (!isset(static::$_projects[$project])) {
- continue;
- }
- $p = static::$_projects[$project];
+
+ foreach (static::$_projects as $project_id => $p) {
if (Permissions::getCompanyByUser($p->client) != $company) {
continue;
}
+ $res[$project_id] = ['entry' => $p, 'tasks' => []];
- $res[$p->projet_id] = ['entry' => $p, 'tasks' => []];
- foreach ($tasks as $id => $task) {
- $res[$p->projet_id]['tasks'][$id] = $task->nom;
+ if (isset(static::$_projectTasks[$project_id])) {
+ foreach (static::$_projectTasks[$project_id] as $id => $task) {
+ $res[$project_id]['tasks'][$id] = ['name' => $task->nom, 'amount' => $task->budget];
+ }
}
}
+
return $res;
}
}
$tasks[$task->projet][$task->tache_id] = $task;
}
+
return $tasks;
});
}
- public static function cleanCache()
+ public static function clearCache()
{
Cache::forget('fluidbook_extranet_tasks');
Cache::forget('fluidbook_extranet_tasks_projects');
use App\Fields\FluidbookExtranetTask;
use App\Models\FluidbookPublication;
+use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
trait InvoiceOperation
protected function setupInvoiceRoutes($segment, $routeName, $controller)
{
Route::match(['get'], $segment . '/{id}/invoice/dialog', $controller . '@dialogProject');
- Route::match(['get'], $segment . '/{id}/invoice/dialog/{project}', $controller . '@dialogTask');
+ Route::match(['post'], $segment . '/{id}/invoice/dialog/project', $controller . '@dialogSetProject');
+ Route::match(['post'], $segment . '/{id}/invoice/dialog/task', $controller . '@dialogSetTask');
}
public function dialogProject($id)
$data = FluidbookExtranetTask::getInvoiceData($invoicable);
}
- return view('invoice.dialog_project', ['entry' => $entry, 'invoice' => $data]);
+ return view('invoice.dialog_project', ['entry' => $entry, 'projects' => $data]);
}
- public function dialogTasj($id, $project)
+ public function dialogSetProject($id)
{
$entry = FluidbookPublication::find($id);
if ($entry && $entry->invoicable_company) {
$invoicable = $entry->invoicable_company;
+ if (request('type') === 'new') {
+ $time = time();
+ $projectData = [
+ 'nom' => request('value'),
+ 'date_creation' => $time,
+ 'date_debut' => $time,
+ 'date_fin' => $time,
+ 'deadline' => $time,
+ 'devis' => 0,
+ 'client' => $entry->owner,
+ 'chef' => backpack_user()->id,
+ 'old' => 0,
+ 'status' => 0,
+ ];
+ $project_id = DB::connection('extranet')->table('projets')->insertGetId($projectData);
+ FluidbookExtranetTask::clearCache();
+ } else {
+ $project_id = request('value');
+ }
$data = FluidbookExtranetTask::getInvoiceData($invoicable);
+ $project = $data[$project_id];
+
+ }
+
+ return view('invoice.dialog_task', ['entry' => $entry, 'project' => $project]);
+ }
+
+ public function dialogSetTask($id)
+ {
+ if (request('type') === 'new') {
+ $taskData = [
+ 'nom' => request('value'),
+ 'projet' => request('project'),
+ 'budget' => request('amount'),
+ 'categorie' => 8, // Fluidbook
+ 'type' => 0, // normal task
+ 'taux_journalier' => env('RATE_PEOPLE_DAY'),
+ 'jours_prevus' => request('amount') / env('RATE_PEOPLE_DAY'),
+ ];
+ $task_id = DB::connection('extranet')->table('taches')->insertGetId($taskData);
+ FluidbookExtranetTask::clearCache();
+ } else {
+ $task_id = request('value');
}
- return view('invoice.dialog_task', ['entry' => $entry, 'invoice' => $data]);
+ /** @var FluidbookPublication $fluidbook */
+ $fluidbook = FluidbookPublication::find($id);
+ $fluidbook->extranet_task = $task_id;
+ $fluidbook->setStatus(3);
+ $fluidbook->saveQuietly();
}
}
return self::$_docs[$documentID];
}
- public function getLinksFile($page){
+ public function getLinksFile($page)
+ {
$compo = $this->getComposition()[$page];
- $document=self::_getDocument($compo[0]);
- return $document->path('links').'p'.$compo[1].'.csv';
+ $document = self::_getDocument($compo[0]);
+ return $document->path('links') . 'p' . $compo[1] . '.csv';
}
public function getTextFile($page, $type = FluidbookDocument::TEXT_PLAIN, $mode = null)
if (!$this->isOnePage()) {
$w = $this->getPageWidth();
foreach ($links as $k => $link) {
+
+ foreach (['width', 'height', 'top', 'left'] as $dim) {
+ if (!is_numeric($link[$dim])) {
+ $link[$dim] = $links[$k][$dim] = (float)str_replace(',', '.', $link[$dim]);
+ }
+ }
+
if ($link['left'] > $w && is_numeric($link['page']) && $link['page'] % 2 == 0) {
$links[$k]['left'] -= $w;
$links[$k]['page']++;
}
+
+
}
}
}
@if(!isset($crud->seenStatusChange))
@php $crud->seenStatusChange=true; @endphp
<style>
+ .invoice-form {
+ text-align: left;
+ }
+
+ .invoice-form h4 {
+ font-size: 16px;
+ font-weight: bold;
+ margin: 10px 0 2px;
+ }
+ .invoice-form input, .invoice-form .select2 {
+ max-width: 100%;
+ width: 100%;
+ }
</style>
<script>
+
+ $(function () {
+ $(document).on('change', '.invoice-form select', function () {
+ console.log($(this).val());
+ if ($(this).val() === '') {
+ $('.invoice-form .custom').show();
+ } else {
+ $('.invoice-form .custom').hide();
+ }
+ });
+ });
+
+ function parseSelect2() {
+ let select = $(Swal.getHtmlContainer()).find('select');
+ $(select).select2({
+ theme: 'bootstrap',
+ escapeMarkup: function (m) {
+ return m;
+ }
+ });
+ }
+
+ function swal(data, callbackProject, callbackTask) {
+ Swal.fire({
+ title: '{{__('Facturer la publication')}}',
+ html: '<div id="invoice_fluidbook">' + data + '</div>',
+ confirmButtonColor: '#467fcf',
+ confirmButtonText: '{{__('Valider')}}',
+ showCancelButton: true,
+ cancelButtonText: '{{__('Annuler')}}',
+ cancelButtonColor: '#f1ecec',
+ cancelButtonTextColor: '#000000',
+ focusConfirm: true,
+ reverseButtons: true,
+ didOpen: function () {
+ parseSelect2();
+ },
+ didDestroy: function () {
+
+ },
+ preConfirm: function () {
+ let c = $(Swal.getHtmlContainer());
+ let v = '';
+ let type = 'existing';
+ let s = c.find('select');
+ if ($(s).length > 0) {
+ v = s.val();
+ type = "existing";
+ }
+ if (v === undefined || v === '') {
+ v = c.find('input[name="name"]').val();
+ type = 'new';
+ }
+ if (v === '') {
+ return false;
+ }
+ if ($("#invoice_task").length === 0) {
+ return callbackProject({type: type, value: v});
+ }
+ return callbackTask({
+ type: type,
+ project: c.find('input[name="project"]').val(),
+ value: v,
+ amount: c.find('input[name="amount"]').val()
+ })
+
+
+ }
+ }).then(function (result) {
+
+ });
+ }
+
function statusCallback(element, value) {
if (value < 3) {
return true;
$.ajax({
url: '{{$crud->route}}/' + id + '/invoice/dialog',
}).done(function (data) {
- Swal.fire({
- title: '{{__('Facturer la publication')}}',
- html: '<div id="invoice_fluidbook">' + data + '</div>',
- confirmButtonColor: '#467fcf',
- confirmButtonText: '{{__('Valider')}}',
- showCancelButton: true,
- cancelButtonText: '{{__('Annuler')}}',
- cancelButtonColor: '#f1ecec',
- cancelButtonTextColor: '#000000',
- focusConfirm: false,
- didOpen: function () {
- let select = $(Swal.getHtmlContainer()).find('select');
- $(select).select2({
- theme: 'bootstrap',
- escapeMarkup: function (m) {
- return m;
- }
- });
- },
- didDestroy: function () {
-
- },
- }).then((result) => {
- if (result.isConfirmed) {
- let select = $(Swal.getHtmlContainer()).find('select');
- //window.location = '{{backpack_url($entry->getOption('name'))}}/' + $(a).data('entry-id') + '/changeowner/' + select.val();
- }
+ swal(data, function (v) {
+ $.ajax({
+ url: '{{$crud->route}}/' + id + '/invoice/dialog/project',
+ method: 'post',
+ data: v,
+ }).done(function (data) {
+ let c = $("#invoice_project").parent();
+ $(c).html(data);
+ parseSelect2();
+ });
+ return false;
+ }, function (v) {
+ $.ajax({
+ url: '{{$crud->route}}/' + id + '/invoice/dialog/task',
+ method: 'post',
+ data: v,
+ }).done(function (data) {
+ Swal.close();
+ });
+ return false;
});
});
-
}
</script>
@endif
-<form action="" method="post">
- <div id="invoice_project">
- {{__('Choisir un projet')}} : <select name="project">
+<div id="invoice_project" class="invoice-form">
+ <h4>{{__('Choisir un projet')}}</h4>
+ <div><select name="id">
<option value="">--</option>
- @foreach($invoice as $project_id=>$project)
+ @foreach($projects as $project_id=>$project)
<option value="{{$project_id}}">#{{$project_id}} | {{$project['entry']->nom}}</option>
@endforeach
</select>
- {{__('ou créer un nouveau projet')}} : <input type="text" name="project_new"/>
</div>
-
-</form>
+ <div class="custom">
+ <h4>{{__('ou créer un nouveau projet')}}</h4>
+ <div>
+ <input type="text" class="form-control" name="name" value="Fluidbook #{{$entry->id}} - {{$entry->title}}"/>
+ </div>
+ </div>
+</div>
-<form action="" method="post">
- <div id="invoice_task">
- {{__('Choisir une tâche')}} : <select name="task">
- <option value="">--</option>
- </select>
- {{__('ou créer une nouvelle tâche')}} <input type="text" name="task_new"/>
- {!! __('ayant un budget de :amount €',['amount'=>'<input type="text" name="task_amout">'])!!}
+@php
+ $hasTask=count($project['tasks'])>0;
+@endphp
+
+<div id="invoice_task" class="invoice-form">
+ <input type="hidden" name="project" value="{{$project['entry']->projet_id}}">
+ @if($hasTask)
+ <h4>{{__('Choisir une tâche')}}</h4>
+ <div>
+ <select name="id">
+ <option value="">--</option>
+ @foreach($project['tasks'] as $task_id=>$task)
+ <option value="{{$task_id}}">{{$task['name']}} ({{$task['amount']}}€)</option>
+ @endforeach
+ </select>
+ </div>
+ @endif
+ <div class="custom">
+ <h4>@if($hasTask)
+ {{__('ou créer une nouvelle tâche')}}
+ @else
+ {{__('Créer une tâche')}}
+ @endif</h4>
+ <p><input type="text" name="name" class="form-control" value="Fluidbook #{{$entry->id}} - {{$entry->title}}"/>
+ </p>
+ <h4>{{__('budget en euros')}}</h4>
+ <p><input type="text" name="amount" class="form-control"></p>
</div>
-</form>
+</div>