[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb: [1276] trunk/LedgerSMB
- Subject: SF.net SVN: ledger-smb: [1276] trunk/LedgerSMB
- From: ..hidden..
- Date: Wed, 13 Jun 2007 20:59:29 -0700
Revision: 1276
http://svn.sourceforge.net/ledger-smb/?rev=1276&view=rev
Author: einhverfr
Date: 2007-06-13 20:59:29 -0700 (Wed, 13 Jun 2007)
Log Message:
-----------
Now possible to save vendors (minus telephone info). AR/AP aging reports now run
Modified Paths:
--------------
trunk/LedgerSMB/CT.pm
trunk/LedgerSMB/RP.pm
Modified: trunk/LedgerSMB/CT.pm
===================================================================
--- trunk/LedgerSMB/CT.pm 2007-06-14 03:08:50 UTC (rev 1275)
+++ trunk/LedgerSMB/CT.pm 2007-06-14 03:59:29 UTC (rev 1276)
@@ -198,46 +198,31 @@
}
-sub save_customer {
-
- my ( $self, $myconfig, $form ) = @_;
-
- # connect to database
+sub _save_vc {
+ ($form) = @_;
my $dbh = $form->{dbh};
- my $query;
- my $sth;
- my $null;
-
- # remove double spaces
- $form->{name} =~ s/ / /g;
-
- # remove double minus and minus at the end
- $form->{name} =~ s/--+/-/g;
- $form->{name} =~ s/-+$//;
-
- # assign value discount, terms, creditlimit
- $form->{discount} = $form->parse_amount( $myconfig, $form->{discount} );
- $form->{discount} /= 100;
- $form->{terms} *= 1;
- $form->{taxincluded} *= 1;
- $form->{creditlimit} =
- $form->parse_amount( $myconfig, $form->{creditlimit} );
- if ( !$form->{creditlimit} ) {
- $form->{creditlimit} = 0;
- }
my $updated = 0;
+ if ($form->{vc} eq 'customer'){
+ $form->{vc} = 'customer';
+ $form->{entity_class} = 2;
+ } else {
+ $form->{vc} = 'vendor';
+ $form->{entity_class} = 1;
+ }
if ( $form->{id} ) {
$query = qq|
- DELETE FROM customertax
- WHERE customer_id = ?|;
+ DELETE FROM $form->{vc}tax
+ WHERE entity_id =
+ (select entity_id from $form->{vc}
+ WHERE id = ?)|;
$sth = $dbh->prepare($query);
$sth->execute( $form->{id} ) || $form->dberror($query);
$query = qq|
SELECT id
- FROM customer
+ FROM $form->{vc}
WHERE id = ?|;
$sth = $dbh->prepare($query);
@@ -246,12 +231,12 @@
if ( $sth->fetchrow_array ) {
$sth->finish;
$query = qq|
- UPDATE customer
+ UPDATE $form->{vc}
SET discount = ?
taxincluded = ?
creditlimit = ?
terms = ?
- customernumber = ?
+ $form->{vc}number = ?
cc = ?
bcc = ?
business_id = ?
@@ -268,7 +253,7 @@
$sth = $dbh->prepare($query);
$sth->execute(
$form->{discount}, $form->{taxincluded}, $form->{creditlimit},
- $form->{terms}, $form->{customernumber}, $form->{cc},
+ $form->{terms}, $form->{"$form->{vc}number"}, $form->{cc},
$form->{bcc}, $form->{business_id}, $form->{sic_code},
$form->{language_code}, $form->{pricegroup_id},
$form->{curr}, $form->{startdate}, $form->{enddate},
@@ -279,9 +264,9 @@
}
if (!$updated){
# Creating Entity
- $query = qq|INSERT INTO entity (name, entity_class) VALUES (?, 2)|;
+ $query = qq|INSERT INTO entity (name, entity_class) VALUES (?, ?)|;
$sth = $dbh->prepare($query);
- $sth->execute($form->{name});
+ $sth->execute($form->{name}, $form->{entity_class});
$sth->finish;
($form->{entity_id}) =
$dbh->selectrow_array("SELECT currval('entity_id_seq')");
@@ -309,10 +294,11 @@
(entity_id, entity_class_id, legal_name,
primary_location_id, tax_id)
VALUES
- (?, 2, ?, ?, ?)
+ (?, ?, ?, ?, ?)
|;
$sth = $dbh->prepare($query) || $form->dberror($query);
- $sth->execute($form->{entity_id}, $form->{name},
+ $sth->execute($form->{entity_id}, $form->{entity_class},
+ $form->{name},
$form->{location_id}, $form->{taxnumber});
#Creating customer record
$query = qq|
@@ -331,7 +317,7 @@
$sth->execute(
$form->{entity_id}, $form->{discount}, $form->{taxincluded},
$form->{creditlimit},
- $form->{terms}, $form->{customernumber}, $form->{cc},
+ $form->{terms}, $form->{"$form->{vc}number"}, $form->{cc},
$form->{bcc}, $form->{business_id}, $form->{sic_code},
$form->{language_code}, $form->{pricegroup_id}, $form->{curr},
$form->{startdate} || undef, $form->{enddate} || undef,
@@ -339,7 +325,36 @@
$form->{bic}, $form->{iban}
) || $form->dberror($query);
}
+}
+sub save_customer {
+
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+ my $query;
+ my $sth;
+ my $null;
+
+ # remove double spaces
+ $form->{name} =~ s/ / /g;
+
+ # remove double minus and minus at the end
+ $form->{name} =~ s/--+/-/g;
+ $form->{name} =~ s/-+$//;
+
+ # assign value discount, terms, creditlimit
+ $form->{discount} = $form->parse_amount( $myconfig, $form->{discount} );
+ $form->{discount} /= 100;
+ $form->{terms} *= 1;
+ $form->{taxincluded} *= 1;
+ $form->{creditlimit} =
+ $form->parse_amount( $myconfig, $form->{creditlimit} );
+ if ( !$form->{creditlimit} ) {
+ $form->{creditlimit} = 0;
+ }
+ &_save_vc($form);
# save taxes
foreach $item ( split / /, $form->{taxaccounts} ) {
@@ -386,134 +401,8 @@
$form->{taxincluded} *= 1;
$form->{creditlimit} =
$form->parse_amount( $myconfig, $form->{creditlimit} );
+ &_save_vc($form);
- if ( $form->{id} ) {
- $query = qq|DELETE FROM vendortax
- WHERE vendor_id = ?|;
-
- $sth = $dbh->prepare($query);
- $sth->execute( $form->{id} ) || $form->dberror($query);
-
- $query = qq|DELETE FROM shipto
- WHERE trans_id = ?|;
-
- $sth = $dbh->prepare($query);
- $sth->execute( $form->{id} ) || $form->dberror($query);
-
- $query = qq|SELECT id
- FROM vendor
- WHERE id = ?|;
-
- $sth = $dbh->prepare($query);
- $sth->execute( $form->{id} ) || $form->dberror($query);
-
- if ( !$sth->fetchrow_array ) {
- $query = qq|INSERT INTO vendor (id)
- VALUES (?)|;
-
- $sth = $dbh->prepare($query);
- $sth->execute( $form->{id} ) || $form->dberror($query);
- }
-
- # retrieve enddate
- if ( $form->{type} && $form->{enddate} ) {
- my $now;
- $query = qq|SELECT enddate, current_date AS now FROM vendor|;
- ( $form->{enddate}, $now ) = $dbh->selectrow_array($query);
- $form->{enddate} = $now if $form->{enddate} lt $now;
- }
-
- }
- else {
- my $uid = localtime;
- $uid .= "$$";
-
- $query = qq|INSERT INTO vendor (name)
- VALUES ('$uid')|;
-
- $dbh->do($query) || $form->dberror($query);
-
- $query = qq|SELECT id
- FROM vendor
- WHERE name = '$uid'|;
-
- ( $form->{id} ) = $dbh->selectrow_array($query);
-
- }
-
- my $employee_id;
- ( $null, $employee_id ) = split /--/, $form->{employee};
- $employee_id *= 1;
-
- my $pricegroup_id;
- ( $null, $pricegroup_id ) = split /--/, $form->{pricegroup};
- $pricegroup_id *= 1;
-
- my $business_id;
- ( $null, $business_id ) = split /--/, $form->{business};
- $business_id *= 1;
-
- my $language_code;
- ( $null, $language_code ) = split /--/, $form->{language};
-
- $form->{vendornumber} =
- $form->update_defaults( $myconfig, "vendornumber", $dbh )
- if !$form->{vendornumber};
-
- $form->{startdate} = undef unless $form->{startdate};
- $form->{enddate} = undef unless $form->{enddate};
-
- $query = qq|
- UPDATE vendor
- SET vendornumber = ?,
- name = ?,
- address1 = ?,
- address2 = ?,
- city = ?,
- state = ?,
- zipcode = ?,
- country = ?,
- contact = ?,
- phone = ?,
- fax = ?,
- email = ?,
- cc = ?,
- bcc = ?,
- notes = ?,
- discount = ?,
- creditlimit = ?,
- terms = ?,
- taxincluded = ?,
- gifi_accno = ?,
- business_id = ?,
- taxnumber = ?,
- sic_code = ?,
- iban = ?,
- bic = ?,
- employee_id = ?,
- language_code = ?,
- pricegroup_id = ?,
- curr = ?,
- startdate = ?,
- enddate = ?
- WHERE id = ?|;
-
- $sth = $dbh->prepare($query);
-
- $sth->execute(
- $form->{vendornumber}, $form->{name}, $form->{address1},
- $form->{address2}, $form->{city}, $form->{state},
- $form->{zipcode}, $form->{country}, $form->{contact},
- $form->{phone}, $form->{fax}, $form->{email},
- $form->{cc}, $form->{bcc}, $form->{notes},
- $form->{discount}, $form->{creditlimit}, $form->{terms},
- $form->{taxincluded}, $form->{gifi_accno}, $business_id,
- $form->{taxnumber}, $form->{sic_code}, $form->{iban},
- $form->{bic}, $employee_id, $language_code,
- $pricegroup_id, $form->{curr}, $form->{startdate},
- $form->{enddate}, $form->{id}
- ) || $form->dberror($query);
-
# save taxes
foreach $item ( split / /, $form->{taxaccounts} ) {
if ( $form->{"tax_$item"} ) {
Modified: trunk/LedgerSMB/RP.pm
===================================================================
--- trunk/LedgerSMB/RP.pm 2007-06-14 03:08:50 UTC (rev 1275)
+++ trunk/LedgerSMB/RP.pm 2007-06-14 03:59:29 UTC (rev 1276)
@@ -1603,14 +1603,15 @@
# select outstanding vendors or customers, depends on $ct
$query = qq|
- SELECT DISTINCT ct.id, ct.name, ct.language_code
+ SELECT DISTINCT ct.id, e.name, ct.language_code
FROM $form->{ct} ct
- JOIN $form->{arap} a ON (a.$form->{ct}_id = ct.id)
+ JOIN $form->{arap} a USING (entity_id)
+ JOIN entity e ON (ct.entity_id = e.id)
WHERE $where AND a.paid != a.amount
AND (a.$transdate <= ?)
- ORDER BY ct.name|;
+ ORDER BY e.name|;
my $sth = $dbh->prepare($query);
- $sth->execute( $form->{todate} ) || $form->dberror;
+ $sth->execute( $form->{todate} ) || $form->dberror($query);
my @ot = ();
while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.