diff --git a/app/Models/Document.php b/app/Models/Document.php index 913c6fd..aeee71e 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -42,7 +42,7 @@ class Document extends Model 'due_date' => 'datetime:Y-m-d' ]; - protected $appends = ['due_status']; + protected $appends = ['due_status', 'due_status_color']; public function creator() { @@ -67,33 +67,63 @@ class Document extends Model protected function dueStatus(): Attribute { return Attribute::make( - get: function() { - $diff = $this->category->duration; + get: function () { + $maxMonthDiff = 3; + $maxDayDiff = 30; //$this->category->duration; if ($this->due_date == null) { return ''; } + if (now()->toDateString() == $this->due_date->toDateString()) { return "hari ini jatuh tempo"; } - $date = now()->diffInDays($this->due_date, false) + 1; + $diffMonth = now()->diffInMonths($this->due_date, true); + + if ($maxMonthDiff >= $diffMonth && $diffMonth > 0) { + return $diffMonth . " bulan mendekati jatuh tempo"; + } + + $diffDays = now()->diffInDays($this->due_date, false); - if ($diff >= $date && $date > 0) { - return $date . " hari mendekati jatuh tempo"; + if ($maxDayDiff >= $diffDays && $diffDays > 0) { + return $diffDays . " hari mendekati jatuh tempo"; } - if ($date <= 0) { + if ($diffDays <= 0) { return "jatuh tempo"; } - }, + } + ); + } + + protected function dueStatusColor(): Attribute + { + return Attribute::make( + get: function () { + $maxMonthDiff = 3; + + $diffMonth = now()->diffInMonths($this->due_date, true); + + if ($maxMonthDiff >= $diffMonth && $diffMonth > 0) { + return [ + 1 => '#dc2626', + 2 => '#facc15', + 3 => '#4ade80', + ][$diffMonth]; + } + + return '#dc2626'; + } ); } protected function isCloseDue(): Attribute { return Attribute::make( - get: function() { - $diff = $this->category->duration; + get: function () { + $maxMonthDiff = 3; + $diff = 30; //$this->category->duration; if ($this->due_date == null) { return 0; @@ -103,12 +133,19 @@ class Document extends Model return 0; } - $date = now()->diffInDays($this->due_date, false) + 1; + $diffMonth = now()->diffInMonths($this->due_date, true); - if ($diff >= $date && $date > 0) { - return $date; + if ($maxMonthDiff >= $diffMonth && $diffMonth > 0) { + return $diffMonth; } - if ($date <= 0) { + + $diffDays = now()->diffInDays($this->due_date, false) + 1; + + if ($diff >= $diffDays && $diffDays > 0) { + return $diffDays; + } + + if ($diffDays <= 0) { return 0; } @@ -117,11 +154,12 @@ class Document extends Model ); } - public function scopeCloseToExpired($query) { + public function scopeCloseToExpired($query) + { $ids = collect(); $categories = Category::all(); - foreach($categories as $category) { - foreach($category->documents as $docs) { + foreach ($categories as $category) { + foreach ($category->documents as $docs) { if ($docs->is_close_due != 0) { $ids->add($docs->id); } diff --git a/docker-compose.yml b/docker-compose.yml index d8f5609..a69b38e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,6 +39,19 @@ services: networks: monitordoc: ipv4_address: 10.4.0.99 + nodejs: + image: node:16-alpine + container_name: monitordoc-node + ports: + - 5173:5173 + volumes: + - ./:/var/www + working_dir: /var/www + entrypoint: ["npm","run", "dev"] + networks: + monitordoc: + ipv4_address: 10.4.0.100 + networks: monitordoc: driver: bridge diff --git a/package.json b/package.json index 30171ed..d91936a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "scripts": { - "dev": "vite", + "dev": "vite --host 0.0.0.0", "build": "vite build" }, "devDependencies": { @@ -29,4 +29,4 @@ "react-toastify": "^9.0.8", "react-use": "^17.4.0" } -} +} \ No newline at end of file diff --git a/resources/js/Pages/Document/Index.jsx b/resources/js/Pages/Document/Index.jsx index ddae36e..52c9e4b 100644 --- a/resources/js/Pages/Document/Index.jsx +++ b/resources/js/Pages/Document/Index.jsx @@ -15,7 +15,7 @@ import ModalImport from './ModalImport' export default function Document(props) { const { data: docs, links } = props.docs - const [search, setSearch] = useState({q: '', status: 0}) + const [search, setSearch] = useState({ q: '', status: 0 }) const preValue = usePrevious(search) const importModal = useModalState(false) @@ -28,7 +28,7 @@ export default function Document(props) { const onDelete = () => { const doc = confirmModal.data - if(doc != null) { + if (doc != null) { router.delete(route('docs.destroy', doc), { onSuccess: () => toast.success('The Data has been deleted'), }) @@ -46,20 +46,16 @@ export default function Document(props) { setSearch({ ...search, sortBy: key, - sortRule: search.sortRule == 'asc' ? 'desc' : 'asc' + sortRule: search.sortRule == 'asc' ? 'desc' : 'asc', }) } useEffect(() => { if (preValue) { - router.get( - route(route().current()), - search, - { - replace: true, - preserveState: true, - } - ) + router.get(route(route().current()), search, { + replace: true, + preserveState: true, + }) } }, [search]) @@ -81,51 +77,130 @@ export default function Document(props) {
-
- {canCreate && ( - - Tambah - - )} - {canImport && ( -
- Import -
- )} +
+ {canCreate && ( + + Tambah + + )} + {canImport && ( +
+ Import +
+ )}
-
+
- handleFilter({q: e.target.value}) + handleFilter({ q: e.target.value }) } placeholder="Search" />
-
+
- -
    -
  • handleFilter({status: 0})}>Semua
  • -
  • handleFilter({status: 1})}>Jatuh Tempo
  • -
  • handleFilter({status: 2})}>Mendekati Jatuh Tempo
  • + +
      +
    • +
      + handleFilter({ + status: 0, + }) + } + > + Semua +
      +
    • +
    • +
      + handleFilter({ + status: 1, + }) + } + > + Jatuh Tempo +
      +
    • +
    • +
      + handleFilter({ + status: 2, + }) + } + > + Mendekati Jatuh Tempo +
      +
{canExport && ( -
- - -
+
+ + +
)}
@@ -135,12 +210,32 @@ export default function Document(props) { Perusahaan - sort('type_id')}>Jenis - sort('category_id')}>Ketegori + sort('type_id')} + > + Jenis + + sort('category_id')} + > + Ketegori + No Dokumen Nama Dokumen - sort('publish_date')}>Tanggal Terbit - sort('due_date')}>Tanggal Berakhir + sort('publish_date')} + > + Tanggal Terbit + + sort('due_date')} + > + Tanggal Berakhir + Catatan @@ -148,33 +243,79 @@ export default function Document(props) { {docs?.map((doc) => ( - {doc.company.short} ({doc.company.region.name}) + + {doc.company.short} ( + {doc.company.region.name}) + {doc.variety.name} {doc.category.name} {doc.no_doc} {doc.name} - {doc.publish_date !== null ? formatDate(doc.publish_date) : ''} + {doc.publish_date !== null + ? formatDate( + doc.publish_date + ) + : ''} - {doc.due_date !== null ? formatDate(doc.due_date) : ''} + {doc.due_date !== null + ? formatDate(doc.due_date) + : ''} - {doc.due_status} - + + {doc.due_status} + +
- -
    + +
    • - Detail + + Detail +
    • {canUpdate && (
    • - Edit + + Edit +
    • )} {canDelete && ( -
    • handleDelete(doc)} className="bg-error "> -
      Delete
      +
    • + handleDelete( + doc + ) + } + className="bg-error " + > +
      + Delete +
    • )}
    @@ -184,23 +325,20 @@ export default function Document(props) { ))} -
    - +
    +
    -
- + - + ) -} \ No newline at end of file +}