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

SF.net SVN: ledger-smb:[6353] branches/1.3



Revision: 6353
          http://sourceforge.net/p/ledger-smb/code/6353
Author:   einhverfr
Date:     2014-01-02 15:51:53 +0000 (Thu, 02 Jan 2014)
Log Message:
-----------
Removing check for LedgerSMB base object.  This was previously required before we moved a lot of stuff to App_State but with the current set-up it does more harm than good, and it keeps a lot of backported addons from working out of the box.

Modified Paths:
--------------
    branches/1.3/LedgerSMB/AA.pm
    branches/1.3/LedgerSMB/DBObject.pm
    branches/1.3/LedgerSMB/Form.pm
    branches/1.3/LedgerSMB/GL.pm
    branches/1.3/LedgerSMB/IC.pm
    branches/1.3/LedgerSMB/IR.pm
    branches/1.3/LedgerSMB/IS.pm
    branches/1.3/LedgerSMB/OE.pm
    branches/1.3/LedgerSMB/Tax.pm
    branches/1.3/UI/journal/journal_entry.html
    branches/1.3/bin/aa.pl
    branches/1.3/bin/gl.pl
    branches/1.3/bin/ic.pl
    branches/1.3/bin/ir.pl
    branches/1.3/bin/is.pl
    branches/1.3/bin/oe.pl
    branches/1.3/sql/modules/Defaults.sql
    branches/1.3/sql/modules/Fixes.sql

Modified: branches/1.3/LedgerSMB/AA.pm
===================================================================
--- branches/1.3/LedgerSMB/AA.pm	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/LedgerSMB/AA.pm	2014-01-02 15:51:53 UTC (rev 6353)
@@ -101,7 +101,7 @@
         $invnumber = "vinumber";
     }
     $form->{invnumber} = $form->update_defaults( $myconfig, $invnumber )
