[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[5930] trunk/LedgerSMB/Scripts/contact.pm



Revision: 5930
          http://sourceforge.net/p/ledger-smb/code/5930
Author:   ehuelsmann
Date:     2013-08-03 09:06:50 +0000 (Sat, 03 Aug 2013)
Log Message:
-----------
Port over a lost (but used) function from 1.3's ScriptLib/Company.pm.

Modified Paths:
--------------
    trunk/LedgerSMB/Scripts/contact.pm

Modified: trunk/LedgerSMB/Scripts/contact.pm
===================================================================
--- trunk/LedgerSMB/Scripts/contact.pm	2013-08-01 21:03:24 UTC (rev 5929)
+++ trunk/LedgerSMB/Scripts/contact.pm	2013-08-03 09:06:50 UTC (rev 5930)
@@ -707,6 +707,80 @@
     $template->render($request);
 }
 
+
+=item save_pricelist
+
+This routine saves the price matrix.  For existing rows, valid_to, valid_from,
+price fields are saved.
+
+For the new row, the partnumber field matches the beginning of the part number,
+and the description is a full text search.
+
+=cut
+
+sub save_pricelist {
+    my ($request) = @_;
+    use LedgerSMB::ScriptLib::Common_Search::Part;
+    use LedgerSMB::DBObject::Pricelist;
+    my $count = $request->{rowcount_pricematrix};
+
+    my $pricelist = LedgerSMB::DBObject::Pricelist->new({base => $request});
+    my @lines;
+    my $redirect_to_selection = 0;
+    my $psearch;
+
+    # Search and populate
+    if (defined $request->{"int_partnumber_tfoot_$count"}
+         or defined $request->{"description_tfoot_$count"})
+    {
+        $psearch = LedgerSMB::ScriptLib::Common_Search::Part->new($request);
+        my @parts = $psearch->search(
+                   { partnumber => $request->{"int_partnumber_tfoot_$count"},
+                    description => $request->{"description_tfoot_$count"}, }
+        );
+
+        if (scalar @parts == 0) {
+            $request->error($request->{_locale}->text('Part not found'));
+        } elsif (scalar @parts > 1){
+            $redirect_to_selection = 1;
+        } else {
+            my $part = shift @parts;
+            push @lines, {
+                   parts_id => $part->{id},
+                  validfrom => $request->{"validfrom_tfoot_$count"},
+                    validto => $request->{"validto_tfoot_$count"},
+                      price => $request->{"lastcost_tfoot_$count"} ||
+                               $request->{"sellprice_tfoot_$count"},
+                   leadtime => $request->{"leadtime_tfoot_$count"},
+             };
+        }
+    }
+
+    # Save rows
+    for (1 .. ($count - 1)){
+        my $id = $request->{"row_$_"};
+        push @lines, {
+                entry_id => $id,
+                parts_id => $request->{"parts_id_$id"},
+               validfrom => $request->{"validfrom_$id"},
+                 validto => $request->{"validto_$id"},
+                   price => $request->{"lastcost_$id"} ||
+                            $request->{"sellprice_$id"},
+                leadtime => $request->{"leadtime_$id"},
+        };
+    }
+
+    $pricelist->save(..hidden..);
+
+    # Return to UI
+
+    get_pricelist($request) unless $redirect_to_selection;
+
+    $request->{search_redirect} = 'pricelist_search_handle';
+    $psearch->render($request);
+}
+
+
 =back
 
 =head1 COPYRIGHT

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.