kleine codeverbesserungen
[kivitendo-erp.git] / SL / IC.pm
index 11bf586..a2703b6 100644 (file)
--- a/SL/IC.pm
+++ b/SL/IC.pm
@@ -34,6 +34,7 @@
 
 package IC;
 use Data::Dumper;
+use SL::DBUtils;
 
 sub get_part {
   $main::lxdebug->enter_sub();
@@ -53,9 +54,10 @@ sub get_part {
                 LEFT JOIN chart c2 ON (p.income_accno_id = c2.id)
                 LEFT JOIN chart c3 ON (p.expense_accno_id = c3.id)
                 LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
-                 WHERE p.id = $form->{id}|;
+                 WHERE p.id = ? |;
+  my @vars = ($form->{id});
   my $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
+  $sth->execute(@vars) || $form->dberror("$query (" . join(', ', @vars) . ")");
   my $ref = $sth->fetchrow_hashref(NAME_lc);
 
   # copy to $form variables
@@ -78,12 +80,12 @@ sub get_part {
                 FROM parts p
                JOIN assembly a ON (a.parts_id = p.id)
                LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
-               WHERE a.id = $form->{id}
-               ORDER BY $oid{$myconfig->{dbdriver}}|;
-
+               WHERE a.id = ?
+               ORDER BY ?|;
+    @vars = ($form->{id}, $oid{$myconfig->{dbdriver}});
     $sth = $dbh->prepare($query);
-    $sth->execute || $form->dberror($query);
-
+    $sth->execute(@vars) || $form->dberror("$query (" . join(', ', @vars) . ")");
+    
     $form->{assembly_rows} = 0;
     while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
       $form->{assembly_rows}++;
@@ -105,11 +107,12 @@ sub get_part {
   # get prices
   $query =
     qq|SELECT p.parts_id, p.pricegroup_id, p.price, (SELECT pg.pricegroup FROM pricegroup pg WHERE pg.id=p.pricegroup_id) AS pricegroup FROM prices p
-              WHERE parts_id = $form->{id}
+              WHERE parts_id = 
               ORDER by pricegroup|;
 
+  @vars = ($form->{id});
   $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
+  $sth->execute(@vars) || $form->dberror("$query (" . join(', ', @vars) . ")");
 
   @pricegroups          = ();
   @pricegroups_not_used = ();
@@ -177,10 +180,10 @@ sub get_part {
     # get makes
     if ($form->{makemodel}) {
       $query = qq|SELECT m.make, m.model FROM makemodel m
-                  WHERE m.parts_id = $form->{id}|;
-
+                  WHERE m.parts_id = ?|;
+      @vars = ($form->{id});
       $sth = $dbh->prepare($query);
-      $sth->execute || $form->dberror($query);
+      $sth->execute(@vars) || $form->dberror("$query (" . join(', ', @vars) . ")");
 
       my $i = 1;
       while (($form->{"make_$i"}, $form->{"model_$i"}) = $sth->fetchrow_array)
@@ -195,9 +198,10 @@ sub get_part {
 
   # get translations
   $form->{language_values} = "";
-  $query = qq|SELECT language_id, translation FROM translation WHERE parts_id = $form->{id}|;
+  $query = qq|SELECT language_id, translation FROM translation WHERE parts_id = ?|;
+  @vars = ($form->{id});
   $trq = $dbh->prepare($query);
-  $trq->execute || $form->dberror($query);
+  $trq->execute(@vars) || $form->dberror("$query (" . join(', ', @vars) . ")");
   while ($tr = $trq->fetchrow_hashref(NAME_lc)) {
     $form->{language_values} .= "---+++---".$tr->{language_id}."--++--".$tr->{translation};
   }
@@ -1145,7 +1149,7 @@ sub all_parts {
                 p.priceupdate, p.image, p.drawing, p.microfiche,
                 pg.partsgroup,
                 '' AS invnumber, o.ordnumber, o.quonumber, oi.trans_id,
-                ct.name|;
+                ct.name, NULL AS deliverydate|;
 
       if ($form->{ordered}) {
         $query .= qq|$union
@@ -1172,7 +1176,7 @@ sub all_parts {
                   p.priceupdate, p.image, p.drawing, p.microfiche,
                   pg.partsgroup,
                   '' AS invnumber, o.ordnumber, o.quonumber, oi.trans_id,
-                  ct.name|;
+                  ct.name, NULL AS deliverydate|;
 
         $query .= qq|$union
                    SELECT $flds, 'oe' AS module, 'purchase_order' AS type,
@@ -1210,7 +1214,7 @@ sub all_parts {
                 p.priceupdate, p.image, p.drawing, p.microfiche,
                 pg.partsgroup,
                 '' AS invnumber, o.ordnumber, o.quonumber, oi.trans_id,
-                ct.name|;
+                ct.name, NULL AS deliverydate|;
 
       if ($form->{quoted}) {
         $query .= qq|$union
@@ -1237,7 +1241,7 @@ sub all_parts {
                   p.priceupdate, p.image, p.drawing, p.microfiche,
                   pg.partsgroup,
                   '' AS invnumber, o.ordnumber, o.quonumber, oi.trans_id,
-                  ct.name|;
+                  ct.name, NULL AS deliverydate|;
 
         $query .= qq|$union
                    SELECT $flds, 'oe' AS module, 'request_quotation' AS type,
@@ -1742,7 +1746,7 @@ sub retrieve_languages {
 }
 
 sub follow_account_chain {
-  $main::lxdebug->enter_sub();
+  $main::lxdebug->enter_sub(2);
 
   my ($self, $form, $dbh, $transdate, $accno_id, $accno) = @_;
 
@@ -1768,13 +1772,13 @@ sub follow_account_chain {
     push(@visited_accno_ids, $accno_id);
   }
 
-  $main::lxdebug->leave_sub();
+  $main::lxdebug->leave_sub(2);
 
   return ($accno_id, $accno);
 }
 
 sub retrieve_accounts {
-  $main::lxdebug->enter_sub();
+  $main::lxdebug->enter_sub(2);
 
   my ($self, $myconfig, $form, $parts_id, $index, $copy_accnos) = @_;
 
@@ -1827,7 +1831,7 @@ sub retrieve_accounts {
 
   if (!$ref) {
     $dbh->disconnect();
-    return $main::lxdebug->leave_sub();
+    return $main::lxdebug->leave_sub(2);
   }
 
   $ref->{"inventory_accno_id"} = undef unless ($ref->{"is_part"});
@@ -1854,16 +1858,17 @@ sub retrieve_accounts {
     "WHERE t.id IN " .
     "  (SELECT tk.tax_id " .
     "   FROM taxkeys tk " .
-    "   WHERE tk.chart_id = $accno_id AND startdate <= $transdate " .
+    "   WHERE tk.chart_id = ? AND startdate <= " . quote_db_date($transdate) .
     "   ORDER BY startdate DESC LIMIT 1) ";
+  @vars = ($accno_id);
   $sth = $dbh->prepare($query);
-  $sth->execute() || $form->dberror($query);
+  $sth->execute(@vars) || $form->dberror("$query (" . join(', ', @vars) . ")");
   $ref = $sth->fetchrow_hashref();
   $sth->finish();
   $dbh->disconnect();
 
   unless ($ref) {
-    $main::lxdebug->leave_sub();
+    $main::lxdebug->leave_sub(2);
     return;
   }
 
@@ -1880,6 +1885,7 @@ sub retrieve_accounts {
 #                           " || taxaccounts_$index " . $form->{"taxaccounts_$index"} .
 #                           " || taxaccounts " . $form->{"taxaccounts"});
 
-  $main::lxdebug->leave_sub();
+  $main::lxdebug->leave_sub(2);
 }
+
 1;