Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / templates / webpages / yearend / form.html
diff --git a/templates/webpages/yearend/form.html b/templates/webpages/yearend/form.html
new file mode 100644 (file)
index 0000000..d28dfc1
--- /dev/null
@@ -0,0 +1,98 @@
+[%- USE HTML %]
+[%- USE T8 %]
+[%- USE L %]
+[%- USE LxERP %]
+
+<h1>[% title | html %]</h1>
+
+[%- INCLUDE 'common/flash.html' %]
+
+[% IF carry_over_chart AND profit_chart AND loss_chart %] [% THEN %]
+<form id="filter" name="filter" method="post" action="controller.pl">
+<table>
+  <tr>
+    <td align="right">[% 'Year-end date' | $T8 %]</td>
+    <td>[% L.date_tag('cb_date', SELF.cb_date) %]</td>
+  </tr>
+  <tr class="startdate">
+   <td align="right">[% 'Startdate method' | $T8 %]</td>
+   <td>[% L.select_tag('balance_startdate_method', balance_startdate_method_options, value_key = 'value', title_key = 'title') %]</td>
+  </tr>
+  <tr class="startdate">
+    <td align="right">[% 'Start date' | $T8 %]</td>
+    <td>[% L.date_tag('cb_startdate', '', readonly=1) %]</td>
+  </tr>
+  <tr>
+    <td align="right">[% 'Carry over account for year-end closing' | $T8 %]</td>
+    <td>[% carry_over_chart.displayable_name | html %]</td>
+  </tr>
+  <tr>
+    <td align="right">[% 'Profit carried forward account' | $T8 %]</td>
+    <td>[% profit_chart.displayable_name | html %]</td>
+  </tr>
+  <tr>
+    <td align="right">[% 'Loss carried forward account' | $T8 %]</td>
+    <td>[% loss_chart.displayable_name | html %]</td>
+  </tr>
+</table>
+</form>
+[% ELSE %]
+  [% 'Please configure the carry over and profit and loss accounts for year-end closing in the client configuration!' | $T8 %]
+[% END %]
+
+[% # L.button_tag("refresh_charts();", LxERP.t8("Preview")) %]
+[% L.button_tag("year_end_bookings();", LxERP.t8("Apply year-end bookings"), id='apply_year_end_bookings_button', confirm=LxERP.t8("Are you sure?")) %]
+
+<div id="charts" style="padding-top: 20px">
+</div>
+
+<script type="text/javascript">
+
+  function get_startdate() {
+    $.get("controller.pl", {
+      action:                   'YearEndTransactions/get_start_date',
+      cb_date:                  $('#cb_date').val(),
+      balance_startdate_method: $('#balance_startdate_method').val()
+    }, kivi.eval_json_result)
+  }
+
+  function year_end_bookings() {
+    $.post("controller.pl", {
+      action:  'YearEndTransactions/year_end_bookings',
+      cb_date: $('#cb_date').val(),
+    }, kivi.eval_json_result)
+  }
+
+  function refresh_charts() {
+    var filterdata = $('#filter').serialize()
+    var url = './controller.pl?action=YearEndTransactions/update_charts&' + filterdata;
+    $.ajax({
+       url : url,
+       type: 'GET',
+       success: function(data){
+           $('#charts').html(data);
+       }
+    })
+  };
+
+$(function(){
+
+  $('#apply_year_end_bookings_button').hide();
+  $('.startdate').hide();
+
+  $('#balance_startdate_method').change(function(){
+    get_startdate();
+    setTimeout(function() {
+      refresh_charts();
+    }, 200);    
+  });
+
+  $('#cb_date').change(function(){
+    get_startdate();
+    setTimeout(function() {
+      refresh_charts();
+    }, 200);    
+  });
+})
+
+</script>