UpdateDatabase.php
authorAlan Knowles <alan@roojs.com>
Wed, 25 Feb 2015 05:43:23 +0000 (13:43 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 25 Feb 2015 05:43:23 +0000 (13:43 +0800)
UpdateDatabase.php

index c45874b..ba3302f 100644 (file)
@@ -272,4 +272,192 @@ class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
     }
     
     
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    /*
+    
+    function updateData($k='')
+    {
+        $uom = DB_DataObject::factory('uom');
+        $uom->setFrom(array(
+            'uom_name' => 'YEAR',
+            'uom_descrip' => 'YEAR'
+        ));
+        
+        if(!$uom->find(true)){
+            $uom->insert();
+        }
+        $this->addWarehouse();
+        $this->addExtraYears();
+        $this->addAccounts();
+        $this->addBankAccounts();
+    }
+    */
+    
+    function addWarehouse()
+    {
+        $l = DB_DataObject::Factory('location');
+        if ($l->count()) {
+            echo "location exists - SKIP\n";
+            return;
+        }
+        $cust = DB_DataObject::Factory('custinfo');
+        $cc =$cust->count() ;
+        if ($cc != 1) {
+            echo "location create - needs 1 custinfo - got $cc\n";
+            return;
+        }
+        $cust->find(true);
+        
+        $l->setFrom(array(
+            'location_name' => 'Warehouse',
+            'location_descrip' => 'Warehouse',
+            'location_cust_id' => $cust->pid()
+        ));
+    }
+    
+    
+    
+    function addExtraYears()
+    {
+        $p = DB_DataObject::Factory('period');
+        if ($p->count()) {
+            echo "SKIP - already have periods\n";
+            return;
+        }
+        $p->initPeriods($this);
+        $p->initPeriods($this);
+        $p->initPeriods($this);
+        $p->initPeriods($this);
+        
+    }
+    function addAccounts()
+    {
+        require_once 'File/Convert.php';
+        $cp = $this->tempName('xls');
+        copy(dirname(__FILE__).'/../Xtuple/Setup/accounts_sample.xls', $cp);
+        $fc = new File_Convert($cp, 'application/vnd.ms-excel');
+        //var_Dump($img->getStoreName());
+        $csv = $fc->convert('text/csv');
+        unlink($cp);
+        //var_dump($csv);
+        require_once 'Pman/Xtuple/Import/Accounts.php';
+        $ia = new Pman_Xtuple_Import_Accounts();
+        $ia->importCsv($csv);
+    }
+    
+    function addBankAccounts() {
+        
+        $accnt = DB_DataObject::factory('subaccnt');
+        if (!$accnt->get('subaccnt_number', '01')) {
+            echo "SKIP Bank account creation - no subaccnt - 01\n";
+            return;
+        }
+        
+        $bankaccnt = DB_DataObject::factory('bankaccnt');
+        
+        $bankaccnt->whereAdd("
+            bankaccnt_name != ''
+        ");
+        
+        if(!$bankaccnt->count()){
+            $bankaccnt = DB_DataObject::factory('bankaccnt');
+        
+            if(!$bankaccnt->get('bankaccnt_name', 'Current Account')){
+                $accnt = DB_DataObject::factory('accnt');
+                $accnt->setFrom(array(
+                    'accnt_number' => '131',
+                    'accnt_descrip' => 'Current Account',
+                    'accnt_comments' => '',
+                    'accnt_profit' => '01',
+                    'accnt_sub' => '01',
+                    'accnt_type' => 'A',
+                    'accnt_extref' => '',
+                    'accnt_closedpost' => false,
+                    'accnt_forwardupdate' => false,
+                    'accnt_subaccnttype_code' => 'CA',
+                    'accnt_curr_id' => $accnt->sqlValue("baseCurrId()"),
+                    'accnt_active' => true
+                ));
+
+                if(!$accnt->find(true)){
+                    $accnt->insert();
+                }
+
+                $bankaccnt->setFrom(array(
+                    'bankaccnt_name' => 'Current Account',
+                    'bankaccnt_descrip' => 'Current Account',
+                    'bankaccnt_bankname' => 'Current Account',
+                    'bankaccnt_accntnumber' => 'N/A',
+                    'bankaccnt_ar' => true,
+                    'bankaccnt_ap' => true,
+                    'bankaccnt_nextchknum' => 5000,
+                    'bankaccnt_type' => 'K',
+                    'bankaccnt_accnt_id' => $accnt->pid(),
+                    'bankaccnt_curr_id' => $bankaccnt->sqlValue("baseCurrId()"),
+                    'bankaccnt_notes' => '',
+                    'bankaccnt_routing' => '',
+                    'bankaccnt_ach_enabled' => false,
+                    'bankaccnt_ach_origintype' => 'I'
+                ));
+
+                $bankaccnt->insert();
+            }
+
+            $bankaccnt = DB_DataObject::factory('bankaccnt');
+
+            if(!$bankaccnt->get('bankaccnt_name', 'Savings Account')){
+                $accnt = DB_DataObject::factory('accnt');
+                $accnt->setFrom(array(
+                    'accnt_number' => '404',
+                    'accnt_descrip' => 'Savings Account',
+                    'accnt_comments' => '',
+                    'accnt_profit' => '01',
+                    'accnt_sub' => '01',
+                    'accnt_type' => 'A',
+                    'accnt_extref' => '',
+                    'accnt_closedpost' => false,
+                    'accnt_forwardupdate' => false,
+                    'accnt_subaccnttype_code' => 'CA',
+                    'accnt_curr_id' => $accnt->sqlValue("baseCurrId()"),
+                    'accnt_active' => true
+                ));
+
+                if(!$accnt->find(true)){
+                    $accnt->insert();
+                }
+
+                $bankaccnt->setFrom(array(
+                    'bankaccnt_name' => 'Savings Account',
+                    'bankaccnt_descrip' => 'Savings Account',
+                    'bankaccnt_bankname' => 'Savings Account',
+                    'bankaccnt_accntnumber' => 'N/A',
+                    'bankaccnt_ar' => true,
+                    'bankaccnt_ap' => true,
+                    'bankaccnt_nextchknum' => 5000,
+                    'bankaccnt_type' => 'K',
+                    'bankaccnt_accnt_id' => $accnt->pid(),
+                    'bankaccnt_curr_id' => $bankaccnt->sqlValue("baseCurrId()"),
+                    'bankaccnt_notes' => '',
+                    'bankaccnt_routing' => '',
+                    'bankaccnt_ach_enabled' => false,
+                    'bankaccnt_ach_origintype' => 'I'
+                ));
+
+                $bankaccnt->insert();
+            }
+        }
+        
+    }
+    
 }
\ No newline at end of file