소스 검색

Fix albero

Luca Parisio 1 년 전
부모
커밋
4a03bda1e8

+ 37 - 2
app/Http/Livewire/RecordINOUT.php

@@ -115,14 +115,49 @@ class RecordINOUT extends Component
                 $first_parent_id = \App\Models\Causal::where('id', $record->parent_id)->first()->parent_id;
             }
             if ($type == 'IN')
-                $this->rows_in[] = array('id' => $record->id, 'name' => $record->name, 'level' => $indentation, 'parent_id' => $record->parent_id, 'parent_name' => $this->getCausalName($record->parent_id), 'first_parent_id' => $first_parent_id, 'first_parent_name' => $this->getCausalName($first_parent_id));
+                $this->rows_in[] = array('id' => $record->id, 'name' => $record->name, 'level' => $indentation, 'parent_id' => $record->parent_id, 'parent_name' => $this->getCausalName($record->parent_id), 'first_parent_id' => $first_parent_id, 'first_parent_name' => $this->getCausalName($first_parent_id), 'all_childs' => $this->getAllChild($record->id));
             if ($type == 'OUT')
-                $this->rows_out[] = array('id' => $record->id, 'name' => $record->name, 'level' => $indentation, 'parent_id' => $record->parent_id, 'parent_name' => $this->getCausalName($record->parent_id), 'first_parent_id' => $first_parent_id, 'first_parent_name' => $this->getCausalName($first_parent_id));
+                $this->rows_out[] = array('id' => $record->id, 'name' => $record->name, 'level' => $indentation, 'parent_id' => $record->parent_id, 'parent_name' => $this->getCausalName($record->parent_id), 'first_parent_id' => $first_parent_id, 'first_parent_name' => $this->getCausalName($first_parent_id), 'all_childs' => $this->getAllChild($record->id));
             if(count($record->childs))
                 $this->getCausale($record->childs, $type, $indentation + 1);
         }
     }
 
+    public function getAllChild($id)
+    {
+        $aChilds = array();
+        $aChilds[] = $id;
+
+
+        $record = \App\Models\Causal::findOrFail($id);
+        $aChilds[] = $record->parent_id;
+        if ($record->parent_id != null)
+        {
+            $first_parent_id = \App\Models\Causal::where('id', $record->parent_id)->first()->parent_id;
+            $aChilds[] = $first_parent_id;
+        }
+
+        $childs = \App\Models\Causal::where('parent_id', $id)->get();            
+        foreach($childs as $child)
+        {            
+            $aChilds[] = $child->id;
+            $childs2 = \App\Models\Causal::where('parent_id', $child->id)->get();            
+            foreach($childs2 as $child2)
+            {
+                $aChilds[] = $child2->id;
+                $childs3 = \App\Models\Causal::where('parent_id', $child2->id)->get();            
+                foreach($childs3 as $child3)
+                {
+                    $aChilds[] = $child3->id;
+                    
+                }   
+            }
+        }
+        return $aChilds;
+        
+    }
+
+
     public function getCausalName($id)
     {
         if ($id > 0)

+ 275 - 0
public/assets/js/bootstrap-treefy.js

@@ -0,0 +1,275 @@
++function ($) {
+    'use strict';
+
+    var Node = function (row) {
+        var template = /treetable-([A-Za-z0-9_-]+)/;
+        var parentTemplate = /treetable-parent-([A-Za-z0-9_-]+)/;
+        this.row = row;
+        this.id = null;
+        if (template.test(this.row.attr('data-node'))) {
+            this.id = template.exec(this.row.attr('data-node'))[1];
+        }
+
+        this.parentId = null;
+        if (parentTemplate.test(this.row.attr('data-pnode'))) {
+            this.parentId = parentTemplate.exec(this.row.attr('data-pnode'))[1];
+        }
+        this.children = [];
+        this.status = true;
+    }
+
+
+    Node.prototype.addChildren = function(treeContainer) {
+        var self = this;
+        var templateData = "treetable-parent-" + self.id;
+        var $children = treeContainer.find('[data-pnode="' + templateData + '"]');
+        if ($children.length != 0) {
+            $.each($children, function(index, child) {
+                var childNode = new Node($(child));
+                self.children.push(childNode)
+                childNode.addChildren(treeContainer);
+            });
+        }
+    }
+
+    Node.prototype.initIndent = function(treeFy) {
+        this.row.find('.treetable-indent').remove();
+        var expander = this.row.find('.treetable-expander');
+        var depth = this.getDepth(treeFy.$table);
+        for (var i = 0; i < depth; i++) {
+            var indentTemplate = treeFy.options.indentTemplate;
+            $(indentTemplate).insertBefore(expander);
+        }
+    }
+
+    Node.prototype.initExpander = function(treeFy) {
+        var self = this;
+        var element = self.row.find('td').get(treeFy.options.treeColumn);
+        var $expander = self.row.find('.treetable-expander');
+        if ($expander) {
+            $expander.remove();
+        }
+        var expanderTemplate = treeFy.options.expanderTemplate;
+        $(expanderTemplate).prependTo(element).click(function(event) {
+            //self.toggle($(this).closest('tr'));
+            self.toggle();
+        });
+    }
+
+    Node.prototype.renderExpand = function(treeFy) {
+        var $expander = this.row.find('.treetable-expander');
+        if ($expander) {
+            if (!this.row.hasClass('treetable-collapsed')) {
+                $expander.removeClass(treeFy.options.expanderCollapsedClass);
+                $expander.addClass(treeFy.options.expanderExpandedClass);
+            } else {
+                $expander.removeClass(treeFy.options.expanderExpandedClass);
+                $expander.addClass(treeFy.options.expanderCollapsedClass);
+            }
+        } else {
+            this.initExpander(treeFy);
+            this.renderExpand(treeFy);
+        }
+    }
+
+    Node.prototype.toggle = function() {
+        if (this.row.hasClass('treetable-expanded')) {
+            if (!this.isLeaf() && !this.row.hasClass('treetable-collapsed')) {
+                this.row.removeClass('treetable-expanded');
+                this.row.addClass('treetable-collapsed');
+            }
+        } else {
+            if (!this.isLeaf() && !this.row.hasClass('treetable-expanded')) {
+                this.row.removeClass('treetable-collapsed');
+                this.row.addClass('treetable-expanded');
+            }
+        }
+    }
+
+
+    /* 是否为叶子节点 */
+    Node.prototype.isLeaf = function() {
+        return this.children.length === 0;
+    }
+
+    Node.prototype.isCollapsed = function(treeContainer) {
+        var isRoot = (this.getDepth(treeContainer) === 0);
+        if (isRoot) {
+            return false;
+        } else {
+            if (this.getParentNode(treeContainer).row.hasClass('treetable-collapsed')) {
+                return true;
+            } else {
+                return this.getParentNode(treeContainer).isCollapsed(treeContainer);
+            }
+        }
+    }
+
+    Node.prototype.getDepth = function(treeContainer) {
+        if (this.getParentNode(treeContainer) === null) {
+            return 0;
+        }
+        return this.getParentNode(treeContainer).getDepth(treeContainer) + 1;
+    }
+
+    Node.prototype.getParentNode = function(treeContainer) {
+        if (this.parentId === null) {
+            return null;
+        } else {
+            return this.getNodeById(this.parentId, treeContainer);
+        }
+    }
+
+    Node.prototype.getNodeById = function(id, treeContainer) {
+        var templateData = "treetable-" + id;
+        var $row = treeContainer.find('[data-node="' + templateData + '"]');
+        var node = new Node($row);
+        node.addChildren(treeContainer);
+        return node;
+    }
+
+    var TreeFy = function (element, options) {
+        
+        this.options = options;
+
+        this.$table = $(element);
+
+        var allNodes = this.getAllNodes();
+        this.initTree(allNodes);
+        return TreeFy;
+    }
+
+    TreeFy.VERSION = '0.0.1'
+
+    TreeFy.prototype.getAllNodes = function() {
+        var self = this;
+        var result = $.grep(self.$table.find('tr'), function(trElement) {
+            var nodeData = $(trElement).attr('data-node');
+            var template = /treetable-([A-Za-z0-9_-]+)/;
+            return template.test(nodeData);
+        });
+        var $allNodes = $(result);
+        var allNodes = [];
+        $.each($allNodes, function() {
+            var node = new Node($(this));
+            node.addChildren(self.$table);
+            allNodes.push(node);
+        });
+        return allNodes;
+    }
+
+    TreeFy.prototype.initTree = function(allNodes) {
+        var self = this;
+        var rootNodes = [];
+        $.each(allNodes, function() {
+            var noChildren = this.children.length === 0;
+            if (!noChildren) {
+                this.row.addClass(self.options.initStatusClass);
+            }
+            if (!this.parentId) {
+                rootNodes.push(this);
+            }
+        });
+        self.initNode(rootNodes);
+        self.render(rootNodes);
+    }
+
+    TreeFy.prototype.initNode = function(nodes) {
+        var self = this;
+        $.each(nodes, function() {
+            self.initNode(this.children);
+            this.initExpander(self);
+            this.initIndent(self);
+            var $row = this.row;
+            var click_nodes = [];
+            click_nodes.push(this);
+            $row.find('.treetable-expander').on("click", function(event) {
+                event.stopPropagation();
+                self.render(click_nodes);
+            });
+        });
+    }
+
+    TreeFy.prototype.render = function(nodes) {
+        var self = this;
+        $.each(nodes, function(node) {
+            //若父节点折叠, 隐藏子节点
+            if (this.isCollapsed(self.$table)) {
+                this.row.hide();
+            } else {
+                this.row.show();
+            }
+            if (!this.isLeaf()) {
+                this.renderExpand(self);
+                self.render(this.children);
+            }
+        })
+    }
+
+
+    // PLUGIN DEFINITION
+    // =======================
+
+    function Plugin(option) {
+        var args = arguments;
+        var ret;
+        return this.each(function () {
+            var $this = $(this)
+            var data  = $this.data('treeFy')
+
+            if (!data) {
+                var options = $.extend(true, {}, $.fn.treeFy.defaults, typeof option == 'object' && option);
+                $this.data('treeFy', (data = new TreeFy(this, options)));
+            }
+            if (typeof option == 'string') data[option].call($this)
+        })
+
+        if (typeof option == 'string') {
+            if (args.length == 1) {
+                var _ret = data[option].call(data);
+                if (typeof _ret != 'undefined') {
+                    ret = _ret;
+                }
+            } else {
+                var _ret = data[option].apply(data, Array.prototype.slice.call(args, 1));
+                if (typeof _ret != 'undefined') {
+                    ret = _ret;
+                }
+            }
+        }
+
+        if (typeof ret != 'undefined') {
+            return ret;
+        }
+        return this;
+    }
+
+    var old = $.fn.treeFy
+
+    $.fn.treeFy             = Plugin
+    $.fn.treeFy.Constructor = TreeFy
+    $.fn.treeFy.defaults = {
+
+        expanderTemplate: '<span class="treetable-expander"></span>',
+
+        indentTemplate: '<span class="treetable-indent"></span>',
+
+        expanderExpandedClass: 'fa fa-angle-down',
+
+        expanderCollapsedClass: 'fa fa-angle-right',
+
+        treeColumn: 0,
+
+        initStatusClass: 'treetable-expanded'
+    }
+
+
+    // ALERT NO CONFLICT
+    // =================
+
+    $.fn.treeFy.noConflict = function () {
+        $.fn.treeFy = old
+        return this
+    }
+
+}(jQuery);

+ 3 - 0
resources/views/livewire/course.blade.php

@@ -408,6 +408,9 @@
             });
 
             $(document).ready(function() {
+                $(document).on("click",".addData",function() {
+                    $(".title--section_addButton").trigger("click");
+                });
                 $(document).on("click",".duplicateData",function() {
                     @this.duplicateMultiple(courses);
                 });

+ 4 - 4
resources/views/livewire/records_in.blade.php

@@ -534,9 +534,9 @@
                                             @if($this->member && !$commercial && !$this->member->isAdult() && $parent == '')
                                                 <span style="color:red">Devi selezionare un genitore</span>
                                             @else
-                                                @if($currentReceip->status != 99)
+                                                
                                                     <button class="btn--ui primary sendInvoice d-flex ms-auto" wire:click.prevent="store(true)" onclick='window.location.href = "#top";'><i class="ico--ui sendingBtn"></i><span>inserisci {{!$commercial ? 'genera ricevuta' : ''}}</span></button>
-                                                @endif
+                                                
                                             @endif
 
                                         @endif
@@ -546,9 +546,9 @@
                                         @if($this->member && !$commercial && !$this->member->isAdult() && $parent == '')
                                             <span style="color:red">Devi selezionare un genitore</span>
                                         @else
-                                            @if($currentReceip->status != 99)
+                                            
                                                 <button class="btn--ui primary sendInvoice d-flex ms-auto" wire:click.prevent="update({{!$commercial}})"><i class="ico--ui sendingBtn"></i><span>inserisci {{!$commercial ? 'genera ricevuta' : ''}}</span></button>
-                                            @endif
+                                            
                                         @endif
                                     @endif
                                 @else

+ 75 - 55
resources/views/livewire/records_in_out.blade.php

@@ -69,7 +69,7 @@
                         </div>
                     </div>
 
-                    <table class="table tablesaw tableHead tablesaw-stack collaptableIN" >
+                    <table class="table tablesaw tableHead tablesaw-stack collaptableIN" id="collaptableIN" >
                         <thead>
                             <tr>
                                 <th scope="col" style="width:20%;text-align:left"></th>
@@ -81,39 +81,31 @@
                                 @endfor
                             </tr>
                         </thead>
-                        <tbody id="checkall-target">
-                            @php
-                            $aScritto = array();
-                            @endphp
+                        <tbody >
                             @foreach($rows_in as $in)
-                                @if($filterCausalsIn == null || (sizeof($filterCausalsIn) == 0 || in_array($in["id"], $filterCausalsIn) || in_array($in["parent_id"], $filterCausalsIn) || in_array($in["first_parent_id"], $filterCausalsIn)))
-                                    @if($in["first_parent_name"] != "" && $filterCausalsIn != null && !in_array($in["first_parent_id"], $filterCausalsIn) && !in_array($in["first_parent_id"] . "_" . $in["parent_id"], $aScritto))
-                                        @php
-                                        $aScritto[] = $in["first_parent_id"] . "_" . $in["parent_id"];
-                                        @endphp
-                                        <tr>
-                                            <td>
-                                                <b>{{$in["first_parent_name"]}} - {{$in["parent_name"]}}</b>
-                                            </td>
-                                            @foreach($columns as $column)
-                                                <td class="cellBorder" style="text-align:right">
-                                                    @if(isset($records_in[$column][$in["parent_id"]]))
-                                                        <span class="tablesaw-cell-content {{$in["level"] == 0 ? 'primary' : ''}}" {{$in["level"] == 0 ? 'style="font-weight:bold;' : ''}}>
-                                                            {{formatPrice($records_in[$column][$in["parent_id"]])}}
-                                                        </span>
-                                                    @else
-                                                        &nbsp;
-                                                    @endif
-                                                </td>
-                                            @endforeach
-                                        </tr>
+
+                                @php
+                                $show = false;
+                                if ($filterCausalsIn != null)
+                                {
+                                    foreach($filterCausalsIn as $cIn)
+                                    {
+                                        if (in_array($cIn, $in["all_childs"]))
+                                            $show = true;
+                                    }
+                                }
+                                else
+                                    $show = true;
+                                @endphp
+                                @if($show)
+                                    @if($in["parent_id"] != null)
+                                        <tr data-node="treetable-{{$in["id"]}}" data-pnode="treetable-parent-{{$in["parent_id"]}}">
+                                    @else
+                                        <tr data-node="treetable-{{$in["id"]}}" >
                                     @endif
-                                    <tr data-id="{{$in["id"]}}" data-parent="{{$filterCausalsIn == null || in_array($in["parent_id"], $filterCausalsIn) ? $in["parent_id"] : ''}}">
-                                        <td>
-                                            <span class="spaces">{!!str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $in["level"])!!}</span>
-                                            @if($filterCausalsIn != null && !in_array($in["first_parent_id"], $filterCausalsIn))
-                                                <span style="padding-left:20px">{!!str_repeat(" ", 5)!!}</span>
-                                            @endif
+                                    
+                                        <td style="padding-left:{{$in["level"] * 20}}px;">
+                                            
                                             {{$in["name"]}}
                                         </td>
                                         @foreach($columns as $column)
@@ -128,10 +120,12 @@
                                             </td>
                                         @endforeach
                                         @for($j=sizeof($columns);$j<6;$j++)
-                                            <td class="cellBorder">&nbsp;</th>
+                                            <td class="cellBorder">&nbsp;</td>
                                         @endfor
                                     </tr>
                                 @endif
+
+
                             @endforeach
                             <tr>
                                 <td><b>Totale entrate mensili</b></td>
@@ -195,7 +189,7 @@
                         </div>
                     </div>
 
-                    <table class="table tablesaw tableHead tablesaw-stack collaptableOUT">
+                    <table class="table tablesaw tableHead tablesaw-stack collaptableOUT" id="collaptableOUT">
                         <thead>
                             <tr>
                                 <th scope="col" style="width:20%;text-align:left"></th>
@@ -208,28 +202,37 @@
                             </tr>
                         </thead>
                         <tbody id="checkall-target">
-                            @php
-                            $aScrittoX = array();
-                            @endphp
                             @foreach($rows_out as $out)
-                                @if($filterCausalsOut == null || (sizeof($filterCausalsOut) == 0 || in_array($out["id"], $filterCausalsOut) || in_array($out["parent_id"], $filterCausalsOut) || in_array($out["first_parent_id"], $filterCausalsOut)))
-                                    @if($filterCausalsOut != null && !in_array($out["first_parent_id"], $filterCausalsOut) && !in_array($out["first_parent_id"] . "_" . $out["parent_id"], $aScrittoX))
-                                        @php
-                                        $aScrittoX[] = $out["first_parent_id"] . "_" . $out["parent_id"];
-                                        @endphp
-                                        <tr>
-                                            <td colspan="20">
-                                                <b>{{$out["first_parent_name"]}} - {{$out["parent_name"]}}</b>
-                                            </td>
-                                        </tr>
+
+                                @php
+                                $show = false;
+                                if ($filterCausalsOut != null)
+                                {
+                                    foreach($filterCausalsOut as $cOut)
+                                    {
+                                        if (in_array($cOut, $out["all_childs"]))
+                                            $show = true;
+                                    }
+                                }
+                                else
+                                    $show = true;
+                                @endphp
+                                @if($show)
+                                    @if($out["parent_id"] != null)
+                                        <tr data-node="treetable-{{$out["id"] + 1000}}" data-pnode="treetable-parent-{{$out["parent_id"] + 1000}}">
+                                    @else
+                                        <tr data-node="treetable-{{$out["id"] + 1000}}" >
                                     @endif
-                                    <tr data-id="{{$out["id"] + 1000}}" data-parent="{{$out["parent_id"] != null ? ($out["parent_id"] + 1000) : 0}}">
-                                        <td>{!!str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $out["level"])!!}{{$out["name"]}}</td>
+                                    
+                                        <td style="padding-left:{{$out["level"] * 20}}px;">
+                                            
+                                            {{$out["name"]}}
+                                        </td>
                                         @foreach($columns as $column)
                                             <td class="cellBorder" style="text-align:right">
                                                 @if(isset($records_out[$column][$out["id"]]))
