From 8654cec739f156fbb1e97c154d64ee728179b8f8 Mon Sep 17 00:00:00 2001
From: Josef Moravec <josef.moravec@gmail.com>
Date: Wed, 2 Nov 2016 12:02:34 +0000
Subject: [PATCH] Bug 8612: QA follow-up - distinguish between late issues and
 basket export csv profiles

---
 acqui/basket.pl                                    |  2 +-
 installer/data/mysql/atomicupdate/bug_8612.sql     |  1 +
 .../prog/en/modules/tools/csv-profiles.tt          | 36 +++++++++++++---------
 serials/claims.pl                                  |  2 +-
 t/db_dependent/Acquisition/GetBasketAsCSV.t        |  2 +-
 t/db_dependent/Koha/CsvProfiles.t                  |  2 +-
 6 files changed, 26 insertions(+), 19 deletions(-)
 create mode 100644 installer/data/mysql/atomicupdate/bug_8612.sql

diff --git a/acqui/basket.pl b/acqui/basket.pl
index 2bbf42d..40327ee 100755
--- a/acqui/basket.pl
+++ b/acqui/basket.pl
@@ -424,7 +424,7 @@ if ( $op eq 'list' ) {
         unclosable           => @orders ? $basket->{is_standing} : 1,
         has_budgets          => $has_budgets,
         duplinbatch          => $duplinbatch,
-        csv_profiles         => [ Koha::CsvProfiles->search({ type => 'sql' }) ],
+        csv_profiles         => [ Koha::CsvProfiles->search({ type => 'export_basket' }) ],
     );
 }
 
diff --git a/installer/data/mysql/atomicupdate/bug_8612.sql b/installer/data/mysql/atomicupdate/bug_8612.sql
new file mode 100644
index 0000000..37a643b
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_8612.sql
@@ -0,0 +1 @@
+UPDATE export_format SET type = 'late_issues' WHERE type ='sql';
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt
index 46fc155..51ae687 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt
@@ -101,6 +101,14 @@ function reloadPage(p) {
     [% END %]
 [% END %]
 
+[% BLOCK type_description %]
+    [% IF type_code == 'marc' %] MARC for export records
+    [% ELSIF type_code == 'late_issues' %] SQL for late serial issues claims
+    [% ELSIF type_code == 'export_basket' %] SQL for basket export in acquisition
+    [% ELSE %] Uknown type
+    [% END %]
+[% END %]
+
 [% IF op == 'add_form' %]
     [% IF csv_profile %]
         <h1>Modify a CSV profile</h1>
@@ -124,12 +132,12 @@ function reloadPage(p) {
                 <li>
                     <label for="type" class="required">Profile type: </label>
                     <select id="type" name="type">
-                        [% IF csv_profile.type == 'sql' %]
-                            <option value="marc">MARC</option>
-                            <option value="sql" selected="selected">SQL</option>
+                        [% FOREACH type IN [ 'marc' 'late_issues' 'export_basket'] %]
+                        [% IF csv_profile.type == type %]
+                            <option value="[% type %]" selected="selected">[% PROCESS type_description type_code = type %]</option>
                         [% ELSE %]
-                            <option value="marc" selected="selected">MARC</option>
-                            <option value="sql">SQL</option>
+                            <option value="[% type %]">[% PROCESS type_description type_code = type %]</option>
+                        [% END %]
                         [% END %]
                     </select>
                     <span class="required">Required</span>
@@ -182,11 +190,13 @@ function reloadPage(p) {
                 </li>
 
                 <li class="sql_specific">
-                  <label for="sql_content" class="required">Profile SQL fields: </label>
-                  <textarea cols="50" rows="2" name="sql_content" id="sql_content">[% csv_profile.content %]</textarea>
-                  <p>You have to define which fields you want to export, separated by pipes.</p>
-                  <p>You can also use your own headers (instead of the ones from Koha) by prefixing the field name with an header, followed by the equal sign.</p>
-                  <p>Example: Name=subscription.name|Title=subscription.title|Issue number=serial.serialseq</p>
+                    <label for="late_issues_content" class="required">Profile SQL fields: </label>
+                    <textarea cols="50" rows="2" name="sql_content" id="sql_content">[% csv_profile.content %]</textarea>
+                    <p>You have to define which fields you want to export, separated by pipes.</p>
+                    <p>You can also use your own headers (instead of the ones from Koha) by prefixing the field name with an header, followed by the equal sign.</p>
+                    <p>Example: Name=subscription.name|Title=subscription.title|Issue number=serial.serialseq</p>
+                    <p>For late issues claims you can use data from following tables: serial, subscription, biblio, biblioitems and aqbookseller.</p>
+                    <p>For basket exports you can use data from following tables: biblio, biblioitems, aqorders, aqbudgets and aqbasket.</p>
                 </li>
             </ol>
         </fieldset>
@@ -243,11 +253,7 @@ function reloadPage(p) {
                     <td>[% csv_profile.description %]</td>
                     <td>[% csv_profile.content %]</td>
                     <td>[% csv_profile.csv_separator %]</td>
-                    [% IF csv_profile.type == 'sql' %]
-                        <td>SQL</td>
-                    [% ELSE %]
-                        <td>MARC</td>
-                    [% END %]
+                    <td>[% PROCESS type_description type_code = csv_profile.type %]</td>
                     <td><a href="/cgi-bin/koha/tools/csv-profiles.pl?op=add_form&amp;export_format_id=[% csv_profile.export_format_id %]">Edit</a></td>
                     <td><a href="/cgi-bin/koha/tools/csv-profiles.pl?op=delete_confirm&amp;export_format_id=[% csv_profile.export_format_id %]">Delete</a></td>
                 </tr>
diff --git a/serials/claims.pl b/serials/claims.pl
index b4bc94f..6f6baba 100755
--- a/serials/claims.pl
+++ b/serials/claims.pl
@@ -104,7 +104,7 @@ $template->param(
         supplierid => $supplierid,
         claimletter => $claimletter,
         additional_fields_for_subscription => $additional_fields,
-        csv_profiles => [ Koha::CsvProfiles->search({ type => 'sql' }) ],
+        csv_profiles => [ Koha::CsvProfiles->search({ type => 'late_issues' }) ],
         letters => $letters,
         (uc(C4::Context->preference("marcflavour"))) => 1
         );
diff --git a/t/db_dependent/Acquisition/GetBasketAsCSV.t b/t/db_dependent/Acquisition/GetBasketAsCSV.t
index 320bcca..5ff1f23 100644
--- a/t/db_dependent/Acquisition/GetBasketAsCSV.t
+++ b/t/db_dependent/Acquisition/GetBasketAsCSV.t
@@ -36,7 +36,7 @@ my $budget = C4::Budgets::GetBudget( $budget_id );
 
 my $csv_profile = Koha::CsvProfile->new({
     profile => 'my user profile',
-    type => 'sql',
+    type => 'export_basket',
     csv_separator => ',',
     content => 'autor=biblio.author|title=biblio.title|quantity=aqorders.quantity',
 })->store;
diff --git a/t/db_dependent/Koha/CsvProfiles.t b/t/db_dependent/Koha/CsvProfiles.t
index 70c2201..aee3152 100644
--- a/t/db_dependent/Koha/CsvProfiles.t
+++ b/t/db_dependent/Koha/CsvProfiles.t
@@ -35,7 +35,7 @@ my $nb_of_csv_profiles = Koha::CsvProfiles->search->count;
 my $new_csv_profile_1 = Koha::CsvProfile->new({
     profile => 'my_csv_profile_name_for_test_1',
     description => 'my_csv_profile_description_for_test_1',
-    type => 'sql'
+    type => 'late_issues'
 })->store;
 my $new_csv_profile_2 = Koha::CsvProfile->new({
     profile => 'my_csv_profile_name_for_test_2',
-- 
2.1.4