navigation  interaction  search

 other resources

Changeset 405

Show
Ignore:
Timestamp:
05/28/08 13:34:05
Author:
nate
Message:

- Fixed saving / updating address records for clients from the sales order page.

- Will now properly insert/update address from saving of a new sales order record.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phpbms/modules/bms/include/invoices.php

    r386 r405  
    465465                } 
    466466                 
     467                function addressUpdate($variables, $invoiceid, $modifiedby, $method){ 
     468                // Updates/Inserts address records (billing or shipping )for the sales order's corresponding client 
     469                        switch($method){ 
     470                                case "shipping": 
     471                                        $varprefix = "shipto"; 
     472                                        $idprefix = "shipto"; 
     473                                break; 
     474                                 
     475                                case "billing": 
     476                                        $varprefix = ""; 
     477                                        $idprefix = "billing"; 
     478                                break; 
     479                        }//endswitch 
     480                         
     481                        switch($variables[$idprefix."saveoptions"]){ 
     482                         
     483                                case "updateAddress": 
     484                                        if($variables[$idprefix."addressid"]){ 
     485                                                 
     486                                                $address = new addresses($this->db, 306); 
     487                                                 
     488                                                $addressRecord = $address->getRecord($variables[$idprefix."addressid"]); 
     489                                                 
     490                                                if($varprefix == "shipto") 
     491                                                        $addressRecord["shiptoname"] = $variables["shiptoname"]; 
     492                                                $addressRecord["address1"] = $variables[$varprefix."address1"]; 
     493                                                $addressRecord["address2"] = $variables[$varprefix."address2"]; 
     494                                                $addressRecord["city"] = $variables[$varprefix."city"]; 
     495                                                $addressRecord["state"] = $variables[$varprefix."state"]; 
     496                                                $addressRecord["postalcode"] = $variables[$varprefix."postalcode"]; 
     497                                                $addressRecord["country"] = $variables[$varprefix."country"]; 
     498                                                 
     499                                                $address->updateRecord($addressRecord, $modifiedby); 
     500                                                 
     501                                        }//endif 
     502                                         
     503                                        break; 
     504                         
     505                                case "createAddress": 
     506                                        $addresstorecord = new addresstorecord($this->db,306); 
     507                                         
     508                                        if($varprefix == "shipto") 
     509                                                $addressRecord["shiptoname"] = $variables["shiptoname"]; 
     510                                        $atrRecord["address1"] = $variables[$varprefix."address1"]; 
     511                                        $atrRecord["address2"] = $variables[$varprefix."address2"]; 
     512                                        $atrRecord["city"] = $variables[$varprefix."city"]; 
     513                                        $atrRecord["state"] = $variables[$varprefix."state"]; 
     514                                        $atrRecord["postalcode"] = $variables[$varprefix."postalcode"]; 
     515                                        $atrRecord["country"] = $variables[$varprefix."country"]; 
     516                                        $atrRecord["recordid"] = $variables[$varprefix."clientid"]; 
     517                                        $atrRecord["tabledefid"] = 2; 
     518                                        $atrRecord["primary"] = 0; 
     519                                        $atrRecord["shiptodefault"] = 0; 
     520                                        $atrRecord["notes"] = "Created from sales order #".$invoiceid; 
     521                                         
     522                                        $newAtrID = $addresstorecord->insertRecord($atrRecord, $modifiedby); 
     523                                         
     524                                        $atrRecord = $addresstorecord->getRecord($newAtrID); 
     525                         
     526                                        //Need to connect the sales order to the new address record 
     527                                        $updatestatement = " 
     528                                                UPDATE 
     529                                                        invoices 
     530                                                SET 
     531                                                        ".$idprefix."addressid = ".$atrRecord["id"]." 
     532                                                WHERE 
     533                                                        id = ".$invoiceid; 
     534                                         
     535                                        $this->db->query($updatestatement); 
     536                                         
     537                                        break; 
     538                         
     539                        }//endswitch - saveoptions 
     540                         
     541                }//end method - addressUpdate 
     542                 
    467543                 
    468544                function updateRecord($variables, $modifiedby = NULL){ 
     
    505581                                // billing address 
    506582                                if($variables["billingsaveoptions"] != "orderOnly" || $variables["shiptosaveoptions"] != "orderOnly"){ 
    507                                  
     583                                        
    508584                                        require_once("addresses.php"); 
    509585                                        require_once("addresstorecord.php"); 
    510586                                         
    511                                         switch($variables["billingsaveoptions"]){ 
    512                                          
    513                                                 case "updateAddress": 
    514                                                         if($variables["billingaddressid"]){ 
    515                                                          
    516                                                                 $address = new addresses($this->db,306); 
    517                                                                  
    518                                                                 $addressRecord = $address->getRecord($variables["billingaddressid"]); 
    519                                                                  
    520                                                                 $addressRecord["address1"] = $variables["address1"]; 
    521                                                                 $addressRecord["address2"] = $variables["address2"]; 
    522                                                                 $addressRecord["city"] = $variables["city"]; 
    523                                                                 $addressRecord["state"] = $variables["state"]; 
    524                                                                 $addressRecord["postalcode"] = $variables["postalcode"]; 
    525                                                                 $addressRecord["country"] = $variables["country"]; 
    526  
    527                                                                 $address->updateRecord($addressRecord, $modifiedby); 
    528                                                                  
    529                                                         }//end if 
    530                                                         break; 
    531                                                          
    532                                                 case "createAddress": 
    533                                                         $addresstorecord = new addresstorecord($this->db,306); 
    534                                                          
    535                                                         $atrRecord["address1"] = $variables["address1"]; 
    536                                                         $atrRecord["address2"] = $variables["address2"]; 
    537                                                         $atrRecord["city"] = $variables["city"]; 
    538                                                         $atrRecord["state"] = $variables["state"]; 
    539                                                         $atrRecord["postalcode"] = $variables["postalcode"]; 
    540                                                         $atrRecord["country"] = $variables["country"]; 
    541                                                         $atrRecord["recordid"] = $variables["clientid"]; 
    542                                                         $atrRecord["tabledefid"] = 2; 
    543                                                         $atrRecord["primary"] = 0; 
    544                                                         $atrRecord["shiptodefault"] = 0; 
    545                                                         $atrRecord["notes"] = "Created from sales order #".$variables["id"]; 
    546                                                          
    547                                                         $newAtrID = $addresstorecord->insertRecord($atrRecord, $modifiedby); 
    548                                                          
    549                                                         $atrRecord = $addresstorecord->getRecord($newAtrID); 
    550  
    551                                                         //Need to connect the sales order to the new address record 
    552                                                         $updatestatement = " 
    553                                                                 UPDATE 
    554                                                                         invoices 
    555                                                                 SET 
    556                                                                         billingaddressid = ".$atrRecord["id"]." 
    557                                                                 WHERE 
    558                                                                         id = ".$variables["id"]; 
    559  
    560                                                         $this->db->query($updatestatement); 
    561                                                          
    562                                                         break; 
    563                                          
    564                                         }//endswitch billingsaveoptions 
    565                                          
    566                                         switch($variables["shiptosaveoptions"]){ 
    567  
    568                                                 case "updateAddress": 
    569                                                         if($variables["shiptoaddressid"]){ 
    570                                                          
    571                                                                 $address = new addresses($this->db,306); 
    572                                                                  
    573                                                                 $addressRecord = $address->getRecord($variables["shiptoaddressid"]); 
    574                                                                  
    575                                                                 $addressRecord["shiptoname"] = $variables["shiptoname"]; 
    576                                                                 $addressRecord["address1"] = $variables["shiptoaddress1"]; 
    577                                                                 $addressRecord["address2"] = $variables["shiptoaddress2"]; 
    578                                                                 $addressRecord["city"] = $variables["shiptocity"]; 
    579                                                                 $addressRecord["state"] = $variables["shiptostate"]; 
    580                                                                 $addressRecord["postalcode"] = $variables["shiptopostalcode"]; 
    581                                                                 $addressRecord["country"] = $variables["shiptocountry"]; 
    582  
    583                                                                 $address->updateRecord($addressRecord, $modifiedby); 
    584                                                                  
    585                                                         }//end if 
    586                                                         break; 
    587  
    588                                                 case "createAddress": 
    589                                                         $addresstorecord = new addresstorecord($this->db,306); 
    590                                                          
    591                                                         $atrRecord["shiptoname"] = $variables["shiptoname"]; 
    592                                                         $atrRecord["address1"] = $variables["shiptoaddress1"]; 
    593                                                         $atrRecord["address2"] = $variables["shiptoaddress2"]; 
    594                                                         $atrRecord["city"] = $variables["shiptocity"]; 
    595                                                         $atrRecord["state"] = $variables["shiptostate"]; 
    596                                                         $atrRecord["postalcode"] = $variables["shiptopostalcode"]; 
    597                                                         $atrRecord["country"] = $variables["shiptocountry"]; 
    598                                                         $atrRecord["recordid"] = $variables["clientid"]; 
    599                                                         $atrRecord["tabledefid"] = 2; 
    600                                                         $atrRecord["primary"] = 0; 
    601                                                         $atrRecord["shiptodefault"] = 0; 
    602                                                         $atrRecord["notes"] = "Created from sales order #".$variables["id"]; 
    603                                                          
    604                                                         $newAtrID = $addresstorecord->insertRecord($atrRecord, $modifiedby); 
    605                                                          
    606                                                         $atrRecord = $addresstorecord->getRecord($newAtrID); 
    607                                                          
    608                                                         //Need to connect the sales order to the new address record 
    609                                                         $updatestatement = " 
    610                                                                 UPDATE 
    611                                                                         invoices 
    612                                                                 SET 
    613                                                                         shiptoaddressid = ".$atrRecord["id"]." 
    614                                                                 WHERE 
    615                                                                         id = ".$variables["id"]; 
    616  
    617                                                         $this->db->query($updatestatement); 
    618                                                          
    619                                                         break; 
    620                                                                                                  
    621                                         }//endif 
    622                                  
     587                                        $this->addressUpdate($variables, $variables["id"], $modifiedby, "billing"); 
     588                                        $this->addressUpdate($variables, $variables["id"], $modifiedby, "shipping"); 
     589                                         
    623590                                }//end if 
    624                                         
     591                                 
    625592                        }//end if 
    626593                         
     
    642609         
    643610                        $newid = parent::insertRecord($variables, $createdby); 
    644          
     611                         
     612                        if($variables["billingsaveoptions"] != "orderOnly" || $variables["shiptosaveoptions"] != "orderOnly"){ 
     613                                 
     614                                require_once("addresses.php"); 
     615                                require_once("addresstorecord.php"); 
     616                                 
     617                                $this->addressUpdate($variables, $newid, $createdby, "billing"); 
     618                                $this->addressUpdate($variables, $newid, $createdby, "shipping"); 
     619                                 
     620                        }//end if 
     621                         
    645622                        if($variables["lineitemschanged"]==1){ 
    646623                                 
     
    657634         
    658635                        return $newid; 
    659                 } 
     636                 
     637                }//end method - insertRecord 
     638                 
    660639        }//end class 
    661640 
Copyright © 2006-2007 Kreotek, LLC. All Rights reserved.