{"id":21327,"date":"2022-04-11T13:56:08","date_gmt":"2022-04-11T11:56:08","guid":{"rendered":"https:\/\/help.openbee.com\/open-bee-scan-capture\/knowledge-base\/how-to-guides\/scripts-in-capture\/case-studies\/index\/index-closing-status-by-period\/"},"modified":"2026-05-13T09:36:49","modified_gmt":"2026-05-13T07:36:49","slug":"index-closing-status-by-period","status":"publish","type":"page","link":"https:\/\/help.openbee.com\/en\/open-bee-scan-capture\/knowledge-base\/how-to-guides\/scripts-in-capture\/case-studies\/index\/index-closing-status-by-period\/","title":{"rendered":"Index: Closing Status by Period"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"Index:d'&#xE9;tatdecloturationparp&#xE9;riode-Principe:\">Principle:<\/h2>\n\n<p>Calculates the period corresponding to the current date and returns CLOSED or UNCLOSED next if the document date is included in the current period.<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"Index:d'&#xE9;tatdecloturationparp&#xE9;riode-Script:\">Script:<\/h2>\n\n<pre class=\"wp-block-code\"><code>var CLOSING_DAY = 20;\nvar NUMBER_OF_MONTH = 3;\nvar START_MONTH = 0; \/\/January is 0!\nvar CLOSED = \"Clotur\u00e9\";\nvar UNCLOSED = \"Non clotur\u00e9\";\n\nvar getPartOfYear = function(pDate, closingDay, numberOfMonth, startMonth){\n    var nbDiffMonth = Math.abs(pDate.getMonth() - startMonth); \n\tvar period = Math.ceil(nbDiffMonth \/ numberOfMonth);\n\treturn nbDiffMonth % numberOfMonth == 0 &amp;&amp; pDate.getDate() &gt; closingDay ? period + 1 : period;\n}\n\nvar getClotureFromDateState = function(dateInvoice, today, closingDay, numberOfMonth, startMonth){\n\tif(today.getFullYear() != dateInvoice.getFullYear()){\n\t \tvar diffMonth = today.getMonth() + 12 - dateInvoice.getMonth();\n\t \tif(diffMonth &gt; numberOfMonth)\n\t \t\treturn CLOSED;\n\t \t\n\t \tif(today.getDate() &gt; closingDay)\n\t \t\tdiffMonth++;\n\t \tif(dateInvoice.getDate() &lt; closingDay)\n\t \t\tdiffMonth++;\n\t \t\n\t \treturn diffMonth &gt; numberOfMonth ? CLOSED : UNCLOSED;\n\t}\n\treturn getPartOfYear(today, closingDay, numberOfMonth, startMonth) == getPartOfYear(dateInvoice, closingDay, numberOfMonth, startMonth) ? UNCLOSED : CLOSED;\n};\n\nvar getClotureState = function(pParameters){\n\tvar dateGeneralIndex = getTextFromIndexInfo(getFirstIndexFromID(pParameters,\"DATE_INDEX\"));\n\tvar dateParts = dateGeneralIndex.split(\"\/\");\n\tvar dateInvoice = new Date(dateParts&#91;2], dateParts&#91;1] - 1, dateParts&#91;0]);\n\treturn getClotureFromDateState(dateInvoice, new Date(), CLOSING_DAY, NUMBER_OF_MONTH, START_MONTH);\n};\n\nreturn getClotureState(pParameters);<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\" id=\"Index:d'&#xE9;tatdecloturationparp&#xE9;riode-Tests:\">Tests:<\/h2>\n\n<pre class=\"wp-block-code\"><code>var testPeriodDate = function(pNumber, dateInvoice, today, closingDay, numberOfMonth, startMonth, pResult){\n\t\n\tvar result = getClotureFromDateState(dateInvoice, today, closingDay, numberOfMonth, startMonth) == pResult;\n\tprint(pNumber+ \" result : \"+result + \" t factDate:\"+dateInvoice.getDate()+\"\/\"+dateInvoice.getMonth()+\"\/\"+dateInvoice.getFullYear()+\" actualDate : \"+today.getDate()+\"\/\"+today.getMonth()+\"\/\"+today.getFullYear()+ \" closingDay : \"+closingDay+ \" periodLength : \"+numberOfMonth+ \" start : \"+startMonth);\n};\n\ntestPeriodDate(1, new Date(), new Date(), 20, 3, 0, UNCLOSED);\ntestPeriodDate(2, new Date(2018, 3, 19), new Date(2018, 3, 21), 20, 3, 0, CLOSED);\ntestPeriodDate(3, new Date(2017, 3, 19), new Date(2018, 3, 21), 20, 3, 0, CLOSED);\ntestPeriodDate(4, new Date(2017,11,25), new Date(2018, 0, 1), 20, 3, 0, UNCLOSED);\ntestPeriodDate(5, new Date(2017,11,1), new Date(2018, 0, 1), 20, 3, 0, UNCLOSED);\ntestPeriodDate(6, new Date(2018,1,19), new Date(2018, 11, 21), 20, 3, 0, CLOSED);\ntestPeriodDate(7, new Date(2017,11,19), new Date(2018, 1, 21), 20, 3, 0, CLOSED);\ntestPeriodDate(8, new Date(2018,11,17), new Date(2018, 1, 1), 20, 3, 1, CLOSED);\ntestPeriodDate(9, new Date(2017,10,25), new Date(2018, 1, 17), 20, 3, 1, UNCLOSED);\ntestPeriodDate(10, new Date(2017,11,1), new Date(2018, 1, 17), 20, 3, 1, UNCLOSED);\ntestPeriodDate(11, new Date(2017,9,1), new Date(2018, 9, 17), 31, 12, 0, CLOSED);\ntestPeriodDate(12, new Date(2018,1,1), new Date(2018, 11, 26), 31, 12, 0, UNCLOSED);\ntestPeriodDate(13, new Date(2018,0,1), new Date(2018, 0, 31), 31, 1, 0, UNCLOSED);\ntestPeriodDate(14, new Date(2018,0,31), new Date(2018, 1, 1), 31, 1, 0, CLOSED);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Principle: Calculates the period corresponding to the current date and returns CLOSED or UNCLOSED next if the document date is included in the current period. Script: Tests:<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":21276,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"templates\/ob-help-products.php","meta":{"footnotes":""},"class_list":["post-21327","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/21327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/comments?post=21327"}],"version-history":[{"count":1,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/21327\/revisions"}],"predecessor-version":[{"id":21332,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/21327\/revisions\/21332"}],"up":[{"embeddable":true,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/21276"}],"wp:attachment":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/media?parent=21327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}