-                                                    <span class="tablesaw-cell-content {{$out["level"] == 0 ? 'primary' : ''}}"  {{$out["level"] == 0 ? 'style="font-weight:bold;' : ''}}>
-                                                    {{formatPrice($records_out[$column][$out["id"]])}}
+                                                    <span class="tablesaw-cell-content {{$out["level"] == 0 ? 'primary' : ''}}" {{$out["level"] == 0 ? 'style="font-weight:bold;' : ''}}>
+                                                        {{formatPrice($records_out[$column][$out["id"]])}}
                                                     </span>
                                                 @else
                                                     &nbsp;
@@ -237,10 +240,11 @@
                                             </td>
                                         @endforeach
                                         @for($j=sizeof($columns);$j<6;$j++)
-                                            <td class="cellBorder">&nbsp;</th>
+                                            <td class="cellBorder">&nbsp;</td>
                                         @endfor
                                     </tr>
                                 @endif
+
                             @endforeach
 
                             <tr>
@@ -353,7 +357,10 @@
     </style>
     <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
     <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
-    <script src="/assets/js/aCollapTable.js"></script>
+    
+    <script src="/assets/js/bootstrap-treefy.js"></script>
+    <!--<script src="/assets/js/aCollapTable.js"></script>-->
+
 @endpush
 
 @push('scripts')
