Allow saving UID of producers
authorJoey Schulze <joey@infodrom.org>
Mon, 9 Jul 2018 20:40:30 +0000 (22:40 +0200)
committerJoey Schulze <joey@infodrom.org>
Sat, 6 Oct 2018 17:30:27 +0000 (19:30 +0200)
class/sales.class.php
src/InfoCon/buch/list.wml
src/pix/if_europeanunion_4618.png [new file with mode: 0644]

index 8dde7d8..60985ba 100644 (file)
@@ -68,5 +68,16 @@ class Sales extends DatabaseTable {
       return $this->modify('description', utf8_decode($data['content']));
   }
 
+  public function ajaxGetUID(Array $data)
+  {
+      return array('description' => utf8_encode($this->data->description),
+                  'uid' => is_null($this->data->uid) ? '' : $this->data->uid);
+  }
+
+  public function ajaxSetUID(Array $data)
+  {
+      return $this->modify('uid', strlen($data['uid']) ? utf8_decode($data['uid']) : NULL);
+  }
+
 }
 
index 100dc5d..3bc7198 100644 (file)
@@ -19,7 +19,8 @@ if ($_POST["submit"] == "List") {
   <th width=10%>Datum</th>
   <th width=10%>Buchung</th>
   <th width=10%>Kategorie</th>
-  <th width=60%>Verwendungszweck</th>
+  <th width=2%>&nbsp;</th>
+  <th width=58%>Verwendungszweck</th>
   <th width=10%>Betrag</th>
 </tr>
 <?
@@ -63,7 +64,9 @@ if ($_POST["submit"] == "List") {
     printf ("<td width=\"10%%\" align=\"right\">%s</td>", $date);
     printf ("<td width=\"10%%\" align=\"right\">%s</td>", $billing_date);
     printf ("<td width=\"10%%\" align=\"center\">%s</td>", $row['category']);
-    printf ("<td width=\"0%%\"><span class=\"edit\" route=\"Sales/EditDescription\" item_id=\"%d\">%s</span></td>",
+    printf ("<td width=\"2%%\" align=\"center\"><img src=\"<root_prefix>pix/if_europeanunion_4618.png\" class=\"eu\" alt=\"\" item_id=\"%d\"></td>",
+           $row['nr']);
+    printf ("<td width=\"58%%\"><span class=\"edit\" route=\"Sales/EditDescription\" item_id=\"%d\">%s</span></td>",
       $row['nr'], $row['description']);
     printf ("<td width=\"10%%\" align=\"right\">%5.2f</td>", $row['price']);
     $sum += $row['price'];
@@ -71,7 +74,7 @@ if ($_POST["submit"] == "List") {
     $color = !$color;
   }
   printf ("<tr class=\"t%d\">", $color);
-  echo ("<td width=\"85%\" colspan=\"4\"><b>Summe</b></td>");
+  echo ("<td width=\"85%\" colspan=\"5\"><b>Summe</b></td>");
   printf ("<td width=\"15%%\" align=\"right\"><b>%5.2f</b></td>", $sum);
   echo ("</tr>");
   echo ("</table>");
@@ -245,7 +248,46 @@ function tally ($dbh, $head, $where, $class)
 <protect>
 $(function(){
     make_editable('table.smallfont tr span.edit');
+
+    $('table.smallfont tr img.eu').click(eu_popup);
 });
+
+var euwindow = false;
+function eu_popup(event)
+{
+    var content = ['<div id="eubody">',
+                  '<input type="hidden" id="eu_nr">',
+                  '<label for="eu_uid"></label>',
+                  '<input type="text" id="eu_uid" style="width:100%;">',
+                  '<br>',
+                  '<button style="margin-top:5px;">Speichern</button>',
+                  '</div>'];
+
+    if (!euwindow) {
+       euwindow = new Popup('Inner-EU-Rechnung', '250px', false, content.join(''));
+       euwindow.centerPopup();
+       $('div#eubody button').click(function(event){
+           $.invoke('Sales/SetUID',
+                    {id: $('#eu_nr').val(),
+                     uid: $('#eu_uid').val()},
+                    function(data){
+                        euwindow.closePopup();
+                        show_message('UID des Lieferanten für innergemeinschaftlichen Erwerb gespeichert', 3);
+                    });
+       });
+    } else {
+       euwindow.openPopup();
+    }
+
+    $('#eu_nr').val($(event.target).attr('item_id'));
+    $.invoke('Sales/GetUID',
+            {id: $(event.target).attr('item_id')},
+            function(data){
+                $('label[for="eu_uid"]').text(data.description);
+                $('#eu_uid').val(data.uid);
+            });
+}
+
 </protect>
 </script>
 </page>
diff --git a/src/pix/if_europeanunion_4618.png b/src/pix/if_europeanunion_4618.png
new file mode 100644 (file)
index 0000000..d6d8711
Binary files /dev/null and b/src/pix/if_europeanunion_4618.png differ