-      unless $form->{invnumber};
+      if $form->should_update_defaults('invnumber');
 
     if ( $form->{currency} eq $form->{defaultcurrency} ) {
         $form->{exchangerate} = 1;

Modified: branches/1.3/LedgerSMB/DBObject.pm
===================================================================
--- branches/1.3/LedgerSMB/DBObject.pm	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/LedgerSMB/DBObject.pm	2014-01-02 15:51:53 UTC (rev 6353)
@@ -72,9 +72,6 @@
     else {
         @mergelist = ();
     }
-    if ( !$base->isa('LedgerSMB') ) {
-        $self->error("Constructor called without LedgerSMB object arg");
-    }
 
     my $attr;
     if (lc($mode) eq 'base'){

Modified: branches/1.3/LedgerSMB/Form.pm
===================================================================
--- branches/1.3/LedgerSMB/Form.pm	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/LedgerSMB/Form.pm	2014-01-02 15:51:53 UTC (rev 6353)
@@ -67,6 +67,7 @@
 use File::Copy;
 use LedgerSMB::Company_Config;
 use LedgerSMB::App_State;
+use LedgerSMB::Setting::Sequence;
 
 use charnames qw(:full);
 use open ':utf8';
@@ -3457,6 +3458,10 @@
 sub update_defaults {
 
     my ( $self, $myconfig, $fld,$dbh_parm,$nocommit) = @_;
+    if ($self->{setting_sequence}){
+        return LedgerSMB::Setting::Sequence->increment(
+              $self->{setting_sequence}, $self);
+    }
 
     if ( !$self->{dbh} && $self ) {
         $self->db_init($myconfig);
@@ -3600,6 +3605,26 @@
     return $var;
 }
 
+=item should_update_defaults(fldname)
+
+This should be used instead of direct tests, and checks for a sequence selected.
+
+=cut
+
+sub should_update_defaults {
+    my ($self, $fldname) = @_;
+    if (!$self->{$fldname}){
+       return 1;
+    }
+    if (!$self->{setting_sequence}){
+        return 0;
+    }
+
+    my $sequence = LedgerSMB::Setting::Sequence->get($self->{setting_sequence});
+    return 1 unless $sequence->accept_input;
+    return 0;
+}
+
 =item $form->db_prepare_vars(var1, var2, ..., varI<n>)
 
 Undefines $form->{varI<m>}, 1 <= I<m> <= I<n>, iff $form-<{varI<m> is both
@@ -3617,6 +3642,34 @@
     }
 }
 
+=item sequence_dropdown(setting_key)
+
+This function returns the HTML code for a dropdown box for a given setting
+key.  It is not generally to be used with code on new templates.
+
+=cut
+
+sub sequence_dropdown{
+    my ($self, $setting_key) = @_;
+    return undef if $self->{id};
+    my @sequences = LedgerSMB::Setting::Sequence->list($setting_key);
+    my $retval = qq|<select name='setting_sequence' class='sequence'>\n|;
+    $retval .= qq|<option></option>|;
+    for my $seq (@sequences){
+        my $selected = '';
+        my $label = $seq->label;
+        $selected = "SELECTED='SELECTED'"
+            if $self->{setting_sequence} eq $label;
+        $retval .= qq|<option value='$label' $selected>$label</option>\n|;
+    }
+    $retval .= "</select>";
+    if (@sequences){
+        return $retval;
+    } else {
+        return undef
+    }
+}
+
 =item $form->split_date($dateformat[, $date]);
 
 Returns ($rv, $yy, $mm, $dd) for the provided $date, or the current date if no

Modified: branches/1.3/LedgerSMB/GL.pm
===================================================================
--- branches/1.3/LedgerSMB/GL.pm	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/LedgerSMB/GL.pm	2014-01-02 15:51:53 UTC (rev 6353)
@@ -98,7 +98,7 @@
 
     my ( $self, $myconfig, $form, $locale) = @_;
     $form->{reference} = $form->update_defaults( $myconfig, 'glnumber', $dbh )
-      unless $form->{reference};
+      if $form->should_update_defaults('glnumber');
     my $null;
     my $project_id;
     my $department_id;

Modified: branches/1.3/LedgerSMB/IC.pm
===================================================================
--- branches/1.3/LedgerSMB/IC.pm	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/LedgerSMB/IC.pm	2014-01-02 15:51:53 UTC (rev 6353)
@@ -253,7 +253,7 @@
     my $nocommit=1;
     $form->{partnumber} =
       $form->update_defaults( $myconfig, "partnumber", $dbh,$nocommit)
-      if !$form->{partnumber};
+      if $form->should_update_defaults('partnumber');
 
     ( $form->{inventory_accno} ) = split( /--/, $form->{IC_inventory} );
     ( $form->{expense_accno} )   = split( /--/, $form->{IC_expense} );

Modified: branches/1.3/LedgerSMB/IR.pm
===================================================================
--- branches/1.3/LedgerSMB/IR.pm	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/LedgerSMB/IR.pm	2014-01-02 15:51:53 UTC (rev 6353)
@@ -75,7 +75,7 @@
     }
     my $dbh = $form->{dbh};
     $form->{invnumber} = $form->update_defaults( $myconfig, "vinumber", $dbh )
-      unless $form->{invnumber};
+      if $form->should_update_defaults('invnumber');
 
     for ( 1 .. $form->{rowcount} ) {
         $form->{"qty_$_"} *= -1 if $form->{reverse};

Modified: branches/1.3/LedgerSMB/IS.pm
===================================================================
--- branches/1.3/LedgerSMB/IS.pm	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/LedgerSMB/IS.pm	2014-01-02 15:51:53 UTC (rev 6353)
@@ -913,7 +913,7 @@
 
     my ( $self, $myconfig, $form ) = @_;
     $form->{invnumber} = $form->update_defaults( $myconfig, "sinumber", $dbh )
-      unless $form->{invnumber};
+      if $form->should_update_defaults('invnumber');
 
     my $dbh = $form->{dbh};
 

Modified: branches/1.3/LedgerSMB/OE.pm
===================================================================
--- branches/1.3/LedgerSMB/OE.pm	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/LedgerSMB/OE.pm	2014-01-02 15:51:53 UTC (rev 6353)
@@ -347,7 +347,7 @@
     }
     $form->{"$ordnumber"} =
       $form->update_defaults( $myconfig, $numberfld, $dbh )
-      unless $form->{"$ordnumber"};
+      if $form->should_update_defaults($form->{"$ordnumber"});
 
 
 

Modified: branches/1.3/LedgerSMB/Tax.pm
===================================================================
--- branches/1.3/LedgerSMB/Tax.pm	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/LedgerSMB/Tax.pm	2014-01-02 15:51:53 UTC (rev 6353)
@@ -67,6 +67,7 @@
         if ( defined $taxaccounts2 ) {
             next if $taxaccounts2 !~ /\b$taxaccount\b/;
         }
+        $form->{transdate} = undef unless $form->{transdate};
         $sth->execute($taxaccount, $form->{transdate}) || $form->dberror($query);
         my $ref = $sth->fetchrow_hashref;
         next unless $ref;

Modified: branches/1.3/UI/journal/journal_entry.html
===================================================================
--- branches/1.3/UI/journal/journal_entry.html	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/UI/journal/journal_entry.html	2014-01-02 15:51:53 UTC (rev 6353)
@@ -29,8 +29,17 @@
 			size = "20",
 			class = 'reference'
 			id = "ref_1"
-		} ?>
-
+		};
+             IF form.sequences;
+                 form.sequences.unshift({});
+                 PROCESS select element_data = {
+                    name = 'setting_sequence'
+          default_values = [form.setting_sequence]
+                 options = form.sequences
+               text_attr = 'label'
+              value_attr = 'label'
+                 }; 
+             END; ?>
          </td>          
 	  <th align="right"><?lsmb text('Date') ?></th>
 	  <td>

