]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DB/Helper/FlattenToForm.pm
Merge branch 'master' of http://wagnertech.de/git/mfinanz
[mfinanz.git] / SL / DB / Helper / FlattenToForm.pm
index ccd6ca045b10e138d1e236d6d698fafc499457dc..4f2e73e3d603211ce79eedbc01a323ec004d04f4 100644 (file)
@@ -3,7 +3,7 @@ package SL::DB::Helper::FlattenToForm;
 use strict;
 
 use parent qw(Exporter);
-our @EXPORT = qw(flatten_to_form);
+our @EXPORT = qw(flatten_to_form prepare_stock_info);
 
 use List::MoreUtils qw(uniq any);
 
@@ -15,7 +15,8 @@ sub flatten_to_form {
   _copy($self, $form, '', '', 0, qw(id type taxzone_id ordnumber quonumber invnumber donumber cusordnumber taxincluded shippingpoint shipvia notes intnotes cp_id
                                     employee_id salesman_id closed department_id language_id payment_id delivery_customer_id delivery_vendor_id shipto_id proforma
                                     globalproject_id delivered transaction_description container_type accepted_by_customer invoice storno storno_id dunning_config_id
-                                    orddate quodate reqdate gldate duedate deliverydate datepaid transdate tax_point delivery_term_id));
+                                    orddate quodate reqdate gldate duedate deliverydate datepaid transdate tax_point delivery_term_id billing_address_id
+                                    vendor_confirmation_number));
   $form->{currency} = $form->{curr} = $self->currency_id ? $self->currency->name || '' : '';
 
   if ( $vc eq 'customer' ) {
@@ -27,9 +28,10 @@ sub flatten_to_form {
   };
 
   if (_has($self, 'transdate')) {
-    my $transdate_idx = ref($self) eq 'SL::DB::Order'   ? ($self->quotation ? 'quodate' : 'orddate')
-                      : ref($self) eq 'SL::DB::Invoice' ? 'invdate'
-                      :                                   'transdate';
+    my $transdate_idx = ref($self) eq 'SL::DB::Order'         ? ($self->quotation ? 'quodate' : 'orddate')
+                      : ref($self) eq 'SL::DB::Invoice'       ? 'invdate'
+                      : ref($self) eq 'SL::DB::DeliveryOrder' ? 'dodate'
+                      :                                         'transdate';
     $form->{$transdate_idx} = $self->transdate->to_lxoffice;
   }
 
@@ -74,6 +76,7 @@ sub flatten_to_form {
   my $items_name = ref($self) eq 'SL::DB::Order'         ? 'orderitems'
                  : ref($self) eq 'SL::DB::DeliveryOrder' ? 'delivery_order_items'
                  : ref($self) eq 'SL::DB::Invoice'       ? 'invoice'
+                 : ref($self) eq 'SL::DB::Reclamation'   ? 'reclamation_items'
                  : '';
 
   my %cvar_validity = _determine_cvar_validity($self, $vc);
@@ -97,7 +100,7 @@ sub flatten_to_form {
     _copy($item->part,    $form, '',               "_${idx}", 0,               qw(listprice));
     _copy($item,          $form, '',               "_${idx}", 0,               qw(description project_id ship serialnumber pricegroup_id ordnumber donumber cusordnumber unit
                                                                                   subtotal longdescription price_factor_id marge_price_factor reqdate transdate
-                                                                                  active_price_source active_discount_source));
+                                                                                  active_price_source active_discount_source optional));
     _copy($item,          $form, '',              "_${idx}", $format_noround, qw(qty sellprice fxsellprice));
     _copy($item,          $form, '',              "_${idx}", $format_amounts, qw(marge_total marge_percent lastcost));
     _copy($item,          $form, '',              "_${idx}", $format_percent, qw(discount));
@@ -110,6 +113,10 @@ sub flatten_to_form {
       $form->{"deliverydate_oe_${idx}"} = $date;
       $form->{"reqdate_${idx}"}         = $date;
     }
+    if (ref($self) eq 'SL::DB::DeliveryOrder'){
+      my $in_out   = $form->{type} =~ /^sales|^supplier/ ? 'out' : 'in';
+      $form->{"stock_" . $in_out . "_" . ${idx}} = prepare_stock_info($self,$item);
+    }
   }
 
   _copy_custom_variables($self, $form, 'vc_cvar_', '', $cvar_validity{vc});
@@ -118,6 +125,21 @@ sub flatten_to_form {
   return $self;
 }
 
+sub prepare_stock_info {
+  my ($self, $item) = @_;
+
+  $item->{stock_info} = SL::YAML::Dump([
+    map +{
+      delivery_order_items_stock_id => $_->id,
+      qty                           => $_->qty,
+      warehouse_id                  => $_->warehouse_id,
+      bin_id                        => $_->bin_id,
+      chargenumber                  => $_->chargenumber,
+      unit                          => $_->unit,
+    }, $item->delivery_order_stock_entries
+  ]);
+}
+
 sub _has {
   my ($obj, $column) = @_;
   return $obj->can($column) && $obj->$column;