@@ -363,6 +370,7 @@
             load();
         });
 
+
         function load()
         {
             $(document).ready(function(){
@@ -382,6 +390,8 @@
 
                 $('.filterCausalsIn').on('change', function (e) {
                     var data = $('.filterCausalsIn').select2("val");
+                    //selectedCausalsIn.push(data);
+                    //showHideNodes();
                     setTimeout(function() {createCollapse();}, 1000);
                     @this.set('filterCausalsIn', data);
                 });
@@ -416,7 +426,17 @@
 
             //$("#checkall-target > tr").removeAttr("data-level");
             //$("#checkall-target > tr").removeAttr("class");
+            $('#collaptableIN').unbind().removeData();
+            $("#collaptableIN").treeFy({
+                treeColumn: 0
+            });
 
+            $('#collaptableOUT').unbind().removeData();
+            $("#collaptableOUT").treeFy({
+                treeColumn: 0
+            });
+            
+            /*
             $('.collaptableIN').aCollapTable({
                 startCollapsed: true,
                 addColumn: false,
@@ -429,7 +449,7 @@
                 plusButton: '<span class="i"> + </span>',
                 minusButton: '<span class="i"> - </span>'
             });
-            $("#collapseAll").trigger("click");
+            $("#collapseAll").trigger("click");*/
         }
 
         Livewire.on('reset-collapse', () => {
@@ -456,7 +476,7 @@
         $(document).on("click", ".show", function () {
             var m = $('#month').val();
             var y = $('#year').val();
-            @this.show(m, y);
+            @this.show(m, y);            
         });
 
         $(document).on("click", ".exportYear", function () {