Modified: branches/1.3/bin/aa.pl
===================================================================
--- branches/1.3/bin/aa.pl	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/bin/aa.pl	2014-01-02 15:51:53 UTC (rev 6353)
@@ -158,6 +158,12 @@
 }
 
 sub display_form {
+    my $invnumber = "sinumber";
+    if ( $form->{vc} eq 'vendor' ) {
+        $invnumber = "vinumber";
+    }
+    $form->{sequence_select} = $form->sequence_dropdown($invnumber)
+        unless $form->{id};
     $form->close_form;
     $form->open_form;
     $form->{dbh}->commit;
@@ -677,7 +683,8 @@
 	      $employee
 	      <tr>
 		<th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
-		<td><input name=invnumber size=20 value="$form->{invnumber}"></td>
+		<td><input name=invnumber size=20 value="$form->{invnumber}">
+                      $form->{sequence_select}</td>
 	      </tr>
 	      <tr>
 		<th align=right nowrap>| . $locale->text('Order Number') . qq|</th>

Modified: branches/1.3/bin/gl.pl
===================================================================
--- branches/1.3/bin/gl.pl	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/bin/gl.pl	2014-01-02 15:51:53 UTC (rev 6353)
@@ -48,6 +48,7 @@
 use LedgerSMB::GL;
 use LedgerSMB::PE;
 use LedgerSMB::Template;
+use LedgerSMB::Setting::Sequence;
 
 require "bin/arap.pl";
 
@@ -162,7 +163,6 @@
       unless $form->{callback};
 
     &create_links;
-    $form->{reference} = $form->update_defaults(\%myconfig, 'glnumber');
     if (!$form->{rowcount}){
         $form->{rowcount} = ( $form->{transfer} ) ? 3 : 9;
     }
@@ -190,6 +190,8 @@
     if (@{$form->{all_project}}){
        unshift @{ $form->{all_project} }, {};
     }
+    @{$form->{sequences}} = LedgerSMB::Setting::Sequence->list('glnumber')
+         unless $form->{id};
     $title = $form->{title};
     if ( $form->{transfer} ) {
         $form->{title} = $locale->text("[_1] Cash Transfer Transaction", $title);

Modified: branches/1.3/bin/ic.pl
===================================================================
--- branches/1.3/bin/ic.pl	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/bin/ic.pl	2014-01-02 15:51:53 UTC (rev 6353)
@@ -769,7 +769,8 @@
 	  <th align=left>$group</th>
 	</tr>
 	<tr valign=top>
-          <td><input name=partnumber value="$form->{partnumber}" size=20></td>
+          <td><input name=partnumber value="$form->{partnumber}" size=20> 
+              | . $form->sequence_dropdown('partnumber') . qq| </td>
           <td>$description</td>
 	  <td>$partsgroup</td>
 	</tr>

Modified: branches/1.3/bin/ir.pl
===================================================================
--- branches/1.3/bin/ir.pl	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/bin/ir.pl	2014-01-02 15:51:53 UTC (rev 6353)
@@ -508,7 +508,8 @@
 	    <table>
 	      <tr>
 		<th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
-		<td><input name=invnumber size=20 value="$form->{invnumber}"></td>
+		<td><input name=invnumber size=20 value="$form->{invnumber}">
+                   | .  $form->sequence_dropdown('vinumber') . qq|</td>
 	      </tr>
 	      <tr>
 		<th align=right nowrap>| . $locale->text('Order Number') . qq|</th>

Modified: branches/1.3/bin/is.pl
===================================================================
--- branches/1.3/bin/is.pl	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/bin/is.pl	2014-01-02 15:51:53 UTC (rev 6353)
@@ -572,7 +572,7 @@
 	      $employee
 	      <tr class="invnumber-row">
 		<th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
-		<td><input name="invnumber" size="20" value="$form->{invnumber}"></td>
+		<td><input name="invnumber" size="20" value="$form->{invnumber}">| .  $form->sequence_dropdown('sinumber') . qq|</td>
 	      </tr>
 	      <tr class="ordnumber-row">
 		<th align=right nowrap>| . $locale->text('Order Number') . qq|</th>

Modified: branches/1.3/bin/oe.pl
===================================================================
--- branches/1.3/bin/oe.pl	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/bin/oe.pl	2014-01-02 15:51:53 UTC (rev 6353)
@@ -332,7 +332,29 @@
 
 sub form_header {
 
+    my $ordnumber;
+    my $numberfld;
+    if ( $form->{type} =~ /_order$/ ) {
+        $quotation = "0";
+        $ordnumber = "ordnumber";
+	if ($form->{vc} eq 'customer'){
+             $numberfld = "sonumber";
+        } else {
+             $numberfld = "ponumber";
+        }
+    }
+    else {
+        $quotation = "1";
+        $ordnumber = "quonumber";
+        if ( $form->{vc} eq 'customer' ) {
+	    $numberfld = "sqnumber";
+	} else {
+	    $numberfld = "rfqnumber";
+	}
+    }
     $form->{nextsub} = 'update';
+
+    $sequences = $form->sequence_dropdown($numberfld) unless $form->{id};
    
     $checkedopen   = ( $form->{closed} ) ? ""        : "checked";
     $checkedclosed = ( $form->{closed} ) ? "checked" : "";
@@ -428,7 +450,8 @@
         $ordnumber = qq|
 	      <tr class="ordnumber-row">
 		<th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
-                <td><input name=ordnumber size=20 value="$form->{ordnumber}"></td>
+                <td><input name=ordnumber size=20 value="$form->{ordnumber}">
+                     $sequences</td>
 		<input type=hidden name=quonumber value="$form->{quonumber}">
 	      </tr>
 	      <tr class="transdate-row">
@@ -497,7 +520,8 @@
 		<th width=70% align=right nowrap>|
               . $locale->text('Quotation Number')
               . qq|</th>
-		<td><input name=quonumber size=20 value="$form->{quonumber}"></td>
+		<td><input name=quonumber size=20 value="$form->{quonumber}">
+                    $sequences</td>
 		<input type=hidden name=ordnumber value="$form->{ordnumber}">
 	      </tr>
 |;
@@ -506,7 +530,8 @@
             $ordnumber = qq|
 	      <tr class="rfqnumber-row">
 		<th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
-		<td><input name=quonumber size=20 value="$form->{quonumber}"></td>
+		<td><input name=quonumber size=20 value="$form->{quonumber}">
+                    $sequences</td>
 		<input type=hidden name=ordnumber value="$form->{ordnumber}">
 	      </tr>
 |;

Modified: branches/1.3/sql/modules/Defaults.sql
===================================================================
--- branches/1.3/sql/modules/Defaults.sql	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/sql/modules/Defaults.sql	2014-01-02 15:51:53 UTC (rev 6353)
@@ -19,3 +19,113 @@
 $$ language plpgsql;                                                                  
 COMMENT ON FUNCTION defaults_get_defaultcurrency() IS
 $$ This function return the default currency asigned by the program. $$;
+
+CREATE OR REPLACE FUNCTION sequence__list() RETURNS SETOF lsmb_sequence
+LANGUAGE SQL AS
+$$
+SELECT * FROM lsmb_sequence order by label;
+$$;
+
+CREATE OR REPLACE FUNCTION sequence__get(in_label text) RETURNS LSMB_SEQUENCE
+LANGUAGE SQL AS
+$$
+SELECT * FROM lsmb_sequence WHERE label = $1;
+$$;
+
+CREATE OR REPLACE FUNCTION sequence__list_by_key(in_setting_key text)
+RETURNS SETOF lsmb_sequence LANGUAGE SQL AS
+$$
+SELECT * FROM lsmb_sequence where setting_key = $1 order by label;
+$$;
+
+CREATE OR REPLACE FUNCTION sequence__save
+(in_label text, in_setting_key text, in_prefix text, in_suffix text,
+ in_sequence text, in_accept_input bool)
+RETURNS lsmb_sequence LANGUAGE plpgsql AS
+$$
+DECLARE retval lsmb_sequence;
+BEGIN
+UPDATE lsmb_sequence 
+   SET prefix = coalesce(in_prefix, ''),
+       suffix = coalesce(in_suffix, ''),
+       sequence = coalesce(in_sequence, '1'),
+       setting_key = in_setting_key,
+       accept_input = coalesce(in_accept_input, true)
+ WHERE label = in_label;
+
+IF FOUND THEN 
+   retval := sequence__get(in_label);
+   RETURN retval;
+END IF;
+
+INSERT INTO lsmb_sequence(label, setting_key, prefix, suffix, sequence, 
+                          accept_input)
+VALUES (in_label, in_setting_key, 
+        coalesce(in_prefix, ''), 
+        coalesce(in_suffix, ''), 
+        coalesce(in_sequence, '1'),
+        coalesce(in_accept_input, false)
+);
+
+retval := sequence__get(in_label);
+RETURN retval;
+
+end;
+$$;
+
+CREATE OR REPLACE FUNCTION sequence__increment(in_label text)
+RETURNS defaults LANGUAGE PLPGSQL AS
+$$
+DECLARE t_seq lsmb_sequence;
+        new_value text;
+        retval    defaults;
+BEGIN
+
+   SELECT * INTO t_seq FROM lsmb_sequence WHERE label = in_label
+          FOR UPDATE;
+
+   new_value := setting__increment_base(t_seq.sequence);
+
+   UPDATE lsmb_sequence SET sequence = new_value WHERE label = in_label;
+
+   retval := row(t_seq.setting_key, t_seq.prefix || new_value || t_seq.suffix);
+   return retval;
+   
+END;
+$$;
+
+CREATE OR REPLACE FUNCTION sequence__delete(in_label text)
+RETURNS lsmb_sequence LANGUAGE SQL AS
+$$
+DELETE FROM lsmb_sequence where label = $1;
+
+SELECT NULL::lsmb_sequence;
+$$;
+
+CREATE OR REPLACE FUNCTION setting__increment_base(in_raw_var text)
+returns varchar language plpgsql as $$
+declare raw_value VARCHAR;
+       base_value VARCHAR;
+       increment  INTEGER;
+       inc_length INTEGER;
+       new_value VARCHAR;
+begin
+    raw_value := in_raw_var;
+    base_value := substring(raw_value from  
+                                '(' || E'\\' || 'd*)(' || E'\\' || 'D*|<' 
+                                    || E'\\' || '?lsmb [^<>] ' || E'\\' 
+                                    || '?>)*$');
+    IF base_value like '0%' THEN
+         increment := base_value::integer + 1;
+         inc_length := char_length(increment::text);
+         new_value := overlay(base_value placing increment::varchar
+                              from (char_length(base_value)
+                                    - inc_length + 1) 
+                              for inc_length);
+    ELSE
+         new_value := base_value::integer + 1;
+    END IF;
+    return regexp_replace(raw_value, base_value, new_value);
+end;
+$$;
+

Modified: branches/1.3/sql/modules/Fixes.sql
===================================================================
--- branches/1.3/sql/modules/Fixes.sql	2014-01-02 15:07:28 UTC (rev 6352)
+++ branches/1.3/sql/modules/Fixes.sql	2014-01-02 15:51:53 UTC (rev 6353)
@@ -671,4 +671,16 @@
 COMMIT;
 
 
+BEGIN;
 
+CREATE TABLE lsmb_sequence (
+   label text primary key,
+   setting_key text not null references defaults(setting_key),
+   prefix text,
+   suffix text,
+   sequence text not null default '1',
+   accept_input bool default true
+);
+
+COMMIT;
+

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


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits